|
| 1 | +#!/usr/bin/env ruby |
| 2 | +HELP=<<EOS |
| 3 | +Runs the bindfs test suite in all vagrant boxes in parallel. |
| 4 | +
|
| 5 | +Usage: test.rb [--nohalt] [vm1 [...]] |
| 6 | +Options: |
| 7 | + -h --help Print this and exit. |
| 8 | + --nohalt Don't halt VMs when done. |
| 9 | +
|
| 10 | +If VM names are given, only those are tested. |
| 11 | +
|
| 12 | +Bugs: |
| 13 | + - Spurious "Connection to 127.0.0.1 closed." messages can appear, and the |
| 14 | + terminal may need a `reset` after this command finishes. |
| 15 | +EOS |
| 16 | + |
| 17 | +require'fileutils' |
| 18 | + |
| 19 | +Dir.chdir(File.dirname(__FILE__)) |
| 20 | + |
| 21 | +halt_vms=true |
| 22 | +specifically_selected_vms=[] |
| 23 | +ARGV.eachdo |arg| |
| 24 | +ifarg =='-h' ||arg =='--help' |
| 25 | +putsHELP |
| 26 | +exit |
| 27 | +elsifarg =='--nohalt' |
| 28 | +halt_vms=false |
| 29 | +elsif !arg.start_with?('-') |
| 30 | +specifically_selected_vms <<arg |
| 31 | +else |
| 32 | +raise"Unknown option:#{arg}" |
| 33 | +end |
| 34 | +end |
| 35 | + |
| 36 | +dirs=Dir.glob('*/Vagrantfile').map{ |path|File.dirname(path)} |
| 37 | +unlessspecifically_selected_vms.empty? |
| 38 | +dirs=dirs.select{ |dir|ARGV.include?(dir)} |
| 39 | +end |
| 40 | + |
| 41 | +puts"Running#{dirs.size} VMs in parallel:#{dirs.join(' ')}" |
| 42 | +puts"Note: if your terminal goes wonky after this command, type 'reset'" |
| 43 | +mutex=Thread::Mutex.new# protects `$stdout` and `errors` |
| 44 | +errors=[] |
| 45 | +threads=dirs.mapdo |dir| |
| 46 | +Thread.newdo |
| 47 | +begin |
| 48 | +File.open(dir +"/test.log","wb")do |logfile| |
| 49 | +run_and_log=->(command)do |
| 50 | +logfile.puts"" |
| 51 | +logfile.puts"######{command} #####" |
| 52 | +logfile.flush |
| 53 | +pid=Process.spawn(command,chdir:dir,out:logfile,err::out) |
| 54 | +Process.waitpid(pid) |
| 55 | + $?.success? |
| 56 | +end |
| 57 | +unlessrun_and_log.call"vagrant up" |
| 58 | +raise"vagrant up failed" |
| 59 | +end |
| 60 | +unlessrun_and_log.call"vagrant rsync" |
| 61 | +raise"vagrant rsync failed" |
| 62 | +end |
| 63 | +unlessrun_and_log.call"vagrant ssh -c 'cd /bindfs && sudo rm -Rf tests/tmp_test_bindfs && ./configure && make clean && make && make check && sudo make check'" |
| 64 | +mutex.synchronizedo |
| 65 | +errors <<"VM#{dir} tests failed." |
| 66 | +end |
| 67 | +end |
| 68 | +ifhalt_vms |
| 69 | +unlessrun_and_log.call"vagrant halt" |
| 70 | +raise"vagrant halt failed" |
| 71 | +end |
| 72 | +end |
| 73 | +end |
| 74 | +rescue |
| 75 | +mutex.synchronizedo |
| 76 | +errors <<"VM#{dir} error:#{$!}" |
| 77 | +end |
| 78 | +ensure |
| 79 | +mutex.synchronizedo |
| 80 | +puts"Finished VM:#{dir}" |
| 81 | +end |
| 82 | +end |
| 83 | +end |
| 84 | +end |
| 85 | + |
| 86 | +threads.each(&:join) |
| 87 | + |
| 88 | +iferrors.empty? |
| 89 | +puts"OK" |
| 90 | +else |
| 91 | +unlesserrors.empty? |
| 92 | +puts |
| 93 | +puts"Errors:" |
| 94 | +errors.each{ |err|puts"#{err}"} |
| 95 | +puts |
| 96 | +puts"See test.log in a failed VM's directory for more information" |
| 97 | +puts |
| 98 | +end |
| 99 | +end |