Description:
[grader] fixed: import_problem (error in erb calls), check_wrapper; better error handling -- will get 0 score for a particular test run that fails
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@118 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
r31:d810d6c2e99e - - 5 files changed: 28 inserted, 15 deleted
@@ -1,139 +1,139 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | # import_problem: |
|
3 | # import_problem: |
|
4 | # * creates a directory for a problem in the current directory, |
|
4 | # * creates a directory for a problem in the current directory, |
|
5 | # * copy testdata in the old format and create standard testcase config file |
|
5 | # * copy testdata in the old format and create standard testcase config file |
|
6 |
|
6 | ||
|
7 | require 'erb' |
|
7 | require 'erb' |
|
8 | require 'fileutils' |
|
8 | require 'fileutils' |
|
9 |
|
9 | ||
|
10 | def input_filename(dir,i) |
|
10 | def input_filename(dir,i) |
|
11 | "#{dir}/input-#{i}.txt" |
|
11 | "#{dir}/input-#{i}.txt" |
|
12 | end |
|
12 | end |
|
13 |
|
13 | ||
|
14 | def answer_filename(dir,i) |
|
14 | def answer_filename(dir,i) |
|
15 | "#{dir}/answer-#{i}.txt" |
|
15 | "#{dir}/answer-#{i}.txt" |
|
16 | end |
|
16 | end |
|
17 |
|
17 | ||
|
18 | def copy_testcase(importing_test_dir,dir,i) |
|
18 | def copy_testcase(importing_test_dir,dir,i) |
|
19 | system("cp #{importing_test_dir}/#{i}.in #{input_filename(dir,i)}") |
|
19 | system("cp #{importing_test_dir}/#{i}.in #{input_filename(dir,i)}") |
|
20 | system("cp #{importing_test_dir}/#{i}.sol #{answer_filename(dir,i)}") |
|
20 | system("cp #{importing_test_dir}/#{i}.sol #{answer_filename(dir,i)}") |
|
21 | end |
|
21 | end |
|
22 |
|
22 | ||
|
23 | def process_options(options) |
|
23 | def process_options(options) |
|
24 | i = 4 |
|
24 | i = 4 |
|
25 | while i<ARGV.length |
|
25 | while i<ARGV.length |
|
26 | if ARGV[i]=='-t' |
|
26 | if ARGV[i]=='-t' |
|
27 | options[:time_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
27 | options[:time_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
28 | i += 1 |
|
28 | i += 1 |
|
29 | end |
|
29 | end |
|
30 | if ARGV[i]=='-m' |
|
30 | if ARGV[i]=='-m' |
|
31 | options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
31 | options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
32 | i += 1 |
|
32 | i += 1 |
|
33 | end |
|
33 | end |
|
34 | i += 1 |
|
34 | i += 1 |
|
35 | end |
|
35 | end |
|
36 | end |
|
36 | end |
|
37 |
|
37 | ||
|
38 | SCRIPT_DIR = File.dirname(__FILE__) |
|
38 | SCRIPT_DIR = File.dirname(__FILE__) |
|
39 |
|
39 | ||
|
40 | # print usage |
|
40 | # print usage |
|
41 | if (ARGV.length < 4) or (ARGV[3][0,1]=="-") |
|
41 | if (ARGV.length < 4) or (ARGV[3][0,1]=="-") |
|
42 | puts <<USAGE |
|
42 | puts <<USAGE |
|
43 | using: import_problem name dir num check [options] |
|
43 | using: import_problem name dir num check [options] |
|
44 | where: name = problem_name [ |
|
44 | where: name = problem_name [ |
|
45 | dir = importing testcase directory |
|
45 | dir = importing testcase directory |
|
46 | num = number of testcases |
|
46 | num = number of testcases |
|
47 | check = check script, which can be |
|
47 | check = check script, which can be |
|
48 | 'integer', 'text' (for standard script), |
|
48 | 'integer', 'text' (for standard script), |
|
49 | path_to_your_script, or |
|
49 | path_to_your_script, or |
|
50 | 'wrapper:(path_to_your_wrapped_script)' |
|
50 | 'wrapper:(path_to_your_wrapped_script)' |
|
51 | options: -t time-limit (in seconds) |
|
51 | options: -t time-limit (in seconds) |
|
52 | -m memory-limit (in megabytes) |
|
52 | -m memory-limit (in megabytes) |
|
53 | What it does: |
|
53 | What it does: |
|
54 | * creates a directory for a problem in the current directory, |
|
54 | * creates a directory for a problem in the current directory, |
|
55 | * copies testdata in the old format and create standard testcase config file |
|
55 | * copies testdata in the old format and create standard testcase config file |
|
56 | * copies a check script for grading |
|
56 | * copies a check script for grading |
|
57 | * creates a test_request template in the current directory + '/test_request' |
|
57 | * creates a test_request template in the current directory + '/test_request' |
|
58 |
|
58 | ||
|
59 | For wrapped checked script see comment in templates/check_wrapper for |
|
59 | For wrapped checked script see comment in templates/check_wrapper for |
|
60 | information. |
|
60 | information. |
|
61 | USAGE |
|
61 | USAGE |
|
62 | exit(127) |
|
62 | exit(127) |
|
63 | end |
|
63 | end |
|
64 |
|
64 | ||
|
65 | # processing arguments |
|
65 | # processing arguments |
|
66 | problem = ARGV[0] |
|
66 | problem = ARGV[0] |
|
67 | testcase_dir = ARGV[1] |
|
67 | testcase_dir = ARGV[1] |
|
68 | num_testcases = ARGV[2].to_i |
|
68 | num_testcases = ARGV[2].to_i |
|
69 | check_script = ARGV[3] |
|
69 | check_script = ARGV[3] |
|
70 | options = {:time_limit => 1, :mem_limit => 16} |
|
70 | options = {:time_limit => 1, :mem_limit => 16} |
|
71 | process_options(options) |
|
71 | process_options(options) |
|
72 |
|
72 | ||
|
73 | # start working |
|
73 | # start working |
|
74 | puts "creating directories" |
|
74 | puts "creating directories" |
|
75 |
|
75 | ||
|
76 | system("mkdir #{problem}") |
|
76 | system("mkdir #{problem}") |
|
77 | system("mkdir #{problem}/script") |
|
77 | system("mkdir #{problem}/script") |
|
78 | system("mkdir #{problem}/test_cases") |
|
78 | system("mkdir #{problem}/test_cases") |
|
79 | #system("cp #{GRADER_DIR}/std-script/* #{problem}/script") |
|
79 | #system("cp #{GRADER_DIR}/std-script/* #{problem}/script") |
|
80 |
|
80 | ||
|
81 | puts "copying testcases" |
|
81 | puts "copying testcases" |
|
82 |
|
82 | ||
|
83 | 1.upto(num_testcases) do |i| |
|
83 | 1.upto(num_testcases) do |i| |
|
84 | system("mkdir #{problem}/test_cases/#{i}") |
|
84 | system("mkdir #{problem}/test_cases/#{i}") |
|
85 | copy_testcase("#{testcase_dir}","#{problem}/test_cases/#{i}",i) |
|
85 | copy_testcase("#{testcase_dir}","#{problem}/test_cases/#{i}",i) |
|
86 | end |
|
86 | end |
|
87 |
|
87 | ||
|
88 |
|
88 | ||
|
89 | # generating all_tests.cfg |
|
89 | # generating all_tests.cfg |
|
90 | puts "generating testcase config file" |
|
90 | puts "generating testcase config file" |
|
91 |
|
91 | ||
|
92 | template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read |
|
92 | template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read |
|
93 | all_test_cfg = ERB.new(template) |
|
93 | all_test_cfg = ERB.new(template) |
|
94 |
|
94 | ||
|
95 | cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") |
|
95 | cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") |
|
96 | cfg_file.puts all_test_cfg.result |
|
96 | cfg_file.puts all_test_cfg.result |
|
97 | cfg_file.close |
|
97 | cfg_file.close |
|
98 |
|
98 | ||
|
99 |
|
99 | ||
|
100 | # copy check script |
|
100 | # copy check script |
|
101 | if res = /^wrapper:(.*)$/.match(check_script) |
|
101 | if res = /^wrapper:(.*)$/.match(check_script) |
|
102 | # wrapper script |
|
102 | # wrapper script |
|
103 | check_script_fname = res[1] |
|
103 | check_script_fname = res[1] |
|
104 | script_name = File.basename(check_script_fname) |
|
104 | script_name = File.basename(check_script_fname) |
|
105 | - check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper") |
|
105 | + check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read |
|
106 | - check_wrapper = ERB.new(template) |
|
106 | + check_wrapper = ERB.new(check_wrapper_template) |
|
107 |
|
107 | ||
|
108 | check_file = File.open("#{problem}/script/check","w") |
|
108 | check_file = File.open("#{problem}/script/check","w") |
|
109 | - check_file.puts check_wrapper |
|
109 | + check_file.puts check_wrapper.result |
|
110 | check_file.close |
|
110 | check_file.close |
|
111 |
|
111 | ||
|
112 | File.chmod(0755,"#{problem}/script/check") |
|
112 | File.chmod(0755,"#{problem}/script/check") |
|
113 |
|
113 | ||
|
114 | system("cp #{check_script_fname} #{problem}/script/#{script_name}") |
|
114 | system("cp #{check_script_fname} #{problem}/script/#{script_name}") |
|
115 | else |
|
115 | else |
|
116 | if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") |
|
116 | if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") |
|
117 | check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" |
|
117 | check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" |
|
118 | else |
|
118 | else |
|
119 | check_script_fname = check_script |
|
119 | check_script_fname = check_script |
|
120 | end |
|
120 | end |
|
121 | system("cp #{check_script_fname} #{problem}/script/check") |
|
121 | system("cp #{check_script_fname} #{problem}/script/check") |
|
122 | end |
|
122 | end |
|
123 |
|
123 | ||
|
124 | # generating test_request directory |
|
124 | # generating test_request directory |
|
125 | puts "generating test_request template" |
|
125 | puts "generating test_request template" |
|
126 | FileUtils.mkdir_p("test_request/#{problem}/script") |
|
126 | FileUtils.mkdir_p("test_request/#{problem}/script") |
|
127 | FileUtils.mkdir_p("test_request/#{problem}/test_cases/1") |
|
127 | FileUtils.mkdir_p("test_request/#{problem}/test_cases/1") |
|
128 |
|
128 | ||
|
129 | template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read |
|
129 | template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read |
|
130 | test_request_all_test_cfg = ERB.new(template) |
|
130 | test_request_all_test_cfg = ERB.new(template) |
|
131 |
|
131 | ||
|
132 | cfg_file = File.open("test_request/#{problem}/test_cases/all_tests.cfg","w") |
|
132 | cfg_file = File.open("test_request/#{problem}/test_cases/all_tests.cfg","w") |
|
133 | cfg_file.puts test_request_all_test_cfg.result |
|
133 | cfg_file.puts test_request_all_test_cfg.result |
|
134 | cfg_file.close |
|
134 | cfg_file.close |
|
135 |
|
135 | ||
|
136 | system("cp #{SCRIPT_DIR}/templates/check_empty test_request/#{problem}/script/check") |
|
136 | system("cp #{SCRIPT_DIR}/templates/check_empty test_request/#{problem}/script/check") |
|
137 | system("cp #{SCRIPT_DIR}/templates/answer-1.txt test_request/#{problem}/test_cases/1") |
|
137 | system("cp #{SCRIPT_DIR}/templates/answer-1.txt test_request/#{problem}/test_cases/1") |
|
138 |
|
138 | ||
|
139 | puts "done" |
|
139 | puts "done" |
@@ -1,81 +1,86 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
|
3 | + CORRECT_MARK = 'P' | ||
|
|
4 | + INCORRECT_MARK = '-' | ||
|
|
5 | + TIMEOUT_MARK = 'T' | ||
|
|
6 | + RUN_ERROR_MARK = 'x' | ||
|
|
7 | + | ||
|
3 | def log(str='') |
|
8 | def log(str='') |
|
4 | if ENV['TALKATIVE']!=nil |
|
9 | if ENV['TALKATIVE']!=nil |
|
5 | puts str |
|
10 | puts str |
|
6 | end |
|
11 | end |
|
7 | if ENV['GRADER_LOGGING']!=nil |
|
12 | if ENV['GRADER_LOGGING']!=nil |
|
8 | log_fname = ENV['GRADER_LOGGING'] |
|
13 | log_fname = ENV['GRADER_LOGGING'] |
|
9 | fp = File.open(log_fname,"a") |
|
14 | fp = File.open(log_fname,"a") |
|
10 | fp.puts("grade: #{Time.new.strftime("%H:%M")} #{str}") |
|
15 | fp.puts("grade: #{Time.new.strftime("%H:%M")} #{str}") |
|
11 | fp.close |
|
16 | fp.close |
|
12 | end |
|
17 | end |
|
13 | end |
|
18 | end |
|
14 |
|
19 | ||
|
15 | def char_comment(comment) |
|
20 | def char_comment(comment) |
|
16 | if comment =~ /[iI]ncorrect/ |
|
21 | if comment =~ /[iI]ncorrect/ |
|
17 | - '-' |
|
22 | + INCORRECT_MARK |
|
18 | elsif comment =~ /[Cc]orrect/ |
|
23 | elsif comment =~ /[Cc]orrect/ |
|
19 | - 'P' |
|
24 | + CORRECT_MARK |
|
20 | elsif comment =~ /[Tt]ime/ |
|
25 | elsif comment =~ /[Tt]ime/ |
|
21 | - 'T' |
|
26 | + TIMEOUT_MARK |
|
22 | else |
|
27 | else |
|
23 |
- |
|
28 | + RUN_ERROR_MARK # these are run time errors |
|
24 | end |
|
29 | end |
|
25 | end |
|
30 | end |
|
26 |
|
31 | ||
|
27 | problem_home = ENV['PROBLEM_HOME'] |
|
32 | problem_home = ENV['PROBLEM_HOME'] |
|
28 | require "#{problem_home}/script/test_dsl.rb" |
|
33 | require "#{problem_home}/script/test_dsl.rb" |
|
29 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
34 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
30 | problem = Problem.get_instance |
|
35 | problem = Problem.get_instance |
|
31 |
|
36 | ||
|
32 | if problem.well_formed? == false |
|
37 | if problem.well_formed? == false |
|
33 | log "The problem specification is not well formed." |
|
38 | log "The problem specification is not well formed." |
|
34 | exit(127) |
|
39 | exit(127) |
|
35 | end |
|
40 | end |
|
36 |
|
41 | ||
|
37 | all_score = 0 |
|
42 | all_score = 0 |
|
38 | all_comment = '' |
|
43 | all_comment = '' |
|
39 | (1..(problem.runs.length-1)).each do |k| |
|
44 | (1..(problem.runs.length-1)).each do |k| |
|
40 | log "grade run #{k}" |
|
45 | log "grade run #{k}" |
|
41 | run = problem.runs[k] |
|
46 | run = problem.runs[k] |
|
42 | run_score = 0 |
|
47 | run_score = 0 |
|
43 | run_comment = '' |
|
48 | run_comment = '' |
|
44 | run_comment_short = '' |
|
49 | run_comment_short = '' |
|
45 | run.tests.each do |test_num| |
|
50 | run.tests.each do |test_num| |
|
46 | result_file_name = "#{test_num}/result" |
|
51 | result_file_name = "#{test_num}/result" |
|
47 | if not File.exists?(result_file_name) |
|
52 | if not File.exists?(result_file_name) |
|
48 | run_comment += "result file for test #{test_num} not found\n" |
|
53 | run_comment += "result file for test #{test_num} not found\n" |
|
49 |
- run_comment_short += |
|
54 | + run_comment_short += RUN_ERROR_MARK |
|
50 | log "Cannot find the file #{test_num}/result!" |
|
55 | log "Cannot find the file #{test_num}/result!" |
|
51 | else |
|
56 | else |
|
52 | result_file = File.new(result_file_name, "r") |
|
57 | result_file = File.new(result_file_name, "r") |
|
53 | result_file_lines = result_file.readlines |
|
58 | result_file_lines = result_file.readlines |
|
54 | run_score = run_score + result_file_lines[1].to_i |
|
59 | run_score = run_score + result_file_lines[1].to_i |
|
55 | run_comment += result_file_lines[0] |
|
60 | run_comment += result_file_lines[0] |
|
56 | run_comment_short += char_comment(result_file_lines[0]) |
|
61 | run_comment_short += char_comment(result_file_lines[0]) |
|
57 | result_file.close |
|
62 | result_file.close |
|
58 | end |
|
63 | end |
|
59 | end |
|
64 | end |
|
60 |
|
65 | ||
|
61 | run_result_file = File.new("result-#{k}", "w") |
|
66 | run_result_file = File.new("result-#{k}", "w") |
|
62 | run_result_file.write run_score |
|
67 | run_result_file.write run_score |
|
63 | run_result_file.write "\n" |
|
68 | run_result_file.write "\n" |
|
64 | run_result_file.close |
|
69 | run_result_file.close |
|
65 |
|
70 | ||
|
66 | run_comment_file = File.new("comment-#{k}", "w") |
|
71 | run_comment_file = File.new("comment-#{k}", "w") |
|
67 | run_comment_file.write "#{run_comment}\n" |
|
72 | run_comment_file.write "#{run_comment}\n" |
|
68 | run_comment_file.close |
|
73 | run_comment_file.close |
|
69 |
|
74 | ||
|
70 | all_score = all_score + run_score |
|
75 | all_score = all_score + run_score |
|
71 | all_comment += run_comment_short |
|
76 | all_comment += run_comment_short |
|
72 | end |
|
77 | end |
|
73 |
|
78 | ||
|
74 | result_file = File.new("result", "w") |
|
79 | result_file = File.new("result", "w") |
|
75 | result_file.write all_score |
|
80 | result_file.write all_score |
|
76 | result_file.write "\n" |
|
81 | result_file.write "\n" |
|
77 | result_file.close |
|
82 | result_file.close |
|
78 |
|
83 | ||
|
79 | comment_file = File.new("comment", "w") |
|
84 | comment_file = File.new("comment", "w") |
|
80 | comment_file.write "#{all_comment}\n" |
|
85 | comment_file.write "#{all_comment}\n" |
|
81 | comment_file.close |
|
86 | comment_file.close |
@@ -1,128 +1,132 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | def log(str='') |
|
3 | def log(str='') |
|
4 | if ENV['TALKATIVE']!=nil |
|
4 | if ENV['TALKATIVE']!=nil |
|
5 | puts str |
|
5 | puts str |
|
6 | end |
|
6 | end |
|
7 | if ENV['GRADER_LOGGING']!=nil |
|
7 | if ENV['GRADER_LOGGING']!=nil |
|
8 | log_fname = ENV['GRADER_LOGGING'] |
|
8 | log_fname = ENV['GRADER_LOGGING'] |
|
9 | fp = File.open(log_fname,"a") |
|
9 | fp = File.open(log_fname,"a") |
|
10 | fp.puts("judge: #{Time.new.strftime("%H:%M")} #{str}") |
|
10 | fp.puts("judge: #{Time.new.strftime("%H:%M")} #{str}") |
|
11 | fp.close |
|
11 | fp.close |
|
12 | end |
|
12 | end |
|
13 | end |
|
13 | end |
|
14 |
|
14 | ||
|
15 | problem_home = ENV['PROBLEM_HOME'] |
|
15 | problem_home = ENV['PROBLEM_HOME'] |
|
16 |
|
16 | ||
|
17 | def execute(command, error_message="") |
|
17 | def execute(command, error_message="") |
|
18 | if not system(command) |
|
18 | if not system(command) |
|
19 |
- |
|
19 | + msg = "ERROR: #{error_message}" |
|
20 | - puts "ERROR: #{error_message}" |
|
20 | + log msg |
|
21 | - exit(127) |
|
21 | + raise msg |
|
22 | end |
|
22 | end |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | # ARGV[0] --- language |
|
25 | # ARGV[0] --- language |
|
26 | # ARGV[1] --- program source file |
|
26 | # ARGV[1] --- program source file |
|
27 | # ARGV[2] --- test result directory |
|
27 | # ARGV[2] --- test result directory |
|
28 | # ARGV[3] --- sandbox directory |
|
28 | # ARGV[3] --- sandbox directory |
|
29 |
|
29 | ||
|
30 | if ARGV.length < 2 || ARGV.length > 4 |
|
30 | if ARGV.length < 2 || ARGV.length > 4 |
|
31 | puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]" |
|
31 | puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]" |
|
32 | puts " <sandbox-directory> is defaulted to ./sandbox" |
|
32 | puts " <sandbox-directory> is defaulted to ./sandbox" |
|
33 | puts " <test-result-directory> is defaulted to ./test-result" |
|
33 | puts " <test-result-directory> is defaulted to ./test-result" |
|
34 | puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it." |
|
34 | puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it." |
|
35 | exit(127) |
|
35 | exit(127) |
|
36 | end |
|
36 | end |
|
37 |
|
37 | ||
|
38 | language = ARGV[0] |
|
38 | language = ARGV[0] |
|
39 | if language != "c" && language != "c++" && language != "pascal" |
|
39 | if language != "c" && language != "c++" && language != "pascal" |
|
40 | log "You specified a language that is not supported." |
|
40 | log "You specified a language that is not supported." |
|
41 | exit(127) |
|
41 | exit(127) |
|
42 | end |
|
42 | end |
|
43 |
|
43 | ||
|
44 | source_file = ARGV[1] |
|
44 | source_file = ARGV[1] |
|
45 | if File.exist?(source_file) == false |
|
45 | if File.exist?(source_file) == false |
|
46 | log "The source file does not exist." |
|
46 | log "The source file does not exist." |
|
47 | exit(127) |
|
47 | exit(127) |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | log "Making test result and sandbox directories..." |
|
50 | log "Making test result and sandbox directories..." |
|
51 |
|
51 | ||
|
52 | current_dir = `pwd` |
|
52 | current_dir = `pwd` |
|
53 | current_dir.strip! |
|
53 | current_dir.strip! |
|
54 |
|
54 | ||
|
55 | if ARGV.length >= 3 |
|
55 | if ARGV.length >= 3 |
|
56 | test_result_dir = ARGV[2] |
|
56 | test_result_dir = ARGV[2] |
|
57 | else |
|
57 | else |
|
58 | test_result_dir = "#{current_dir}/test-result" |
|
58 | test_result_dir = "#{current_dir}/test-result" |
|
59 | end |
|
59 | end |
|
60 | log "Test result directory: #{test_result_dir}" |
|
60 | log "Test result directory: #{test_result_dir}" |
|
61 | system("rm -Rf #{test_result_dir}") |
|
61 | system("rm -Rf #{test_result_dir}") |
|
62 | execute("mkdir #{test_result_dir}", "Cannot make directory #{test_result_dir}.") |
|
62 | execute("mkdir #{test_result_dir}", "Cannot make directory #{test_result_dir}.") |
|
63 |
|
63 | ||
|
64 | if ARGV.length >= 4 |
|
64 | if ARGV.length >= 4 |
|
65 | sandbox_dir = ARGV[3] |
|
65 | sandbox_dir = ARGV[3] |
|
66 | else |
|
66 | else |
|
67 | sandbox_dir = "#{current_dir}/sandbox" |
|
67 | sandbox_dir = "#{current_dir}/sandbox" |
|
68 | end |
|
68 | end |
|
69 | log "Sandbox directory: #{sandbox_dir}" |
|
69 | log "Sandbox directory: #{sandbox_dir}" |
|
70 | system("rm -Rf #{sandbox_dir}") |
|
70 | system("rm -Rf #{sandbox_dir}") |
|
71 | execute("mkdir #{sandbox_dir}", "Cannot make directory #{sandbox_dir}") |
|
71 | execute("mkdir #{sandbox_dir}", "Cannot make directory #{sandbox_dir}") |
|
72 |
|
72 | ||
|
73 | # Compile |
|
73 | # Compile |
|
74 | log |
|
74 | log |
|
75 | log "Compiling..." |
|
75 | log "Compiling..." |
|
76 | execute("cp #{source_file} #{sandbox_dir}", "Cannot copy the source file to #{sandbox_dir}") |
|
76 | execute("cp #{source_file} #{sandbox_dir}", "Cannot copy the source file to #{sandbox_dir}") |
|
77 | begin |
|
77 | begin |
|
78 | Dir.chdir sandbox_dir |
|
78 | Dir.chdir sandbox_dir |
|
79 | rescue |
|
79 | rescue |
|
80 | log "ERROR: Cannot change directory to #{sandbox_dir}." |
|
80 | log "ERROR: Cannot change directory to #{sandbox_dir}." |
|
81 | exit(127) |
|
81 | exit(127) |
|
82 | end |
|
82 | end |
|
83 | execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
83 | execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
84 | compile_message = `cat compiler_message` |
|
84 | compile_message = `cat compiler_message` |
|
85 | compile_message.strip! |
|
85 | compile_message.strip! |
|
86 | execute("mv compiler_message #{test_result_dir}", "Cannot move the compiler message to #{test_result_dir}.") |
|
86 | execute("mv compiler_message #{test_result_dir}", "Cannot move the compiler message to #{test_result_dir}.") |
|
87 | if !FileTest.exist?("a.out") |
|
87 | if !FileTest.exist?("a.out") |
|
88 | log "Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
88 | log "Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
89 | exit(127) |
|
89 | exit(127) |
|
90 | else |
|
90 | else |
|
91 | execute("mv a.out #{test_result_dir}", "Cannot move the compiled program to #{test_result_dir}") |
|
91 | execute("mv a.out #{test_result_dir}", "Cannot move the compiled program to #{test_result_dir}") |
|
92 | system("rm -Rf #{sandbox_dir}/*") |
|
92 | system("rm -Rf #{sandbox_dir}/*") |
|
93 | end |
|
93 | end |
|
94 |
|
94 | ||
|
95 | require "#{problem_home}/script/test_dsl.rb" |
|
95 | require "#{problem_home}/script/test_dsl.rb" |
|
96 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
96 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
97 | problem = Problem.get_instance |
|
97 | problem = Problem.get_instance |
|
98 |
|
98 | ||
|
99 | if problem.well_formed? == false |
|
99 | if problem.well_formed? == false |
|
100 | log "The problem specification is not well formed." |
|
100 | log "The problem specification is not well formed." |
|
101 | exit(127) |
|
101 | exit(127) |
|
102 | end |
|
102 | end |
|
103 |
|
103 | ||
|
104 | # Doing the testing. |
|
104 | # Doing the testing. |
|
105 | (1..(problem.num_tests)).each do |test_num| |
|
105 | (1..(problem.num_tests)).each do |test_num| |
|
106 | log "Test number: #{test_num}" |
|
106 | log "Test number: #{test_num}" |
|
107 | execute("cp #{test_result_dir}/a.out #{sandbox_dir}", "Cannot copy the compiled program into #{sandbox_dir}") |
|
107 | execute("cp #{test_result_dir}/a.out #{sandbox_dir}", "Cannot copy the compiled program into #{sandbox_dir}") |
|
108 | - execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") |
|
108 | + begin |
|
|
109 | + execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") | ||
|
|
110 | + rescue | ||
|
|
111 | + # do nothing | ||
|
|
112 | + end | ||
|
109 | execute("mkdir #{test_result_dir}/#{test_num}", "Cannot create directory #{test_result_dir}/#{test_num}") |
|
113 | execute("mkdir #{test_result_dir}/#{test_num}", "Cannot create directory #{test_result_dir}/#{test_num}") |
|
110 | execute("mv #{sandbox_dir}/result #{test_result_dir}/#{test_num}", "Cannot copy the result file into #{test_result_dir}/#{test_num}") |
|
114 | execute("mv #{sandbox_dir}/result #{test_result_dir}/#{test_num}", "Cannot copy the result file into #{test_result_dir}/#{test_num}") |
|
111 | execute("mv #{sandbox_dir}/comment #{test_result_dir}/#{test_num}", "Cannot copy the comment file into #{test_result_dir}/#{test_num}") |
|
115 | execute("mv #{sandbox_dir}/comment #{test_result_dir}/#{test_num}", "Cannot copy the comment file into #{test_result_dir}/#{test_num}") |
|
112 | execute("mv #{sandbox_dir}/output.txt #{test_result_dir}/#{test_num}", "Cannot copy the output file into #{test_result_dir}/#{test_num}") |
|
116 | execute("mv #{sandbox_dir}/output.txt #{test_result_dir}/#{test_num}", "Cannot copy the output file into #{test_result_dir}/#{test_num}") |
|
113 | execute("rm -Rf #{sandbox_dir}/*", "Cannot clear #{sandbox_dir}") |
|
117 | execute("rm -Rf #{sandbox_dir}/*", "Cannot clear #{sandbox_dir}") |
|
114 | end |
|
118 | end |
|
115 |
|
119 | ||
|
116 | # Grade |
|
120 | # Grade |
|
117 | log |
|
121 | log |
|
118 | log "Grading..." |
|
122 | log "Grading..." |
|
119 | begin |
|
123 | begin |
|
120 | Dir.chdir test_result_dir |
|
124 | Dir.chdir test_result_dir |
|
121 | rescue |
|
125 | rescue |
|
122 | log "ERROR: Cannot change directory to #{test_result_dir}." |
|
126 | log "ERROR: Cannot change directory to #{test_result_dir}." |
|
123 | exit(127) |
|
127 | exit(127) |
|
124 | end |
|
128 | end |
|
125 | execute("#{problem_home}/script/grade", "An error occured during grading!") |
|
129 | execute("#{problem_home}/script/grade", "An error occured during grading!") |
|
126 |
|
130 | ||
|
127 | log |
|
131 | log |
|
128 | log "All done!" |
|
132 | log "All done!" |
@@ -1,142 +1,143 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | def log(str='') |
|
3 | def log(str='') |
|
4 | if ENV['TALKATIVE']!=nil |
|
4 | if ENV['TALKATIVE']!=nil |
|
5 | puts str |
|
5 | puts str |
|
6 | end |
|
6 | end |
|
7 | if ENV['GRADER_LOGGING']!=nil |
|
7 | if ENV['GRADER_LOGGING']!=nil |
|
8 | log_fname = ENV['GRADER_LOGGING'] |
|
8 | log_fname = ENV['GRADER_LOGGING'] |
|
9 | fp = File.open(log_fname,"a") |
|
9 | fp = File.open(log_fname,"a") |
|
10 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
10 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
11 | fp.close |
|
11 | fp.close |
|
12 | end |
|
12 | end |
|
13 | end |
|
13 | end |
|
14 |
|
14 | ||
|
15 | def extract_time(t) |
|
15 | def extract_time(t) |
|
16 | if (result=/^(.*)r(.*)u(.*)s/.match(t)) |
|
16 | if (result=/^(.*)r(.*)u(.*)s/.match(t)) |
|
17 | {:real => result[1], :user => result[2], :sys => result[3]} |
|
17 | {:real => result[1], :user => result[2], :sys => result[3]} |
|
18 | else |
|
18 | else |
|
19 | raise "Error reading running time" |
|
19 | raise "Error reading running time" |
|
20 | end |
|
20 | end |
|
21 | end |
|
21 | end |
|
22 |
|
22 | ||
|
23 | def compile_box(source,bin) |
|
23 | def compile_box(source,bin) |
|
24 | system("gcc #{source} -o #{bin}") |
|
24 | system("gcc #{source} -o #{bin}") |
|
25 | end |
|
25 | end |
|
26 |
|
26 | ||
|
27 | if ARGV.length < 2 || ARGV.length > 3 |
|
27 | if ARGV.length < 2 || ARGV.length > 3 |
|
28 | puts "Usage: run <language> <test-num> [<program-name>]" |
|
28 | puts "Usage: run <language> <test-num> [<program-name>]" |
|
29 | exit(127) |
|
29 | exit(127) |
|
30 | end |
|
30 | end |
|
31 |
|
31 | ||
|
32 | language = ARGV[0] |
|
32 | language = ARGV[0] |
|
33 | test_num = ARGV[1].to_i |
|
33 | test_num = ARGV[1].to_i |
|
34 | if ARGV.length > 2 |
|
34 | if ARGV.length > 2 |
|
35 | program_name = ARGV[2] |
|
35 | program_name = ARGV[2] |
|
36 | else |
|
36 | else |
|
37 | program_name = "a.out" |
|
37 | program_name = "a.out" |
|
38 | end |
|
38 | end |
|
39 |
|
39 | ||
|
40 | problem_home = ENV['PROBLEM_HOME'] |
|
40 | problem_home = ENV['PROBLEM_HOME'] |
|
41 | require "#{problem_home}/script/test_dsl.rb" |
|
41 | require "#{problem_home}/script/test_dsl.rb" |
|
42 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
42 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
43 | problem = Problem.get_instance |
|
43 | problem = Problem.get_instance |
|
44 |
|
44 | ||
|
45 | if problem.well_formed? == false |
|
45 | if problem.well_formed? == false |
|
46 | log "The problem specification is not well formed." |
|
46 | log "The problem specification is not well formed." |
|
47 | exit(127) |
|
47 | exit(127) |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | # Check if the test number is okay. |
|
50 | # Check if the test number is okay. |
|
51 | if test_num <= 0 || test_num > problem.num_tests |
|
51 | if test_num <= 0 || test_num > problem.num_tests |
|
52 | log "You have specified a wrong test number." |
|
52 | log "You have specified a wrong test number." |
|
53 | exit(127) |
|
53 | exit(127) |
|
54 | end |
|
54 | end |
|
55 |
|
55 | ||
|
56 | ##################################### |
|
56 | ##################################### |
|
57 | # Set the relavant file names here. # |
|
57 | # Set the relavant file names here. # |
|
58 | ##################################### |
|
58 | ##################################### |
|
59 |
|
59 | ||
|
60 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
60 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
61 |
|
61 | ||
|
62 | ##################################### |
|
62 | ##################################### |
|
63 |
|
63 | ||
|
64 | time_limit = problem.get_time_limit test_num |
|
64 | time_limit = problem.get_time_limit test_num |
|
65 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
65 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
66 |
|
66 | ||
|
67 | # Copy the input file. |
|
67 | # Copy the input file. |
|
68 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
68 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
69 |
|
69 | ||
|
70 | time_output_format = "%Er%Uu%Ss" |
|
70 | time_output_format = "%Er%Uu%Ss" |
|
71 |
|
71 | ||
|
72 | # check if box is there, if not, compile it! |
|
72 | # check if box is there, if not, compile it! |
|
73 | if !File.exists?("#{problem_home}/script/box") |
|
73 | if !File.exists?("#{problem_home}/script/box") |
|
74 | log "WARNING: Compiling box: to increase efficiency, it should be compile manually" |
|
74 | log "WARNING: Compiling box: to increase efficiency, it should be compile manually" |
|
75 | compile_box("#{problem_home}/script/box.c", |
|
75 | compile_box("#{problem_home}/script/box.c", |
|
76 | "#{problem_home}/script/box") |
|
76 | "#{problem_home}/script/box") |
|
77 | end |
|
77 | end |
|
78 |
|
78 | ||
|
79 | # Run the program. |
|
79 | # Run the program. |
|
80 | run_command = "/usr/bin/time -f \"#{time_output_format}\" 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}" |
|
80 | run_command = "/usr/bin/time -f \"#{time_output_format}\" 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}" |
|
81 | log "Running test #{test_num}..." |
|
81 | log "Running test #{test_num}..." |
|
82 | log run_command |
|
82 | log run_command |
|
83 | log |
|
83 | log |
|
84 | system(run_command) |
|
84 | system(run_command) |
|
85 |
|
85 | ||
|
86 | # Create the result file. |
|
86 | # Create the result file. |
|
87 | result_file = File.new("result", "w") |
|
87 | result_file = File.new("result", "w") |
|
88 | comment_file = File.new("comment", "w") |
|
88 | comment_file = File.new("comment", "w") |
|
89 |
|
89 | ||
|
90 | # Check if the program actually produced any output. |
|
90 | # Check if the program actually produced any output. |
|
91 | run_result_file = File.new("run_result", "r") |
|
91 | run_result_file = File.new("run_result", "r") |
|
92 | run_result = run_result_file.readlines |
|
92 | run_result = run_result_file.readlines |
|
93 | run_result_file.close |
|
93 | run_result_file.close |
|
94 | time_elapsed = run_result[run_result.length-1] |
|
94 | time_elapsed = run_result[run_result.length-1] |
|
95 | running_time = extract_time(time_elapsed) |
|
95 | running_time = extract_time(time_elapsed) |
|
96 |
|
96 | ||
|
97 | report = lambda{ |status, points, comment| |
|
97 | report = lambda{ |status, points, comment| |
|
98 | result_file.write status.strip |
|
98 | result_file.write status.strip |
|
99 | result_file.write "\n" |
|
99 | result_file.write "\n" |
|
100 | result_file.write points.to_s.strip |
|
100 | result_file.write points.to_s.strip |
|
101 | result_file.write "\n" |
|
101 | result_file.write "\n" |
|
102 | result_file.write time_elapsed.strip |
|
102 | result_file.write time_elapsed.strip |
|
103 | result_file.write "\n" |
|
103 | result_file.write "\n" |
|
104 | result_file.close |
|
104 | result_file.close |
|
105 | `rm run_result` |
|
105 | `rm run_result` |
|
106 | # `rm output.txt` --- keep the output |
|
106 | # `rm output.txt` --- keep the output |
|
107 |
|
107 | ||
|
108 | comment_file.write comment |
|
108 | comment_file.write comment |
|
109 | comment_file.write "--run-result--\n" |
|
109 | comment_file.write "--run-result--\n" |
|
110 | run_result.each do |l| |
|
110 | run_result.each do |l| |
|
111 | comment_file.write l |
|
111 | comment_file.write l |
|
112 | end |
|
112 | end |
|
113 | comment_file.close |
|
113 | comment_file.close |
|
114 |
|
114 | ||
|
115 | log "Done!" |
|
115 | log "Done!" |
|
116 | exit(0) |
|
116 | exit(0) |
|
117 | } |
|
117 | } |
|
118 |
|
118 | ||
|
119 | if run_result[0][0,2] != "OK" |
|
119 | if run_result[0][0,2] != "OK" |
|
120 | log "There was a runtime error." |
|
120 | log "There was a runtime error." |
|
121 | report.call(run_result[0], 0, "No comment.\n") |
|
121 | report.call(run_result[0], 0, "No comment.\n") |
|
122 | end |
|
122 | end |
|
123 |
|
123 | ||
|
124 | if running_time[:user].to_f + running_time[:sys].to_f > time_limit |
|
124 | if running_time[:user].to_f + running_time[:sys].to_f > time_limit |
|
125 | log "Time limit exceeded." |
|
125 | log "Time limit exceeded." |
|
126 | report.call("Time limit exceeded", 0, "No comment.\n") |
|
126 | report.call("Time limit exceeded", 0, "No comment.\n") |
|
127 | end |
|
127 | end |
|
128 |
|
128 | ||
|
129 | # Run 'check' to evaluate the output. |
|
129 | # Run 'check' to evaluate the output. |
|
130 | #puts "There was no runtime error. Proceed to checking the output." |
|
130 | #puts "There was no runtime error. Proceed to checking the output." |
|
131 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
131 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
132 | log "Checking the output..." |
|
132 | log "Checking the output..." |
|
133 | log check_command |
|
133 | log check_command |
|
134 | if not system(check_command) |
|
134 | if not system(check_command) |
|
135 | log "Problem with check script" |
|
135 | log "Problem with check script" |
|
|
136 | + report.call("Incorrect",0,"Check script error.\n") | ||
|
136 | exit(127) |
|
137 | exit(127) |
|
137 | end |
|
138 | end |
|
138 |
|
139 | ||
|
139 | check_file = File.new("check_result", "r") |
|
140 | check_file = File.new("check_result", "r") |
|
140 | check_file_lines = check_file.readlines |
|
141 | check_file_lines = check_file.readlines |
|
141 |
|
142 | ||
|
142 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
|
143 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
@@ -1,45 +1,48 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | # |
|
3 | # |
|
4 | # This is a check script wrapper. It read all required information |
|
4 | # This is a check script wrapper. It read all required information |
|
5 | # and call a real check script call REAL_CHECK_SCRIPT in directory |
|
5 | # and call a real check script call REAL_CHECK_SCRIPT in directory |
|
6 | # [problem_home]/script |
|
6 | # [problem_home]/script |
|
7 | # |
|
7 | # |
|
8 |
|
8 | ||
|
9 | REAL_CHECK_SCRIPT = "<%= script_name %>" |
|
9 | REAL_CHECK_SCRIPT = "<%= script_name %>" |
|
10 |
|
10 | ||
|
11 | # The REAL_CHECK_SCRIPT is called with: |
|
11 | # The REAL_CHECK_SCRIPT is called with: |
|
12 | # |
|
12 | # |
|
13 | # (script) <lang> <test-num> <in-file> <out-file> <ans-file> <full-score> |
|
13 | # (script) <lang> <test-num> <in-file> <out-file> <ans-file> <full-score> |
|
14 | # |
|
14 | # |
|
15 | # and REAL_CHECK_SCRIPT's output to standard out is redirected to |
|
15 | # and REAL_CHECK_SCRIPT's output to standard out is redirected to |
|
16 | # 'check_result' as required by normal check script. |
|
16 | # 'check_result' as required by normal check script. |
|
17 |
|
17 | ||
|
18 | problem_home = ENV['PROBLEM_HOME'] |
|
18 | problem_home = ENV['PROBLEM_HOME'] |
|
19 | require "#{problem_home}/script/test_dsl.rb" |
|
19 | require "#{problem_home}/script/test_dsl.rb" |
|
20 |
|
20 | ||
|
21 | if ARGV.length < 2 |
|
21 | if ARGV.length < 2 |
|
22 | puts "Usage: check <language> <test-number> [<output-file>]" |
|
22 | puts "Usage: check <language> <test-number> [<output-file>]" |
|
23 | exit(0) |
|
23 | exit(0) |
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | language = ARGV[0] |
|
26 | language = ARGV[0] |
|
27 | test_num = ARGV[1].to_i |
|
27 | test_num = ARGV[1].to_i |
|
28 | if ARGV.length >= 3 |
|
28 | if ARGV.length >= 3 |
|
29 | output_file_name = ARGV[2] |
|
29 | output_file_name = ARGV[2] |
|
30 | else |
|
30 | else |
|
31 | output_file_name = "output.txt" |
|
31 | output_file_name = "output.txt" |
|
32 | end |
|
32 | end |
|
33 |
|
33 | ||
|
34 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
34 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
35 | problem = Problem.get_instance |
|
35 | problem = Problem.get_instance |
|
36 |
|
36 | ||
|
37 |
- answer_file_name = |
|
37 | + answer_file_name = "#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt" |
|
38 |
- input_file_name = |
|
38 | + input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
39 |
|
39 | ||
|
40 |
- score = |
|
40 | + score = problem.get_score(test_num) |
|
41 |
|
41 | ||
|
42 | cmd = "#{problem_home}/script/#{REAL_CHECK_SCRIPT} " + |
|
42 | cmd = "#{problem_home}/script/#{REAL_CHECK_SCRIPT} " + |
|
43 | "#{language} #{test_num} #{input_file_name} #{output_file_name} " + |
|
43 | "#{language} #{test_num} #{input_file_name} #{output_file_name} " + |
|
44 | "#{answer_file_name} #{score} > check_result" |
|
44 | "#{answer_file_name} #{score} > check_result" |
|
45 |
|
45 | ||
|
|
46 | + #puts "wrapper-CMD: #{cmd}" | ||
|
|
47 | + | ||
|
|
48 | + system(cmd) |
You need to be logged in to leave comments.
Login now