Description:
removed calls to 'pwd', other uses of back quotes
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r102:a3aedb7e3776 - - 4 files changed: 7 inserted, 5 deleted
@@ -1,89 +1,91 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
|
3 | + require 'fileutils' | ||
|
|
4 | + | ||
|
3 | def talk(str) |
|
5 | def talk(str) |
|
4 | if TALKATIVE |
|
6 | if TALKATIVE |
|
5 | puts str |
|
7 | puts str |
|
6 | end |
|
8 | end |
|
7 | end |
|
9 | end |
|
8 |
|
10 | ||
|
9 | def save_source(submission,dir,fname) |
|
11 | def save_source(submission,dir,fname) |
|
10 | f = File.open("#{dir}/#{fname}","w") |
|
12 | f = File.open("#{dir}/#{fname}","w") |
|
11 | f.write(submission.source) |
|
13 | f.write(submission.source) |
|
12 | f.close |
|
14 | f.close |
|
13 | end |
|
15 | end |
|
14 |
|
16 | ||
|
15 | def call_judge(problem_home,language,problem_out_dir,fname) |
|
17 | def call_judge(problem_home,language,problem_out_dir,fname) |
|
16 | ENV['PROBLEM_HOME'] = problem_home |
|
18 | ENV['PROBLEM_HOME'] = problem_home |
|
17 | Dir.chdir problem_out_dir |
|
19 | Dir.chdir problem_out_dir |
|
18 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
20 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
19 | # puts "CMD: #{cmd}" |
|
21 | # puts "CMD: #{cmd}" |
|
20 | system(cmd) |
|
22 | system(cmd) |
|
21 | end |
|
23 | end |
|
22 |
|
24 | ||
|
23 | def read_result(test_result_dir) |
|
25 | def read_result(test_result_dir) |
|
24 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
26 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
25 | cmp_msg = File.open(cmp_msg_fname).read |
|
27 | cmp_msg = File.open(cmp_msg_fname).read |
|
26 |
|
28 | ||
|
27 | result_fname = "#{test_result_dir}/result" |
|
29 | result_fname = "#{test_result_dir}/result" |
|
28 | comment_fname = "#{test_result_dir}/comment" |
|
30 | comment_fname = "#{test_result_dir}/comment" |
|
29 | if FileTest.exist?(result_fname) |
|
31 | if FileTest.exist?(result_fname) |
|
30 | result = File.open(result_fname).readline.to_i |
|
32 | result = File.open(result_fname).readline.to_i |
|
31 | comment = File.open(comment_fname).readline.chomp |
|
33 | comment = File.open(comment_fname).readline.chomp |
|
32 | return {:points => result, |
|
34 | return {:points => result, |
|
33 | :comment => comment, |
|
35 | :comment => comment, |
|
34 | :cmp_msg => cmp_msg} |
|
36 | :cmp_msg => cmp_msg} |
|
35 | else |
|
37 | else |
|
36 | return {:points => 0, |
|
38 | return {:points => 0, |
|
37 | :comment => 'compile error', |
|
39 | :comment => 'compile error', |
|
38 | :cmp_msg => cmp_msg} |
|
40 | :cmp_msg => cmp_msg} |
|
39 | end |
|
41 | end |
|
40 | end |
|
42 | end |
|
41 |
|
43 | ||
|
42 | def save_result(submission,result) |
|
44 | def save_result(submission,result) |
|
43 | submission.graded_at = Time.now |
|
45 | submission.graded_at = Time.now |
|
44 | submission.points = result[:points] |
|
46 | submission.points = result[:points] |
|
45 | submission.grader_comment = report_comment(result[:comment]) |
|
47 | submission.grader_comment = report_comment(result[:comment]) |
|
46 | submission.compiler_message = result[:cmp_msg] |
|
48 | submission.compiler_message = result[:cmp_msg] |
|
47 | submission.save |
|
49 | submission.save |
|
48 | end |
|
50 | end |
|
49 |
|
51 | ||
|
50 | def grade(submission_id) |
|
52 | def grade(submission_id) |
|
51 | sub = Submission.find(submission_id) |
|
53 | sub = Submission.find(submission_id) |
|
52 | user = sub.user |
|
54 | user = sub.user |
|
53 | problem = sub.problem |
|
55 | problem = sub.problem |
|
54 |
|
56 | ||
|
55 | language = sub.language.name |
|
57 | language = sub.language.name |
|
56 | lang_ext = sub.language.ext |
|
58 | lang_ext = sub.language.ext |
|
57 | # FIX THIS |
|
59 | # FIX THIS |
|
58 | talk 'some hack on language' |
|
60 | talk 'some hack on language' |
|
59 | if language == 'cpp' |
|
61 | if language == 'cpp' |
|
60 | language = 'c++' |
|
62 | language = 'c++' |
|
61 | end |
|
63 | end |
|
62 |
|
64 | ||
|
63 | user_dir = "#{USER_RESULT_DIR}/#{user.login}" |
|
65 | user_dir = "#{USER_RESULT_DIR}/#{user.login}" |
|
64 | Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) |
|
66 | Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) |
|
65 |
|
67 | ||
|
66 | problem_out_dir = "#{user_dir}/#{problem.name}" |
|
68 | problem_out_dir = "#{user_dir}/#{problem.name}" |
|
67 | Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) |
|
69 | Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) |
|
68 |
|
70 | ||
|
69 | problem_home = "#{PROBLEMS_DIR}/#{problem.name}" |
|
71 | problem_home = "#{PROBLEMS_DIR}/#{problem.name}" |
|
70 | source_name = "#{problem.name}.#{lang_ext}" |
|
72 | source_name = "#{problem.name}.#{lang_ext}" |
|
71 |
|
73 | ||
|
72 | save_source(sub,problem_out_dir,source_name) |
|
74 | save_source(sub,problem_out_dir,source_name) |
|
73 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
75 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
74 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
76 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
75 | end |
|
77 | end |
|
76 |
|
78 | ||
|
77 | # reading environment and options |
|
79 | # reading environment and options |
|
78 | GRADER_ENV = 'exam' |
|
80 | GRADER_ENV = 'exam' |
|
79 | puts "environment: #{GRADER_ENV}" |
|
81 | puts "environment: #{GRADER_ENV}" |
|
80 | require File.dirname(__FILE__) + "/environment.rb" |
|
82 | require File.dirname(__FILE__) + "/environment.rb" |
|
81 |
|
83 | ||
|
82 | #main program |
|
84 | #main program |
|
83 | talk 'Reading rails environment' |
|
85 | talk 'Reading rails environment' |
|
84 |
|
86 | ||
|
85 | RAILS_ENV = 'development' |
|
87 | RAILS_ENV = 'development' |
|
86 | require RAILS_APP_DIR + '/config/environment' |
|
88 | require RAILS_APP_DIR + '/config/environment' |
|
87 |
|
89 | ||
|
88 |
- current_dir = |
|
90 | + current_dir = FileUtils.pwd |
|
89 | grade(ARGV[0].to_i) |
|
91 | grade(ARGV[0].to_i) |
@@ -1,82 +1,82 | |||||
|
1 | require 'fileutils' |
|
1 | require 'fileutils' |
|
2 | require File.join(File.dirname(__FILE__),'dir_init') |
|
2 | require File.join(File.dirname(__FILE__),'dir_init') |
|
3 |
|
3 | ||
|
4 | module Grader |
|
4 | module Grader |
|
5 |
|
5 | ||
|
6 | # |
|
6 | # |
|
7 | # A grader engine grades a submission, against anything: a test |
|
7 | # A grader engine grades a submission, against anything: a test |
|
8 | # data, or a user submitted test data. It uses two helpers objects: |
|
8 | # data, or a user submitted test data. It uses two helpers objects: |
|
9 | # room_maker and reporter. |
|
9 | # room_maker and reporter. |
|
10 | # |
|
10 | # |
|
11 | class Engine |
|
11 | class Engine |
|
12 |
|
12 | ||
|
13 | attr_writer :room_maker |
|
13 | attr_writer :room_maker |
|
14 | attr_writer :reporter |
|
14 | attr_writer :reporter |
|
15 |
|
15 | ||
|
16 | def initialize(options={}) |
|
16 | def initialize(options={}) |
|
17 | # default options |
|
17 | # default options |
|
18 | if not options.include? :room_maker |
|
18 | if not options.include? :room_maker |
|
19 | options[:room_maker] = Grader::SubmissionRoomMaker.new |
|
19 | options[:room_maker] = Grader::SubmissionRoomMaker.new |
|
20 | end |
|
20 | end |
|
21 | if not options.include? :reporter |
|
21 | if not options.include? :reporter |
|
22 | options[:reporter] = Grader::SubmissionReporter.new |
|
22 | options[:reporter] = Grader::SubmissionReporter.new |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | @config = Grader::Configuration.get_instance |
|
25 | @config = Grader::Configuration.get_instance |
|
26 |
|
26 | ||
|
27 | @room_maker = options[:room_maker] |
|
27 | @room_maker = options[:room_maker] |
|
28 | @reporter = options[:reporter] |
|
28 | @reporter = options[:reporter] |
|
29 | end |
|
29 | end |
|
30 |
|
30 | ||
|
31 | # takes a submission, asks room_maker to produce grading directories, |
|
31 | # takes a submission, asks room_maker to produce grading directories, |
|
32 | # calls grader scripts, and asks reporter to save the result |
|
32 | # calls grader scripts, and asks reporter to save the result |
|
33 | def grade(submission) |
|
33 | def grade(submission) |
|
34 |
- current_dir = |
|
34 | + current_dir = FileUtils.pwd |
|
35 |
|
35 | ||
|
36 | user = submission.user |
|
36 | user = submission.user |
|
37 | problem = submission.problem |
|
37 | problem = submission.problem |
|
38 |
|
38 | ||
|
39 | # TODO: will have to create real exception for this |
|
39 | # TODO: will have to create real exception for this |
|
40 | if user==nil or problem == nil |
|
40 | if user==nil or problem == nil |
|
41 | @reporter.report_error(submission,"Grading error: problem with submission") |
|
41 | @reporter.report_error(submission,"Grading error: problem with submission") |
|
42 | #raise "engine: user or problem is nil" |
|
42 | #raise "engine: user or problem is nil" |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | # TODO: this is another hack so that output only task can be judged |
|
45 | # TODO: this is another hack so that output only task can be judged |
|
46 | if submission.language!=nil |
|
46 | if submission.language!=nil |
|
47 | language = submission.language.name |
|
47 | language = submission.language.name |
|
48 | lang_ext = submission.language.ext |
|
48 | lang_ext = submission.language.ext |
|
49 | else |
|
49 | else |
|
50 | language = 'c' |
|
50 | language = 'c' |
|
51 | lang_ext = 'c' |
|
51 | lang_ext = 'c' |
|
52 | end |
|
52 | end |
|
53 |
|
53 | ||
|
54 | # FIX THIS |
|
54 | # FIX THIS |
|
55 | talk 'some hack on language' |
|
55 | talk 'some hack on language' |
|
56 | if language == 'cpp' |
|
56 | if language == 'cpp' |
|
57 | language = 'c++' |
|
57 | language = 'c++' |
|
58 | end |
|
58 | end |
|
59 |
|
59 | ||
|
60 | # COMMENT: should it be only source.ext? |
|
60 | # COMMENT: should it be only source.ext? |
|
61 | if problem!=nil |
|
61 | if problem!=nil |
|
62 | source_name = "#{problem.name}.#{lang_ext}" |
|
62 | source_name = "#{problem.name}.#{lang_ext}" |
|
63 | else |
|
63 | else |
|
64 | source_name = "source.#{lang_ext}" |
|
64 | source_name = "source.#{lang_ext}" |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | begin |
|
67 | begin |
|
68 | grading_dir = @room_maker.produce_grading_room(submission) |
|
68 | grading_dir = @room_maker.produce_grading_room(submission) |
|
69 | @room_maker.save_source(submission,source_name) |
|
69 | @room_maker.save_source(submission,source_name) |
|
70 | problem_home = @room_maker.find_problem_home(submission) |
|
70 | problem_home = @room_maker.find_problem_home(submission) |
|
71 |
|
71 | ||
|
72 | # puts "GRADING DIR: #{grading_dir}" |
|
72 | # puts "GRADING DIR: #{grading_dir}" |
|
73 | # puts "PROBLEM DIR: #{problem_home}" |
|
73 | # puts "PROBLEM DIR: #{problem_home}" |
|
74 |
|
74 | ||
|
75 | if !FileTest.exist?(problem_home) |
|
75 | if !FileTest.exist?(problem_home) |
|
76 | raise "No test data." |
|
76 | raise "No test data." |
|
77 | end |
|
77 | end |
|
78 |
|
78 | ||
|
79 | dinit = DirInit::Manager.new(problem_home) |
|
79 | dinit = DirInit::Manager.new(problem_home) |
|
80 |
|
80 | ||
|
81 | dinit.setup do |
|
81 | dinit.setup do |
|
82 | copy_log = copy_script(problem_home) |
|
82 | copy_log = copy_script(problem_home) |
@@ -21,130 +21,130 | |||||
|
21 | msg = "ERROR: #{error_message}" |
|
21 | msg = "ERROR: #{error_message}" |
|
22 | log msg |
|
22 | log msg |
|
23 | raise msg |
|
23 | raise msg |
|
24 | end |
|
24 | end |
|
25 | end |
|
25 | end |
|
26 |
|
26 | ||
|
27 | def call_and_log(error_message) |
|
27 | def call_and_log(error_message) |
|
28 | begin |
|
28 | begin |
|
29 | yield |
|
29 | yield |
|
30 | rescue |
|
30 | rescue |
|
31 | msg = "ERROR: #{error_message}" |
|
31 | msg = "ERROR: #{error_message}" |
|
32 | log msg |
|
32 | log msg |
|
33 | raise msg |
|
33 | raise msg |
|
34 | end |
|
34 | end |
|
35 | end |
|
35 | end |
|
36 |
|
36 | ||
|
37 | def clear_and_create_empty_dir(dir) |
|
37 | def clear_and_create_empty_dir(dir) |
|
38 | FileUtils.rm_rf(dir, :secure => true) |
|
38 | FileUtils.rm_rf(dir, :secure => true) |
|
39 | call_and_log("Cannot make directory #{dir}.") { FileUtils.mkdir(dir) } |
|
39 | call_and_log("Cannot make directory #{dir}.") { FileUtils.mkdir(dir) } |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | # ARGV[0] --- language |
|
42 | # ARGV[0] --- language |
|
43 | # ARGV[1] --- program source file |
|
43 | # ARGV[1] --- program source file |
|
44 | # ARGV[2] --- test result directory |
|
44 | # ARGV[2] --- test result directory |
|
45 | # ARGV[3] --- sandbox directory |
|
45 | # ARGV[3] --- sandbox directory |
|
46 |
|
46 | ||
|
47 | if ARGV.length < 2 || ARGV.length > 4 |
|
47 | if ARGV.length < 2 || ARGV.length > 4 |
|
48 | puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]" |
|
48 | puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]" |
|
49 | puts " <sandbox-directory> is defaulted to ./sandbox" |
|
49 | puts " <sandbox-directory> is defaulted to ./sandbox" |
|
50 | puts " <test-result-directory> is defaulted to ./test-result" |
|
50 | puts " <test-result-directory> is defaulted to ./test-result" |
|
51 | puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it." |
|
51 | puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it." |
|
52 | exit(127) |
|
52 | exit(127) |
|
53 | end |
|
53 | end |
|
54 |
|
54 | ||
|
55 | language = ARGV[0] |
|
55 | language = ARGV[0] |
|
56 | if language != "c" && language != "c++" && language != "pas" |
|
56 | if language != "c" && language != "c++" && language != "pas" |
|
57 | log "You specified a language that is not supported: #{language}." |
|
57 | log "You specified a language that is not supported: #{language}." |
|
58 | exit(127) |
|
58 | exit(127) |
|
59 | end |
|
59 | end |
|
60 |
|
60 | ||
|
61 | source_file = ARGV[1] |
|
61 | source_file = ARGV[1] |
|
62 | if File.exist?(source_file) == false |
|
62 | if File.exist?(source_file) == false |
|
63 | log "The source file does not exist." |
|
63 | log "The source file does not exist." |
|
64 | exit(127) |
|
64 | exit(127) |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | log "Making test result and sandbox directories..." |
|
67 | log "Making test result and sandbox directories..." |
|
68 |
|
68 | ||
|
69 |
- current_dir = |
|
69 | + current_dir = FileUtils.pwd |
|
70 | current_dir.strip! |
|
70 | current_dir.strip! |
|
71 |
|
71 | ||
|
72 | if ARGV.length >= 3 |
|
72 | if ARGV.length >= 3 |
|
73 | test_result_dir = ARGV[2] |
|
73 | test_result_dir = ARGV[2] |
|
74 | else |
|
74 | else |
|
75 | test_result_dir = "#{current_dir}/test-result" |
|
75 | test_result_dir = "#{current_dir}/test-result" |
|
76 | end |
|
76 | end |
|
77 |
|
77 | ||
|
78 | log "Test result directory: #{test_result_dir}" |
|
78 | log "Test result directory: #{test_result_dir}" |
|
79 | clear_and_create_empty_dir(test_result_dir) |
|
79 | clear_and_create_empty_dir(test_result_dir) |
|
80 |
|
80 | ||
|
81 | if ARGV.length >= 4 |
|
81 | if ARGV.length >= 4 |
|
82 | sandbox_dir = ARGV[3] |
|
82 | sandbox_dir = ARGV[3] |
|
83 | else |
|
83 | else |
|
84 | sandbox_dir = "#{current_dir}/sandbox" |
|
84 | sandbox_dir = "#{current_dir}/sandbox" |
|
85 | end |
|
85 | end |
|
86 | log "Sandbox directory: #{sandbox_dir}" |
|
86 | log "Sandbox directory: #{sandbox_dir}" |
|
87 | clear_and_create_empty_dir(sandbox_dir) |
|
87 | clear_and_create_empty_dir(sandbox_dir) |
|
88 |
|
88 | ||
|
89 | # Compile |
|
89 | # Compile |
|
90 | log |
|
90 | log |
|
91 | log "Compiling..." |
|
91 | log "Compiling..." |
|
92 | call_and_log("Cannot copy the source file to #{sandbox_dir}") { |
|
92 | call_and_log("Cannot copy the source file to #{sandbox_dir}") { |
|
93 | FileUtils.cp(source_file, sandbox_dir) |
|
93 | FileUtils.cp(source_file, sandbox_dir) |
|
94 | } |
|
94 | } |
|
95 | begin |
|
95 | begin |
|
96 | Dir.chdir sandbox_dir |
|
96 | Dir.chdir sandbox_dir |
|
97 | rescue |
|
97 | rescue |
|
98 | log "ERROR: Cannot change directory to #{sandbox_dir}." |
|
98 | log "ERROR: Cannot change directory to #{sandbox_dir}." |
|
99 | exit(127) |
|
99 | exit(127) |
|
100 | end |
|
100 | end |
|
101 | execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
101 | execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
102 |
- compile_message = |
|
102 | + compile_message = open("compiler_message").read |
|
103 | compile_message.strip! |
|
103 | compile_message.strip! |
|
104 | call_and_log("Cannot move the compiler message to #{test_result_dir}.") { |
|
104 | call_and_log("Cannot move the compiler message to #{test_result_dir}.") { |
|
105 | FileUtils.mv("compiler_message", test_result_dir) |
|
105 | FileUtils.mv("compiler_message", test_result_dir) |
|
106 | } |
|
106 | } |
|
107 | if !FileTest.exist?("a.out") |
|
107 | if !FileTest.exist?("a.out") |
|
108 | log "Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
108 | log "Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
109 | exit(127) |
|
109 | exit(127) |
|
110 | else |
|
110 | else |
|
111 | call_and_log("Cannot move the compiled program to #{test_result_dir}") { |
|
111 | call_and_log("Cannot move the compiled program to #{test_result_dir}") { |
|
112 | FileUtils.mv("a.out",test_result_dir) |
|
112 | FileUtils.mv("a.out",test_result_dir) |
|
113 | } |
|
113 | } |
|
114 | FileUtils.rm_rf("#{sandbox_dir}/.") |
|
114 | FileUtils.rm_rf("#{sandbox_dir}/.") |
|
115 | end |
|
115 | end |
|
116 |
|
116 | ||
|
117 | require "#{problem_home}/script/test_dsl.rb" |
|
117 | require "#{problem_home}/script/test_dsl.rb" |
|
118 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
118 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
119 | problem = Problem.get_instance |
|
119 | problem = Problem.get_instance |
|
120 |
|
120 | ||
|
121 | if problem.well_formed? == false |
|
121 | if problem.well_formed? == false |
|
122 | log "The problem specification is not well formed." |
|
122 | log "The problem specification is not well formed." |
|
123 | exit(127) |
|
123 | exit(127) |
|
124 | end |
|
124 | end |
|
125 |
|
125 | ||
|
126 | # Doing the testing. |
|
126 | # Doing the testing. |
|
127 | (1..(problem.num_tests)).each do |test_num| |
|
127 | (1..(problem.num_tests)).each do |test_num| |
|
128 |
|
128 | ||
|
129 | $stdout.print "[#{test_num}]" |
|
129 | $stdout.print "[#{test_num}]" |
|
130 | $stdout.flush |
|
130 | $stdout.flush |
|
131 |
|
131 | ||
|
132 | log "Test number: #{test_num}" |
|
132 | log "Test number: #{test_num}" |
|
133 | call_and_log("Cannot copy the compiled program into #{sandbox_dir}") { |
|
133 | call_and_log("Cannot copy the compiled program into #{sandbox_dir}") { |
|
134 | FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir) |
|
134 | FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir) |
|
135 | } |
|
135 | } |
|
136 | begin |
|
136 | begin |
|
137 | execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") |
|
137 | execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") |
|
138 | rescue |
|
138 | rescue |
|
139 | # do nothing |
|
139 | # do nothing |
|
140 | end |
|
140 | end |
|
141 | call_and_log("Cannot create directory #{test_result_dir}/#{test_num}") { |
|
141 | call_and_log("Cannot create directory #{test_result_dir}/#{test_num}") { |
|
142 | FileUtils.mkdir "#{test_result_dir}/#{test_num}" |
|
142 | FileUtils.mkdir "#{test_result_dir}/#{test_num}" |
|
143 | } |
|
143 | } |
|
144 | call_and_log("Cannot copy the result file into #{test_result_dir}/#{test_num}") { |
|
144 | call_and_log("Cannot copy the result file into #{test_result_dir}/#{test_num}") { |
|
145 | FileUtils.mv "#{sandbox_dir}/result", "#{test_result_dir}/#{test_num}" |
|
145 | FileUtils.mv "#{sandbox_dir}/result", "#{test_result_dir}/#{test_num}" |
|
146 | } |
|
146 | } |
|
147 | call_and_log("Cannot copy the comment file into #{test_result_dir}/#{test_num}") { |
|
147 | call_and_log("Cannot copy the comment file into #{test_result_dir}/#{test_num}") { |
|
148 | FileUtils.mv "#{sandbox_dir}/comment", "#{test_result_dir}/#{test_num}" |
|
148 | FileUtils.mv "#{sandbox_dir}/comment", "#{test_result_dir}/#{test_num}" |
|
149 | } |
|
149 | } |
|
150 | call_and_log("Cannot copy the output file into #{test_result_dir}/#{test_num}") { |
|
150 | call_and_log("Cannot copy the output file into #{test_result_dir}/#{test_num}") { |
@@ -66,90 +66,90 | |||||
|
66 |
|
66 | ||
|
67 | time_limit = problem.get_time_limit test_num |
|
67 | time_limit = problem.get_time_limit test_num |
|
68 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
68 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
69 |
|
69 | ||
|
70 | # Copy the input file. |
|
70 | # Copy the input file. |
|
71 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
71 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
72 |
|
72 | ||
|
73 | # check if box is there, if not, compile it! |
|
73 | # check if box is there, if not, compile it! |
|
74 | if !File.exists?("#{problem_home}/script/box") |
|
74 | if !File.exists?("#{problem_home}/script/box") |
|
75 | log "WARNING: Compiling box: to increase efficiency, it should be compile manually" |
|
75 | log "WARNING: Compiling box: to increase efficiency, it should be compile manually" |
|
76 | compile_box("#{problem_home}/script/box.cc", |
|
76 | compile_box("#{problem_home}/script/box.cc", |
|
77 | "#{problem_home}/script/box") |
|
77 | "#{problem_home}/script/box") |
|
78 | end |
|
78 | end |
|
79 |
|
79 | ||
|
80 | # Hide PROBLEM_HOME |
|
80 | # Hide PROBLEM_HOME |
|
81 | ENV['PROBLEM_HOME'] = nil |
|
81 | ENV['PROBLEM_HOME'] = nil |
|
82 |
|
82 | ||
|
83 | # Run the program. |
|
83 | # 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}" |
|
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}" |
|
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" |
|
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" |
|
86 | log "Running test #{test_num}..." |
|
86 | log "Running test #{test_num}..." |
|
87 | log run_command |
|
87 | log run_command |
|
88 | log |
|
88 | log |
|
89 | system(run_command) |
|
89 | system(run_command) |
|
90 |
|
90 | ||
|
91 | # Restore PROBLEM_HOME |
|
91 | # Restore PROBLEM_HOME |
|
92 | ENV['PROBLEM_HOME'] = problem_home |
|
92 | ENV['PROBLEM_HOME'] = problem_home |
|
93 |
|
93 | ||
|
94 | # Create the result file. |
|
94 | # Create the result file. |
|
95 | result_file = File.new("result", "w") |
|
95 | result_file = File.new("result", "w") |
|
96 | comment_file = File.new("comment", "w") |
|
96 | comment_file = File.new("comment", "w") |
|
97 |
|
97 | ||
|
98 | # Check if the program actually produced any output. |
|
98 | # Check if the program actually produced any output. |
|
99 | run_result_file = File.new("run_result", "r") |
|
99 | run_result_file = File.new("run_result", "r") |
|
100 | run_result = run_result_file.readlines |
|
100 | run_result = run_result_file.readlines |
|
101 | run_result_file.close |
|
101 | run_result_file.close |
|
102 |
|
102 | ||
|
103 | run_stat = run_result[run_result.length-1] |
|
103 | run_stat = run_result[run_result.length-1] |
|
104 | running_time = extract_time(run_stat) |
|
104 | running_time = extract_time(run_stat) |
|
105 |
|
105 | ||
|
106 | report = lambda{ |status, points, comment| |
|
106 | report = lambda{ |status, points, comment| |
|
107 | result_file.write status.strip |
|
107 | result_file.write status.strip |
|
108 | result_file.write "\n" |
|
108 | result_file.write "\n" |
|
109 | result_file.write points.to_s.strip |
|
109 | result_file.write points.to_s.strip |
|
110 | result_file.write "\n" |
|
110 | result_file.write "\n" |
|
111 | result_file.write run_stat.strip |
|
111 | result_file.write run_stat.strip |
|
112 | result_file.write "\n" |
|
112 | result_file.write "\n" |
|
113 | result_file.close |
|
113 | result_file.close |
|
114 |
- |
|
114 | + FileUtils.rm "run_result" |
|
115 | # `rm output.txt` --- keep the output |
|
115 | # `rm output.txt` --- keep the output |
|
116 |
|
116 | ||
|
117 | comment_file.write comment |
|
117 | comment_file.write comment |
|
118 |
|
118 | ||
|
119 | # added for debuggin --- jittat |
|
119 | # added for debuggin --- jittat |
|
120 | comment_file.write "--run-result--\n" |
|
120 | comment_file.write "--run-result--\n" |
|
121 | run_result.each do |l| |
|
121 | run_result.each do |l| |
|
122 | comment_file.write l |
|
122 | comment_file.write l |
|
123 | end |
|
123 | end |
|
124 |
|
124 | ||
|
125 | comment_file.close |
|
125 | comment_file.close |
|
126 |
|
126 | ||
|
127 | log "Done!" |
|
127 | log "Done!" |
|
128 | exit(0) |
|
128 | exit(0) |
|
129 | } |
|
129 | } |
|
130 |
|
130 | ||
|
131 | if run_result[0][0,2] != "OK" |
|
131 | if run_result[0][0,2] != "OK" |
|
132 | log "There was a runtime error." |
|
132 | log "There was a runtime error." |
|
133 | report.call(run_result[0], 0, "No comment.\n") |
|
133 | report.call(run_result[0], 0, "No comment.\n") |
|
134 | end |
|
134 | end |
|
135 |
|
135 | ||
|
136 | if running_time[:user].to_f + running_time[:sys].to_f > time_limit |
|
136 | if running_time[:user].to_f + running_time[:sys].to_f > time_limit |
|
137 | log "Time limit exceeded." |
|
137 | log "Time limit exceeded." |
|
138 | report.call("Time limit exceeded", 0, "No comment.\n") |
|
138 | report.call("Time limit exceeded", 0, "No comment.\n") |
|
139 | end |
|
139 | end |
|
140 |
|
140 | ||
|
141 | # Run 'check' to evaluate the output. |
|
141 | # Run 'check' to evaluate the output. |
|
142 | #puts "There was no runtime error. Proceed to checking the output." |
|
142 | #puts "There was no runtime error. Proceed to checking the output." |
|
143 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
143 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
144 | log "Checking the output..." |
|
144 | log "Checking the output..." |
|
145 | log check_command |
|
145 | log check_command |
|
146 | if not system(check_command) |
|
146 | if not system(check_command) |
|
147 | log "Problem with check script" |
|
147 | log "Problem with check script" |
|
148 | report.call("Incorrect",0,"Check script error.\n") |
|
148 | report.call("Incorrect",0,"Check script error.\n") |
|
149 | exit(127) |
|
149 | exit(127) |
|
150 | end |
|
150 | end |
|
151 |
|
151 | ||
|
152 | check_file = File.new("check_result", "r") |
|
152 | check_file = File.new("check_result", "r") |
|
153 | check_file_lines = check_file.readlines |
|
153 | check_file_lines = check_file.readlines |
|
154 |
|
154 | ||
|
155 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
|
155 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
You need to be logged in to leave comments.
Login now