diff --git a/lib/bwoken/script.rb b/lib/bwoken/script.rb index 11df9bf..af95856 100644 --- a/lib/bwoken/script.rb +++ b/lib/bwoken/script.rb @@ -47,9 +47,22 @@ def device_flag simulator ? '' : "-w #{Bwoken::Device.uuid}" end + # unix_instruments will try to open /dev/ptyvf + def check_ptyvf! + ptyvf_fd = IO.sysopen('/dev/ptyvf', 'r') + ptyvf_io = IO.new(ptyvf_fd, 'r') + rescue Errno::EBUSY => e + # TODO: log error here + raise + ensure + ptyvf_io.close if ptyvf_io + end + def run formatter.before_script_run path + check_ptyvf! + Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| exit_status = formatter.format stdout raise ScriptFailedError.new('Test Script Failed') unless exit_status == 0 diff --git a/spec/lib/bwoken/script_spec.rb b/spec/lib/bwoken/script_spec.rb index 1411b23..e41759b 100644 --- a/spec/lib/bwoken/script_spec.rb +++ b/spec/lib/bwoken/script_spec.rb @@ -15,6 +15,7 @@ class Simulator; end describe '#run' do let(:exit_status) { 0 } before do + IO.stub(:sysopen).and_return(STDOUT.fcntl(Fcntl::F_DUPFD)) subject.formatter.stub(:format).and_return(exit_status) subject.formatter.stub(:before_script_run) end @@ -132,4 +133,12 @@ class Simulator; end end end + describe "#check_ptyvf!" do + it "raises an exception when busy" do + subject.formatter.stub(:before_script_run) + IO.should_receive(:sysopen).with('/dev/ptyvf', 'r').and_raise('busy!') + expect { subject.run }.to raise_error RuntimeError, "busy!" + end + end + end