Show More
Commit Description:
merge
Commit Description:
merge
References:
File last commit:
Show/Diff file:
Action:
std-script/judge | 194 lines | 5.6 KiB | text/plain | TextLexer |
Jittat Fakcharoenphol
fixed grader to work with ruby 1.9
r137 #!/usr/bin/env ruby
jittat
import original files...
r0
Jittat Fakcharoenphol
removed many 'system' invokations
r101 require 'fileutils'
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 def log(str='')
if ENV['TALKATIVE']!=nil
puts str
end
if ENV['GRADER_LOGGING']!=nil
log_fname = ENV['GRADER_LOGGING']
fp = File.open(log_fname,"a")
fp.puts("judge: #{Time.new.strftime("%H:%M")} #{str}")
fp.close
end
end
jittat
import original files...
r0 problem_home = ENV['PROBLEM_HOME']
def execute(command, error_message="")
if not system(command)
jittat
[grader] fixed: import_problem (error in erb calls), check_wrapper; better error handling -- will get 0 score for a particular test run that fails...
r31 msg = "ERROR: #{error_message}"
log msg
Jittat Fakcharoenphol
fixed grader to work with ruby 1.9
r137 raise(msg)
jittat
import original files...
r0 end
end
Jittat Fakcharoenphol
removed many 'system' invokations
r101 def call_and_log(error_message)
begin
yield
rescue
- add isolate...
r256 msg = "JUDGE: ERROR: #{error_message}"
Jittat Fakcharoenphol
removed many 'system' invokations
r101 log msg
raise msg
end
end
def clear_and_create_empty_dir(dir)
FileUtils.rm_rf(dir, :secure => true)
call_and_log("Cannot make directory #{dir}.") { FileUtils.mkdir(dir) }
end
jittat
import original files...
r0 # ARGV[0] --- language
# ARGV[1] --- program source file
# ARGV[2] --- test result directory
# ARGV[3] --- sandbox directory
if ARGV.length < 2 || ARGV.length > 4
puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]"
puts " <sandbox-directory> is defaulted to ./sandbox"
puts " <test-result-directory> is defaulted to ./test-result"
puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it."
exit(127)
end
language = ARGV[0]
add dump submission & octave
r261 if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" && language != "python" && language != "php" && language != "haskell" && language != "octave"
- add isolate...
r256 log "JUDGE: You specified a language that is not supported: #{language}."
jittat
import original files...
r0 exit(127)
end
source_file = ARGV[1]
clean up run command to check for running time / memory...
r161 ENV['SOURCE_NAME'] = source_file
jittat
import original files...
r0 if File.exist?(source_file) == false
- add isolate...
r256 log "JUDGE: The source file does not exist."
jittat
import original files...
r0 exit(127)
end
- add isolate...
r256 log "JUDGE: Making test result and sandbox directories..."
jittat
import original files...
r0
Jittat Fakcharoenphol
removed calls to 'pwd', other uses of back quotes
r102 current_dir = FileUtils.pwd
jittat
import original files...
r0 current_dir.strip!
if ARGV.length >= 3
test_result_dir = ARGV[2]
else
test_result_dir = "#{current_dir}/test-result"
end
Jittat Fakcharoenphol
removed many 'system' invokations
r101
- add isolate...
r256 log "JUDGE: Test result directory: #{test_result_dir}"
Jittat Fakcharoenphol
removed many 'system' invokations
r101 clear_and_create_empty_dir(test_result_dir)
jittat
import original files...
r0
if ARGV.length >= 4
sandbox_dir = ARGV[3]
else
sandbox_dir = "#{current_dir}/sandbox"
end
- add isolate...
r256 log "JUDGE: Sandbox directory: #{sandbox_dir}"
Jittat Fakcharoenphol
removed many 'system' invokations
r101 clear_and_create_empty_dir(sandbox_dir)
jittat
import original files...
r0
- add isolate...
r256 # ------------------------------
jittat
import original files...
r0 # Compile
- add isolate...
r256 # ------------------------------
log "JUDGE: Compiling..."
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 log
Jittat Fakcharoenphol
removed many 'system' invokations
r101 call_and_log("Cannot copy the source file to #{sandbox_dir}") {
FileUtils.cp(source_file, sandbox_dir)
}
jittat
import original files...
r0 begin
Dir.chdir sandbox_dir
rescue
- add isolate...
r256 log "JUDGE: ERROR: Cannot change directory to #{sandbox_dir}."
jittat
import original files...
r0 exit(127)
end
execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!")
Jittat Fakcharoenphol
removed calls to 'pwd', other uses of back quotes
r102 compile_message = open("compiler_message").read
jittat
import original files...
r0 compile_message.strip!
Jittat Fakcharoenphol
removed many 'system' invokations
r101 call_and_log("Cannot move the compiler message to #{test_result_dir}.") {
FileUtils.mv("compiler_message", test_result_dir)
}
jittat
fix bugs: paths, check compilation error, all_tests.cfg.erb...
r3 if !FileTest.exist?("a.out")
- add isolate...
r256 log "JUDGE: EROOR: Cannot compile the source code. See message in #{test_result_dir}/compile_message"
jittat
import original files...
r0 exit(127)
else
Jittat Fakcharoenphol
removed many 'system' invokations
r101 call_and_log("Cannot move the compiled program to #{test_result_dir}") {
FileUtils.mv("a.out",test_result_dir)
add more languages, java and ruby...
r147 if language == "java" then Dir["*.class"].each { |file| FileUtils.mv(file,test_result_dir)} end
add python support...
r154 if language == "python" then Dir["*.pyc"].each { |file| FileUtils.mv(file,test_result_dir)} end
Jittat Fakcharoenphol
removed many 'system' invokations
r101 }
FileUtils.rm_rf("#{sandbox_dir}/.")
jittat
import original files...
r0 end
- add isolate...
r256
#-----------------------------------------------
# run
#-----------------------------------------------
jittat
import original files...
r0 require "#{problem_home}/script/test_dsl.rb"
load "#{problem_home}/test_cases/all_tests.cfg"
problem = Problem.get_instance
if problem.well_formed? == false
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 log "The problem specification is not well formed."
jittat
import original files...
r0 exit(127)
end
# Doing the testing.
- add isolate...
r256 log
log "JUDGE: Running each test case..."
jittat
import original files...
r0 (1..(problem.num_tests)).each do |test_num|
jittat
[grader] +grade submission...
r61
$stdout.print "[#{test_num}]"
$stdout.flush
Jittat Fakcharoenphol
removed many 'system' invokations
r101 call_and_log("Cannot copy the compiled program into #{sandbox_dir}") {
Jittat Fakcharoenphol
fixed grader to work with ruby 1.9
r137 FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir, :preserve => true)
add more languages, java and ruby...
r147 if language == "java" then Dir["#{test_result_dir}/*.class"].each { |file| FileUtils.cp(file,sandbox_dir)} end
add python support...
r154 if language == "python" then Dir["#{test_result_dir}/*.pyc"].each { |file| FileUtils.cp(file,sandbox_dir)} end
Jittat Fakcharoenphol
removed many 'system' invokations
r101 }
Jittat Fakcharoenphol
fixed grader to work with ruby 1.9
r137
add feature to import_problem to automatically copy *.txt file and fix the judge script accordingly
r235 #additionally copy any extra .txt file
data_files = Dir[problem_home + '/*.txt']
data_files.each do |file|
FileUtils.cp(file,sandbox_dir)
end
jittat
[grader] fixed: import_problem (error in erb calls), check_wrapper; better error handling -- will get 0 score for a particular test run that fails...
r31 begin
clean up run command to check for running time / memory...
r161 execute("#{problem_home}/script/run #{language} #{test_num} ", "Error occured during execution of the run script")
jittat
[grader] fixed: import_problem (error in erb calls), check_wrapper; better error handling -- will get 0 score for a particular test run that fails...
r31 rescue
# do nothing
end
Jittat Fakcharoenphol
fixed grader to work with ruby 1.9
r137
more commenting on script
r257
#copy the output of run script to each test-result folder
Jittat Fakcharoenphol
removed many 'system' invokations
r101 call_and_log("Cannot create directory #{test_result_dir}/#{test_num}") {
FileUtils.mkdir "#{test_result_dir}/#{test_num}"
}
call_and_log("Cannot copy the result file into #{test_result_dir}/#{test_num}") {
FileUtils.mv "#{sandbox_dir}/result", "#{test_result_dir}/#{test_num}"
}
call_and_log("Cannot copy the comment file into #{test_result_dir}/#{test_num}") {
FileUtils.mv "#{sandbox_dir}/comment", "#{test_result_dir}/#{test_num}"
}
call_and_log("Cannot copy the output file into #{test_result_dir}/#{test_num}") {
FileUtils.mv "#{sandbox_dir}/output.txt", "#{test_result_dir}/#{test_num}"
}
call_and_log("Cannot clear #{sandbox_dir}") {
FileUtils.rm_rf(Dir.glob("#{sandbox_dir}/*"), :secure => true)
}
jittat
import original files...
r0 end
jittat
[grader] +grade submission...
r61 $stdout.print "[done]\n"
jittat
import original files...
r0 # Grade
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 log
- add isolate...
r256 log "JUDGE: Grading..."
jittat
import original files...
r0 begin
Dir.chdir test_result_dir
rescue
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 log "ERROR: Cannot change directory to #{test_result_dir}."
jittat
import original files...
r0 exit(127)
end
execute("#{problem_home}/script/grade", "An error occured during grading!")
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 log
log "All done!"