def test_common_time_limiting(): def _test(source, time_limit, executor, callback): with TemporaryCwd(): upload_files() result_env = compile_and_run(source, { 'in_file': '/input', 'exec_time_limit': time_limit }, executor) print_env(result_env) callback(result_env) for executor in CHECKING_EXECUTORS: yield _test, '/procspam.c', 500, executor(), res_tle if not NO_JAVA_TESTS: yield _test, '/procspam.java', 500, executor(), res_tle if ENABLE_SANDBOXES: for executor in SANDBOXED_CHECKING_EXECUTORS: yield _test, "/procspam.c", 200, executor(), res_tle yield _test, "/1-sec-prog.c", 10, executor(), res_tle yield _test, "/1-sec-prog.c", 1000, SupervisedExecutor(), res_ok yield _test, "/1-sec-prog.c", 990, VCPUExecutor(), res_tle yield _test, "/1-sec-prog.c", 1100, VCPUExecutor(), res_ok if not NO_JAVA_TESTS: yield _test, "/proc1secprog.java", 100, SupervisedExecutor(), \ res_tle yield _test, "/proc1secprog.java", 1000, SupervisedExecutor(), \ res_ok
def test_local_opens(): def change(env): res_ok(env) eq_('13', open(tempcwd('somefile')).read().strip()) ok_(os.path.exists(tempcwd('./not_existing'))) def nochange(env): res_re(1)(env) eq_('42', open(tempcwd('somefile')).read().strip()) ok_(not os.path.exists(tempcwd('./not_existing'))) # Test that this is in fact unsafe yield _test_exec, '/openrw.c', DetailedUnprotectedExecutor(), change, {} if ENABLE_SANDBOXES: yield _test_exec, '/open.c', SupervisedExecutor(), \ res_rv('opening files'), {} yield _test_exec, '/openrw.c', SupervisedExecutor(), \ res_rv('opening files'), {} yield _test_exec, '/open.c', \ SupervisedExecutor(allow_local_open=True), res_ok, {} yield _test_exec, '/openrw.c', \ SupervisedExecutor(allow_local_open=True), nochange, {} yield _test_exec, '/open2.c', \ SupervisedExecutor(allow_local_open=True), res_re(1), {}
def _make_common_time_limiting_cases(): for executor in CHECKING_EXECUTORS: yield '/procspam.c', 500, executor(), res_tle if not NO_JAVA_TESTS: yield '/procspam.java', 500, executor(), res_tle if ENABLE_SANDBOXES: for executor in SANDBOXED_CHECKING_EXECUTORS: yield "/procspam.c", 200, executor(), res_tle yield "/1-sec-prog.c", 10, executor(), res_tle yield "/1-sec-prog.c", 1000, SupervisedExecutor(), res_ok if not NO_JAVA_TESTS: yield "/proc1secprog.java", 100, SupervisedExecutor(), res_tle yield "/proc1secprog.java", 1000, SupervisedExecutor(), res_ok
def _run_inwer(environ, use_sandboxes=False): command = [tempcwd('inwer')] if use_sandboxes: executor = SupervisedExecutor() else: executor = DetailedUnprotectedExecutor() return _run_in_executor(environ, command, executor, ignore_errors=True)
def test_outputting_non_utf8(): if ENABLE_SANDBOXES: with TemporaryCwd(): upload_files() renv = compile_and_run('/output-non-utf8.c', { 'in_file': '/input', 'check_output': True, 'hint_file': '/input', }, SupervisedExecutor(), use_sandboxes=True) print_env(renv) in_('42', renv['result_string']) ok_(renv['result_string'])
def _test(): with TemporaryCwd(): upload_files() checker_bin = compile(checker, '/chk.e')['out_file'] with TemporaryCwd(): executor = SupervisedExecutor(use_program_return_code=True) if \ sandboxed else DetailedUnprotectedExecutor() renv = compile_and_run('/add_print.c', { 'in_file': '/input', 'check_output': True, 'hint_file': '/hint', 'chk_file': checker_bin, 'untrusted_checker': True, }, executor, use_sandboxes=sandboxed) print_env(renv) if callback: callback(renv)
def _make_return_codes_cases(): def ret_42(env): eq_(42, env['return_code']) executors = [UnprotectedExecutor] for executor in executors: yield raises(ExecError)(_test_transparent_exec), [ '/return-scanf.c', executor(), None, {}, ] yield _test_transparent_exec, [ '/return-scanf.c', executor(), ret_42, { 'ignore_errors': True }, ] yield _test_transparent_exec, [ '/return-scanf.c', executor(), ret_42, { 'extra_ignore_errors': (42, ) }, ] checking_executors = CHECKING_EXECUTORS if ENABLE_SANDBOXES: checking_executors = checking_executors + SANDBOXED_CHECKING_EXECUTORS for executor in checking_executors: yield _test_exec, ['/return-scanf.c', executor(), res_re(42), {}] if ENABLE_SANDBOXES: yield _test_exec, [ '/return-scanf.c', SupervisedExecutor(), res_ok, { 'ignore_return': True }, ]
def run(environ): return common.run(environ, SupervisedExecutor())