Skip to content
This repository was archived by the owner on Feb 1, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/bwoken/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/bwoken/script_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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