Commit | Line | Data |
---|---|---|
1518fa0f PMF |
1 | #!/bin/bash |
2 | ||
1518fa0f PMF |
3 | function NOFAIL() { |
4 | "$@" | |
5 | if [ "$?" -ne "0" ]; then | |
6 | echo "!!!!!!!!!!!!!!!!!!!!!!!!" | |
7 | echo "$0: Stopping because of error" | |
8 | echo "!!!!!!!!!!!!!!!!!!!!!!!!" | |
9 | exit 1; | |
10 | fi | |
11 | } | |
12 | ||
53bd45cf PMF |
13 | function starttest() { |
14 | echo "------------------------------------" | |
15 | echo "Starting test: $1" | |
16 | echo "------------------------------------" | |
17 | } | |
18 | ||
68d19739 PMF |
19 | function check_trace_logs() { |
20 | TRACE=$1 | |
21 | ||
22 | for f in $(ls $1/*.log); do | |
23 | NLINES=$(egrep "Warning|Error" $f | wc -l) | |
24 | if [ "$NLINES" -ne "0" ]; then | |
25 | echo "Errors/warnings found in $f" | |
26 | return 1; | |
27 | fi | |
28 | done | |
29 | return 0; | |
30 | } | |
31 | ||
1518fa0f PMF |
32 | TESTDIR=$(dirname $0) |
33 | MATCHES="$TESTDIR/trace_matches" | |
34 | ||
53bd45cf | 35 | starttest "Test-nevents" |
1518fa0f | 36 | NOFAIL usttrace $TESTDIR/test-nevents/prog |
68d19739 PMF |
37 | trace_loc=$(usttrace -W) |
38 | NOFAIL $MATCHES -N "an_event (100000)" -n 100000 "^ust.an_event:" $trace_loc | |
39 | NOFAIL $MATCHES -N "another_event (100000)" -n 100000 "^ust.another_event:" $trace_loc | |
40 | NOFAIL check_trace_logs "$trace_loc" | |
1518fa0f | 41 | |
53bd45cf | 42 | starttest "fork()/exec() test" |
1518fa0f | 43 | NOFAIL usttrace -f $TESTDIR/fork/.libs/fork $TESTDIR/fork/.libs/fork2 |
68d19739 PMF |
44 | trace_loc=$(usttrace -W) |
45 | NOFAIL $MATCHES -N "fork - before_fork" "^ust.before_fork:" $trace_loc | |
46 | NOFAIL $MATCHES -N "fork - after_fork_parent" "^ust.after_fork_parent:" $trace_loc | |
47 | NOFAIL $MATCHES -N "fork - after_fork_child" "^ust.after_fork_child:" $trace_loc | |
48 | NOFAIL $MATCHES -N "fork - before_exec" "^ust.before_exec:" $trace_loc | |
49 | NOFAIL $MATCHES -N "fork - potential_exec" "^ust.potential_exec:" $trace_loc | |
50 | NOFAIL $MATCHES -N "fork - after_exec" "^ust.after_exec:" $trace_loc | |
51 | NOFAIL check_trace_logs "$trace_loc" | |
1518fa0f | 52 | |
30ca09e1 PMF |
53 | starttest "libustinstr-malloc" |
54 | NOFAIL usttrace -lm $TESTDIR/test-libustinstr-malloc/.libs/prog | |
68d19739 | 55 | trace_loc=$(usttrace -W) |
30ca09e1 | 56 | NOFAIL $MATCHES -N "libustinstr-malloc - malloc" -n 1000 "^ust.malloc:.*{ size = 1[0-9][0-9][0-9]," $trace_loc |
68d19739 | 57 | NOFAIL check_trace_logs "$trace_loc" |
1518fa0f PMF |
58 | |
59 | ### Manual mode test | |
53bd45cf | 60 | starttest "Manual mode tracing" |
1518fa0f PMF |
61 | TRACE_DIR="/tmp/ust-testsuite-manual-trace" |
62 | rm -rf "$TRACE_DIR" | |
63 | mkdir "$TRACE_DIR" | |
64 | ||
3ee8b5be PMF |
65 | pidfilepath="/tmp/ust-testsuite-$USER-$(date +%Y%m%d%H%M%S%N)-ustd-pid" |
66 | mkfifo -m 0600 "$pidfilepath" | |
67 | # It's not useful to run ustd in NOFAIL because it's running in the background | |
68 | ustd --pidfile "$pidfilepath" -o "$TRACE_DIR" >/dev/null 2>&1 & | |
69 | USTD_PID="$(<$pidfilepath)" | |
1518fa0f | 70 | |
30ca09e1 | 71 | LD_PRELOAD=/usr/local/lib/libust.so.0.0.0:/usr/local/lib/libustinstr-malloc.so find / >/dev/null 2>&1 & |
1518fa0f PMF |
72 | PID=$! |
73 | sleep 0.1 | |
74 | NOFAIL ustctl --list-markers "$PID" >/dev/null | |
75 | NOFAIL ustctl --enable-marker ust/malloc $PID | |
76 | NOFAIL ustctl --enable-marker ust/free $PID | |
77 | NOFAIL ustctl --create-trace $PID | |
78 | NOFAIL ustctl --alloc-trace $PID | |
79 | NOFAIL ustctl --start-trace $PID | |
80 | sleep 0.5 | |
3ee8b5be | 81 | |
1518fa0f PMF |
82 | NOFAIL ustctl --stop-trace $PID |
83 | NOFAIL ustctl --destroy-trace $PID | |
84 | kill $PID | |
3ee8b5be PMF |
85 | kill -SIGTERM $USTD_PID |
86 | wait $USTD_PID | |
1518fa0f PMF |
87 | |
88 | NOFAIL $MATCHES -N "manual - find - ust.malloc" "^ust.malloc:" "$TRACE_DIR" | |
89 | ||
6c42ce2c PMF |
90 | ### Valgrind ustd ### |
91 | starttest "ustd valgrind check" | |
92 | TRACE_DIR="/tmp/ust-testsuite-ustdvalgrind-trace" | |
93 | rm -rf "$TRACE_DIR" | |
94 | mkdir "$TRACE_DIR" | |
95 | ||
96 | pidfilepath="/tmp/ust-testsuite-$USER-$(date +%Y%m%d%H%M%S%N)-ustd-pid" | |
97 | mkfifo -m 0600 "$pidfilepath" | |
98 | # It's not useful to run ustd in NOFAIL because it's running in the background | |
99 | VALG_OUT=/tmp/ust-testsuite-valg.txt | |
100 | valgrind -q ustd --pidfile "$pidfilepath" -o "$TRACE_DIR" >/dev/null 2>"$VALG_OUT" & | |
101 | VALG_PID=$! | |
102 | USTD_PID="$(<$pidfilepath)" | |
103 | ||
104 | usttrace -s $TESTDIR/basic/.libs/basic | |
105 | ||
106 | kill -SIGTERM $USTD_PID | |
107 | wait $! | |
108 | ||
109 | echo "Valgrind output is in $VALG_OUT" | |
110 | NOFAIL [ -z "$(<$VALG_OUT)" ] | |
111 | ||
5f06028d PMF |
112 | ### Valgrind libust ### |
113 | starttest "libust valgrind check" | |
114 | ||
1518fa0f PMF |
115 | echo "************************************" |
116 | echo "$0: All passed" | |
117 | echo "************************************" | |
118 | exit 0 |