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"
55 local retcode_file
="$3"
56 local server_args
="$4"
57 local server_script
="$test_data_dir/lttng_live_server.py"
60 echo "$server_args" |
xargs "$BT_TESTS_PYTHON_BIN" "$server_script" --port-file "$port_file" &
65 # wait for server to exit
68 # write return code to file
69 echo $?
> "$retcode_file"
72 kill_lttng_live_server
() {
75 if [ ! -s "$pid_file" ]; then
79 kill -9 "$(cat "$pid_file")"
82 get_cli_output_with_lttng_live_server
() {
83 local cli_args_template
="$1"
84 local server_args
="$2"
85 local cli_stdout_file
="$3"
86 local cli_stderr_file
="$4"
94 local server_retcode_file
96 server_pid_file
="$(mktemp)"
97 server_retcode_file
="$(mktemp)"
99 diag
"Starting LTTng live server mockup"
101 # This starts the server, which eventually writes its listening
102 # port number to the `$port_file` file. The lttng_live_server()
103 # function itself writes the server's PID to the
104 # `$server_pid_file` file. When the server exits,
105 # lttng_live_server() writes its return code to the
106 # `$server_retcode_file` file.
107 lttng_live_server
"$port_file" "$server_pid_file" \
108 "$server_retcode_file" "$server_args" &
112 while [ ! -s "$port_file" ]; do
115 # Timeout of 30 seconds
116 if [ "$i" -eq "300" ]; then
118 kill_lttng_live_server
"$server_pid_file"
120 rm -f "$server_pid_file"
121 rm -f "$server_retcode_file"
128 port
=$
(<"$port_file")
130 diag
"LTTng live port is $port"
132 cli_args
=${cli_args_template//@PORT@/$port}
134 diag
"Running CLI: 'babeltrace2 $cli_args'"
135 if ! "$BT_TESTS_BT2_BIN" $cli_args 1>"$cli_stdout_file" 2>"$cli_stderr_file"; then
136 # CLI failed: cancel everything else
137 kill_lttng_live_server
"$server_pid_file"
139 rm -f "$server_pid_file"
140 rm -f "$server_retcode_file"
144 # get server's return code
146 while [ ! -s "$server_retcode_file" ]; do
149 # Timeout of 30 seconds
150 if [ "$i" -eq "300" ]; then
152 kill_lttng_live_server
"$server_pid_file"
154 rm -f "$server_pid_file"
155 rm -f "$server_retcode_file"
164 ret
=$
(<"$server_retcode_file")
166 rm -f "$server_pid_file"
167 rm -f "$server_retcode_file"
173 local cli_args_template
="$2"
174 local server_args
="$3"
175 local expected_stdout
="$4"
176 local expected_stderr
="$5"
183 cli_stderr
="$(mktemp)"
184 cli_stdout
="$(mktemp)"
185 port_file
="$(mktemp)"
187 get_cli_output_with_lttng_live_server
"$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file"
188 port
=$
(<"$port_file")
190 bt_diff
"$expected_stdout" "$cli_stdout"
191 ok $?
"$test_text - stdout"
192 bt_diff
"$expected_stderr" "$cli_stderr"
193 ok $?
"$test_text - stderr"
200 test_list_sessions
() {
201 # Test the basic listing of sessions.
202 # Ensure that a multi-domain trace is seen as a single session.
203 # run_test() is not used here because the port is needed to craft the
208 local tmp_stdout_expected
209 local template_expected
211 local test_text
="CLI prints the expected session list"
212 local cli_args_template
="-i lttng-live net://localhost:@PORT@"
213 local server_args
="'multi-domains,0,hostname,1,0,${trace_dir}/multi-domains/ust/' 'multi-domains,1,hostname,1,0,${trace_dir}/multi-domains/kernel/' 'trace-with-index,2,hostname,1,0,${trace_dir}/trace-with-index/' "
215 template_expected
=$
(<"$test_data_dir/cli-list-sessions.expect")
216 cli_stderr
="$(mktemp)"
217 cli_stdout
="$(mktemp)"
218 empty_file
="$(mktemp)"
219 port_file
="$(mktemp)"
220 tmp_stdout_expected
="$(mktemp)"
222 get_cli_output_with_lttng_live_server
"$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file"
223 port
=$
(<"$port_file")
225 # Craft the expected output. This is necessary since the port number
226 # (random) of a "relayd" is present in the output.
227 template_expected
=${template_expected//@PORT@/$port}
229 echo "$template_expected" > "$tmp_stdout_expected"
231 bt_diff
"$tmp_stdout_expected" "$cli_stdout"
232 ok $?
"$test_text - stdout"
233 bt_diff
"$empty_file" "$cli_stderr"
234 ok $?
"$test_text - stderr"
240 rm -f "$tmp_stdout_expected"
244 # Attach and consume data from a multi packets ust session with no
246 local test_text
="CLI attach and fetch from single-domains session - no discarded events"
247 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details"
248 local server_args
="'trace-with-index,0,hostname,1,0,${trace_dir}/trace-with-index/'"
249 local expected_stdout
="${test_data_dir}/cli-base.expect"
250 local expected_stderr
252 # Empty file for stderr expected
253 expected_stderr
=$
(mktemp
)
255 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
257 rm -f "$expected_stderr"
260 test_multi_domains
() {
261 # Attach and consume data from a multi-domains session with discarded
263 local test_text
="CLI attach and fetch from multi-domains session - discarded events"
264 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/multi-domains -c sink.text.details"
265 local server_args
="'multi-domains,0,hostname,1,0,${trace_dir}/multi-domains/kernel/,${trace_dir}/multi-domains/ust/'"
266 local expected_stdout
="${test_data_dir}/cli-multi-domains.expect"
267 local expected_stderr
269 # Empty file for stderr expected
270 expected_stderr
=$
(mktemp
)
272 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
274 rm -f "$expected_stderr"
277 test_rate_limited
() {
278 # Attach and consume data from a multi packets ust session with no
279 # discarded events. Enforce a server side limit on the stream data
280 # requests size. Ensure that babeltrace respect the returned size and that
281 # many requests per packet works as expected.
282 # The packet size of the test trace is 4k. Limit requests to 1k.
283 local test_text
="CLI many requests per packet"
284 local cli_args_template
="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details"
285 local server_args
="--max-query-data-response-size 1024 'trace-with-index,0,hostname,1,0,${trace_dir}/trace-with-index/'"
286 local expected_stdout
="${test_data_dir}/cli-base.expect"
287 local expected_stderr
289 # Empty file for stderr expected
290 expected_stderr
="$(mktemp)"
292 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
294 rm -f "$expected_stderr"
297 test_compare_to_ctf_fs
() {
298 # Compare the details text sink or ctf.fs and ctf.lttng-live to ensure
299 # that the trace is parsed the same way.
300 # Do the same with the session swapped on the relayd side. This validate
301 # that ordering is consistent between live and ctf fs.
302 local test_text
="CLI src.ctf.fs vs src.ctf.lttng-live"
303 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"
304 local server_args
="'multi-domains,0,hostname,1,0,${trace_dir}/multi-domains/kernel/' 'multi-domains,1,hostname,1,0,${trace_dir}/multi-domains/ust/'"
305 local server_args_inverse
="'multi-domains,0,hostname,1,0,${trace_dir}/multi-domains/ust/' 'multi-domains,1,hostname,1,0,${trace_dir}/multi-domains/kernel/'"
306 local expected_stdout
307 local expected_stderr
309 expected_stdout
=$
(mktemp
)
310 expected_stderr
=$
(mktemp
)
312 bt_cli
"$expected_stdout" "$expected_stderr" "${trace_dir}/multi-domains" -c sink.text.details
--params "with-trace-name=false,with-stream-name=false"
313 run_test
"$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
314 diag
"Inverse session order from lttng-relayd"
315 run_test
"$test_text" "$cli_args_template" "$server_args_inverse" "$expected_stdout" "$expected_stderr"
317 rm -f "$expected_stdout"
318 rm -f "$expected_stderr"
327 test_compare_to_ctf_fs