Show More
Commit Description:
[grader] report error when the check script crashed (i.e., when the result file is not found, while the compilation is okay)...
Commit Description:
[grader] report error when the check script crashed (i.e., when the result file is not found, while the compilation is okay) git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@117 6386c4cd-e34a-4fa8-8920-d93eb39b512e
File last commit:
Show/Diff file:
Action:
std-script/run | 142 lines | 3.7 KiB | text/plain | AmplLexer |
jittat
import original files...
r0 #!/usr/bin/ruby
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("run: #{Time.new.strftime("%H:%M")} #{str}")
fp.close
end
end
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 def extract_time(t)
if (result=/^(.*)r(.*)u(.*)s/.match(t))
{:real => result[1], :user => result[2], :sys => result[3]}
else
raise "Error reading running time"
end
end
def compile_box(source,bin)
system("gcc #{source} -o #{bin}")
end
jittat
import original files...
r0 if ARGV.length < 2 || ARGV.length > 3
puts "Usage: run <language> <test-num> [<program-name>]"
exit(127)
end
language = ARGV[0]
test_num = ARGV[1].to_i
if ARGV.length > 2
program_name = ARGV[2]
else
program_name = "a.out"
end
problem_home = ENV['PROBLEM_HOME']
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
# Check if the test number is okay.
if test_num <= 0 || test_num > problem.num_tests
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 log "You have specified a wrong test number."
jittat
import original files...
r0 exit(127)
end
#####################################
# Set the relavant file names here. #
#####################################
input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt"
#####################################
time_limit = problem.get_time_limit test_num
mem_limit = problem.get_mem_limit(test_num) * 1024
# Copy the input file.
#`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .`
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 time_output_format = "%Er%Uu%Ss"
# check if box is there, if not, compile it!
if !File.exists?("#{problem_home}/script/box")
log "WARNING: Compiling box: to increase efficiency, it should be compile manually"
compile_box("#{problem_home}/script/box.c",
"#{problem_home}/script/box")
end
jittat
import original files...
r0 # Run the program.
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 run_command = "/usr/bin/time -f \"#{time_output_format}\" 2>run_result #{problem_home}/script/box -a 2 -f -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name}"
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 log "Running test #{test_num}..."
log run_command
log
jittat
import original files...
r0 system(run_command)
# Create the result file.
result_file = File.new("result", "w")
comment_file = File.new("comment", "w")
# Check if the program actually produced any output.
run_result_file = File.new("run_result", "r")
run_result = run_result_file.readlines
run_result_file.close
time_elapsed = run_result[run_result.length-1]
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 running_time = extract_time(time_elapsed)
jittat
import original files...
r0
report = lambda{ |status, points, comment|
result_file.write status.strip
result_file.write "\n"
result_file.write points.to_s.strip
result_file.write "\n"
result_file.write time_elapsed.strip
result_file.write "\n"
result_file.close
`rm run_result`
jittat
fix various bugs, save output, save comment...
r8 # `rm output.txt` --- keep the output
jittat
import original files...
r0
comment_file.write comment
jittat
git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@20 6386c4cd-e34a-4fa8-8920-d93eb39b512e
r7 comment_file.write "--run-result--\n"
run_result.each do |l|
comment_file.write l
end
jittat
import original files...
r0 comment_file.close
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 log "Done!"
jittat
import original files...
r0 exit(0)
}
if run_result[0][0,2] != "OK"
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 log "There was a runtime error."
jittat
import original files...
r0 report.call(run_result[0], 0, "No comment.\n")
end
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 if running_time[:user].to_f + running_time[:sys].to_f > time_limit
log "Time limit exceeded."
report.call("Time limit exceeded", 0, "No comment.\n")
end
jittat
import original files...
r0 # Run 'check' to evaluate the output.
#puts "There was no runtime error. Proceed to checking the output."
check_command = "#{problem_home}/script/check #{language} #{test_num}"
jittat
Merged new-arch-branch changes 61:73 into the trunk...
r22 log "Checking the output..."
log check_command
jittat
import original files...
r0 if not system(check_command)
jittat
[grader] report error when the check script crashed (i.e., when the result file is not found, while the compilation is okay)...
r30 log "Problem with check script"
jittat
import original files...
r0 exit(127)
end
check_file = File.new("check_result", "r")
check_file_lines = check_file.readlines
report.call(check_file_lines[0], check_file_lines[1], "No comment.\n")