⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auto_grader.pl

📁 SSD6 练习5的原版正确答案
💻 PL
字号:
#!/usr/local/bin/perl

#
#  Skeleton for a perl daemon to keep watching a directory for handins, 
#  running a performance check on them when appropriate
#


### SITE CONFIGURATION 

#$DEBUG = 1;

# the ID of the current project
$project = "Exercise5";

### END SITE CONFIGURATION


## GLOBAL PARAMETERS
#Course-specific variables

$term = "Fall02";
$course = "SSD6";
$section = "SectionA";
$assessment = "Exercise5";
$question = "CacheLab";

#
#Example of structure:  TERM/COURSE/SECTION/ASSESSMENT/QUESTIONNAME/
chomp($g_execute_dir = `cd`);
$g_lab_dir = "$term\\$course\\$section\\$assessment\\$question";	#TODO fix
$g_sandbox_dir="$g_execute_dir\\sandbox427";
$g_support_dir="$g_execute_dir\\orig_codefiles";
## END GLOBAL PARAMETERS

$compile_error = "Hi,
We tried to compile driver, but the compilation
generated some errors.  Sorry!";



# Main execution
#

$curr_dir = `cd`;


print "Please enter the directory where handins are stored:\n";
print "(This will be the same directory specified in CTEGrader Options.)\n";
print "\n";
print "==> ";
$g_handin_dir = <STDIN>;
chomp($g_handin_dir);

unless (chdir($g_handin_dir)) {
	print "Unable to find directory '$g_handin_dir'.\n";
	print "Press return to exit.\n";
	<STDIN>;		#to force a 
	exit;
}
opendir(DIR, '.');

#unless grep(/$course_id/, (readdir(DIR))) { 
#	print "Course handins not present."; <STDIN>; exit;
#}

unless (chdir $g_lab_dir) {
	print "Unable to find directory '$g_lab_dir'.\n";
	print "Press return to exit.\n";
	<STDIN>;
	exit;

}


	my @files;
	my $thefile;
	my $filecount=0;
	my @studentIds;
	
	print "Doing work....\n"			if $DEBUG;

	opendir DIR, "." 
		or die "Unable to read handin directory ($g_handin_dir\\$g_lab_dir).";
	@sdirs = readdir DIR;
	closedir DIR;

	foreach $studentdir (grep (!/^\.+$/, @sdirs)) {
		next unless -d $studentdir;
		next if grep(/$studentdir/, @studendIds);
		
		opendir(SDIR, $studentdir);
		my @files = readdir(SDIR);
		closedir(SDIR);
		if(grep(/^rotate\.c$/ || /^smooth\.c$/, @files)) {
			push(@studentIds, $studentdir);
		}
			
	}

	print "Executing ", scalar @studentIds, " student handins.\n"	if $DEBUG;
	
	foreach $sid (@studentIds)
	{		
		print "SID: $sid\n"		if $DEBUG;
		next unless $sid;
		
		#setup the sandbox
		print "Testing files for $sid...\n";
		setupsandbox($sid);
		
		#run the test
		doruntest($sid);
	}
	



#
#
# Setup the sandbox, where we will test the program
#
#
sub setupsandbox()
{
    my ($sid) = @_;
    # you should delete any files in the sandbox directory and
    # copy or link in any Makefiles or supporting files 
    # that are needed to run the test
    #
    # The filename of the student's handin is $myhandinfile.
    # You should copy it into the directory giving it the appropriate
    # name for the assignment
    
	print "Setting up:  <$sid>\n"		if	$DEBUG;

    # clean directory
    `del /s /f /q \"$g_sandbox_dir\"`;
    
    
    # do stuff
    `copy \"$g_support_dir\" \"$g_sandbox_dir\"`;

    # move the handin into the sandbox
	`copy \"$sid\" \"$g_sandbox_dir\"`;

}



#
#  Run tests on the stuff setup in the sandbox directory
#  
#
sub doruntest()
{
	my ($student) = @_;
	# compile and run performance tests
	# you can use the saferun utility to redirect
	# output into a temporary file, and catch the
	# return value 
	my $prev_dir = `cd`;
	chomp($prev_dir);
	unless (chdir($g_sandbox_dir)) {
		print "Couldn't change to $g_sandbox_dir, stuck in ", `cd`;
		return;
	}
		
	# check whether make successful

	if(system("nmake")){
		print "\n\nERROR: NMake was unable to compile ${student}'s submission.\n";
	}
	else{
		print "\n\nNMake compiled the driver successfully.\n";
		print "\nExecuting driver (this should take a while)...\n";
		$output1 = `grading_driver.exe > $prev_dir\\$student\\feedback\\results-$student.txt`;
		print "\nDriver finished executing.\n";

		$output = "----------Output from driver----------\n" . $output1 . "\n";
	}

	## reset our global flag
	chdir($prev_dir);
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -