Show More
Commit Description:
add grader stop, fix ARGV bug...
Commit Description:
add grader stop, fix ARGV bug git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@19 6386c4cd-e34a-4fa8-8920-d93eb39b512e
References:
File last commit:
Show/Diff file:
Action:
std-script/run | 99 lines | 2.5 KiB | text/plain | AmplLexer |
#!/usr/bin/ruby
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
puts "The problem specification is not well formed."
exit(127)
end
# Check if the test number is okay.
if test_num <= 0 || test_num > problem.num_tests
puts "You have specified a wrong test number."
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} .`
# Run the program.
run_command = "/usr/bin/time -f \"%E\" 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}"
puts "Running test #{test_num}..."
puts run_command
puts
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]
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`
`rm output.txt`
comment_file.write comment
comment_file.close
puts
puts "Done!"
exit(0)
}
if run_result[0][0,2] != "OK"
puts "There was a runtime error."
report.call(run_result[0], 0, "No comment.\n")
end
# 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}"
puts "Checking the output..."
puts check_command
if not system(check_command)
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")