reduce verbosity of unit test ouput, some clean up
authorLunaixsky <lunaixsky@qq.com>
Fri, 13 Dec 2024 17:22:06 +0000 (17:22 +0000)
committerLunaixsky <lunaixsky@qq.com>
Fri, 13 Dec 2024 17:22:06 +0000 (17:22 +0000)
lunaix-os/kernel/ds/btrie.c
lunaix-os/tests/includes/testing/basic.h
lunaix-os/tests/shared/framework.c
lunaix-os/tests/units/btrie/test-alloc.c
lunaix-os/tests/units/test_build.mkinc [deleted file]

index 37bf80350b963a58f47ad8e15175aa9ef52dfec7..8971759e931baa27195b92d6f7b0ddf5ea82b462 100644 (file)
@@ -151,7 +151,7 @@ __get_immediate_node(struct btrie* tree, struct btrie_node *root,
 
     mask  = (1UL << tree->order) - 1;
     index = loc & mask;
-    for (int i = 0; i <= mask; ++i, index = (index + 1) & mask) 
+    for (unsigned long i = 0; i <= mask; ++i, index = (index + 1) & mask) 
     {    
         loc = (loc & ~mask) + index;
         node = __btrie_get_child(root, index);
index a81dc4fc1bac7fa16b2c543bc8942e81e1514b96..ea2261bc17b8689f682b655aae5a0b9cdae6491e 100644 (file)
@@ -13,35 +13,44 @@ struct test_context
             struct {
                 int passed;
                 int failed;
+                int skipped;
             };
-            int countings[2];
+            int countings[3];
         };
 
         union {
             struct {
                 int total_passed;
                 int total_failed;
+                int total_skipped;
             };
-            int total_countings[2];
+            int total_countings[3];
         };
     } stats;
 };
 
 #define fmt_passed  "[\x1b[32;49mPASS\x1b[0m]"
 #define fmt_failed  "[\x1b[31;49mFAIL\x1b[0m]"
+#define fmt_skiped  "[\x1b[33;49mSKIP\x1b[0m]"
 
 #define active_context      \
     ({ extern struct test_context* __test_ctx; __test_ctx; })
 
 #define _expect(expr, act, exp, type_fmt)                                   \
     do {                                                                    \
+        if(should_skip_test()) {                                            \
+            printf("  @%s:%03d ....... ", __FILE__, __LINE__);              \
+            printf(fmt_skiped "\n");                                        \
+            active_context->stats.skipped++;                                \
+            break;                                                          \
+        }                                                                   \
+                                                                            \
         int failed = !(expr);                                               \
-        printf("  @%s:%03d ....... ", __FILE__, __LINE__);                    \
-        if (failed)                                                         \
+        if (failed) {                                                       \
+            printf("  @%s:%03d ....... ", __FILE__, __LINE__);              \
             printf(fmt_failed " (expect: " type_fmt ", got: " type_fmt ")\n",\
                     exp, act);                                              \
-        else                                                                \
-            printf(fmt_passed "\n");                                       \
+        }                                                                   \
         active_context->stats.countings[failed]++;                          \
     } while(0)
 
@@ -88,4 +97,10 @@ end_testcase();
 void 
 run_test(int argc, const char* argv[]);
 
+static inline int
+should_skip_test()
+{
+    return active_context->stats.failed;
+}
+
 #endif /* __COMMON_TEST_BASIC_H */
index 3c3f19141e5747b75e2d632e27a0b4c2f51bfe1e..e8adb4367891dc1cfb50e9806919f462b6d59dfa 100644 (file)
@@ -14,9 +14,10 @@ main(int argc, const char* argv[])
     run_test(argc, argv);
 
     printf(
-        "All test done: %d passed, %d failed\n\n",
+        "All test done: %d passed, %d failed, %d skipped\n\n",
         __test_ctx->stats.total_passed,
-        __test_ctx->stats.total_failed
+        __test_ctx->stats.total_failed,
+        __test_ctx->stats.total_skipped
     );
 
     memchk_print_stats();
@@ -37,6 +38,7 @@ begin_testcase(const char* name)
     __test_ctx->name = name;
     __test_ctx->stats.countings[0] = 0;
     __test_ctx->stats.countings[1] = 0;
+    __test_ctx->stats.countings[2] = 0;
 
     printf("%s\n", name);
 }
@@ -44,11 +46,14 @@ begin_testcase(const char* name)
 void
 end_testcase()
 {
-    printf("..... passed: %d, failed: %d\n\n", 
-            __test_ctx->stats.passed, __test_ctx->stats.failed);
+    printf("..... passed: %d, failed: %d, %d skipped\n\n", 
+            __test_ctx->stats.passed, 
+            __test_ctx->stats.failed,
+            __test_ctx->stats.skipped);
 
     __test_ctx->stats.total_passed += __test_ctx->stats.passed;
     __test_ctx->stats.total_failed += __test_ctx->stats.failed;
+    __test_ctx->stats.total_skipped += __test_ctx->stats.skipped;
     __test_ctx->name = NULL;
 
 }
\ No newline at end of file
index cad32c961f271e777187feca0f6b286db5bc204c..92439d99305ac51e472a43150dfa22c991d5e0b4 100644 (file)
@@ -12,10 +12,10 @@ __alloc_simple()
     struct btrie_node *root;
     btrie_init(&tree, ilog2(WIDTH));
 
-    expect_ulong(btrie_map(&tree, 0, 100, (void*)1), 0);
-    expect_ulong(btrie_map(&tree, 0, 100, (void*)2), 1);
-    expect_ulong(btrie_map(&tree, 0, 100, (void*)3), 2);
-    expect_ulong(btrie_map(&tree, 0, 100, (void*)4), 3);
+    expect_long(btrie_map(&tree, 0, 100, (void*)1), 0);
+    expect_long(btrie_map(&tree, 0, 100, (void*)2), 1);
+    expect_long(btrie_map(&tree, 0, 100, (void*)3), 2);
+    expect_long(btrie_map(&tree, 0, 100, (void*)4), 3);
 
     root = tree.btrie_root;
     expect_notnull(root->children);
@@ -43,10 +43,10 @@ __alloc_edge()
     struct btrie_node *root;
     btrie_init(&tree, ilog2(WIDTH));
 
-    expect_ulong(btrie_map(&tree, 7, 100, (void*)1), 7);
-    expect_ulong(btrie_map(&tree, 7, 100, (void*)2), 8);
-    expect_ulong(btrie_map(&tree, 7, 100, (void*)3), 9);
-    expect_ulong(btrie_map(&tree, 7, 100, (void*)4), 10);
+    expect_long(btrie_map(&tree, 7, 100, (void*)1), 7);
+    expect_long(btrie_map(&tree, 7, 100, (void*)2), 8);
+    expect_long(btrie_map(&tree, 7, 100, (void*)3), 9);
+    expect_long(btrie_map(&tree, 7, 100, (void*)4), 10);
 
     root = tree.btrie_root;
     expect_notnull(root->children);
@@ -76,10 +76,10 @@ __alloc_narrow()
     struct btrie_node *root;
     btrie_init(&tree, ilog2(WIDTH));
 
-    expect_ulong(btrie_map(&tree, 4, 7, (void*)1), 4);
-    expect_ulong(btrie_map(&tree, 4, 7, (void*)2), 5);
-    expect_ulong(btrie_map(&tree, 4, 7, (void*)3), 6);
-    expect_ulong(btrie_map(&tree, 4, 7, (void*)4), -1);
+    expect_long(btrie_map(&tree, 4, 7, (void*)1), 4);
+    expect_long(btrie_map(&tree, 4, 7, (void*)2), 5);
+    expect_long(btrie_map(&tree, 4, 7, (void*)3), 6);
+    expect_long(btrie_map(&tree, 4, 7, (void*)4), -1);
 
     root = tree.btrie_root;
     expect_notnull(root->children);
@@ -107,9 +107,9 @@ __alloc_narrow_partial()
     struct btrie_node *root;
     btrie_init(&tree, ilog2(WIDTH));
 
-    expect_ulong(btrie_map(&tree, 15, 17, (void*)1), 15);
-    expect_ulong(btrie_map(&tree, 15, 17, (void*)2), 16);
-    expect_ulong(btrie_map(&tree, 15, 17, (void*)3), -1);
+    expect_long(btrie_map(&tree, 15, 17, (void*)1), 15);
+    expect_long(btrie_map(&tree, 15, 17, (void*)2), 16);
+    expect_long(btrie_map(&tree, 15, 17, (void*)3), -1);
 
     root = tree.btrie_root;
     expect_notnull(root->children);
@@ -178,9 +178,9 @@ __alloc_retrive()
     struct btrie_node *root;
     btrie_init(&tree, ilog2(WIDTH));
 
-    expect_ulong(btrie_map(&tree, 4, 7, (void*)1), 4);
-    expect_ulong(btrie_map(&tree, 4, 7, (void*)2), 5);
-    expect_ulong(btrie_map(&tree, 4, 7, (void*)3), 6);
+    expect_long(btrie_map(&tree, 4, 7, (void*)1), 4);
+    expect_long(btrie_map(&tree, 4, 7, (void*)2), 5);
+    expect_long(btrie_map(&tree, 4, 7, (void*)3), 6);
 
     expect_ulong(__ptr(btrie_get(&tree, 6)), 3);
     expect_ulong(__ptr(btrie_get(&tree, 5)), 2);
diff --git a/lunaix-os/tests/units/test_build.mkinc b/lunaix-os/tests/units/test_build.mkinc
deleted file mode 100644 (file)
index 1a3fcdb..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-MAKEFLAGS += --no-print-directory
-
-include $(LUNAIX_ROOT)/tests/shared/makefile
-
-CFLAGS += -isystem $(unit-test-root)/stubs/includes
\ No newline at end of file