Description:
add more languages, java and ruby
add bookmark algo-bm and branch algo
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r147:9e3cee7d454d - - 5 files changed: 54 inserted, 7 deleted
@@ -26,10 +26,13 | |||
|
26 | 26 | C_COMPILER = "/usr/bin/gcc" |
|
27 | 27 | CPLUSPLUS_COMPILER = "/usr/bin/g++" |
|
28 | 28 | PASCAL_COMPILER = "/usr/bin/fpc" |
|
29 | + JAVA_COMPILER = "/usr/bin/javac" | |
|
30 | + RUBY_INTEPRETER = "/home/dae/.rvm/rubies/ruby-1.9.2-p320/bin/ruby" | |
|
29 | 31 | |
|
30 | 32 | C_OPTIONS = "-O2 -s -static -std=c99 -DCONTEST -lm -Wall" |
|
31 | 33 | CPLUSPLUS_OPTIONS = "-O2 -s -static -DCONTEST -lm -Wall" |
|
32 | 34 | PASCAL_OPTIONS = "-O1 -XS -dCONTEST" |
|
35 | + JAVA_OPTIONS = "" | |
|
33 | 36 | |
|
34 | 37 | # Check for the correct number of arguments. Otherwise, print usage. |
|
35 | 38 | if ARGV.length == 0 or ARGV.length > 4 |
@@ -96,6 +99,32 | |||
|
96 | 99 | command = "#{PASCAL_COMPILER} #{params[:source_file]} -ooutpas #{PASCAL_OPTIONS} > #{params[:message_file]}" |
|
97 | 100 | system(command) |
|
98 | 101 | FileUtils.mv("output", params[:output_file]) |
|
102 | + | |
|
103 | + when "java" | |
|
104 | + #rename the file to the public class name | |
|
105 | + | |
|
106 | + #get the class name | |
|
107 | + classname = 'DUMMY' | |
|
108 | + File.foreach(params[:source_file]) do |line| | |
|
109 | + md = /\s*public\s*class\s*(\w*)/.match(line) | |
|
110 | + classname=md[1] if md | |
|
111 | + end | |
|
112 | + system("cp #{params[:source_file]} #{classname}.java") | |
|
113 | + command = "#{JAVA_COMPILER} #{classname}.java > #{params[:message_file]}" | |
|
114 | + system(command) | |
|
115 | + File.open(params[:output_file],"w") {|file| file.write("#!/bin/sh\n/usr/bin/java #{classname}\n")} | |
|
116 | + File.chmod(0755, params[:output_file]) | |
|
117 | + | |
|
118 | + when "ruby" | |
|
119 | + command = "#{RUBY_INTEPRETER} -c #{params[:source_file]} > #{params[:message_file]}" | |
|
120 | + system(command) | |
|
121 | + File.open(params[:output_file],"w") do |out_file| | |
|
122 | + out_file.puts "#!#{RUBY_INTEPRETER}" | |
|
123 | + File.open(params[:source_file],"r").each do |line| | |
|
124 | + out_file.print line | |
|
125 | + end | |
|
126 | + end | |
|
127 | + File.chmod(0755, params[:output_file]) | |
|
99 | 128 | |
|
100 | 129 | else |
|
101 | 130 | talk("ERROR: Invalid language specified!") |
@@ -53,7 +53,7 | |||
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | language = ARGV[0] |
|
56 | - if language != "c" && language != "c++" && language != "pas" | |
|
56 | + if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" | |
|
57 | 57 | log "You specified a language that is not supported: #{language}." |
|
58 | 58 | exit(127) |
|
59 | 59 | end |
@@ -110,6 +110,7 | |||
|
110 | 110 | else |
|
111 | 111 | call_and_log("Cannot move the compiled program to #{test_result_dir}") { |
|
112 | 112 | FileUtils.mv("a.out",test_result_dir) |
|
113 | + if language == "java" then Dir["*.class"].each { |file| FileUtils.mv(file,test_result_dir)} end | |
|
113 | 114 | } |
|
114 | 115 | FileUtils.rm_rf("#{sandbox_dir}/.") |
|
115 | 116 | end |
@@ -133,6 +134,7 | |||
|
133 | 134 | |
|
134 | 135 | call_and_log("Cannot copy the compiled program into #{sandbox_dir}") { |
|
135 | 136 | FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir, :preserve => true) |
|
137 | + if language == "java" then Dir["#{test_result_dir}/*.class"].each { |file| FileUtils.cp(file,sandbox_dir)} end | |
|
136 | 138 | } |
|
137 | 139 | |
|
138 | 140 | begin |
@@ -15,8 +15,9 | |||
|
15 | 15 | end |
|
16 | 16 | |
|
17 | 17 | def extract_time(t) |
|
18 |
- # |
|
|
19 |
- if (result=/^(.*)r |
|
|
18 | + #puts "TIME: #{t}" | |
|
19 | + #if (result=/^(.*)real(.*)wall(.*)s/.match(t)) | |
|
20 | + if (result=/^OK \((.*) sec real\, (.*) sec wall,.*MB, (.*) syscalls/.match(t)) | |
|
20 | 21 | {:real => result[1], :user => result[2], :sys => result[3]} |
|
21 | 22 | else |
|
22 | 23 | #{:real => 0, :user => 0, :sys => 0} |
@@ -84,8 +85,23 | |||
|
84 | 85 | |
|
85 | 86 | # Run the program. |
|
86 | 87 | #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}" |
|
88 | + # | |
|
87 | 89 | |
|
88 | - 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" | |
|
90 | + | |
|
91 | + | |
|
92 | + | |
|
93 | + case language | |
|
94 | + when "java" | |
|
95 | + # for java, we have to add additional systemcall and we don't check the mem limit (dunno how to fix...) | |
|
96 | + run_command = "#{problem_home}/script/box -T -t #{time_limit} -s getppid -s clone -s wait4 -p /usr/bin/ -p ./ -i #{input_file_name} -o output.txt #{program_name} 2>run_result" | |
|
97 | + when "ruby" | |
|
98 | + 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" | |
|
99 | + when "c++" | |
|
100 | + 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" | |
|
101 | + else | |
|
102 | + 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" | |
|
103 | + end | |
|
104 | + | |
|
89 | 105 | |
|
90 | 106 | log "Running test #{test_num}..." |
|
91 | 107 | log run_command |
@@ -137,7 +153,7 | |||
|
137 | 153 | report.call(run_result[0], 0, "No comment.\n") |
|
138 | 154 | end |
|
139 | 155 | |
|
140 |
- if running_time[:user].to_f |
|
|
156 | + if running_time[:user].to_f > time_limit | |
|
141 | 157 | log "Time limit exceeded." |
|
142 | 158 | report.call("Time limit exceeded", 0, "No comment.\n") |
|
143 | 159 | end |
You need to be logged in to leave comments.
Login now