From: Lukas Krickl Date: Sun, 26 Nov 2023 21:18:06 +0000 (+0100) Subject: Added built tests for t0 X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=fbbd44f63fc2718c8d48b12b8934c731fb765c2e;p=ulas%2F.git Added built tests for t0 --- diff --git a/makefile b/makefile index 2e21406..c5fa268 100644 --- a/makefile +++ b/makefile @@ -72,3 +72,8 @@ lint: .PHONY: runtest runtest: ./$(BDIR)/$(TEST_BNAME) + +.PHONY: buildtests +buildtests: + ./$(BDIR)/$(BNAME) tests/t0.s -l - -o tests/t0.bin + diff --git a/src/test.c b/src/test.c index 27acf57..f551650 100644 --- a/src/test.c +++ b/src/test.c @@ -303,19 +303,23 @@ void test_asminstr(void) { #define ULAS_FULLEN 0xFFFF -#define ASSERT_FULL(expect_len, expect_rc, in_path, ...) \ +#define ASSERT_FULL(expect_rc, in_path, expect_path) \ { \ + printf("[source: %s; expect: %s]\n", in_path, expect_path); \ ulaslstout = stdout; \ struct ulas_config cfg = ulas_cfg_from_env(); \ char dstbuf[ULAS_FULLEN]; \ - char expect[] = {__VA_ARGS__}; \ + char expect[ULAS_FULLEN]; \ + FILE *expectf = fopen(expect_path, "re"); \ + int expect_len = fread(expect, 1, ULAS_FULLEN, expectf); \ + fclose(expectf); \ memset(dstbuf, 0, ULAS_FULLEN); \ ulasout = fmemopen(dstbuf, ULAS_FULLEN, "we"); \ ulasin = fopen(in_path, "re"); \ assert(ulas_main(cfg) == expect_rc); \ fclose(ulasout); \ for (int i = 0; i < expect_len; i++) { \ - assert(dstbuf[i] == expect[i]); \ + assert(expect[i] == dstbuf[i]); \ } \ for (int i = expect_len; i < ULAS_FULLEN; i++) { \ assert(dstbuf[i] == 0); \ @@ -328,7 +332,7 @@ void test_asminstr(void) { void test_full(void) { TESTBEGIN("testfull"); - ASSERT_FULL(2, 0, "tests/t0.s", 0, 0x76); + ASSERT_FULL(0, "tests/t0.s", "tests/t0.bin"); TESTEND("testfull"); } diff --git a/tests/t0.bin b/tests/t0.bin new file mode 100644 index 0000000..1cc8c84 Binary files /dev/null and b/tests/t0.bin differ diff --git a/tests/t0.s b/tests/t0.s index 630c4b7..be28504 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -1,5 +1,9 @@ ; this is a sample assembly file -; that can be read by tests +; that can be read by tests. +; the expected result will just be a regular run of the program +; that will be verified for correctness manually once +; generate expected result with: +; make buildtests .org 0x100 ; comment nop ; full line is a comments