From cb2b6ddee27ad5d2e63c1f50cc8af632eea85dc6 Mon Sep 17 00:00:00 2001 From: Laurent MAZET Date: Mon, 15 Jul 2024 16:53:40 +0200 Subject: [PATCH] add hash during testing --- checkers.c | 5 +++++ function.c | 12 ++++++++++++ function.h | 4 ++++ makefile | 4 +++- test.c | 7 +++++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test.c diff --git a/checkers.c b/checkers.c index 92d86f6..4f7c871 100644 --- a/checkers.c +++ b/checkers.c @@ -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: "); diff --git a/function.c b/function.c index 41a5722..bac2091 100644 --- a/function.c +++ b/function.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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: */ diff --git a/function.h b/function.h index 11fc148..e48e4c5 100644 --- a/function.h +++ b/function.h @@ -1,6 +1,8 @@ #ifndef __FUNCTION_H__ #define __FUNCTION_H__ +#include + #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: */ diff --git a/makefile b/makefile index 436ffbc..7329ad3 100644 --- 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 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: */ -- 2.30.2