Description:
merge
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r270:cfcb015a0053 - - 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 |
@@ -23,24 +23,25 | |||||
|
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>]" |
@@ -177,24 +178,36 | |||||
|
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 |
@@ -44,25 +44,25 | |||||
|
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..." |
@@ -103,45 +103,48 | |||||
|
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 |
You need to be logged in to leave comments.
Login now