Commit | Line | Data |
---|---|---|
7972aab2 DG |
1 | #!/bin/bash |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
7972aab2 | 4 | # |
9d16b343 MJ |
5 | # SPDX-License-Identifier: LGPL-2.1-only |
6 | ||
f5481aa9 | 7 | TEST_DESC="UST tracer - Tracing with per PID buffers" |
7972aab2 DG |
8 | |
9 | CURDIR=$(dirname $0)/ | |
10 | TESTDIR=$CURDIR/../../.. | |
11 | NR_ITER=100 | |
b6a8c35e | 12 | NR_USEC_WAIT=100000 |
f5481aa9 | 13 | SESSION_NAME="buffers-pid" |
b6a8c35e CB |
14 | |
15 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
16 | TESTAPP_NAME="gen-ust-events" | |
17 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
18 | EVENT_NAME="tp:tptest" | |
5dca3876 | 19 | NUM_TESTS=59 |
7972aab2 DG |
20 | |
21 | source $TESTDIR/utils/utils.sh | |
22 | ||
b6a8c35e CB |
23 | if [ ! -x "$TESTAPP_BIN" ]; then |
24 | BAIL_OUT "No UST events binary detected." | |
7972aab2 DG |
25 | fi |
26 | ||
27 | # MUST set TESTDIR before calling those functions | |
28 | ||
f5481aa9 | 29 | function enable_channel_per_pid() |
7972aab2 DG |
30 | { |
31 | sess_name=$1 | |
32 | channel_name=$2 | |
33 | ||
f5481aa9 DG |
34 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name >/dev/null 2>&1 |
35 | ok $? "Enable channel $channel_name per PID for session $sess_name" | |
7972aab2 DG |
36 | } |
37 | ||
7972aab2 DG |
38 | test_after_multiple_apps() { |
39 | local out | |
40 | local i | |
41 | ||
42 | diag "Start multiple applications AFTER tracing is started" | |
43 | ||
44 | # BEFORE application is spawned | |
bf6ae429 | 45 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
f5481aa9 | 46 | enable_channel_per_pid $SESSION_NAME "channel0" |
c4926bb5 | 47 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
e563bbdb | 48 | start_lttng_tracing_ok $SESSION_NAME |
7972aab2 DG |
49 | |
50 | for i in `seq 1 5`; do | |
6c4a91d6 | 51 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT >/dev/null 2>&1 & |
7972aab2 DG |
52 | ok $? "Start application $i for tracing" |
53 | done | |
c7613334 | 54 | wait |
7972aab2 | 55 | |
96340a01 | 56 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 57 | destroy_lttng_session_ok $SESSION_NAME |
7972aab2 | 58 | |
d53addeb | 59 | trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH |
7972aab2 DG |
60 | |
61 | return $? | |
62 | } | |
63 | ||
64 | test_before_multiple_apps() { | |
65 | local out | |
66 | local i | |
33e55711 FD |
67 | local file_sync_after_first=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX") |
68 | local file_sync_before_last=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX") | |
7972aab2 DG |
69 | |
70 | diag "Start multiple applications BEFORE tracing is started" | |
71 | ||
72 | for i in `seq 1 5`; do | |
6c4a91d6 MD |
73 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \ |
74 | --sync-after-first-event ${file_sync_after_first}_${i} \ | |
75 | --sync-before-last-event ${file_sync_before_last}_${i} >/dev/null 2>&1 & | |
7972aab2 DG |
76 | ok $? "Start application $i for tracing" |
77 | done | |
78 | ||
79 | # BEFORE application is spawned | |
bf6ae429 | 80 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
f5481aa9 | 81 | enable_channel_per_pid $SESSION_NAME "channel0" |
c4926bb5 | 82 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
e563bbdb | 83 | start_lttng_tracing_ok $SESSION_NAME |
7972aab2 | 84 | |
5fcaccbc MD |
85 | for i in `seq 1 5`; do |
86 | touch ${file_sync_before_last}_${i} | |
87 | done | |
88 | ||
5dca3876 MD |
89 | diag "Waiting for applications to end" |
90 | wait | |
91 | pass "Waiting done" | |
7972aab2 | 92 | |
96340a01 | 93 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 94 | destroy_lttng_session_ok $SESSION_NAME |
7972aab2 | 95 | |
5fcaccbc MD |
96 | for i in `seq 1 5`; do |
97 | rm -f ${file_sync_after_first}_${i} | |
98 | rm -f ${file_sync_before_last}_${i} | |
99 | done | |
100 | ||
7972aab2 DG |
101 | out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l) |
102 | if [ $out -eq 0 ]; then | |
103 | fail "Trace validation" | |
104 | diag "No event(s) found. We are supposed to have at least one." | |
105 | out=1 | |
106 | else | |
107 | pass "Trace validation" | |
108 | diag "Found $out event(s). Coherent." | |
109 | out=0 | |
110 | fi | |
111 | ||
7972aab2 DG |
112 | return $out |
113 | } | |
114 | ||
115 | test_after_app() { | |
116 | local out | |
117 | ||
118 | diag "Start application AFTER tracing is started" | |
119 | ||
120 | # BEFORE application is spawned | |
bf6ae429 | 121 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
f5481aa9 | 122 | enable_channel_per_pid $SESSION_NAME "channel0" |
c4926bb5 | 123 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
e563bbdb | 124 | start_lttng_tracing_ok $SESSION_NAME |
7972aab2 | 125 | |
6c4a91d6 | 126 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT & |
7972aab2 | 127 | ok $? "Start application to trace" |
c7613334 | 128 | wait |
7972aab2 | 129 | |
96340a01 | 130 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 131 | destroy_lttng_session_ok $SESSION_NAME |
7972aab2 | 132 | |
d53addeb | 133 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH |
7972aab2 DG |
134 | |
135 | return $? | |
136 | } | |
137 | ||
138 | test_before_app() { | |
139 | local out | |
33e55711 FD |
140 | local file_sync_after_first=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX") |
141 | local file_sync_before_last=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX") | |
7972aab2 DG |
142 | |
143 | diag "Start application BEFORE tracing is started" | |
144 | ||
7972aab2 DG |
145 | |
146 | # BEFORE application is spawned | |
bf6ae429 | 147 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
f5481aa9 | 148 | enable_channel_per_pid $SESSION_NAME "channel0" |
c4926bb5 | 149 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
f8ccb5c8 | 150 | |
6c4a91d6 MD |
151 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \ |
152 | --sync-after-first-event ${file_sync_after_first} \ | |
153 | --sync-before-last-event ${file_sync_before_last} & | |
f8ccb5c8 CB |
154 | ok $? "Start application to trace" |
155 | ||
e563bbdb | 156 | start_lttng_tracing_ok $SESSION_NAME |
7972aab2 | 157 | |
5fcaccbc MD |
158 | touch ${file_sync_before_last} |
159 | ||
c7613334 | 160 | wait |
7972aab2 | 161 | |
96340a01 | 162 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 163 | destroy_lttng_session_ok $SESSION_NAME |
7972aab2 | 164 | |
5fcaccbc MD |
165 | rm -f ${file_sync_after_first} |
166 | rm -f ${file_sync_before_last} | |
167 | ||
7972aab2 DG |
168 | out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l) |
169 | if [ $out -eq 0 ]; then | |
170 | fail "Trace validation" | |
171 | diag "No event(s) found. We are supposed to have at least one." | |
172 | out=1 | |
173 | else | |
174 | pass "Trace validation" | |
175 | diag "Found $out event(s). Coherent." | |
176 | out=0 | |
177 | fi | |
178 | ||
7972aab2 DG |
179 | return $out |
180 | } | |
181 | ||
182 | test_multiple_channels() { | |
183 | local out | |
184 | ||
185 | diag "Start with multiple channels" | |
186 | ||
187 | # BEFORE application is spawned | |
bf6ae429 | 188 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
f5481aa9 DG |
189 | enable_channel_per_pid $SESSION_NAME "channel0" |
190 | enable_channel_per_pid $SESSION_NAME "channel1" | |
191 | enable_channel_per_pid $SESSION_NAME "channel2" | |
192 | enable_channel_per_pid $SESSION_NAME "channel3" | |
193 | enable_channel_per_pid $SESSION_NAME "channel4" | |
7972aab2 DG |
194 | # Enable event in all channels. |
195 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel0 -s $SESSION_NAME -u >/dev/null 2>&1 | |
196 | ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel0" | |
197 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel1 -s $SESSION_NAME -u >/dev/null 2>&1 | |
198 | ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel1" | |
199 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel2 -s $SESSION_NAME -u >/dev/null 2>&1 | |
200 | ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel2" | |
201 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel3 -s $SESSION_NAME -u >/dev/null 2>&1 | |
202 | ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel3" | |
203 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel4 -s $SESSION_NAME -u >/dev/null 2>&1 | |
204 | ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel4" | |
e563bbdb | 205 | start_lttng_tracing_ok $SESSION_NAME |
7972aab2 | 206 | |
6c4a91d6 | 207 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT & |
7972aab2 | 208 | ok $? "Start application to trace" |
c7613334 | 209 | wait |
7972aab2 | 210 | |
96340a01 | 211 | stop_lttng_tracing_ok $SESSION_NAME |
d53addeb | 212 | trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH |
7972aab2 DG |
213 | out=$? |
214 | ||
67b4c664 | 215 | destroy_lttng_session_ok $SESSION_NAME |
7972aab2 DG |
216 | |
217 | return $out | |
218 | } | |
219 | ||
220 | # MUST set TESTDIR before calling those functions | |
221 | plan_tests $NUM_TESTS | |
222 | ||
e3bef725 CB |
223 | print_test_banner "$TEST_DESC" |
224 | ||
7972aab2 DG |
225 | TESTS=( |
226 | "test_before_app" | |
227 | "test_after_app" | |
228 | "test_after_multiple_apps" | |
229 | "test_before_multiple_apps" | |
230 | "test_multiple_channels" | |
231 | ) | |
232 | ||
233 | TEST_COUNT=${#TESTS[@]} | |
234 | i=0 | |
235 | ||
236 | start_lttng_sessiond | |
237 | ||
238 | while [ $i -lt $TEST_COUNT ]; do | |
33e55711 | 239 | TRACE_PATH=$(mktemp --tmpdir -d tmp.test_buffers_pid_trace_path.XXXXXX) |
7972aab2 | 240 | ${TESTS[$i]} |
7972aab2 DG |
241 | rm -rf $TRACE_PATH |
242 | let "i++" | |
243 | done | |
244 | ||
245 | stop_lttng_sessiond |