]> git.sesse.net Git - stockfish/blob - tests/instrumented.sh
Retire lever (#1378)
[stockfish] / tests / instrumented.sh
1 #!/bin/bash
2 # check for errors under valgrind or sanitizers.
3
4 error()
5 {
6   echo "instrumented testing failed on line $1"
7   exit 1
8 }
9 trap 'error ${LINENO}' ERR
10
11 # define suitable post and prefixes for testing options
12 case $1 in
13   --valgrind)
14     echo "valgrind testing started"
15     prefix=''
16     exeprefix='valgrind --error-exitcode=42'
17     postfix='1>/dev/null'
18     threads="1"
19   ;;
20   --valgrind-thread)
21     echo "valgrind-thread testing started"
22     prefix=''
23     exeprefix='valgrind --error-exitcode=42'
24     postfix='1>/dev/null'
25     threads="2"
26   ;;
27   --sanitizer-undefined)
28     echo "sanitizer-undefined testing started"
29     prefix='!'
30     exeprefix=''
31     postfix='2>&1 | grep "runtime error:"'
32     threads="1"
33   ;;
34   --sanitizer-thread)
35     echo "sanitizer-thread testing started"
36     prefix='!'
37     exeprefix=''
38     postfix='2>&1 | grep "WARNING: ThreadSanitizer:"'
39     threads="2"
40
41 cat << EOF > tsan.supp
42 race:TTEntry::move
43 race:TTEntry::depth
44 race:TTEntry::bound
45 race:TTEntry::save
46 race:TTEntry::value
47 race:TTEntry::eval
48
49 race:TranspositionTable::probe
50 race:TranspositionTable::hashfull
51
52 EOF
53
54     export TSAN_OPTIONS="suppressions=./tsan.supp"
55
56   ;;
57   *)
58     echo "unknown testing started"
59     prefix=''
60     exeprefix=''
61     postfix=''
62     threads="1"
63   ;;
64 esac
65
66 # simple command line testing
67 for args in "eval" \
68             "go nodes 1000" \
69             "go depth 10" \
70             "go movetime 1000" \
71             "go wtime 8000 btime 8000 winc 500 binc 500" \
72             "bench 128 $threads 10 default depth"
73 do
74
75    echo "$prefix $exeprefix ./stockfish $args $postfix"
76    eval "$prefix $exeprefix ./stockfish $args $postfix"
77
78 done
79
80 # more general testing, following an uci protocol exchange
81 cat << EOF > game.exp
82  set timeout 10
83  spawn $exeprefix ./stockfish
84
85  send "uci\n"
86  expect "uciok"
87
88  send "setoption name Threads value $threads\n"
89
90  send "ucinewgame\n"
91  send "position startpos\n"
92  send "go nodes 1000\n"
93  expect "bestmove"
94
95  send "position startpos moves e2e4 e7e6\n"
96  send "go nodes 1000\n"
97  expect "bestmove"
98
99  send "position fen 5rk1/1K4p1/8/8/3B4/8/8/8 b - - 0 1\n"
100  send "go depth 30\n"
101  expect "bestmove"
102
103  send "quit\n"
104  expect eof
105
106  # return error code of the spawned program, useful for valgrind
107  lassign [wait] pid spawnid os_error_flag value
108  exit \$value
109 EOF
110
111 for exps in game.exp
112 do
113
114   echo "$prefix expect $exps $postfix"
115   eval "$prefix expect $exps $postfix"
116
117   rm $exps
118
119 done
120
121 rm -f tsan.supp
122
123 echo "instrumented testing OK"