test for two markers on the same line
[ust.git] / tests / runtests
CommitLineData
1518fa0f
PMF
1#!/bin/bash
2
1518fa0f
PMF
3function 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
13function starttest() {
14 echo "------------------------------------"
15 echo "Starting test: $1"
16 echo "------------------------------------"
17}
18
68d19739
PMF
19function 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
32TESTDIR=$(dirname $0)
33MATCHES="$TESTDIR/trace_matches"
34
53bd45cf 35starttest "Test-nevents"
1518fa0f 36NOFAIL usttrace $TESTDIR/test-nevents/prog
68d19739
PMF
37trace_loc=$(usttrace -W)
38NOFAIL $MATCHES -N "an_event (100000)" -n 100000 "^ust.an_event:" $trace_loc
39NOFAIL $MATCHES -N "another_event (100000)" -n 100000 "^ust.another_event:" $trace_loc
40NOFAIL check_trace_logs "$trace_loc"
1518fa0f 41
53bd45cf 42starttest "fork()/exec() test"
1518fa0f 43NOFAIL usttrace -f $TESTDIR/fork/.libs/fork $TESTDIR/fork/.libs/fork2
68d19739
PMF
44trace_loc=$(usttrace -W)
45NOFAIL $MATCHES -N "fork - before_fork" "^ust.before_fork:" $trace_loc
46NOFAIL $MATCHES -N "fork - after_fork_parent" "^ust.after_fork_parent:" $trace_loc
47NOFAIL $MATCHES -N "fork - after_fork_child" "^ust.after_fork_child:" $trace_loc
48NOFAIL $MATCHES -N "fork - before_exec" "^ust.before_exec:" $trace_loc
49NOFAIL $MATCHES -N "fork - potential_exec" "^ust.potential_exec:" $trace_loc
50NOFAIL $MATCHES -N "fork - after_exec" "^ust.after_exec:" $trace_loc
51NOFAIL check_trace_logs "$trace_loc"
1518fa0f 52
30ca09e1
PMF
53starttest "libustinstr-malloc"
54NOFAIL usttrace -lm $TESTDIR/test-libustinstr-malloc/.libs/prog
68d19739 55trace_loc=$(usttrace -W)
30ca09e1 56NOFAIL $MATCHES -N "libustinstr-malloc - malloc" -n 1000 "^ust.malloc:.*{ size = 1[0-9][0-9][0-9]," $trace_loc
68d19739 57NOFAIL check_trace_logs "$trace_loc"
1518fa0f
PMF
58
59### Manual mode test
53bd45cf 60starttest "Manual mode tracing"
1518fa0f
PMF
61TRACE_DIR="/tmp/ust-testsuite-manual-trace"
62rm -rf "$TRACE_DIR"
63mkdir "$TRACE_DIR"
64
3ee8b5be
PMF
65pidfilepath="/tmp/ust-testsuite-$USER-$(date +%Y%m%d%H%M%S%N)-ustd-pid"
66mkfifo -m 0600 "$pidfilepath"
67# It's not useful to run ustd in NOFAIL because it's running in the background
68ustd --pidfile "$pidfilepath" -o "$TRACE_DIR" >/dev/null 2>&1 &
69USTD_PID="$(<$pidfilepath)"
1518fa0f 70
30ca09e1 71LD_PRELOAD=/usr/local/lib/libust.so.0.0.0:/usr/local/lib/libustinstr-malloc.so find / >/dev/null 2>&1 &
1518fa0f
PMF
72PID=$!
73sleep 0.1
74NOFAIL ustctl --list-markers "$PID" >/dev/null
75NOFAIL ustctl --enable-marker ust/malloc $PID
76NOFAIL ustctl --enable-marker ust/free $PID
77NOFAIL ustctl --create-trace $PID
78NOFAIL ustctl --alloc-trace $PID
79NOFAIL ustctl --start-trace $PID
80sleep 0.5
3ee8b5be 81
1518fa0f
PMF
82NOFAIL ustctl --stop-trace $PID
83NOFAIL ustctl --destroy-trace $PID
84kill $PID
3ee8b5be
PMF
85kill -SIGTERM $USTD_PID
86wait $USTD_PID
1518fa0f
PMF
87
88NOFAIL $MATCHES -N "manual - find - ust.malloc" "^ust.malloc:" "$TRACE_DIR"
89
6c42ce2c
PMF
90### Valgrind ustd ###
91starttest "ustd valgrind check"
92TRACE_DIR="/tmp/ust-testsuite-ustdvalgrind-trace"
93rm -rf "$TRACE_DIR"
94mkdir "$TRACE_DIR"
95
96pidfilepath="/tmp/ust-testsuite-$USER-$(date +%Y%m%d%H%M%S%N)-ustd-pid"
97mkfifo -m 0600 "$pidfilepath"
98# It's not useful to run ustd in NOFAIL because it's running in the background
99VALG_OUT=/tmp/ust-testsuite-valg.txt
100valgrind -q ustd --pidfile "$pidfilepath" -o "$TRACE_DIR" >/dev/null 2>"$VALG_OUT" &
101VALG_PID=$!
102USTD_PID="$(<$pidfilepath)"
103
104usttrace -s $TESTDIR/basic/.libs/basic
105
106kill -SIGTERM $USTD_PID
107wait $!
108
109echo "Valgrind output is in $VALG_OUT"
110NOFAIL [ -z "$(<$VALG_OUT)" ]
111
2b9093e1
OEM
112### dlopen ###
113starttest "dlopen"
114LD_LIBRARY_PATH=$TESTDIR/dlopen/.libs NOFAIL usttrace $TESTDIR/dlopen/dlopen
115trace_loc=$(usttrace -W)
116NOFAIL $MATCHES -N "from_library" -n 1 "^ust.from_library:" $trace_loc
117NOFAIL $MATCHES -N "from_main_before_lib" -n 1 "^ust.from_main_before_lib:" $trace_loc
118NOFAIL $MATCHES -N "from_main_after_lib" -n 1 "^ust.from_main_after_lib:" $trace_loc
e73784f2
OEM
119
120### same-line-marker ###
121starttest "same_line_marker"
122NOFAIL usttrace $TESTDIR/same_line_marker/same_line_marker
123trace_loc=$(usttrace -W)
124NOFAIL $MATCHES -N "same_line_event" -n 2 "^ust.same_line_event:" $trace_loc
125
126
1518fa0f
PMF
127echo "************************************"
128echo "$0: All passed"
129echo "************************************"
130exit 0
This page took 0.028461 seconds and 4 git commands to generate.