From 9dd7c7064d6e494efb14cdaa85324139d80f385c Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Wed, 11 Sep 2024 08:09:40 +0200 Subject: [PATCH] perft-test: improve displayed info, add selective tests - print total #tests, #tests to do and VERSION string - add starting point for tests, and #tests to run --- Makefile | 10 +++++----- test/common-test.h | 7 ++++++- test/perft-test.c | 26 +++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index f65a209..32456bc 100644 --- a/Makefile +++ b/Makefile @@ -126,7 +126,7 @@ else # ifeq ($(build),dev) # fen.c #CPPFLAGS += -DDEBUG_FEN # FEN decoding # hash / TT - #CPPFLAGS += -DZOBRIST_VERIFY # double chk zobrist + CPPFLAGS += -DZOBRIST_VERIFY # double chk zobrist #CPPFLAGS += -DPERFT_MOVE_HISTORY # perft, keep prev moves # attack.c #CPPFLAGS += -DDEBUG_ATTACK_ATTACKERS # sq_attackers @@ -229,16 +229,16 @@ else all: libs testing $(TARGET) release: - $(MAKE) BUILD=release clean all + $(MAKE) build=release clean all dev: - $(MAKE) BUILD=dev clean all + $(MAKE) build=dev clean all perf: - $(MAKE) BUILD=perf clean all + $(MAKE) build=perf clean all debug: - $(MAKE) BUILD=debug clean all + $(MAKE) build=debug clean all compile: brlib objs diff --git a/test/common-test.h b/test/common-test.h index dad6aad..7d17406 100644 --- a/test/common-test.h +++ b/test/common-test.h @@ -451,7 +451,12 @@ struct fentest { static int fentest_cur = -1; -static char *next_fen(uint module) +static __unused void restart_fen(void) +{ + fentest_cur = -1; +} + +static __unused char *next_fen(uint module) { fentest_cur++; diff --git a/test/perft-test.c b/test/perft-test.c index d8cab81..9299a6c 100644 --- a/test/perft-test.c +++ b/test/perft-test.c @@ -242,7 +242,9 @@ static int usage(char *prg) fprintf(stderr, "Usage: %s [-cms][-d depth] [-p version] [-t size:\n", prg); fprintf(stderr, "\t-c: do *not* print FEN comments\n"); fprintf(stderr, "\t-d depth: perft depth (default: 6)\n"); + fprintf(stderr, "\t-l line: start from 'line' test\n"); fprintf(stderr, "\t-m: print moves details\n"); + fprintf(stderr, "\t-n number: do 'number' tests (default: all)\n"); fprintf(stderr, "\t-s: use Stockfish to validate perft result\n"); fprintf(stderr, "\t-t size: Transposition Table size (Mb). Default: 32\n"); fprintf(stderr, @@ -252,7 +254,7 @@ static int usage(char *prg) int main(int ac, char**av) { - int curtest = 0; + int curtest = 0, totalfen = 0; u64 sf_count = 0, my_count; bool comment = true, sf_run = false, divide = false; char *fen; @@ -262,6 +264,8 @@ int main(int ac, char**av) FILE *outfd = NULL; s64 ms, lps; int opt, depth = 6, run = 3, tt, newtt = HASH_SIZE_DEFAULT; + int startline = 1, ntests = INT_MAX; + struct { s64 count, countskipped, ms; s64 minlps, maxlps; @@ -273,7 +277,8 @@ int main(int ac, char**av) { .minlps = LONG_MAX }, }; - while ((opt = getopt(ac, av, "cd:mp:st:")) != -1) { + printf("Perft " VERSION "\n"); + while ((opt = getopt(ac, av, "cd:l:mn:p:st:")) != -1) { switch (opt) { case 'c': comment = false; @@ -283,9 +288,15 @@ int main(int ac, char**av) if (depth <= 0) depth = 6; break; + case 'l': + startline = atoi(optarg); + break; case 'm': divide = true; break; + case 'n': + ntests = atoi(optarg); + break; case 'p': run = atoi(optarg); break; @@ -325,14 +336,23 @@ int main(int ac, char**av) if (sf_run) outfd = open_stockfish(); + /* count total fen tests we will do */ + while (next_fen(PERFT | MOVEDO)) + totalfen++; + restart_fen(); + CLOCK_DEFINE(clock, CLOCK_MONOTONIC); while ((fen = next_fen(PERFT | MOVEDO))) { + if (cur_line() < startline) + continue; + if (curtest >= ntests) + break; if (!(fenpos = fen2pos(pos, fen))) { printf("wrong fen line:%d fen:%s\n\n", cur_line(), fen); continue; } curtest++; - printf("test:%d line:%d fen:%s\n", curtest, cur_line(), fen); + printf("test:%d/%d line:%d fen:%s\n", curtest, totalfen, cur_line(), fen); if (comment) printf("\t\"%s\"\n", *cur_comment()? cur_comment(): "no test desc");