3 # Copyright (C) 2019 Philippe Proulx <pproulx@efficios.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; only version 2
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # This test validates that a `src.ctf.fs` component successfully reads
20 # specific CTF traces and creates the expected messages.
22 # Such CTF traces to open either exist (in `tests/ctf-traces/succeed`)
23 # or are generated by this test using local trace generators.
27 if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
28 UTILSSH
="$BT_TESTS_SRCDIR/utils/utils.sh"
30 UTILSSH
="$(dirname "$0")/../../utils/utils.sh"
33 # shellcheck source=../../utils/utils.sh
38 # Disable trap for SIGTERM since the following kill to the
39 # pidgroup will be SIGTERM. Otherwise it loops.
40 # The '-' before the pid number ($$) indicates 'kill' to signal the
41 # whole process group.
42 trap - SIGTERM
&& kill -- -$$
45 # Ensure that background child jobs are killed on SIGINT/SIGTERM
46 trap cleanup SIGINT SIGTERM
48 this_dir_relative
="plugins/src.ctf.lttng-live"
49 test_data_dir
="$BT_TESTS_DATADIR/$this_dir_relative"
50 trace_dir
="$BT_CTF_TRACES_PATH/succeed"
52 if [ "$BT_OS_TYPE" = "mingw" ]; then
53 # Same as the above, but in Windows form (C:\foo\bar) instead of Unix form
55 trace_dir_native
=$
(cygpath
-w "${trace_dir}")
57 trace_dir_native
="${trace_dir}"
63 local retcode_file
="$3"
64 local server_args
="$4"
65 local server_script
="$test_data_dir/lttng_live_server.py"
68 echo "$server_args" |
xargs "$BT_TESTS_PYTHON_BIN" "$server_script" --port-file "$port_file" &
73 # wait for server to exit
76 # write return code to file
77 echo $?
> "$retcode_file"
80 kill_lttng_live_server
() {
83 if [ ! -s "$pid_file" ]; then
87 kill -9 "$(cat "$pid_file")"
90 get_cli_output_with_lttng_live_server
() {
91 local cli_args_template
="$1"
92 local server_args
="$2"
93 local cli_stdout_file
="$3"
94 local cli_stderr_file
="$4"
101 local server_pid_file
102 local server_retcode_file
104 server_pid_file
="$(mktemp -t test_live_server_pid.XXXXXX)"
105 server_retcode_file
="$(mktemp -t test_live_server_ret.XXXXX)"
107 diag
"Starting LTTng live server mockup"
109 # This starts the server, which eventually writes its listening
110 # port number to the `$port_file` file. The lttng_live_server()
111 # function itself writes the server's PID to the
112 # `$server_pid_file` file. When the server exits,
113 # lttng_live_server() writes its return code to the
114 # `$server_retcode_file` file.
115 lttng_live_server
"$port_file" "$server_pid_file" \
116 "$server_retcode_file" "$server_args" &
120 while [ ! -s "$port_file" ]; do
123 # Timeout of 30 seconds
124 if [ "$i" -eq "300" ]; then
126 kill_lttng_live_server
"$server_pid_file"
128 rm -f "$server_pid_file"
129 rm -f "$server_retcode_file"
136 port
=$
(<"$port_file")
138 diag
"LTTng live port is $port"
140 cli_args
=${cli_args_template//@PORT@/$port}
142 # Split argument string by spaces into an array.
143 IFS
=' ' read -ra cli_args
<<< "$cli_args"
145 if ! bt_cli
"$cli_stdout_file" "$cli_stderr_file" "${cli_args[@]}"; then
146 # CLI failed: cancel everything else
147 kill_lttng_live_server
"$server_pid_file"
149 rm -f "$server_pid_file"
150 rm -f "$server_retcode_file"
154 # get server's return code
156 while [ ! -s "$server_retcode_file" ]; do
159 # Timeout of 30 seconds
160 if [ "$i" -eq "300" ]; then
162 kill_lttng_live_server
"$server_pid_file"
164 rm -f "$server_pid_file"
165 rm -f "$server_retcode_file"
174 ret
=$
(<"$server_retcode_file")
176 rm -f "$server_pid_file"
177 rm -f "$server_retcode_file"
183 local cli_args_template
="$2"
184 local server_args
="$3"
185 local expected_stdout
="$4"
186 local expected_stderr
="$5"
193 cli_stderr
="$(mktemp -t test_live_stderr.XXXXXX)"
194 cli_stdout
="$(mktemp -t test_live_stdout.XXXXXX)"
195 port_file
="$(mktemp -t test_live_server_port.XXXXXX)"
197 get_cli_output_with_lttng_live_server
"$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file"
198 port
=$
(<"$port_file")
200 bt_diff
"$expected_stdout" "$cli_stdout"
201 ok $?
"$test_text - stdout"
202 bt_diff
"$expected_stderr" "$cli_stderr"
203 ok $?
"$test_text - stderr"
210 test_list_sessions
() {
211 # Test the basic listing of sessions.
212 # Ensure that a multi-domain trace is seen as a single session.
213 # run_test() is not used here because the port is needed to craft the
218 local tmp_stdout_expected
219 local template_expected
221 local test_text
="CLI prints the expected session list"
222 local cli_args_template
="-i lttng-live net://localhost:@PORT@"
223 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/' "
225 template_expected
=$
(<"$test_data_dir/cli-list-sessions.expect")
226 cli_stderr
="$(mktemp -t test_live_list_sessions_stderr.XXXXXX)"
227 cli_stdout
="$(mktemp -t test_live_list_sessions_stdout.XXXXXX)"
228 empty_file
="$(mktemp -t test_live_list_sessions_empty.XXXXXX)"
229 port_file
="$(mktemp -t test_live_list_sessions_server_port.XXXXXX)"
230 tmp_stdout_expected
="$(mktemp -t test_live_list_sessions_stdout_expected.XXXXXX)"
232 get_cli_output_with_lttng_live_server
"$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file"
233 port
=$
(<"$port_file")
235 # Craft the expected output. This is necessary since the port number
236 # (random) of a "relayd" is present in the output.
237 template_expected
=${template_expected//@PORT@/$port}
239 echo "$template_expected" > "$tmp_stdout_expected"
241 bt_diff
"$tmp_stdout_expected" "$cli_stdout"
242 ok $?
"$test_text - stdout"
243 bt_diff
"$empty_file" "$cli_stderr"
244 ok $?
"$test_text - stderr"
250 rm -f "$tmp_stdout_expected"
254 # Attach and consume data from a multi packets ust session with no
256 local test_text
="CLI attach and fetch from single-domains session - no discarded events"
257 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details"
258 local server_args
="'trace-with-index,0,hostname,1,0,${trace_dir_native}/trace-with-index/'"
259 local expected_stdout
="${test_data_dir}/cli-base.expect"
260 local expected_stderr
262 # Empty file for stderr expected
263 expected_stderr
="$(mktemp -t test_live_base_stderr_expected.XXXXXX)"
265 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
267 rm -f "$expected_stderr"
270 test_multi_domains
() {
271 # Attach and consume data from a multi-domains session with discarded
273 local test_text
="CLI attach and fetch from multi-domains session - discarded events"
274 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/multi-domains -c sink.text.details"
275 local server_args
="'multi-domains,0,hostname,1,0,${trace_dir_native}/multi-domains/kernel/,${trace_dir_native}/multi-domains/ust/'"
276 local expected_stdout
="${test_data_dir}/cli-multi-domains.expect"
277 local expected_stderr
279 # Empty file for stderr expected
280 expected_stderr
="$(mktemp -t test_live_multi_domains_stderr_expected.XXXXXX)"
282 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
284 rm -f "$expected_stderr"
287 test_rate_limited
() {
288 # Attach and consume data from a multi packets ust session with no
289 # discarded events. Enforce a server side limit on the stream data
290 # requests size. Ensure that babeltrace respect the returned size and that
291 # many requests per packet works as expected.
292 # The packet size of the test trace is 4k. Limit requests to 1k.
293 local test_text
="CLI many requests per packet"
294 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details"
295 local server_args
="--max-query-data-response-size 1024 'trace-with-index,0,hostname,1,0,${trace_dir_native}/trace-with-index/'"
296 local expected_stdout
="${test_data_dir}/cli-base.expect"
297 local expected_stderr
299 # Empty file for stderr expected
300 expected_stderr
="$(mktemp -t test_live_rate_limited_stderr_expected.XXXXXX)"
302 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
304 rm -f "$expected_stderr"
307 test_compare_to_ctf_fs
() {
308 # Compare the details text sink or ctf.fs and ctf.lttng-live to ensure
309 # that the trace is parsed the same way.
310 # Do the same with the session swapped on the relayd side. This validate
311 # that ordering is consistent between live and ctf fs.
312 local test_text
="CLI src.ctf.fs vs src.ctf.lttng-live"
313 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"
314 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/'"
315 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/'"
316 local expected_stdout
317 local expected_stderr
319 expected_stdout
="$(mktemp -t test_live_compare_stdout_expected.XXXXXX)"
320 expected_stderr
="$(mktemp -t test_live_compare_stderr_expected.XXXXXX)"
322 bt_cli
"$expected_stdout" "$expected_stderr" "${trace_dir}/multi-domains" -c sink.text.details
--params "with-trace-name=false,with-stream-name=false"
323 bt_remove_cr
"${expected_stdout}"
324 bt_remove_cr
"${expected_stderr}"
325 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
326 diag
"Inverse session order from lttng-relayd"
327 run_test
"$test_text" "$cli_args_template" "$server_args_inverse" "$expected_stdout" "$expected_stderr"
329 rm -f "$expected_stdout"
330 rm -f "$expected_stderr"
339 test_compare_to_ctf_fs