diff --git a/std-script/compile b/std-script/compile --- a/std-script/compile +++ b/std-script/compile @@ -26,10 +26,13 @@ C_COMPILER = "/usr/bin/gcc" CPLUSPLUS_COMPILER = "/usr/bin/g++" PASCAL_COMPILER = "/usr/bin/fpc" +JAVA_COMPILER = "/usr/bin/javac" +RUBY_INTEPRETER = "/home/dae/.rvm/rubies/ruby-1.9.2-p320/bin/ruby" C_OPTIONS = "-O2 -s -static -std=c99 -DCONTEST -lm -Wall" CPLUSPLUS_OPTIONS = "-O2 -s -static -DCONTEST -lm -Wall" PASCAL_OPTIONS = "-O1 -XS -dCONTEST" +JAVA_OPTIONS = "" # Check for the correct number of arguments. Otherwise, print usage. if ARGV.length == 0 or ARGV.length > 4 @@ -96,6 +99,32 @@ command = "#{PASCAL_COMPILER} #{params[:source_file]} -ooutpas #{PASCAL_OPTIONS} > #{params[:message_file]}" system(command) FileUtils.mv("output", params[:output_file]) + + when "java" + #rename the file to the public class name + + #get the class name + classname = 'DUMMY' + File.foreach(params[:source_file]) do |line| + md = /\s*public\s*class\s*(\w*)/.match(line) + classname=md[1] if md + end + system("cp #{params[:source_file]} #{classname}.java") + command = "#{JAVA_COMPILER} #{classname}.java > #{params[:message_file]}" + system(command) + File.open(params[:output_file],"w") {|file| file.write("#!/bin/sh\n/usr/bin/java #{classname}\n")} + File.chmod(0755, params[:output_file]) + + when "ruby" + command = "#{RUBY_INTEPRETER} -c #{params[:source_file]} > #{params[:message_file]}" + system(command) + File.open(params[:output_file],"w") do |out_file| + out_file.puts "#!#{RUBY_INTEPRETER}" + File.open(params[:source_file],"r").each do |line| + out_file.print line + end + end + File.chmod(0755, params[:output_file]) else talk("ERROR: Invalid language specified!") diff --git a/std-script/judge b/std-script/judge --- a/std-script/judge +++ b/std-script/judge @@ -53,7 +53,7 @@ end language = ARGV[0] -if language != "c" && language != "c++" && language != "pas" +if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" log "You specified a language that is not supported: #{language}." exit(127) end @@ -110,6 +110,7 @@ else call_and_log("Cannot move the compiled program to #{test_result_dir}") { FileUtils.mv("a.out",test_result_dir) + if language == "java" then Dir["*.class"].each { |file| FileUtils.mv(file,test_result_dir)} end } FileUtils.rm_rf("#{sandbox_dir}/.") end @@ -133,6 +134,7 @@ call_and_log("Cannot copy the compiled program into #{sandbox_dir}") { FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir, :preserve => true) + if language == "java" then Dir["#{test_result_dir}/*.class"].each { |file| FileUtils.cp(file,sandbox_dir)} end } begin diff --git a/std-script/run b/std-script/run --- a/std-script/run +++ b/std-script/run @@ -15,8 +15,9 @@ end def extract_time(t) - # puts "TIME: #{t}" - if (result=/^(.*)r(.*)u(.*)s/.match(t)) + #puts "TIME: #{t}" + #if (result=/^(.*)real(.*)wall(.*)s/.match(t)) + if (result=/^OK \((.*) sec real\, (.*) sec wall,.*MB, (.*) syscalls/.match(t)) {:real => result[1], :user => result[2], :sys => result[3]} else #{:real => 0, :user => 0, :sys => 0} @@ -84,8 +85,23 @@ # 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}" +# -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" + + + +case language + when "java" + # for java, we have to add additional systemcall and we don't check the mem limit (dunno how to fix...) + 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 #{program_name} 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" + when "c++" + 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" + else + 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 + log "Running test #{test_num}..." log run_command @@ -137,7 +153,7 @@ report.call(run_result[0], 0, "No comment.\n") end -if running_time[:user].to_f + running_time[:sys].to_f > time_limit +if running_time[:user].to_f > time_limit log "Time limit exceeded." report.call("Time limit exceeded", 0, "No comment.\n") end diff --git a/test/data/ev/test_yesno/script/check b/test/data/ev/test_yesno/script/check --- a/test/data/ev/test_yesno/script/check +++ b/test/data/ev/test_yesno/script/check @@ -1,4 +1,4 @@ -#!/usr/bin/ruby +#!/usr/bin/env ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" diff --git a/test/data/test_request/problems/test_normal/script/check b/test/data/test_request/problems/test_normal/script/check --- a/test/data/test_request/problems/test_normal/script/check +++ b/test/data/test_request/problems/test_normal/script/check @@ -1,4 +1,4 @@ -#!/usr/bin/ruby +#!/usr/bin/env ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb"