Refactor tests to use data structs

Rather than a pointer to the end of the parseable string, we now store
the number of bytes we expect to be parsed. Current code allows for 11
bytes of string data which should suffice for most usecases.
This commit is contained in:
PleegWat
2026-09-03 11:34:01 +02:00
parent 9ff0a3192c
commit 2c6e025dff
+44 -117
View File
@@ -1,126 +1,53 @@
mov r1, 1 ; test harness for strint.atoi
mov r2, test1 ; Registers:
mov r3, test1_end ; r8 - test address
mov r13, test1_pass ; r9 - expected result
jmp atoi_test ; r10 - actual length
test1_pass: ; r11 - expected length
mov r8, tests
mov r1, 2 next_test:
mov r2, test2 ; Set up arguments and run test
mov r3, test2_end add r1, r8, 5 ; Start of test string
mov r13, test2_pass
jmp atoi_test
test2_pass:
mov r1, 3
mov r2, test3
mov r3, test3_end
mov r13, test3_pass
jmp atoi_test
test3_pass:
mov r1, 4
mov r2, test4
mov r3, test4_end
mov r13, test4_pass
jmp atoi_test
test4_pass:
mov r1, 5
mov r2, test5
mov r3, test5_end
mov r13, test5_pass
jmp atoi_test
test5_pass:
mov r1, 6
mov r2, test6
mov r3, test6_end
mov r13, test6_pass
jmp atoi_test
test6_pass:
mov r1, 7
mov r2, test7
mov r3, test7_end
mov r13, test7_pass
jmp atoi_test
test7_pass:
mov r1, 8
mov r2, test8
mov r3, test8_end
mov r13, test8_pass
jmp atoi_test
test8_pass:
mov r1, 9
mov r2, test9
mov r3, test9_end
mov r13, test9_pass
jmp atoi_test
test9_pass:
success:
jmp success
; test strint.atoi
; Arguments:
; r1 - test number
; r2 - test data label
; r3 - test end-of-string label
; Result:
; void. Hangs in failure: on failure.
; Clobbers:
; r8 - test number
; r9 - Expected result in r1
; r10 - Expected result in r2
; Notes:
; Depends on atoi not clobbering r8-r10.
atoi_test:
mov r8, r1
load_32 r9, [r2]
add r1, r2, 4
mov r10, r3
push r13
mov r13, atoi_test_ret mov r13, atoi_test_ret
jmp stdlib.strint.atoi jmp stdlib.strint.atoi
atoi_test_ret: atoi_test_ret:
pop r13
; Load reference data
load_32 r9, [r8] ; Expected result
sub r10, r2, r8
sub r10, r10, 5 ; Actual string length
add r11, r8, 4 ; Address of expected length
load_8 r11, [r11] ; Expected length
; Verify results
cmp r1, r9 cmp r1, r9
jne failure incorrect_result: jne incorrect_result
cmp r2, r10 cmp r10, r11
jne failure incorrect_length: jne incorrect_length
jmp r13
failure: ; Next test
jmp failure add r8, r8, 0x10
cmp r8, end_of_tests
jl next_test
test1: U32 0 "0" ; Done
test1_end: "\0" success: jmp success
test2: U32 1 "1"
test2_end: "\0"
test3: U32 2 "2"
test3_end: "\0"
test4: U32 42 "42"
test4_end: "\0"
test5: U32 67 "67"
test5_end: "lol\0"
test6: U32 1690 "0x69a"
test6_end: "\0"
test7: U32 19 "023"
test7_end: "9\0"
test8: U32 11 "0b1011"
test8_end: "\0"
test9: U32 17 "0b10001"
test9_end: "2\0"
include stdlib include stdlib
@0x1000
tests:
; addr result inlen instr
@0x1000 U32 0 U8 0 "\0"
@0x1010 U32 0 U8 1 "0\0"
@0x1020 U32 1 U8 1 "1\0"
@0x1030 U32 2 U8 1 "2\0"
@0x1040 U32 42 U8 2 "42\0"
@0x1050 U32 67 U8 2 "67lol\0"
@0x1060 U32 0x69a U8 5 "0x69a\0"
@0x1070 U32 0o23 U8 3 "0239\0"
@0x1080 U32 0b1011 U8 6 "0b1011\0"
@0x1090 U32 0b10001 U8 7 "0b100012\0"
end_of_tests: