Description:
Merge branch 'master' of gitorious.org:cafe-grader/cafe-grader-judge-scripts into win-local
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r106:502201e59a2c - - 1 file changed: 2 inserted, 0 deleted
@@ -1,155 +1,157 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
|
3 | + require 'fileutils' | ||
|
|
4 | + | ||
|
3 | def log(str='') |
|
5 | def log(str='') |
|
4 | if ENV['TALKATIVE']!=nil |
|
6 | if ENV['TALKATIVE']!=nil |
|
5 | puts str |
|
7 | puts str |
|
6 | end |
|
8 | end |
|
7 | if ENV['GRADER_LOGGING']!=nil |
|
9 | if ENV['GRADER_LOGGING']!=nil |
|
8 | log_fname = ENV['GRADER_LOGGING'] |
|
10 | log_fname = ENV['GRADER_LOGGING'] |
|
9 | fp = File.open(log_fname,"a") |
|
11 | fp = File.open(log_fname,"a") |
|
10 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
12 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
11 | fp.close |
|
13 | fp.close |
|
12 | end |
|
14 | end |
|
13 | end |
|
15 | end |
|
14 |
|
16 | ||
|
15 | def extract_time(t) |
|
17 | def extract_time(t) |
|
16 | # puts "TIME: #{t}" |
|
18 | # puts "TIME: #{t}" |
|
17 | if (result=/^(.*)r(.*)u(.*)s/.match(t)) |
|
19 | if (result=/^(.*)r(.*)u(.*)s/.match(t)) |
|
18 | {:real => result[1], :user => result[2], :sys => result[3]} |
|
20 | {:real => result[1], :user => result[2], :sys => result[3]} |
|
19 | else |
|
21 | else |
|
20 | #{:real => 0, :user => 0, :sys => 0} |
|
22 | #{:real => 0, :user => 0, :sys => 0} |
|
21 | #puts "ERROR READING RUNNING TIME: #{t}" |
|
23 | #puts "ERROR READING RUNNING TIME: #{t}" |
|
22 | raise "Error reading running time: #{t}" |
|
24 | raise "Error reading running time: #{t}" |
|
23 | end |
|
25 | end |
|
24 | end |
|
26 | end |
|
25 |
|
27 | ||
|
26 | def compile_box(source,bin) |
|
28 | def compile_box(source,bin) |
|
27 | system("g++ #{source} -o #{bin}") |
|
29 | system("g++ #{source} -o #{bin}") |
|
28 | end |
|
30 | end |
|
29 |
|
31 | ||
|
30 | if ARGV.length < 2 || ARGV.length > 3 |
|
32 | if ARGV.length < 2 || ARGV.length > 3 |
|
31 | puts "Usage: run <language> <test-num> [<program-name>]" |
|
33 | puts "Usage: run <language> <test-num> [<program-name>]" |
|
32 | exit(127) |
|
34 | exit(127) |
|
33 | end |
|
35 | end |
|
34 |
|
36 | ||
|
35 | language = ARGV[0] |
|
37 | language = ARGV[0] |
|
36 | test_num = ARGV[1].to_i |
|
38 | test_num = ARGV[1].to_i |
|
37 | if ARGV.length > 2 |
|
39 | if ARGV.length > 2 |
|
38 | program_name = ARGV[2] |
|
40 | program_name = ARGV[2] |
|
39 | else |
|
41 | else |
|
40 | program_name = "a.out" |
|
42 | program_name = "a.out" |
|
41 | end |
|
43 | end |
|
42 |
|
44 | ||
|
43 | problem_home = ENV['PROBLEM_HOME'] |
|
45 | problem_home = ENV['PROBLEM_HOME'] |
|
44 | require "#{problem_home}/script/test_dsl.rb" |
|
46 | require "#{problem_home}/script/test_dsl.rb" |
|
45 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
47 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
46 | problem = Problem.get_instance |
|
48 | problem = Problem.get_instance |
|
47 |
|
49 | ||
|
48 | if problem.well_formed? == false |
|
50 | if problem.well_formed? == false |
|
49 | log "The problem specification is not well formed." |
|
51 | log "The problem specification is not well formed." |
|
50 | exit(127) |
|
52 | exit(127) |
|
51 | end |
|
53 | end |
|
52 |
|
54 | ||
|
53 | # Check if the test number is okay. |
|
55 | # Check if the test number is okay. |
|
54 | if test_num <= 0 || test_num > problem.num_tests |
|
56 | if test_num <= 0 || test_num > problem.num_tests |
|
55 | log "You have specified a wrong test number." |
|
57 | log "You have specified a wrong test number." |
|
56 | exit(127) |
|
58 | exit(127) |
|
57 | end |
|
59 | end |
|
58 |
|
60 | ||
|
59 | ##################################### |
|
61 | ##################################### |
|
60 | # Set the relavant file names here. # |
|
62 | # Set the relavant file names here. # |
|
61 | ##################################### |
|
63 | ##################################### |
|
62 |
|
64 | ||
|
63 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
65 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
64 |
|
66 | ||
|
65 | ##################################### |
|
67 | ##################################### |
|
66 |
|
68 | ||
|
67 | time_limit = problem.get_time_limit test_num |
|
69 | time_limit = problem.get_time_limit test_num |
|
68 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
70 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
69 |
|
71 | ||
|
70 | # Copy the input file. |
|
72 | # Copy the input file. |
|
71 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
73 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
72 |
|
74 | ||
|
73 | # check if box is there, if not, compile it! |
|
75 | # check if box is there, if not, compile it! |
|
74 | if !File.exists?("#{problem_home}/script/box") |
|
76 | if !File.exists?("#{problem_home}/script/box") |
|
75 | log "WARNING: Compiling box: to increase efficiency, it should be compile manually" |
|
77 | log "WARNING: Compiling box: to increase efficiency, it should be compile manually" |
|
76 | compile_box("#{problem_home}/script/box.cc", |
|
78 | compile_box("#{problem_home}/script/box.cc", |
|
77 | "#{problem_home}/script/box") |
|
79 | "#{problem_home}/script/box") |
|
78 | end |
|
80 | end |
|
79 |
|
81 | ||
|
80 | # Hide PROBLEM_HOME |
|
82 | # Hide PROBLEM_HOME |
|
81 | ENV['PROBLEM_HOME'] = nil |
|
83 | ENV['PROBLEM_HOME'] = nil |
|
82 |
|
84 | ||
|
83 | # Run the program. |
|
85 | # Run the program. |
|
84 | #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}" |
|
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}" |
|
85 | 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" |
|
87 | 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" |
|
86 | log "Running test #{test_num}..." |
|
88 | log "Running test #{test_num}..." |
|
87 | log run_command |
|
89 | log run_command |
|
88 | log |
|
90 | log |
|
89 | system(run_command) |
|
91 | system(run_command) |
|
90 |
|
92 | ||
|
91 | # Restore PROBLEM_HOME |
|
93 | # Restore PROBLEM_HOME |
|
92 | ENV['PROBLEM_HOME'] = problem_home |
|
94 | ENV['PROBLEM_HOME'] = problem_home |
|
93 |
|
95 | ||
|
94 | # Create the result file. |
|
96 | # Create the result file. |
|
95 | result_file = File.new("result", "w") |
|
97 | result_file = File.new("result", "w") |
|
96 | comment_file = File.new("comment", "w") |
|
98 | comment_file = File.new("comment", "w") |
|
97 |
|
99 | ||
|
98 | # Check if the program actually produced any output. |
|
100 | # Check if the program actually produced any output. |
|
99 | run_result_file = File.new("run_result", "r") |
|
101 | run_result_file = File.new("run_result", "r") |
|
100 | run_result = run_result_file.readlines |
|
102 | run_result = run_result_file.readlines |
|
101 | run_result_file.close |
|
103 | run_result_file.close |
|
102 |
|
104 | ||
|
103 | run_stat = run_result[run_result.length-1] |
|
105 | run_stat = run_result[run_result.length-1] |
|
104 | running_time = extract_time(run_stat) |
|
106 | running_time = extract_time(run_stat) |
|
105 |
|
107 | ||
|
106 | report = lambda{ |status, points, comment| |
|
108 | report = lambda{ |status, points, comment| |
|
107 | result_file.write status.strip |
|
109 | result_file.write status.strip |
|
108 | result_file.write "\n" |
|
110 | result_file.write "\n" |
|
109 | result_file.write points.to_s.strip |
|
111 | result_file.write points.to_s.strip |
|
110 | result_file.write "\n" |
|
112 | result_file.write "\n" |
|
111 | result_file.write run_stat.strip |
|
113 | result_file.write run_stat.strip |
|
112 | result_file.write "\n" |
|
114 | result_file.write "\n" |
|
113 | result_file.close |
|
115 | result_file.close |
|
114 | FileUtils.rm "run_result" |
|
116 | FileUtils.rm "run_result" |
|
115 | # `rm output.txt` --- keep the output |
|
117 | # `rm output.txt` --- keep the output |
|
116 |
|
118 | ||
|
117 | comment_file.write comment |
|
119 | comment_file.write comment |
|
118 |
|
120 | ||
|
119 | # added for debuggin --- jittat |
|
121 | # added for debuggin --- jittat |
|
120 | comment_file.write "--run-result--\n" |
|
122 | comment_file.write "--run-result--\n" |
|
121 | run_result.each do |l| |
|
123 | run_result.each do |l| |
|
122 | comment_file.write l |
|
124 | comment_file.write l |
|
123 | end |
|
125 | end |
|
124 |
|
126 | ||
|
125 | comment_file.close |
|
127 | comment_file.close |
|
126 |
|
128 | ||
|
127 | log "Done!" |
|
129 | log "Done!" |
|
128 | exit(0) |
|
130 | exit(0) |
|
129 | } |
|
131 | } |
|
130 |
|
132 | ||
|
131 | if run_result[0][0,2] != "OK" |
|
133 | if run_result[0][0,2] != "OK" |
|
132 | log "There was a runtime error." |
|
134 | log "There was a runtime error." |
|
133 | report.call(run_result[0], 0, "No comment.\n") |
|
135 | report.call(run_result[0], 0, "No comment.\n") |
|
134 | end |
|
136 | end |
|
135 |
|
137 | ||
|
136 | if running_time[:user].to_f + running_time[:sys].to_f > time_limit |
|
138 | if running_time[:user].to_f + running_time[:sys].to_f > time_limit |
|
137 | log "Time limit exceeded." |
|
139 | log "Time limit exceeded." |
|
138 | report.call("Time limit exceeded", 0, "No comment.\n") |
|
140 | report.call("Time limit exceeded", 0, "No comment.\n") |
|
139 | end |
|
141 | end |
|
140 |
|
142 | ||
|
141 | # Run 'check' to evaluate the output. |
|
143 | # Run 'check' to evaluate the output. |
|
142 | #puts "There was no runtime error. Proceed to checking the output." |
|
144 | #puts "There was no runtime error. Proceed to checking the output." |
|
143 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
145 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
144 | log "Checking the output..." |
|
146 | log "Checking the output..." |
|
145 | log check_command |
|
147 | log check_command |
|
146 | if not system(check_command) |
|
148 | if not system(check_command) |
|
147 | log "Problem with check script" |
|
149 | log "Problem with check script" |
|
148 | report.call("Incorrect",0,"Check script error.\n") |
|
150 | report.call("Incorrect",0,"Check script error.\n") |
|
149 | exit(127) |
|
151 | exit(127) |
|
150 | end |
|
152 | end |
|
151 |
|
153 | ||
|
152 | check_file = File.new("check_result", "r") |
|
154 | check_file = File.new("check_result", "r") |
|
153 | check_file_lines = check_file.readlines |
|
155 | check_file_lines = check_file.readlines |
|
154 |
|
156 | ||
|
155 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
|
157 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
You need to be logged in to leave comments.
Login now