diff --git a/std-script/compile b/std-script/compile --- a/std-script/compile +++ b/std-script/compile @@ -147,6 +147,7 @@ out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c" end File.chmod(0755, params[:output_file]) + FileUtils.cp("#{params[:source_file]}c",params[:output_file]) end else diff --git a/std-script/judge b/std-script/judge --- a/std-script/judge +++ b/std-script/judge @@ -59,6 +59,7 @@ end source_file = ARGV[1] +ENV['SOURCE_NAME'] = source_file if File.exist?(source_file) == false log "The source file does not exist." exit(127) @@ -140,7 +141,7 @@ } begin - execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") + execute("#{problem_home}/script/run #{language} #{test_num} ", "Error occured during execution of the run script") rescue # do nothing end diff --git a/std-script/run b/std-script/run --- a/std-script/run +++ b/std-script/run @@ -43,10 +43,13 @@ end problem_home = ENV['PROBLEM_HOME'] +source_name = ENV['SOURCE_NAME'] require "#{problem_home}/script/test_dsl.rb" load "#{problem_home}/test_cases/all_tests.cfg" problem = Problem.get_instance +sandbox_dir = Dir.getwd + if problem.well_formed? == false log "The problem specification is not well formed." exit(127) @@ -81,29 +84,30 @@ # Hide PROBLEM_HOME ENV['PROBLEM_HOME'] = nil +ENV['SOURCE_NAME'] = nil # Run the program. #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}" # - - +JAVA_OPTION = "-s set_robust_list -s futex -s clone -s getppid -s clone -s wait4 -p /usr/bin/ -p ./" +RUBY_OPTION = "-p /usr/lib64/ -p /lib64/ -p /dev/urandom -p #{sandbox_dir}/#{program_name} -s set_robust_list -s sched_getaffinity -s clock_gettime -s sigaltstack -s pipe2 -s clone -s futex -s openat" +PYTHON_OPTION = "-p /usr/lib64/ -p /lib64/ -p /usr/bin/ -p /usr/local/lib64/ -p /usr/local/lib/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p #{sandbox_dir}/#{source_name} -s set_robust_list -s openat -s recvmsg -s connect -s socket -s sendto -E PYTHONNOUSERSITE=yes" case language when "java" - # 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 - run_command = "#{problem_home}/script/box -T -t #{time_limit} -s getppid -s clone -s wait4 -p /usr/bin/ -p ./ -i #{input_file_name} -o output.txt /usr/bin/java #{classname} 2>run_result" + #for java, we cannot really check the memory limit... + 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 #{classname} 2>run_result" when "ruby" - run_command = "#{problem_home}/script/box -T -t #{time_limit} -s getppid -s wait4 -s clone -s set_robust_list -s futex -s sigaltstack -p /dev/urandom -p ./ -p /home/dae/.rvm/rubies/ruby-1.9.2-p320/ -p #{problem_home}/ -i #{input_file_name} -o output.txt #{program_name} 2>run_result" + run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{mem_limit} #{RUBY_OPTION} -i #{input_file_name} -o output.txt /usr/bin/ruby #{program_name} 2>run_result" when "python" - #this code just run without any checking - run_command = "#{problem_home}/script/box -T -t #{time_limit} -p #{problem_home}/ -i #{input_file_name} -o output.txt #{program_name} 2>run_result" + run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{mem_limit} #{PYTHON_OPTION} -i #{input_file_name} -o output.txt /usr/bin/python #{program_name} 2>run_result" else # for c++, pascal, we do the normal checking 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} 2>run_result" end @@ -111,7 +115,7 @@ log "Running test #{test_num}..." log run_command -log +log system(run_command) # Restore PROBLEM_HOME @@ -154,6 +158,7 @@ exit(0) } + if run_result[0][0,2] != "OK" log "There was a runtime error." report.call(run_result[0], 0, "No comment.\n") diff --git a/templates/check.float b/templates/check.float new file mode 100755 --- /dev/null +++ b/templates/check.float @@ -0,0 +1,66 @@ +#!/usr/bin/env ruby + +problem_home = ENV['PROBLEM_HOME'] +require "#{problem_home}/script/test_dsl.rb" + +if ARGV.length < 2 + puts "Usage: check []" + exit(0) +end + +language = ARGV[0] +test_num = ARGV[1].to_i +if ARGV.length >= 3 + output_file_name = ARGV[2] +else + output_file_name = "output.txt" +end + +load "#{problem_home}/test_cases/all_tests.cfg" +problem = Problem.get_instance + +output_file = File.new(output_file_name, "r") +answer_file = File.new("#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt") +result_file = File.new("check_result", "w") + +output_file_content = output_file.read +answer_file_content = answer_file.read + +report_correct = lambda { + result_file.write "Correct\n" + result_file.write problem.get_score(test_num) + result_file.write "\n" + result_file.close + exit(0) +} + +report_wrong = lambda { + result_file.write "Incorrect\n" + result_file.write "0\n" + result_file.close + exit(0) +} + +################## +# Your code here # +################## + +########### THIS IS FOR CHECKING FLOAT with EPSILON error ########## + +EPSILON = 0.000001 + +out_items = output_file_content.split +ans_items = answer_file_content.split + +if out_items.length != ans_items.length + report_wrong.call +else + out_items.length.times do |i| + out_value = out_items[i].to_f + ans_value = ans_items[i].to_f + if (out_value - ans_value).abs > EPSILON * [out_value.abs,ans_value.abs].max + report_wrong.call + end + end + report_correct.call +end