Changeset 993
- Timestamp:
- 01/22/09 01:32:19 (3 years ago)
- Location:
- trunk
- Files:
-
- 10 added
- 9 edited
-
common/job.php (modified) (3 diffs)
-
common/user.php (modified) (1 diff)
-
eval/classic_grader.php (modified) (2 diffs)
-
eval/utilities.php (modified) (4 diffs)
-
jrun/bad_syscalls (modified) (1 diff)
-
jrun/run-tests.php (modified) (6 diffs)
-
jrun/tests/do_math.py (added)
-
jrun/tests/eval_fork.py (added)
-
jrun/tests/exception.py (added)
-
jrun/tests/file.py (added)
-
jrun/tests/fork_bomb.py (added)
-
jrun/tests/mem_limit_huge.py (added)
-
jrun/tests/missing_import.py (added)
-
jrun/tests/network.py (added)
-
jrun/tests/time_limit.py (added)
-
scripts/pybin.sh (added)
-
www/macros/macro_tasksubmit.php (modified) (1 diff)
-
www/static/js/submit.js (modified) (1 diff)
-
www/views/submit.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/common/job.php
r991 r993 10 10 // round_id: Round to submit for. Optional, if missing the job is sent 11 11 // to all parent rounds. 12 // compiler_id: c, cpp or fpc.12 // compiler_id: c, cpp, fpc, or py. 13 13 // solution: A string with the file to submit. 14 14 // … … 38 38 39 39 // Validate compiler id 40 $valid_compilers = array('c', 'cpp', 'fpc' );40 $valid_compilers = array('c', 'cpp', 'fpc', 'py'); 41 41 if (!array_key_exists('compiler_id', $args)) { 42 42 $errors['compiler_id'] = "Lipseste compilatorul."; 43 43 } else if (array_search($args['compiler_id'], $valid_compilers) === false) { 44 44 $errors['compiler_id'] = "Compilator invalid."; 45 } 46 // HACK: For the moment, only admin`s are allowed to submit Python jobs. 47 // TODO: Remove this once Python support is stable. 48 if ('py' == $args['compiler_id'] && !user_is_admin($user)) { 49 $errors['compiler_id'] = 'Deocamdata, numai administratorii pot ' 50 .'trimite surse Python.'; 45 51 } 46 52 … … 56 62 57 63 // Check task submit security 58 if ( !security_query($user, 'task-submit', $task)) {64 if ($task && !security_query($user, 'task-submit', $task)) { 59 65 $errors[] = "Nu ai voie sa trimiti la acest task."; 60 66 } 61 if ($round != null&& !security_query($round, 'task-submit', $round)) {67 if ($round && !security_query($round, 'task-submit', $round)) { 62 68 $errors[] = "Nu poti sa trimiti la aceasta runda."; 63 69 } -
trunk/common/user.php
r852 r993 107 107 } 108 108 109 function user_is_admin($user) { 110 if (!$user) { 111 return false; 112 } 113 log_assert_valid(user_validate($user)); 114 return $user['security_level'] === 'admin'; 115 } 116 109 117 ?> -
trunk/eval/classic_grader.php
r852 r993 56 56 } 57 57 58 // HACK: Capture run-time stderr for Python jobs. 59 // 60 // WARNING! This is a security hole! Users may dump input tests 61 // on stderr and see them in the monitor page. Currently, only 62 // admins are allowed to submit Python. 63 // 64 // TODO: Come up with a safe way of reporting run-time errors 65 // for Python scripts. 66 $capture_std = ('py' == $job['compiler_id']); 67 58 68 // Running tests. 59 69 $test_score = array(); … … 101 111 102 112 // Run user program. 103 $jrunres = jail_run($userfile, $jaildir, $tparams['timelimit'] * 1000, $tparams['memlimit']); 113 $jrunres = jail_run($userfile, $jaildir, $tparams['timelimit'] * 1000, 114 $tparams['memlimit'], $capture_std); 104 115 log_assert($jrunres['result'] != 'ERROR', "Error in jrun."); 105 116 if ($jrunres['result'] == 'FAIL') { 106 117 log_print("Test $testno: User program failed: {$jrunres['message']} ". 107 118 "{$jrunres['time']}ms {$jrunres['memory']}kb"); 119 if ($capture_std) { 120 // TODO: Come up with a safe way of reporting run-time 121 // errors for Python scripts. 122 $job_message = $jrunres['message'].": " 123 .substr($jrunres['stderr'], 124 -min(100, strlen($jrunres['stderr']))); 125 } else { 126 $job_message = $jrunres['message']; 127 } 108 128 job_test_update($job['id'], $testno, $group_idx, $jrunres['time'], $jrunres['memory'], 109 null, null, 0, $j runres['message']);129 null, null, 0, $job_message); 110 130 // User program failed on this test. Bye bye. 111 131 continue; -
trunk/eval/utilities.php
r852 r993 25 25 // Returns success value, and a friendly error message in $compiler_message. 26 26 // 27 // Can currently handle C, C++ and FreePascal27 // Can currently handle C, C++, FreePascal, and Python. 28 28 function compile_file($input_file_name, $output_file_name, &$compiler_message) 29 29 { … … 35 35 'pas' => 'fpc -O2 -Xs %file_name%', 36 36 'fpc' => 'fpc -O2 -Xs %file_name%', 37 'py' => IA_JUDGE_PY_COMPILER.' %file_name% %exe_name%', 37 38 ); 38 if (!preg_match("/^(.*)\.(c|cpp|pas|fpc )$/i", $input_file_name, $matches)) {39 if (!preg_match("/^(.*)\.(c|cpp|pas|fpc|py)$/i", $input_file_name, $matches)) { 39 40 $compiler_message = "Nu am putut sa determin compilatorul ". 40 41 "pentru '$input_file_name'."; … … 53 54 54 55 // Running compiler 55 $compiler_message = shell_exec("$cmdline 2>&1 | head -n 25");56 $compiler_message = shell_exec("$cmdline 2>&1 | head -n 50"); 56 57 57 58 // This is the BEST way to fail on compilation errors. … … 168 169 } 169 170 170 if ($ result['result'] == 'OK' && $capture_std) {171 if ($capture_std) { 171 172 $result['stdout'] = @file_get_contents($jaildir.'jailed_stdout'); 172 173 if ($result['stdout'] === false) { -
trunk/jrun/bad_syscalls
r651 r993 34 34 mount 35 35 umount 36 accept 37 bind 38 connect 39 getsockname 40 getsockopt 41 listen 42 recv 43 recvfrom 44 send 45 setsockopt 46 socket 47 socketpair -
trunk/jrun/run-tests.php
r852 r993 3 3 4 4 require_once(dirname($argv[0]) . "/../config.php"); 5 require_once(IA_ROOT_DIR . 'eval/config.php'); 5 6 require_once(IA_ROOT_DIR . 'common/log.php'); 6 7 … … 8 9 $jail_dir = "jail"; 9 10 $exe_name = "prog"; 10 $extra_args = "--block-syscalls-file=bad_syscalls -- chroot --verbose";11 $extra_args = "--block-syscalls-file=bad_syscalls --verbose"; 11 12 //$extra_args = "--nice -5 --block-syscalls-file=bad_syscalls --verbose"; 12 //$extra_args = "--uid 65534 --gid 65534 --block-syscalls-file=bad_syscalls -- verbose";13 //$extra_args = "--uid 65534 --gid 65534 --block-syscalls-file=bad_syscalls --chroot"; 13 14 //$extra_args = "--uid 65534 --gid 65534 --block-syscalls-file=bad_syscalls"; 15 16 // In order to run python tests, download a python distribution, configure, 17 // make, make install, then specify the top level directory here. 18 $py_compiler = IA_ROOT_DIR."scripts/pybin.sh ".IA_JUDGE_PY_DISTRO 19 ." {$jail_dir}"; 14 20 15 21 // Parse a source file … … 20 26 $test_args = $test_exp_res = null; 21 27 foreach (file("$filename") as $line) { 22 if (preg_match("/ \/\/JRUN_ARGS =(.*)$/", $line, $matches)) {28 if (preg_match("/(?:\/\/|#) JRUN_ARGS =(.*)$/", $line, $matches)) { 23 29 $test_args = trim($matches[1]); 24 30 } 25 if (preg_match("/ \/\/JRUN_RES =(.*)$/", $line, $matches)) {31 if (preg_match("/(?:\/\/|#) JRUN_RES =(.*)$/", $line, $matches)) { 26 32 $test_exp_res = trim($matches[1]); 27 33 } … … 34 40 function compile_source($source, $exe) 35 41 { 42 global $py_compiler; 36 43 if (strpos($source, ".cpp") === strlen($source) - 4) { 37 system("g++ -Wall -lm -O2 $source - o $exe", $ret);44 system("g++ -Wall -lm -O2 $source --static -o $exe", $ret); 38 45 } else if (strpos($source, ".c") === strlen($source) - 2) { 39 system("gcc -Wall -lm -O2 $source -o $exe", $ret); 46 system("gcc -Wall -lm -O2 $source --static -o $exe", $ret); 47 } else if (strpos($source, ".py") === strlen($source) - 3) { 48 system("{$py_compiler} $source $exe", $ret); 40 49 } else { 41 50 log_error("Can't compile $source, unknown file extension\n"); … … 53 62 global $jail_dir, $exe_name; 54 63 55 system("rm -rf jail");64 system("rm -rf $jail_dir"); 56 65 system("mkdir -p $jail_dir"); 57 66 system("chmod 777 $jail_dir"); 58 67 compile_source($filename, "$jail_dir/$exe_name"); 59 60 68 $cmd = "./jrun --dir=$jail_dir --prog=$exe_name $args"; 61 69 … … 130 138 print("Invalid arguments\n"); 131 139 } 132 } while ( true);140 } while (false); 133 141 134 142 ?> -
trunk/www/macros/macro_tasksubmit.php
r934 r993 60 60 <option value="cpp">GNU C++</option> 61 61 <option value="fpc">FreePascal</option> 62 <?php if (user_is_admin($identity_user)) { ?> 63 <option value="py">Python (FOARTE EXPERIMENTAL!)</option> 64 <?php } ?> 62 65 </select> 63 66 </li> -
trunk/www/static/js/submit.js
r852 r993 43 43 } 44 44 var ext = f.value.substring(k + 1).toLowerCase(); 45 if ('c' == ext || 'cpp' == ext || 'pas' == ext ) {45 if ('c' == ext || 'cpp' == ext || 'pas' == ext || 'py' == ext) { 46 46 if ('pas' == ext) { 47 47 // choose FreePascal compiler -
trunk/www/views/submit.php
r934 r993 54 54 <option value="cpp"<?= 'cpp' == fval('compiler_id') ? ' selected="selected"' : '' ?>>GNU C++</option> 55 55 <option value="fpc"<?= 'fpc' == fval('compiler_id') ? ' selected="selected"' : '' ?>>FreePascal</option> 56 <?php if (user_is_admin($identity_user)) { ?> 57 <option value="py"<?= 'py' == fval('compiler_id') ? ' selected="selected"' : '' ?>>Python (FOARTE EXPERIMENTAL!)</option> 58 <?php } ?> 56 59 </select> 57 60 <?= ferr_span('compiler_id') ?>
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)