-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests
executable file
·83 lines (77 loc) · 1.63 KB
/
run-tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env perl
use strict;
my $dirname = @ARGV[0];
my %tests;
print "TEST\tRESULT\tEXIT CODE\tERROR NAME\n";
my @files;
opendir(DIR, $dirname) or die "Unable to open directory '$dirname'";
@files = grep {/^[^.]/} readdir(DIR);
closedir(DIR);
foreach my $file (@files) {
my $pid = fork();
if ($pid == 0) {
chdir $dirname;
exec("../parse", $file);
} elsif ($pid > 0) {
$tests{$file} = $pid;
} else {
print STDERR "Skipping '$file'; fork failed\n";
}
}
my @error_messages = ();
if (open my $header, "<", "json.h") {
my $begun = 0;
my $idx = 0;
while (my $line = <$header>) {
if ($line =~ /enum json_type \{/) {
last;
}
}
while (my $line = <$header>) {
if ($line =~ /^\tJSON_(?:ERROR_)?(\w+)/) {
push @error_messages, $1;
} elsif ($line =~ /\};/) {
last;
}
}
}
@error_messages[0] = "";
while (my ($file, $pid) = (each %tests)) {
my $kill_signal = 15;
my $timed_out = 0;
$SIG{'ALRM'} = sub {
$timed_out = 1;
kill $kill_signal, $pid;
};
alarm 1;
waitpid $pid, 0;
alarm 0;
my ($result, $exit, $message);
if ($timed_out) {
$result = "TIMED OUT";
$exit = 128 + $kill_signal;
} else {
my $test_type = substr($file, 0, 1);
my ($zero, $nonzero);
if ($test_type eq 'y') {
$zero = "SUCCEEDED";
$nonzero = "FAILED";
} elsif ($test_type eq 'n') {
$nonzero = "SUCCEEDED";
$zero = "FAILED";
} else {
$nonzero = "SUCCEEDED";
$zero = "SUCCEEDED";
}
$exit = $? >> 8;
if ($exit) {
$result = $nonzero;
} else {
$result = $zero;
}
if ($exit <= $#error_messages) {
$message = @error_messages[$exit];
}
}
printf "%s\t%s\t%03d\t%s\n", $file, $result, $exit, $message;
}