Description:
fixed: grader crashes when the problem has no test data git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@431 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r83:285efa98811f - - 1 file changed: 5 inserted, 1 deleted

@@ -20,115 +20,119
20 @room_maker = room_maker || Grader::SubmissionRoomMaker.new
20 @room_maker = room_maker || Grader::SubmissionRoomMaker.new
21 @reporter = reporter || Grader::SubmissionReporter.new
21 @reporter = reporter || Grader::SubmissionReporter.new
22 end
22 end
23
23
24 # takes a submission, asks room_maker to produce grading directories,
24 # takes a submission, asks room_maker to produce grading directories,
25 # calls grader scripts, and asks reporter to save the result
25 # calls grader scripts, and asks reporter to save the result
26 def grade(submission)
26 def grade(submission)
27 current_dir = `pwd`.chomp
27 current_dir = `pwd`.chomp
28
28
29 user = submission.user
29 user = submission.user
30 problem = submission.problem
30 problem = submission.problem
31
31
32 # TODO: will have to create real exception for this
32 # TODO: will have to create real exception for this
33 if user==nil or problem == nil
33 if user==nil or problem == nil
34 @reporter.report_error(submission,"Grading error: problem with submission")
34 @reporter.report_error(submission,"Grading error: problem with submission")
35 #raise "engine: user or problem is nil"
35 #raise "engine: user or problem is nil"
36 end
36 end
37
37
38 # TODO: this is another hack so that output only task can be judged
38 # TODO: this is another hack so that output only task can be judged
39 if submission.language!=nil
39 if submission.language!=nil
40 language = submission.language.name
40 language = submission.language.name
41 lang_ext = submission.language.ext
41 lang_ext = submission.language.ext
42 else
42 else
43 language = 'c'
43 language = 'c'
44 lang_ext = 'c'
44 lang_ext = 'c'
45 end
45 end
46
46
47 # FIX THIS
47 # FIX THIS
48 talk 'some hack on language'
48 talk 'some hack on language'
49 if language == 'cpp'
49 if language == 'cpp'
50 language = 'c++'
50 language = 'c++'
51 end
51 end
52
52
53 # COMMENT: should it be only source.ext?
53 # COMMENT: should it be only source.ext?
54 if problem!=nil
54 if problem!=nil
55 source_name = "#{problem.name}.#{lang_ext}"
55 source_name = "#{problem.name}.#{lang_ext}"
56 else
56 else
57 source_name = "source.#{lang_ext}"
57 source_name = "source.#{lang_ext}"
58 end
58 end
59
59
60 begin
60 begin
61 grading_dir = @room_maker.produce_grading_room(submission)
61 grading_dir = @room_maker.produce_grading_room(submission)
62 @room_maker.save_source(submission,source_name)
62 @room_maker.save_source(submission,source_name)
63 problem_home = @room_maker.find_problem_home(submission)
63 problem_home = @room_maker.find_problem_home(submission)
64
64
65 # puts "GRADING DIR: #{grading_dir}"
65 # puts "GRADING DIR: #{grading_dir}"
66 # puts "PROBLEM DIR: #{problem_home}"
66 # puts "PROBLEM DIR: #{problem_home}"
67
67
68 + if !FileTest.exist?(problem_home)
69 + raise "No test data."
70 + end
71 +
68 dinit = DirInit::Manager.new(problem_home)
72 dinit = DirInit::Manager.new(problem_home)
69
73
70 dinit.setup do
74 dinit.setup do
71 copy_log = copy_script(problem_home)
75 copy_log = copy_script(problem_home)
72 save_copy_log(problem_home,copy_log)
76 save_copy_log(problem_home,copy_log)
73 end
77 end
74
78
75 call_judge(problem_home,language,grading_dir,source_name)
79 call_judge(problem_home,language,grading_dir,source_name)
76
80
77 @reporter.report(submission,"#{grading_dir}/test-result")
81 @reporter.report(submission,"#{grading_dir}/test-result")
78
82
79 dinit.teardown do
83 dinit.teardown do
80 copy_log = load_copy_log(problem_home)
84 copy_log = load_copy_log(problem_home)
81 clear_copy_log(problem_home)
85 clear_copy_log(problem_home)
82 clear_script(copy_log,problem_home)
86 clear_script(copy_log,problem_home)
83 end
87 end
84
88
85 rescue RuntimeError => msg
89 rescue RuntimeError => msg
86 - @reporter.report_error(submission,"Grading error: #{msg}")
90 + @reporter.report_error(submission, msg)
87
91
88 ensure
92 ensure
89 @room_maker.clean_up(submission)
93 @room_maker.clean_up(submission)
90 Dir.chdir(current_dir) # this is really important
94 Dir.chdir(current_dir) # this is really important
91 end
95 end
92 end
96 end
93
97
94 protected
98 protected
95
99
96 def talk(str)
100 def talk(str)
97 if @config.talkative
101 if @config.talkative
98 puts str
102 puts str
99 end
103 end
100 end
104 end
101
105
102 def call_judge(problem_home,language,grading_dir,fname)
106 def call_judge(problem_home,language,grading_dir,fname)
103 ENV['PROBLEM_HOME'] = problem_home
107 ENV['PROBLEM_HOME'] = problem_home
104
108
105 talk grading_dir
109 talk grading_dir
106 Dir.chdir grading_dir
110 Dir.chdir grading_dir
107 cmd = "#{problem_home}/script/judge #{language} #{fname}"
111 cmd = "#{problem_home}/script/judge #{language} #{fname}"
108 talk "CMD: #{cmd}"
112 talk "CMD: #{cmd}"
109 system(cmd)
113 system(cmd)
110 end
114 end
111
115
112 def get_std_script_dir
116 def get_std_script_dir
113 GRADER_ROOT + '/std-script'
117 GRADER_ROOT + '/std-script'
114 end
118 end
115
119
116 def copy_script(problem_home)
120 def copy_script(problem_home)
117 script_dir = "#{problem_home}/script"
121 script_dir = "#{problem_home}/script"
118 std_script_dir = get_std_script_dir
122 std_script_dir = get_std_script_dir
119
123
120 raise "std-script directory not found" if !FileTest.exist?(std_script_dir)
124 raise "std-script directory not found" if !FileTest.exist?(std_script_dir)
121
125
122 scripts = Dir[std_script_dir + '/*']
126 scripts = Dir[std_script_dir + '/*']
123
127
124 copied = []
128 copied = []
125
129
126 scripts.each do |s|
130 scripts.each do |s|
127 fname = File.basename(s)
131 fname = File.basename(s)
128 if !FileTest.exist?("#{script_dir}/#{fname}")
132 if !FileTest.exist?("#{script_dir}/#{fname}")
129 copied << fname
133 copied << fname
130 system("cp #{s} #{script_dir}")
134 system("cp #{s} #{script_dir}")
131 end
135 end
132 end
136 end
133
137
134 return copied
138 return copied
You need to be logged in to leave comments. Login now