add hash during testing
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 15 Jul 2024 14:53:40 +0000 (16:53 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 15 Jul 2024 14:53:40 +0000 (16:53 +0200)
checkers.c
function.c
function.h
makefile
test.c [new file with mode: 0644]

index 92d86f65fd67a1c5ce6bfad80be10f7b802e10e8..4f7c8719a8adb0a95f869f4b0a27a9ec8ad24f6f 100644 (file)
@@ -24,6 +24,7 @@ char *boardname = "10x10";
 char *filename = NULL;
 int maxnbrecords = 0;
 int scale = 2;
+int dohash = 0;
 
 int xoffset = 1;
 int yoffset = 1;
@@ -422,6 +423,10 @@ int main (int argc, char *argv[])
 
     endwin ();
 
+    if (dohash) {
+        printf ("hash: 0x%08x\n", computehash (board->tab));
+    }
+
     if (nbrecords) {
         int i;
         printf ("records: ");
index 41a5722c7cb50775d38e8ccc474b56430a83ead3..bac20911b1acb839c643404de6a5a4ba6c9f985b 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -597,4 +598,15 @@ void freecache (cache_t *cache)
     free (cache);
 }
 
+uint32_t computehash (char *key)
+{
+  uint32_t hash = 3323198485ul;
+  for (;*key;++key) {
+    hash ^= *key;
+    hash *= 0x5bd1e995;
+    hash ^= hash >> 15;
+  }
+  return hash;
+}
+
 /* vim: set ts=4 sw=4 et: */
index 11fc14800d2bee362af6a46ff33523e7dde06249..e48e4c5fa43368184343f70026092d7d359a4259 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __FUNCTION_H__
 #define __FUNCTION_H__
 
+#include <stdint.h>
+
 #include "type.h"
 
 #define CHECKALLOC(ptr) \
@@ -83,6 +85,8 @@ void emptycache (cache_t *cache);
 
 void freecache (cache_t *cache);
 
+uint32_t computehash (char *key);
+
 #endif /* __FUNCTION_H__ */
 
 /* vim: set ts=4 sw=4 et: */
index 436ffbcfde5341df98d545a6081219848d05c82f..7329ad3bc2f7fb467c6c3f0a72e8e018c2d160f6 100644 (file)
--- a/makefile
+++ b/makefile
@@ -88,7 +88,9 @@ wipe: purge
        rm -f wipe $(wildcard *.gcda *.gcno *.gcov *.glog)
        $(call PASS, SUCCESS)
 
-tests: all
+tests: test.o
+       -rm -f $(ALLEXE)
+       LDFLAGS="$$LDFLAGS test.o" $(MAKE) all
        $(MAKE) $(addprefix test_,$(ALLEXE))
 
 ## Main rules
diff --git a/test.c b/test.c
new file mode 100644 (file)
index 0000000..47fa970
--- /dev/null
+++ b/test.c
@@ -0,0 +1,7 @@
+void __attribute__((constructor)) _checker (void)
+{
+    extern int dohash;
+    dohash = 1;
+}
+
+/* vim: set ts=4 sw=4 et: */