| 1 |
import pytest |
| 2 |
from shared_vars import * |
| 3 |
|
| 4 |
@pytest.mark.parametrize('filename', FILENAMES) |
| 5 |
def test_asm(filename: str, errns: SimpleNamespace): |
| 6 |
maybe_skip(filename) |
| 7 |
input_file = TXT_DIR / filename |
| 8 |
expect_file = BPF_DIR / f'{filename}.bpf' |
| 9 |
_, stdout, stderr = run_process( |
| 10 |
[CECCOMP, 'asm', *COMMON_OPTS, '-f', 'raw', str(input_file)], True, |
| 11 |
) |
| 12 |
errns.stderr = stderr.decode() |
| 13 |
|
| 14 |
with expect_file.open('rb') as expect: |
| 15 |
assert filter2text(stdout) == filter2text(expect.read()) |
| 16 |
|
| 17 |
def test_s390x_asm(errns: SimpleNamespace): |
| 18 |
input_file = BE_DIR / 's390x.text' |
| 19 |
expect_file = BE_DIR / 's390x.hexfmt' |
| 20 |
_, stdout, stderr = run_process( |
| 21 |
[CECCOMP, 'asm', '-f', 'hexfmt', 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('a*')]) |
| 29 |
|
| 30 |
@pytest.mark.parametrize('errorid', ERROR_IDS) |
| 31 |
def test_error_cases(errorid: str): |
| 32 |
chunk_file = ERR_CASE_DIR / f'a{errorid}' |
| 33 |
with chunk_file.open() as f: |
| 34 |
blob = f.read() |
| 35 |
in_idx = blob.find('STDIN') |
| 36 |
err_idx = blob.find('STDERR') |
| 37 |
assert in_idx != -1 and err_idx != -1 |
| 38 |
|
| 39 |
stdin = blob[in_idx + 6 : err_idx] |
| 40 |
_, _, stderr = run_process( |
| 41 |
# error case for asm will not print to stdout, |
| 42 |
# so no need to specify arch |
| 43 |
[CECCOMP, 'asm', '-'], stdin=stdin, |
| 44 |
) |
| 45 |
assert stderr == blob[err_idx + 7:] |