Files
bootler/twasm/asm/tests.asm

387 lines
8.0 KiB
NASM

; ------------------------------------------------------------------------------
; tests
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
; run_tests
;
; description:
; runs all tests
; ------------------------------------------------------------------------------
run_tests:
mov rsi, .msg
call print.test
call clear_test_arena
call test_elemb
call clear_test_arena
call test_get_tte_type
call clear_test_arena
call test_get_tte_typed_metadata
call clear_test_arena
call test_get_direct_addressing_ModRM
call clear_test_arena
call test_get_opcode
call clear_test_arena
call test_get_reg_bits
call clear_test_arena
call test_evaluate_constant
ret
.msg db "running test suite...", 0x0A, 0x00
; ------------------------------------------------------------------------------
; test_elemb
;
; description:
; tests elemb described functionality
; ------------------------------------------------------------------------------
test_elemb:
mov rsi, .msg
call print.test
; [0]
mov rdi, 5
mov rsi, test_elemb_5
mov dl, [test_elemb_5]
call elemb
cmp al, 1
jne .fail
; [n - 1]
mov rdi, 5
mov rsi, test_elemb_5
mov dl, [test_elemb_5 + 4]
call elemb
cmp al, 1
jne .fail
; [1]
mov rdi, 5
mov rsi, test_elemb_5
mov dl, [test_elemb_5 + 1]
call elemb
cmp al, 1
jne .fail
; not present
mov rdi, 5
mov rsi, test_elemb_5
mov dl, 0xDA
call elemb
cmp al, 0
jne .fail
; 0 length list
mov rdi, 0
mov rsi, test_elemb_0
mov dl, 0x34
call elemb
cmp al, 0
jne .fail
.pass:
mov rsi, msg_pass
call print
ret
.fail:
mov rsi, msg_fail
call print
ret
.msg db "test_elemb...", 0x00
; ------------------------------------------------------------------------------
; test_get_tte_type
;
; description:
; tests get_tte_type described functionality
; ------------------------------------------------------------------------------
test_get_tte_type:
mov rsi, .msg
call print.test
mov di, 0x0053 ; xor
call get_tte_type
cmp al, 0x01 ; operator
jne .fail
mov di, 0x0003 ; rdx
call get_tte_type
cmp al, 0x02 ; register
jne .fail
mov di, 0x0056 ; mov
call get_tte_type
cmp al, 0x01 ; operator
jne .fail
mov di, 0xFFFF ; unrecognised token
call get_tte_type
cmp al, UNRECOGNISED_ID_TYPE
jne .fail
.pass:
mov rsi, msg_pass
call print
ret
.fail:
mov rsi, msg_fail
call print
ret
.msg db "test_get_tte_type...", 0x00
; ------------------------------------------------------------------------------
; test_get_tte_typed_metadata
;
; description:
; tests get_tte_typed_metadata described functionality
; ------------------------------------------------------------------------------
test_get_tte_typed_metadata:
mov rsi, .msg
call print.test
mov di, 0x0053 ; xor
call get_tte_typed_metadata
cmp al, 0x02 ; # operands
jne .fail
mov di, 0x0003 ; rdx
call get_tte_typed_metadata
cmp al, 00001011b ; reg: 010b
; width: 11b (64 bits)
jne .fail
mov di, 0x0056 ; mov
call get_tte_typed_metadata
cmp al, 0x02 ; # operands
jne .fail
mov di, 0xFFFF ; unrecognised token
call get_tte_typed_metadata
cmp al, UNRECOGNISED_ID_METADATA
jne .fail
.pass:
mov rsi, msg_pass
call print
ret
.fail:
mov rsi, msg_fail
call print
ret
.msg db "test_get_tte_typed_metadata...", 0x00
; ------------------------------------------------------------------------------
; test_get_direct_addressing_ModRM
;
; description:
; tests get_direct_addressing_ModRM described functionality
; ------------------------------------------------------------------------------
test_get_direct_addressing_ModRM:
mov rsi, .msg
call print.test
mov di, 0x0000 ; rax
mov si, 0x0000 ; rax
call get_direct_addressing_ModRM
cmp al, 11000000b ; Mod Reg R/M: 11b 000b 000b
jne .fail
mov di, 0x0000 ; rax
mov si, 0x0003 ; rdx
call get_direct_addressing_ModRM
cmp al, 11000010b ; Mod Reg R/M: 11b 000b 010b
jne .fail
mov di, 0x0003 ; rdx
mov si, 0x0000 ; rax
call get_direct_addressing_ModRM
cmp al, 11010000b ; Mod Reg R/M: 11b 010b 000b
jne .fail
mov di, 0x0003 ; rdx
mov si, 0x0003 ; rdx
call get_direct_addressing_ModRM
cmp al, 11010010b ; Mod Reg R/M 11b 010b 010b
jne .fail
.pass:
mov rsi, msg_pass
call print
ret
.fail:
mov rsi, msg_fail
call print
ret
.msg db "test_get_direct_addressing_ModRM...", 0x00
; ------------------------------------------------------------------------------
; test_get_opcode
;
; description:
; tests get_opcode described functionality
; ------------------------------------------------------------------------------
test_get_opcode:
mov rsi, .msg
call print.test
mov di, 0x0053 ; xor
call get_opcode
cmp al, 0x31
jne .fail
mov di, 0x0054 ; inc
call get_opcode
cmp al, 0xFF
jne .fail
mov di, 0x004F ; hlt
call get_opcode
cmp al, 0xF4
jne .fail
mov di, 0x0003 ; rdx (not an operator)
call get_opcode
cmp al, UNRECOGNISED_ID_OPCODE
jne .fail
.pass:
mov rsi, msg_pass
call print
ret
.fail:
mov rsi, msg_fail
call print
ret
.msg db "test_get_opcode...", 0x00
; ------------------------------------------------------------------------------
; test_get_reg_bits
;
; description:
; tests get_reg_bits described functionality
; ------------------------------------------------------------------------------
test_get_reg_bits:
mov rsi, .msg
call print.test
mov di, 0x0000 ; rax
call get_reg_bits
cmp al, 000b
jne .fail
mov di, 0x0010 ; eax
call get_reg_bits
cmp al, 000b
jne .fail
mov di, 0x0003 ; rdx
call get_reg_bits
cmp al, 010b
jne .fail
.pass:
mov rsi, msg_pass
call print
ret
.fail:
mov rsi, msg_fail
call print
ret
.msg db "test_get_reg_bits...", 0x00
; ------------------------------------------------------------------------------
; test_evaluate_constant
;
; description:
; tests evaluate_constant described funtionality
; ------------------------------------------------------------------------------
test_evaluate_constant:
mov rsi, .msg
call print.test
; just numerals
mov rdi, .case0 ; addr of constant
mov rsi, 8 ; length of constant
call evaluate_constant
cmp rax, [.case0_solution]
jne .fail
cmp rdx, 0x00
jne .fail
; just chars
mov rdi, .case1 ; addr of constant
mov rsi, 8 ; length of constant
call evaluate_constant
cmp rax, [.case1_solution]
jne .fail
cmp rdx, 0x00
jne .fail
; just chars
mov rdi, .case2 ; addr of constant
mov rsi, 12 ; length of constant
call evaluate_constant
cmp rax, [.case2_solution]
jne .fail
cmp rdx, 0x00
jne .fail
; PI
mov rdi, .case3 ; addr of constant
mov rsi, 18 ; length of constant
call evaluate_constant
cmp rax, [.case3_solution]
jne .fail
cmp rdx, 0x00
jne .fail
.pass:
mov rsi, msg_pass
call print
ret
.fail:
mov rsi, msg_fail
call print
ret
.msg db "test_evaluate_constant...", 0x00
.case0 db "0x012390"
.case0_solution dq 0x012390
.case1 db "0xABCDEF"
.case1_solution dq 0xABCDEF
.case2 db "0x1234567890"
.case2_solution dq 0x1234567890
.case3 db "0x243F6A8885A308D3"
.case3_solution dq 0x243F6A8885A308D3
msg_pass:
db 0x0A
times (TEST_LINE_LENGTH + .start - .end) db " ", ; right align
.start db "passed."
.end db 0x0A, 0x00
msg_fail:
db 0x0A
times (TEST_LINE_LENGTH + .start - .end) db " ",
.start db "failed."
.end db 0x0A, 0x00
test_byte db "Q" ; unterminated, just a byte chillin
test_token_null db "TestTokn", 0x00 ; followed by null terminator. Quad word
test_token_space db "TestTokn " ; followed by space. Quad word
test_elemb_0: ; [This Page Intentionally Left Blank]
test_elemb_5 db 0x54, 0x00, 0x21, 0x20, 0x34