Description:
more commenting on script
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r257:98303143aafa - - 3 files changed: 24 inserted, 2 deleted
@@ -69,24 +69,25 | |||||
|
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 | puts "PROBLEM DIR: #{problem_home}" |
|
76 | puts "PROBLEM DIR: #{problem_home}" |
|
77 | raise "engine: No test data." |
|
77 | raise "engine: No test data." |
|
78 | end |
|
78 | end |
|
79 |
|
79 | ||
|
80 | talk "ENGINE: grading dir at #{grading_dir} is created" |
|
80 | talk "ENGINE: grading dir at #{grading_dir} is created" |
|
|
81 | + talk "ENGINE: located problem home at #{problem_home} is created" | ||
|
81 |
|
82 | ||
|
82 | # copy the source script, using lock |
|
83 | # copy the source script, using lock |
|
83 | dinit = DirInit::Manager.new(problem_home) |
|
84 | dinit = DirInit::Manager.new(problem_home) |
|
84 |
|
85 | ||
|
85 | # lock the directory and copy the scripts |
|
86 | # lock the directory and copy the scripts |
|
86 | dinit.setup do |
|
87 | dinit.setup do |
|
87 | copy_log = copy_script(problem_home) |
|
88 | copy_log = copy_script(problem_home) |
|
88 | save_copy_log(problem_home,copy_log) |
|
89 | save_copy_log(problem_home,copy_log) |
|
89 | talk "ENGINE: following std script is copied: #{copy_log.join ' '}" |
|
90 | talk "ENGINE: following std script is copied: #{copy_log.join ' '}" |
|
90 | end |
|
91 | end |
|
91 |
|
92 | ||
|
92 |
|
93 |
@@ -149,24 +149,26 | |||||
|
149 | #additionally copy any extra .txt file |
|
149 | #additionally copy any extra .txt file |
|
150 | data_files = Dir[problem_home + '/*.txt'] |
|
150 | data_files = Dir[problem_home + '/*.txt'] |
|
151 | data_files.each do |file| |
|
151 | data_files.each do |file| |
|
152 | FileUtils.cp(file,sandbox_dir) |
|
152 | FileUtils.cp(file,sandbox_dir) |
|
153 | end |
|
153 | end |
|
154 |
|
154 | ||
|
155 | begin |
|
155 | begin |
|
156 | execute("#{problem_home}/script/run #{language} #{test_num} ", "Error occured during execution of the run script") |
|
156 | execute("#{problem_home}/script/run #{language} #{test_num} ", "Error occured during execution of the run script") |
|
157 | rescue |
|
157 | rescue |
|
158 | # do nothing |
|
158 | # do nothing |
|
159 | end |
|
159 | end |
|
160 |
|
160 | ||
|
|
161 | + | ||
|
|
162 | + #copy the output of run script to each test-result folder | ||
|
161 | call_and_log("Cannot create directory #{test_result_dir}/#{test_num}") { |
|
163 | call_and_log("Cannot create directory #{test_result_dir}/#{test_num}") { |
|
162 | FileUtils.mkdir "#{test_result_dir}/#{test_num}" |
|
164 | FileUtils.mkdir "#{test_result_dir}/#{test_num}" |
|
163 | } |
|
165 | } |
|
164 | call_and_log("Cannot copy the result file into #{test_result_dir}/#{test_num}") { |
|
166 | call_and_log("Cannot copy the result file into #{test_result_dir}/#{test_num}") { |
|
165 | FileUtils.mv "#{sandbox_dir}/result", "#{test_result_dir}/#{test_num}" |
|
167 | FileUtils.mv "#{sandbox_dir}/result", "#{test_result_dir}/#{test_num}" |
|
166 | } |
|
168 | } |
|
167 | call_and_log("Cannot copy the comment file into #{test_result_dir}/#{test_num}") { |
|
169 | call_and_log("Cannot copy the comment file into #{test_result_dir}/#{test_num}") { |
|
168 | FileUtils.mv "#{sandbox_dir}/comment", "#{test_result_dir}/#{test_num}" |
|
170 | FileUtils.mv "#{sandbox_dir}/comment", "#{test_result_dir}/#{test_num}" |
|
169 | } |
|
171 | } |
|
170 | call_and_log("Cannot copy the output file into #{test_result_dir}/#{test_num}") { |
|
172 | call_and_log("Cannot copy the output file into #{test_result_dir}/#{test_num}") { |
|
171 | FileUtils.mv "#{sandbox_dir}/output.txt", "#{test_result_dir}/#{test_num}" |
|
173 | FileUtils.mv "#{sandbox_dir}/output.txt", "#{test_result_dir}/#{test_num}" |
|
172 | } |
|
174 | } |
@@ -1,14 +1,28 | |||||
|
1 | #!/usr/bin/env ruby |
|
1 | #!/usr/bin/env ruby |
|
2 |
|
2 | ||
|
|
3 | + ## | ||
|
|
4 | + # This program should be run in the sandbox dir containing the compiled file | ||
|
|
5 | + # (or source file for script language). It will call the sandbox program with | ||
|
|
6 | + # the given input and process the output of the sandbox | ||
|
|
7 | + # | ||
|
|
8 | + # If sandbox exit normally, this program will call the "check" script to do | ||
|
|
9 | + # scoring. Otherwise, it would record the error accordingly | ||
|
|
10 | + # | ||
|
|
11 | + # This program produces several file | ||
|
|
12 | + # * result - the result from check script | ||
|
|
13 | + # * comment - comment from sandbox | ||
|
|
14 | + # * output - output of the program | ||
|
|
15 | + # | ||
|
|
16 | + | ||
|
3 | require 'fileutils' |
|
17 | require 'fileutils' |
|
4 |
|
18 | ||
|
5 | def log(str='') |
|
19 | def log(str='') |
|
6 | if ENV['TALKATIVE']!=nil |
|
20 | if ENV['TALKATIVE']!=nil |
|
7 | puts str |
|
21 | puts str |
|
8 | end |
|
22 | end |
|
9 | if ENV['GRADER_LOGGING']!=nil |
|
23 | if ENV['GRADER_LOGGING']!=nil |
|
10 | log_fname = ENV['GRADER_LOGGING'] |
|
24 | log_fname = ENV['GRADER_LOGGING'] |
|
11 | fp = File.open(log_fname,"a") |
|
25 | fp = File.open(log_fname,"a") |
|
12 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
26 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
13 | fp.close |
|
27 | fp.close |
|
14 | end |
|
28 | end |
@@ -20,53 +34,58 | |||||
|
20 | {:real => result[1], :user => result[2], :sys => result[3]} |
|
34 | {:real => result[1], :user => result[2], :sys => result[3]} |
|
21 | else |
|
35 | else |
|
22 | #{:real => 0, :user => 0, :sys => 0} |
|
36 | #{:real => 0, :user => 0, :sys => 0} |
|
23 | #puts "ERROR READING RUNNING TIME: #{t}" |
|
37 | #puts "ERROR READING RUNNING TIME: #{t}" |
|
24 | raise "Error reading running time: #{t}" |
|
38 | raise "Error reading running time: #{t}" |
|
25 | end |
|
39 | end |
|
26 | end |
|
40 | end |
|
27 |
|
41 | ||
|
28 | def compile_box(source,bin) |
|
42 | def compile_box(source,bin) |
|
29 | system("g++ #{source} -o #{bin}") |
|
43 | system("g++ #{source} -o #{bin}") |
|
30 | end |
|
44 | end |
|
31 |
|
45 | ||
|
|
46 | + #------------------------------------------ | ||
|
|
47 | + # MAIN | ||
|
|
48 | + #------------------------------------------ | ||
|
|
49 | + | ||
|
|
50 | + #parse parameter | ||
|
32 | if ARGV.length < 2 || ARGV.length > 3 |
|
51 | if ARGV.length < 2 || ARGV.length > 3 |
|
33 | puts "Usage: run <language> <test-num> [<program-name>]" |
|
52 | puts "Usage: run <language> <test-num> [<program-name>]" |
|
34 | exit(127) |
|
53 | exit(127) |
|
35 | end |
|
54 | end |
|
36 |
|
55 | ||
|
37 | language = ARGV[0] |
|
56 | language = ARGV[0] |
|
38 | test_num = ARGV[1].to_i |
|
57 | test_num = ARGV[1].to_i |
|
39 | if ARGV.length > 2 |
|
58 | if ARGV.length > 2 |
|
40 | program_name = ARGV[2] |
|
59 | program_name = ARGV[2] |
|
41 | else |
|
60 | else |
|
42 | program_name = "a.out" |
|
61 | program_name = "a.out" |
|
43 | end |
|
62 | end |
|
44 |
|
63 | ||
|
45 | problem_home = ENV['PROBLEM_HOME'] |
|
64 | problem_home = ENV['PROBLEM_HOME'] |
|
46 | source_name = ENV['SOURCE_NAME'] |
|
65 | source_name = ENV['SOURCE_NAME'] |
|
47 | require "#{problem_home}/script/test_dsl.rb" |
|
66 | require "#{problem_home}/script/test_dsl.rb" |
|
48 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
67 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
49 | problem = Problem.get_instance |
|
68 | problem = Problem.get_instance |
|
50 |
|
69 | ||
|
51 | sandbox_dir = Dir.getwd |
|
70 | sandbox_dir = Dir.getwd |
|
52 |
|
71 | ||
|
53 | if problem.well_formed? == false |
|
72 | if problem.well_formed? == false |
|
54 | - log "RUN: The problem specification is not well formed." |
|
73 | + log "RUN: ERROR: The problem specification is not well formed." |
|
55 | exit(127) |
|
74 | exit(127) |
|
56 | end |
|
75 | end |
|
57 |
|
76 | ||
|
58 | # Check if the test number is okay. |
|
77 | # Check if the test number is okay. |
|
59 | if test_num <= 0 || test_num > problem.num_tests |
|
78 | if test_num <= 0 || test_num > problem.num_tests |
|
60 | - log "RUN: You have specified a wrong test number." |
|
79 | + log "RUN: ERROR: You have specified a wrong test number." |
|
61 | exit(127) |
|
80 | exit(127) |
|
62 | end |
|
81 | end |
|
63 |
|
82 | ||
|
64 | ##################################### |
|
83 | ##################################### |
|
65 | # Set the relavant file names here. # |
|
84 | # Set the relavant file names here. # |
|
66 | ##################################### |
|
85 | ##################################### |
|
67 |
|
86 | ||
|
68 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
87 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
69 |
|
88 | ||
|
70 | ##################################### |
|
89 | ##################################### |
|
71 |
|
90 | ||
|
72 | time_limit = problem.get_time_limit test_num |
|
91 | time_limit = problem.get_time_limit test_num |
You need to be logged in to leave comments.
Login now