3 # SPDX-License-Identifier: GPL-2.0-only
5 # Copyright (C) 2019 Philippe Proulx <pproulx@efficios.com>
8 # This test validates that a `src.ctf.fs` component successfully reads
9 # specific CTF traces and creates the expected messages.
11 # Such CTF traces to open either exist (in `tests/ctf-traces/succeed`)
12 # or are generated by this test using local trace generators.
16 if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
17 UTILSSH
="$BT_TESTS_SRCDIR/utils/utils.sh"
19 UTILSSH
="$(dirname "$0")/../../utils/utils.sh"
22 # shellcheck source=../../utils/utils.sh
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 -- -$$
34 # Ensure that background child jobs are killed on SIGINT/SIGTERM
35 trap cleanup SIGINT SIGTERM
37 this_dir_relative
="plugins/src.ctf.lttng-live"
38 test_data_dir
="$BT_TESTS_DATADIR/$this_dir_relative"
39 trace_dir
="$BT_CTF_TRACES_PATH/succeed"
41 if [ "$BT_OS_TYPE" = "mingw" ]; then
42 # Same as the above, but in Windows form (C:\foo\bar) instead of Unix form
44 trace_dir_native
=$
(cygpath
-w "${trace_dir}")
46 trace_dir_native
="${trace_dir}"
52 local retcode_file
="$3"
53 local server_args
="$4"
54 local server_script
="$test_data_dir/lttng_live_server.py"
57 echo "$server_args" |
xargs "$BT_TESTS_PYTHON_BIN" "$server_script" --port-file "$port_file" &
62 # wait for server to exit
65 # write return code to file
66 echo $?
> "$retcode_file"
69 kill_lttng_live_server
() {
72 if [ ! -s "$pid_file" ]; then
76 kill -9 "$(cat "$pid_file")"
79 get_cli_output_with_lttng_live_server
() {
80 local cli_args_template
="$1"
81 local server_args
="$2"
82 local cli_stdout_file
="$3"
83 local cli_stderr_file
="$4"
91 local server_retcode_file
93 server_pid_file
="$(mktemp -t test_live_server_pid.XXXXXX)"
94 server_retcode_file
="$(mktemp -t test_live_server_ret.XXXXX)"
96 diag
"Starting LTTng live server mockup"
98 # This starts the server, which eventually writes its listening
99 # port number to the `$port_file` file. The lttng_live_server()
100 # function itself writes the server's PID to the
101 # `$server_pid_file` file. When the server exits,
102 # lttng_live_server() writes its return code to the
103 # `$server_retcode_file` file.
104 lttng_live_server
"$port_file" "$server_pid_file" \
105 "$server_retcode_file" "$server_args" &
109 while [ ! -s "$port_file" ]; do
112 # Timeout of 30 seconds
113 if [ "$i" -eq "300" ]; then
115 kill_lttng_live_server
"$server_pid_file"
117 rm -f "$server_pid_file"
118 rm -f "$server_retcode_file"
125 port
=$
(<"$port_file")
127 diag
"LTTng live port is $port"
129 cli_args
=${cli_args_template//@PORT@/$port}
131 # Split argument string by spaces into an array.
132 IFS
=' ' read -ra cli_args
<<< "$cli_args"
134 if ! bt_cli
"$cli_stdout_file" "$cli_stderr_file" "${cli_args[@]}"; then
135 # CLI failed: cancel everything else
136 kill_lttng_live_server
"$server_pid_file"
138 rm -f "$server_pid_file"
139 rm -f "$server_retcode_file"
143 # get server's return code
145 while [ ! -s "$server_retcode_file" ]; do
148 # Timeout of 30 seconds
149 if [ "$i" -eq "300" ]; then
151 kill_lttng_live_server
"$server_pid_file"
153 rm -f "$server_pid_file"
154 rm -f "$server_retcode_file"
163 ret
=$
(<"$server_retcode_file")
165 rm -f "$server_pid_file"
166 rm -f "$server_retcode_file"
172 local cli_args_template
="$2"
173 local server_args
="$3"
174 local expected_stdout
="$4"
175 local expected_stderr
="$5"
182 cli_stderr
="$(mktemp -t test_live_stderr.XXXXXX)"
183 cli_stdout
="$(mktemp -t test_live_stdout.XXXXXX)"
184 port_file
="$(mktemp -t test_live_server_port.XXXXXX)"
186 get_cli_output_with_lttng_live_server
"$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file"
187 port
=$
(<"$port_file")
189 bt_diff
"$expected_stdout" "$cli_stdout"
190 ok $?
"$test_text - stdout"
191 bt_diff
"$expected_stderr" "$cli_stderr"
192 ok $?
"$test_text - stderr"
199 test_list_sessions
() {
200 # Test the basic listing of sessions.
201 # Ensure that a multi-domain trace is seen as a single session.
202 # run_test() is not used here because the port is needed to craft the
207 local tmp_stdout_expected
208 local template_expected
210 local test_text
="CLI prints the expected session list"
211 local cli_args_template
="-i lttng-live net://localhost:@PORT@"
212 local server_args
="'multi-domains,0,hostname,1,0,${trace_dir_native}/multi-domains/ust/' 'multi-domains,1,hostname,1,0,${trace_dir_native}/multi-domains/kernel/' 'trace-with-index,2,hostname,1,0,${trace_dir_native}/trace-with-index/' "
214 template_expected
=$
(<"$test_data_dir/cli-list-sessions.expect")
215 cli_stderr
="$(mktemp -t test_live_list_sessions_stderr.XXXXXX)"
216 cli_stdout
="$(mktemp -t test_live_list_sessions_stdout.XXXXXX)"
217 empty_file
="$(mktemp -t test_live_list_sessions_empty.XXXXXX)"
218 port_file
="$(mktemp -t test_live_list_sessions_server_port.XXXXXX)"
219 tmp_stdout_expected
="$(mktemp -t test_live_list_sessions_stdout_expected.XXXXXX)"
221 get_cli_output_with_lttng_live_server
"$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file"
222 port
=$
(<"$port_file")
224 # Craft the expected output. This is necessary since the port number
225 # (random) of a "relayd" is present in the output.
226 template_expected
=${template_expected//@PORT@/$port}
228 echo "$template_expected" > "$tmp_stdout_expected"
230 bt_diff
"$tmp_stdout_expected" "$cli_stdout"
231 ok $?
"$test_text - stdout"
232 bt_diff
"$empty_file" "$cli_stderr"
233 ok $?
"$test_text - stderr"
239 rm -f "$tmp_stdout_expected"
243 # Attach and consume data from a multi packets ust session with no
245 local test_text
="CLI attach and fetch from single-domains session - no discarded events"
246 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details"
247 local server_args
="'trace-with-index,0,hostname,1,0,${trace_dir_native}/trace-with-index/'"
248 local expected_stdout
="${test_data_dir}/cli-base.expect"
249 local expected_stderr
251 # Empty file for stderr expected
252 expected_stderr
="$(mktemp -t test_live_base_stderr_expected.XXXXXX)"
254 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
256 rm -f "$expected_stderr"
259 test_multi_domains
() {
260 # Attach and consume data from a multi-domains session with discarded
262 local test_text
="CLI attach and fetch from multi-domains session - discarded events"
263 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/multi-domains -c sink.text.details"
264 local server_args
="'multi-domains,0,hostname,1,0,${trace_dir_native}/multi-domains/kernel/,${trace_dir_native}/multi-domains/ust/'"
265 local expected_stdout
="${test_data_dir}/cli-multi-domains.expect"
266 local expected_stderr
268 # Empty file for stderr expected
269 expected_stderr
="$(mktemp -t test_live_multi_domains_stderr_expected.XXXXXX)"
271 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
273 rm -f "$expected_stderr"
276 test_rate_limited
() {
277 # Attach and consume data from a multi packets ust session with no
278 # discarded events. Enforce a server side limit on the stream data
279 # requests size. Ensure that babeltrace respect the returned size and that
280 # many requests per packet works as expected.
281 # The packet size of the test trace is 4k. Limit requests to 1k.
282 local test_text
="CLI many requests per packet"
283 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details"
284 local server_args
="--max-query-data-response-size 1024 'trace-with-index,0,hostname,1,0,${trace_dir_native}/trace-with-index/'"
285 local expected_stdout
="${test_data_dir}/cli-base.expect"
286 local expected_stderr
288 # Empty file for stderr expected
289 expected_stderr
="$(mktemp -t test_live_rate_limited_stderr_expected.XXXXXX)"
291 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
293 rm -f "$expected_stderr"
296 test_compare_to_ctf_fs
() {
297 # Compare the details text sink or ctf.fs and ctf.lttng-live to ensure
298 # that the trace is parsed the same way.
299 # Do the same with the session swapped on the relayd side. This validate
300 # that ordering is consistent between live and ctf fs.
301 local test_text
="CLI src.ctf.fs vs src.ctf.lttng-live"
302 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"
303 local server_args
="'multi-domains,0,hostname,1,0,${trace_dir_native}/multi-domains/kernel/' 'multi-domains,1,hostname,1,0,${trace_dir_native}/multi-domains/ust/'"
304 local server_args_inverse
="'multi-domains,0,hostname,1,0,${trace_dir_native}/multi-domains/ust/' 'multi-domains,1,hostname,1,0,${trace_dir_native}/multi-domains/kernel/'"
305 local expected_stdout
306 local expected_stderr
308 expected_stdout
="$(mktemp -t test_live_compare_stdout_expected.XXXXXX)"
309 expected_stderr
="$(mktemp -t test_live_compare_stderr_expected.XXXXXX)"
311 bt_cli
"$expected_stdout" "$expected_stderr" "${trace_dir}/multi-domains" -c sink.text.details
--params "with-trace-name=false,with-stream-name=false"
312 bt_remove_cr
"${expected_stdout}"
313 bt_remove_cr
"${expected_stderr}"
314 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
315 diag
"Inverse session order from lttng-relayd"
316 run_test
"$test_text" "$cli_args_template" "$server_args_inverse" "$expected_stdout" "$expected_stderr"
318 rm -f "$expected_stdout"
319 rm -f "$expected_stderr"
328 test_compare_to_ctf_fs