]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- testbound selftest also works in non-debug mode.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 22 Sep 2015 09:52:17 +0000 (09:52 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 22 Sep 2015 09:52:17 +0000 (09:52 +0000)
git-svn-id: file:///svn/unbound/trunk@3490 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
testcode/replay.c
testcode/testbound.c

index 08beef362f8b4dac8d9b569683344acd87b33199..6e0f5ef3128f396825820cd1028e479fc23f3d6a 100644 (file)
@@ -5,6 +5,7 @@
        - Fix #702: New IPs for for h.root-servers.net.
        - Remove confusion comment from canonical_compare() function.
        - Fix #705: ub_ctx_set_fwd() return value mishandled on windows.
+       - testbound selftest also works in non-debug mode.
 
 31 August 2015: Wouter
        - changed windows setup compression to be more transparent.
index 01b17a7f7d0cc5f5b7400b89c69774b12007c62f..8a88814e765ad8c201104001d7bef5e6d3be5f56 100644 (file)
@@ -909,118 +909,127 @@ macro_assign(rbtree_t* store, char* name, char* value)
        return x->value != NULL;
 }
 
+/* testbound assert function for selftest.  counts the number of tests */
+#define tb_assert(x) \
+       do { if(!(x)) fatal_exit("%s:%d: %s: assertion %s failed", \
+               __FILE__, __LINE__, __func__, #x); \
+               num_asserts++; \
+       } while(0);
+
 void testbound_selftest(void)
 {
        /* test the macro store */
        rbtree_t* store = macro_store_create();
        char* v;
        int r;
-       log_assert(store);
+       int num_asserts = 0;
+       tb_assert(store);
 
        v = macro_lookup(store, "bla");
-       log_assert(strcmp(v, "") == 0);
+       tb_assert(strcmp(v, "") == 0);
        free(v);
 
        v = macro_lookup(store, "vlerk");
-       log_assert(strcmp(v, "") == 0);
+       tb_assert(strcmp(v, "") == 0);
        free(v);
 
        r = macro_assign(store, "bla", "waarde1");
-       log_assert(r);
+       tb_assert(r);
 
        v = macro_lookup(store, "vlerk");
-       log_assert(strcmp(v, "") == 0);
+       tb_assert(strcmp(v, "") == 0);
        free(v);
 
        v = macro_lookup(store, "bla");
-       log_assert(strcmp(v, "waarde1") == 0);
+       tb_assert(strcmp(v, "waarde1") == 0);
        free(v);
 
        r = macro_assign(store, "vlerk", "kanteel");
-       log_assert(r);
+       tb_assert(r);
 
        v = macro_lookup(store, "bla");
-       log_assert(strcmp(v, "waarde1") == 0);
+       tb_assert(strcmp(v, "waarde1") == 0);
        free(v);
 
        v = macro_lookup(store, "vlerk");
-       log_assert(strcmp(v, "kanteel") == 0);
+       tb_assert(strcmp(v, "kanteel") == 0);
        free(v);
 
        r = macro_assign(store, "bla", "ww");
-       log_assert(r);
+       tb_assert(r);
 
        v = macro_lookup(store, "bla");
-       log_assert(strcmp(v, "ww") == 0);
+       tb_assert(strcmp(v, "ww") == 0);
        free(v);
 
-       log_assert( macro_length("}") == 1);
-       log_assert( macro_length("blabla}") == 7);
-       log_assert( macro_length("bla${zoink}bla}") == 7+8);
-       log_assert( macro_length("bla${zoink}${bla}bla}") == 7+8+6);
+       tb_assert( macro_length("}") == 1);
+       tb_assert( macro_length("blabla}") == 7);
+       tb_assert( macro_length("bla${zoink}bla}") == 7+8);
+       tb_assert( macro_length("bla${zoink}${bla}bla}") == 7+8+6);
 
        v = macro_process(store, NULL, "");
-       log_assert( v && strcmp(v, "") == 0);
+       tb_assert( v && strcmp(v, "") == 0);
        free(v);
 
        v = macro_process(store, NULL, "${}");
-       log_assert( v && strcmp(v, "") == 0);
+       tb_assert( v && strcmp(v, "") == 0);
        free(v);
 
        v = macro_process(store, NULL, "blabla ${} dinges");
-       log_assert( v && strcmp(v, "blabla  dinges") == 0);
+       tb_assert( v && strcmp(v, "blabla  dinges") == 0);
        free(v);
 
        v = macro_process(store, NULL, "1${$bla}2${$bla}3");
-       log_assert( v && strcmp(v, "1ww2ww3") == 0);
+       tb_assert( v && strcmp(v, "1ww2ww3") == 0);
        free(v);
 
        v = macro_process(store, NULL, "it is ${ctime 123456}");
-       log_assert( v && strcmp(v, "it is Fri Jan  2 10:17:36 1970") == 0);
+       tb_assert( v && strcmp(v, "it is Fri Jan  2 10:17:36 1970") == 0);
        free(v);
 
        r = macro_assign(store, "t1", "123456");
-       log_assert(r);
+       tb_assert(r);
        v = macro_process(store, NULL, "it is ${ctime ${$t1}}");
-       log_assert( v && strcmp(v, "it is Fri Jan  2 10:17:36 1970") == 0);
+       tb_assert( v && strcmp(v, "it is Fri Jan  2 10:17:36 1970") == 0);
        free(v);
 
        v = macro_process(store, NULL, "it is ${ctime $t1}");
-       log_assert( v && strcmp(v, "it is Fri Jan  2 10:17:36 1970") == 0);
+       tb_assert( v && strcmp(v, "it is Fri Jan  2 10:17:36 1970") == 0);
        free(v);
 
        r = macro_assign(store, "x", "1");
-       log_assert(r);
+       tb_assert(r);
        r = macro_assign(store, "y", "2");
-       log_assert(r);
+       tb_assert(r);
        v = macro_process(store, NULL, "${$x + $x}");
-       log_assert( v && strcmp(v, "2") == 0);
+       tb_assert( v && strcmp(v, "2") == 0);
        free(v);
        v = macro_process(store, NULL, "${$x - $x}");
-       log_assert( v && strcmp(v, "0") == 0);
+       tb_assert( v && strcmp(v, "0") == 0);
        free(v);
        v = macro_process(store, NULL, "${$y * $y}");
-       log_assert( v && strcmp(v, "4") == 0);
+       tb_assert( v && strcmp(v, "4") == 0);
        free(v);
        v = macro_process(store, NULL, "${32 / $y + $x + $y}");
-       log_assert( v && strcmp(v, "19") == 0);
+       tb_assert( v && strcmp(v, "19") == 0);
        free(v);
 
        v = macro_process(store, NULL, "${32 / ${$y+$y} + ${${100*3}/3}}");
-       log_assert( v && strcmp(v, "108") == 0);
+       tb_assert( v && strcmp(v, "108") == 0);
        free(v);
 
        v = macro_process(store, NULL, "${1 2 33 2 1}");
-       log_assert( v && strcmp(v, "1 2 33 2 1") == 0);
+       tb_assert( v && strcmp(v, "1 2 33 2 1") == 0);
        free(v);
 
        v = macro_process(store, NULL, "${123 3 + 5}");
-       log_assert( v && strcmp(v, "123 8") == 0);
+       tb_assert( v && strcmp(v, "123 8") == 0);
        free(v);
 
        v = macro_process(store, NULL, "${123 glug 3 + 5}");
-       log_assert( v && strcmp(v, "123 glug 8") == 0);
+       tb_assert( v && strcmp(v, "123 glug 8") == 0);
        free(v);
 
        macro_store_delete(store);
+       printf("selftest successful (%d checks).\n", num_asserts);
 }
index fa361c4ead6417a7b56e510ce5c4d52d0f7767c3..b297f477476e81e3006a83d4babdf0a532291efa 100644 (file)
@@ -284,7 +284,6 @@ main(int argc, char* argv[])
                case 's':
                        free(pass_argv[1]);
                        testbound_selftest();
-                       printf("selftest successful\n");
                        exit(0);
                case '2':
 #if (defined(HAVE_EVP_SHA256) || defined(HAVE_NSS)) && defined(USE_SHA2)