From f69ddee71fe39dc09fb01b0756fcafbcde40cdf9 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 26 Feb 2024 17:46:09 +0100 Subject: [PATCH] Added test for disas --- makefile | 4 ++ src/test.c | 36 +++++++++++--- tests/t0_dasm.s | 122 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 tests/t0_dasm.s diff --git a/makefile b/makefile index 7703521..87fe841 100644 --- a/makefile +++ b/makefile @@ -71,3 +71,7 @@ format: .PHONY: lint lint: clang-tidy ./src/*.h ./src/*.c + +buildtests: + ./$(BDIR)/$(BNAME) tests/t0.s -l - -o tests/t0.bin + ./$(BDIR)/$(BNAME) tests/t0.bin -d - -o tests/t0_dasm.s diff --git a/src/test.c b/src/test.c index a6425ed..b00742e 100644 --- a/src/test.c +++ b/src/test.c @@ -379,7 +379,6 @@ void test_symscope(void) { printf("[source: %s; expect: %s]\n", in_path, expect_path); \ ulaslstout = stdout; \ ulassymout = stdout; \ - struct ulas_config cfg = ulas_cfg_from_env(); \ cfg.verbose = 1; \ char dstbuf[ULAS_FULLEN]; \ char expect[ULAS_FULLEN]; \ @@ -393,6 +392,9 @@ void test_symscope(void) { fclose(ulasout); \ for (int i = 0; i < expect_len; i++) { \ assert(expect[i] == dstbuf[i]); \ + if (cfg.disas) { \ + putchar(dstbuf[i]); /* for easier debugging in disas mode */ \ + } \ } \ for (int i = expect_len; i < ULAS_FULLEN; i++) { \ assert(dstbuf[i] == 0); \ @@ -401,13 +403,34 @@ void test_symscope(void) { ulasout = stdout; \ } +#define ASSERT_FULL_ASM(expect_rc, in_path, expect_path) \ + { \ + struct ulas_config cfg = ulas_cfg_from_env(); \ + ASSERT_FULL(expect_rc, in_path, expect_path) \ + } + // tests the entire stack -void test_full(void) { - TESTBEGIN("testfull"); +void test_full_asm(void) { + TESTBEGIN("testfullasm"); + + ASSERT_FULL_ASM(0, "tests/t0.s", "tests/t0.bin"); + + TESTEND("testfullasm"); +} + +#define ASSERT_FULL_DASM(expect_rc, in_path, expect_path) \ + { \ + struct ulas_config cfg = ulas_cfg_from_env(); \ + cfg.disas = 1; \ + ASSERT_FULL(expect_rc, in_path, expect_path) \ + } + +void test_full_dasm(void) { + TESTBEGIN("testfulldasm"); - ASSERT_FULL(0, "tests/t0.s", "tests/t0.bin"); + ASSERT_FULL_DASM(0, "tests/t0.bin", "tests/t0_dasm.s"); - TESTEND("testfull"); + TESTEND("testfulldasm"); } int main(int arc, char **argv) { @@ -431,7 +454,8 @@ int main(int arc, char **argv) { // this will re-init everything on its own, // so call after free - test_full(); + test_full_dasm(); + test_full_asm(); TESTEND("ulas test"); return 0; diff --git a/tests/t0_dasm.s b/tests/t0_dasm.s new file mode 100644 index 0000000..a83a590 --- /dev/null +++ b/tests/t0_dasm.s @@ -0,0 +1,122 @@ +.org 0x0 + nop + halt + stop + di + ei + ld c, a + ld b, [hl] + adc a, c + ld b, 0x8 + jr nz, 0x4 + ld sp, 0x31a + ld [hl+], a + inc hl + inc [hl] + ld [hl], 0x1 + ld [0x3], sp + jr 0xfe + add hl, bc + ld a, [bc] + ld a, [hl+] + dec bc + dec a + ld c, 0x3 + ret nz + ldh [0x1], a + ldh a, [0x2] + ldh [c], a + ldh a, [c] + ld [0x1], a + ld a, [0x2] + pop bc + jp nz, 0x2 + jp 0x3 + call nc, 0x2 + push af + add a, 0x3 + rst 0x00 + add sp, 0x4 + ld hl, sp+0x2 + ret + reti + jp z, 0x2 + call 0x5 + rlc b + ld bc, 0x6cb + rlc b + ld b, d + rlc b + ld b, [hl] + ld bc, 0x14d + ld bc, 0x153 + ld bc, 0x156 + ld bc, 0x159 + jr z, 0x6 + ld a, 0x3 + ld a, 0x4 + ld bc, 0x302 + ld bc, 0x101 + ld bc, 0x101 + ld bc, 0x101 + ld bc, 0x101 + ld bc, 0x101 + ld bc, 0x101 + ld bc, 0x101 + ld bc, 0x101 + ld bc, 0x101 + nop +.db 0x74 + ld h, l +.db 0x73 +.db 0x74 + ld sp, 0x6574 +.db 0x73 +.db 0x74 + ld [hl-], a + xor a, d + cp a, e + call z, 0xdd + halt + nop + jp 0x195 + jp 0x195 + add a, h + ld [hl], a + ld bc, 0x9b3e + call 0x1a1 + swap a + ld [0x1], a + inc de + ld [bc], a + ld a, 0x21 + ld a, 0x23 + jp hl + ld a, 0x2 + ld bc, 0x6261 + ld h, e + ld h, [hl] + ld h, d + ld h, e + ld bc, 0x302 + dec a + ld e, e + ld a, 0x0 + ld a, 0x2 + ld a, 0x4 + ld a, 0x0 + ld a, 0x1 + ld a, 0x2 + ld a, 0x3 + ld a, 0x4 + ld a, 0x5 + inc a + dec a + ld a, 0x3f +.db 0x74 + ld h, l +.db 0x73 +.db 0x74 + dec b + inc b +.db 0x6 -- 2.30.2