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:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r3:4a517b89268a - - 4 files changed: 19 inserted, 13 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
@@ -77,33 +77,35
77 77 source_name = "#{problem.name}.#{lang_ext}"
78 78
79 79 save_source(sub,problem_out_dir,source_name)
80 80 call_judge(problem_home,language,problem_out_dir,source_name)
81 81 save_result(sub,read_result("#{problem_out_dir}/test-result"))
82 82 end
83 83
84 84 # reading environment
85 85 GRADER_ENV = 'exam'
86 86 if ARGV.length > 1
87 87 GRADER_ENV = ARGV[1]
88 88 end
89 89 require File.dirname(__FILE__) + "/environment.rb"
90 90
91 91 #main program
92 92
93 93 talk 'Reading rails environment'
94 94
95 95 RAILS_ENV = 'development'
96 96 require RAILS_APP_DIR + '/config/environment'
97 97
98 98 current_dir = `pwd`
99 99
100 100 talk 'Grader queue'
101 + while true
101 102 task = Task.find(:first, :order => 'created_at')
102 103 if task!=nil
103 104 grade(task.submission_id)
104 105 task.destroy
105 106 else
106 - puts "No job"
107 + sleep(1)
108 + end
107 109 end
108 110
109 111
@@ -49,41 +49,32
49 49 num_testcases = ARGV[2].to_i
50 50
51 51 options = {:time_limit => 1, :mem_limit => 16}
52 52 process_options(options)
53 53
54 54 # start working
55 55 puts "creating directories"
56 56
57 57 system("mkdir #{problem}")
58 58 system("mkdir #{problem}/script")
59 59 system("mkdir #{problem}/test_cases")
60 60 system("cp #{GRADER_DIR}/std-script/* #{problem}/script")
61 61
62 62 puts "copying testcases"
63 63
64 64 1.upto(num_testcases) do |i|
65 65 system("mkdir #{problem}/test_cases/#{i}")
66 66 copy_testcase("#{testcase_dir}","#{problem}/test_cases/#{i}",i)
67 67 end
68 68
69 69
70 70 # generating all_tests.cfg
71 71 puts "generating testcase config file"
72 72
73 - template = %q{
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 -
73 + template = File.open("all_tests.cfg.erb").readlines
83 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 77 cfg_file.puts all_test_cfg.result
87 78 cfg_file.close
88 79
89 80 puts "done"
@@ -50,49 +50,49
50 50
51 51 if ARGV.length >= 4
52 52 sandbox_dir = ARGV[3]
53 53 else
54 54 sandbox_dir = "#{current_dir}/sandbox"
55 55 end
56 56 puts "Sandbox directory: #{sandbox_dir}"
57 57 system("rm -Rf #{sandbox_dir}")
58 58 execute("mkdir #{sandbox_dir}", "Cannot make directory #{sandbox_dir}")
59 59
60 60 # Compile
61 61 puts
62 62 puts "Compiling..."
63 63 execute("cp #{source_file} #{sandbox_dir}", "Cannot copy the source file to #{sandbox_dir}")
64 64 begin
65 65 Dir.chdir sandbox_dir
66 66 rescue
67 67 puts "ERROR: Cannot change directory to #{sandbox_dir}."
68 68 exit(127)
69 69 end
70 70 execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!")
71 71 compile_message = `cat compiler_message`
72 72 compile_message.strip!
73 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 75 puts "Cannot compile the source code. See message in #{test_result_dir}/compile_message"
76 76 exit(127)
77 77 else
78 78 execute("mv a.out #{test_result_dir}", "Cannot move the compiled program to #{test_result_dir}")
79 79 system("rm -Rf #{sandbox_dir}/*")
80 80 end
81 81
82 82 require "#{problem_home}/script/test_dsl.rb"
83 83 load "#{problem_home}/test_cases/all_tests.cfg"
84 84 problem = Problem.get_instance
85 85
86 86 if problem.well_formed? == false
87 87 puts "The problem specification is not well formed."
88 88 exit(127)
89 89 end
90 90
91 91 # Doing the testing.
92 92 (1..(problem.num_tests)).each do |test_num|
93 93 puts
94 94 execute("cp #{test_result_dir}/a.out #{sandbox_dir}", "Cannot copy the compiled program into #{sandbox_dir}")
95 95 execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script")
96 96 execute("mkdir #{test_result_dir}/#{test_num}", "Cannot create directory #{test_result_dir}/#{test_num}")
97 97 execute("mv #{sandbox_dir}/result #{test_result_dir}/#{test_num}", "Cannot copy the result file into #{test_result_dir}/#{test_num}")
98 98 execute("mv #{sandbox_dir}/comment #{test_result_dir}/#{test_num}", "Cannot copy the comment file into #{test_result_dir}/#{test_num}")
You need to be logged in to leave comments. Login now