]> git.sesse.net Git - stockfish/blob - tests/instrumented.sh
Fix multiPV issue #502
[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   ;;
19   --sanitizer)
20     echo "sanitizer testing started"
21     prefix='!'
22     exeprefix=''
23     postfix='2>&1 | grep "runtime error:"'
24   ;;
25   *)
26     echo "unknown testing started"
27     prefix=''
28     exeprefix=''
29     postfix=''
30   ;;
31 esac
32
33 # simple command line testing
34 for args in "eval" \
35             "go nodes 1000" \
36             "go depth 10" \
37             "go movetime 1000" \
38             "go wtime 8000 btime 8000 winc 500 binc 500" \
39             "bench 128 1 10 default depth"
40 do
41
42    echo "$prefix $exeprefix ./stockfish $args $postfix"
43    eval "$prefix $exeprefix ./stockfish $args $postfix"
44
45 done
46
47 # more general testing, following an uci protocol exchange
48 cat << EOF > game.exp
49  set timeout 10
50  spawn $exeprefix ./stockfish
51
52  send "uci\n"
53  expect "uciok"
54
55  send "ucinewgame\n"
56  send "position startpos\n"
57  send "go nodes 1000\n"
58  expect "bestmove"
59
60  send "position startpos moves e2e4 e7e6\n"
61  send "go nodes 1000\n"
62  expect "bestmove"
63
64  send "position fen 5rk1/1K4p1/8/8/3B4/8/8/8 b - - 0 1\n"
65  send "go depth 30\n"
66  expect "bestmove"
67
68  send "quit\n"
69  expect eof
70
71  # return error code of the spawned program, useful for valgrind
72  lassign [wait] pid spawnid os_error_flag value
73  exit \$value
74 EOF
75
76 for exps in game.exp
77 do
78
79   echo "$prefix expect game.exp $postfix"
80   eval "$prefix expect game.exp $postfix"
81
82 done
83
84 rm game.exp
85
86 echo "instrumented testing OK"