]> git.draconx.ca Git - cdecl99.git/commitdiff
tests: Use TAP helpers in rng-test.
authorNick Bowler <nbowler@draconx.ca>
Thu, 30 Nov 2023 01:42:07 +0000 (20:42 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 30 Nov 2023 02:03:06 +0000 (21:03 -0500)
I imagine the helpers were avoided originally to avoid extra files in
the distribution, but they're there anyway now so there seems to be
no reason not to use them.

Makefile.am
t/rng-test.c
tests/stress.at

index 220280ce76ff8f87a06827f36cd02a06d763f5a8..ee4f7799cb56a250695e637ce2f3888f098f200e 100644 (file)
@@ -81,7 +81,7 @@ $(libmain_a_OBJECTS): src/options.h
 
 check_PROGRAMS = t/crossparse t/normalize t/randomdecl t/rng-test
 check_LIBRARIES = libtest.a
-libtest_a_SOURCES = t/testlib.c t/rng.c common/src/help.c
+libtest_a_SOURCES = t/testlib.c t/rng.c common/src/help.c common/src/tap.c
 $(libtest_a_OBJECTS): $(gnulib_headers)
 
 TEST_LIBS = libtest.a libcdecl.la libgnu.a $(LDEXP_LIBM)
index 3f4cf322dbcbfe71c10d0d5b8918d2e7db943594..1d5c6e9373f16acb663e234ee6467d60f0dd0b31 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Simple random number generator for testing.
- * Copyright © 2022 Nick Bowler
+ * Copyright © 2022-2023 Nick Bowler
  *
  * Directly compare the test lib RNG against the reference implementation.
  *
@@ -19,7 +19,7 @@
  */
 
 #include <config.h>
-#include <stdlib.h>
+#include "tap.h"
 
 #include "rng.c"
 #include "xos256p.c"
@@ -31,7 +31,7 @@ int main(void)
        unsigned long long ref_state[4], test_state[4];
        int i, ret = 0;
 
-       printf("1..200\n");
+       tap_plan(200);
        for (i = 0; i < 100; i++) {
                s[0] = ref_state[0] = test_state[0] = splitmix64(&seed_state);
                s[1] = ref_state[1] = test_state[1] = splitmix64(&seed_state);
@@ -41,40 +41,33 @@ int main(void)
                ref_result = next();
                test_result = xoshiro256p(test_state);
 
-               if (ref_result != test_result) {
-                       printf("not ok %d rng output\n", 2*i+1);
-                       printf("# Failed, unexpected result\n");
-                       printf("#   with initial state %llx %llx %llx %llx\n",
-                              ref_state[0], ref_state[1],
-                              ref_state[2], ref_state[3]);
-                       printf("#   received: %llx\n", test_result);
-                       printf("#   expected: %llx\n", ref_result);
-                       ret = EXIT_FAILURE;
-               } else {
-                       printf("ok %d rng output\n", 2*i+1);
+               if (!tap_result(ref_result == test_result, "rng output")) {
+                       tap_diag("Failed, unexpected result");
+                       tap_diag("   with initial state %llx %llx %llx %llx",
+                                                 ref_state[0], ref_state[1],
+                                                 ref_state[2], ref_state[3]);
+                       tap_diag("   received: %llx", test_result);
+                       tap_diag("   expected: %llx", ref_result);
                }
 
-               if (s[0] != test_state[0] || s[1] != test_state[1]
-                   || s[2] != test_state[2] || s[3] != test_state[3])
+               if (!tap_result(s[0] == test_state[0] && s[1] == test_state[1]
+                            && s[2] == test_state[2] && s[3] == test_state[3],
+                               "rng state update"))
                {
-                       printf("not ok %d rng state update\n", 2*i+2);
-                       printf("# Failed, state update differed\n");
-                       printf("#   with initial state %llx %llx %llx %llx\n",
-                              ref_state[0], ref_state[1],
-                              ref_state[2], ref_state[3]);
-                       printf("#   received: %llx %llx %llx %llx\n",
-                              test_state[0], test_state[1],
-                              test_state[2], test_state[3]);
-                       printf("#   expected: %llx %llx %llx %llx\n",
-                              (unsigned long long)s[0],
-                              (unsigned long long)s[1],
-                              (unsigned long long)s[2],
-                              (unsigned long long)s[3]);
-                       ret = EXIT_FAILURE;
-               } else {
-                       printf("ok %d rng state update\n", 2*i+2);
+                       tap_diag("Failed, state update differed");
+                       tap_diag("   with initial state %llx %llx %llx %llx",
+                                                 ref_state[0], ref_state[1],
+                                                 ref_state[2], ref_state[3]);
+                       tap_diag("   received: %llx %llx %llx %llx",
+                                      test_state[0], test_state[1],
+                                      test_state[2], test_state[3]);
+                       tap_diag("   expected: %llx %llx %llx %llx",
+                                      (unsigned long long)s[0],
+                                      (unsigned long long)s[1],
+                                      (unsigned long long)s[2],
+                                      (unsigned long long)s[3]);
                }
        }
 
-       return ret;
+       tap_done();
 }
index 9bc84cf5e76693a431487e0d5722ead4d3fe4a84..b71836950db3d98de82f85b0140e2f489bf4cd20 100644 (file)
 AT_BANNER([Randomized tests])
 
 dnl Verify the RNG implementation
-AT_SETUP([xoshiro256p sanity])
-
-TEST_NEED_PROGRAM([rng-test])
-AT_CHECK([rng-test >out
-grep -v '^ok' out], [0], [1..200
-])
-
-AT_CLEANUP
+TEST_TAP_SIMPLE([xoshiro256p sanity], [rng-test],
+  [TEST_NEED_PROGRAM([rng-test])])
 
 dnl Verify that randomdecl actually produces all keywords and a variety
 dnl of different declarations.