1
0

grader.pl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #!/usr/local/bin/perl
  2. use strict;
  3. use Cwd;
  4. my $MAX_SCORE;
  5. my $PPT;
  6. my $NUM_TC;
  7. #my $NUM_Prob;
  8. #my $GTYPE;
  9. my @list;
  10. my $dir;
  11. my $totalScore;
  12. my @score;
  13. my $SPT; # score per thread
  14. my @tcscore;
  15. my $prefscore;
  16. my $fail_info;
  17. my $line;
  18. my $isMemTestSuccess;
  19. my $isMaTestSuccess;
  20. my $i;
  21. my $j;
  22. my $base = 0;
  23. my $time_margin = 1.5;
  24. # Set maximum possible scores
  25. $MAX_SCORE = $ARGV[0];
  26. # Finds number of testcase to be run and calculates number of
  27. # points per testcase
  28. #@list = `ls expected/expected*`;
  29. $NUM_TC = $ARGV[2];
  30. #$NUM_Prob = $#ARGV - 1;
  31. if($ARGV[1] == 1){
  32. $PPT = (0.95 * $MAX_SCORE) / $NUM_TC;
  33. }
  34. elsif($ARGV[1] == 2){
  35. $PPT = $MAX_SCORE / $NUM_TC;
  36. }
  37. #correct directory path
  38. #$dir = quotemeta($_);
  39. #Run executable and tests in testing directory
  40. print "GRADING RESULTS\n";
  41. print "\nChecking Correctness.\n";
  42. my @host = `hostname`;
  43. my @currline;
  44. my @numthreads = (3,3,3,4,5,6,7,8,9,4, 1,2,3,4,5,6,7,8,9,10, 4,4,4,4,5,6,7);
  45. #my @PPT_ARRAY = (.2, .2, .2, .2, .2, .2, .2, .2, .5, .3, .3, .3,.4,.3,.3);
  46. #initalize score
  47. for($i = 0; $i < $NUM_TC; $i++) {
  48. $score[$i] = 0;
  49. }
  50. $totalScore = 0;
  51. if($ARGV[1] == 1){
  52. for($i = $NUM_TC; $i <= $NUM_TC+1; $i++) {
  53. if((system("make corrtest$i") == 512)) {
  54. #print "make corrtest$i passes\n";
  55. $score[$i] = 0.025 * $MAX_SCORE;
  56. } else {
  57. $fail_info = `make corrtest$i 2>&1`;
  58. print "corrtest$i fails\n";
  59. print "$fail_info\n\n";
  60. }
  61. }
  62. }
  63. print "Running $NUM_TC tests\n";
  64. for($i = 0; $i < $NUM_TC; $i++) {
  65. if(system("make corrtest$i") == 0) {
  66. print "Correctness Test $i passes\n";
  67. #$score[$i] = $PPT_ARRAY[$i];
  68. $PPT = $MAX_SCORE / $NUM_TC;
  69. $score[$i] = $PPT;
  70. $isMemTestSuccess = 0;
  71. $isMaTestSuccess = 0;
  72. if(-e "memoutput$i"){
  73. open(MEM, "<memoutput$i");
  74. while ($line = <MEM>) {
  75. if ($line =~ m/All heap blocks were freed -- no leaks are possible/){
  76. #print "memory management test passes\n";
  77. $isMemTestSuccess = 1;
  78. }
  79. elsif ($line =~ m/ERROR SUMMARY: 0 errors from 0 contexts/){
  80. #print "memory access test passes\n";
  81. $isMaTestSuccess = 1;
  82. }
  83. }
  84. close(MEM);
  85. if ($isMemTestSuccess == 0) {
  86. print "memory management test $i fails\n";
  87. #$score[$i] = $score[$i] - ($PPT_ARRAY[$i]/2);
  88. $score[$i] = $score[$i] - ($PPT/2);
  89. }
  90. if ($isMaTestSuccess == 0) {
  91. print "memory access test $i fails. Check memoutput$i to see whtat the errors are\n";
  92. #$score[$i] = $score[$i] - ($PPT/2);
  93. }
  94. }
  95. if($host[0] =~ m/quatro/){
  96. if(system("make perftest$i") == 0) {
  97. $prefscore = 0;
  98. my $missedcount = 0;
  99. #$PPT = $score[$i] / $numthreads[$i];
  100. $SPT = $score[$i] / $numthreads[$i];
  101. if(-e "outputs/timeinfo$i"){
  102. my @stutimes;
  103. my @exptimes;
  104. open(TIMEINFO, "<outputs/timeinfo$i");
  105. while ($line = <TIMEINFO>) {
  106. if ($line =~ m/run/){
  107. @currline = split(" ", $line);
  108. push(@stutimes, $currline[4]);
  109. }
  110. }
  111. close(TIMEINFO);
  112. open(EXPECTED, "<expected/exptime$i");
  113. while ($line = <EXPECTED>) {
  114. if ($line =~ m/run/){
  115. @currline = split(" ", $line);
  116. push(@exptimes, $currline[4]);
  117. }
  118. }
  119. close(EXPECTED);
  120. for($j = 0; $j < scalar(@stutimes); $j++){
  121. if($stutimes[$j] > $time_margin * $exptimes[$j]){
  122. $missedcount++;
  123. $tcscore[$j] = (($time_margin * $exptimes[$j]) / $stutimes[$j]) * $SPT;
  124. }
  125. else{
  126. $tcscore[$j] = $SPT;
  127. }
  128. }
  129. }
  130. for($j = 0; $j < $numthreads[$i]; $j++){
  131. $prefscore += $tcscore[$j];
  132. }
  133. if($missedcount > 3){
  134. $score[$i] = $prefscore;
  135. print "missedcount is $missedcount\n";
  136. print "One or more threads runs longer than the allowed maximum\n";
  137. }
  138. else{
  139. print "Performance test $i passes\n";
  140. }
  141. } else {
  142. $fail_info = `make perftest$i 2>&1`;
  143. print "perftest$i fails\n";
  144. print "$fail_info\n";
  145. }
  146. }
  147. else{
  148. print "Performance test needs to be run on quatro01 or quatro02\n";
  149. }
  150. } else {
  151. $fail_info = `make corrtest$i 2>&1`;
  152. print "corrtest$i fails\n";
  153. print "$fail_info\n";
  154. }
  155. }
  156. for ($i = 0; $i < $NUM_TC; $i++) {
  157. $totalScore = $totalScore + $score[$i];
  158. }
  159. if($host[0] =~ m/quatro/){
  160. }
  161. else{
  162. $totalScore = 0;
  163. }
  164. #print student's score on screen
  165. printf("\n\nTOTAL SCORE = %.2f/%.2f\n", $totalScore, $MAX_SCORE);
  166. print "\nYour Program will be manually graded for styling and implementation correctness\n";
  167. print "This manual grading can have affect on your final grade\n";
  168. print "DONE\n\n";