Description:
fix bugs: paths, check compilation error, all_tests.cfg.erb
git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@15 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
r3:4a517b89268a - - 4 files changed: 24 inserted, 18 deleted
@@ -0,0 +1,13 | |||||
|
|
1 | + problem do | ||
|
|
2 | + num_tests <%= num_testcases %> | ||
|
|
3 | + full_score <%= num_testcases*10 %> | ||
|
|
4 | + time_limit_each <%= options[:time_limit] %> | ||
|
|
5 | + mem_limit_each <%= options[:mem_limit] %> | ||
|
|
6 | + score_each 10 | ||
|
|
7 | + | ||
|
|
8 | + <% 1.upto(num_testcase) do |i| %> | ||
|
|
9 | + run <%= i %> | ||
|
|
10 | + tests <%= i %> | ||
|
|
11 | + end | ||
|
|
12 | + <% end %> | ||
|
|
13 | + end |
@@ -1,109 +1,111 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | def talk(str) |
|
3 | def talk(str) |
|
4 | if TALKATIVE |
|
4 | if TALKATIVE |
|
5 | puts str |
|
5 | puts str |
|
6 | end |
|
6 | end |
|
7 | end |
|
7 | end |
|
8 |
|
8 | ||
|
9 | def execute(command, error_message="") |
|
9 | def execute(command, error_message="") |
|
10 | if not system(command) |
|
10 | if not system(command) |
|
11 | puts "ERROR: #{error_message}" |
|
11 | puts "ERROR: #{error_message}" |
|
12 | exit(127) |
|
12 | exit(127) |
|
13 | end |
|
13 | end |
|
14 | end |
|
14 | end |
|
15 |
|
15 | ||
|
16 | def save_source(submission,dir,fname) |
|
16 | def save_source(submission,dir,fname) |
|
17 | f = File.open("#{dir}/#{fname}","w") |
|
17 | f = File.open("#{dir}/#{fname}","w") |
|
18 | f.write(submission.source) |
|
18 | f.write(submission.source) |
|
19 | f.close |
|
19 | f.close |
|
20 | end |
|
20 | end |
|
21 |
|
21 | ||
|
22 | def call_judge(problem_home,language,problem_out_dir,fname) |
|
22 | def call_judge(problem_home,language,problem_out_dir,fname) |
|
23 | ENV['PROBLEM_HOME'] = problem_home |
|
23 | ENV['PROBLEM_HOME'] = problem_home |
|
24 | Dir.chdir problem_out_dir |
|
24 | Dir.chdir problem_out_dir |
|
25 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
25 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
26 | # puts "CMD: #{cmd}" |
|
26 | # puts "CMD: #{cmd}" |
|
27 | system(cmd) |
|
27 | system(cmd) |
|
28 | end |
|
28 | end |
|
29 |
|
29 | ||
|
30 | def read_result(test_result_dir) |
|
30 | def read_result(test_result_dir) |
|
31 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
31 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
32 | cmp_msg = File.open(cmp_msg_fname).read |
|
32 | cmp_msg = File.open(cmp_msg_fname).read |
|
33 |
|
33 | ||
|
34 | result_fname = "#{test_result_dir}/result" |
|
34 | result_fname = "#{test_result_dir}/result" |
|
35 | comment_fname = "#{test_result_dir}/comment" |
|
35 | comment_fname = "#{test_result_dir}/comment" |
|
36 | if FileTest.exist?(result_fname) |
|
36 | if FileTest.exist?(result_fname) |
|
37 | result = File.open(result_fname).readline.to_i |
|
37 | result = File.open(result_fname).readline.to_i |
|
38 | comment = File.open(comment_fname).readline.chomp |
|
38 | comment = File.open(comment_fname).readline.chomp |
|
39 | return {:points => result, |
|
39 | return {:points => result, |
|
40 | :comment => comment, |
|
40 | :comment => comment, |
|
41 | :cmp_msg => cmp_msg} |
|
41 | :cmp_msg => cmp_msg} |
|
42 | else |
|
42 | else |
|
43 | return {:points => 0, |
|
43 | return {:points => 0, |
|
44 | :comment => 'compile error', |
|
44 | :comment => 'compile error', |
|
45 | :cmp_msg => cmp_msg} |
|
45 | :cmp_msg => cmp_msg} |
|
46 | end |
|
46 | end |
|
47 | end |
|
47 | end |
|
48 |
|
48 | ||
|
49 | def save_result(submission,result) |
|
49 | def save_result(submission,result) |
|
50 | submission.graded_at = Time.now |
|
50 | submission.graded_at = Time.now |
|
51 | submission.points = result[:points] |
|
51 | submission.points = result[:points] |
|
52 | submission.grader_comment = report_comment(result[:comment]) |
|
52 | submission.grader_comment = report_comment(result[:comment]) |
|
53 | submission.compiler_message = result[:cmp_msg] |
|
53 | submission.compiler_message = result[:cmp_msg] |
|
54 | submission.save |
|
54 | submission.save |
|
55 | end |
|
55 | end |
|
56 |
|
56 | ||
|
57 | def grade(submission_id) |
|
57 | def grade(submission_id) |
|
58 | sub = Submission.find(submission_id) |
|
58 | sub = Submission.find(submission_id) |
|
59 | user = sub.user |
|
59 | user = sub.user |
|
60 | problem = sub.problem |
|
60 | problem = sub.problem |
|
61 |
|
61 | ||
|
62 | language = sub.language.name |
|
62 | language = sub.language.name |
|
63 | lang_ext = sub.language.ext |
|
63 | lang_ext = sub.language.ext |
|
64 | # FIX THIS |
|
64 | # FIX THIS |
|
65 | talk 'some hack on language' |
|
65 | talk 'some hack on language' |
|
66 | if language == 'cpp' |
|
66 | if language == 'cpp' |
|
67 | language = 'c++' |
|
67 | language = 'c++' |
|
68 | end |
|
68 | end |
|
69 |
|
69 | ||
|
70 | user_dir = "#{USER_RESULT_DIR}/#{user.login}" |
|
70 | user_dir = "#{USER_RESULT_DIR}/#{user.login}" |
|
71 | Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) |
|
71 | Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) |
|
72 |
|
72 | ||
|
73 | problem_out_dir = "#{user_dir}/#{problem.name}" |
|
73 | problem_out_dir = "#{user_dir}/#{problem.name}" |
|
74 | Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) |
|
74 | Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) |
|
75 |
|
75 | ||
|
76 | problem_home = "#{PROBLEMS_DIR}/#{problem.name}" |
|
76 | problem_home = "#{PROBLEMS_DIR}/#{problem.name}" |
|
77 | source_name = "#{problem.name}.#{lang_ext}" |
|
77 | source_name = "#{problem.name}.#{lang_ext}" |
|
78 |
|
78 | ||
|
79 | save_source(sub,problem_out_dir,source_name) |
|
79 | save_source(sub,problem_out_dir,source_name) |
|
80 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
80 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
81 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
81 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
82 | end |
|
82 | end |
|
83 |
|
83 | ||
|
84 | # reading environment |
|
84 | # reading environment |
|
85 | GRADER_ENV = 'exam' |
|
85 | GRADER_ENV = 'exam' |
|
86 | if ARGV.length > 1 |
|
86 | if ARGV.length > 1 |
|
87 | GRADER_ENV = ARGV[1] |
|
87 | GRADER_ENV = ARGV[1] |
|
88 | end |
|
88 | end |
|
89 | require File.dirname(__FILE__) + "/environment.rb" |
|
89 | require File.dirname(__FILE__) + "/environment.rb" |
|
90 |
|
90 | ||
|
91 | #main program |
|
91 | #main program |
|
92 |
|
92 | ||
|
93 | talk 'Reading rails environment' |
|
93 | talk 'Reading rails environment' |
|
94 |
|
94 | ||
|
95 | RAILS_ENV = 'development' |
|
95 | RAILS_ENV = 'development' |
|
96 | require RAILS_APP_DIR + '/config/environment' |
|
96 | require RAILS_APP_DIR + '/config/environment' |
|
97 |
|
97 | ||
|
98 | current_dir = `pwd` |
|
98 | current_dir = `pwd` |
|
99 |
|
99 | ||
|
100 | talk 'Grader queue' |
|
100 | talk 'Grader queue' |
|
101 | - task = Task.find(:first, :order => 'created_at') |
|
101 | + while true |
|
102 | - if task!=nil |
|
102 | + task = Task.find(:first, :order => 'created_at') |
|
103 | - grade(task.submission_id) |
|
103 | + if task!=nil |
|
104 | - task.destroy |
|
104 | + grade(task.submission_id) |
|
105 | - else |
|
105 | + task.destroy |
|
106 | - puts "No job" |
|
106 | + else |
|
|
107 | + sleep(1) | ||
|
|
108 | + end | ||
|
107 | end |
|
109 | end |
|
108 |
|
110 | ||
|
109 |
|
111 |
@@ -1,89 +1,80 | |||||
|
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 standard scripts |
|
5 | # * copy standard scripts |
|
6 | # * copy testdata in the old format and create standard testcase config file |
|
6 | # * copy testdata in the old format and create standard testcase config file |
|
7 |
|
7 | ||
|
8 | require 'erb' |
|
8 | require 'erb' |
|
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 = 3 |
|
24 | i = 3 |
|
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 | GRADER_DIR = File.dirname(__FILE__) |
|
38 | GRADER_DIR = File.dirname(__FILE__) |
|
39 |
|
39 | ||
|
40 | # print usage |
|
40 | # print usage |
|
41 | if ARGV.length < 3 |
|
41 | if ARGV.length < 3 |
|
42 | puts "using: import_task problem importing_testcase_dir number_of_testcase [options]" |
|
42 | puts "using: import_task problem importing_testcase_dir number_of_testcase [options]" |
|
43 | exit(127) |
|
43 | exit(127) |
|
44 | end |
|
44 | end |
|
45 |
|
45 | ||
|
46 | # processing arguments |
|
46 | # processing arguments |
|
47 | problem = ARGV[0] |
|
47 | problem = ARGV[0] |
|
48 | testcase_dir = ARGV[1] |
|
48 | testcase_dir = ARGV[1] |
|
49 | num_testcases = ARGV[2].to_i |
|
49 | num_testcases = ARGV[2].to_i |
|
50 |
|
50 | ||
|
51 | options = {:time_limit => 1, :mem_limit => 16} |
|
51 | options = {:time_limit => 1, :mem_limit => 16} |
|
52 | process_options(options) |
|
52 | process_options(options) |
|
53 |
|
53 | ||
|
54 | # start working |
|
54 | # start working |
|
55 | puts "creating directories" |
|
55 | puts "creating directories" |
|
56 |
|
56 | ||
|
57 | system("mkdir #{problem}") |
|
57 | system("mkdir #{problem}") |
|
58 | system("mkdir #{problem}/script") |
|
58 | system("mkdir #{problem}/script") |
|
59 | system("mkdir #{problem}/test_cases") |
|
59 | system("mkdir #{problem}/test_cases") |
|
60 | system("cp #{GRADER_DIR}/std-script/* #{problem}/script") |
|
60 | system("cp #{GRADER_DIR}/std-script/* #{problem}/script") |
|
61 |
|
61 | ||
|
62 | puts "copying testcases" |
|
62 | puts "copying testcases" |
|
63 |
|
63 | ||
|
64 | 1.upto(num_testcases) do |i| |
|
64 | 1.upto(num_testcases) do |i| |
|
65 | system("mkdir #{problem}/test_cases/#{i}") |
|
65 | system("mkdir #{problem}/test_cases/#{i}") |
|
66 | copy_testcase("#{testcase_dir}","#{problem}/test_cases/#{i}",i) |
|
66 | copy_testcase("#{testcase_dir}","#{problem}/test_cases/#{i}",i) |
|
67 | end |
|
67 | end |
|
68 |
|
68 | ||
|
69 |
|
69 | ||
|
70 | # generating all_tests.cfg |
|
70 | # generating all_tests.cfg |
|
71 | puts "generating testcase config file" |
|
71 | puts "generating testcase config file" |
|
72 |
|
72 | ||
|
73 | - template = %q{ |
|
73 | + template = File.open("all_tests.cfg.erb").readlines |
|
74 | - problem do |
|
||
|
75 | - num_tests <%= num_testcases %> |
|
||
|
76 | - full_score <%= num_testcases*10 %> |
|
||
|
77 | - time_limit_each <%= options[:time_limit] %> |
|
||
|
78 | - mem_limit_each <%= options[:mem_limit] %> |
|
||
|
79 | - score_each 10 |
|
||
|
80 | - end |
|
||
|
81 | - } |
|
||
|
82 | - |
|
||
|
83 | all_test_cfg = ERB.new(template) |
|
74 | all_test_cfg = ERB.new(template) |
|
84 |
|
75 | ||
|
85 | - cfg_file = File.open("#{problem}/test_cases/all_test.cfg","w") |
|
76 | + cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") |
|
86 | cfg_file.puts all_test_cfg.result |
|
77 | cfg_file.puts all_test_cfg.result |
|
87 | cfg_file.close |
|
78 | cfg_file.close |
|
88 |
|
79 | ||
|
89 | puts "done" |
|
80 | puts "done" |
@@ -1,114 +1,114 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | problem_home = ENV['PROBLEM_HOME'] |
|
3 | problem_home = ENV['PROBLEM_HOME'] |
|
4 |
|
4 | ||
|
5 | def execute(command, error_message="") |
|
5 | def execute(command, error_message="") |
|
6 | if not system(command) |
|
6 | if not system(command) |
|
7 | puts "ERROR: #{error_message}" |
|
7 | puts "ERROR: #{error_message}" |
|
8 | exit(127) |
|
8 | exit(127) |
|
9 | end |
|
9 | end |
|
10 | end |
|
10 | end |
|
11 |
|
11 | ||
|
12 | # ARGV[0] --- language |
|
12 | # ARGV[0] --- language |
|
13 | # ARGV[1] --- program source file |
|
13 | # ARGV[1] --- program source file |
|
14 | # ARGV[2] --- test result directory |
|
14 | # ARGV[2] --- test result directory |
|
15 | # ARGV[3] --- sandbox directory |
|
15 | # ARGV[3] --- sandbox directory |
|
16 |
|
16 | ||
|
17 | if ARGV.length < 2 || ARGV.length > 4 |
|
17 | if ARGV.length < 2 || ARGV.length > 4 |
|
18 | puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]" |
|
18 | puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]" |
|
19 | puts " <sandbox-directory> is defaulted to ./sandbox" |
|
19 | puts " <sandbox-directory> is defaulted to ./sandbox" |
|
20 | puts " <test-result-directory> is defaulted to ./test-result" |
|
20 | puts " <test-result-directory> is defaulted to ./test-result" |
|
21 | puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it." |
|
21 | puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it." |
|
22 | exit(127) |
|
22 | exit(127) |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | language = ARGV[0] |
|
25 | language = ARGV[0] |
|
26 | if language != "c" && language != "c++" && language != "pascal" |
|
26 | if language != "c" && language != "c++" && language != "pascal" |
|
27 | puts "You specified a language that is not supported." |
|
27 | puts "You specified a language that is not supported." |
|
28 | exit(127) |
|
28 | exit(127) |
|
29 | end |
|
29 | end |
|
30 |
|
30 | ||
|
31 | source_file = ARGV[1] |
|
31 | source_file = ARGV[1] |
|
32 | if File.exist?(source_file) == false |
|
32 | if File.exist?(source_file) == false |
|
33 | puts "The source file does not exist." |
|
33 | puts "The source file does not exist." |
|
34 | exit(127) |
|
34 | exit(127) |
|
35 | end |
|
35 | end |
|
36 |
|
36 | ||
|
37 | puts "Making test result and sandbox directories..." |
|
37 | puts "Making test result and sandbox directories..." |
|
38 |
|
38 | ||
|
39 | current_dir = `pwd` |
|
39 | current_dir = `pwd` |
|
40 | current_dir.strip! |
|
40 | current_dir.strip! |
|
41 |
|
41 | ||
|
42 | if ARGV.length >= 3 |
|
42 | if ARGV.length >= 3 |
|
43 | test_result_dir = ARGV[2] |
|
43 | test_result_dir = ARGV[2] |
|
44 | else |
|
44 | else |
|
45 | test_result_dir = "#{current_dir}/test-result" |
|
45 | test_result_dir = "#{current_dir}/test-result" |
|
46 | end |
|
46 | end |
|
47 | puts "Test result directory: #{test_result_dir}" |
|
47 | puts "Test result directory: #{test_result_dir}" |
|
48 | system("rm -Rf #{test_result_dir}") |
|
48 | system("rm -Rf #{test_result_dir}") |
|
49 | execute("mkdir #{test_result_dir}", "Cannot make directory #{test_result_dir}.") |
|
49 | execute("mkdir #{test_result_dir}", "Cannot make directory #{test_result_dir}.") |
|
50 |
|
50 | ||
|
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 compile_message != "" |
|
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("rm -Rf #{sandbox_dir}/*", "Cannot clear #{sandbox_dir}") |
|
99 | execute("rm -Rf #{sandbox_dir}/*", "Cannot clear #{sandbox_dir}") |
|
100 | end |
|
100 | end |
|
101 |
|
101 | ||
|
102 | # Grade |
|
102 | # Grade |
|
103 | puts |
|
103 | puts |
|
104 | puts "Grading..." |
|
104 | puts "Grading..." |
|
105 | begin |
|
105 | begin |
|
106 | Dir.chdir test_result_dir |
|
106 | Dir.chdir test_result_dir |
|
107 | rescue |
|
107 | rescue |
|
108 | puts "ERROR: Cannot change directory to #{test_result_dir}." |
|
108 | puts "ERROR: Cannot change directory to #{test_result_dir}." |
|
109 | exit(127) |
|
109 | exit(127) |
|
110 | end |
|
110 | end |
|
111 | execute("#{problem_home}/script/grade", "An error occured during grading!") |
|
111 | execute("#{problem_home}/script/grade", "An error occured during grading!") |
|
112 |
|
112 | ||
|
113 | puts |
|
113 | puts |
|
114 | puts "All done!" |
|
114 | puts "All done!" |
You need to be logged in to leave comments.
Login now