Fix: Tests with racy event validation
[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=16
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 test_before_apps()
39 {
40 # BEFORE application is spawned
41 create_lttng_session $SESSION_NAME $TRACE_PATH
42 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
43 start_lttng_tracing $SESSION_NAME
44
45 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
46 ok $? "Traced application stopped."
47
48 stop_lttng_tracing $SESSION_NAME
49 destroy_lttng_session $SESSION_NAME
50
51 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
52
53 return $?
54 }
55
56 function test_after_apps()
57 {
58 local out
59
60 create_lttng_session $SESSION_NAME $TRACE_PATH
61 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
62
63 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
64 ok $? "Application started in background."
65
66 start_lttng_tracing $SESSION_NAME
67
68 wait ${!}
69
70 stop_lttng_tracing $SESSION_NAME
71 destroy_lttng_session $SESSION_NAME
72
73 validate_trace $EVENT_NAME $TRACE_PATH
74 out=$?
75
76 return $out
77 }
78
79 # MUST set TESTDIR before calling those functions
80 plan_tests $NUM_TESTS
81
82 print_test_banner "$TEST_DESC"
83
84 start_lttng_sessiond
85
86 diag "Start tracing BEFORE application is started"
87
88 TRACE_PATH=$(mktemp -d)
89
90 test_before_apps
91 out=$?
92 if [ $out -ne 0 ]; then
93 stop_lttng_sessiond
94 exit $out
95 fi
96
97 rm -rf $TRACE_PATH
98
99 diag "Start tracing AFTER application is started"
100
101 TRACE_PATH=$(mktemp -d)
102
103 test_after_apps
104 out=$?
105 if [ $out -ne 0 ]; then
106 stop_lttng_sessiond
107 exit $out
108 fi
109
110 stop_lttng_sessiond
111
112 rm -rf $TRACE_PATH
This page took 0.034834 seconds and 6 git commands to generate.