3 # Verifies that the contents of a given file produced by producer.pl with the given
13 print "Usage: ./verifier.pl <-seed seed> <-file fname> : Verifies that file fname,\n";
14 print " : produced with the given \n";
15 print " : seed matches\n";
21 my $MAX_SIZE = 2147483648;
28 $num = rand $MAX_SIZE;
29 my $tmpstr = sprintf("%d", $num);
31 $len += length $tmpstr;
40 my ($cmdfh, $outfh, $filename) = @_;
43 # Allocate the read buffer
44 my $cmd = '$buf = ALLOC 1024'."\n";
45 helper::send_cmd($cmdfh, $outfh, "alloc", $cmd);
48 $cmd = '$fd = CALL open '."$filename O_RDONLY\n";
49 helper::send_cmd($cmdfh, $outfh, "open", $cmd);
51 # Verify the system call's output
52 helper::verify_cmd($cmdfh, $outfh, "open");
57 # Read all of the file in 1024 byte chunks
61 $cmd = 'CALL clear $buf'."\n";
62 helper::send_cmd($cmdfh, $outfh, "clear", $cmd);
64 my ($len, $buf) = get_buf;
66 $cmd = 'CALL read $fd $buf '."$len\n";
67 helper::send_cmd($cmdfh, $outfh, "read", $cmd);
68 $bytes = helper::verify_cmd($cmdfh, $outfh, "read");
73 # Print out the buffer
74 $cmd = 'PRINT $buf 0 1 STR'."\n";
75 helper::send_cmd($cmdfh, $outfh, "print", $cmd);
79 $str = substr($str, 0, $len-1);
80 } elsif ($len > $bytes) {
81 $buf = substr($buf, 0, $bytes);
84 my $errstr = "ERROR! Str $str is not equal to str $buf\n";
85 helper::print_and_exit($cmdfh, $outfh, 1, $errstr);
94 my ($filename, $is_alpha) = @_;
98 open2(\*OUTFILE, \*CMDFILE, "./test_driver --np");
100 open2(\*OUTFILE, \*CMDFILE,
101 "yod -batch -quiet -sz 1 ./test_driver --np");
106 if ($@ =~ /^open2/) {
107 warn "open2 failed: $!\n$@\n";
114 my $outfh = \*OUTFILE;
115 my $cmdfh = \*CMDFILE;
117 if ($is_alpha == 0) {
118 helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
122 check_file($cmdfh, $outfh, $filename);
125 my $cmd = 'CALL close $fd'."\n";
126 helper::send_cmd($cmdfh, $outfh, "close", $cmd);
128 helper::verify_cmd($cmdfh, $outfh, "close");
131 helper::print_and_exit($cmdfh, $outfh, 0, "File $filename valid\n");
137 my $filename = "randfile.$seed.$$";
139 for (my $i = 0; $i < @ARGV; $i++)
141 if ($ARGV[$i] eq "-file") {
143 $filename = $ARGV[$i];
144 } elsif ($ARGV[$i] eq "-seed") {
147 } elsif ($ARGV[$i] eq "-alpha") {
152 # seed the randome number generator
155 verify_file($filename, $is_alpha);