Description:
clean up run command to check for running time / memory merge check.float
Commit status:
[Not Reviewed]
References:
merge algo
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r161:d5a0f0a406b5 - - 4 files changed: 82 inserted, 9 deleted

@@ -0,0 +1,66
1 + #!/usr/bin/env ruby
2 +
3 + problem_home = ENV['PROBLEM_HOME']
4 + require "#{problem_home}/script/test_dsl.rb"
5 +
6 + if ARGV.length < 2
7 + puts "Usage: check <language> <test-number> [<output-file>]"
8 + exit(0)
9 + end
10 +
11 + language = ARGV[0]
12 + test_num = ARGV[1].to_i
13 + if ARGV.length >= 3
14 + output_file_name = ARGV[2]
15 + else
16 + output_file_name = "output.txt"
17 + end
18 +
19 + load "#{problem_home}/test_cases/all_tests.cfg"
20 + problem = Problem.get_instance
21 +
22 + output_file = File.new(output_file_name, "r")
23 + answer_file = File.new("#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt")
24 + result_file = File.new("check_result", "w")
25 +
26 + output_file_content = output_file.read
27 + answer_file_content = answer_file.read
28 +
29 + report_correct = lambda {
30 + result_file.write "Correct\n"
31 + result_file.write problem.get_score(test_num)
32 + result_file.write "\n"
33 + result_file.close
34 + exit(0)
35 + }
36 +
37 + report_wrong = lambda {
38 + result_file.write "Incorrect\n"
39 + result_file.write "0\n"
40 + result_file.close
41 + exit(0)
42 + }
43 +
44 + ##################
45 + # Your code here #
46 + ##################
47 +
48 + ########### THIS IS FOR CHECKING FLOAT with EPSILON error ##########
49 +
50 + EPSILON = 0.000001
51 +
52 + out_items = output_file_content.split
53 + ans_items = answer_file_content.split
54 +
55 + if out_items.length != ans_items.length
56 + report_wrong.call
57 + else
58 + out_items.length.times do |i|
59 + out_value = out_items[i].to_f
60 + ans_value = ans_items[i].to_f
61 + if (out_value - ans_value).abs > EPSILON * [out_value.abs,ans_value.abs].max
62 + report_wrong.call
63 + end
64 + end
65 + report_correct.call
66 + end
@@ -102,64 +102,65
102 command = "#{PASCAL_COMPILER} #{params[:source_file]} -ooutpas #{PASCAL_OPTIONS} > #{params[:message_file]}"
102 command = "#{PASCAL_COMPILER} #{params[:source_file]} -ooutpas #{PASCAL_OPTIONS} > #{params[:message_file]}"
103 system(command)
103 system(command)
104 FileUtils.mv("output", params[:output_file])
104 FileUtils.mv("output", params[:output_file])
105
105
106 when "java"
106 when "java"
107 #rename the file to the public class name
107 #rename the file to the public class name
108
108
109 #get the class name
109 #get the class name
110 classname = 'DUMMY'
110 classname = 'DUMMY'
111 File.foreach(params[:source_file]) do |line|
111 File.foreach(params[:source_file]) do |line|
112 md = /\s*public\s*class\s*(\w*)/.match(line)
112 md = /\s*public\s*class\s*(\w*)/.match(line)
113 classname=md[1] if md
113 classname=md[1] if md
114 end
114 end
115 system("cp #{params[:source_file]} #{classname}.java")
115 system("cp #{params[:source_file]} #{classname}.java")
116 command = "#{JAVA_COMPILER} #{classname}.java 2> #{params[:message_file]}"
116 command = "#{JAVA_COMPILER} #{classname}.java 2> #{params[:message_file]}"
117 system(command)
117 system(command)
118 if File.exists?(classname + ".class")
118 if File.exists?(classname + ".class")
119 File.open(params[:output_file],"w") {|file| file.write("#{classname}")}
119 File.open(params[:output_file],"w") {|file| file.write("#{classname}")}
120 end
120 end
121 if classname == 'DUMMY'
121 if classname == 'DUMMY'
122 File.open(params[:message_file],"w") {|file| file.write("Cannot find any public class in the source code\n")}
122 File.open(params[:message_file],"w") {|file| file.write("Cannot find any public class in the source code\n")}
123 end
123 end
124
124
125 when "ruby"
125 when "ruby"
126 command = "#{RUBY_INTERPRETER} -c #{params[:source_file]} 2> #{params[:message_file]}"
126 command = "#{RUBY_INTERPRETER} -c #{params[:source_file]} 2> #{params[:message_file]}"
127 if system(command)
127 if system(command)
128 File.open(params[:output_file],"w") do |out_file|
128 File.open(params[:output_file],"w") do |out_file|
129 out_file.puts "#!#{RUBY_INTERPRETER}"
129 out_file.puts "#!#{RUBY_INTERPRETER}"
130 File.open(params[:source_file],"r").each do |line|
130 File.open(params[:source_file],"r").each do |line|
131 out_file.print line
131 out_file.print line
132 end
132 end
133 end
133 end
134 File.chmod(0755, params[:output_file])
134 File.chmod(0755, params[:output_file])
135 end
135 end
136
136
137 when "python"
137 when "python"
138 command = "#{PYTHON_CHECKER} #{params[:source_file]} > #{params[:message_file]}"
138 command = "#{PYTHON_CHECKER} #{params[:source_file]} > #{params[:message_file]}"
139 if system(command)
139 if system(command)
140 #compile to python bytecode
140 #compile to python bytecode
141 command = "#{PYTHON_INTERPRETER} -m py_compile #{params[:source_file]}"
141 command = "#{PYTHON_INTERPRETER} -m py_compile #{params[:source_file]}"
142 puts "compile: #{command}"
142 puts "compile: #{command}"
143 system(command)
143 system(command)
144 puts "pwd: " + Dir.pwd
144 puts "pwd: " + Dir.pwd
145 Dir.new('.').each {|file| puts file}
145 Dir.new('.').each {|file| puts file}
146 File.open(params[:output_file],"w") do |out_file|
146 File.open(params[:output_file],"w") do |out_file|
147 out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c"
147 out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c"
148 end
148 end
149 File.chmod(0755, params[:output_file])
149 File.chmod(0755, params[:output_file])
150 + FileUtils.cp("#{params[:source_file]}c",params[:output_file])
150 end
151 end
151
152
152 else
153 else
153 talk("ERROR: Invalid language specified!")
154 talk("ERROR: Invalid language specified!")
154 open(params[:message_file],"w") do |f|
155 open(params[:message_file],"w") do |f|
155 f.puts "ERROR: Invalid language specified!"
156 f.puts "ERROR: Invalid language specified!"
156 end
157 end
157 exit(127)
158 exit(127)
158 end
159 end
159
160
160 # Report success or failure.
161 # Report success or failure.
161 if FileTest.exists? params[:output_file]
162 if FileTest.exists? params[:output_file]
162 talk "Compilation was successful!"
163 talk "Compilation was successful!"
163 else
164 else
164 talk "ERROR: Something was wrong during the compilation!"
165 talk "ERROR: Something was wrong during the compilation!"
165 end
166 end
@@ -14,166 +14,167
14 end
14 end
15 end
15 end
16
16
17 problem_home = ENV['PROBLEM_HOME']
17 problem_home = ENV['PROBLEM_HOME']
18
18
19 def execute(command, error_message="")
19 def execute(command, error_message="")
20 if not system(command)
20 if not system(command)
21 msg = "ERROR: #{error_message}"
21 msg = "ERROR: #{error_message}"
22 log msg
22 log msg
23 raise(msg)
23 raise(msg)
24 end
24 end
25 end
25 end
26
26
27 def call_and_log(error_message)
27 def call_and_log(error_message)
28 begin
28 begin
29 yield
29 yield
30 rescue
30 rescue
31 msg = "ERROR: #{error_message}"
31 msg = "ERROR: #{error_message}"
32 log msg
32 log msg
33 raise msg
33 raise msg
34 end
34 end
35 end
35 end
36
36
37 def clear_and_create_empty_dir(dir)
37 def clear_and_create_empty_dir(dir)
38 FileUtils.rm_rf(dir, :secure => true)
38 FileUtils.rm_rf(dir, :secure => true)
39 call_and_log("Cannot make directory #{dir}.") { FileUtils.mkdir(dir) }
39 call_and_log("Cannot make directory #{dir}.") { FileUtils.mkdir(dir) }
40 end
40 end
41
41
42 # ARGV[0] --- language
42 # ARGV[0] --- language
43 # ARGV[1] --- program source file
43 # ARGV[1] --- program source file
44 # ARGV[2] --- test result directory
44 # ARGV[2] --- test result directory
45 # ARGV[3] --- sandbox directory
45 # ARGV[3] --- sandbox directory
46
46
47 if ARGV.length < 2 || ARGV.length > 4
47 if ARGV.length < 2 || ARGV.length > 4
48 puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]"
48 puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]"
49 puts " <sandbox-directory> is defaulted to ./sandbox"
49 puts " <sandbox-directory> is defaulted to ./sandbox"
50 puts " <test-result-directory> is defaulted to ./test-result"
50 puts " <test-result-directory> is defaulted to ./test-result"
51 puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it."
51 puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it."
52 exit(127)
52 exit(127)
53 end
53 end
54
54
55 language = ARGV[0]
55 language = ARGV[0]
56 if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" && language != "python"
56 if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" && language != "python"
57 log "You specified a language that is not supported: #{language}."
57 log "You specified a language that is not supported: #{language}."
58 exit(127)
58 exit(127)
59 end
59 end
60
60
61 source_file = ARGV[1]
61 source_file = ARGV[1]
62 + ENV['SOURCE_NAME'] = source_file
62 if File.exist?(source_file) == false
63 if File.exist?(source_file) == false
63 log "The source file does not exist."
64 log "The source file does not exist."
64 exit(127)
65 exit(127)
65 end
66 end
66
67
67 log "Making test result and sandbox directories..."
68 log "Making test result and sandbox directories..."
68
69
69 current_dir = FileUtils.pwd
70 current_dir = FileUtils.pwd
70 current_dir.strip!
71 current_dir.strip!
71
72
72 if ARGV.length >= 3
73 if ARGV.length >= 3
73 test_result_dir = ARGV[2]
74 test_result_dir = ARGV[2]
74 else
75 else
75 test_result_dir = "#{current_dir}/test-result"
76 test_result_dir = "#{current_dir}/test-result"
76 end
77 end
77
78
78 log "Test result directory: #{test_result_dir}"
79 log "Test result directory: #{test_result_dir}"
79 clear_and_create_empty_dir(test_result_dir)
80 clear_and_create_empty_dir(test_result_dir)
80
81
81 if ARGV.length >= 4
82 if ARGV.length >= 4
82 sandbox_dir = ARGV[3]
83 sandbox_dir = ARGV[3]
83 else
84 else
84 sandbox_dir = "#{current_dir}/sandbox"
85 sandbox_dir = "#{current_dir}/sandbox"
85 end
86 end
86 log "Sandbox directory: #{sandbox_dir}"
87 log "Sandbox directory: #{sandbox_dir}"
87 clear_and_create_empty_dir(sandbox_dir)
88 clear_and_create_empty_dir(sandbox_dir)
88
89
89 # Compile
90 # Compile
90 log
91 log
91 log "Compiling..."
92 log "Compiling..."
92 call_and_log("Cannot copy the source file to #{sandbox_dir}") {
93 call_and_log("Cannot copy the source file to #{sandbox_dir}") {
93 FileUtils.cp(source_file, sandbox_dir)
94 FileUtils.cp(source_file, sandbox_dir)
94 }
95 }
95 begin
96 begin
96 Dir.chdir sandbox_dir
97 Dir.chdir sandbox_dir
97 rescue
98 rescue
98 log "ERROR: Cannot change directory to #{sandbox_dir}."
99 log "ERROR: Cannot change directory to #{sandbox_dir}."
99 exit(127)
100 exit(127)
100 end
101 end
101 execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!")
102 execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!")
102 compile_message = open("compiler_message").read
103 compile_message = open("compiler_message").read
103 compile_message.strip!
104 compile_message.strip!
104 call_and_log("Cannot move the compiler message to #{test_result_dir}.") {
105 call_and_log("Cannot move the compiler message to #{test_result_dir}.") {
105 FileUtils.mv("compiler_message", test_result_dir)
106 FileUtils.mv("compiler_message", test_result_dir)
106 }
107 }
107 if !FileTest.exist?("a.out")
108 if !FileTest.exist?("a.out")
108 log "Cannot compile the source code. See message in #{test_result_dir}/compile_message"
109 log "Cannot compile the source code. See message in #{test_result_dir}/compile_message"
109 exit(127)
110 exit(127)
110 else
111 else
111 call_and_log("Cannot move the compiled program to #{test_result_dir}") {
112 call_and_log("Cannot move the compiled program to #{test_result_dir}") {
112 FileUtils.mv("a.out",test_result_dir)
113 FileUtils.mv("a.out",test_result_dir)
113 if language == "java" then Dir["*.class"].each { |file| FileUtils.mv(file,test_result_dir)} end
114 if language == "java" then Dir["*.class"].each { |file| FileUtils.mv(file,test_result_dir)} end
114 if language == "python" then Dir["*.pyc"].each { |file| FileUtils.mv(file,test_result_dir)} end
115 if language == "python" then Dir["*.pyc"].each { |file| FileUtils.mv(file,test_result_dir)} end
115 }
116 }
116 FileUtils.rm_rf("#{sandbox_dir}/.")
117 FileUtils.rm_rf("#{sandbox_dir}/.")
117 end
118 end
118
119
119 require "#{problem_home}/script/test_dsl.rb"
120 require "#{problem_home}/script/test_dsl.rb"
120 load "#{problem_home}/test_cases/all_tests.cfg"
121 load "#{problem_home}/test_cases/all_tests.cfg"
121 problem = Problem.get_instance
122 problem = Problem.get_instance
122
123
123 if problem.well_formed? == false
124 if problem.well_formed? == false
124 log "The problem specification is not well formed."
125 log "The problem specification is not well formed."
125 exit(127)
126 exit(127)
126 end
127 end
127
128
128 # Doing the testing.
129 # Doing the testing.
129 (1..(problem.num_tests)).each do |test_num|
130 (1..(problem.num_tests)).each do |test_num|
130
131
131 $stdout.print "[#{test_num}]"
132 $stdout.print "[#{test_num}]"
132 $stdout.flush
133 $stdout.flush
133
134
134 log "Test number: #{test_num}"
135 log "Test number: #{test_num}"
135
136
136 call_and_log("Cannot copy the compiled program into #{sandbox_dir}") {
137 call_and_log("Cannot copy the compiled program into #{sandbox_dir}") {
137 FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir, :preserve => true)
138 FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir, :preserve => true)
138 if language == "java" then Dir["#{test_result_dir}/*.class"].each { |file| FileUtils.cp(file,sandbox_dir)} end
139 if language == "java" then Dir["#{test_result_dir}/*.class"].each { |file| FileUtils.cp(file,sandbox_dir)} end
139 if language == "python" then Dir["#{test_result_dir}/*.pyc"].each { |file| FileUtils.cp(file,sandbox_dir)} end
140 if language == "python" then Dir["#{test_result_dir}/*.pyc"].each { |file| FileUtils.cp(file,sandbox_dir)} end
140 }
141 }
141
142
142 begin
143 begin
143 - execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script")
144 + execute("#{problem_home}/script/run #{language} #{test_num} ", "Error occured during execution of the run script")
144 rescue
145 rescue
145 # do nothing
146 # do nothing
146 end
147 end
147
148
148 call_and_log("Cannot create directory #{test_result_dir}/#{test_num}") {
149 call_and_log("Cannot create directory #{test_result_dir}/#{test_num}") {
149 FileUtils.mkdir "#{test_result_dir}/#{test_num}"
150 FileUtils.mkdir "#{test_result_dir}/#{test_num}"
150 }
151 }
151 call_and_log("Cannot copy the result file into #{test_result_dir}/#{test_num}") {
152 call_and_log("Cannot copy the result file into #{test_result_dir}/#{test_num}") {
152 FileUtils.mv "#{sandbox_dir}/result", "#{test_result_dir}/#{test_num}"
153 FileUtils.mv "#{sandbox_dir}/result", "#{test_result_dir}/#{test_num}"
153 }
154 }
154 call_and_log("Cannot copy the comment file into #{test_result_dir}/#{test_num}") {
155 call_and_log("Cannot copy the comment file into #{test_result_dir}/#{test_num}") {
155 FileUtils.mv "#{sandbox_dir}/comment", "#{test_result_dir}/#{test_num}"
156 FileUtils.mv "#{sandbox_dir}/comment", "#{test_result_dir}/#{test_num}"
156 }
157 }
157 call_and_log("Cannot copy the output file into #{test_result_dir}/#{test_num}") {
158 call_and_log("Cannot copy the output file into #{test_result_dir}/#{test_num}") {
158 FileUtils.mv "#{sandbox_dir}/output.txt", "#{test_result_dir}/#{test_num}"
159 FileUtils.mv "#{sandbox_dir}/output.txt", "#{test_result_dir}/#{test_num}"
159 }
160 }
160 call_and_log("Cannot clear #{sandbox_dir}") {
161 call_and_log("Cannot clear #{sandbox_dir}") {
161 FileUtils.rm_rf(Dir.glob("#{sandbox_dir}/*"), :secure => true)
162 FileUtils.rm_rf(Dir.glob("#{sandbox_dir}/*"), :secure => true)
162 }
163 }
163 end
164 end
164
165
165 $stdout.print "[done]\n"
166 $stdout.print "[done]\n"
166
167
167 # Grade
168 # Grade
168 log
169 log
169 log "Grading..."
170 log "Grading..."
170 begin
171 begin
171 Dir.chdir test_result_dir
172 Dir.chdir test_result_dir
172 rescue
173 rescue
173 log "ERROR: Cannot change directory to #{test_result_dir}."
174 log "ERROR: Cannot change directory to #{test_result_dir}."
174 exit(127)
175 exit(127)
175 end
176 end
176 execute("#{problem_home}/script/grade", "An error occured during grading!")
177 execute("#{problem_home}/script/grade", "An error occured during grading!")
177
178
178 log
179 log
179 log "All done!"
180 log "All done!"
@@ -1,181 +1,186
1 #!/usr/bin/env ruby
1 #!/usr/bin/env ruby
2
2
3 require 'fileutils'
3 require 'fileutils'
4
4
5 def log(str='')
5 def log(str='')
6 if ENV['TALKATIVE']!=nil
6 if ENV['TALKATIVE']!=nil
7 puts str
7 puts str
8 end
8 end
9 if ENV['GRADER_LOGGING']!=nil
9 if ENV['GRADER_LOGGING']!=nil
10 log_fname = ENV['GRADER_LOGGING']
10 log_fname = ENV['GRADER_LOGGING']
11 fp = File.open(log_fname,"a")
11 fp = File.open(log_fname,"a")
12 fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}")
12 fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}")
13 fp.close
13 fp.close
14 end
14 end
15 end
15 end
16
16
17 def extract_time(t)
17 def extract_time(t)
18 # puts "TIME: #{t}"
18 # puts "TIME: #{t}"
19 if (result=/^(.*)r(.*)u(.*)s/.match(t))
19 if (result=/^(.*)r(.*)u(.*)s/.match(t))
20 {:real => result[1], :user => result[2], :sys => result[3]}
20 {:real => result[1], :user => result[2], :sys => result[3]}
21 else
21 else
22 #{:real => 0, :user => 0, :sys => 0}
22 #{:real => 0, :user => 0, :sys => 0}
23 #puts "ERROR READING RUNNING TIME: #{t}"
23 #puts "ERROR READING RUNNING TIME: #{t}"
24 raise "Error reading running time: #{t}"
24 raise "Error reading running time: #{t}"
25 end
25 end
26 end
26 end
27
27
28 def compile_box(source,bin)
28 def compile_box(source,bin)
29 system("g++ #{source} -o #{bin}")
29 system("g++ #{source} -o #{bin}")
30 end
30 end
31
31
32 if ARGV.length < 2 || ARGV.length > 3
32 if ARGV.length < 2 || ARGV.length > 3
33 puts "Usage: run <language> <test-num> [<program-name>]"
33 puts "Usage: run <language> <test-num> [<program-name>]"
34 exit(127)
34 exit(127)
35 end
35 end
36
36
37 language = ARGV[0]
37 language = ARGV[0]
38 test_num = ARGV[1].to_i
38 test_num = ARGV[1].to_i
39 if ARGV.length > 2
39 if ARGV.length > 2
40 program_name = ARGV[2]
40 program_name = ARGV[2]
41 else
41 else
42 program_name = "a.out"
42 program_name = "a.out"
43 end
43 end
44
44
45 problem_home = ENV['PROBLEM_HOME']
45 problem_home = ENV['PROBLEM_HOME']
46 + source_name = ENV['SOURCE_NAME']
46 require "#{problem_home}/script/test_dsl.rb"
47 require "#{problem_home}/script/test_dsl.rb"
47 load "#{problem_home}/test_cases/all_tests.cfg"
48 load "#{problem_home}/test_cases/all_tests.cfg"
48 problem = Problem.get_instance
49 problem = Problem.get_instance
49
50
51 + sandbox_dir = Dir.getwd
52 +
50 if problem.well_formed? == false
53 if problem.well_formed? == false
51 log "The problem specification is not well formed."
54 log "The problem specification is not well formed."
52 exit(127)
55 exit(127)
53 end
56 end
54
57
55 # Check if the test number is okay.
58 # Check if the test number is okay.
56 if test_num <= 0 || test_num > problem.num_tests
59 if test_num <= 0 || test_num > problem.num_tests
57 log "You have specified a wrong test number."
60 log "You have specified a wrong test number."
58 exit(127)
61 exit(127)
59 end
62 end
60
63
61 #####################################
64 #####################################
62 # Set the relavant file names here. #
65 # Set the relavant file names here. #
63 #####################################
66 #####################################
64
67
65 input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt"
68 input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt"
66
69
67 #####################################
70 #####################################
68
71
69 time_limit = problem.get_time_limit test_num
72 time_limit = problem.get_time_limit test_num
70 mem_limit = problem.get_mem_limit(test_num) * 1024
73 mem_limit = problem.get_mem_limit(test_num) * 1024
71
74
72 # Copy the input file.
75 # Copy the input file.
73 #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .`
76 #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .`
74
77
75 # check if box is there, if not, compile it!
78 # check if box is there, if not, compile it!
76 if !File.exists?("#{problem_home}/script/box")
79 if !File.exists?("#{problem_home}/script/box")
77 log "WARNING: Compiling box: to increase efficiency, it should be compile manually"
80 log "WARNING: Compiling box: to increase efficiency, it should be compile manually"
78 compile_box("#{problem_home}/script/box.cc",
81 compile_box("#{problem_home}/script/box.cc",
79 "#{problem_home}/script/box")
82 "#{problem_home}/script/box")
80 end
83 end
81
84
82 # Hide PROBLEM_HOME
85 # Hide PROBLEM_HOME
83 ENV['PROBLEM_HOME'] = nil
86 ENV['PROBLEM_HOME'] = nil
87 + ENV['SOURCE_NAME'] = nil
84
88
85 # Run the program.
89 # Run the program.
86 #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}"
90 #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}"
87 #
91 #
88
92
89 -
93 + JAVA_OPTION = "-s set_robust_list -s futex -s clone -s getppid -s clone -s wait4 -p /usr/bin/ -p ./"
90 -
94 + 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"
95 + 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"
91
96
92 case language
97 case language
93 when "java"
98 when "java"
94 -
95 # for java, extract the classname
99 # for java, extract the classname
96 # wne have to add additional systemcall and we don't check the mem limit (dunno how to fix...)
100 # wne have to add additional systemcall and we don't check the mem limit (dunno how to fix...)
97 classname = 'DUMMY'
101 classname = 'DUMMY'
98 File.open(program_name,"r").each do |line|
102 File.open(program_name,"r").each do |line|
99 classname = line
103 classname = line
100 end
104 end
101 - 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"
105 + #for java, we cannot really check the memory limit...
106 + 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"
102 when "ruby"
107 when "ruby"
103 - 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"
108 + 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"
104 when "python"
109 when "python"
105 - #this code just run without any checking
110 + 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"
106 - 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"
107 else # for c++, pascal, we do the normal checking
111 else # for c++, pascal, we do the normal checking
108 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"
112 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"
109 end
113 end
110
114
111
115
112 log "Running test #{test_num}..."
116 log "Running test #{test_num}..."
113 log run_command
117 log run_command
114 - log
118 + log
115 system(run_command)
119 system(run_command)
116
120
117 # Restore PROBLEM_HOME
121 # Restore PROBLEM_HOME
118 ENV['PROBLEM_HOME'] = problem_home
122 ENV['PROBLEM_HOME'] = problem_home
119
123
120 # Create the result file.
124 # Create the result file.
121 result_file = File.new("result", "w")
125 result_file = File.new("result", "w")
122 comment_file = File.new("comment", "w")
126 comment_file = File.new("comment", "w")
123
127
124 # Check if the program actually produced any output.
128 # Check if the program actually produced any output.
125 run_result_file = File.new("run_result", "r")
129 run_result_file = File.new("run_result", "r")
126 run_result = run_result_file.readlines
130 run_result = run_result_file.readlines
127 run_result_file.close
131 run_result_file.close
128
132
129 run_stat = run_result[run_result.length-1]
133 run_stat = run_result[run_result.length-1]
130 running_time = extract_time(run_stat)
134 running_time = extract_time(run_stat)
131
135
132 report = lambda{ |status, points, comment|
136 report = lambda{ |status, points, comment|
133 result_file.write status.strip
137 result_file.write status.strip
134 result_file.write "\n"
138 result_file.write "\n"
135 result_file.write points.to_s.strip
139 result_file.write points.to_s.strip
136 result_file.write "\n"
140 result_file.write "\n"
137 result_file.write run_stat.strip
141 result_file.write run_stat.strip
138 result_file.write "\n"
142 result_file.write "\n"
139 result_file.close
143 result_file.close
140 FileUtils.rm "run_result"
144 FileUtils.rm "run_result"
141 # `rm output.txt` --- keep the output
145 # `rm output.txt` --- keep the output
142
146
143 comment_file.write comment
147 comment_file.write comment
144
148
145 # added for debuggin --- jittat
149 # added for debuggin --- jittat
146 comment_file.write "--run-result--\n"
150 comment_file.write "--run-result--\n"
147 run_result.each do |l|
151 run_result.each do |l|
148 comment_file.write l
152 comment_file.write l
149 end
153 end
150
154
151 comment_file.close
155 comment_file.close
152
156
153 log "Done!"
157 log "Done!"
154 exit(0)
158 exit(0)
155 }
159 }
156
160
161 +
157 if run_result[0][0,2] != "OK"
162 if run_result[0][0,2] != "OK"
158 log "There was a runtime error."
163 log "There was a runtime error."
159 report.call(run_result[0], 0, "No comment.\n")
164 report.call(run_result[0], 0, "No comment.\n")
160 end
165 end
161
166
162 if running_time[:user].to_f > time_limit
167 if running_time[:user].to_f > time_limit
163 log "Time limit exceeded."
168 log "Time limit exceeded."
164 report.call("Time limit exceeded", 0, "No comment.\n")
169 report.call("Time limit exceeded", 0, "No comment.\n")
165 end
170 end
166
171
167 # Run 'check' to evaluate the output.
172 # Run 'check' to evaluate the output.
168 #puts "There was no runtime error. Proceed to checking the output."
173 #puts "There was no runtime error. Proceed to checking the output."
169 check_command = "#{problem_home}/script/check #{language} #{test_num}"
174 check_command = "#{problem_home}/script/check #{language} #{test_num}"
170 log "Checking the output..."
175 log "Checking the output..."
171 log check_command
176 log check_command
172 if not system(check_command)
177 if not system(check_command)
173 log "Problem with check script"
178 log "Problem with check script"
174 report.call("Incorrect",0,"Check script error.\n")
179 report.call("Incorrect",0,"Check script error.\n")
175 exit(127)
180 exit(127)
176 end
181 end
177
182
178 check_file = File.new("check_result", "r")
183 check_file = File.new("check_result", "r")
179 check_file_lines = check_file.readlines
184 check_file_lines = check_file.readlines
180
185
181 report.call(check_file_lines[0], check_file_lines[1], "No comment.\n")
186 report.call(check_file_lines[0], check_file_lines[1], "No comment.\n")
You need to be logged in to leave comments. Login now