Exemplo n.º 1
0
def test_run_file_size_limit(profile):
    limits = {'file_size': 10}

    result = run(profile.name, 'echo -n "0123456789" > file', limits=limits)

    assert result['exit_code'] == 0

    result = run(profile.name, 'echo -n "01234567890" > file', limits=limits)

    assert result['exit_code'] == 1
    assert b'write error: File too large' in result['stderr']
Exemplo n.º 2
0
def test_run_reuse_workdir(profile, docker_client):
    with working_directory() as workdir:
        assert workdir.node is None

        run(profile.name, 'true',
            files=[{'name': 'file', 'content': b'first run data\n'}],
            workdir=workdir)

        if is_docker_swarm(docker_client):
            assert workdir.node

        result = run(profile.name, 'cat file', workdir=workdir)

        assert result['exit_code'] == 0
        assert result['stdout'] == b'first run data\n'
Exemplo n.º 3
0
def test_run_read_stdin(profile):
    result = run(profile.name, 'cat', stdin=b'')

    assert result['exit_code'] == 0
    assert result['stdout'] == b''

    result = run(profile.name, 'cat', stdin=b'binary data\n')

    assert result['exit_code'] == 0
    assert result['stdout'] == b'binary data\n'

    result = run(profile.name, 'cat', stdin='utf8 данные\n')

    assert result['exit_code'] == 0
    assert result['stdout'] == 'utf8 данные\n'.encode()
Exemplo n.º 4
0
def test_run_memory_limit(profile):
    result = run(profile.name, 'python3 -c "[1] * 10 ** 8"',
                 limits={'cputime': 10, 'memory': 8})

    assert result['oom_killed'] is True
    assert result['timeout'] is False
    assert result['exit_code'] not in [None, 0]
Exemplo n.º 5
0
def test_run_upload_files(profile):
    files = [
        {'name': 'main.py', 'content': b'print(open("file.txt").read())'},
        {'name': 'file.txt', 'content': b'Data in file.txt'},
    ]

    result = run(profile.name, 'python3 main.py', files=files)

    assert result['exit_code'] == 0
    assert result['stdout'] == b'Data in file.txt\n'
Exemplo n.º 6
0
def test_run_cpu_timeout(profile):
    start_time = time.time()

    result = run(profile.name, 'cat /dev/urandom > /dev/null',
                 limits={'cputime': 1, 'realtime': 10})

    assert result['timeout'] is True
    assert result['exit_code'] is not None
    assert b'Killed' in result['stderr']
    realtime_duration = time.time() - start_time
    assert realtime_duration < 10
Exemplo n.º 7
0
def test_run_python(profile):
    command = ('python3 -c \'import sys; '
               'print("stdout data"); print("stderr data", file=sys.stderr)\'')
    result = run(profile.name, command)

    expected_result = {
        'exit_code': 0,
        'stdout': b'stdout data\n',
        'stderr': b'stderr data\n',
        'duration': ANY,
        'timeout': False,
        'oom_killed': False,
    }
    assert result == expected_result
    assert result['duration'] > 0
Exemplo n.º 8
0
def test_run_fork_limit(profile):
    result = run(profile.name, 'ls &', limits={'cputime': 30})

    assert result['exit_code']
    assert b'fork: retry: No child processes' in result['stderr']
Exemplo n.º 9
0
def test_run_read_only_file_system(profile_read_only):
    result = run(profile_read_only.name, 'touch /tmp/file')

    assert result['exit_code'] not in [None, 0]
    assert b'Read-only file system' in result['stderr']
Exemplo n.º 10
0
def test_run_real_timeout(profile):
    result = run(profile.name, 'sleep 100', limits={'realtime': 1})

    assert result['timeout'] is True
    assert result['exit_code'] is None
Exemplo n.º 11
0
def test_run_profile_command(profile):
    result = run(profile.name)

    assert result['exit_code'] == 0
    assert result['stdout'] == b'profile stdout\n'
Exemplo n.º 12
0
def test_run_non_zero_exit(profile):
    result = run(profile.name, 'false')

    assert result['exit_code'] == 1
Exemplo n.º 13
0
def test_run_invalid_workdir(profile):
    with pytest.raises(ValueError) as excinfo:
        run(profile.name, 'true', workdir='dir')

    assert "working_directory" in str(excinfo.value)
Exemplo n.º 14
0
def test_run_unknown_profile():
    with pytest.raises(ValueError):
        run('unknown', 'true')