237e21b916bb5567c489faa2dcb36fc874738a3f
[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_ok $SESSION_NAME $TRACE_PATH
42 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
43 start_lttng_tracing_ok $SESSION_NAME
44
45 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
46 wait
47 ok $? "Traced application stopped."
48
49 stop_lttng_tracing_ok $SESSION_NAME
50 destroy_lttng_session_ok $SESSION_NAME
51
52 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
53
54 return $?
55 }
56
57 function test_after_apps()
58 {
59 local out
60 local file_sync_after_first=$(mktemp -u)
61 local file_sync_before_last=$(mktemp -u)
62
63 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
64 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
65
66 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
67 --sync-after-first-event ${file_sync_after_first} \
68 --sync-before-last-event ${file_sync_before_last} &
69 ok $? "Application started in background."
70
71 start_lttng_tracing_ok $SESSION_NAME
72
73 touch ${file_sync_before_last}
74
75 wait
76
77 stop_lttng_tracing_ok $SESSION_NAME
78 destroy_lttng_session_ok $SESSION_NAME
79
80 rm -f ${file_sync_after_first}
81 rm -f ${file_sync_before_last}
82
83 validate_trace $EVENT_NAME $TRACE_PATH
84 out=$?
85
86 return $out
87 }
88
89 # MUST set TESTDIR before calling those functions
90 plan_tests $NUM_TESTS
91
92 print_test_banner "$TEST_DESC"
93
94 start_lttng_sessiond
95
96 diag "Start tracing BEFORE application is started"
97
98 TRACE_PATH=$(mktemp -d)
99
100 test_before_apps
101 out=$?
102 if [ $out -ne 0 ]; then
103 stop_lttng_sessiond
104 exit $out
105 fi
106
107 rm -rf $TRACE_PATH
108
109 diag "Start tracing AFTER application is started"
110
111 TRACE_PATH=$(mktemp -d)
112
113 test_after_apps
114 out=$?
115 if [ $out -ne 0 ]; then
116 stop_lttng_sessiond
117 exit $out
118 fi
119
120 stop_lttng_sessiond
121
122 rm -rf $TRACE_PATH
This page took 0.031149 seconds and 3 git commands to generate.