; ------------------------------------------------------------------------------ ; tests ; ------------------------------------------------------------------------------ ; ------------------------------------------------------------------------------ ; run_tests ; ; description: ; runs all tests ; ------------------------------------------------------------------------------ run_tests: mov rsi, .msg call print.test call test_completeness call clear_test_arena call test_djb2 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_opcode call clear_test_arena call test_get_reg_bits call clear_test_arena call test_evaluate_constant call clear_test_arena call test_identify_register call clear_test_arena call test_identify_operator call clear_test_arena call test_evaluate_operand ret .msg db "running test suite...", 0x0A, 0x00 ; ------------------------------------------------------------------------------ ; test_completeness ; ; description: ; visual confirmation of binary integrity ; ------------------------------------------------------------------------------ test_completeness: mov rsi, .msg call print.test mov rsi, .msg_content call print mov rsi, msg_end call print mov rsi, .msg_confirm call print ret .msg db "test_completeness...", 0x0A, 0x00 .msg_content db " here is the ", 0x00 .msg_confirm db " here is the end of the binary ->|", 0x0A, " assert: the previous 2 lines are identical", 0x0A, 0x00 ; ------------------------------------------------------------------------------ ; test_elemb ; ; description: ; tests elemb described functionality ; ------------------------------------------------------------------------------ test_elemb: mov rsi, .msg call print.test ; [0] mov rdi, 5 mov rsi, .case1 mov dl, [.case1] call elemb cmp al, 1 jne .fail ; [n - 1] mov rdi, 5 mov rsi, .case1 mov dl, [.case1 + 4] call elemb cmp al, 1 jne .fail ; [1] mov rdi, 5 mov rsi, .case1 mov dl, [.case1 + 1] call elemb cmp al, 1 jne .fail ; not present mov rdi, 5 mov rsi, .case1 mov dl, 0xDA call elemb cmp al, 0 jne .fail ; 0 length list mov rdi, 0 mov rsi, .case0 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 .case0: ; [This Page Intentionally Left Blank] .case1 db 0x54, 0x00, 0x21, 0x20, 0x34 .msg db "test_elemb...", 0x00 ; ------------------------------------------------------------------------------ ; test_djb2 ; ; description: ; tests djb2 described functionality ; ------------------------------------------------------------------------------ test_djb2: mov rsi, .msg call print.test mov rsi, .case0 mov rdi, 0 call djb2 cmp rax, 5381 jne .fail mov rsi, .case1 mov rdi, 1 call djb2 cmp rax, 177670 jne .fail mov rsi, .case2 mov rdi, 2 call djb2 cmp rax, 5863208 jne .fail ; why am I testing this, of course it's without side effects xD mov rsi, .case0 mov rdi, 0 call djb2 cmp rax, 5381 jne .fail mov rsi, .case1 mov rdi, 1 call djb2 cmp rax, 177670 jne .fail mov rsi, .case2 mov rdi, 2 call djb2 cmp rax, 5863208 jne .fail .pass: mov rsi, msg_pass call print ret .fail: mov rsi, msg_fail call print ret .case0 db "" .case1 db "a" .case2 db "ab" .msg db "test_djb2...", 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, 0x004F ; hlt call get_tte_typed_metadata cmp al, 0x00 ; # 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_opcode ; ; description: ; tests get_opcode described functionality ; ------------------------------------------------------------------------------ test_get_opcode: mov rsi, .msg call print.test mov di, 0x0053 ; xor mov sil, 0 mov bl, 0 call get_opcode cmp al, 0x31 jne .fail cmp dl, 0q0 jne .fail mov di, 0x0053 ; xor mov sil, 1 mov bl, 0 call get_opcode cmp al, 0x33 jne .fail cmp dl, 0q0 jne .fail mov di, 0x0053 ; xor mov sil, 2 mov bl, 0 call get_opcode cmp al, 0x81 jne .fail cmp dl, 0q6 jne .fail mov di, 0x0053 ; xor mov sil, 3 mov bl, 0 call get_opcode cmp al, 0x83 jne .fail cmp dl, 0q6 jne .fail mov di, 0x0054 ; inc mov sil, 0 mov bl, 0 call get_opcode cmp al, 0xFF jne .fail cmp dl, 0q0 jne .fail mov di, 0x0055 ; dec mov sil, 0 mov bl, 0 call get_opcode cmp al, 0xFF jne .fail cmp dl, 0q1 jne .fail mov di, 0x004F ; hlt mov sil, 0 mov bl, 0 call get_opcode cmp al, 0xF4 jne .fail cmp dl, 0q0 jne .fail mov di, 0x0059 ; call mov sil, 0q0 mov bl, 0 call get_opcode cmp al, 0xFF jne .fail cmp dl, 0q2 jne .fail mov di, 0x0003 ; rdx (not an operator) mov sil, 0q0 mov bl, 0 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, .case0h ; addr of constant mov rsi, 8 ; length of constant call evaluate_constant cmp rax, [.case0h_solution] jne .fail cmp rdx, 0x00 jne .fail ; just chars mov rdi, .case1h ; addr of constant mov rsi, 8 ; length of constant call evaluate_constant cmp rax, [.case1h_solution] jne .fail cmp rdx, 0x00 jne .fail ; just chars mov rdi, .case2h ; addr of constant mov rsi, 12 ; length of constant call evaluate_constant cmp rax, [.case2h_solution] jne .fail cmp rdx, 0x00 jne .fail ; PI x mov rdi, .case3h ; addr of constant mov rsi, 18 ; length of constant call evaluate_constant cmp rax, [.case3h_solution] jne .fail cmp rdx, 0x00 jne .fail ; PI q mov rdi, .case0q mov rsi, 16 call evaluate_constant cmp rax, [.case0q_solution] jne .fail cmp rdx, 0x01 jne .fail ; PI b mov rdi, .case0b mov rsi, 66 call evaluate_constant cmp rax, [.case0b_solution] jne .fail cmp rdx, 0x02 jne .fail ; char mov rdi, .case0c mov rsi, 6 call evaluate_constant cmp rax, [.case0c_solution] jne .fail cmp rdx, 0x03 jne .fail .pass: mov rsi, msg_pass call print ret .fail: mov rsi, msg_fail call print ret .msg db "test_evaluate_constant...", 0x00 .case0h db "0x012390" .case0h_solution dq 0x012390 .case1h db "0xABCDEF" .case1h_solution dq 0xABCDEF .case2h db "0x1234567890" .case2h_solution dq 0x1234567890 .case3h db "0x243F6A8885A308D3" .case3h_solution dq 0x243F6A8885A308D3 .case0c db '"char"' .case0c_solution dq "char" .case1c db '"chars"' .case1c_solution dq "chars" ; " wow my editor really doesn't like highlighting quotes correctly .case0q db "0q31103755242102" .case0q_solution dq 0q31103755242102 .case0b db "0b0110011001101001011100100111001101110100001000000011011000110100" .case0b_solution dq 0b0110011001101001011100100111001101110100001000000011011000110100 ; ------------------------------------------------------------------------------ ; test_identify_register ; ; description: ; tests identify_register described funtionality ; ------------------------------------------------------------------------------ test_identify_register: mov rsi, .msg call print.test mov edi, "rcx" call identify_register cmp ax, 0x0002 jne .fail mov edi, "RaNd" call identify_register cmp ax, UNRECOGNISED_TOKEN_ID jne .fail mov edi, "" call identify_register cmp ax, UNRECOGNISED_TOKEN_ID jne .fail .pass: mov rsi, msg_pass call print ret .fail: mov rsi, msg_fail call print ret .msg db "test_identify_register...", 0x00 ; ------------------------------------------------------------------------------ ; test_identify_operator ; ; description: ; tests identify_operator described funtionality ; ------------------------------------------------------------------------------ test_identify_operator: mov rsi, .msg call print.test mov edi, "xor" call identify_operator cmp ax, 0x0053 jne .fail mov edi, [tokens.operators_end] call identify_operator cmp ax, UNRECOGNISED_TOKEN_ID jne .fail mov edi, "RaNd" call identify_operator cmp ax, UNRECOGNISED_TOKEN_ID jne .fail mov edi, "" call identify_operator cmp ax, UNRECOGNISED_TOKEN_ID jne .fail .pass: mov rsi, msg_pass call print ret .fail: mov rsi, msg_fail call print ret .msg db "test_identify_operator...", 0x00 ; ------------------------------------------------------------------------------ ; test_evaluate_operand ; ; description: ; tests evaluate_operand described funtionality ; ------------------------------------------------------------------------------ test_evaluate_operand: mov rsi, .msg call print.test mov rdi, .case0 mov rsi, 3 call evaluate_operand cmp dl, 0x00 jne .fail cmp ax, 0x0000 jne .fail mov rdi, .case1 mov rsi, 0 call evaluate_operand cmp dl, 0xFF jne .fail mov rdi, .case2 mov rsi, 3 call evaluate_operand cmp dl, 0x00 jne .fail cmp ax, 0x0003 jne .fail mov rdi, .case3 mov rsi, 5 call evaluate_operand cmp dl, 0x10 jne .fail cmp ax, 0x0003 jne .fail .pass: mov rsi, msg_pass call print ret .fail: mov rsi, msg_fail call print ret .case0 db "rax" .case1: ; intentionally blank .case2 db "rdx" .case3 db "[rdx]" .msg db "test_evaluate_operand...", 0x00 msg_pass: db 0x0A times (TEST_LINE_LENGTH + .start - .end) db " ", ; right align db 0x1B, "[32m" .start db "passed." .end db 0x1B, "[0m", 0x0A, 0x00 msg_fail: db 0x0A times (TEST_LINE_LENGTH + .start - .end) db " ", db 0x1B, "[31m" .start db "failed." .end db 0x1B, "[0m", 0x0A, 0x00