| 1 | #!@PERL@ |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | |
|---|
| 6 | use lib 'infrastructure'; |
|---|
| 7 | use BoxPlatform; |
|---|
| 8 | |
|---|
| 9 | my ($test_name,$test_mode) = @ARGV; |
|---|
| 10 | |
|---|
| 11 | $test_mode = 'debug' if not defined $test_mode or $test_mode eq ''; |
|---|
| 12 | |
|---|
| 13 | if($test_name eq '' || ($test_mode ne 'debug' && $test_mode ne 'release')) |
|---|
| 14 | { |
|---|
| 15 | print <<__E; |
|---|
| 16 | Run Test utility -- bad usage. |
|---|
| 17 | |
|---|
| 18 | runtest.pl (test|ALL) [release|debug] |
|---|
| 19 | |
|---|
| 20 | Mode defaults to debug. |
|---|
| 21 | |
|---|
| 22 | __E |
|---|
| 23 | exit(2); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | my @results; |
|---|
| 27 | my $exit_code = 0; |
|---|
| 28 | |
|---|
| 29 | if($test_name ne 'ALL') |
|---|
| 30 | { |
|---|
| 31 | # run one or more specified test |
|---|
| 32 | if ($test_name =~ m/,/) |
|---|
| 33 | { |
|---|
| 34 | foreach my $test (split m/,/, $test_name) |
|---|
| 35 | { |
|---|
| 36 | runtest($test); |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | else |
|---|
| 40 | { |
|---|
| 41 | runtest($test_name); |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | else |
|---|
| 45 | { |
|---|
| 46 | # run all tests |
|---|
| 47 | my @tests; |
|---|
| 48 | open MODULES,'modules.txt' or die "Can't open modules file"; |
|---|
| 49 | while(<MODULES>) |
|---|
| 50 | { |
|---|
| 51 | # omit bits on some platforms? |
|---|
| 52 | next if m/\AEND-OMIT/; |
|---|
| 53 | if(m/\AOMIT:(.+)/) |
|---|
| 54 | { |
|---|
| 55 | if($1 eq $build_os or $1 eq $target_os) |
|---|
| 56 | { |
|---|
| 57 | while(<MODULES>) |
|---|
| 58 | { |
|---|
| 59 | last if m/\AEND-OMIT/; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | next; |
|---|
| 63 | } |
|---|
| 64 | push @tests,$1 if m~\Atest/(\w+)\s~; |
|---|
| 65 | } |
|---|
| 66 | close MODULES; |
|---|
| 67 | |
|---|
| 68 | runtest($_) for(@tests) |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | # report results |
|---|
| 72 | print "--------\n",join("\n",@results),"\n"; |
|---|
| 73 | |
|---|
| 74 | if ($exit_code != 0) |
|---|
| 75 | { |
|---|
| 76 | print <<__E; |
|---|
| 77 | |
|---|
| 78 | One or more tests have failed. Please check the following common causes: |
|---|
| 79 | |
|---|
| 80 | * Check that no instances of bbstored or bbackupd are already running |
|---|
| 81 | on this machine. |
|---|
| 82 | * Make sure there isn't a firewall blocking incoming or outgoing connections |
|---|
| 83 | on port 2201. |
|---|
| 84 | * Check that there is sufficient space in the filesystem that the tests |
|---|
| 85 | are being run from (at least 1 GB free). |
|---|
| 86 | * The backupdiff test fails if it takes too long, so it's sensitive to |
|---|
| 87 | the speed of the host and your connection to it. |
|---|
| 88 | |
|---|
| 89 | After checking all the above, if you still have problems please contact |
|---|
| 90 | us on the mailing list, boxbackup\@boxbackup.org. Thanks! |
|---|
| 91 | __E |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | exit $exit_code; |
|---|
| 95 | |
|---|
| 96 | sub runtest |
|---|
| 97 | { |
|---|
| 98 | my ($t) = @_; |
|---|
| 99 | |
|---|
| 100 | # attempt to make this test |
|---|
| 101 | my $flag = ($test_mode eq 'release')?(BoxPlatform::make_flag('RELEASE')):''; |
|---|
| 102 | my $make_res = system("cd test/$t ; $make_command $flag"); |
|---|
| 103 | if($make_res != 0) |
|---|
| 104 | { |
|---|
| 105 | push @results,"$t: make failed"; |
|---|
| 106 | $exit_code = 2; |
|---|
| 107 | return; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | my $logfile = "test-$t.log"; |
|---|
| 111 | |
|---|
| 112 | # run it |
|---|
| 113 | my $test_res = system("cd $test_mode/test/$t ; ./t 2>&1 " . |
|---|
| 114 | "| tee ../../../$logfile"); |
|---|
| 115 | |
|---|
| 116 | # open test results |
|---|
| 117 | if(open RESULTS, $logfile) |
|---|
| 118 | { |
|---|
| 119 | my $last; |
|---|
| 120 | while(<RESULTS>) |
|---|
| 121 | { |
|---|
| 122 | $last = $_ if m/\w/; |
|---|
| 123 | } |
|---|
| 124 | close RESULTS; |
|---|
| 125 | |
|---|
| 126 | chomp $last; |
|---|
| 127 | $last =~ s/\r//; |
|---|
| 128 | push @results, "$t: $last"; |
|---|
| 129 | |
|---|
| 130 | if ($last ne "PASSED") |
|---|
| 131 | { |
|---|
| 132 | $exit_code = 1; |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | else |
|---|
| 136 | { |
|---|
| 137 | push @results, |
|---|
| 138 | "$t: failed to open test log file: $logfile: $!"; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | # delete test results |
|---|
| 142 | # unlink $logfile; |
|---|
| 143 | } |
|---|
| 144 | |
|---|