Commit | Line | Data |
---|---|---|
584af91e PP |
1 | #!/bin/bash |
2 | # | |
0235b0db | 3 | # SPDX-License-Identifier: GPL-2.0-only |
584af91e | 4 | # |
0235b0db | 5 | # Copyright (C) 2019 Philippe Proulx <pproulx@efficios.com> |
584af91e | 6 | # |
584af91e PP |
7 | |
8 | # This test validates that a `src.ctf.fs` component successfully reads | |
9 | # specific CTF traces and creates the expected messages. | |
10 | # | |
2b763e29 | 11 | # Such CTF traces to open either exist (in `tests/ctf-traces/`) |
584af91e PP |
12 | # or are generated by this test using local trace generators. |
13 | ||
14 | SH_TAP=1 | |
15 | ||
16 | if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then | |
17 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" | |
18 | else | |
19 | UTILSSH="$(dirname "$0")/../../utils/utils.sh" | |
20 | fi | |
21 | ||
22 | # shellcheck source=../../utils/utils.sh | |
23 | source "$UTILSSH" | |
24 | ||
25 | function cleanup () | |
26 | { | |
27 | # Disable trap for SIGTERM since the following kill to the | |
28 | # pidgroup will be SIGTERM. Otherwise it loops. | |
29 | # The '-' before the pid number ($$) indicates 'kill' to signal the | |
30 | # whole process group. | |
31 | trap - SIGTERM && kill -- -$$ | |
32 | } | |
33 | ||
34 | # Ensure that background child jobs are killed on SIGINT/SIGTERM | |
35 | trap cleanup SIGINT SIGTERM | |
36 | ||
37 | this_dir_relative="plugins/src.ctf.lttng-live" | |
38 | test_data_dir="$BT_TESTS_DATADIR/$this_dir_relative" | |
2b763e29 | 39 | trace_dir="$BT_CTF_TRACES_PATH" |
584af91e | 40 | |
742e3279 SM |
41 | if [ "$BT_OS_TYPE" = "mingw" ]; then |
42 | # Same as the above, but in Windows form (C:\foo\bar) instead of Unix form | |
43 | # (/c/foo/bar). | |
44 | trace_dir_native=$(cygpath -w "${trace_dir}") | |
45 | else | |
46 | trace_dir_native="${trace_dir}" | |
47 | fi | |
48 | ||
584af91e PP |
49 | lttng_live_server() { |
50 | local port_file="$1" | |
51 | local pid_file="$2" | |
52 | local retcode_file="$3" | |
53 | local server_args="$4" | |
54 | local server_script="$test_data_dir/lttng_live_server.py" | |
55 | ||
56 | # start server | |
2b763e29 JG |
57 | echo "$server_args" | xargs "$BT_TESTS_PYTHON_BIN" "$server_script" \ |
58 | --port-file "$port_file" \ | |
59 | --trace-path-prefix "$trace_dir_native" & | |
584af91e PP |
60 | |
61 | # write PID to file | |
62 | echo $! > "$pid_file" | |
63 | ||
64 | # wait for server to exit | |
65 | wait | |
66 | ||
67 | # write return code to file | |
68 | echo $? > "$retcode_file" | |
69 | } | |
70 | ||
71 | kill_lttng_live_server() { | |
72 | local pid_file="$1" | |
73 | ||
74 | if [ ! -s "$pid_file" ]; then | |
75 | return | |
76 | fi | |
77 | ||
78 | kill -9 "$(cat "$pid_file")" | |
79 | } | |
80 | ||
81 | get_cli_output_with_lttng_live_server() { | |
82 | local cli_args_template="$1" | |
2b763e29 | 83 | local sessions_file="$2" |
584af91e PP |
84 | local cli_stdout_file="$3" |
85 | local cli_stderr_file="$4" | |
86 | local port_file="$5" | |
87 | ||
88 | local i | |
89 | local ret | |
90 | local port | |
91 | local cli_args | |
92 | local server_pid_file | |
93 | local server_retcode_file | |
94 | ||
a01934b7 SM |
95 | server_pid_file="$(mktemp -t test_live_server_pid.XXXXXX)" |
96 | server_retcode_file="$(mktemp -t test_live_server_ret.XXXXX)" | |
584af91e PP |
97 | |
98 | diag "Starting LTTng live server mockup" | |
99 | ||
100 | # This starts the server, which eventually writes its listening | |
101 | # port number to the `$port_file` file. The lttng_live_server() | |
102 | # function itself writes the server's PID to the | |
103 | # `$server_pid_file` file. When the server exits, | |
104 | # lttng_live_server() writes its return code to the | |
105 | # `$server_retcode_file` file. | |
106 | lttng_live_server "$port_file" "$server_pid_file" \ | |
2b763e29 | 107 | "$server_retcode_file" "$sessions_file" & |
584af91e PP |
108 | |
109 | # Get port number | |
110 | i=0 | |
111 | while [ ! -s "$port_file" ]; do | |
112 | sleep .1 | |
113 | ||
114 | # Timeout of 30 seconds | |
115 | if [ "$i" -eq "300" ]; then | |
116 | # too long, kill it | |
117 | kill_lttng_live_server "$server_pid_file" | |
118 | wait | |
119 | rm -f "$server_pid_file" | |
120 | rm -f "$server_retcode_file" | |
121 | return 1 | |
122 | fi | |
123 | ||
124 | i=$((i + 1)) | |
125 | done | |
126 | ||
127 | port=$(<"$port_file") | |
128 | ||
129 | diag "LTTng live port is $port" | |
130 | ||
131 | cli_args=${cli_args_template//@PORT@/$port} | |
132 | ||
db4cb7f1 SM |
133 | # Split argument string by spaces into an array. |
134 | IFS=' ' read -ra cli_args <<< "$cli_args" | |
135 | ||
136 | if ! bt_cli "$cli_stdout_file" "$cli_stderr_file" "${cli_args[@]}"; then | |
584af91e PP |
137 | # CLI failed: cancel everything else |
138 | kill_lttng_live_server "$server_pid_file" | |
139 | wait | |
140 | rm -f "$server_pid_file" | |
141 | rm -f "$server_retcode_file" | |
142 | return 1 | |
143 | fi | |
144 | ||
145 | # get server's return code | |
146 | i=0 | |
147 | while [ ! -s "$server_retcode_file" ]; do | |
148 | sleep .1 | |
149 | ||
150 | # Timeout of 30 seconds | |
151 | if [ "$i" -eq "300" ]; then | |
152 | # too long, kill it | |
153 | kill_lttng_live_server "$server_pid_file" | |
154 | wait | |
155 | rm -f "$server_pid_file" | |
156 | rm -f "$server_retcode_file" | |
157 | return 1 | |
158 | fi | |
159 | ||
160 | i=$((i + 1)) | |
161 | done | |
162 | ||
163 | wait | |
164 | ||
165 | ret=$(<"$server_retcode_file") | |
166 | ||
167 | rm -f "$server_pid_file" | |
168 | rm -f "$server_retcode_file" | |
169 | return "$ret" | |
170 | } | |
171 | ||
172 | run_test() { | |
173 | local test_text="$1" | |
174 | local cli_args_template="$2" | |
175 | local server_args="$3" | |
176 | local expected_stdout="$4" | |
177 | local expected_stderr="$5" | |
178 | ||
179 | local cli_stderr | |
180 | local cli_stdout | |
181 | local port_file | |
4079467b | 182 | local port |
584af91e | 183 | |
a01934b7 SM |
184 | cli_stderr="$(mktemp -t test_live_stderr.XXXXXX)" |
185 | cli_stdout="$(mktemp -t test_live_stdout.XXXXXX)" | |
186 | port_file="$(mktemp -t test_live_server_port.XXXXXX)" | |
584af91e PP |
187 | |
188 | get_cli_output_with_lttng_live_server "$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file" | |
189 | port=$(<"$port_file") | |
190 | ||
191 | bt_diff "$expected_stdout" "$cli_stdout" | |
192 | ok $? "$test_text - stdout" | |
193 | bt_diff "$expected_stderr" "$cli_stderr" | |
194 | ok $? "$test_text - stderr" | |
195 | ||
196 | rm -f "$cli_stderr" | |
197 | rm -f "$cli_stdout" | |
198 | rm -f "$port_file" | |
199 | } | |
200 | ||
201 | test_list_sessions() { | |
202 | # Test the basic listing of sessions. | |
203 | # Ensure that a multi-domain trace is seen as a single session. | |
204 | # run_test() is not used here because the port is needed to craft the | |
205 | # expected output. | |
206 | ||
207 | local port | |
208 | local port_file | |
209 | local tmp_stdout_expected | |
210 | local template_expected | |
211 | ||
212 | local test_text="CLI prints the expected session list" | |
213 | local cli_args_template="-i lttng-live net://localhost:@PORT@" | |
2b763e29 JG |
214 | local sessions_file="$test_data_dir/list_sessions.json" |
215 | local server_args="--sessions-filename '$sessions_file'" | |
584af91e PP |
216 | |
217 | template_expected=$(<"$test_data_dir/cli-list-sessions.expect") | |
a01934b7 SM |
218 | cli_stderr="$(mktemp -t test_live_list_sessions_stderr.XXXXXX)" |
219 | cli_stdout="$(mktemp -t test_live_list_sessions_stdout.XXXXXX)" | |
220 | empty_file="$(mktemp -t test_live_list_sessions_empty.XXXXXX)" | |
221 | port_file="$(mktemp -t test_live_list_sessions_server_port.XXXXXX)" | |
222 | tmp_stdout_expected="$(mktemp -t test_live_list_sessions_stdout_expected.XXXXXX)" | |
584af91e PP |
223 | |
224 | get_cli_output_with_lttng_live_server "$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file" | |
225 | port=$(<"$port_file") | |
226 | ||
227 | # Craft the expected output. This is necessary since the port number | |
228 | # (random) of a "relayd" is present in the output. | |
229 | template_expected=${template_expected//@PORT@/$port} | |
230 | ||
231 | echo "$template_expected" > "$tmp_stdout_expected" | |
232 | ||
233 | bt_diff "$tmp_stdout_expected" "$cli_stdout" | |
234 | ok $? "$test_text - stdout" | |
235 | bt_diff "$empty_file" "$cli_stderr" | |
236 | ok $? "$test_text - stderr" | |
237 | ||
238 | rm -f "$cli_stderr" | |
239 | rm -f "$cli_stdout" | |
240 | rm -f "$empty_file" | |
241 | rm -f "$port_file" | |
242 | rm -f "$tmp_stdout_expected" | |
243 | } | |
244 | ||
245 | test_base() { | |
246 | # Attach and consume data from a multi packets ust session with no | |
247 | # discarded events. | |
248 | local test_text="CLI attach and fetch from single-domains session - no discarded events" | |
249 | local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details" | |
2b763e29 JG |
250 | local sessions_file="$test_data_dir/base.json" |
251 | local server_args="--sessions-filename '$sessions_file'" | |
584af91e PP |
252 | local expected_stdout="${test_data_dir}/cli-base.expect" |
253 | local expected_stderr | |
254 | ||
255 | # Empty file for stderr expected | |
a01934b7 | 256 | expected_stderr="$(mktemp -t test_live_base_stderr_expected.XXXXXX)" |
584af91e PP |
257 | |
258 | run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr" | |
259 | ||
260 | rm -f "$expected_stderr" | |
261 | } | |
262 | ||
263 | test_multi_domains() { | |
264 | # Attach and consume data from a multi-domains session with discarded | |
265 | # events. | |
266 | local test_text="CLI attach and fetch from multi-domains session - discarded events" | |
267 | local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/multi-domains -c sink.text.details" | |
2b763e29 JG |
268 | local sessions_file="${test_data_dir}/multi_domains.json" |
269 | local server_args="--sessions-filename '$sessions_file'" | |
270 | local expected_stdout="$test_data_dir/cli-multi-domains.expect" | |
584af91e PP |
271 | local expected_stderr |
272 | ||
273 | # Empty file for stderr expected | |
a01934b7 | 274 | expected_stderr="$(mktemp -t test_live_multi_domains_stderr_expected.XXXXXX)" |
584af91e PP |
275 | |
276 | run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr" | |
277 | ||
278 | rm -f "$expected_stderr" | |
279 | } | |
280 | ||
281 | test_rate_limited() { | |
282 | # Attach and consume data from a multi packets ust session with no | |
283 | # discarded events. Enforce a server side limit on the stream data | |
284 | # requests size. Ensure that babeltrace respect the returned size and that | |
285 | # many requests per packet works as expected. | |
286 | # The packet size of the test trace is 4k. Limit requests to 1k. | |
287 | local test_text="CLI many requests per packet" | |
288 | local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details" | |
2b763e29 JG |
289 | local sessions_file="$test_data_dir/rate_limited.json" |
290 | local server_args="--max-query-data-response-size 1024 --sessions-filename '$sessions_file'" | |
584af91e PP |
291 | local expected_stdout="${test_data_dir}/cli-base.expect" |
292 | local expected_stderr | |
293 | ||
294 | # Empty file for stderr expected | |
a01934b7 | 295 | expected_stderr="$(mktemp -t test_live_rate_limited_stderr_expected.XXXXXX)" |
584af91e PP |
296 | |
297 | run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr" | |
298 | ||
299 | rm -f "$expected_stderr" | |
300 | } | |
301 | ||
302 | test_compare_to_ctf_fs() { | |
303 | # Compare the details text sink or ctf.fs and ctf.lttng-live to ensure | |
304 | # that the trace is parsed the same way. | |
2d2a59db JR |
305 | # Do the same with the session swapped on the relayd side. This validate |
306 | # that ordering is consistent between live and ctf fs. | |
584af91e | 307 | local test_text="CLI src.ctf.fs vs src.ctf.lttng-live" |
2d2a59db | 308 | local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/multi-domains -c sink.text.details --params with-trace-name=false,with-stream-name=false" |
2b763e29 JG |
309 | local sessions_file="$test_data_dir/multi_domains.json" |
310 | local sessions_file_inverse="$test_data_dir/multi_domains_inverse.json" | |
311 | local server_args="--sessions-filename '$sessions_file'" | |
312 | local server_args_inverse="--sessions-filename '$sessions_file_inverse'" | |
584af91e PP |
313 | local expected_stdout |
314 | local expected_stderr | |
315 | ||
a01934b7 SM |
316 | expected_stdout="$(mktemp -t test_live_compare_stdout_expected.XXXXXX)" |
317 | expected_stderr="$(mktemp -t test_live_compare_stderr_expected.XXXXXX)" | |
584af91e | 318 | |
2b763e29 | 319 | bt_cli "$expected_stdout" "$expected_stderr" "${trace_dir}/succeed/multi-domains" -c sink.text.details --params "with-trace-name=false,with-stream-name=false" |
90a8a0f2 SM |
320 | bt_remove_cr "${expected_stdout}" |
321 | bt_remove_cr "${expected_stderr}" | |
584af91e | 322 | run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr" |
2d2a59db JR |
323 | diag "Inverse session order from lttng-relayd" |
324 | run_test "$test_text" "$cli_args_template" "$server_args_inverse" "$expected_stdout" "$expected_stderr" | |
584af91e PP |
325 | |
326 | rm -f "$expected_stdout" | |
327 | rm -f "$expected_stderr" | |
328 | } | |
329 | ||
b198ef81 JG |
330 | test_inactivity_discarded_packet() { |
331 | # Attach and consume data from a multi-packet trace with discarded | |
332 | # packets and emit an inactivity beacon during the discarded packets | |
333 | # period. | |
334 | # | |
335 | # | pkt seq:0 |<-------discarded packets------>| pkt seq:8 | | |
336 | # 0 20 121 140 | |
337 | # | |
338 | # This test was introduced to cover the following bug: | |
339 | # | |
340 | # When reading this type of trace locally, the CTF source is expected | |
341 | # to introduce a "Discarded packets" message between packets 0 and 8. | |
342 | # The timestamps of this message are [pkt0.end_ts, pkt8.begin_ts]. | |
343 | # | |
344 | # In the context of a live source, the tracer could report an inactivity | |
345 | # period during the interval of the "Discarded packets" message. | |
346 | # Those messages eventually translate into a | |
347 | # "Iterator inactivity" message with a timestamp set at the end of the | |
348 | # inactivity period. | |
349 | # | |
350 | # If the tracer reports an inactivity period that ends at a point | |
351 | # between pkt0 and pkt7 (resulting in an "Iterator inactivity" message), | |
352 | # the live source could send a "Discarded packets" message that starts | |
353 | # before the preceding "Iterator inactivity" message. This would break | |
354 | # the monotonicity constraint of the graph. | |
355 | local test_text="CLI attach and fetch from single-domains session - inactivity discarded packet" | |
356 | local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/7_lost_between_2_with_index -c sink.text.details" | |
357 | local sessions_file="$test_data_dir/inactivity_discarded_packet.json" | |
358 | local server_args="--sessions-filename '$sessions_file'" | |
359 | local expected_stdout="$test_data_dir/inactivity_discarded_packet.expect" | |
360 | local expected_stderr | |
361 | ||
362 | # Empty file for stderr expected | |
363 | expected_stderr="$(mktemp -t test_live_inactivity_discarded_packet_stderr_expected.XXXXXX)" | |
364 | ||
365 | run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr" | |
366 | ||
367 | rm -f "$expected_stderr" | |
368 | } | |
369 | ||
370 | plan_tests 14 | |
584af91e PP |
371 | |
372 | test_list_sessions | |
373 | test_base | |
374 | test_multi_domains | |
375 | test_rate_limited | |
376 | test_compare_to_ctf_fs | |
b198ef81 | 377 | test_inactivity_discarded_packet |