Esempio n. 1
0
def compile_and_run(compiler_env, expected_output):
    """Helper function for compiling, launching and
       testing the result of a program.
    """

    run(compiler_env)

    binary = ft.download({'path': '/out'}, 'path')

    os.chmod(binary, stat.S_IXUSR)

    retcode, output = execute(['./' + binary])
    eq_(retcode, 0)
    eq_(output.strip(), expected_output)

    os.remove(binary)
Esempio n. 2
0
def test_output_compilation_and_running(source):
    with TemporaryCwd():
        upload_files()
        result_env = run(
            {
                'source_file': source,
                'compiler': 'output-only',
            }
        )
        eq_(result_env['result_code'], 'OK')
        eq_(result_env['exec_info'], {'mode': 'output-only'})

        ft.download(result_env, 'out_file', tempcwd('out.txt'))
        ft.download({'source_file': source}, 'source_file', tempcwd('source.txt'))
        with open(tempcwd('out.txt'), 'r') as outfile:
            with open(tempcwd('source.txt'), 'r') as sourcefile:
                eq_(outfile.read(), sourcefile.read())

        post_run_env = run_from_executors(
            {
                'exec_info': result_env['exec_info'],
                'exe_file': result_env['out_file'],
                'check_output': True,
                'hint_file': source,
            },
            executor=None,
        )
        eq_(post_run_env['result_code'], 'OK')

        ft.download(post_run_env, 'out_file', tempcwd('out.txt'))
        ft.download({'source_file': source}, 'source_file', tempcwd('source.txt'))
        with open(tempcwd('out.txt'), 'r') as outfile:
            with open(tempcwd('source.txt'), 'r') as sourcefile:
                eq_(outfile.read(), sourcefile.read())
Esempio n. 3
0
def compile_fail(compiler_env, expected_in_compiler_output=None):
    """Helper function for compiling and asserting that it fails."""

    result_env = run(compiler_env)

    eq_(result_env['result_code'], 'CE')

    if 'compilation_output_limit' not in  compiler_env:
        ok_(len(result_env['compiler_output']) <=
                DEFAULT_COMPILER_OUTPUT_LIMIT)
    elif compiler_env['compilation_output_limit'] is not None:
        ok_(len(result_env['compiler_output']) <=
                compiler_env['compilation_output_limit'])

    if expected_in_compiler_output:
        in_(expected_in_compiler_output, result_env['compiler_output'])

    return result_env
Esempio n. 4
0
def compile_fail(compiler_env, expected_in_compiler_output=None):
    """Helper function for compiling and asserting that it fails."""

    result_env = run(compiler_env)
    print_env(result_env)

    eq_(result_env['result_code'], 'CE')

    if 'compilation_output_limit' not in  compiler_env:
        ok_(len(result_env['compiler_output']) <=
                DEFAULT_COMPILER_OUTPUT_LIMIT)
    elif compiler_env['compilation_output_limit'] is not None:
        ok_(len(result_env['compiler_output']) <=
                compiler_env['compilation_output_limit'])

    if expected_in_compiler_output:
        in_(expected_in_compiler_output, result_env['compiler_output'])

    return result_env
Esempio n. 5
0
def compile_and_run(compiler_env, expected_output):
    """Helper function for compiling, launching and
       testing the result of a program.
    """

    # Dummy sandbox doesn't support asking for versioned filename
    out_file = compiler_env['out_file']
    result_env = run(compiler_env)

    eq_(result_env['result_code'], 'OK')
    binary = ft.download({'path': out_file}, 'path')

    os.chmod(binary, stat.S_IXUSR)

    retcode, output = execute(['./' + binary])
    eq_(retcode, 0)
    eq_(output.strip(), expected_output)

    os.remove(binary)
Esempio n. 6
0
def compile_and_run(compiler_env, expected_output, program_args=None):
    """Helper function for compiling, launching and
       testing the result of a program.
    """

    # Dummy sandbox doesn't support asking for versioned filename
    out_file = compiler_env['out_file']
    if compiler_env.get('compiler', '').endswith('-java'):
        compiler_env['compilation_time_limit'] = 180000
    with TemporaryCwd('compile'):
        result_env = run(compiler_env)
    print_env(result_env)

    eq_(result_env['result_code'], 'OK')
    binary = ft.download({'path': out_file}, 'path')

    os.chmod(binary, stat.S_IXUSR | os.stat(binary).st_mode)

    if not program_args:
        program_args = []

    executor = UnprotectedExecutor()
    frkwargs = {}

    # Hack for java
    if compiler_env.get('compiler') == 'default-java':
        executor = PRootExecutor('compiler-java.1_8')
        frkwargs['proot_options'] = ['-b', '/proc']

    frunner = get_file_runner(executor, result_env)
    with frunner:
        renv = frunner(binary,
                       program_args,
                       stderr=sys.__stderr__,
                       capture_output=True,
                       **frkwargs)
    eq_(renv['return_code'], 0)
    eq_(renv['stdout'].decode().strip(), expected_output)

    os.remove(binary)
Esempio n. 7
0
def compile_and_run(compiler_env, expected_output, program_args=None):
    """Helper function for compiling, launching and
       testing the result of a program.
    """

    # Dummy sandbox doesn't support asking for versioned filename
    out_file = compiler_env['out_file']
    if compiler_env.get('compiler', '').endswith('-java'):
        compiler_env['compilation_time_limit'] = 180000
    with TemporaryCwd('compile'):
        result_env = run(compiler_env)
    print_env(result_env)

    eq_(result_env['result_code'], 'OK')
    binary = ft.download({'path': out_file}, 'path')

    os.chmod(binary, stat.S_IXUSR | os.stat(binary).st_mode)

    if not program_args:
        program_args = []

    executor = UnprotectedExecutor()
    frkwargs = {}

    # Hack for java
    if compiler_env.get('compiler') == 'default-java':
        executor = PRootExecutor('compiler-java.1_8')
        frkwargs['proot_options'] = ['-b', '/proc']

    frunner = get_file_runner(executor, result_env)
    with frunner:
        renv = frunner(binary, program_args,
                       stderr=sys.__stderr__, capture_output=True, **frkwargs)
    eq_(renv['return_code'], 0)
    eq_(renv['stdout'].strip(), expected_output)

    os.remove(binary)