Description:
Merge branch 'master' of gitorious.org:cafe-grader/cafe-grader-judge-scripts into win-local
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r106:502201e59a2c - - 1 file changed: 2 inserted, 0 deleted
@@ -1,98 +1,100 | |||
|
1 | 1 | #!/usr/bin/ruby |
|
2 | 2 | |
|
3 | + require 'fileutils' | |
|
4 | + | |
|
3 | 5 | def log(str='') |
|
4 | 6 | if ENV['TALKATIVE']!=nil |
|
5 | 7 | puts str |
|
6 | 8 | end |
|
7 | 9 | if ENV['GRADER_LOGGING']!=nil |
|
8 | 10 | log_fname = ENV['GRADER_LOGGING'] |
|
9 | 11 | fp = File.open(log_fname,"a") |
|
10 | 12 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
11 | 13 | fp.close |
|
12 | 14 | end |
|
13 | 15 | end |
|
14 | 16 | |
|
15 | 17 | def extract_time(t) |
|
16 | 18 | # puts "TIME: #{t}" |
|
17 | 19 | if (result=/^(.*)r(.*)u(.*)s/.match(t)) |
|
18 | 20 | {:real => result[1], :user => result[2], :sys => result[3]} |
|
19 | 21 | else |
|
20 | 22 | #{:real => 0, :user => 0, :sys => 0} |
|
21 | 23 | #puts "ERROR READING RUNNING TIME: #{t}" |
|
22 | 24 | raise "Error reading running time: #{t}" |
|
23 | 25 | end |
|
24 | 26 | end |
|
25 | 27 | |
|
26 | 28 | def compile_box(source,bin) |
|
27 | 29 | system("g++ #{source} -o #{bin}") |
|
28 | 30 | end |
|
29 | 31 | |
|
30 | 32 | if ARGV.length < 2 || ARGV.length > 3 |
|
31 | 33 | puts "Usage: run <language> <test-num> [<program-name>]" |
|
32 | 34 | exit(127) |
|
33 | 35 | end |
|
34 | 36 | |
|
35 | 37 | language = ARGV[0] |
|
36 | 38 | test_num = ARGV[1].to_i |
|
37 | 39 | if ARGV.length > 2 |
|
38 | 40 | program_name = ARGV[2] |
|
39 | 41 | else |
|
40 | 42 | program_name = "a.out" |
|
41 | 43 | end |
|
42 | 44 | |
|
43 | 45 | problem_home = ENV['PROBLEM_HOME'] |
|
44 | 46 | require "#{problem_home}/script/test_dsl.rb" |
|
45 | 47 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
46 | 48 | problem = Problem.get_instance |
|
47 | 49 | |
|
48 | 50 | if problem.well_formed? == false |
|
49 | 51 | log "The problem specification is not well formed." |
|
50 | 52 | exit(127) |
|
51 | 53 | end |
|
52 | 54 | |
|
53 | 55 | # Check if the test number is okay. |
|
54 | 56 | if test_num <= 0 || test_num > problem.num_tests |
|
55 | 57 | log "You have specified a wrong test number." |
|
56 | 58 | exit(127) |
|
57 | 59 | end |
|
58 | 60 | |
|
59 | 61 | ##################################### |
|
60 | 62 | # Set the relavant file names here. # |
|
61 | 63 | ##################################### |
|
62 | 64 | |
|
63 | 65 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
64 | 66 | |
|
65 | 67 | ##################################### |
|
66 | 68 | |
|
67 | 69 | time_limit = problem.get_time_limit test_num |
|
68 | 70 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
69 | 71 | |
|
70 | 72 | # Copy the input file. |
|
71 | 73 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
72 | 74 | |
|
73 | 75 | # check if box is there, if not, compile it! |
|
74 | 76 | if !File.exists?("#{problem_home}/script/box") |
|
75 | 77 | log "WARNING: Compiling box: to increase efficiency, it should be compile manually" |
|
76 | 78 | compile_box("#{problem_home}/script/box.cc", |
|
77 | 79 | "#{problem_home}/script/box") |
|
78 | 80 | end |
|
79 | 81 | |
|
80 | 82 | # Hide PROBLEM_HOME |
|
81 | 83 | ENV['PROBLEM_HOME'] = nil |
|
82 | 84 | |
|
83 | 85 | # Run the program. |
|
84 | 86 | #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 | 87 | 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 | 88 | log "Running test #{test_num}..." |
|
87 | 89 | log run_command |
|
88 | 90 | log |
|
89 | 91 | system(run_command) |
|
90 | 92 | |
|
91 | 93 | # Restore PROBLEM_HOME |
|
92 | 94 | ENV['PROBLEM_HOME'] = problem_home |
|
93 | 95 | |
|
94 | 96 | # Create the result file. |
|
95 | 97 | result_file = File.new("result", "w") |
|
96 | 98 | comment_file = File.new("comment", "w") |
|
97 | 99 | |
|
98 | 100 | # Check if the program actually produced any output. |
You need to be logged in to leave comments.
Login now