From ad559062efcccbdf1fb4c464b2470f704bb00e66 Mon Sep 17 00:00:00 2001 From: Kwarde Date: Mon, 21 Jul 2025 15:33:54 +0200 Subject: [PATCH] Start rewriting tests --- src/tests.asm | 1304 +++++++++---------------------------------------- 1 file changed, 230 insertions(+), 1074 deletions(-) diff --git a/src/tests.asm b/src/tests.asm index 3ef7c16..64787cf 100644 --- a/src/tests.asm +++ b/src/tests.asm @@ -1,6 +1,38 @@ %include "src/constants.asm" -; core.asm +;addTestHeader(var, func) +%define addTestHeader(var, func) \ + var db NL,"TEST ",func,"()",NL,EOS +;addTest(var, msg) +%define addTest(var, msg) \ + var db TAB,msg,":",NL,EOS +;printTestHeader var +%macro printTestHeader 1 + lea rdi, [rel %1] + call print +%endmacro +;printTest var +%macro printTest 1 + lea rdi, [rel %1] + call printf +%endmacro +;assert value, jmp instruction, testMsg_X +%macro assert 3 + inc r13 + mov rsi, %1 + cmp rax, %1 + %2 %%true + lea rdx, [rel testMsg_False] + jmp %%cnt + %%true: + inc r14 + lea rdx, [rel testMsg_True] + %%cnt: + lea rdi, [rel %3] + call printf +%endmacro + +;core.asm extern exit extern islower extern isupper @@ -12,1129 +44,253 @@ extern max extern maxu extern clamp extern clampu -; console.asm +;console.asm extern print extern puts extern printf -; string.asm +;string.asm extern strlen extern strcpy extern strcat extern strclr extern strcmp -; convert.asm +;convert.asm +extern atoi extern itoa extern utoa -extern atoi section .rodata - TEST_print equ 1 - TEST_puts equ 1 - TEST_itoa equ 1 ;includes utoa - TEST_printf equ 1 - TEST_strlen equ 1 - TEST_strcpy equ 1 - TEST_strcat equ 1 - TEST_strclr equ 1 + ;;; + ;;; enable/disable tests + ;;; + ;core.asm TEST_islower equ 1 TEST_isupper equ 1 TEST_tolower equ 1 TEST_toupper equ 1 + TEST_min equ 1 + TEST_minu equ 1 + TEST_max equ 1 + TEST_maxu equ 1 + TEST_clamp equ 1 + TEST_clampu equ 1 + ;console.asm + TEST_print equ 1 + TEST_puts equ 1 + TEST_printf equ 1 + ;string.asm_ + TEST_strlen equ 1 + TEST_strcpy equ 1 + TEST_strcat equ 1 + TEST_strclr equ 1 TEST_strcmp equ 1 - TEST_min equ 1 ;includes minu - TEST_max equ 1 ;includes maxu - TEST_clamp equ 1 ;includes clampu + ;convert.asm TEST_atoi equ 1 + TEST_itoa equ 1 + TEST_utoa equ 1 - str1 db "Hello, world!",EOS - str2 db "Hello, World!",EOS - str3 db "Hello world!",EOS - str4 db "Howdy environment!",EOS - str5 db "The quick brown fox jumps over the lazy dog",EOS - msgStrings db "PRINT str1-5:",NL,"str1: %s",NL,"str2: %s",NL,"str3: %s",NL,"str4: %s",NL,"str5: %s",NL,EOS + ;;; + ;;; Global test messages + ;;; + testMsg_assertIEqual db "\t\tassert(output == %d): %s",NL,EOS + testMsg_assertINEqual db "\t\tassert(output != %d): %s",NL,EOS + testMsg_assertILess db "\t\tassert(output < %d): %s",NL,EOS + testMsg_assertILessE db "\t\tassert(output <= %d): %s",NL,EOS + testMsg_assertIMore db "\t\tassert(output > %d): %s",NL,EOS + testMsg_assertIMoreE db "\t\tassert(output >= %d): %s",NL,EOS + testMsg_assertUEqual db "\t\tassert(output == %u): %s",NL,EOS + testMsg_assertUNEqual db "\t\tassert(output != %u): %s",NL,EOS + testMsg_assertULess db "\t\tassert(output < %u): %s",NL,EOS + testMsg_assertULessE db "\t\tassert(output <= %u): %s",NL,EOS + testMsg_assertUMore db "\t\tassert(output > %u): %s",NL,EOS + testMsg_assertUMoreE db "\t\tassert(output >= %u): %s",NL,EOS + testMsg_False db "FALSE",EOS + testMsg_True db "true",EOS + testMsg_Results db "\n*** Test Results ***\n* Total tests:\t\t%d\n* Succeeded tests:\t%d\n* Failed tests:\t\t%d\n",EOS - ; print() - msgPrint db NL,"TEST print()",NL,EOS + ;;; + ;;; Specific test data + ;;; + ;islower() + addTestHeader(_islower, "islower") + addTest(islower_d, "islower('d')") + addTest(islower_D, "islower('D')") + addTest(islower_em, "islower('!')") + ;isupper() + addTestHeader(_isupper, "isupper") + addTest(isupper_d, "isupper('d')") + addTest(isupper_D, "isupper('D')") + addTest(isupper_em, "isupper('!')") + ;tolower() + addTestHeader(_tolower, "tolower") + addTest(tolower_d, "tolower('d')") + addTest(tolower_D, "tolower('D')") + addTest(tolower_em, "tolower('em')") + addTest(tolower_cb, "tolower('}')") + ;toupper() + addTestHeader(_toupper, "toupper") + addTest(toupper_d, "toupper('d')") + addTest(toupper_D, "toupper('D')") + addTest(toupper_em, "toupper('em')") + addTest(toupper_cb, "toupper('}')") + ;min() + addTestHeader(_min, "min") + addTest(min1, "min(-1337, 1337)") + addTest(min2, "min(MIN_INT64, MAX_INT64)") + addTest(min3, "min(MIN_UINT64, MAX_UINT64)") + addTest(min4, "min(-1, 0)") + addTest(min5, "min(MIN_UINT64, MIN_INT8)") - ; puts() - msgPuts db NL,"TEST puts()",EOS - - ; itoa() / utoa9) - msgItoa db NL,"TEST itoa() / utoa()",NL,TAB,"See printf outputs",NL,EOS - - ; printf() - msgPrintf db NL,"TEST printf()",NL,EOS - printf1 db TAB,"printf(",DQUO,"He%ll%0 there%v%%%%!%!%\n",DQUO,"): ",NL,TAB,TAB,EOS - printf1Str db "He%ll%0 there%v%%%%!%!%\n",EOS - printf2 db TAB,"printf(",DQUO,"Are %s doing %s?\n",DQUO,", printf2Str1, printf2Str2): ",NL,TAB,TAB,EOS - printf2Str db "Are %s doing %s?\n",EOS - printf2Str1 db "you",EOS - printf2Str2 db "okay",EOS - printf3 db TAB,"printf(",DQUO,"%c%c%c%c%c there %c%c %s%c\n",DQUO,", 'H', 'e', 'l', 'l', 'o', 'm', 'y', ",DQUO,"friend",DQUO,", '!'): ",NL,TAB,TAB,EOS - printf3Str db "%c%c%c%c%c there %c%c %s%c\n",EOS - printf3C1 equ 'H' - printf3C2 equ 'e' - printf3C3 equ 'l' - printf3C4 equ 'l' - printf3C5 equ 'o' - printf3C6 equ 'm' - printf3C7 equ 'y' - printf3Str1 db "friend",EOS - printf3C8 equ '!' - printf4 db TAB,"printf(",DQUO,"%i|%d|%u , %i|%d|%u\n",DQUO,", -50, -50, -50, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF): ",NL,TAB,TAB,EOS - printf4Str db "%i|%d|%u , %i|%d|%u\n",EOS - printf5 db TAB,"printf(",DQUO,"%x|%X , %x|%X\n",DQUO,", 0xabcdeffedcba, 0x069bc0e, 666, -1): ",NL,TAB,TAB,EOS - printf5Str db "%x|%X , %x|%X\n",EOS - printf6 db TAB,"printf(",DQUO,"%b | %8b | %08b\n",DQUO,", 5, 7, 9): ",NL,TAB,TAB,EOS - printf6Str db "%b | %8b | %08b\n",EOS - printf7 db TAB,"printf(",DQUO,"%d | %8d | %08d\n",DQUO,", -234, -666, 234): ",NL,TAB,TAB,EOS - printf7Str db "%d | %8d | %08d\n",EOS - printf8 db TAB,"printf(",DQUO,"%i | %8i | %08i\n",DQUO,", -234, -666, 234): ",NL,TAB,TAB,EOS - printf8Str db "%i | %8i | %08i\n",EOS - printf9 db TAB,"printf(",DQUO,"%u | %8u | %08u\n",DQUO,", -234, -666, 234): ",NL,TAB,TAB,EOS - printf9Str db "%u | %8u | %08u\n",EOS - printf10 db TAB,"printf(",DQUO,"%x | %8x | %08x\n",DQUO,", 0xAB0F, 0xBA0F, 0xAB0F): ",NL,TAB,TAB,EOS - printf10Str db "%x | %8x | %08x\n",EOS - printf11 db TAB,"printf(",DQUO,"%X | %8X | %08X\n",DQUO,", 0xAB0F, 0xBA0F, 0xAB0F): ",NL,TAB,TAB,EOS - printf11Str db "%X | %8X | %08X\n",EOS - printf12 db TAB,"rax=0x1234567890ABCDEF",NL,TAB,"printf(",DQUO,"\nRAX\t%064b\nEAX\t\t\t\t\t%032b\n AX\t\t\t\t\t\t\t%016b\n AH\t\t\t\t\t\t\t%08b\t\n AL\t\t\t\t\t\t\t\t%08b\n",DQUO,", rax, eax, ax, ah, al): ",NL,TAB,TAB,EOS - printf12Str db "\nRAX\t%064b\nEAX\t\t\t\t\t%032b\n AX\t\t\t\t\t\t\t%016b\n AH\t\t\t\t\t\t\t%08b\t\n AL\t\t\t\t\t\t\t\t%08b\n",EOS - printf13 db TAB,"printf(",DQUO,"%o | %8o | %08o\n",DQUO,", 1500, 1500, 1500): ",NL,TAB,TAB,EOS - printf13Str db "%o | %8o | %08o\n",EOS - printf14 db TAB,"printf(",DQUO,"%#b | %#08b | %#x | %#8X | %#o\n",DQUO,", 8, 8, 0xABCDEF, 0x12345678, 15): ",NL,TAB,TAB,EOS - printf14Str db "%#b | %#08b | %#x | %#8X | %#o\n",EOS - printf15 db TAB,"printf(",DQUO,"%p | %#p | %8p | %#8p | %08p | %#08p\n",DQUO,", str5, str5, str5, str5, strBuff1, strBuff1): ",NL,TAB,TAB,EOS - printf15Str db "%p | %#p | %8p | %#8p | %08p | %#08p\n",EOS - printf16 db TAB,"printf(",DQUO,"%x | %#10x | %10x | %#10x | %010x | %#010x\n",DQUO,", str5, str5, str5, str5, strBuff1, strBuff1): ",NL,TAB,TAB,EOS - printf16Str db "%x | %#10x | %10x | %#10x | %010x | %#010x\n",EOS - printf17 db TAB,"printf(",DQUO,"Ran\dom in\v\a\li%\d test%\n",DQUO,"): ",NL,TAB,TAB,EOS - printf17Str db "Ran\dom in\v\a\li%\d test%\n",EOS - printf18 db TAB,"printf(",DQUO,"itoa(12345, 9, 0, 0): %s < strBuff1: %s",NL,TAB,"> str1: %s",NL,TAB,"strcmp(str1, strBuff1): %d",NL,EOS - strcmp4 db TAB,"strcmp(strBuff1, str1): %d",NL,EOS - strcmp5 db TAB,"- strclr(strBuff1, 32)",NL,TAB,"strcmp(strBuff1, str1): %d",NL,TAB,"strcmp(str1, strBuff1): %d",NL,EOS - strcmp6 db TAB,"strcmp(str1, str5): %d",NL,EOS - - ; min() / minu() - msgMin db NL,"TEST min(), minu()",NL,EOS - min1 db TAB,"min(15, 30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - min2 db TAB,"min(-15, -30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - min3 db TAB,"min(-1, 0):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - min4 db TAB,"min(0xFFFFFFFF, -4294967295):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - minu1 db TAB,"minu(15, 30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - minu2 db TAB,"minu(-15, -30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - minu3 db TAB,"minu(-1, 0):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - minu4 db TAB,"minu(0xFFFFFFFF, -4294967295):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - - ; max() / maxu() - msgMax db NL,"TEST max(), maxu()",NL,EOS - max1 db TAB,"max(15, 30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - max2 db TAB,"max(-15, -30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - max3 db TAB,"max(-1, 0):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - max4 db TAB,"max(0xFFFFFFFF, -4294967295):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - maxu1 db TAB,"maxu(15, 30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - maxu2 db TAB,"maxu(-15, -30):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - maxu3 db TAB,"maxu(-1, 0):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - maxu4 db TAB,"maxu(0xFFFFFFFF, -4294967295):",NL,TAB,TAB,"[%d] (%x) (%b)",NL,EOS - - ; clamp() / clampu() - msgClamp db NL,"clampArg1 = MIN_INT32, clampArg2 = MAX_INT32",NL,"clampuArg1 = MIN_UINT32, clampuArg2 = MAX_UINT32",NL,"TEST clamp(), clampu()",NL,EOS - clampArg1 equ MIN_INT32 - clampArg2 equ MAX_INT32 - clamp1 db TAB,"clamp(MIN_INT64, clampArg1, clampArg2): %d",NL,EOS - clamp2 db TAB,"clamp(MAX_INT64, clampArg1, clampArg2): %d",NL,EOS - clamp3 db TAB,"clamp(MAX_UINT16, clampArg1, clampArg2): %d",NL,EOS - clamp4 db TAB,"clamp(MAX_INT32+1, clampArg1, clampArg2): %d",NL,EOS - clampuArg1 equ MIN_UINT32 - clampuArg2 equ MAX_UINT32 - clampu1 db TAB,"clampu(MAX_UINT64, clampArg1, clampArg2): %d",NL,EOS - clampu2 db TAB,"clampu(MAX_UINT16, clampArg1, clampArg2): %d",NL,EOS - - ; atoi() - msgAtoi db NL,"TEST atoi()",NL,EOS - atoiOutput db TAB,"atoi(",DQUO,"%s",DQUO,"): %d",NL,EOS - atoi1 db "1234567890",EOS - atoi2 db "0xFFFFFFFF",EOS ;4 294 967 295 - atoi3 db "0o776655",EOS ;261 549 - atoi4 db "0b11001001",EOS ;201 - atoi5 db "-0000001",EOS ;-1 - atoi6 db "-1690000000004",EOS - atoi7 db "0x0962ABCDEF",EOS ;40 310 132 207 - atoi8 db "0x0962GBCDEF",EOS ;0 - atoi9 db "0o77865",EOS ;0 - atoi10 db "0b102001",EOS;0 - atoi11 db "0xffffffff",EOS ;4 294 967 295 section .data section .bss - strBuff1 resb 32 - strBuff2 resb 32 section .text global _start _start: - push rbp - mov rbp, rsp - sub rsp, SIZE_QWORD + xor r13, r13 ;total tests + xor r14, r14 ;OK tests (assert => true) -; PRINT STRINGS - lea rdi, [rel msgStrings] - lea rsi, [rel str1] - lea rdx, [rel str2] - lea rcx, [rel str3] - lea r8, [rel str4] - lea r9, [rel str5] - call printf - -;--- -;--- print() -;--- -%if TEST_print - lea rdi, [rel msgPrint] - call print -%endif - -;--- -;--- puts() -;--- -%if TEST_puts - lea rdi, [rel msgPuts] - call puts -%endif - -%if TEST_itoa - lea rdi, [rel msgItoa] - call print -%endif - -;--- -;--- printf() -;--- -%if TEST_printf - lea rdi, [rel msgPrintf] - call printf - - ; TEST 1 - lea rdi, [rel printf1] - call print - lea rdi, [rel printf1Str] - call printf - - ; TEST 2 - lea rdi, [rel printf2] - call print - lea rdi, [rel printf2Str] - lea rsi, [rel printf2Str1] - lea rdx, [rel printf2Str2] - call printf - - ; TEST 3 - lea rdi, [rel printf3] - call print - lea rdi, [rel printf3Str] - mov rsi, printf3C1 - mov rdx, printf3C2 - mov rcx, printf3C3 - mov r8, printf3C4 - mov r9, printf3C5 - push printf3C8 - push printf3Str1 - push printf3C7 - push printf3C6 - call printf - add rsp, SIZE_QWORD * 4 - - ; TEST 4 - lea rdi, [rel printf4] - call print - lea rdi, [rel printf4Str] - mov rsi, -50 - mov rdx, -50 - mov rcx, -50 - mov r8, 0xFFFFFFFFFFFFFFFF - mov r9, 0xFFFFFFFFFFFFFFFF - sub rsp, SIZE_QWORD - push 0xFFFFFFFFFFFFFFFF - call printf - add rsp, SIZE_QWORD - - ; TEST 5 - lea rdi, [rel printf5] - call print - lea rdi, [rel printf5Str] - mov rsi, 0xabcdeffedcba - mov rdx, 0x069bc0e - mov rcx, 666 - mov r8, -1 - call printf - - ; TEST 6 - lea rdi, [rel printf6] - call print - lea rdi, [rel printf6Str] - mov rsi, 5 - mov rdx, 7 - mov rcx, 9 - call printf - - ; TEST 7 - lea rdi, [rel printf7] - call print - lea rdi, [rel printf7Str] - mov rsi, -234 - mov rdx, -666 - mov rcx, 234 - call printf - - ; TEST 8 - lea rdi, [rel printf8] - call print - lea rdi, [rel printf8Str] - mov rsi, -234 - mov rdx, -666 - mov rcx, 234 - call printf - - ; TEST 9 - lea rdi, [rel printf9] - call print - lea rdi, [rel printf9Str] - mov rsi, -234 - mov rdx, -666 - mov rcx, 234 - call printf - - ; TEST 10 - lea rdi, [rel printf10] - call print - lea rdi, [rel printf10Str] - mov rsi, 0xAB0F - mov rdx, 0xBA0F - mov rcx, 0xAB0F - call printf - - ; TEST 11 - lea rdi, [rel printf11] - call print - lea rdi, [rel printf11Str] - mov rsi, 0xAB0F - mov rdx, 0xBA0F - mov rcx, 0xAB0F - call printf - - ; TEST 12 - lea rdi, [rel printf12] - call print - - mov rax, 0x1234567890abcdef - xor rbx, rbx - xor rcx, rcx - xor r8, r8 - xor r9, r9 - - lea rdi, [rel printf12Str] - mov rsi, rax - mov edx, eax - mov cx, ax - mov bh, ah - mov r8, rbx - shr r8, 8 - mov r9b, al - call printf - - ; TEST 13 - lea rdi, [rel printf13] - call print - lea rdi, [rel printf13Str] - mov rsi, 1500 - mov rdx, 1500 - mov rcx, 1500 - call printf - - ; TEST 14 - lea rdi, [rel printf14] - call print - lea rdi, [rel printf14Str] - mov rsi, 8 - mov rdx, 8 - mov rcx, 0xABCDEF - mov r8, 0x12345678 - mov r9, 15 - call printf - - ; TEST 15 - lea rdi, [rel printf15] - call print - lea rdi, [rel printf15Str] - lea rsi, [rel str5] - lea rdx, [rel str5] - lea rcx, [rel str5] - lea r8, [rel str5] - lea r9, [rel strBuff1] - sub rsp, SIZE_QWORD - push strBuff1 - call printf - add rsp, SIZE_QWORD * 2 - - ; TEST 16 - lea rdi, [rel printf16] - call print - lea rdi, [rel printf16Str] - lea rsi, [rel str5] - lea rdx, [rel str5] - lea rcx, [rel str5] - lea r8, [rel str5] - lea r9, [rel strBuff1] - sub rsp, SIZE_QWORD - push strBuff1 - call printf - add rsp, SIZE_QWORD * 2 - - ; TEST 17 - lea rdi, [rel printf17] - call print - lea rdi, [rel printf17Str] - call printf - - ; TEST 18 - lea rdi, [rel printf18] - call print - - mov rdi, 12345 - mov rsi, 9 - xor rdx, rdx - xor rcx, rcx - call itoa - lea rdi, [rel printf18Str] - mov rsi, rax - call printf -%endif - -;--- -;--- strlen() -;--- -%if TEST_strlen - lea rdi, [rel msgStrlen] - call print - - ; TEST 1 - lea rdi, [rel str1] - call strlen - lea rdi, [rel strlen1] - mov rsi, rax - call printf - - ; TEST 2 - lea rdi, [rel str3] - call strlen - lea rdi, [rel strlen2] - mov rsi, rax - call printf - - ; TEST 3 - lea rdi, [rel str5] - call strlen - lea rdi, [rel strlen3] - mov rsi, rax - call printf -%endif - -;--- -;--- strcpy() -;--- -%if TEST_strcpy - lea rdi, [rel msgStrcpy] - call print - - ; TEST 1 - lea rdi, [rel strcpy1] - call print - lea rdi, [rel strBuff1] - lea rsi, [rel str1] - mov rdx, 12 - call strcpy - mov rdi, rax - call puts - ; TEST 2 - lea rdi, [rel strcpy2] - call print - lea rdi, [rel strBuff1] - lea rsi, [rel str1] - mov rdx, 13 - call strcpy - mov rdi, rax - call puts - ; TEST 3 - lea rdi, [rel strcpy3] - call print - lea rdi, [rel strBuff1] - lea rsi, [rel str1] - mov rdx, 32 - call strcpy - mov rdi, rax - call puts - ; TEST 4 - lea rdi, [rel strcpy4] - call print - lea rdi, [rel strBuff1] - lea rsi, [rel str5] - mov rdx, 32 - call strcpy - mov rdi, rax - call puts -%endif - -;--- -;--- strcat -;--- -%if TEST_strcat - lea rdi, [rel msgStrcat] - call print - - ; TEST 1 - lea rdi, [rel strcat1] - call print - lea rdi, [rel strBuff2] - lea rsi, [rel str1] - mov rcx, 32 - call strcat - mov rdi, rax - call puts - - ; TEST 3 - lea rdi, [rel strcat2] - call print - lea rdi, [rel strBuff2] - lea rsi, [rel str5] - mov rcx, 32 - call strcat - mov rdi, rax - call puts -%endif - -;--- -;--- strclr -;--- -%if TEST_strclr - lea rdi, [rel msgStrclr] - call print - - ; TEST 1 - lea rdi, [rel strclr1a] - call print - lea rdi, [rel strBuff1] - lea rsi, [rel str5] - mov rdx, 32 - call strcat - lea rdi, [rel strBuff1] - mov rsi, 32 - call strclr - lea rdi, [rel strBuff1] - call puts - - lea rdi, [rel strclr1b] - call print - lea rdi, [rel strBuff1] - add rdi, 3 - call puts - - ; TEST 2 - lea rdi, [rel strclr2] - call print - lea rdi, [rel strBuff1] - lea rsi, [rel str5] - mov rdx, 32 - call strcat - lea rdi, [rel strBuff1] - mov rsi, 2 - call strclr - ;lea rdi, [rel strBuff1] ;will add output for this later < works as expected tho - ;call puts - lea rdi, [rel strBuff1] - add rdi, 3 - call puts -%endif - -;--- ;--- islower() -;--- -%if TEST_islower - lea rdi, [rel msgIslower] - call print - - ; TEST 1 - mov dil, byte [str1] - call islower - lea rdi, [rel islower1] - mov rsi, rax - call printf - - ; TEST 2 - mov dil, byte [str1 + 1] - call islower - lea rdi, [rel islower2] - mov rsi, rax - call printf - - ; TEST 3 - mov dil, 'd' - call islower - lea rdi, [rel islower3] - mov rsi, rax - call printf - - ; TEST 4 - mov dil, 'D' - call islower - lea rdi, [rel islower4] - mov rsi, rax - call printf - - ; TEST 5 - mov dil, '!' - call islower - lea rdi, [rel islower5] - mov rsi, rax - call printf -%endif - -;--- -;--- isupper() -;--- -%if TEST_isupper - lea rdi, [rel msgIsupper] - call print - - ; TEST 1 - mov dil, byte [str1] - call isupper - lea rdi, [rel isupper1] - mov rsi, rax - call printf - - ; TEST 2 - mov dil, byte [str1 + 1] - call isupper - lea rdi, [rel isupper2] - mov rsi, rax - call printf - - ; TEST 3 - mov dil, 'd' - call isupper - lea rdi, [rel isupper3] - mov rsi, rax - call printf - - ; TEST 4 - mov dil, 'D' - call isupper - lea rdi, [rel isupper4] - mov rsi, rax - call printf - - ; TEST 5 - mov dil, '!' - call isupper - lea rdi, [rel isupper5] - mov rsi, rax - call printf -%endif - -;--- -;--- tolower() -;--- %if TEST_tolower - lea rdi, [rel msgTolower] - call print + printTestHeader(_islower) - ; TEST 1 - mov dil, byte [str1] - call tolower - lea rdi, [rel tolower1] - mov rsi, rax - call printf - - ; TEST 2 - mov dil, byte [str1 + 1] - call tolower - lea rdi, [rel tolower2] - mov rsi, rax - call printf - - ; TEST 3 - mov dil, '!' - call tolower - lea rdi, [rel tolower3] - mov rsi, rax - call printf - - ; TEST 4 - lea rdi, [rel strBuff1] - lea rsi, [rel str4] - mov rdx, 32 - call strcpy - mov rdi, rax - call strlen - mov rcx, rax - lea rsi, [rel strBuff1] - .tolowerLoop: - mov dil, byte [rsi] - call tolower - mov byte [rsi], al - inc rsi - loop .tolowerLoop - lea rdi, [rel tolower4] - lea rsi, [rel strBuff1] - call printf + ; TEST 1: islower('d') + printTest(islower_d) + mov rdi, 'd' + call islower + assert 1, je, testMsg_assertIEqual + ; TEST 2: islower('D') + printTest(islower_D) + mov rdi, 'D' + call islower + assert 0, je, testMsg_assertIEqual + ; TEST 3: islower('!') + printTest(islower_em) + mov rdi, '!' + call islower + assert 0, je, testMsg_assertIEqual +%endif + +;--- isupper() +%if TEST_isupper + printTestHeader(_isupper) + + ; TEST 1: isupper('d') + printTest(isupper_d) + mov rdi, 'd' + call isupper + assert 0, je, testMsg_assertIEqual + ; TEST 2: isupper('D') + printTest(isupper_D) + mov rdi, 'D' + call isupper + assert 1, je, testMsg_assertIEqual + ; TEST 3: isupper('!') + printTest(isupper_em) + mov rdi, '!' + call isupper + assert 0, je, testMsg_assertIEqual +%endif + +;--- tolower() +%if TEST_tolower + printTestHeader(_tolower) + + ; TEST 1: tolower('d') + printTest(tolower_d) + mov rdi, 'd' + call tolower + assert 'd', je, testMsg_assertIEqual + ; TEST 2: tolower('D') + printTest(tolower_D) + mov rdi, 'D' + call tolower + assert 'd', je, testMsg_assertIEqual + ; TEST 3: tolower('!') + printTest(tolower_em) + mov rdi, '!' + call tolower + assert '!', je, testMsg_assertIEqual + ; TEST 4: tolower('}') + printTest(tolower_cb) + mov rdi, '}' + call tolower + assert '}', je, testMsg_assertIEqual %endif -;--- ;--- toupper() -;--- %if TEST_toupper - lea rdi, [rel msgToupper] - call print + printTestHeader(_toupper) - ; TEST 1 - mov dil, byte [str1] + ; TEST 1: toupper('d') + printTest(toupper_d) + mov rdi, 'd' call toupper - lea rdi, [rel toupper1] - mov rsi, rax - call printf - - ; TEST 2 - mov dil, byte [str1 + 1] + assert 'D', je, testMsg_assertIEqual + ; TEST 2: toupper('D') + printTest(toupper_D) + mov rdi, 'D' call toupper - lea rdi, [rel toupper2] - mov rsi, rax - call printf - - ; TEST 3 - mov dil, '!' + assert 'D', je, testMsg_assertIEqual + ; TEST 3: toupper('!') + printTest(toupper_em) + mov rdi, '!' call toupper - lea rdi, [rel toupper3] - mov rsi, rax - call printf - - ; TEST 4 - lea rdi, [rel strBuff1] - lea rsi, [rel str4] - mov rdx, 32 - call strcpy - mov rdi, rax - call strlen - mov rcx, rax - lea rsi, [rel strBuff1] - .toupperLoop: - mov dil, byte [rsi] - call toupper - mov byte [rsi], al - inc rsi - loop .toupperLoop - lea rdi, [rel toupper4] - lea rsi, [rel strBuff1] - call printf + assert '!', je, testMsg_assertIEqual + ; TEST 4: toupper('}') + printTest(toupper_cb) + mov rdi, '}' + call toupper + assert '}', je, testMsg_assertIEqual %endif -;--- -;--- strcmp() -;--- -%if TEST_strcmp - lea rdi, [rel msgStrcmp] - call printf - - ; TEST 1 - lea rdi, [rel str1] - lea rsi, [rel str1] - call strcmp - lea rdi, [rel strcmp1] - mov rsi, rax - call printf - - ; TEST 2 - lea rdi, [rel str1] - lea rsi, [rel str2] - call strcmp - lea rdi, [rel strcmp2] - mov rsi, rax - call printf - - ; TEST 3 - lea rdi, [rel strBuff1] - lea rsi, [rel str1] - call strcpy - lea rdi, [rel strBuff1] - lea rsi, [rel str2] - call strcat - lea rdi, [rel str1] - lea rsi, [rel strBuff1] - call strcmp - lea rdi, [rel strcmp3] - lea rsi, [rel strBuff1] - lea rdx, [rel str1] - mov rcx, rax - call printf - - ; TEST 4 - lea rdi, [rel strBuff1] - lea rsi, [rel str1] - call strcmp - lea rdi, [rel strcmp4] - mov rsi, rax - call printf - - ; TEST 5 - lea rdi, [rel strBuff1] - mov rsi, 32 - call strclr - lea rdi, [rel strBuff1] - lea rsi, [rel str1] - call strcmp - mov rbx, rax - lea rdi, [rel str1] - lea rsi, [rel strBuff1] - call strcmp - lea rdi, [rel strcmp5] - mov rsi, rbx - mov rdx, rax - call printf - - ; TEST 6 - - lea rdi, [rel str1] - lea rsi, [rel str5] - call strcmp - lea rdi, [rel strcmp6] - mov rsi, rax - call printf -%endif - -;--- -;--- min() / minu() -;--- +;--- min() %if TEST_min - lea rdi, [rel msgMin] - call print + printTestHeader(_min) - ; TEST 1 - mov rdi, 15 - mov rsi, 30 + ; TEST 1: min(-1337, 1337) + printTest(min1) + mov rdi, -1337 + mov rsi, 1337 call min - lea rdi, [rel min1] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 2 - mov rdi, -15 - mov rsi, -30 - call min - lea rdi, [rel min2] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 3 - mov rdi, -1 - xor rsi, rsi - call min - lea rdi, [rel min3] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 4 - mov rdi, 0xFFFFFFFF - mov rsi, -4294967295 - call min - lea rdi, [rel min4] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 1 - mov rdi, 15 - mov rsi, 30 - call minu - lea rdi, [rel minu1] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 2 - mov rdi, -15 - mov rsi, -30 - call minu - lea rdi, [rel minu2] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 3 - mov rdi, -1 - xor rsi, rsi - call minu - lea rdi, [rel minu3] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 4 - mov rdi, 0xFFFFFFFF - mov rsi, -4294967295 - call minu - lea rdi, [rel minu4] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf -%endif - -;--- -;--- max() / maxu() -;--- -%if TEST_max - lea rdi, [rel msgMin] - call print - - ; TEST 1 - mov rdi, 15 - mov rsi, 30 - call max - lea rdi, [rel max1] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 2 - mov rdi, -15 - mov rsi, -30 - call max - lea rdi, [rel max2] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 3 - mov rdi, -1 - xor rsi, rsi - call max - lea rdi, [rel max3] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 4 - mov rdi, 0xFFFFFFFF - mov rsi, -4294967295 - call max - lea rdi, [rel max4] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 1 - mov rdi, 15 - mov rsi, 30 - call maxu - lea rdi, [rel maxu1] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 2 - mov rdi, -15 - mov rsi, -30 - call maxu - lea rdi, [rel maxu2] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 3 - mov rdi, -1 - xor rsi, rsi - call maxu - lea rdi, [rel maxu3] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf - - ; TEST 4 - mov rdi, 0xFFFFFFFF - mov rsi, -4294967295 - call maxu - lea rdi, [rel maxu4] - mov rsi, rax - mov rdx, rax - mov rcx, rax - call printf -%endif - -;--- -;--- clamp() / clampu() -;--- -%if TEST_clamp - lea rdi, [rel msgClamp] - call print - - ; TEST 1 + assert rdi, je, testMsg_assertIEqual + ; TEST 2: min(MIN_INT64, MAX_INT64) + printTest(min2) mov rdi, MIN_INT64 - mov rsi, clampArg1 - mov rdx, clampArg2 - call clamp - mov rsi, rax - lea rdi, [rel clamp1] - call printf - ; TEST 2 - mov rdi, MAX_INT64 - mov rsi, clampArg1 - mov rdx, clampArg2 - call clamp - mov rsi, rax - lea rdi, [rel clamp2] - call printf - ; TEST 3 - mov rdi, MAX_UINT16 - mov rsi, clampArg1 - mov rdx, clampArg2 - call clamp - mov rsi, rax - lea rdi, [rel clamp3] - call printf - ; TEST 4 - mov rdi, MAX_INT32+1 - mov rsi, clampArg1 - mov rdx, clampArg2 - call clamp - mov rsi, rax - lea rdi, [rel clamp4] - call printf - - ; TEST 5 - mov rdi, MAX_UINT64 - mov rsi, clampuArg1 - mov rdx, clampuArg2 - call clampu - mov rsi, rax - lea rdi, [rel clampu1] - call printf - - ; TEST 6 - mov rdi, MAX_UINT16 - mov rsi, clampuArg1 - mov rdx, clampuArg2 - call clampu - mov rsi, rax - lea rdi, [rel clampu2] - call printf + mov rsi, MAX_INT64 + call min + assert rdi, je, testMsg_assertIEqual + ; TEST 3: min(MIN_UINT64, MAX_UINT64) + printTest(min3) + mov rdi, MIN_UINT64 + mov rsi, MAX_UINT64 + call min + assert rdi, je, testMsg_assertIEqual + ; TEST 4: min(-1, 0) + printTest(min4) + mov rdi, -1 + xor rsi, rdx + call min + assert rdi, je, testMsg_assertIEqual + ; TEST 5: min(MIN_UINT64, MIN_INT8) + printTest(min5) + mov rdi, MIN_UINT64 + mov rsi, MIN_INT8 + call min + assert rsi, je, testMsg_assertIEqual %endif -;--- -;--- atoi() -;--- -%if TEST_atoi - lea rdi, [rel msgAtoi] - call print - %macro testatoi 1 - lea rdi, [rel %1] - call atoi - lea rdi, [rel atoiOutput] - lea rsi, [rel %1] - mov rdx, rax +;;; +;;; TEST RESULTS +;;; + lea rdi, [rel testMsg_Results] + mov rsi, r13 + mov rdx, r14 + mov rcx, r13 + sub rcx, r14 call printf - %endmacro - testatoi atoi1 - testatoi atoi2 - testatoi atoi3 - testatoi atoi4 - testatoi atoi5 - testatoi atoi6 - testatoi atoi7 - testatoi atoi8 - testatoi atoi9 - testatoi atoi10 - testatoi atoi11 -%endif - -;--- ;--- exit() -;--- - leave xor rdi, rdi call exit