| 1 |
# Copyright 2025 Valve Corporation |
| 2 |
# SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
import sys |
| 5 |
import os |
| 6 |
import textwrap |
| 7 |
import binascii |
| 8 |
from test.disasm import disasm |
| 9 |
|
| 10 |
errors = False |
| 11 |
new_cases = [] |
| 12 |
|
| 13 |
for case in open(sys.argv[1]).read().strip().split('\n'): |
| 14 |
first = case.split(' ')[0] |
| 15 |
ref = case[len(first):].strip() |
| 16 |
|
| 17 |
# Extract bytes |
| 18 |
lst = [int(x, 16) for x in textwrap.wrap(first, 2)] |
| 19 |
|
| 20 |
# Make sure we don't depend on zeroes in upper bits |
| 21 |
padded = lst + [0xCA, 0xFE, 0xBA, 0xBE] * 16 |
| 22 |
raw = sum([x << (8 * i) for i, x in enumerate(padded)]) |
| 23 |
|
| 24 |
error = False |
| 25 |
length, asm = disasm(raw) |
| 26 |
error |= (length != len(lst)) |
| 27 |
|
| 28 |
actual = f'{str(binascii.hexlify(bytes(lst)).decode()):<20} {asm}\n' |
| 29 |
new_cases.append(actual) |
| 30 |
error |= (actual[:-1] != case) |
| 31 |
|
| 32 |
if error: |
| 33 |
print(case) |
| 34 |
print(actual) |
| 35 |
errors |= error |
| 36 |
|
| 37 |
# If there were errors, optionally update expectations. |
| 38 |
if len(sys.argv) >= 3: |
| 39 |
assert(sys.argv[2] in ['-u', '--update']) |
| 40 |
open(sys.argv[1], 'w').write(''.join(new_cases)) |
| 41 |
|
| 42 |
if errors: |
| 43 |
print('Fail.') |
| 44 |
sys.exit(1) |
| 45 |
else: |
| 46 |
print('Pass.') |