| 1 |
import pytest |
| 2 |
from shared_vars import * |
| 3 |
|
| 4 |
@pytest.mark.parametrize('filename', FILENAMES) |
| 5 |
def test_disasm(filename: str, errns: SimpleNamespace): |
| 6 |
maybe_skip(filename) |
| 7 |
input_file = BPF_DIR / f'{filename}.bpf' |
| 8 |
expect_file = TXT_DIR / filename |
| 9 |
_, stdout, stderr = run_process( |
| 10 |
[CECCOMP, 'disasm', *COMMON_OPTS, str(input_file)], |
| 11 |
) |
| 12 |
errns.stderr = stderr |
| 13 |
|
| 14 |
with expect_file.open('r') as expect: |
| 15 |
assert stdout == expect.read() |
| 16 |
|
| 17 |
def test_s390x_disasm(errns: SimpleNamespace): |
| 18 |
input_file = BE_DIR / 's390x.bpf' |
| 19 |
expect_file = BE_DIR / 's390x.disasm' |
| 20 |
_, stdout, stderr = run_process( |
| 21 |
[CECCOMP, 'disasm', str(input_file), '-a', 's390x'], |
| 22 |
) |
| 23 |
errns.stderr = stderr |
| 24 |
|
| 25 |
with expect_file.open() as expect: |
| 26 |
assert stdout == expect.read() |
| 27 |
|
| 28 |
ERROR_IDS = sorted([p.stem[1:] for p in ERR_CASE_DIR.glob('b*')]) |
| 29 |
|
| 30 |
@pytest.mark.parametrize('errorid', ERROR_IDS) |
| 31 |
def test_error_cases(errorid: str): |
| 32 |
chunk_file = ERR_CASE_DIR / f'b{errorid}' |
| 33 |
with chunk_file.open() as f: |
| 34 |
blob = f.read() |
| 35 |
in_idx = blob.find('STDIN') |
| 36 |
out_idx = blob.find('STDOUT') |
| 37 |
err_idx = blob.find('STDERR') |
| 38 |
assert in_idx != -1 and err_idx != -1 |
| 39 |
|
| 40 |
stdin = bytes.fromhex(blob[in_idx + 6 : err_idx]) |
| 41 |
_, stdout, stderr = run_process( |
| 42 |
[CECCOMP, 'disasm', '-', '-a', 'x86_64'], stdin=stdin, is_binary=True, |
| 43 |
) |
| 44 |
if out_idx == -1: |
| 45 |
assert stderr.decode() == blob[err_idx + 7:] |
| 46 |
else: |
| 47 |
assert stderr.decode() == blob[err_idx + 7 : out_idx] |
| 48 |
assert stdout.decode() == blob[out_idx + 7:] |