X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=grading%2Fthreads%2Frun-tests;h=bd705e43b2da871acc5e51a3a5d034e8e9bcd646;hb=59385cfe7f0fc5a66dfc1da7c2e5b817edbcae65;hp=f40e0d814a0a3d80181f311070d8c7dc61b695ac;hpb=d23698a4667868796409d15c94cf5d3e509480c5;p=pintos-anon diff --git a/grading/threads/run-tests b/grading/threads/run-tests index f40e0d8..bd705e4 100755 --- a/grading/threads/run-tests +++ b/grading/threads/run-tests @@ -1,94 +1,108 @@ -#! /usr/bin/perl -w +#! /usr/bin/perl -use POSIX; -use Text::Diff; +# Find the directory that contains the grading files. +our ($GRADES_DIR); -$verbose = 0; -($GRADES_DIR = $0) =~ s#/[^/]+$##; --d $GRADES_DIR or die "$GRADES_DIR: stat: $!\n"; +# Add our Perl library directory to the include path. +BEGIN { + ($GRADES_DIR = $0) =~ s#/[^/]+$##; + -d $GRADES_DIR or die "$GRADES_DIR: stat: $!\n"; + unshift @INC, "$GRADES_DIR/../lib"; +} --d ("output") || mkdir ("output") or die "output: mkdir: $!\n"; +use warnings; +use strict; +use Pintos::Grading; -if (! -d "pintos") { - my (@tarballs) - = grep (/^[a-z0-9]+\.[A-Za-z]+\.\d+\.\d+\.\d+\.\d+.\d+\.tar\.gz$/, - glob ("*.tar.gz")); - die "no pintos dir and no source tarball\n" if scalar (@tarballs) == 0; +our ($hw) = "threads"; +our (@TESTS); # Tests to run. +our ($test); +our (%details); +our (%result); +our ($action); - # Sort tarballs in reverse order by time. - @tarballs = sort { ext_mdyHMS ($b) cmp ext_mdyHMS ($a) } @tarballs; - - die "no pintos dir and multiple tarballs\n" if scalar (@tarballs) > 1; - mkdir "pintos" or die "pintos: mkdir: $!\n"; - mkdir "pintos/src" or die "pintos: mkdir: $!\n"; - - print "Extracting $tarballs[0]...\n"; - xsystem ("", "cd pintos/src && tar xzf ../../$tarballs[0]") - or die "extraction failed\n"; - - print "Patching...\n"; - xsystem ("panic.diff", - "patch -fs pintos/src/lib/debug.c < $GRADES_DIR/panic.diff") - or die "patch failed\n"; -} --d "pintos/src/threads" or die "pintos/src/threads: stat: $!\n"; - -sub ext_mdyHMS { - my ($s) = $_; - my ($ms, $d, $y, $H, $M, $S) = - $s =~ /.([A-Za-z]+)\.(\d+)\.(\d+)\.(\d+)\.(\d+).(\d+)\.tar\.gz$/ - or die; - my ($m) = index ("janfebmaraprmayjunjulaugsepoctnovdec", lc $ms) / 3 - or die; - return sprintf "%02d-%02d-%02d %02d:%02d:%02d", $m, $d, $y, $H, $M, $S; -} +parse_cmd_line qw (alarm-single alarm-multiple alarm-zero alarm-negative + priority-preempt priority-fifo priority-donate-one + priority-donate-multiple priority-donate-nest + mlfqs-on mlfqs-off); -@TESTS = ("alarm-single", "alarm-multiple", "alarm-zero", "alarm-negative", - "join-simple", - "join-quick", "join-multiple", "join-nested", - "join-dummy", "join-invalid", "join-no", - "priority-preempt", "priority-fifo", "priority-donate-one", - "priority-donate-multiple", "priority-donate-nest", - "mlfqs-on", "mlfqs-off"); - -for $test (@TESTS) { - my ($result); - do { - print "$test: "; - $result = run_test ($test); - if ($result eq 'ok') { - $result = grade_test ($test); - $result =~ s/\n$//; - } - print "$result\n"; - } while ($result eq 'rerun'); - - $result{$test} = $result; +clean_dir (), exit if $action eq 'clean'; + +extract_sources (); +exit if $action eq 'extract'; + +build (); +exit if $action eq 'build'; + +run_and_grade_tests (); +if (defined ($result{'mlfqs-on'}) && defined ($result{'mlfqs-off'})) { + grade_mlfqs_speedup (); + grade_mlfqs_priority (); } +write_grades (); +write_details (); +exit success () if $action eq 'test'; -make_summary (); +assemble_final_grade (); +exit success () if $action eq 'assemble'; -sub grade_test { - my ($test) = @_; +die "Don't know how to '$action'"; - my (@output) = snarf ("output/$test.run.out"); +# Runs $test in directory output/$test. +# Returns 'ok' if it went ok, otherwise an explanation. +sub run_test { + # Changes devices/timer.c if necessary. + my ($new_time_slice) = $test eq 'priority-fifo' ? 100 : 1; + my (@timer_c) = snarf ("pintos/src/devices/timer.c"); + if (!grep (/^\#define TIME_SLICE $new_time_slice$/, @timer_c)) { + @timer_c = grep (!/^\#define TIME_SLICE/, @timer_c); + unshift (@timer_c, "#define TIME_SLICE $new_time_slice"); + open (TIMER_C, ">pintos/src/devices/timer.c"); + print TIMER_C map ("$_\n", @timer_c); + close (TIMER_C); + } - if (-e "$GRADES_DIR/$test.exp") { - eval { - verify_common (@output); - compare_output ("$GRADES_DIR/$test.exp", @output); - } - } else { - ($grade_func = $test) =~ s/-/_/g; - eval "grade_$grade_func(\@output)"; + # Changes devices/timer.h if necessary. + my ($new_timer_freq) = $test eq 'priority-fifo' ? 19 : 100; + my (@timer_h) = snarf ("pintos/src/devices/timer.h"); + if (!grep (/^\#define TIMER_FREQ $new_time_slice$/, @timer_h)) { + @timer_h = grep (!/^\#define TIMER_FREQ/, @timer_h); + unshift (@timer_h, "#define TIMER_FREQ $new_timer_freq"); + open (TIMER_H, ">pintos/src/devices/timer.h"); + print TIMER_H map ("$_\n", @timer_h); + close (TIMER_H); } - if ($@) { - die $@ if $@ =~ /at \S+ line \d+$/; - return $@; + + # Copy in the new test.c and delete enough files to ensure a full rebuild. + my ($src) = "$GRADES_DIR/" . ($test !~ /^mlfqs/ ? "$test.c" : "mlfqs.c"); + -e $src or die "$src: stat: $!\n"; + xsystem ("cp $src pintos/src/threads/test.c", DIE => "cp failed\n"); + unlink ("pintos/src/threads/build/threads/test.o"); + unlink ("pintos/src/threads/build/kernel.o"); + unlink ("pintos/src/threads/build/kernel.bin"); + unlink ("pintos/src/threads/build/os.dsk"); + + # Build. + if (xsystem ("cd pintos/src/threads && make", + LOG => "$test/make") ne 'ok') { + $details{$test} = snarf ("output/$test/make.err"); + return "Compile error"; } - return "ok"; -} + # Copy out files for backtraces later. + xsystem ("cp pintos/src/threads/build/kernel.o output/$test"); + xsystem ("cp pintos/src/threads/build/os.dsk output/$test"); + + # Run. + my ($timeout) = $test !~ /^mlfqs/ ? 15 : 600; + my (@command) = ("-v", "run", "-q"); + push (@command, "-o mlfqs") if $test eq 'mlfqs-on'; + return run_pintos (\@command, + CHDIR => "pintos/src/threads/build", + LOG => "$test/run", + TIMEOUT => $timeout); +} + sub grade_alarm_single { verify_alarm (1, @_); } @@ -97,64 +111,44 @@ sub grade_alarm_multiple { verify_alarm (7, @_); } -sub grade_alarm_zero { - my (@output) = @_; - verify_common (@output); - die "Crashed in timer_sleep()\n" if !grep (/^Success\.$/, @output); -} +sub verify_alarm { + my ($iterations, @output) = @_; -sub grade_alarm_negative { - my (@output) = @_; verify_common (@output); - die "Crashed in timer_sleep()\n" if !grep (/^Success\.$/, @output); -} -sub grade_join_invalid { - my (@output) = @_; - verify_common (@output); - grep (/Testing invalid join/, @output) or die "Test didn't start\n"; - grep (/Invalid join test done/, @output) or die "Test didn't complete\n"; + my (@products); + for (my ($i) = 0; $i < $iterations; $i++) { + for (my ($t) = 0; $t < 5; $t++) { + push (@products, ($i + 1) * ($t + 1) * 10); + } + } + @products = sort {$a <=> $b} @products; + + local ($_); + foreach (@output) { + die $_ if /out of order/i; + + my ($p) = /product=(\d+)$/; + next if !defined $p; + + my ($q) = shift (@products); + die "Too many wakeups.\n" if !defined $q; + die "Out of order wakeups ($p vs. $q).\n" if $p != $q; # FIXME + } + die scalar (@products) . " fewer wakeups than expected.\n" + if @products != 0; } -sub grade_join_no { +sub grade_alarm_zero { my (@output) = @_; verify_common (@output); - grep (/Testing no join/, @output) or die "Test didn't start\n"; - grep (/No join test done/, @output) or die "Test didn't complete\n"; + die "Crashed in timer_sleep()\n" if !grep (/^Success\.$/, @output); } -sub grade_join_multiple { +sub grade_alarm_negative { my (@output) = @_; - verify_common (@output); - my (@t); - $t[4] = $t[5] = $t[6] = -1; - for $_ (@output) { - my ($idx) = /^Thread (\d+)/ or next; - my ($iter) = /iteration (\d+)$/; - $iter = 5 if /done!$/; - die "Malformed output\n" if !defined $iter; - if ($idx == 6) { - die "Thread 6 started before either other thread finished\n" - if $t[4] < 5 && $t[5] < 5; - die "Thread 6 started before thread 4 finished\n" - if $t[4] < 5; - die "Thread 6 started before thread 5 finished\n" - if $t[5] < 5; - } - die "Thread $idx out of order output\n" if $t[$idx] != $iter - 1; - $t[$idx] = $iter; - } - - my ($err) = ""; - for my $idx (4, 5, 6) { - if ($t[$idx] == -1) { - $err .= "Thread $idx did not run at all\n"; - } elsif ($t[$idx] != 5) { - $err .= "Thread $idx only completed $t[$idx] iterations\n"; - } - } - die $err if $err ne ''; + die "Crashed in timer_sleep()\n" if !grep (/^Success\.$/, @output); } sub grade_priority_fifo { @@ -165,7 +159,8 @@ sub grade_priority_fifo { my ($iter_cnt) = 5; my (@order); my (@t) = (-1) x $thread_cnt; - for $_ (@output) { + local ($_); + foreach (@output) { my ($idx) = /^Thread (\d+)/ or next; my ($iter) = /iteration (\d+)$/; $iter = $iter_cnt if /done!$/; @@ -198,377 +193,96 @@ sub grade_priority_fifo { sub grade_mlfqs_on { my (@output) = @_; verify_common (@output); - mlfqs_stats (@output); + our (@mlfqs_on_stats) = mlfqs_stats (@output); } sub grade_mlfqs_off { my (@output) = @_; verify_common (@output); - mlfqs_stats (@output); + our (@mlfqs_off_stats) = mlfqs_stats (@output); } -sub mlfqs_stats { - my (@output) = @_; - my (%stats) = ("io" => {}, "cpu" => {}, "mix" => {}); - my (%map) = ("CPU intensive" => "cpu", - "IO intensive" => "io", - "Alternating IO/CPU" => "mix"); - for $_ (@output) { - my ($thread, $pri) = /^([A-Za-z\/ ]+): (\d+)$/ or next; - my ($t) = $map{$thread} or next; - - my ($s) = $stats{$t}; - $$s{"n"}++; - $$s{"sum"} += $pri; - $$s{"sum2"} += $pri * $pri; - $$s{"min"} = $pri if !defined ($$s{"min"}) || $pri < $$s{"min"}; - $$s{"max"} = $pri if !defined ($$s{"max"}) || $pri > $$s{"max"}; - } - for my $t (keys %stats) { - my ($s) = $stats{$t}; - print "$t: n=$$s{'n'}, min=$$s{'min'}, max=$$s{'max'}, avg=", int ($$s{'sum'} / $$s{'n'}), "\n"; - } -} - -sub get_binaries { - if (!files_equal ("pintos/src/threads/test.c", test_source ($test)) - || !file_contains ("pintos/src/constants.h", - test_constants ($test))) { - unlink ("output/$test.run.out") - or die "output/$test.run.out: unlink: $!\n"; - die "rerun\n"; - } -} - -sub verify_common { - my (@output) = @_; - - my (@assertion) = grep (/PANIC/, @output); - if (@assertion != 0) { - my ($details) = "Kernel panic:\n $assertion[0]\n"; - - my (@stack_line) = grep (/Call stack:/, @output); - if (@stack_line != 0) { - get_binaries (); - $details .= " $stack_line[0]\n\n"; - $details .= "Translation of backtrace:\n"; - my ($addrs) = $stack_line[0] =~ /Call stack:((?: 0x[0-9a-f]+)+)/; - - my ($A2L); - if (`uname -m` - =~ /i.86|pentium.*|[pk][56]|nexgen|viac3|6x86|athlon.*/) { - $A2L = "addr2line"; - } else { - $A2L = "i386-elf-addr2line"; - } - open (A2L, "$A2L -fe pintos/src/threads/build/kernel.o $addrs|"); - while ($function = ) { - $line = ; - chomp $function; - chomp $line; - $details .= " $function ($line)\n"; - } - } - $extra{$test} = $details; - die "Kernel panic. Details at end of file.\n" - } - - die "No output at all\n" if @output == 0; - die "Didn't start up properly: no \"Pintos booting\" startup message\n" - if !grep (/Pintos booting with.*kB RAM\.\.\./, @output); - die "Didn't start up properly: no \"Boot complete\" startup message\n" - if !grep (/Boot complete/, @output); - die "Didn't shut down properly: no \"Timer: # ticks\" shutdown message\n" - if !grep (/Timer: \d+ ticks/, @output); - die "Didn't shut down properly: no \"Powering off\" shutdown message\n" - if !grep (/Powering off/, @output); -} - -sub compare_output { - my ($exp_file, @actual) = @_; - my (@expected) = snarf ($exp_file); - - @actual = map ("$_\n", @actual); - @expected = map ("$_\n", @expected); - - # Trim header and trailer from @actual. - while (scalar (@actual) && $actual[0] ne $expected[0]) { - shift (@actual); - } - die "First line of expected output was not present.\n" if !@actual; - while (scalar (@actual) && $actual[$#actual] ne $expected[$#expected]) { - pop (@actual); - } - die "Final line of expected output was not present.\n" if !@actual; - - # Check whether they're the same. - if ($#actual == $#expected) { - my ($eq) = 1; - for (my ($i) = 0; $i <= $#expected; $i++) { - $eq = 0 if $actual[$i] ne $expected[$i]; - } - return if $eq; - } - - # They differ. Output a diff. - my ($diff) = ""; - my ($d) = Algorithm::Diff->new (\@expected, \@actual); - $d->Base (1); - while ($d->Next ()) { - my ($ef, $el, $af, $al) = $d->Get (qw (min1 max1 min2 max2)); - if ($d->Same ()) { - if ($af != $al) { - $diff .= "Actual lines $af...$al match expected lines " - . "$ef...$el.\n"; - } else { - $diff .= "Actual line $af matches expected line $ef.\n"; - } - } else { - my (@i1) = $d->Items (1); - my (@i2) = $d->Items (2); - if (!@i1) { - $diff .= "Extra or misplaced line(s) $af...$al " - . "in actual output:\n"; - $diff .= number_lines ($af, \@i2); - } elsif (!$d->Items (2)) { - $diff .= "Expected line(s) $ef...$el missing or misplaced:\n"; - $diff .= number_lines ($ef, \@i1); - } else { - $diff .= "The following expected line(s) $ef...$el:\n"; - $diff .= number_lines ($ef, \@i1); - $diff .= "became actual line(s) $af...$al:\n"; - $diff .= number_lines ($af, \@i2); - } - } - } - - my ($details) = ""; - $details .= "$test actual output (line numbers added):\n"; - $details .= number_lines (1, \@actual); - $details .= "\n$test expected output (line numbers added):\n"; - $details .= number_lines (1, \@expected); - $details .= "\n$diff\n"; - $details{$test} = $details; - die "Output differs from expected. Details at end of file.\n"; -} - -sub verify_alarm { - my ($iterations, @output) = @_; - - verify_common (@output); - - my (@products); - for (my ($i) = 0; $i < $iterations; $i++) { - for (my ($t) = 0; $t < 5; $t++) { - push (@products, ($i + 1) * ($t + 1) * 10); - } - } - @products = sort {$a <=> $b} @products; - - for $_ (@output) { - die $_ if /Out of order/; - - my ($p) = /product=(\d+)$/; - next if !defined $p; - - my ($q) = shift (@products); - die "Too many wakeups.\n" if !defined $q; - die "Out of order wakeups ($p vs. $q).\n" if $p != $q; # FIXME - } - die scalar (@products) . " fewer wakeups than expected.\n" - if @products != 0; -} - -sub test_source { - my ($test) = @_; - my ($src) = "$GRADES_DIR/$test.c"; - $src = "$GRADES_DIR/mlfqs.c" if $test =~ /^mlfqs/; - -e $src or die "$src: stat: $!\n"; - return $src; -} - -sub test_constants { - my ($defines) = ""; - $defines .= "#define MLFQS 1\n" if $test eq 'mlfqs-on'; - return $defines; - } - -sub run_test { - my ($test) = @_; - return "ok" if -f "output/$test.run.out"; - - my ($defines) = test_constants ($test); - if ($defines ne snarf ("pintos/src/constants.h")) { - open (CONSTANTS, ">pintos/src/constants.h"); - print CONSTANTS $defines; - close (CONSTANTS); - } - - $src = test_source ($test); - xsystem ("", "cp $src pintos/src/threads/test.c") or die; - unlink ("pintos/src/threads/build/threads/test.o"); - unlink ("pintos/src/threads/build/kernel.o"); - unlink ("pintos/src/threads/build/kernel.bin"); - unlink ("pintos/src/threads/build/os.dsk"); - xsystem ("$test.make", "cd pintos/src/threads && make") - or return "compile error"; - - my ($timeout) = 10; - $timeout = 600 if $test =~ /^mlfqs/; - xsystem ("$test.run", "cd pintos/src/threads/build && pintos -v run -q", - $timeout) - or return "Bochs error"; - return "ok"; -} - -sub xsystem { - my ($log, $command, $timeout) = @_; - print "$command\n" if $verbose; - - $timeout = 0 if !defined $timeout; - - my ($status); - if ($log ne '') { - $status = systimeout ("($command) >output/$log.out 2>output/$log.err", - $timeout); - unlink ("output/$log.err") unless $status != 0; - } else { - $status = systimeout ($command, $timeout); - } - - die "Interrupted\n" - if WIFSIGNALED ($status) && WTERMSIG ($status) == SIGINT; - - return $status == 0; +sub grade_mlfqs_speedup { + our (@mlfqs_off_stats); + our (@mlfqs_on_stats); + eval { + check_mlfqs (); + my ($off_ticks) = $mlfqs_off_stats[1]; + my ($on_ticks) = $mlfqs_on_stats[1]; + die "$off_ticks ticks without MLFQS, $on_ticks with MLFQS\n" + if $on_ticks >= $off_ticks; + die "ok\n"; + }; + chomp $@; + $result{'mlfqs-speedup'} = $@; } -sub systimeout { - my ($command, $timeout) = @_; - my ($pid, $status); +sub grade_mlfqs_priority { + our (@mlfqs_off_stats); + our (@mlfqs_on_stats); eval { - local $SIG{ALRM} = sub { die "alarm\n" }; - alarm $timeout; - $pid = fork; - die "fork: $!\n" if !defined $pid; - exec ($command), die "$command: exec: $!\n" if !$pid; - waitpid ($pid, 0); - $status = $?; - alarm 0; + check_mlfqs () if !defined (@mlfqs_on_stats); + for my $cat qw (CPU IO MIX) { + die "Priority changed away from PRI_DEFAULT (29) without MLFQS\n" + if $mlfqs_off_stats[0]{$cat}{MIN} != 29 + || $mlfqs_off_stats[0]{$cat}{MAX} != 29; + die "Minimum priority never changed from PRI_DEFAULT (29) " + . "with MLFQS\n" + if $mlfqs_on_stats[0]{$cat}{MIN} == 29; + die "Maximum priority never changed from PRI_DEFAULT (29) " + . "with MLFQS\n" + if $mlfqs_on_stats[0]{$cat}{MAX} == 29; + } + die "ok\n"; }; - if ($@) { - die unless $@ eq "alarm\n"; # propagate unexpected errors - print "Timed out.\n"; - kill SIGTERM, $pid; - $status = 0; - } - return $status; + chomp $@; + $result{'mlfqs-priority'} = $@; } -sub snarf { - my ($file) = @_; - open (OUTPUT, $file) or die "$file: open: $!\n"; - my (@lines) = ; - chomp (@lines); - close (OUTPUT); - return wantarray ? @lines : join ('', map ("$_\n", @lines)); +sub check_mlfqs { + our (@mlfqs_off_stats); + our (@mlfqs_on_stats); + die "p1-4 didn't finish with MLFQS on or off\n" + if !defined (@mlfqs_off_stats) && !defined (@mlfqs_on_stats); + die "p1-4 didn't finish with MLFQS on\n" + if !defined (@mlfqs_on_stats); + die "p1-4 didn't finish with MLFQS off\n" + if !defined (@mlfqs_off_stats); } -sub make_summary { - @summary = snarf ("$GRADES_DIR/tests.txt"); - - my ($ploss) = 0; - my ($tloss) = 0; - my ($total) = 0; - for (my ($i) = 0; $i <= $#summary; $i++) { - $_ = $summary[$i]; - if (my ($loss, $test) = /^ -(\d+) ([-a-zA-Z0-9]+):/) { - my ($result) = $result{$test} or die "missing results for $test\n"; - - if ($result eq 'ok') { - splice (@summary, $i, 1); - $i--; - } else { - $ploss += $loss; - $tloss += $loss; - splice (@summary, $i + 1, 0, - map (" $_", split ("\n", $result))); - } - } elsif (my ($ptotal) = /^Score: \/(\d+)$/) { - $total += $ptotal; - $summary[$i] = "Score: " . ($ptotal - $ploss) . "/$ptotal"; - splice (@summary, $i, 0, " All tests passed.") if $ploss == 0; - $ploss = 0; - $i++; - } - } - my ($ts) = "(" . ($total - $tloss) . "/" . $total . ")"; - $summary[0] =~ s/\[\[total\]\]/$ts/; - - open (SUMMARY, ">tests.out"); - print SUMMARY map ("$_\n", @summary); - close (SUMMARY); - - open (DETAILS, ">details.out"); - my ($n) = 0; - for my $test (@TESTS) { - next if $result{$test} eq 'ok'; +sub mlfqs_stats { + my (@output) = @_; + my (%stats) = (CPU => {}, IO => {}, MIX => {}); + my (%map) = ("CPU intensive" => 'CPU', + "IO intensive" => 'IO', + "Alternating IO/CPU" => 'MIX'); + my (%rmap) = reverse %map; + my ($ticks); + local ($_); + foreach (@output) { + $ticks = $1 if /Timer: (\d+) ticks/; + my ($thread, $pri) = /^([A-Za-z\/ ]+): (\d+)$/ or next; + my ($t) = $map{$thread} or next; - my ($details) = $details{$test}; - next if !defined ($details) && ! -e "output/$test.run.out"; - - print DETAILS "\n" if $n++; - print DETAILS "--- $test details ", '-' x (50 - length ($test)); - print DETAILS "\n\n"; - - if (!defined $details) { - $details = "Output:\n\n" . snarf ("output/$test.run.out"); - } - print DETAILS $details; - - print DETAILS "\n", "-" x 10, "\n\n$extra{$test}" - if defined $extra{$test}; + my ($s) = $stats{$t}; + $$s{N}++; + $$s{SUM} += $pri; + $$s{SUM2} += $pri * $pri; + $$s{MIN} = $pri if !defined ($$s{MIN}) || $pri < $$s{MIN}; + $$s{MAX} = $pri if !defined ($$s{MAX}) || $pri > $$s{MAX}; } - close (DETAILS); - -} -sub files_equal { - my ($a, $b) = @_; - my ($equal); - open (A, "<$a") or die "$a: open: $!\n"; - open (B, "<$b") or die "$b: open: $!\n"; - if (-s A != -s B) { - $equal = 0; - } else { - my ($sa, $sb); - for (;;) { - sysread (A, $sa, 1024); - sysread (B, $sb, 1024); - $equal = 0, last if $sa ne $sb; - $equal = 1, last if $sa eq ''; - } + my (%expect_n) = (CPU => 5000, IO => 1000, MIX => 12000); + for my $cat (values (%map)) { + my ($s) = $stats{$cat}; + die "$rmap{$cat} printed $$s{N} times, not $expect_n{$cat}\n" + if $$s{N} != $expect_n{$cat}; + die "$rmap{$cat} priority dropped to $$s{MIN}, below PRI_MIN (0)\n" + if $$s{MIN} < 0; + die "$rmap{$cat} priority rose to $$s{MAX}, above PRI_MAX (59)\n" + if $$s{MAX} > 59; + $$s{MEAN} = $$s{SUM} / $$s{N}; } - close (A); - close (B); - return $equal; -} -sub file_contains { - my ($file, $expected) = @_; - open (FILE, "<$file") or die "$file: open: $!\n"; - my ($actual); - sysread (FILE, $actual, -s FILE); - my ($equal) = $actual eq $expected; - close (FILE); - return $equal; -} - -sub number_lines { - my ($ln, $lines) = @_; - my ($out); - for my $line (@$lines) { - chomp $line; - $out .= sprintf "%4d %s\n", $ln++, $line; - } - return $out; + return (\%stats, $ticks); }