Description:
fix various bugs, save output, save comment
git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@21 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r8:4a121cdd0baf - - 3 files changed: 6 inserted, 7 deleted
@@ -1,69 +1,67 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | def char_comment(comment) |
|
3 | def char_comment(comment) |
|
4 | if comment =~ /[iI]ncorrect/ |
|
4 | if comment =~ /[iI]ncorrect/ |
|
5 | '-' |
|
5 | '-' |
|
6 | elsif comment =~ /[Cc]orrect/ |
|
6 | elsif comment =~ /[Cc]orrect/ |
|
7 | 'P' |
|
7 | 'P' |
|
8 | elsif comment =~ /[Tt]ime/ |
|
8 | elsif comment =~ /[Tt]ime/ |
|
9 | 'T' |
|
9 | 'T' |
|
10 | else |
|
10 | else |
|
11 | '?' |
|
11 | '?' |
|
12 | end |
|
12 | end |
|
13 | end |
|
13 | end |
|
14 |
|
14 | ||
|
15 | problem_home = ENV['PROBLEM_HOME'] |
|
15 | problem_home = ENV['PROBLEM_HOME'] |
|
16 | require "#{problem_home}/script/test_dsl.rb" |
|
16 | require "#{problem_home}/script/test_dsl.rb" |
|
17 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
17 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
18 | problem = Problem.get_instance |
|
18 | problem = Problem.get_instance |
|
19 |
|
19 | ||
|
20 | if problem.well_formed? == false |
|
20 | if problem.well_formed? == false |
|
21 | puts "The problem specification is not well formed." |
|
21 | puts "The problem specification is not well formed." |
|
22 | exit(127) |
|
22 | exit(127) |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | all_score = 0 |
|
25 | all_score = 0 |
|
26 | all_comment = '' |
|
26 | all_comment = '' |
|
27 | (1..(problem.runs.length-1)).each do |k| |
|
27 | (1..(problem.runs.length-1)).each do |k| |
|
28 | run = problem.runs[k] |
|
28 | run = problem.runs[k] |
|
29 | run_score = 0 |
|
29 | run_score = 0 |
|
30 | run_comment = '' |
|
30 | run_comment = '' |
|
|
31 | + run_comment_short = '' | ||
|
31 | run.tests.each do |test_num| |
|
32 | run.tests.each do |test_num| |
|
32 | result_file_name = "#{test_num}/result" |
|
33 | result_file_name = "#{test_num}/result" |
|
33 | if not File.exists?(result_file_name) |
|
34 | if not File.exists?(result_file_name) |
|
34 | puts "Cannot find the file #{test_num}/result!" |
|
35 | puts "Cannot find the file #{test_num}/result!" |
|
35 | exit(127) |
|
36 | exit(127) |
|
36 | end |
|
37 | end |
|
37 |
|
38 | ||
|
38 | result_file = File.new(result_file_name, "r") |
|
39 | result_file = File.new(result_file_name, "r") |
|
39 | result_file_lines = result_file.readlines |
|
40 | result_file_lines = result_file.readlines |
|
40 | run_score = run_score + result_file_lines[1].to_i |
|
41 | run_score = run_score + result_file_lines[1].to_i |
|
41 |
- |
|
42 | + run_comment += result_file_lines[0] |
|
42 | - result_file_lines.each do |l| |
|
43 | + run_comment_short += char_comment(result_file_lines[0]) |
|
43 | - run_comment += l |
|
||
|
44 | - end |
|
||
|
45 | - run_comment += "----\n" |
|
||
|
46 | result_file.close |
|
44 | result_file.close |
|
47 | end |
|
45 | end |
|
48 |
|
46 | ||
|
49 | run_result_file = File.new("result-#{k}", "w") |
|
47 | run_result_file = File.new("result-#{k}", "w") |
|
50 | run_result_file.write run_score |
|
48 | run_result_file.write run_score |
|
51 | run_result_file.write "\n" |
|
49 | run_result_file.write "\n" |
|
52 | run_result_file.close |
|
50 | run_result_file.close |
|
53 |
|
51 | ||
|
54 | run_comment_file = File.new("comment-#{k}", "w") |
|
52 | run_comment_file = File.new("comment-#{k}", "w") |
|
55 | run_comment_file.write "#{run_comment}\n" |
|
53 | run_comment_file.write "#{run_comment}\n" |
|
56 | run_comment_file.close |
|
54 | run_comment_file.close |
|
57 |
|
55 | ||
|
58 | all_score = all_score + run_score |
|
56 | all_score = all_score + run_score |
|
59 | - all_comment += run_comment |
|
57 | + all_comment += run_comment_short |
|
60 | end |
|
58 | end |
|
61 |
|
59 | ||
|
62 | result_file = File.new("result", "w") |
|
60 | result_file = File.new("result", "w") |
|
63 | result_file.write all_score |
|
61 | result_file.write all_score |
|
64 | result_file.write "\n" |
|
62 | result_file.write "\n" |
|
65 | result_file.close |
|
63 | result_file.close |
|
66 |
|
64 | ||
|
67 | comment_file = File.new("comment", "w") |
|
65 | comment_file = File.new("comment", "w") |
|
68 | comment_file.write "#{all_comment}\n" |
|
66 | comment_file.write "#{all_comment}\n" |
|
69 | comment_file.close |
|
67 | comment_file.close |
@@ -51,64 +51,65 | |||||
|
51 | if ARGV.length >= 4 |
|
51 | if ARGV.length >= 4 |
|
52 | sandbox_dir = ARGV[3] |
|
52 | sandbox_dir = ARGV[3] |
|
53 | else |
|
53 | else |
|
54 | sandbox_dir = "#{current_dir}/sandbox" |
|
54 | sandbox_dir = "#{current_dir}/sandbox" |
|
55 | end |
|
55 | end |
|
56 | puts "Sandbox directory: #{sandbox_dir}" |
|
56 | puts "Sandbox directory: #{sandbox_dir}" |
|
57 | system("rm -Rf #{sandbox_dir}") |
|
57 | system("rm -Rf #{sandbox_dir}") |
|
58 | execute("mkdir #{sandbox_dir}", "Cannot make directory #{sandbox_dir}") |
|
58 | execute("mkdir #{sandbox_dir}", "Cannot make directory #{sandbox_dir}") |
|
59 |
|
59 | ||
|
60 | # Compile |
|
60 | # Compile |
|
61 | puts |
|
61 | puts |
|
62 | puts "Compiling..." |
|
62 | puts "Compiling..." |
|
63 | execute("cp #{source_file} #{sandbox_dir}", "Cannot copy the source file to #{sandbox_dir}") |
|
63 | execute("cp #{source_file} #{sandbox_dir}", "Cannot copy the source file to #{sandbox_dir}") |
|
64 | begin |
|
64 | begin |
|
65 | Dir.chdir sandbox_dir |
|
65 | Dir.chdir sandbox_dir |
|
66 | rescue |
|
66 | rescue |
|
67 | puts "ERROR: Cannot change directory to #{sandbox_dir}." |
|
67 | puts "ERROR: Cannot change directory to #{sandbox_dir}." |
|
68 | exit(127) |
|
68 | exit(127) |
|
69 | end |
|
69 | end |
|
70 | execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
70 | execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
71 | compile_message = `cat compiler_message` |
|
71 | compile_message = `cat compiler_message` |
|
72 | compile_message.strip! |
|
72 | compile_message.strip! |
|
73 | execute("mv compiler_message #{test_result_dir}", "Cannot move the compiler message to #{test_result_dir}.") |
|
73 | execute("mv compiler_message #{test_result_dir}", "Cannot move the compiler message to #{test_result_dir}.") |
|
74 | if !FileTest.exist?("a.out") |
|
74 | if !FileTest.exist?("a.out") |
|
75 | puts "Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
75 | puts "Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
76 | exit(127) |
|
76 | exit(127) |
|
77 | else |
|
77 | else |
|
78 | execute("mv a.out #{test_result_dir}", "Cannot move the compiled program to #{test_result_dir}") |
|
78 | execute("mv a.out #{test_result_dir}", "Cannot move the compiled program to #{test_result_dir}") |
|
79 | system("rm -Rf #{sandbox_dir}/*") |
|
79 | system("rm -Rf #{sandbox_dir}/*") |
|
80 | end |
|
80 | end |
|
81 |
|
81 | ||
|
82 | require "#{problem_home}/script/test_dsl.rb" |
|
82 | require "#{problem_home}/script/test_dsl.rb" |
|
83 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
83 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
84 | problem = Problem.get_instance |
|
84 | problem = Problem.get_instance |
|
85 |
|
85 | ||
|
86 | if problem.well_formed? == false |
|
86 | if problem.well_formed? == false |
|
87 | puts "The problem specification is not well formed." |
|
87 | puts "The problem specification is not well formed." |
|
88 | exit(127) |
|
88 | exit(127) |
|
89 | end |
|
89 | end |
|
90 |
|
90 | ||
|
91 | # Doing the testing. |
|
91 | # Doing the testing. |
|
92 | (1..(problem.num_tests)).each do |test_num| |
|
92 | (1..(problem.num_tests)).each do |test_num| |
|
93 | puts |
|
93 | puts |
|
94 | execute("cp #{test_result_dir}/a.out #{sandbox_dir}", "Cannot copy the compiled program into #{sandbox_dir}") |
|
94 | execute("cp #{test_result_dir}/a.out #{sandbox_dir}", "Cannot copy the compiled program into #{sandbox_dir}") |
|
95 | execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") |
|
95 | execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") |
|
96 | execute("mkdir #{test_result_dir}/#{test_num}", "Cannot create directory #{test_result_dir}/#{test_num}") |
|
96 | execute("mkdir #{test_result_dir}/#{test_num}", "Cannot create directory #{test_result_dir}/#{test_num}") |
|
97 | execute("mv #{sandbox_dir}/result #{test_result_dir}/#{test_num}", "Cannot copy the result file into #{test_result_dir}/#{test_num}") |
|
97 | execute("mv #{sandbox_dir}/result #{test_result_dir}/#{test_num}", "Cannot copy the result file into #{test_result_dir}/#{test_num}") |
|
98 | execute("mv #{sandbox_dir}/comment #{test_result_dir}/#{test_num}", "Cannot copy the comment file into #{test_result_dir}/#{test_num}") |
|
98 | execute("mv #{sandbox_dir}/comment #{test_result_dir}/#{test_num}", "Cannot copy the comment file into #{test_result_dir}/#{test_num}") |
|
|
99 | + execute("mv #{sandbox_dir}/output.txt #{test_result_dir}/#{test_num}", "Cannot copy the output file into #{test_result_dir}/#{test_num}") | ||
|
99 | execute("rm -Rf #{sandbox_dir}/*", "Cannot clear #{sandbox_dir}") |
|
100 | execute("rm -Rf #{sandbox_dir}/*", "Cannot clear #{sandbox_dir}") |
|
100 | end |
|
101 | end |
|
101 |
|
102 | ||
|
102 | # Grade |
|
103 | # Grade |
|
103 | puts |
|
104 | puts |
|
104 | puts "Grading..." |
|
105 | puts "Grading..." |
|
105 | begin |
|
106 | begin |
|
106 | Dir.chdir test_result_dir |
|
107 | Dir.chdir test_result_dir |
|
107 | rescue |
|
108 | rescue |
|
108 | puts "ERROR: Cannot change directory to #{test_result_dir}." |
|
109 | puts "ERROR: Cannot change directory to #{test_result_dir}." |
|
109 | exit(127) |
|
110 | exit(127) |
|
110 | end |
|
111 | end |
|
111 | execute("#{problem_home}/script/grade", "An error occured during grading!") |
|
112 | execute("#{problem_home}/script/grade", "An error occured during grading!") |
|
112 |
|
113 | ||
|
113 | puts |
|
114 | puts |
|
114 | puts "All done!" |
|
115 | puts "All done!" |
@@ -24,80 +24,80 | |||||
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | # Check if the test number is okay. |
|
26 | # Check if the test number is okay. |
|
27 | if test_num <= 0 || test_num > problem.num_tests |
|
27 | if test_num <= 0 || test_num > problem.num_tests |
|
28 | puts "You have specified a wrong test number." |
|
28 | puts "You have specified a wrong test number." |
|
29 | exit(127) |
|
29 | exit(127) |
|
30 | end |
|
30 | end |
|
31 |
|
31 | ||
|
32 | ##################################### |
|
32 | ##################################### |
|
33 | # Set the relavant file names here. # |
|
33 | # Set the relavant file names here. # |
|
34 | ##################################### |
|
34 | ##################################### |
|
35 |
|
35 | ||
|
36 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
36 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
37 |
|
37 | ||
|
38 | ##################################### |
|
38 | ##################################### |
|
39 |
|
39 | ||
|
40 | time_limit = problem.get_time_limit test_num |
|
40 | time_limit = problem.get_time_limit test_num |
|
41 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
41 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
42 |
|
42 | ||
|
43 | # Copy the input file. |
|
43 | # Copy the input file. |
|
44 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
44 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
45 |
|
45 | ||
|
46 | # Run the program. |
|
46 | # Run the program. |
|
47 | run_command = "/usr/bin/time -f \"%E\" 2>run_result #{problem_home}/script/box -a 2 -f -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name}" |
|
47 | run_command = "/usr/bin/time -f \"%E\" 2>run_result #{problem_home}/script/box -a 2 -f -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name}" |
|
48 | puts "Running test #{test_num}..." |
|
48 | puts "Running test #{test_num}..." |
|
49 | puts run_command |
|
49 | puts run_command |
|
50 | puts |
|
50 | puts |
|
51 | system(run_command) |
|
51 | system(run_command) |
|
52 |
|
52 | ||
|
53 | # Create the result file. |
|
53 | # Create the result file. |
|
54 | result_file = File.new("result", "w") |
|
54 | result_file = File.new("result", "w") |
|
55 | comment_file = File.new("comment", "w") |
|
55 | comment_file = File.new("comment", "w") |
|
56 |
|
56 | ||
|
57 | # Check if the program actually produced any output. |
|
57 | # Check if the program actually produced any output. |
|
58 | run_result_file = File.new("run_result", "r") |
|
58 | run_result_file = File.new("run_result", "r") |
|
59 | run_result = run_result_file.readlines |
|
59 | run_result = run_result_file.readlines |
|
60 | run_result_file.close |
|
60 | run_result_file.close |
|
61 | time_elapsed = run_result[run_result.length-1] |
|
61 | time_elapsed = run_result[run_result.length-1] |
|
62 |
|
62 | ||
|
63 | report = lambda{ |status, points, comment| |
|
63 | report = lambda{ |status, points, comment| |
|
64 | result_file.write status.strip |
|
64 | result_file.write status.strip |
|
65 | result_file.write "\n" |
|
65 | result_file.write "\n" |
|
66 | result_file.write points.to_s.strip |
|
66 | result_file.write points.to_s.strip |
|
67 | result_file.write "\n" |
|
67 | result_file.write "\n" |
|
68 | result_file.write time_elapsed.strip |
|
68 | result_file.write time_elapsed.strip |
|
69 | result_file.write "\n" |
|
69 | result_file.write "\n" |
|
70 | result_file.close |
|
70 | result_file.close |
|
71 | `rm run_result` |
|
71 | `rm run_result` |
|
72 | - `rm output.txt` |
|
72 | + # `rm output.txt` --- keep the output |
|
73 |
|
73 | ||
|
74 | comment_file.write comment |
|
74 | comment_file.write comment |
|
75 | comment_file.write "--run-result--\n" |
|
75 | comment_file.write "--run-result--\n" |
|
76 | run_result.each do |l| |
|
76 | run_result.each do |l| |
|
77 | comment_file.write l |
|
77 | comment_file.write l |
|
78 | end |
|
78 | end |
|
79 | comment_file.close |
|
79 | comment_file.close |
|
80 |
|
80 | ||
|
81 | puts |
|
81 | puts |
|
82 | puts "Done!" |
|
82 | puts "Done!" |
|
83 | exit(0) |
|
83 | exit(0) |
|
84 | } |
|
84 | } |
|
85 |
|
85 | ||
|
86 | if run_result[0][0,2] != "OK" |
|
86 | if run_result[0][0,2] != "OK" |
|
87 | puts "There was a runtime error." |
|
87 | puts "There was a runtime error." |
|
88 | report.call(run_result[0], 0, "No comment.\n") |
|
88 | report.call(run_result[0], 0, "No comment.\n") |
|
89 | end |
|
89 | end |
|
90 |
|
90 | ||
|
91 | # Run 'check' to evaluate the output. |
|
91 | # Run 'check' to evaluate the output. |
|
92 | #puts "There was no runtime error. Proceed to checking the output." |
|
92 | #puts "There was no runtime error. Proceed to checking the output." |
|
93 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
93 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
94 | puts "Checking the output..." |
|
94 | puts "Checking the output..." |
|
95 | puts check_command |
|
95 | puts check_command |
|
96 | if not system(check_command) |
|
96 | if not system(check_command) |
|
97 | exit(127) |
|
97 | exit(127) |
|
98 | end |
|
98 | end |
|
99 |
|
99 | ||
|
100 | check_file = File.new("check_result", "r") |
|
100 | check_file = File.new("check_result", "r") |
|
101 | check_file_lines = check_file.readlines |
|
101 | check_file_lines = check_file.readlines |
|
102 |
|
102 | ||
|
103 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
|
103 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
You need to be logged in to leave comments.
Login now