Tests: fix racy tests and misleading output messages
[lttng-tools.git] / tests / regression / ust / before-after / test_before_after
1 #!/bin/bash
2 #
3 # Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
4 #
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 TEST_DESC="UST tracer - Start tracing before and after execution"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 NR_ITER=100
22 NR_USEC_WAIT=100000
23 TESTAPP_PATH="$TESTDIR/utils/testapp"
24 TESTAPP_NAME="gen-ust-events"
25 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
26 SESSION_NAME="per-session"
27 EVENT_NAME="tp:tptest"
28 NUM_TESTS=17
29
30 source $TESTDIR/utils/utils.sh
31
32 if [ ! -x "$TESTAPP_BIN" ]; then
33 BAIL_OUT "No UST nevents binary detected."
34 fi
35
36 # MUST set TESTDIR before calling those functions
37
38 function wait_app()
39 {
40 while [ -n "$(pidof $TESTAPP_NAME)" ]; do
41 sleep 0.5
42 done
43 pass "Application $TESTAPP_NAME ended."
44 }
45
46 function test_before_apps()
47 {
48 # BEFORE application is spawned
49 create_lttng_session $SESSION_NAME $TRACE_PATH
50 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
51 start_lttng_tracing $SESSION_NAME
52
53 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
54 ok $? "Traced application stopped."
55
56 stop_lttng_tracing $SESSION_NAME
57 destroy_lttng_session $SESSION_NAME
58
59 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
60
61 return $?
62 }
63
64 function test_after_apps()
65 {
66 local out
67
68 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
69 ok $? "Application started in background."
70
71 # BEFORE application is spawned
72 create_lttng_session $SESSION_NAME $TRACE_PATH
73 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
74 start_lttng_tracing $SESSION_NAME
75
76 # Since the start is done after the application is started, there is a
77 # bootstrap time needed between the session daemon and the UST tracer.
78 # Waiting for the application to end tells us when to stop everything and
79 # validate that at least one event is seen.
80 wait_app
81
82 stop_lttng_tracing $SESSION_NAME
83 destroy_lttng_session $SESSION_NAME
84
85 validate_trace $EVENT_NAME $TRACE_PATH
86 out=$?
87
88 return $out
89 }
90
91 # MUST set TESTDIR before calling those functions
92 plan_tests $NUM_TESTS
93
94 print_test_banner "$TEST_DESC"
95
96 start_lttng_sessiond
97
98 diag "Start tracing BEFORE application is started"
99
100 TRACE_PATH=$(mktemp -d)
101
102 test_before_apps
103 out=$?
104 if [ $out -ne 0 ]; then
105 stop_lttng_sessiond
106 exit $out
107 fi
108
109 rm -rf $TRACE_PATH
110
111 diag "Start tracing AFTER application is started"
112
113 TRACE_PATH=$(mktemp -d)
114
115 test_after_apps
116 out=$?
117 if [ $out -ne 0 ]; then
118 stop_lttng_sessiond
119 exit $out
120 fi
121
122 stop_lttng_sessiond
123
124 rm -rf $TRACE_PATH
This page took 0.035172 seconds and 6 git commands to generate.