-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread-tests.pl
More file actions
executable file
·81 lines (69 loc) · 2.17 KB
/
read-tests.pl
File metadata and controls
executable file
·81 lines (69 loc) · 2.17 KB
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
#! /usr/bin/perl -w
open(FOO, "ospfsmod.c") || die "Did you delete ospfsmod.c?";
$lines = 0;
$lines++ while defined($_ = <FOO>);
close FOO;
@tests = (
# read first byte of file
[ 'dd count=1 bs=1 if=./test/pokercats.gif 2>&-',
"G"
],
#read the first block of a file
[ 'dd ibs=1024 count=1 if=./test/test1block.txt 2>&-| md5sum',
"387820c7cfb039ffeff36b5ddafab2ee -"
],
#read half of the first block of a file
[ 'dd ibs=1024 bs=512 count=1 if=./test/test1block.txt 2>&-|md5sum ',
"afb2de5db24cc249daff0aa8a6614d7c -"
],
#read starting partway through the first block and into part of the next block
[ 'dd skip=2 bs=900 if=./base/test1block.txt 2>&- |md5sum',
"71b480f8a7729d42e4d026e32d89e5e0 -"
],
# read more than one block
[ 'dd ibs=1024 count=2 if=./test/test1block.txt 2>&-|md5sum',
'b1c6e475dad4172ffc6ddc8cd13d33bc -'
],
# try to read past the end of a file
[ 'dd skip=1 count=2 if=./test/hello.txt',
"dd: `./base/hello.txt': cannot skip to specified offset"
],
# need to fix
[ 'cat test/a',
'cat: test/a: No such file or directory'
],
);
my($ntest) = 0;
my(@wanttests);
foreach $i (@ARGV) {
$wanttests[$i] = 1 if (int($i) == $i && $i > 0 && $i <= @tests);
}
my($sh) = "bash";
my($tempfile) = "lab3test.txt";
my($ntestfailed) = 0;
my($ntestdone) = 0;
foreach $test (@tests) {
$ntest++;
next if (@wanttests && !$wanttests[$ntest]);
$ntestdone++;
print STDOUT "Running test $ntest\n";
my($in, $want) = @$test;
open(F, ">$tempfile") || die;
print F $in, "\n";
print STDERR " ", $in, "\n";
close(F);
$result = `$sh < $tempfile 2>&1`;
$result =~ s|\[\d+\]||g;
$result =~ s|^\s+||g;
$result =~ s|\s+| |g;
$result =~ s|\s+$||;
next if $result eq $want;
next if $want eq 'Syntax error [NULL]' && $result eq '[NULL]';
next if $result eq $want;
print STDERR "Test $ntest FAILED!\n input was \"$in\"\n expected output like \"$want\"\n got \"$result\"\n";
$ntestfailed += 1;
}
unlink($tempfile);
my($ntestpassed) = $ntestdone - $ntestfailed;
print "$ntestpassed of $ntestdone tests passed\n";
exit(0);