-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·103 lines (89 loc) · 2.57 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env zsh
VALGRIND_OPT=( "--tool=memcheck" "--track-origins=yes" "--read-var-info=yes" )
VG_MEMCHECK_OPT=( "--leak-check=full" "--show-leak-kinds=all" "--leak-check-heuristics=all" "--keep-stacktraces=alloc-and-free" "--track-fds=yes" "--errors-for-leak-kinds=all" "--error-exitcode=1" "--suppressions=valgrind-suppressions.txt")
#expensive definedness checks (newish option)
#VG_MEMCHECK_OPT+=( "--expensive-definedness-checks=yes")
#long stack traces
VG_MEMCHECK_OPT+=("--num-callers=20")
#generate suppresions
#VG_MEMCHECK_OPT+=("--gen-suppressions=all")
#track files
#VG_MEMCHECK_OPT+=("--track-fds=yes")
TEST=build/shuso_test
TEST_OPT=()
DEBUGGER_NAME="kdbg"
DEBUGGER_CMD="dbus-run-session kdbg -p %s $TEST"
for opt in $*; do
case $opt in
leak|leakcheck|valgrind|memcheck)
valgrind=1
VALGRIND_OPT+=($VG_MEMCHECK_OPT);;
debug-memcheck)
valgrind=1
VALGRIND_OPT+=($VG_MEMCHECK_OPT)
VALGRIND_OPT+=( "--vgdb=yes" "--vgdb-error=1" )
#ATTACH_DDD=1
;;
debug)
debugger=1
;;
sanitize-undefined)
FSANITIZE_UNDEFINED=1
;;
callgrind|profile)
VALGRIND_OPT=( "--tool=callgrind" "--collect-jumps=yes" "--collect-systime=yes" "--branch-sim=yes" "--cache-sim=yes" "--simulate-hwpref=yes" "--simulate-wb=yes" "--callgrind-out-file=callgrind-shuttlesock.out")
valgrind=1;;
helgrind)
VALGRIND_OPT=( "--tool=helgrind" "--free-is-write=yes")
valgrind=1
;;
cachegrind)
VALGRIND_OPT=( "--tool=cachegrind" )
valgrind=1;;
verbose)
TEST_OPT+=("--verbose")
;;
*)
TEST_OPT+=("$opt")
;;
esac
done
export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer
export ASAN_OPTIONS=symbolize=1
debugger_pids=()
TRAPINT() {
if [[ $debugger == 1 ]]; then
sudo kill $debugger_pids
fi
}
attach_debugger() {
master_pid=`cat /tmp/shuttlesock-test-master.pid`
while [[ -z $child_pids ]]; do
if [[ -z $child_text_match ]]; then
child_pids=`pgrep -P $master_pid`
else
child_pids=`pgrep -P $master_pid -f $child_text_match`
fi
sleep 0.1
done
while read -r line; do
echo "attaching $1 to $line"
sudo $(printf $2 $line) &
debugger_pids+="$!"
done <<< $child_pids
echo "$1 at $debugger_pids"
}
if [[ ! -f $TEST ]]; then
echo "$TEST not found"
exit 1
fi
if [[ $debugger == 1 ]]; then
sudo kdbg -a "$TEST_OPT" "$TEST"
elif [[ $valgrind == 1 ]]; then
echo $SUDO valgrind $VALGRIND_OPT $TEST $TEST_OPT
$SUDO valgrind $VALGRIND_OPT $TEST $TEST_OPT
else
echo $SUDO $TEST $TEST_OPT
$SUDO $TEST $TEST_OPT &
wait $!
fi