Show More
Commit Description:
merge
Commit Description:
merge
References:
File last commit:
Show/Diff file:
Action:
std-script/run | 214 lines | 8.1 KiB | text/plain | AmplLexer |
Jittat Fakcharoenphol
fixed grader to work with ruby 1.9
r137 #!/usr/bin/env ruby
jittat
import original files...
r0
more commenting on script
r257 ##
# This program should be run in the sandbox dir containing the compiled file
# (or source file for script language). It will call the sandbox program with
# the given input and process the output of the sandbox
#
# If sandbox exit normally, this program will call the "check" script to do
# scoring. Otherwise, it would record the error accordingly
#
# This program produces several file
# * result - the result from check script
# * comment - comment from sandbox
# * output - output of the program
#
Jittat Fakcharoenphol
fixed missing require
r105 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("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)
add new box, from moe, and modified to report running time in grader format
r156 # puts "TIME: #{t}"
if (result=/^(.*)r(.*)u(.*)s/.match(t))
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 {:real => result[1], :user => result[2], :sys => result[3]}
else
jittat
[grader] added memory usage status report, better running time report...
r42 #{:real => 0, :user => 0, :sys => 0}
#puts "ERROR READING RUNNING TIME: #{t}"
raise "Error reading running time: #{t}"
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 end
end
def compile_box(source,bin)
jittat
[grader] added memory usage status report, better running time report...
r42 system("g++ #{source} -o #{bin}")
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 end
more commenting on script
r257 #------------------------------------------
# MAIN
#------------------------------------------
#parse parameter
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']
clean up run command to check for running time / memory...
r161 source_name = ENV['SOURCE_NAME']
jittat
import original files...
r0 require "#{problem_home}/script/test_dsl.rb"
load "#{problem_home}/test_cases/all_tests.cfg"
problem = Problem.get_instance
clean up run command to check for running time / memory...
r161 sandbox_dir = Dir.getwd
jittat
import original files...
r0 if problem.well_formed? == false
more commenting on script
r257 log "RUN: ERROR: 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
more commenting on script
r257 log "RUN: ERROR: 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 # 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"
jittat
[grader] added memory usage status report, better running time report...
r42 compile_box("#{problem_home}/script/box.cc",
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 "#{problem_home}/script/box")
end
jittat
[grader] new test on accessing PROBLEM_HOME and openning files...
r35 # Hide PROBLEM_HOME
ENV['PROBLEM_HOME'] = nil
clean up run command to check for running time / memory...
r161 ENV['SOURCE_NAME'] = nil
jittat
[grader] new test on accessing PROBLEM_HOME and openning files...
r35
jittat
import original files...
r0 # Run the program.
jittat
[grader] added memory usage status report, better running time report...
r42 #run_command = "/usr/bin/time -f \"#{time_output_format}\" 2>run_result #{problem_home}/script/box_new -a 2 -f -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name}"
add more languages, java and ruby...
r147 #
Jittat Fakcharoenphol
fixed grader to work with ruby 1.9
r137
clean up run command to check for running time / memory...
r161 JAVA_OPTION = "-s set_robust_list -s futex -s clone -s getppid -s clone -s wait4 -p /usr/bin/ -p ./"
add --only-error to grader script
r240 RUBY_OPTION = "-p /usr/lib64/ -p /usr/local/lib64/ -p /usr/local/lib/ -p /lib64/ -p /dev/urandom -p #{sandbox_dir}/#{program_name} -p #{sandbox_dir}/ -s set_robust_list -s sched_getaffinity -s clock_gettime -s sigaltstack -s pipe2 -s clone -s futex -s openat -s pipe -s getrandom"
add more systemcall to python
r227 PYTHON_OPTION = "-p /usr/lib64/ -p /usr/local/lib64/ -p /usr/local/lib/ -p /usr/bin/ -p /lib64/ -p /dev/urandom -p /usr/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p #{sandbox_dir}/#{source_name} -p /proc/sys/crypto/fips_enabled -p /proc/self/status -p /proc/mounts -p /var/lib/dpkg/status -s statfs -s set_robust_list -s openat -s sysinfo -s recvmsg -s connect -s socket -s sendto -s futex -s sigaltstack -s getrandom -E PYTHONNOUSERSITE=yes"
add dump submission & octave
r261 OCTAVE_OPTION = "-p /usr/lib64/ -p /usr/local/lib64/ -p /usr/local/lib/ -p /usr/bin/ -p /lib64/ -p /dev/urandom -p /usr/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p #{sandbox_dir}/#{source_name} -p /proc/sys/crypto/fips_enabled -p /proc/self/status -p /proc/mounts -p /var/lib/dpkg/status -s statfs -s set_robust_list -s openat -s sysinfo -s recvmsg -s connect -s socket -s sendto -s futex -s sigaltstack -s getrandom -s prlimit64 -s execve -E PYTHONNOUSERSITE=yes"
fix run of php
r171 PHP_OPTION = "-p /usr/lib64/ -p/lib64/ -p /usr/bin/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p /usr/share/ -s setfsuid -s setfsgid -s openat -s set_robust_list -s futex -s clone -s socket -s connect"
add haskell
r219 HASKELL_OPTION = "-s set_robust_list -s clock_gettime -s sysinfo -s timer_create -s timer_settime -s futex -s timer_delete"
add more languages, java and ruby...
r147
case language
when "java"
fix java compiler and runner...
r158 # for java, extract the classname
# wne have to add additional systemcall and we don't check the mem limit (dunno how to fix...)
classname = 'DUMMY'
File.open(program_name,"r").each do |line|
classname = line
end
clean up run command to check for running time / memory...
r161 #for java, we cannot really check the memory limit...
accommodate mem limit in php and java, using new box64
r187 run_command = "#{problem_home}/script/box -a 3 -f -T -t #{time_limit} #{JAVA_OPTION} -i #{input_file_name} -o output.txt /usr/bin/java -A -Xmx#{mem_limit}k -A #{classname} "
add more languages, java and ruby...
r147 when "ruby"
use redirection by system(, {out: , err: }) instead of by > or 2> in the command
r178 run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit*=2} -m #{mem_limit} #{RUBY_OPTION} -i #{input_file_name} -o output.txt /usr/bin/ruby #{program_name} "
add python support...
r154 when "python"
set minimum for python to 512
r244 run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit*=2} -m #{[512 * 1024,mem_limit].max} #{PYTHON_OPTION} -i #{input_file_name} -o output.txt /usr/bin/python3 #{program_name} "
add haskell
r219 when "haskell"
add haskell
r220 run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{[512 * 1024,mem_limit].max} #{HASKELL_OPTION} -i #{input_file_name} -o output.txt #{program_name} "
add php
r165 when "php"
update python mem to 512mb again
r252 run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit*=2} -m #{[512 * 1024,mem_limit].max} #{PHP_OPTION} -i #{input_file_name} -o output.txt /usr/bin/php -A -d -A memory_limit=#{mem_limit}k -A #{program_name} "
add dump submission & octave
r261 when "octave"
run_command = "#{problem_home}/script/box -T -t #{time_limit*=2} -m #{[512 * 1024,mem_limit].max} #{OCTAVE_OPTION} -i #{input_file_name} -o output.txt /usr/bin/octave -A -W -A --no-gui #{program_name}"
add python support...
r154 else # for c++, pascal, we do the normal checking
use redirection by system(, {out: , err: }) instead of by > or 2> in the command
r178 run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name} "
add more languages, java and ruby...
r147 end
Jittat Fakcharoenphol
fixed grader to work with ruby 1.9
r137
- add isolate...
r256 log "RUN: Running test #{test_num}..."
log "RUN: Run command = [#{run_command}]"
clean up run command to check for running time / memory...
r161 log
use redirection by system(, {out: , err: }) instead of by > or 2> in the command
r178 system(run_command,err: 'run_result')
jittat
import original files...
r0
jittat
[grader] new test on accessing PROBLEM_HOME and openning files...
r35 # Restore PROBLEM_HOME
ENV['PROBLEM_HOME'] = problem_home
jittat
import original files...
r0 # 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
jittat
[grader] added memory usage status report, better running time report...
r42
run_stat = run_result[run_result.length-1]
running_time = extract_time(run_stat)
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"
jittat
[grader] added memory usage status report, better running time report...
r42 result_file.write run_stat.strip
jittat
import original files...
r0 result_file.write "\n"
result_file.close
Jittat Fakcharoenphol
removed calls to 'pwd', other uses of back quotes
r102 FileUtils.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
[grader] added memory usage status report, better running time report...
r42
# added for debuggin --- jittat
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
[grader] added memory usage status report, better running time report...
r42
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)
}
clean up run command to check for running time / memory...
r161
jittat
import original files...
r0 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
add more languages, java and ruby...
r147 if running_time[:user].to_f > time_limit
jittat
[grader] [MERGED] Merged new-arch-branch changes 74:105 into the trunk...
r23 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
[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 report.call("Incorrect",0,"Check script error.\n")
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")