1
0

grader.pl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 @list;
  9. my $dir;
  10. my $totalScore;
  11. my @score;
  12. my @scoreEachProb;
  13. my $fail_info;
  14. my $line;
  15. my $isMemTestSuccess;
  16. my $isMaTestSuccess;
  17. my $i;
  18. my $j;
  19. my $base = 0;
  20. my @temp;
  21. # PA09
  22. my @heap;
  23. my @unnecessaryByte;
  24. # Set standard heap usage values in PA09 for test0 ~ test100
  25. @heap = (1136, 1160, 2296, 2320, 2320, 2368, 2368, 2368, 2440, 2392, 2416, 2464, 2512, 2488, 2488, 2536, 2488, 2536, 2560, 2632, 2680, 2656, 2632, 2656, 2680, 2608, 2752, 2680, 2728, 2776, 2800, 2848, 2728, 2776, 2848, 2824, 2824, 2944, 2920, 2920, 2992, 2920, 2848, 2992, 2968, 3064, 3064, 3040, 2968, 3112, 3088, 2992, 3136, 3088, 3160, 3160, 3208, 3136, 3208, 3184, 3208, 3280, 3328, 3304, 3352, 3352, 3376, 3328, 3328, 3376, 3448, 3496, 3448, 3520, 3496, 3520, 3544, 3568, 3472, 3568, 3760, 3616, 3640, 3544, 3640, 3736, 3592, 3736, 3640, 3832, 3952, 3760, 3616, 3736, 3712, 3736, 3880, 3832, 3856, 3832, 3880);
  26. # Set maximum possible scores
  27. $MAX_SCORE = $ARGV[0];
  28. # Finds number of testcase to be run and calculates number of
  29. # points per testcase
  30. @list = `ls inputs/input*`;
  31. $NUM_TC = scalar(@list);
  32. $NUM_Prob = $#ARGV - 2;
  33. if($ARGV[1] == 1){
  34. $PPT = (0.95 * $MAX_SCORE) / $NUM_TC;
  35. }
  36. elsif($ARGV[1] == 2){
  37. $PPT = $MAX_SCORE / $NUM_TC;
  38. }
  39. print "GRADING RESULTS\n";
  40. #correct directory path
  41. #$dir = quotemeta($_);
  42. #Run executable and tests in testing directory
  43. #initalize score
  44. for($i = 0; $i < $NUM_TC; $i++) {
  45. $score[$i] = 0;
  46. }
  47. for($i = 0; $i < $NUM_Prob; $i++) {
  48. $scoreEachProb[$i] = 0;
  49. }
  50. $totalScore = 0;
  51. if($ARGV[1] == 1){
  52. for($i = $NUM_TC-1; $i <= $NUM_TC+1; $i++) {
  53. if((system("make test$i") == 512)) {
  54. print "test$i passes\n";
  55. if($i == 10){
  56. $totalScore += $PPT;
  57. }
  58. else {
  59. $totalScore += 0.025 * $MAX_SCORE;
  60. }}
  61. else {
  62. $fail_info = `make test$i 2>&1`;
  63. print "test$i fails\n";
  64. print "$fail_info\n\n";
  65. }
  66. }
  67. }
  68. print "Running $NUM_TC tests\n";
  69. for($i = 0; $i < $NUM_TC; $i++) {
  70. if(system("make test$i") == 0) {
  71. print "test$i passes\n";
  72. $score[$i] = $PPT;
  73. $isMemTestSuccess = 0;
  74. $isMaTestSuccess = 0;
  75. if(-e "outputs/memoutput$i"){
  76. open(MEM, "<outputs/memoutput$i");
  77. while ($line = <MEM>) {
  78. if ($line =~ m/All heap blocks were freed -- no leaks are possible/){
  79. # print "memory management test passes\n";
  80. $isMemTestSuccess = 1;
  81. }
  82. elsif ($line =~ m/ERROR SUMMARY: 0 errors from 0 contexts/){
  83. # print "memory access test passes\n";
  84. $isMaTestSuccess = 1;
  85. }
  86. # Heap usage check for PA09
  87. if ($line =~ m/total heap usage: /){ # Search for heap usage description and save the number of bytes to $temp[1].
  88. $_=$line;
  89. /frees,/;
  90. @temp = split /\s/, "$'";
  91. $temp[1]=~tr/,//d;
  92. if($temp[1] <= $heap[$i]){ #If number of bytes for heap usage is less than or equal to the expected amount, memory usage test passes
  93. } else {
  94. $unnecessaryByte[$i]=$temp[1]-$heap[$i];
  95. }
  96. }
  97. }
  98. close(MEM);
  99. if ($isMemTestSuccess == 0) {
  100. print "memory management test $i fails\n";
  101. $score[$i] = $score[$i] - ($PPT/2);
  102. }
  103. if ($isMaTestSuccess == 0) {
  104. print "memory access test $i fails. Check memoutput$i to see what the errors are\n";
  105. #$score[$i] = $score[$i] - ($PPT/2);
  106. }
  107. # Take score for allocating unnecessary bytes
  108. if ($unnecessaryByte[$i]>0){
  109. print "memory usage for test$i exceeds the expected amount.\n";
  110. # deduct 1% for every unnecessary byte
  111. $score[$i] = $score[$i] - ($MAX_SCORE*$unnecessaryByte[$i]/100);
  112. if($score[$i]<0){
  113. $score[$i]=0;
  114. }
  115. }
  116. }
  117. } else {
  118. $fail_info = `make test$i 2>&1`;
  119. print "test$i fails\n";
  120. print "$fail_info\n";
  121. }
  122. }
  123. for ($i = 0; $i < $NUM_Prob+1; $i++) {
  124. for ($j = 0; $j < $ARGV[2+$i]; $j++) {
  125. $scoreEachProb[$i] += $score[$base+$j];
  126. }
  127. $base += $ARGV[2+$i];
  128. }
  129. for ($i = 0; $i < $NUM_TC; $i++) {
  130. $totalScore = $totalScore + $score[$i];
  131. }
  132. #print student's score on screen
  133. =pod
  134. for ($i = 0; $i < $NUM_Prob+1; $i++) {
  135. printf("\nScore for Problem %d: %.2f/%.2f", $i, $scoreEachProb[$i], $ARGV[0] / $NUM_TC * $ARGV[2 + $i]);
  136. }
  137. =cut
  138. printf("\n\nTOTAL SCORE = %.2f/%.2f\n", $totalScore, $MAX_SCORE);
  139. print "\nYour Program will be manually graded for styling and implementation correctness\n";
  140. print "This manual grading can have affect on your final grade\n";
  141. print "DONE\n\n";