Add more tests for add and addi
This commit is contained in:
@@ -37,8 +37,9 @@ def instr_r(opcode, reg1, reg2):
|
||||
return bytes([opcode, reg1, 0, 0, reg2, 0, 0, 0])
|
||||
|
||||
|
||||
def exec_program(program: bytes) -> int | None:
|
||||
context.log_level = 'debug'
|
||||
def exec_program(program: bytes, debug: bool = False) -> int | None:
|
||||
if debug:
|
||||
context.log_level = 'debug'
|
||||
with remote("localhost", 1337, fam="ipv4") as p:
|
||||
p.recvuntil(b"Password: ", timeout=1)
|
||||
p.sendline(b"1234")
|
||||
|
||||
@@ -10,6 +10,25 @@ class BasicInstructionTest(unittest.TestCase):
|
||||
self.assertIsNotNone(exit_code, "Connection timeout!")
|
||||
self.assertEqual(exit_code, val & 0xFF, "Computed the wrong result!")
|
||||
|
||||
def test_multiple_addi(self):
|
||||
for vals in [[0] * 16, [1] * 8, [0x50] * 256, [0x543210] * 7, [0x6543210] * 5,
|
||||
[0x1337, 0x69, 0x42, 0x420, 0xbeef]]:
|
||||
program = b''
|
||||
val_sum = sum(vals)
|
||||
for val in vals:
|
||||
program += instr_i(Opcode.ADDI, Register.A, val)
|
||||
exit_code = exec_program(program)
|
||||
self.assertIsNotNone(exit_code, "Connection timeout!")
|
||||
self.assertEqual(exit_code, val_sum & 0xFF, "Computed the wrong result!")
|
||||
|
||||
def test_add(self):
|
||||
for val1, val2 in [(0, 0), (5, 8), (0xFFFFFFFF, 0xFFFFFFFF), (0xFFFFFFFF, 1)]:
|
||||
program = instr_i(Opcode.ADDI, Register.A, val1) + instr_i(Opcode.ADDI, Register.B, val2) + instr_r(
|
||||
Opcode.ADD, Register.A, Register.B)
|
||||
exit_code = exec_program(program)
|
||||
self.assertIsNotNone(exit_code, "Connection timeout!")
|
||||
self.assertEqual(exit_code, (val1 + val2) & 0xFF, "Computed the wrong result!")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user