Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / test-driver
1 #!/usr/bin/env perl
2
3 my $interpreter = shift;
4 my $test = shift;
5 my $disabled_tests = shift;
6 my $dump_output = shift;
7
8 my $output = $test;
9 my $stdout = $test.'.stdout';
10 my $stderr = $test.'.stderr';
11
12 $output =~ s/\.exe$/.output/;
13
14 my $timeout_in_minutes = 2;
15
16 my $test_binary = $test;
17
18 if ($test =~ /.*\|.*/) {
19         my @values = split(/\|/, $test);
20         my $binary = @values[0];
21         my $test_name = @values[1];
22
23         $test_binary = $binary;
24         $test = $test_name . "_" . $binary;
25         $stdout = $test.'.stdout';
26         $stderr = $test.'.stderr';
27         $output = $test;
28
29         #This is a silly workaround, but all tests that use extra parameters need a larger timeout.
30         $timeout_in_minutes = 15;
31 }
32 $ENV{'TEST_DRIVER_TIMEOUT_SEC'} = $timeout_in_minutes * 60;
33
34 $| = 0;
35 print "Testing $test... ";
36
37 foreach $disabled (split (/ /, $disabled_tests)) {
38         $disabled =~ s/^\s+|\s+$//g;
39         if ($disabled eq $test) {
40                 print "disabled.\n";
41                 exit (0);
42         }
43 }
44
45 my $res;
46 my $cpid = fork ();
47 if (!defined ($cpid)) {
48         $res = system("$interpreter @ARGV $test_binary 2>$stderr 1>$stdout");
49 } elsif ($cpid == 0) {
50         exec ("$interpreter @ARGV $test_binary 2>$stderr 1>$stdout") || die "Cannot exec: $!";
51 } else {
52         # in the parent, setup the alarm
53         # test must complete in 2 minutes or it is considered buggy
54         my $timeout = $timeout_in_minutes * 60;
55         alarm ($timeout);
56         $SIG{ALRM} = sub {
57                 print "failed after $timeout seconds timeout.\n";
58                 dump_files ();
59                 # process group kill
60                 kill (-9, $cpid);
61                 exit (3);
62         };
63         $res = wait ();
64         $SIG{ALRM} = sub {};
65         $res = $? >> 8;
66 }
67
68 if ($res) {
69         printf ("failed $? (%d) signal (%d).\n", $? >> 8, $? & 127);
70         dump_files ();
71         if (($? & 127) == 2) {
72                 exit (2);
73         } else {
74                 exit (1);
75         }
76 }
77 if (-f $output && (read_file ($output) ne read_file ($stdout))) {
78         print "failed output.\n";
79         dump_files ();
80         exit (1);
81 }
82
83 print "pass.\n";
84 unlink ($stderr);
85 exit (0);
86
87 sub dump_files {
88         if ($dump_output ne "dump-output") {
89                 return;
90         }
91
92         printf ("----STDOUT-----\n");
93         print read_file($stdout);
94         printf ("----STDERR-----\n");
95         print read_file($stderr);
96         printf ("---------------\n");
97 }
98
99 sub read_file {
100         local ($/);
101         my $out = shift;
102         open (F, "<$out") || die $!;
103         $out = <F>;
104         close(F);
105         return $out;
106 }