]> git.draconx.ca Git - rrace.git/commitdiff
tests: Skip reference RNG test on old compilers.
authorNick Bowler <nbowler@draconx.ca>
Sun, 7 Jan 2024 03:34:22 +0000 (22:34 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sun, 7 Jan 2024 03:34:22 +0000 (22:34 -0500)
The reference implementation for xoshiro256** uses C99-style for loop
declarations, which cannot be compiled on some implementations (incl.
all versions of GCC in gnu89 mode).

Rather than changing the reference code (which kinda defeats the point)
arrange for the test to be skipped unless compiler support is available.

Makefile.am
configure.ac
t/rng-test.c
tests/game.at

index ea546a8ca328270671df072c520045080e0b4326..dd3c0d2bd3f53d87f60088b0dc4c29bd73ec5815 100644 (file)
@@ -108,7 +108,6 @@ EXTRA_DIST += t/game-notime.h t/xos256ss.c
 
 $(t_boardbit_OBJECTS): $(gnulib_headers)
 $(t_overlaygoal_OBJECTS): $(gnulib_headers)
-$(t_rng_test_OBJECTS): $(gnulib_headers)
 
 t_boardmove_SOURCES = t/boardmove.c src/game.c
 $(t_boardmove_OBJECTS): $(gnulib_headers)
@@ -126,6 +125,9 @@ $(t_ewmhicon_OBJECTS): $(gnulib_headers)
 t_initboard_SOURCES = t/initboard.c src/game.c
 $(t_initboard_OBJECTS): $(gnulib_headers)
 
+t_rng_test_SOURCES = t/rng-test.c common/src/tap.c
+$(t_rng_test_OBJECTS): $(gnulib_headers)
+
 XPMICONS_LOCOLOR = data/lo16x16.xpm data/lo32x32.xpm data/lo48x48.xpm
 XPMICONS_HICOLOR = data/hi16x16.xpm data/hi24x24.xpm \
                    data/hi32x32.xpm data/hi48x48.xpm
index 0042b3715b8d39b9ef4361fb7e6fbb2e9bdd6b57..9f290c113c11f6ad243f4dfb14ce7bd282155cf7 100644 (file)
@@ -16,8 +16,9 @@ DX_AUTOMAKE_COMPAT
 AC_PROG_CC_C99
 gl_EARLY
 
-AC_C_FLEXIBLE_ARRAY_MEMBER
 AC_C_INLINE
+AC_C_FLEXIBLE_ARRAY_MEMBER
+DX_C_FOR_DECLARATIONS
 
 LT_INIT
 gl_INIT
index 9d27f3838d1b551d650f6ef45d7625083d9bc9fd..e141c0dd462f9c857616bd3404db9dc3c96aaf9e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Test case for xoshiro256** implementation.
- * Copyright © 2022-2023 Nick Bowler
+ * Copyright © 2022-2024 Nick Bowler
  *
  * Directly compare the game RNG against the reference implementation.
  *
  */
 
 #include <config.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include "tap.h"
 
+#if !HAVE_FOR_DECLS
+int main(void)
+{
+       tap_skip_all("cannot compile reference xoshiro256**");
+}
+#else
 #include "game-notime.h"
 #include "game.c"
 #include "xos256ss.c"
@@ -33,7 +38,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);
@@ -43,40 +48,34 @@ int main(void)
                ref_result = next();
                test_result = xoshiro256ss(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();
 }
+#endif
index 7defcdb15ff737dec5c6b7bc40b815e6afcf8b23..7084f6fd0078bf59cb11f020a33c8864d49a8009 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright © 2022-2023 Nick Bowler
+# Copyright © 2022-2024 Nick Bowler
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -592,13 +592,7 @@ AT_CHECK([boardmove m4_do(
 
 AT_CLEANUP
 
-AT_SETUP([xoshiro256** sanity])
-
-AT_CHECK([rng-test >out
-grep -v '^ok' out], [0], [1..200
-])
-
-AT_CLEANUP
+TEST_TAP_SIMPLE([xoshiro256** sanity], [rng-test])
 
 AT_SETUP([game_check_goal])