Description:
add dump submission & octave
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r261:4eedd9c42b48 - - 4 files changed: 62 inserted, 1 deleted
@@ -0,0 +1,45 | |||||
|
|
1 | + #!/usr/bin/env ruby | ||
|
|
2 | + | ||
|
|
3 | + require 'fileutils' | ||
|
|
4 | + | ||
|
|
5 | + ENVIRONMENT_DIRS = ['ev', 'ev-exam'] | ||
|
|
6 | + | ||
|
|
7 | + def config | ||
|
|
8 | + Grader::Configuration.get_instance | ||
|
|
9 | + end | ||
|
|
10 | + | ||
|
|
11 | + def usage | ||
|
|
12 | + puts <<USAGE | ||
|
|
13 | + Usage: | ||
|
|
14 | + dump_submission prob_id1 prob_id2 prob_id3 ... | ||
|
|
15 | + | ||
|
|
16 | + This will dumps all submission of the given problem ids into <current_dir>/<problem_name>/<user login>/<submission_id> | ||
|
|
17 | + USAGE | ||
|
|
18 | + end | ||
|
|
19 | + | ||
|
|
20 | + if (ARGV.length == 0) | ||
|
|
21 | + usage | ||
|
|
22 | + exit(0) | ||
|
|
23 | + end | ||
|
|
24 | + | ||
|
|
25 | + # load grader environment | ||
|
|
26 | + GRADER_ENV = 'grading' | ||
|
|
27 | + require File.join(File.dirname(__FILE__),'config/environment') | ||
|
|
28 | + | ||
|
|
29 | + # boot rails, to be able to rename the problem | ||
|
|
30 | + RAILS_ENV = config.rails_env | ||
|
|
31 | + require RAILS_ROOT + '/config/environment' | ||
|
|
32 | + | ||
|
|
33 | + prob_ids = ARGV.map{ |x| x.to_i} | ||
|
|
34 | + | ||
|
|
35 | + | ||
|
|
36 | + prob_ids.each do |id| | ||
|
|
37 | + p = Problem.find(id) | ||
|
|
38 | + p.submissions.each do |s| | ||
|
|
39 | + dir = "#{p.name}/#{s.user.login}/#{s.id}.#{s.language.ext}" | ||
|
|
40 | + filename = "#{s.id}.#{s.language.ext}" | ||
|
|
41 | + FileUtils.mkdir_p dir | ||
|
|
42 | + File.write("#{dir}/#{filename}",s.source) | ||
|
|
43 | + puts filename | ||
|
|
44 | + end | ||
|
|
45 | + end |
@@ -1,202 +1,215 | |||||
|
1 | #!/usr/bin/env ruby |
|
1 | #!/usr/bin/env ruby |
|
2 |
|
2 | ||
|
3 | require 'fileutils' |
|
3 | require 'fileutils' |
|
4 |
|
4 | ||
|
5 | ############################## |
|
5 | ############################## |
|
6 | # |
|
6 | # |
|
7 | # Standard Compile Script |
|
7 | # Standard Compile Script |
|
8 | # |
|
8 | # |
|
9 | # Supported compilers: |
|
9 | # Supported compilers: |
|
10 | # gcc, g++, and fpc. |
|
10 | # gcc, g++, and fpc. |
|
11 | # |
|
11 | # |
|
12 | ############################## |
|
12 | ############################## |
|
13 |
|
13 | ||
|
14 | def talk(str='') |
|
14 | def talk(str='') |
|
15 | if ENV['TALKATIVE']!=nil |
|
15 | if ENV['TALKATIVE']!=nil |
|
16 | puts str |
|
16 | puts str |
|
17 | end |
|
17 | end |
|
18 | if ENV['GRADER_LOGGING']!=nil |
|
18 | if ENV['GRADER_LOGGING']!=nil |
|
19 | log_fname = ENV['GRADER_LOGGING'] |
|
19 | log_fname = ENV['GRADER_LOGGING'] |
|
20 | fp = File.open(log_fname,"a") |
|
20 | fp = File.open(log_fname,"a") |
|
21 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
21 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
22 | fp.close |
|
22 | fp.close |
|
23 | end |
|
23 | end |
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | C_COMPILER = "/usr/bin/gcc" |
|
26 | C_COMPILER = "/usr/bin/gcc" |
|
27 | CPLUSPLUS_COMPILER = "/usr/bin/g++" |
|
27 | CPLUSPLUS_COMPILER = "/usr/bin/g++" |
|
28 | PASCAL_COMPILER = "/usr/bin/fpc" |
|
28 | PASCAL_COMPILER = "/usr/bin/fpc" |
|
29 | JAVA_COMPILER = "/usr/bin/javac" |
|
29 | JAVA_COMPILER = "/usr/bin/javac" |
|
30 | RUBY_INTERPRETER = "/usr/bin/ruby" |
|
30 | RUBY_INTERPRETER = "/usr/bin/ruby" |
|
31 | PYTHON_INTERPRETER = "/usr/bin/python3" |
|
31 | PYTHON_INTERPRETER = "/usr/bin/python3" |
|
32 | PYTHON_CHECKER = "/usr/bin/pyflakes" |
|
32 | PYTHON_CHECKER = "/usr/bin/pyflakes" |
|
33 | PHP_INTERPRETER = "/usr/bin/php" |
|
33 | PHP_INTERPRETER = "/usr/bin/php" |
|
34 | HASKELL_COMPILER = "/usr/bin/ghc" |
|
34 | HASKELL_COMPILER = "/usr/bin/ghc" |
|
|
35 | + OCTAVE_INTERPRETER = "/usr/bin/octave" | ||
|
35 |
|
36 | ||
|
36 | C_OPTIONS = "-O2 -s -static -std=c99 -DCONTEST -lm -Wall" |
|
37 | C_OPTIONS = "-O2 -s -static -std=c99 -DCONTEST -lm -Wall" |
|
37 | CPLUSPLUS_OPTIONS = "-O2 -s -std=c++11 -static -DCONTEST -lm -Wall" |
|
38 | CPLUSPLUS_OPTIONS = "-O2 -s -std=c++11 -static -DCONTEST -lm -Wall" |
|
38 | PASCAL_OPTIONS = "-O1 -XS -dCONTEST" |
|
39 | PASCAL_OPTIONS = "-O1 -XS -dCONTEST" |
|
39 | JAVA_OPTIONS = "" |
|
40 | JAVA_OPTIONS = "" |
|
40 | PYTHON_OPTIONS = "" |
|
41 | PYTHON_OPTIONS = "" |
|
41 | PHP_OPTIONS = "-l" |
|
42 | PHP_OPTIONS = "-l" |
|
42 | HASKELL_OPTIONS = "" |
|
43 | HASKELL_OPTIONS = "" |
|
43 |
|
44 | ||
|
44 | # Check for the correct number of arguments. Otherwise, print usage. |
|
45 | # Check for the correct number of arguments. Otherwise, print usage. |
|
45 | if ARGV.length == 0 or ARGV.length > 4 |
|
46 | if ARGV.length == 0 or ARGV.length > 4 |
|
46 | puts "Usage: compile <language> [<source-file>] [<output-file>] [<message-file>]" |
|
47 | puts "Usage: compile <language> [<source-file>] [<output-file>] [<message-file>]" |
|
47 | puts |
|
48 | puts |
|
48 | puts "<source-file> is defaulted to \"source\"." |
|
49 | puts "<source-file> is defaulted to \"source\"." |
|
49 | puts "<output-file> is defaulted to \"a.out\"." |
|
50 | puts "<output-file> is defaulted to \"a.out\"." |
|
50 | puts "<message-file> is defaulted to \"compiler_message\"." |
|
51 | puts "<message-file> is defaulted to \"compiler_message\"." |
|
51 | puts |
|
52 | puts |
|
52 | exit(127) |
|
53 | exit(127) |
|
53 | end |
|
54 | end |
|
54 |
|
55 | ||
|
55 | PARAMS = { |
|
56 | PARAMS = { |
|
56 | :source_file => [1,'source'], |
|
57 | :source_file => [1,'source'], |
|
57 | :output_file => [2,'a.out'], |
|
58 | :output_file => [2,'a.out'], |
|
58 | :message_file => [3,'compiler_message'] |
|
59 | :message_file => [3,'compiler_message'] |
|
59 | } |
|
60 | } |
|
60 |
|
61 | ||
|
61 | params = {} |
|
62 | params = {} |
|
62 | params[:prog_lang] = ARGV[0] |
|
63 | params[:prog_lang] = ARGV[0] |
|
63 | PARAMS.each_key do |param_name| |
|
64 | PARAMS.each_key do |param_name| |
|
64 | index, default = PARAMS[param_name] |
|
65 | index, default = PARAMS[param_name] |
|
65 | if ARGV.length > index |
|
66 | if ARGV.length > index |
|
66 | params[param_name] = ARGV[index] |
|
67 | params[param_name] = ARGV[index] |
|
67 | else |
|
68 | else |
|
68 | params[param_name] = default |
|
69 | params[param_name] = default |
|
69 | end |
|
70 | end |
|
70 | talk "COMPILE: param: #{param_name}: #{params[param_name]}" |
|
71 | talk "COMPILE: param: #{param_name}: #{params[param_name]}" |
|
71 | end |
|
72 | end |
|
72 | talk "COMPILE: working dir = " + Dir.pwd |
|
73 | talk "COMPILE: working dir = " + Dir.pwd |
|
73 |
|
74 | ||
|
74 | # Remove any remaining output files or message files. |
|
75 | # Remove any remaining output files or message files. |
|
75 | if FileTest.exists? params[:output_file] |
|
76 | if FileTest.exists? params[:output_file] |
|
76 | FileUtils.rm(params[:output_file]) |
|
77 | FileUtils.rm(params[:output_file]) |
|
77 | end |
|
78 | end |
|
78 | if FileTest.exists? params[:message_file] |
|
79 | if FileTest.exists? params[:message_file] |
|
79 | FileUtils.rm(params[:message_file]) |
|
80 | FileUtils.rm(params[:message_file]) |
|
80 | end |
|
81 | end |
|
81 |
|
82 | ||
|
82 | # Check if the source file exists before attempt compiling. |
|
83 | # Check if the source file exists before attempt compiling. |
|
83 | if !FileTest.exists? params[:source_file] |
|
84 | if !FileTest.exists? params[:source_file] |
|
84 | talk("COMPILE: ERROR: The source file does not exist!") |
|
85 | talk("COMPILE: ERROR: The source file does not exist!") |
|
85 | open(params[:message_file],"w") do |f| |
|
86 | open(params[:message_file],"w") do |f| |
|
86 | f.puts "ERROR: The source file did not exist." |
|
87 | f.puts "ERROR: The source file did not exist." |
|
87 | end |
|
88 | end |
|
88 | exit(127) |
|
89 | exit(127) |
|
89 | end |
|
90 | end |
|
90 |
|
91 | ||
|
91 | if params[:prog_lang]=='cpp' |
|
92 | if params[:prog_lang]=='cpp' |
|
92 | params[:prog_lang] = 'c++' |
|
93 | params[:prog_lang] = 'c++' |
|
93 | end |
|
94 | end |
|
94 |
|
95 | ||
|
95 |
|
96 | ||
|
96 | # Compile. |
|
97 | # Compile. |
|
97 | case params[:prog_lang] |
|
98 | case params[:prog_lang] |
|
98 |
|
99 | ||
|
99 | when "c" |
|
100 | when "c" |
|
100 | command = "#{C_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{C_OPTIONS}" |
|
101 | command = "#{C_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{C_OPTIONS}" |
|
101 | talk "COMPILE: compiling command [#{command}]" |
|
102 | talk "COMPILE: compiling command [#{command}]" |
|
102 | system(command, err: params[:message_file]) |
|
103 | system(command, err: params[:message_file]) |
|
103 |
|
104 | ||
|
104 | when "c++" |
|
105 | when "c++" |
|
105 | command = "#{CPLUSPLUS_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{CPLUSPLUS_OPTIONS}" |
|
106 | command = "#{CPLUSPLUS_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{CPLUSPLUS_OPTIONS}" |
|
106 | talk "COMPILE: compiling command [#{command}]" |
|
107 | talk "COMPILE: compiling command [#{command}]" |
|
107 | system(command, err: params[:message_file]) |
|
108 | system(command, err: params[:message_file]) |
|
108 |
|
109 | ||
|
109 | when "pas" |
|
110 | when "pas" |
|
110 | command = "#{PASCAL_COMPILER} #{params[:source_file]} -ooutpas #{PASCAL_OPTIONS}" |
|
111 | command = "#{PASCAL_COMPILER} #{params[:source_file]} -ooutpas #{PASCAL_OPTIONS}" |
|
111 | talk "COMPILE: compiling command [#{command}]" |
|
112 | talk "COMPILE: compiling command [#{command}]" |
|
112 | system(command,out: params[:message_file]) |
|
113 | system(command,out: params[:message_file]) |
|
113 | FileUtils.mv("output", params[:output_file]) |
|
114 | FileUtils.mv("output", params[:output_file]) |
|
114 |
|
115 | ||
|
115 | when "java" |
|
116 | when "java" |
|
116 | #rename the file to the public class name |
|
117 | #rename the file to the public class name |
|
117 |
|
118 | ||
|
118 | #get the class name |
|
119 | #get the class name |
|
119 | classname = 'DUMMY' |
|
120 | classname = 'DUMMY' |
|
120 | source = Array.new |
|
121 | source = Array.new |
|
121 | File.foreach(params[:source_file],'r:UTF-8') do |line| |
|
122 | File.foreach(params[:source_file],'r:UTF-8') do |line| |
|
122 | line.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') |
|
123 | line.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') |
|
123 | md = /\s*public\s*class\s*(\w*)/.match(line) |
|
124 | md = /\s*public\s*class\s*(\w*)/.match(line) |
|
124 | classname=md[1] if md |
|
125 | classname=md[1] if md |
|
125 | source << line unless line =~ /\s*package\s*\w+\s*\;/ |
|
126 | source << line unless line =~ /\s*package\s*\w+\s*\;/ |
|
126 | end |
|
127 | end |
|
127 | File.open("#{classname}.java","w") do |file| |
|
128 | File.open("#{classname}.java","w") do |file| |
|
128 | source.each do |s| |
|
129 | source.each do |s| |
|
129 | file.puts s |
|
130 | file.puts s |
|
130 | end |
|
131 | end |
|
131 | end |
|
132 | end |
|
132 | #system("cp #{params[:source_file]} #{classname}.java") |
|
133 | #system("cp #{params[:source_file]} #{classname}.java") |
|
133 | command = "#{JAVA_COMPILER} -encoding utf8 #{classname}.java" |
|
134 | command = "#{JAVA_COMPILER} -encoding utf8 #{classname}.java" |
|
134 | talk "COMPILE: compiling command [#{command}]" |
|
135 | talk "COMPILE: compiling command [#{command}]" |
|
135 | system(command, err: params[:message_file]) |
|
136 | system(command, err: params[:message_file]) |
|
136 | if File.exists?(classname + ".class") |
|
137 | if File.exists?(classname + ".class") |
|
137 | File.open(params[:output_file],"w") {|file| file.write("#{classname}")} |
|
138 | File.open(params[:output_file],"w") {|file| file.write("#{classname}")} |
|
138 | end |
|
139 | end |
|
139 | if classname == 'DUMMY' |
|
140 | if classname == 'DUMMY' |
|
140 | File.open(params[:message_file],"w") {|file| file.write("Cannot find any public class in the source code\n")} |
|
141 | File.open(params[:message_file],"w") {|file| file.write("Cannot find any public class in the source code\n")} |
|
141 | end |
|
142 | end |
|
142 |
|
143 | ||
|
143 | when "ruby" |
|
144 | when "ruby" |
|
144 | command = "#{RUBY_INTERPRETER} -c #{params[:source_file]}" |
|
145 | command = "#{RUBY_INTERPRETER} -c #{params[:source_file]}" |
|
145 | talk "COMPILE: compiling command [#{command}]" |
|
146 | talk "COMPILE: compiling command [#{command}]" |
|
146 | if system(command, err: params[:message_file]) |
|
147 | if system(command, err: params[:message_file]) |
|
147 | File.open(params[:output_file],"w") do |out_file| |
|
148 | File.open(params[:output_file],"w") do |out_file| |
|
148 | out_file.puts "#!#{RUBY_INTERPRETER}" |
|
149 | out_file.puts "#!#{RUBY_INTERPRETER}" |
|
149 | File.open(params[:source_file],"r").each do |line| |
|
150 | File.open(params[:source_file],"r").each do |line| |
|
150 | out_file.print line |
|
151 | out_file.print line |
|
151 | end |
|
152 | end |
|
152 | end |
|
153 | end |
|
153 | File.chmod(0755, params[:output_file]) |
|
154 | File.chmod(0755, params[:output_file]) |
|
154 | end |
|
155 | end |
|
155 |
|
156 | ||
|
156 | when "python" |
|
157 | when "python" |
|
157 | #command = "#{PYTHON_CHECKER} #{params[:source_file]}" |
|
158 | #command = "#{PYTHON_CHECKER} #{params[:source_file]}" |
|
158 | #if system(command, out: params[:message_file]) |
|
159 | #if system(command, out: params[:message_file]) |
|
159 | #compile to python bytecode |
|
160 | #compile to python bytecode |
|
160 | command = "#{PYTHON_INTERPRETER} -c \"import py_compile; py_compile.compile('#{params[:source_file]}','#{params[:source_file]}c');\"" |
|
161 | command = "#{PYTHON_INTERPRETER} -c \"import py_compile; py_compile.compile('#{params[:source_file]}','#{params[:source_file]}c');\"" |
|
161 | talk "COMPILE: compiling command [#{command}]" |
|
162 | talk "COMPILE: compiling command [#{command}]" |
|
162 | system(command, err: params[:message_file]) |
|
163 | system(command, err: params[:message_file]) |
|
163 | if FileTest.exists?("#{params[:source_file]}c") |
|
164 | if FileTest.exists?("#{params[:source_file]}c") |
|
164 | File.open(params[:output_file],"w") do |out_file| |
|
165 | File.open(params[:output_file],"w") do |out_file| |
|
165 | out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c" |
|
166 | out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c" |
|
166 | end |
|
167 | end |
|
167 | File.chmod(0755, params[:output_file]) |
|
168 | File.chmod(0755, params[:output_file]) |
|
168 | FileUtils.cp("#{params[:source_file]}c",params[:output_file]) |
|
169 | FileUtils.cp("#{params[:source_file]}c",params[:output_file]) |
|
169 | end |
|
170 | end |
|
170 | #end |
|
171 | #end |
|
171 |
|
172 | ||
|
172 | when "php" |
|
173 | when "php" |
|
173 | command = "#{PHP_INTERPRETER} #{PHP_OPTIONS} #{params[:source_file]}" |
|
174 | command = "#{PHP_INTERPRETER} #{PHP_OPTIONS} #{params[:source_file]}" |
|
174 | if system(command, err: params[:message_file]) |
|
175 | if system(command, err: params[:message_file]) |
|
175 | File.open(params[:output_file],"w") do |out_file| |
|
176 | File.open(params[:output_file],"w") do |out_file| |
|
176 | out_file.puts "#!#{PHP_INTERPRETER}" |
|
177 | out_file.puts "#!#{PHP_INTERPRETER}" |
|
177 | File.open(params[:source_file],"r").each do |line| |
|
178 | File.open(params[:source_file],"r").each do |line| |
|
178 | out_file.print line |
|
179 | out_file.print line |
|
179 | end |
|
180 | end |
|
180 | end |
|
181 | end |
|
181 | File.chmod(0755, params[:output_file]) |
|
182 | File.chmod(0755, params[:output_file]) |
|
182 | end |
|
183 | end |
|
183 |
|
184 | ||
|
184 | when "haskell" |
|
185 | when "haskell" |
|
185 | command = "#{HASKELL_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{HASKELL_OPTIONS}" |
|
186 | command = "#{HASKELL_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{HASKELL_OPTIONS}" |
|
186 | talk "COMPILE: compiling command [#{command}]" |
|
187 | talk "COMPILE: compiling command [#{command}]" |
|
187 | system(command, err: params[:message_file]) |
|
188 | system(command, err: params[:message_file]) |
|
188 |
|
189 | ||
|
|
190 | + when "octave" | ||
|
|
191 | + command = "touch" | ||
|
|
192 | + talk "COMPILE: compiling command [#{command}], log err to #{params[:message_file]}" | ||
|
|
193 | + system(command, err: params[:message_file]) | ||
|
|
194 | + File.open(params[:output_file],"w") do |out_file| | ||
|
|
195 | + out_file.puts "#!#{OCTAVE_INTERPRETER}" | ||
|
|
196 | + File.open(params[:source_file],"r").each do |line| | ||
|
|
197 | + out_file.print line | ||
|
|
198 | + end | ||
|
|
199 | + end | ||
|
|
200 | + File.chmod(0755, params[:output_file]) | ||
|
|
201 | + | ||
|
189 | else |
|
202 | else |
|
190 | talk("COMPILE: ERROR: Invalid language specified!") |
|
203 | talk("COMPILE: ERROR: Invalid language specified!") |
|
191 | open(params[:message_file],"w") do |f| |
|
204 | open(params[:message_file],"w") do |f| |
|
192 | f.puts "ERROR: Invalid language specified!" |
|
205 | f.puts "ERROR: Invalid language specified!" |
|
193 | end |
|
206 | end |
|
194 | exit(127) |
|
207 | exit(127) |
|
195 | end |
|
208 | end |
|
196 |
|
209 | ||
|
197 | # Report success or failure. |
|
210 | # Report success or failure. |
|
198 | if FileTest.exists? params[:output_file] |
|
211 | if FileTest.exists? params[:output_file] |
|
199 | talk "COMPILE: Compilation was successful!" |
|
212 | talk "COMPILE: Compilation was successful!" |
|
200 | else |
|
213 | else |
|
201 | talk "COMPILE: ERROR: Something was wrong during the compilation!" |
|
214 | talk "COMPILE: ERROR: Something was wrong during the compilation!" |
|
202 | end |
|
215 | end |
@@ -1,194 +1,194 | |||||
|
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("judge: #{Time.new.strftime("%H:%M")} #{str}") |
|
12 | fp.puts("judge: #{Time.new.strftime("%H:%M")} #{str}") |
|
13 | fp.close |
|
13 | fp.close |
|
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 = "JUDGE: ERROR: #{error_message}" |
|
31 | msg = "JUDGE: 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" && language != "php" && language != "haskell" |
|
56 | + if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" && language != "python" && language != "php" && language != "haskell" && language != "octave" |
|
57 | log "JUDGE: You specified a language that is not supported: #{language}." |
|
57 | log "JUDGE: 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 | ENV['SOURCE_NAME'] = source_file |
|
63 | if File.exist?(source_file) == false |
|
63 | if File.exist?(source_file) == false |
|
64 | log "JUDGE: The source file does not exist." |
|
64 | log "JUDGE: The source file does not exist." |
|
65 | exit(127) |
|
65 | exit(127) |
|
66 | end |
|
66 | end |
|
67 |
|
67 | ||
|
68 | log "JUDGE: Making test result and sandbox directories..." |
|
68 | log "JUDGE: Making test result and sandbox directories..." |
|
69 |
|
69 | ||
|
70 | current_dir = FileUtils.pwd |
|
70 | current_dir = FileUtils.pwd |
|
71 | current_dir.strip! |
|
71 | current_dir.strip! |
|
72 |
|
72 | ||
|
73 | if ARGV.length >= 3 |
|
73 | if ARGV.length >= 3 |
|
74 | test_result_dir = ARGV[2] |
|
74 | test_result_dir = ARGV[2] |
|
75 | else |
|
75 | else |
|
76 | test_result_dir = "#{current_dir}/test-result" |
|
76 | test_result_dir = "#{current_dir}/test-result" |
|
77 | end |
|
77 | end |
|
78 |
|
78 | ||
|
79 | log "JUDGE: Test result directory: #{test_result_dir}" |
|
79 | log "JUDGE: Test result directory: #{test_result_dir}" |
|
80 | clear_and_create_empty_dir(test_result_dir) |
|
80 | clear_and_create_empty_dir(test_result_dir) |
|
81 |
|
81 | ||
|
82 | if ARGV.length >= 4 |
|
82 | if ARGV.length >= 4 |
|
83 | sandbox_dir = ARGV[3] |
|
83 | sandbox_dir = ARGV[3] |
|
84 | else |
|
84 | else |
|
85 | sandbox_dir = "#{current_dir}/sandbox" |
|
85 | sandbox_dir = "#{current_dir}/sandbox" |
|
86 | end |
|
86 | end |
|
87 | log "JUDGE: Sandbox directory: #{sandbox_dir}" |
|
87 | log "JUDGE: Sandbox directory: #{sandbox_dir}" |
|
88 | clear_and_create_empty_dir(sandbox_dir) |
|
88 | clear_and_create_empty_dir(sandbox_dir) |
|
89 |
|
89 | ||
|
90 | # ------------------------------ |
|
90 | # ------------------------------ |
|
91 | # Compile |
|
91 | # Compile |
|
92 | # ------------------------------ |
|
92 | # ------------------------------ |
|
93 | log "JUDGE: Compiling..." |
|
93 | log "JUDGE: Compiling..." |
|
94 | log |
|
94 | log |
|
95 | call_and_log("Cannot copy the source file to #{sandbox_dir}") { |
|
95 | call_and_log("Cannot copy the source file to #{sandbox_dir}") { |
|
96 | FileUtils.cp(source_file, sandbox_dir) |
|
96 | FileUtils.cp(source_file, sandbox_dir) |
|
97 | } |
|
97 | } |
|
98 | begin |
|
98 | begin |
|
99 | Dir.chdir sandbox_dir |
|
99 | Dir.chdir sandbox_dir |
|
100 | rescue |
|
100 | rescue |
|
101 | log "JUDGE: ERROR: Cannot change directory to #{sandbox_dir}." |
|
101 | log "JUDGE: ERROR: Cannot change directory to #{sandbox_dir}." |
|
102 | exit(127) |
|
102 | exit(127) |
|
103 | end |
|
103 | end |
|
104 | execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
104 | execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
105 | compile_message = open("compiler_message").read |
|
105 | compile_message = open("compiler_message").read |
|
106 | compile_message.strip! |
|
106 | compile_message.strip! |
|
107 | call_and_log("Cannot move the compiler message to #{test_result_dir}.") { |
|
107 | call_and_log("Cannot move the compiler message to #{test_result_dir}.") { |
|
108 | FileUtils.mv("compiler_message", test_result_dir) |
|
108 | FileUtils.mv("compiler_message", test_result_dir) |
|
109 | } |
|
109 | } |
|
110 | if !FileTest.exist?("a.out") |
|
110 | if !FileTest.exist?("a.out") |
|
111 | log "JUDGE: EROOR: Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
111 | log "JUDGE: EROOR: Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
112 | exit(127) |
|
112 | exit(127) |
|
113 | else |
|
113 | else |
|
114 | call_and_log("Cannot move the compiled program to #{test_result_dir}") { |
|
114 | call_and_log("Cannot move the compiled program to #{test_result_dir}") { |
|
115 | FileUtils.mv("a.out",test_result_dir) |
|
115 | FileUtils.mv("a.out",test_result_dir) |
|
116 | if language == "java" then Dir["*.class"].each { |file| FileUtils.mv(file,test_result_dir)} end |
|
116 | if language == "java" then Dir["*.class"].each { |file| FileUtils.mv(file,test_result_dir)} end |
|
117 | if language == "python" then Dir["*.pyc"].each { |file| FileUtils.mv(file,test_result_dir)} end |
|
117 | if language == "python" then Dir["*.pyc"].each { |file| FileUtils.mv(file,test_result_dir)} end |
|
118 | } |
|
118 | } |
|
119 | FileUtils.rm_rf("#{sandbox_dir}/.") |
|
119 | FileUtils.rm_rf("#{sandbox_dir}/.") |
|
120 | end |
|
120 | end |
|
121 |
|
121 | ||
|
122 |
|
122 | ||
|
123 | #----------------------------------------------- |
|
123 | #----------------------------------------------- |
|
124 | # run |
|
124 | # run |
|
125 | #----------------------------------------------- |
|
125 | #----------------------------------------------- |
|
126 | require "#{problem_home}/script/test_dsl.rb" |
|
126 | require "#{problem_home}/script/test_dsl.rb" |
|
127 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
127 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
128 | problem = Problem.get_instance |
|
128 | problem = Problem.get_instance |
|
129 |
|
129 | ||
|
130 | if problem.well_formed? == false |
|
130 | if problem.well_formed? == false |
|
131 | log "The problem specification is not well formed." |
|
131 | log "The problem specification is not well formed." |
|
132 | exit(127) |
|
132 | exit(127) |
|
133 | end |
|
133 | end |
|
134 |
|
134 | ||
|
135 | # Doing the testing. |
|
135 | # Doing the testing. |
|
136 | log |
|
136 | log |
|
137 | log "JUDGE: Running each test case..." |
|
137 | log "JUDGE: Running each test case..." |
|
138 | (1..(problem.num_tests)).each do |test_num| |
|
138 | (1..(problem.num_tests)).each do |test_num| |
|
139 |
|
139 | ||
|
140 | $stdout.print "[#{test_num}]" |
|
140 | $stdout.print "[#{test_num}]" |
|
141 | $stdout.flush |
|
141 | $stdout.flush |
|
142 |
|
142 | ||
|
143 | call_and_log("Cannot copy the compiled program into #{sandbox_dir}") { |
|
143 | call_and_log("Cannot copy the compiled program into #{sandbox_dir}") { |
|
144 | FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir, :preserve => true) |
|
144 | FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir, :preserve => true) |
|
145 | if language == "java" then Dir["#{test_result_dir}/*.class"].each { |file| FileUtils.cp(file,sandbox_dir)} end |
|
145 | if language == "java" then Dir["#{test_result_dir}/*.class"].each { |file| FileUtils.cp(file,sandbox_dir)} end |
|
146 | if language == "python" then Dir["#{test_result_dir}/*.pyc"].each { |file| FileUtils.cp(file,sandbox_dir)} end |
|
146 | if language == "python" then Dir["#{test_result_dir}/*.pyc"].each { |file| FileUtils.cp(file,sandbox_dir)} end |
|
147 | } |
|
147 | } |
|
148 |
|
148 | ||
|
149 | #additionally copy any extra .txt file |
|
149 | #additionally copy any extra .txt file |
|
150 | data_files = Dir[problem_home + '/*.txt'] |
|
150 | data_files = Dir[problem_home + '/*.txt'] |
|
151 | data_files.each do |file| |
|
151 | data_files.each do |file| |
|
152 | FileUtils.cp(file,sandbox_dir) |
|
152 | FileUtils.cp(file,sandbox_dir) |
|
153 | end |
|
153 | end |
|
154 |
|
154 | ||
|
155 | begin |
|
155 | begin |
|
156 | execute("#{problem_home}/script/run #{language} #{test_num} ", "Error occured during execution of the run script") |
|
156 | execute("#{problem_home}/script/run #{language} #{test_num} ", "Error occured during execution of the run script") |
|
157 | rescue |
|
157 | rescue |
|
158 | # do nothing |
|
158 | # do nothing |
|
159 | end |
|
159 | end |
|
160 |
|
160 | ||
|
161 |
|
161 | ||
|
162 | #copy the output of run script to each test-result folder |
|
162 | #copy the output of run script to each test-result folder |
|
163 | call_and_log("Cannot create directory #{test_result_dir}/#{test_num}") { |
|
163 | call_and_log("Cannot create directory #{test_result_dir}/#{test_num}") { |
|
164 | FileUtils.mkdir "#{test_result_dir}/#{test_num}" |
|
164 | FileUtils.mkdir "#{test_result_dir}/#{test_num}" |
|
165 | } |
|
165 | } |
|
166 | call_and_log("Cannot copy the result file into #{test_result_dir}/#{test_num}") { |
|
166 | call_and_log("Cannot copy the result file into #{test_result_dir}/#{test_num}") { |
|
167 | FileUtils.mv "#{sandbox_dir}/result", "#{test_result_dir}/#{test_num}" |
|
167 | FileUtils.mv "#{sandbox_dir}/result", "#{test_result_dir}/#{test_num}" |
|
168 | } |
|
168 | } |
|
169 | call_and_log("Cannot copy the comment file into #{test_result_dir}/#{test_num}") { |
|
169 | call_and_log("Cannot copy the comment file into #{test_result_dir}/#{test_num}") { |
|
170 | FileUtils.mv "#{sandbox_dir}/comment", "#{test_result_dir}/#{test_num}" |
|
170 | FileUtils.mv "#{sandbox_dir}/comment", "#{test_result_dir}/#{test_num}" |
|
171 | } |
|
171 | } |
|
172 | call_and_log("Cannot copy the output file into #{test_result_dir}/#{test_num}") { |
|
172 | call_and_log("Cannot copy the output file into #{test_result_dir}/#{test_num}") { |
|
173 | FileUtils.mv "#{sandbox_dir}/output.txt", "#{test_result_dir}/#{test_num}" |
|
173 | FileUtils.mv "#{sandbox_dir}/output.txt", "#{test_result_dir}/#{test_num}" |
|
174 | } |
|
174 | } |
|
175 | call_and_log("Cannot clear #{sandbox_dir}") { |
|
175 | call_and_log("Cannot clear #{sandbox_dir}") { |
|
176 | FileUtils.rm_rf(Dir.glob("#{sandbox_dir}/*"), :secure => true) |
|
176 | FileUtils.rm_rf(Dir.glob("#{sandbox_dir}/*"), :secure => true) |
|
177 | } |
|
177 | } |
|
178 | end |
|
178 | end |
|
179 |
|
179 | ||
|
180 | $stdout.print "[done]\n" |
|
180 | $stdout.print "[done]\n" |
|
181 |
|
181 | ||
|
182 | # Grade |
|
182 | # Grade |
|
183 | log |
|
183 | log |
|
184 | log "JUDGE: Grading..." |
|
184 | log "JUDGE: Grading..." |
|
185 | begin |
|
185 | begin |
|
186 | Dir.chdir test_result_dir |
|
186 | Dir.chdir test_result_dir |
|
187 | rescue |
|
187 | rescue |
|
188 | log "ERROR: Cannot change directory to #{test_result_dir}." |
|
188 | log "ERROR: Cannot change directory to #{test_result_dir}." |
|
189 | exit(127) |
|
189 | exit(127) |
|
190 | end |
|
190 | end |
|
191 | execute("#{problem_home}/script/grade", "An error occured during grading!") |
|
191 | execute("#{problem_home}/script/grade", "An error occured during grading!") |
|
192 |
|
192 | ||
|
193 | log |
|
193 | log |
|
194 | log "All done!" |
|
194 | log "All done!" |
@@ -1,211 +1,214 | |||||
|
1 | #!/usr/bin/env ruby |
|
1 | #!/usr/bin/env ruby |
|
2 |
|
2 | ||
|
3 | ## |
|
3 | ## |
|
4 | # This program should be run in the sandbox dir containing the compiled file |
|
4 | # This program should be run in the sandbox dir containing the compiled file |
|
5 | # (or source file for script language). It will call the sandbox program with |
|
5 | # (or source file for script language). It will call the sandbox program with |
|
6 | # the given input and process the output of the sandbox |
|
6 | # the given input and process the output of the sandbox |
|
7 | # |
|
7 | # |
|
8 | # If sandbox exit normally, this program will call the "check" script to do |
|
8 | # If sandbox exit normally, this program will call the "check" script to do |
|
9 | # scoring. Otherwise, it would record the error accordingly |
|
9 | # scoring. Otherwise, it would record the error accordingly |
|
10 | # |
|
10 | # |
|
11 | # This program produces several file |
|
11 | # This program produces several file |
|
12 | # * result - the result from check script |
|
12 | # * result - the result from check script |
|
13 | # * comment - comment from sandbox |
|
13 | # * comment - comment from sandbox |
|
14 | # * output - output of the program |
|
14 | # * output - output of the program |
|
15 | # |
|
15 | # |
|
16 |
|
16 | ||
|
17 | require 'fileutils' |
|
17 | require 'fileutils' |
|
18 |
|
18 | ||
|
19 | def log(str='') |
|
19 | def log(str='') |
|
20 | if ENV['TALKATIVE']!=nil |
|
20 | if ENV['TALKATIVE']!=nil |
|
21 | puts str |
|
21 | puts str |
|
22 | end |
|
22 | end |
|
23 | if ENV['GRADER_LOGGING']!=nil |
|
23 | if ENV['GRADER_LOGGING']!=nil |
|
24 | log_fname = ENV['GRADER_LOGGING'] |
|
24 | log_fname = ENV['GRADER_LOGGING'] |
|
25 | fp = File.open(log_fname,"a") |
|
25 | fp = File.open(log_fname,"a") |
|
26 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
26 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
27 | fp.close |
|
27 | fp.close |
|
28 | end |
|
28 | end |
|
29 | end |
|
29 | end |
|
30 |
|
30 | ||
|
31 | def extract_time(t) |
|
31 | def extract_time(t) |
|
32 | # puts "TIME: #{t}" |
|
32 | # puts "TIME: #{t}" |
|
33 | if (result=/^(.*)r(.*)u(.*)s/.match(t)) |
|
33 | if (result=/^(.*)r(.*)u(.*)s/.match(t)) |
|
34 | {:real => result[1], :user => result[2], :sys => result[3]} |
|
34 | {:real => result[1], :user => result[2], :sys => result[3]} |
|
35 | else |
|
35 | else |
|
36 | #{:real => 0, :user => 0, :sys => 0} |
|
36 | #{:real => 0, :user => 0, :sys => 0} |
|
37 | #puts "ERROR READING RUNNING TIME: #{t}" |
|
37 | #puts "ERROR READING RUNNING TIME: #{t}" |
|
38 | raise "Error reading running time: #{t}" |
|
38 | raise "Error reading running time: #{t}" |
|
39 | end |
|
39 | end |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | def compile_box(source,bin) |
|
42 | def compile_box(source,bin) |
|
43 | system("g++ #{source} -o #{bin}") |
|
43 | system("g++ #{source} -o #{bin}") |
|
44 | end |
|
44 | end |
|
45 |
|
45 | ||
|
46 | #------------------------------------------ |
|
46 | #------------------------------------------ |
|
47 | # MAIN |
|
47 | # MAIN |
|
48 | #------------------------------------------ |
|
48 | #------------------------------------------ |
|
49 |
|
49 | ||
|
50 | #parse parameter |
|
50 | #parse parameter |
|
51 | if ARGV.length < 2 || ARGV.length > 3 |
|
51 | if ARGV.length < 2 || ARGV.length > 3 |
|
52 | puts "Usage: run <language> <test-num> [<program-name>]" |
|
52 | puts "Usage: run <language> <test-num> [<program-name>]" |
|
53 | exit(127) |
|
53 | exit(127) |
|
54 | end |
|
54 | end |
|
55 |
|
55 | ||
|
56 | language = ARGV[0] |
|
56 | language = ARGV[0] |
|
57 | test_num = ARGV[1].to_i |
|
57 | test_num = ARGV[1].to_i |
|
58 | if ARGV.length > 2 |
|
58 | if ARGV.length > 2 |
|
59 | program_name = ARGV[2] |
|
59 | program_name = ARGV[2] |
|
60 | else |
|
60 | else |
|
61 | program_name = "a.out" |
|
61 | program_name = "a.out" |
|
62 | end |
|
62 | end |
|
63 |
|
63 | ||
|
64 | problem_home = ENV['PROBLEM_HOME'] |
|
64 | problem_home = ENV['PROBLEM_HOME'] |
|
65 | source_name = ENV['SOURCE_NAME'] |
|
65 | source_name = ENV['SOURCE_NAME'] |
|
66 | require "#{problem_home}/script/test_dsl.rb" |
|
66 | require "#{problem_home}/script/test_dsl.rb" |
|
67 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
67 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
68 | problem = Problem.get_instance |
|
68 | problem = Problem.get_instance |
|
69 |
|
69 | ||
|
70 | sandbox_dir = Dir.getwd |
|
70 | sandbox_dir = Dir.getwd |
|
71 |
|
71 | ||
|
72 | if problem.well_formed? == false |
|
72 | if problem.well_formed? == false |
|
73 | log "RUN: ERROR: The problem specification is not well formed." |
|
73 | log "RUN: ERROR: The problem specification is not well formed." |
|
74 | exit(127) |
|
74 | exit(127) |
|
75 | end |
|
75 | end |
|
76 |
|
76 | ||
|
77 | # Check if the test number is okay. |
|
77 | # Check if the test number is okay. |
|
78 | if test_num <= 0 || test_num > problem.num_tests |
|
78 | if test_num <= 0 || test_num > problem.num_tests |
|
79 | log "RUN: ERROR: You have specified a wrong test number." |
|
79 | log "RUN: ERROR: You have specified a wrong test number." |
|
80 | exit(127) |
|
80 | exit(127) |
|
81 | end |
|
81 | end |
|
82 |
|
82 | ||
|
83 | ##################################### |
|
83 | ##################################### |
|
84 | # Set the relavant file names here. # |
|
84 | # Set the relavant file names here. # |
|
85 | ##################################### |
|
85 | ##################################### |
|
86 |
|
86 | ||
|
87 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
87 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
88 |
|
88 | ||
|
89 | ##################################### |
|
89 | ##################################### |
|
90 |
|
90 | ||
|
91 | time_limit = problem.get_time_limit test_num |
|
91 | time_limit = problem.get_time_limit test_num |
|
92 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
92 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
93 |
|
93 | ||
|
94 | # Copy the input file. |
|
94 | # Copy the input file. |
|
95 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
95 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
96 |
|
96 | ||
|
97 | # check if box is there, if not, compile it! |
|
97 | # check if box is there, if not, compile it! |
|
98 | if !File.exists?("#{problem_home}/script/box") |
|
98 | if !File.exists?("#{problem_home}/script/box") |
|
99 | log "WARNING: Compiling box: to increase efficiency, it should be compile manually" |
|
99 | log "WARNING: Compiling box: to increase efficiency, it should be compile manually" |
|
100 | compile_box("#{problem_home}/script/box.cc", |
|
100 | compile_box("#{problem_home}/script/box.cc", |
|
101 | "#{problem_home}/script/box") |
|
101 | "#{problem_home}/script/box") |
|
102 | end |
|
102 | end |
|
103 |
|
103 | ||
|
104 | # Hide PROBLEM_HOME |
|
104 | # Hide PROBLEM_HOME |
|
105 | ENV['PROBLEM_HOME'] = nil |
|
105 | ENV['PROBLEM_HOME'] = nil |
|
106 | ENV['SOURCE_NAME'] = nil |
|
106 | ENV['SOURCE_NAME'] = nil |
|
107 |
|
107 | ||
|
108 | # Run the program. |
|
108 | # Run the program. |
|
109 | #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}" |
|
109 | #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}" |
|
110 | # |
|
110 | # |
|
111 |
|
111 | ||
|
112 | JAVA_OPTION = "-s set_robust_list -s futex -s clone -s getppid -s clone -s wait4 -p /usr/bin/ -p ./" |
|
112 | JAVA_OPTION = "-s set_robust_list -s futex -s clone -s getppid -s clone -s wait4 -p /usr/bin/ -p ./" |
|
113 | 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" |
|
113 | 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" |
|
114 | 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" |
|
114 | 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" |
|
|
115 | + 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" | ||
|
115 | 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" |
|
116 | 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" |
|
116 | HASKELL_OPTION = "-s set_robust_list -s clock_gettime -s sysinfo -s timer_create -s timer_settime -s futex -s timer_delete" |
|
117 | HASKELL_OPTION = "-s set_robust_list -s clock_gettime -s sysinfo -s timer_create -s timer_settime -s futex -s timer_delete" |
|
117 |
|
118 | ||
|
118 | case language |
|
119 | case language |
|
119 | when "java" |
|
120 | when "java" |
|
120 | # for java, extract the classname |
|
121 | # for java, extract the classname |
|
121 | # wne have to add additional systemcall and we don't check the mem limit (dunno how to fix...) |
|
122 | # wne have to add additional systemcall and we don't check the mem limit (dunno how to fix...) |
|
122 | classname = 'DUMMY' |
|
123 | classname = 'DUMMY' |
|
123 | File.open(program_name,"r").each do |line| |
|
124 | File.open(program_name,"r").each do |line| |
|
124 | classname = line |
|
125 | classname = line |
|
125 | end |
|
126 | end |
|
126 | #for java, we cannot really check the memory limit... |
|
127 | #for java, we cannot really check the memory limit... |
|
127 | 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} " |
|
128 | 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} " |
|
128 | when "ruby" |
|
129 | when "ruby" |
|
129 | 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} " |
|
130 | 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} " |
|
130 | when "python" |
|
131 | when "python" |
|
131 | 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} " |
|
132 | 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} " |
|
132 | when "haskell" |
|
133 | when "haskell" |
|
133 | 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} " |
|
134 | 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} " |
|
134 | when "php" |
|
135 | when "php" |
|
135 | 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} " |
|
136 | 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} " |
|
|
137 | + when "octave" | ||
|
|
138 | + 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}" | ||
|
136 | else # for c++, pascal, we do the normal checking |
|
139 | else # for c++, pascal, we do the normal checking |
|
137 | 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} " |
|
140 | 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} " |
|
138 | end |
|
141 | end |
|
139 |
|
142 | ||
|
140 |
|
143 | ||
|
141 | log "RUN: Running test #{test_num}..." |
|
144 | log "RUN: Running test #{test_num}..." |
|
142 | log "RUN: Run command = [#{run_command}]" |
|
145 | log "RUN: Run command = [#{run_command}]" |
|
143 | log |
|
146 | log |
|
144 | system(run_command,err: 'run_result') |
|
147 | system(run_command,err: 'run_result') |
|
145 |
|
148 | ||
|
146 | # Restore PROBLEM_HOME |
|
149 | # Restore PROBLEM_HOME |
|
147 | ENV['PROBLEM_HOME'] = problem_home |
|
150 | ENV['PROBLEM_HOME'] = problem_home |
|
148 |
|
151 | ||
|
149 | # Create the result file. |
|
152 | # Create the result file. |
|
150 | result_file = File.new("result", "w") |
|
153 | result_file = File.new("result", "w") |
|
151 | comment_file = File.new("comment", "w") |
|
154 | comment_file = File.new("comment", "w") |
|
152 |
|
155 | ||
|
153 | # Check if the program actually produced any output. |
|
156 | # Check if the program actually produced any output. |
|
154 | run_result_file = File.new("run_result", "r") |
|
157 | run_result_file = File.new("run_result", "r") |
|
155 | run_result = run_result_file.readlines |
|
158 | run_result = run_result_file.readlines |
|
156 | run_result_file.close |
|
159 | run_result_file.close |
|
157 |
|
160 | ||
|
158 | run_stat = run_result[run_result.length-1] |
|
161 | run_stat = run_result[run_result.length-1] |
|
159 | running_time = extract_time(run_stat) |
|
162 | running_time = extract_time(run_stat) |
|
160 |
|
163 | ||
|
161 | report = lambda{ |status, points, comment| |
|
164 | report = lambda{ |status, points, comment| |
|
162 | result_file.write status.strip |
|
165 | result_file.write status.strip |
|
163 | result_file.write "\n" |
|
166 | result_file.write "\n" |
|
164 | result_file.write points.to_s.strip |
|
167 | result_file.write points.to_s.strip |
|
165 | result_file.write "\n" |
|
168 | result_file.write "\n" |
|
166 | result_file.write run_stat.strip |
|
169 | result_file.write run_stat.strip |
|
167 | result_file.write "\n" |
|
170 | result_file.write "\n" |
|
168 | result_file.close |
|
171 | result_file.close |
|
169 | FileUtils.rm "run_result" |
|
172 | FileUtils.rm "run_result" |
|
170 | # `rm output.txt` --- keep the output |
|
173 | # `rm output.txt` --- keep the output |
|
171 |
|
174 | ||
|
172 | comment_file.write comment |
|
175 | comment_file.write comment |
|
173 |
|
176 | ||
|
174 | # added for debuggin --- jittat |
|
177 | # added for debuggin --- jittat |
|
175 | comment_file.write "--run-result--\n" |
|
178 | comment_file.write "--run-result--\n" |
|
176 | run_result.each do |l| |
|
179 | run_result.each do |l| |
|
177 | comment_file.write l |
|
180 | comment_file.write l |
|
178 | end |
|
181 | end |
|
179 |
|
182 | ||
|
180 | comment_file.close |
|
183 | comment_file.close |
|
181 |
|
184 | ||
|
182 | log "Done!" |
|
185 | log "Done!" |
|
183 | exit(0) |
|
186 | exit(0) |
|
184 | } |
|
187 | } |
|
185 |
|
188 | ||
|
186 |
|
189 | ||
|
187 | if run_result[0][0,2] != "OK" |
|
190 | if run_result[0][0,2] != "OK" |
|
188 | log "There was a runtime error." |
|
191 | log "There was a runtime error." |
|
189 | report.call(run_result[0], 0, "No comment.\n") |
|
192 | report.call(run_result[0], 0, "No comment.\n") |
|
190 | end |
|
193 | end |
|
191 |
|
194 | ||
|
192 | if running_time[:user].to_f > time_limit |
|
195 | if running_time[:user].to_f > time_limit |
|
193 | log "Time limit exceeded." |
|
196 | log "Time limit exceeded." |
|
194 | report.call("Time limit exceeded", 0, "No comment.\n") |
|
197 | report.call("Time limit exceeded", 0, "No comment.\n") |
|
195 | end |
|
198 | end |
|
196 |
|
199 | ||
|
197 | # Run 'check' to evaluate the output. |
|
200 | # Run 'check' to evaluate the output. |
|
198 | #puts "There was no runtime error. Proceed to checking the output." |
|
201 | #puts "There was no runtime error. Proceed to checking the output." |
|
199 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
202 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
200 | log "Checking the output..." |
|
203 | log "Checking the output..." |
|
201 | log check_command |
|
204 | log check_command |
|
202 | if not system(check_command) |
|
205 | if not system(check_command) |
|
203 | log "Problem with check script" |
|
206 | log "Problem with check script" |
|
204 | report.call("Incorrect",0,"Check script error.\n") |
|
207 | report.call("Incorrect",0,"Check script error.\n") |
|
205 | exit(127) |
|
208 | exit(127) |
|
206 | end |
|
209 | end |
|
207 |
|
210 | ||
|
208 | check_file = File.new("check_result", "r") |
|
211 | check_file = File.new("check_result", "r") |
|
209 | check_file_lines = check_file.readlines |
|
212 | check_file_lines = check_file.readlines |
|
210 |
|
213 | ||
|
211 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
|
214 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
You need to be logged in to leave comments.
Login now