Added built tests for t0
authorLukas Krickl <lukas@krickl.dev>
Sun, 26 Nov 2023 21:18:06 +0000 (22:18 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sun, 26 Nov 2023 21:18:06 +0000 (22:18 +0100)
makefile
src/test.c
tests/t0.bin [new file with mode: 0644]
tests/t0.s

index 2e214068aba5135895375f2f4691e20cb317409d..c5fa268c7fff81fc9db6b68b9f9f532272dae551 100644 (file)
--- 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
+
index 27acf57be5e9d3843809358fd639090b836916b2..f5516503c8512d1ee9927fda12f9cd63c859af7b 100644 (file)
@@ -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 (file)
index 0000000..1cc8c84
Binary files /dev/null and b/tests/t0.bin differ
index 630c4b7613dc9ace7c13514cecc2c33f4411d563..be28504e837a6b2e094d26284546ef53e90200a8 100644 (file)
@@ -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