Description:
[grader] fixed to work with free pascal git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@221 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

r53:45abc6ae27d1 - - 3 files changed: 10 inserted, 7 deleted

@@ -212,96 +212,99
212 case __NR_access:
212 case __NR_access:
213 case __NR_oldlstat:
213 case __NR_oldlstat:
214 case __NR_truncate:
214 case __NR_truncate:
215 case __NR_stat:
215 case __NR_stat:
216 case __NR_lstat:
216 case __NR_lstat:
217 case __NR_truncate64:
217 case __NR_truncate64:
218 case __NR_stat64:
218 case __NR_stat64:
219 case __NR_lstat64:
219 case __NR_lstat64:
220 valid_filename(u->regs.ebx);
220 valid_filename(u->regs.ebx);
221 return 1;
221 return 1;
222 case __NR_exit:
222 case __NR_exit:
223 case __NR_read:
223 case __NR_read:
224 case __NR_write:
224 case __NR_write:
225 case __NR_close:
225 case __NR_close:
226 case __NR_lseek:
226 case __NR_lseek:
227 case __NR_getpid:
227 case __NR_getpid:
228 case __NR_getuid:
228 case __NR_getuid:
229 case __NR_oldfstat:
229 case __NR_oldfstat:
230 case __NR_dup:
230 case __NR_dup:
231 case __NR_brk:
231 case __NR_brk:
232 case __NR_getgid:
232 case __NR_getgid:
233 case __NR_geteuid:
233 case __NR_geteuid:
234 case __NR_getegid:
234 case __NR_getegid:
235 case __NR_dup2:
235 case __NR_dup2:
236 case __NR_ftruncate:
236 case __NR_ftruncate:
237 case __NR_fstat:
237 case __NR_fstat:
238 case __NR_personality:
238 case __NR_personality:
239 case __NR__llseek:
239 case __NR__llseek:
240 case __NR_readv:
240 case __NR_readv:
241 case __NR_writev:
241 case __NR_writev:
242 case __NR_getresuid:
242 case __NR_getresuid:
243 #ifdef __NR_pread64
243 #ifdef __NR_pread64
244 case __NR_pread64:
244 case __NR_pread64:
245 case __NR_pwrite64:
245 case __NR_pwrite64:
246 #else
246 #else
247 case __NR_pread:
247 case __NR_pread:
248 case __NR_pwrite:
248 case __NR_pwrite:
249 #endif
249 #endif
250 case __NR_ftruncate64:
250 case __NR_ftruncate64:
251 case __NR_fstat64:
251 case __NR_fstat64:
252 case __NR_fcntl:
252 case __NR_fcntl:
253 case __NR_fcntl64:
253 case __NR_fcntl64:
254 case __NR_mmap:
254 case __NR_mmap:
255 case __NR_munmap:
255 case __NR_munmap:
256 case __NR_ioctl:
256 case __NR_ioctl:
257 case __NR_uname:
257 case __NR_uname:
258 case 252:
258 case 252:
259 case 243:
259 case 243:
260 + // added for free pascal
261 + case __NR_ugetrlimit:
262 + case __NR_readlink:
260 return 1;
263 return 1;
261 // case __NR_time:
264 // case __NR_time:
262 case __NR_alarm:
265 case __NR_alarm:
263 // case __NR_pause:
266 // case __NR_pause:
264 case __NR_signal:
267 case __NR_signal:
265 case __NR_fchmod:
268 case __NR_fchmod:
266 case __NR_sigaction:
269 case __NR_sigaction:
267 case __NR_sgetmask:
270 case __NR_sgetmask:
268 case __NR_ssetmask:
271 case __NR_ssetmask:
269 case __NR_sigsuspend:
272 case __NR_sigsuspend:
270 case __NR_sigpending:
273 case __NR_sigpending:
271 case __NR_getrlimit:
274 case __NR_getrlimit:
272 case __NR_getrusage:
275 case __NR_getrusage:
273 case __NR_gettimeofday:
276 case __NR_gettimeofday:
274 case __NR_select:
277 case __NR_select:
275 case __NR_readdir:
278 case __NR_readdir:
276 case __NR_setitimer:
279 case __NR_setitimer:
277 case __NR_getitimer:
280 case __NR_getitimer:
278 case __NR_sigreturn:
281 case __NR_sigreturn:
279 case __NR_mprotect:
282 case __NR_mprotect:
280 case __NR_sigprocmask:
283 case __NR_sigprocmask:
281 case __NR_getdents:
284 case __NR_getdents:
282 case __NR_getdents64:
285 case __NR_getdents64:
283 case __NR__newselect:
286 case __NR__newselect:
284 case __NR_fdatasync:
287 case __NR_fdatasync:
285 case __NR_mremap:
288 case __NR_mremap:
286 case __NR_poll:
289 case __NR_poll:
287 case __NR_getcwd:
290 case __NR_getcwd:
288 case __NR_nanosleep:
291 case __NR_nanosleep:
289 case __NR_rt_sigreturn:
292 case __NR_rt_sigreturn:
290 case __NR_rt_sigaction:
293 case __NR_rt_sigaction:
291 case __NR_rt_sigprocmask:
294 case __NR_rt_sigprocmask:
292 case __NR_rt_sigpending:
295 case __NR_rt_sigpending:
293 case __NR_rt_sigtimedwait:
296 case __NR_rt_sigtimedwait:
294 case __NR_rt_sigqueueinfo:
297 case __NR_rt_sigqueueinfo:
295 case __NR_rt_sigsuspend:
298 case __NR_rt_sigsuspend:
296 case __NR_mmap2:
299 case __NR_mmap2:
297 case __NR__sysctl:
300 case __NR__sysctl:
298 return (filter_syscalls == 1);
301 return (filter_syscalls == 1);
299 case __NR_times:
302 case __NR_times:
300 return allow_times;
303 return allow_times;
301 case __NR_kill:
304 case __NR_kill:
302 if (u->regs.ebx == box_pid)
305 if (u->regs.ebx == box_pid)
303 die("Commited suicide by signal %d.", (int)u->regs.ecx);
306 die("Commited suicide by signal %d.", (int)u->regs.ecx);
304 return 0;
307 return 0;
305 default:
308 default:
306 return 0;
309 return 0;
307 }
310 }
@@ -1,106 +1,106
1 #!/bin/sh
1 #!/bin/sh
2
2
3 ##############################
3 ##############################
4 #
4 #
5 # Standard Compile Script
5 # Standard Compile Script
6 #
6 #
7 # Supported compilers:
7 # Supported compilers:
8 - # gcc, g++, and gpc.
8 + # gcc, g++, and fpc.
9 #
9 #
10 ##############################
10 ##############################
11
11
12 talk ()
12 talk ()
13 {
13 {
14 if [ "$TALKATIVE" != "" ]; then
14 if [ "$TALKATIVE" != "" ]; then
15 echo "$1"
15 echo "$1"
16 fi
16 fi
17 }
17 }
18
18
19 export C_COMPILER=/usr/bin/gcc
19 export C_COMPILER=/usr/bin/gcc
20 export CPLUSPLUS_COMPILER=/usr/bin/g++
20 export CPLUSPLUS_COMPILER=/usr/bin/g++
21 - export PASCAL_COMPILER=/usr/bin/gpc
21 + export PASCAL_COMPILER=/usr/bin/fpc
22
22
23 export C_OPTIONS="-O2 -s -static -lm -Wall"
23 export C_OPTIONS="-O2 -s -static -lm -Wall"
24 export CPLUSPLUS_OPTIONS="-O2 -s -static -lm -Wall"
24 export CPLUSPLUS_OPTIONS="-O2 -s -static -lm -Wall"
25 - export PASCAL_OPTIONS="-O2 -XS -lm -Wall"
25 + export PASCAL_OPTIONS="-O1 -XS"
26
26
27 # Check for the correct number of arguments. Otherwise, print usage.
27 # Check for the correct number of arguments. Otherwise, print usage.
28 if [ $# -eq 0 -o $# -gt 4 ]
28 if [ $# -eq 0 -o $# -gt 4 ]
29 then
29 then
30 echo "Usage: $0 <language> [<source-file>] [<output-file>] [<message-file>]"
30 echo "Usage: $0 <language> [<source-file>] [<output-file>] [<message-file>]"
31 echo
31 echo
32 echo "<source-file> is defaulted to \"source\"."
32 echo "<source-file> is defaulted to \"source\"."
33 echo "<output-file> is defaulted to \"a.out\"."
33 echo "<output-file> is defaulted to \"a.out\"."
34 echo "<message-file> is defaulted to \"compiler_message\"."
34 echo "<message-file> is defaulted to \"compiler_message\"."
35 echo
35 echo
36 exit 127
36 exit 127
37 fi
37 fi
38
38
39 # Retrieve the arguments.
39 # Retrieve the arguments.
40 if [ $# -ge 1 ]
40 if [ $# -ge 1 ]
41 then
41 then
42 export PROG_LANG=$1
42 export PROG_LANG=$1
43 talk "programming language: ${PROG_LANG}"
43 talk "programming language: ${PROG_LANG}"
44 fi
44 fi
45
45
46 if [ $# -ge 2 ]
46 if [ $# -ge 2 ]
47 then
47 then
48 export SOURCE_FILE=$2
48 export SOURCE_FILE=$2
49 else
49 else
50 export SOURCE_FILE=source
50 export SOURCE_FILE=source
51 fi
51 fi
52 talk " source file: $SOURCE_FILE"
52 talk " source file: $SOURCE_FILE"
53
53
54 if [ $# -ge 3 ]
54 if [ $# -ge 3 ]
55 then
55 then
56 export OUTPUT_FILE=$3
56 export OUTPUT_FILE=$3
57 else
57 else
58 export OUTPUT_FILE=a.out
58 export OUTPUT_FILE=a.out
59 fi
59 fi
60 talk " output file: $OUTPUT_FILE"
60 talk " output file: $OUTPUT_FILE"
61
61
62 if [ $# -eq 4 ]
62 if [ $# -eq 4 ]
63 then
63 then
64 export MESSAGE_FILE=$4
64 export MESSAGE_FILE=$4
65 else
65 else
66 export MESSAGE_FILE=compiler_message
66 export MESSAGE_FILE=compiler_message
67 fi
67 fi
68 talk " message file: $MESSAGE_FILE"
68 talk " message file: $MESSAGE_FILE"
69
69
70 # Remove any remaining output files or message files.
70 # Remove any remaining output files or message files.
71 rm -Rf $OUTPUT_FILE
71 rm -Rf $OUTPUT_FILE
72 rm -Rf $MESSAGE_FILE
72 rm -Rf $MESSAGE_FILE
73
73
74 # Check if the source file exists before attempt compiling.
74 # Check if the source file exists before attempt compiling.
75 if [ ! -f $SOURCE_FILE ]
75 if [ ! -f $SOURCE_FILE ]
76 then
76 then
77 talk "ERROR: The source file does not exist!"
77 talk "ERROR: The source file does not exist!"
78 echo "ERROR: The source file did not exist." > $MESSAGE_FILE
78 echo "ERROR: The source file did not exist." > $MESSAGE_FILE
79 exit 127
79 exit 127
80 fi
80 fi
81
81
82 # Compile.
82 # Compile.
83 if [ $PROG_LANG = "c" ]
83 if [ $PROG_LANG = "c" ]
84 then
84 then
85 $C_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $C_OPTIONS 2>$MESSAGE_FILE
85 $C_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $C_OPTIONS 2>$MESSAGE_FILE
86 elif [ $PROG_LANG = "c++" ]
86 elif [ $PROG_LANG = "c++" ]
87 then
87 then
88 $CPLUSPLUS_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $CPLUSPLUS_OPTIONS 2>$MESSAGE_FILE
88 $CPLUSPLUS_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $CPLUSPLUS_OPTIONS 2>$MESSAGE_FILE
89 - elif [ $PROG_LANG = "pascal" ]
89 + elif [ $PROG_LANG = "pas" ]
90 then
90 then
91 - $PASCAL_COMPILER $SOURCE_FILE -o $OUTPUT_FILE $PASCAL_OPTIONS 2>$MESSAGE_FILE
91 + $PASCAL_COMPILER $SOURCE_FILE -o$OUTPUT_FILE $PASCAL_OPTIONS >$MESSAGE_FILE
92 else
92 else
93 talk "ERROR: Invalid language specified!"
93 talk "ERROR: Invalid language specified!"
94 echo "ERROR: Invalid language specified!" > $MESSAGE_FILE
94 echo "ERROR: Invalid language specified!" > $MESSAGE_FILE
95 exit 127
95 exit 127
96 fi
96 fi
97
97
98 # Report success or failure.
98 # Report success or failure.
99 if [ -f $OUTPUT_FILE ]
99 if [ -f $OUTPUT_FILE ]
100 then
100 then
101 talk "Compilation was successful!"
101 talk "Compilation was successful!"
102 else
102 else
103 talk "ERROR: Something was wrong during the compilation!"
103 talk "ERROR: Something was wrong during the compilation!"
104 talk "Dumping compiler message:"
104 talk "Dumping compiler message:"
105 #cat $MESSAGE_FILE
105 #cat $MESSAGE_FILE
106 fi
106 fi
@@ -1,88 +1,88
1 #!/usr/bin/ruby
1 #!/usr/bin/ruby
2
2
3 def log(str='')
3 def log(str='')
4 if ENV['TALKATIVE']!=nil
4 if ENV['TALKATIVE']!=nil
5 puts str
5 puts str
6 end
6 end
7 if ENV['GRADER_LOGGING']!=nil
7 if ENV['GRADER_LOGGING']!=nil
8 log_fname = ENV['GRADER_LOGGING']
8 log_fname = ENV['GRADER_LOGGING']
9 fp = File.open(log_fname,"a")
9 fp = File.open(log_fname,"a")
10 fp.puts("judge: #{Time.new.strftime("%H:%M")} #{str}")
10 fp.puts("judge: #{Time.new.strftime("%H:%M")} #{str}")
11 fp.close
11 fp.close
12 end
12 end
13 end
13 end
14
14
15 problem_home = ENV['PROBLEM_HOME']
15 problem_home = ENV['PROBLEM_HOME']
16
16
17 def execute(command, error_message="")
17 def execute(command, error_message="")
18 if not system(command)
18 if not system(command)
19 msg = "ERROR: #{error_message}"
19 msg = "ERROR: #{error_message}"
20 log msg
20 log msg
21 raise msg
21 raise msg
22 end
22 end
23 end
23 end
24
24
25 # ARGV[0] --- language
25 # ARGV[0] --- language
26 # ARGV[1] --- program source file
26 # ARGV[1] --- program source file
27 # ARGV[2] --- test result directory
27 # ARGV[2] --- test result directory
28 # ARGV[3] --- sandbox directory
28 # ARGV[3] --- sandbox directory
29
29
30 if ARGV.length < 2 || ARGV.length > 4
30 if ARGV.length < 2 || ARGV.length > 4
31 puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]"
31 puts "Usage: judge <language> <program-source> [<test-result-directory>] [<sandbox-directory>]"
32 puts " <sandbox-directory> is defaulted to ./sandbox"
32 puts " <sandbox-directory> is defaulted to ./sandbox"
33 puts " <test-result-directory> is defaulted to ./test-result"
33 puts " <test-result-directory> is defaulted to ./test-result"
34 puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it."
34 puts "WARNING: The judge script will forcefully create the (implicitly and explicitly) specified directories and remove anything inside it."
35 exit(127)
35 exit(127)
36 end
36 end
37
37
38 language = ARGV[0]
38 language = ARGV[0]
39 - if language != "c" && language != "c++" && language != "pascal"
39 + if language != "c" && language != "c++" && language != "pas"
40 - log "You specified a language that is not supported."
40 + log "You specified a language that is not supported: #{language}."
41 exit(127)
41 exit(127)
42 end
42 end
43
43
44 source_file = ARGV[1]
44 source_file = ARGV[1]
45 if File.exist?(source_file) == false
45 if File.exist?(source_file) == false
46 log "The source file does not exist."
46 log "The source file does not exist."
47 exit(127)
47 exit(127)
48 end
48 end
49
49
50 log "Making test result and sandbox directories..."
50 log "Making test result and sandbox directories..."
51
51
52 current_dir = `pwd`
52 current_dir = `pwd`
53 current_dir.strip!
53 current_dir.strip!
54
54
55 if ARGV.length >= 3
55 if ARGV.length >= 3
56 test_result_dir = ARGV[2]
56 test_result_dir = ARGV[2]
57 else
57 else
58 test_result_dir = "#{current_dir}/test-result"
58 test_result_dir = "#{current_dir}/test-result"
59 end
59 end
60 log "Test result directory: #{test_result_dir}"
60 log "Test result directory: #{test_result_dir}"
61 system("rm -Rf #{test_result_dir}")
61 system("rm -Rf #{test_result_dir}")
62 execute("mkdir #{test_result_dir}", "Cannot make directory #{test_result_dir}.")
62 execute("mkdir #{test_result_dir}", "Cannot make directory #{test_result_dir}.")
63
63
64 if ARGV.length >= 4
64 if ARGV.length >= 4
65 sandbox_dir = ARGV[3]
65 sandbox_dir = ARGV[3]
66 else
66 else
67 sandbox_dir = "#{current_dir}/sandbox"
67 sandbox_dir = "#{current_dir}/sandbox"
68 end
68 end
69 log "Sandbox directory: #{sandbox_dir}"
69 log "Sandbox directory: #{sandbox_dir}"
70 system("rm -Rf #{sandbox_dir}")
70 system("rm -Rf #{sandbox_dir}")
71 execute("mkdir #{sandbox_dir}", "Cannot make directory #{sandbox_dir}")
71 execute("mkdir #{sandbox_dir}", "Cannot make directory #{sandbox_dir}")
72
72
73 # Compile
73 # Compile
74 log
74 log
75 log "Compiling..."
75 log "Compiling..."
76 execute("cp #{source_file} #{sandbox_dir}", "Cannot copy the source file to #{sandbox_dir}")
76 execute("cp #{source_file} #{sandbox_dir}", "Cannot copy the source file to #{sandbox_dir}")
77 begin
77 begin
78 Dir.chdir sandbox_dir
78 Dir.chdir sandbox_dir
79 rescue
79 rescue
80 log "ERROR: Cannot change directory to #{sandbox_dir}."
80 log "ERROR: Cannot change directory to #{sandbox_dir}."
81 exit(127)
81 exit(127)
82 end
82 end
83 execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!")
83 execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!")
84 compile_message = `cat compiler_message`
84 compile_message = `cat compiler_message`
85 compile_message.strip!
85 compile_message.strip!
86 execute("mv compiler_message #{test_result_dir}", "Cannot move the compiler message to #{test_result_dir}.")
86 execute("mv compiler_message #{test_result_dir}", "Cannot move the compiler message to #{test_result_dir}.")
87 if !FileTest.exist?("a.out")
87 if !FileTest.exist?("a.out")
88 log "Cannot compile the source code. See message in #{test_result_dir}/compile_message"
88 log "Cannot compile the source code. See message in #{test_result_dir}/compile_message"
You need to be logged in to leave comments. Login now