-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgrade-shlab.pl
142 lines (123 loc) · 3.93 KB
/
grade-shlab.pl
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/perl
#!/usr/local/bin/perl
use lib '.';
use Getopt::Std;
use config;
#########################################################################
# grade-shlab.pl - Shell lab autograder
#
# Copyright (c) 2002, R. Bryant and D. O'Hallaron, All rights reserved.
# May not be used, modified, or copied without permission.
#
# This program develops an initial grade for a shell lab solution by
# comparing its output to the output from a reference shell. The
# comparison is not perfect, so the output needs to be checked by hand.
#
########################################################################
# autoflush output on every print statement
$| = 1;
# Any tmp files created by this script are readable only by the user
umask(0077);
#
# usage - print help message and terminate
#
sub usage {
printf STDERR "$_[0]\n";
printf STDERR "Usage: $0 [-he] -f <pathname> [-s <srcdir>]\n";
printf STDERR "Options:\n";
printf STDERR " -h Print this message\n";
printf STDERR " -e Don't include original handin file on the grade sheet\n";
printf STDERR " -f <file> Input tsh.c file to test\n";
printf STDERR " -s <srcdir> Directory where driver source code is located\n";
die "\n";
}
##############
# Main routine
##############
#
# Parse the command line arguments
#
getopts('hef:s:');
if ($opt_h) {
usage();
}
if (!$opt_f) {
usage("Missing required argument (-f)");
}
#
# These optional flags override defaults in config.pm
#
if ($opt_s) { # driver src directory
$SRCDIR = $opt_s;
}
#
# Initialize various file and path names
#
$infile = $opt_f; # src file to test
($infile_basename = $infile) =~ s#.*/##s; # basename of input file
$tmpdir = "/tmp/$infile_basename.$$"; # scratch directory
$0 =~ s#.*/##s; # $0 is this program's basename
#
# This is a message we use in several places when the program dies
#
$diemsg = "The files are in $tmpdir.";
#
# Make sure the src directory exists
#
(-d $SRCDIR and -e $SRCDIR)
or die "$0: ERROR: Can't access source directory $SRCDIR.\n";
#
# Make sure the input file exists and is readable
#
open(INFILE, $infile)
or die "$0: ERROR: couldn't open file $infile\n";
close(INFILE);
#
# Set up the contents of the scratch directory
#
system("mkdir $tmpdir") == 0
or die "$0: ERROR: mkdir $tmpdir failed. $diemsg\n";
system("cp $infile $tmpdir/tsh.c") == 0
or die "$0: ERROR: cp failed. $diemsg\n";
system("cp checktsh.pl $tmpdir") == 0
or die "$0: ERROR: cp failed. $diemsg\n";
system("cp $SRCDIR/Makefile $tmpdir/Makefile") == 0
or die "$0: ERROR: cp failed. $diemsg\n";
system("cp $SRCDIR/trace*.txt $tmpdir") == 0
or die "$0: ERROR: cp failed. $diemsg\n";
system("cp $SRCDIR/tshref $tmpdir/tshref") == 0
or die "$0: ERROR: cp failed. $diemsg\n";
system("cp $SRCDIR/sdriver.pl $tmpdir") == 0
or die "$0: ERROR: cp failed. $diemsg\n";
system("cp $SRCDIR/myspin.c $tmpdir") == 0
or die "$0: ERROR: cp failed. $diemsg\n";
system("cp $SRCDIR/mysplit.c $tmpdir") == 0
or die "$0: ERROR: cp failed. $diemsg\n";
system("cp $SRCDIR/mystop.c $tmpdir") == 0
or die "$0: ERROR: cp failed. $diemsg\n";
system("cp $SRCDIR/myint.c $tmpdir") == 0
or die "$0: ERROR: cp failed. $diemsg\n";
# Print header
print "\nCS:APP Shell Lab: Grading Sheet for $infile_basename\n\n";
#
# Compile the student's tsh.c file
#
print "\nPart 0: Compiling your shell\n\n";
system("(cd $tmpdir; make clean > /dev/null 2>&1)");
system("(cd $tmpdir; make)") == 0
or die "$0: ERROR: $infile_basename did not compile. $diemsg\n";
#
# Run the autograder
#
print "\nPart 1: Correctness Tests\n\n";
$score = 0;
foreach $tracefile (@TRACEFILES) {
# If perfect match, than add in the points
if (system("cd $tmpdir; ./checktsh.pl -e -t $tracefile") == 0) {
$score += $POINTS;
}
}
print "\nPreliminary correctness score: $score\n";
# Clean up and exit
system("rm -rf $tmpdir");
exit;