-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests
executable file
·202 lines (165 loc) · 4.68 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#! /usr/bin/perl
use strict;
use Getopt::Long;
sub prepare_test;
sub run_test;
sub verify_test;
sub table_head;
my $testdir = "tests";
# store reference output, don't do checks
my $opt_create_reference;
my $opt_test_pattern = "*";
GetOptions(
'create-reference|r' => \$opt_create_reference,
'test|t=s' => \$opt_test_pattern,
);
die "error: no gfxboot-compile\n" unless -x "./gfxboot-compile";
die "error: no gfxboot-x11\n" unless -x "./gfxboot-x11";
my $tests = [ qw ( code mem trace basic code1 opt1 code2 opt2 gc screen ) ];
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $count = 0;
my $failed = 0;
my $ok = 0;
table_head if !$opt_create_reference;
for my $test (<$testdir/$opt_test_pattern>) {
next unless -d $test;
$count++;
prepare_test $test;
run_test $test;
prepare_test $test, 1;
run_test $test, 1;
prepare_test $test, 2;
run_test $test, 2;
$failed += verify_test $test if !$opt_create_reference;
}
if($opt_create_reference) {
print "$count test results created\n";
}
else {
$ok = $count - $failed;
my $s = sprintf "%4d tests ok", $ok;
$s .= sprintf ", %3d failed", $failed if $failed;
table_head $s;
}
exit $failed ? 1 : 0;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub prepare_test
{
my $test = $_[0];
my $ref = $opt_create_reference ? ".ref" : "";
my $opt = $_[1] ? "-O$_[1]" : "";
system "./gfxboot-compile $opt -v -c $test/main.gc -l $test/code$_[1].log$ref $test/main.gs";
if($ref && $opt) {
# unlink "$test/code$_[1].log$ref";
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub run_test
{
my $test = $_[0];
my $opt = $_[1] ? "_opt$_[1]" : "";
my $opt_log = "opt$_[1].log";
my $ref = $opt_create_reference ? ".ref" : "";
system "./gfxboot-x11 --no-x11 --file tests/test_script $test >$test/test$opt.log";
if(open my $f, "$test/test$opt.log") {
local $/;
$_ = <$f>;
close $f;
if(/\n(# --- trace ---\n.*\n)# --- trace_end ---\n/s) {
my $s = $1;
$s =~ s/\n[^\n]+trace_end[^\n]+$//s;
if(!$opt) {
if(open my $f, ">$test/trace.log$ref") {
print $f $s;
close $f;
}
}
my $opt_log_name = "$test/opt.log.ref";
if($opt) {
$opt_log_name = "$test/$opt_log";
}
if(open my $f, ">", $opt_log_name) {
$s =~ s/, (ofs|current) 0x[0-9a-f]+\b//g;
$s =~ s/, ip 0x[0-9a-f]+ \(0x[0-9a-f]+\)//g;
$s =~ s/, size \d+\b//g;
$s =~ s/\nIP: [^\n]+//g;
$s =~ s/(\nerror [^\n]+):[^\n]+/$1/g;
print $f $s;
close $f;
}
if(open my $f, ">", "$test/basic.log$ref") {
$s =~ s/#\d+(\.\d+\.\d+\.)/#xxxx$1/g;
print $f $s;
close $f;
}
if($opt) {
link "$test/opt.log.ref", "$test/$opt_log.ref";
}
}
if(!$opt) {
if(/\n(# --- mem ---\n.*\n)# --- mem_end ---\n/s) {
my $s = $1;
$s =~ s/\n[^\n]+mem_end[^\n]+$//s;
if(open my $f, ">$test/mem.log$ref") {
print $f $s;
close $f;
}
}
if(/\n(# --- gc ---\n.*\n)# --- gc_end ---\n/s) {
my $s = $1;
$s =~ s/\n[^\n]+gc_end[^\n]+$//s;
if(open my $f, ">$test/gc.log$ref") {
print $f $s;
close $f;
}
}
if(/\n(# --- screen ---\n.*\n)# --- screen_end ---\n/s) {
my $s = $1;
$s =~ s/\n[^\n]+screen_end[^\n]+$//s;
if(open my $f, ">$test/screen.log$ref") {
print $f $s;
close $f;
}
}
}
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub verify_test
{
my $test = $_[0];
my $all_err = 0;
my $name = $test;
$name =~ s#^.*/##;
printf "%-26s|", $name;
my $msg;
for my $v (@$tests) {
my $res;
my $ref;
if(open my $f, "$test/$v.log") { local $/; $res = <$f>; close $f; }
if(open my $f, "$test/$v.log.ref") { local $/; $ref = <$f>; close $f; }
my $err;
if($v eq "gc" ) {
# gc should have cleaned up everything but for 2 objects:
# - 1. object list
# - 2. gc's own data
$err = $res !~ /olist <size 2,/;
}
else {
$err = $res eq "" || $res ne $ref ? ($ref eq "" ? 2 : 1) : 0;
$err = 3 if $res =~ /\n\s*error\s\d\s\(/ && $res !~ /"error ok"/;
}
$all_err ||= $err;
$msg .= sprintf "%8s", ("ok", "fail", "new", "err")[$err];
}
print "$msg\n";
return $all_err ? 1 : 0;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub table_head
{
print "-" x (27 + 8 * @$tests), "\n";
printf "%-25s |", $_[0];
printf "%8s", $_ for (@$tests);
print "\n", "-" x (27 + 8 * @$tests), "\n";
}