Skip to content

Commit eba97a0

Browse files
thk123thk123
thk123
authored and
thk123
committed
Made the Perl script not using grep
Includes tests for excluded lines and multi lines. Includes tests that the test runner should fail, these are set as KNOWNBUG so we can run the regressions folder. We also don't print out when grep options activated as no chance of doing by accident as very clearly different to any other syntax. The printing messes up the formatting of the output so better to not have it. Added test script to the Makefile Also ordered the tests into alphabetical orde.r
1 parent 8e68cad commit eba97a0

File tree

16 files changed

+184
-23
lines changed

16 files changed

+184
-23
lines changed

regression/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11

2-
DIRS = ansi-c cbmc cpp goto-instrument goto-analyzer cbmc-java
2+
DIRS = ansi-c \
3+
cbmc \
4+
cpp \
5+
cbmc-java \
6+
goto-analyzer \
7+
goto-instrument \
8+
test-script \
9+
# Empty last line
10+
311

412
test:
513
$(foreach var,$(DIRS), $(MAKE) -C $(var) test || exit 1;)

regression/test-script/Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
default: tests.log
3+
4+
test:
5+
@if ! ../test.pl -c ../program_runner.sh ; then \
6+
../failed-tests-printer.pl ; \
7+
exit 1; \
8+
fi
9+
10+
tests.log:
11+
pwd
12+
@if ! ../test.pl -c ../program_runner.sh ; then \
13+
../failed-tests-printer.pl ; \
14+
exit 1; \
15+
fi
16+
17+
show:
18+
@for dir in *; do \
19+
if [ -d "$$dir" ]; then \
20+
vim -o "$$dir/*.c" "$$dir/*.out"; \
21+
fi; \
22+
done;
23+
24+
clean:
25+
@for dir in *; do \
26+
rm -f tests.log; \
27+
if [ -d "$$dir" ]; then \
28+
cd "$$dir"; \
29+
rm -f *.out *.gb; \
30+
cd ..; \
31+
fi \
32+
done
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main(void) {
4+
printf("Hello\n");
5+
printf("World\n");
6+
return 0;
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
program.c
3+
4+
^Hello$
5+
--
6+
^Goodbye$
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main(void) {
4+
printf("Hello\n");
5+
printf("World\n");
6+
return 0;
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
KNOWNBUG
2+
program.c
3+
4+
^Hello$
5+
--
6+
^World$
7+
--
8+
This isn't really a known bug perse, instead this test should fail (since these
9+
are tests of the test runner).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main(void) {
4+
printf("Hello\n");
5+
printf("World\n");
6+
return 0;
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
KNOWNBUG
2+
program.c
3+
4+
activate-multi-line-match
5+
Hello\nAnother\nWorld
6+
--
7+
--
8+
This isn't really a known bug perse, instead this test should fail (since these
9+
are tests of the test runner).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main(void) {
4+
printf("Hello\n");
5+
printf("World\n");
6+
return 0;
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
KNOWNBUG
2+
program.c
3+
4+
^Goodbye$
5+
--
6+
--
7+
This isn't really a known bug perse, instead this test should fail (since these
8+
are tests of the test runner).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main(void) {
4+
printf("Hello\n");
5+
printf("World\n");
6+
return 0;
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
program.c
3+
4+
activate-multi-line-match
5+
Hello\nWorld
6+
--
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
gcc $1 -o a.out
6+
./a.out
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main(void) {
4+
printf("Hello\n");
5+
printf("World\n");
6+
return 0;
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CORE
2+
program.c
3+
4+
^Hello$
5+
--

regression/test.pl

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use strict;
55
use warnings;
66

7+
use Cwd;
8+
79
my $has_thread_pool = eval
810
{
911
# "http://www.cpan.org/authors/id/J/JW/JWU/Thread-Pool-Simple/Thread-Pool-Simple-0.25.tar.gz"
@@ -61,13 +63,9 @@ ($$$$$)
6163
my ($name, $test, $t_level, $cmd, $ign) = @_;
6264
my ($level, $input, $options, $grep_options, @results) = load("$test");
6365

64-
# If the 4th line starts with a '-' we use that line as options to pass to
65-
# grep when matching all lines in this test
66-
if($grep_options =~ /^-/) {
67-
print "\nActivating perl flags: $grep_options\n";
68-
}
69-
else {
70-
# No grep options so stick this back into the results array
66+
# If the 4th line is activate-multi-line-match we enable multi-line checks
67+
if($grep_options ne "activate-multi-line-match") {
68+
# No such flag, so we add it back in
7169
unshift @results, $grep_options;
7270
$grep_options = "";
7371
}
@@ -117,10 +115,43 @@ ($$$$$)
117115
$included--;
118116
} else {
119117
my $r;
120-
$result =~ s/\\/\\\\/g;
121-
$result =~ s/([^\\])\$/$1\\r\\\\?\$/;
122-
system("bash", "-c", "grep $grep_options \$'$result' '$name/$output' >/dev/null");
123-
$r = ($included ? $? != 0 : $? == 0);
118+
119+
my $dir = getcwd();
120+
my $abs_path = "$dir/$name/$output";
121+
open(my $fh => $abs_path) || die "Cannot open '$name/$output': $!";
122+
123+
# Multi line therefore we run each check across the whole output
124+
if($grep_options eq "activate-multi-line-match") {
125+
local $/ = undef;
126+
binmode $fh;
127+
my $whole_file = <$fh>;
128+
my $is_match = $whole_file =~ /$result/;
129+
$r = ($included ? !$is_match : $is_match);
130+
}
131+
else
132+
{
133+
my $found_line = 0;
134+
while(my $line = <$fh>) {
135+
if($line =~ /$result/) {
136+
# We've found the line, therefore if it is included we set
137+
# the result to 0 (OK) If it is excluded, we set the result
138+
# to 1 (FAILED)
139+
$r = !$included;
140+
$found_line = 1;
141+
last;
142+
}
143+
}
144+
145+
if($found_line == 0) {
146+
# None of the lines matched, therefore the result is set to
147+
# 0 (OK) if and only if the line was not meant to be included
148+
$r = $included;
149+
}
150+
151+
}
152+
close($fh);
153+
154+
124155
if($r) {
125156
print LOG "$result [FAILED]\n";
126157
$failed = 1;
@@ -185,24 +216,23 @@ ($$$$)
185216
<level>
186217
<main source>
187218
<options>
188-
<grep_options>
219+
<activate-multi-line-match>
189220
<required patterns>
190221
--
191222
<disallowed patterns>
192223
--
193224
<comment text>
194225
195226
where
196-
<level> is one of CORE, THOROUGH, FUTURE or KNOWNBUG
197-
<main source> is a file with extension .c/.i/.gb/.cpp/.ii/.xml/.class/.jar
198-
<options> additional options to be passed to CMD
199-
<grep_options> additional flags to be passed to grep when checking required
200-
patterns (this is optional, if the line stats with a `-'
201-
it will be used as grep options. Otherwise, it will be
202-
considered part of the required patterns)
203-
<required patterns> one or more lines of regualar expressions that must occur in the output
204-
<disallowed patterns> one or more lines of expressions that must not occur in output
205-
<comment text> free form text
227+
<level> is one of CORE, THOROUGH, FUTURE or KNOWNBUG
228+
<main source> is a file with extension .c/.i/.gb/.cpp/.ii/.xml/.class/.jar
229+
<options> additional options to be passed to CMD
230+
<activate-multi-line-match> The fourth line can optionally be activate-multi-line-match, if this is the
231+
case then each of the rules will be matched over multiple lines (so can contain)
232+
the new line symbol (\\n) inside them.
233+
<required patterns> one or more lines of regualar expressions that must occur in the output
234+
<disallowed patterns> one or more lines of expressions that must not occur in output
235+
<comment text> free form text
206236
207237
EOF
208238
exit 1;

0 commit comments

Comments
 (0)