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 diag
"Running CLI: 'babeltrace2 $cli_args'"
143 if ! "$BT_TESTS_BT2_BIN" $cli_args 1>"$cli_stdout_file" 2>"$cli_stderr_file"; then
144 # CLI failed: cancel everything else
145 kill_lttng_live_server
"$server_pid_file"
147 rm -f "$server_pid_file"
148 rm -f "$server_retcode_file"
152 # get server's return code
154 while [ ! -s "$server_retcode_file" ]; do
157 # Timeout of 30 seconds
158 if [ "$i" -eq "300" ]; then
160 kill_lttng_live_server
"$server_pid_file"
162 rm -f "$server_pid_file"
163 rm -f "$server_retcode_file"
172 ret
=$
(<"$server_retcode_file")
174 rm -f "$server_pid_file"
175 rm -f "$server_retcode_file"
181 local cli_args_template
="$2"
182 local server_args
="$3"
183 local expected_stdout
="$4"
184 local expected_stderr
="$5"
191 cli_stderr
="$(mktemp -t test_live_stderr.XXXXXX)"
192 cli_stdout
="$(mktemp -t test_live_stdout.XXXXXX)"
193 port_file
="$(mktemp -t test_live_server_port.XXXXXX)"
195 get_cli_output_with_lttng_live_server
"$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file"
196 port
=$
(<"$port_file")
198 bt_diff
"$expected_stdout" "$cli_stdout"
199 ok $?
"$test_text - stdout"
200 bt_diff
"$expected_stderr" "$cli_stderr"
201 ok $?
"$test_text - stderr"
208 test_list_sessions
() {
209 # Test the basic listing of sessions.
210 # Ensure that a multi-domain trace is seen as a single session.
211 # run_test() is not used here because the port is needed to craft the
216 local tmp_stdout_expected
217 local template_expected
219 local test_text
="CLI prints the expected session list"
220 local cli_args_template
="-i lttng-live net://localhost:@PORT@"
221 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/' "
223 template_expected
=$
(<"$test_data_dir/cli-list-sessions.expect")
224 cli_stderr
="$(mktemp -t test_live_list_sessions_stderr.XXXXXX)"
225 cli_stdout
="$(mktemp -t test_live_list_sessions_stdout.XXXXXX)"
226 empty_file
="$(mktemp -t test_live_list_sessions_empty.XXXXXX)"
227 port_file
="$(mktemp -t test_live_list_sessions_server_port.XXXXXX)"
228 tmp_stdout_expected
="$(mktemp -t test_live_list_sessions_stdout_expected.XXXXXX)"
230 get_cli_output_with_lttng_live_server
"$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file"
231 port
=$
(<"$port_file")
233 # Craft the expected output. This is necessary since the port number
234 # (random) of a "relayd" is present in the output.
235 template_expected
=${template_expected//@PORT@/$port}
237 echo "$template_expected" > "$tmp_stdout_expected"
239 bt_diff
"$tmp_stdout_expected" "$cli_stdout"
240 ok $?
"$test_text - stdout"
241 bt_diff
"$empty_file" "$cli_stderr"
242 ok $?
"$test_text - stderr"
248 rm -f "$tmp_stdout_expected"
252 # Attach and consume data from a multi packets ust session with no
254 local test_text
="CLI attach and fetch from single-domains session - no discarded events"
255 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details"
256 local server_args
="'trace-with-index,0,hostname,1,0,${trace_dir_native}/trace-with-index/'"
257 local expected_stdout
="${test_data_dir}/cli-base.expect"
258 local expected_stderr
260 # Empty file for stderr expected
261 expected_stderr
="$(mktemp -t test_live_base_stderr_expected.XXXXXX)"
263 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
265 rm -f "$expected_stderr"
268 test_multi_domains
() {
269 # Attach and consume data from a multi-domains session with discarded
271 local test_text
="CLI attach and fetch from multi-domains session - discarded events"
272 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/multi-domains -c sink.text.details"
273 local server_args
="'multi-domains,0,hostname,1,0,${trace_dir_native}/multi-domains/kernel/,${trace_dir_native}/multi-domains/ust/'"
274 local expected_stdout
="${test_data_dir}/cli-multi-domains.expect"
275 local expected_stderr
277 # Empty file for stderr expected
278 expected_stderr
="$(mktemp -t test_live_multi_domains_stderr_expected.XXXXXX)"
280 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
282 rm -f "$expected_stderr"
285 test_rate_limited
() {
286 # Attach and consume data from a multi packets ust session with no
287 # discarded events. Enforce a server side limit on the stream data
288 # requests size. Ensure that babeltrace respect the returned size and that
289 # many requests per packet works as expected.
290 # The packet size of the test trace is 4k. Limit requests to 1k.
291 local test_text
="CLI many requests per packet"
292 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details"
293 local server_args
="--max-query-data-response-size 1024 'trace-with-index,0,hostname,1,0,${trace_dir_native}/trace-with-index/'"
294 local expected_stdout
="${test_data_dir}/cli-base.expect"
295 local expected_stderr
297 # Empty file for stderr expected
298 expected_stderr
="$(mktemp -t test_live_rate_limited_stderr_expected.XXXXXX)"
300 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
302 rm -f "$expected_stderr"
305 test_compare_to_ctf_fs
() {
306 # Compare the details text sink or ctf.fs and ctf.lttng-live to ensure
307 # that the trace is parsed the same way.
308 # Do the same with the session swapped on the relayd side. This validate
309 # that ordering is consistent between live and ctf fs.
310 local test_text
="CLI src.ctf.fs vs src.ctf.lttng-live"
311 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"
312 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/'"
313 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/'"
314 local expected_stdout
315 local expected_stderr
317 expected_stdout
="$(mktemp -t test_live_compare_stdout_expected.XXXXXX)"
318 expected_stderr
="$(mktemp -t test_live_compare_stderr_expected.XXXXXX)"
320 bt_cli
"$expected_stdout" "$expected_stderr" "${trace_dir}/multi-domains" -c sink.text.details
--params "with-trace-name=false,with-stream-name=false"
321 bt_remove_cr
"${expected_stdout}"
322 bt_remove_cr
"${expected_stderr}"
323 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
324 diag
"Inverse session order from lttng-relayd"
325 run_test
"$test_text" "$cli_args_template" "$server_args_inverse" "$expected_stdout" "$expected_stderr"
327 rm -f "$expected_stdout"
328 rm -f "$expected_stderr"
337 test_compare_to_ctf_fs