Added test for disas
authorLukas Krickl <lukas@krickl.dev>
Mon, 26 Feb 2024 16:46:09 +0000 (17:46 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 26 Feb 2024 16:46:09 +0000 (17:46 +0100)
makefile
src/test.c
tests/t0_dasm.s [new file with mode: 0644]

index 7703521b501766e6020d82bf82d89ce88655e8cd..87fe84134a1427f08504b08289ba68c94748f84f 100644 (file)
--- 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
index a6425ed638a188d73a066676671c122787da6d31..b00742e5dd1f3cb873c302049b2bb0185866ee13 100644 (file)
@@ -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 (file)
index 0000000..a83a590
--- /dev/null
@@ -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