84 lines
2.3 KiB
Python
Executable file
84 lines
2.3 KiB
Python
Executable file
#! /usr/bin/python3
|
|
|
|
from machine import PDP1170
|
|
import json
|
|
import sys
|
|
|
|
def return_true(a, b):
|
|
return True
|
|
|
|
def compare(v1, v2, what, test):
|
|
if v1 != v2:
|
|
print(f'Value mismatch for {what}: {v1:o} (is) should be {v2:o} (test: {test})')
|
|
return 1
|
|
return 0
|
|
|
|
file = sys.argv[1]
|
|
print(f'Loading json {file}...')
|
|
j = json.load(open(file))
|
|
|
|
print('Testing...')
|
|
total_n = 0
|
|
total_errors = 0
|
|
tests_with_errors = 0
|
|
for test in j:
|
|
p = PDP1170()
|
|
|
|
id_ = test['id']
|
|
|
|
# setup
|
|
before = test['before']
|
|
|
|
pc = int(before['PC'])
|
|
p.psw = int(before['PSW'])
|
|
p.stackpointers = [ int(before['stack-0']), int(before['stack-1']), int(before['stack-2']), int(before['stack-3']) ]
|
|
p.r[6] = p.stackpointers[0]
|
|
|
|
for kv in before['memory']:
|
|
for k in kv:
|
|
a = int(k, 8)
|
|
clean_a = a & (~1)
|
|
v_work = p.physRW(clean_a)
|
|
if a & 1:
|
|
v_work = (v_work & 0xff00) | int(kv[k])
|
|
else:
|
|
v_work = (v_work & 0x00ff) | (int(kv[k]) << 8)
|
|
p.physRW(clean_a, value=v_work)
|
|
|
|
for reg in range(6):
|
|
p.r[reg] = int(before[f'reg-{reg}.0'])
|
|
p.r_alt[reg] = int(before[f'reg-{reg}.1'])
|
|
|
|
do_n_instructions = int(before['run-n-instructions'])
|
|
|
|
# do
|
|
for count in range(do_n_instructions):
|
|
p.run(pc=pc, breakpoint=return_true)
|
|
p._syncregs()
|
|
|
|
# verify
|
|
after = test['after']
|
|
now_errors = 0
|
|
now_errors += compare(p.r[7], after['PC'], 'PC', id_)
|
|
now_errors += compare(p.psw, after['PSW'], 'PSW', id_)
|
|
now_errors += compare(p.stackpointers[0], int(after['stack-0']), 'kernel stackpointer', id_)
|
|
|
|
for kv in after['memory']:
|
|
for k in kv:
|
|
a = int(k, 8)
|
|
v = p.physRW(a & (~1))
|
|
if a & 1:
|
|
v &= 0xff
|
|
else:
|
|
v >>= 8
|
|
now_errors += compare(v, int(kv[k]), f'memory {a:06o}', id_)
|
|
|
|
for reg in range(6):
|
|
now_errors += compare(p.r[reg], int(after[f'reg-{reg}.0']), f'register {reg}', id_)
|
|
now_errors += compare(p.r_alt[reg], int(after[f'reg-{reg}.1']), f'alt register {reg}', id_)
|
|
|
|
total_errors += now_errors
|
|
tests_with_errors += 1 if now_errors > 0 else 0
|
|
total_n += 1
|
|
|
|
print(f'Done with {total_errors} total errors over {tests_with_errors} failed tests in {total_n} tests')
|