2 # check for errors under valgrind or sanitizers.
6 echo "instrumented testing failed on line $1"
9 trap 'error ${LINENO}' ERR
11 # define suitable post and prefixes for testing options
14 echo "valgrind testing started"
16 exeprefix='valgrind --error-exitcode=42 --errors-for-leak-kinds=all --leak-check=full'
21 echo "valgrind-thread testing started"
23 exeprefix='valgrind --fair-sched=try --error-exitcode=42'
27 --sanitizer-undefined)
28 echo "sanitizer-undefined testing started"
31 postfix='2>&1 | grep -A50 "runtime error:"'
35 echo "sanitizer-thread testing started"
38 postfix='2>&1 | grep -A50 "WARNING: ThreadSanitizer:"'
41 cat << EOF > tsan.supp
42 race:Stockfish::TTEntry::move
43 race:Stockfish::TTEntry::depth
44 race:Stockfish::TTEntry::bound
45 race:Stockfish::TTEntry::save
46 race:Stockfish::TTEntry::value
47 race:Stockfish::TTEntry::eval
48 race:Stockfish::TTEntry::is_pv
50 race:Stockfish::TranspositionTable::probe
51 race:Stockfish::TranspositionTable::hashfull
55 export TSAN_OPTIONS="suppressions=./tsan.supp"
59 echo "unknown testing started"
67 # simple command line testing
72 "go wtime 8000 btime 8000 winc 500 binc 500" \
73 "bench 128 $threads 8 default depth" \
74 "export_net verify.nnue"
77 echo "$prefix $exeprefix ./stockfish $args $postfix"
78 eval "$prefix $exeprefix ./stockfish $args $postfix"
82 # verify the generated net equals the base net
83 network=`./stockfish uci | grep 'option name EvalFile type string default' | awk '{print $NF}'`
84 echo "Comparing $network to the written verify.nnue"
85 diff $network verify.nnue
87 # more general testing, following an uci protocol exchange
90 spawn $exeprefix ./stockfish
95 send "setoption name Threads value $threads\n"
98 send "position startpos\n"
99 send "go nodes 1000\n"
102 send "position startpos moves e2e4 e7e6\n"
103 send "go nodes 1000\n"
106 send "position fen 5rk1/1K4p1/8/8/3B4/8/8/8 b - - 0 1\n"
113 # return error code of the spawned program, useful for valgrind
114 lassign [wait] pid spawnid os_error_flag value
118 #download TB as needed
119 if [ ! -d ../tests/syzygy ]; then
120 curl -sL https://api.github.com/repos/niklasf/python-chess/tarball/9b9aa13f9f36d08aadfabff872882f4ab1494e95 | tar -xzf -
121 mv niklasf-python-chess-9b9aa13 ../tests/syzygy
124 cat << EOF > syzygy.exp
126 spawn $exeprefix ./stockfish
128 send "setoption name SyzygyPath value ../tests/syzygy/\n"
129 expect "info string Found 35 tablebases" {} timeout {exit 1}
130 send "bench 128 1 8 default depth\n"
134 # return error code of the spawned program, useful for valgrind
135 lassign [wait] pid spawnid os_error_flag value
139 for exp in game.exp syzygy.exp
142 echo "$prefix expect $exp $postfix"
143 eval "$prefix expect $exp $postfix"
151 echo "instrumented testing OK"