tests: use -z / -n to test for string empty / non-empty
[babeltrace.git] / tests / plugins / src.ctf.lttng-live / test_live
index 891ce45ae858a7878d8e679043b040dc2317fb83..e1766e158653039f80a2fb0984e5f073afc97a22 100755 (executable)
@@ -1,30 +1,19 @@
 #!/bin/bash
 #
-# Copyright (C) 2019 Philippe Proulx <pproulx@efficios.com>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; only version 2
-# of the License.
+# SPDX-License-Identifier: GPL-2.0-only
 #
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
+# Copyright (C) 2019 Philippe Proulx <pproulx@efficios.com>
 #
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 # This test validates that a `src.ctf.fs` component successfully reads
 # specific CTF traces and creates the expected messages.
 #
-# Such CTF traces to open either exist (in `tests/ctf-traces/succeed`)
+# Such CTF traces to open either exist (in `tests/ctf-traces/`)
 # or are generated by this test using local trace generators.
 
 SH_TAP=1
 
-if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
+if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
        UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
 else
        UTILSSH="$(dirname "$0")/../../utils/utils.sh"
@@ -47,9 +36,9 @@ trap cleanup SIGINT SIGTERM
 
 this_dir_relative="plugins/src.ctf.lttng-live"
 test_data_dir="$BT_TESTS_DATADIR/$this_dir_relative"
-trace_dir="$BT_CTF_TRACES_PATH/succeed"
+trace_dir="$BT_CTF_TRACES_PATH"
 
-if [ "$BT_OS_TYPE" = "mingw" ]; then
+if [ "$BT_TESTS_OS_TYPE" = "mingw" ]; then
        # Same as the above, but in Windows form (C:\foo\bar) instead of Unix form
        # (/c/foo/bar).
        trace_dir_native=$(cygpath -w "${trace_dir}")
@@ -65,7 +54,10 @@ lttng_live_server() {
        local server_script="$test_data_dir/lttng_live_server.py"
 
        # start server
-       echo "$server_args" | xargs "$BT_TESTS_PYTHON_BIN" "$server_script" --port-file "$port_file" &
+       diag "$BT_TESTS_PYTHON_BIN $server_script --port-file $port_file --trace-path-prefix $trace_dir_native $server_args"
+       echo "$server_args" | xargs "$BT_TESTS_PYTHON_BIN" "$server_script" \
+               --port-file "$port_file" \
+               --trace-path-prefix "$trace_dir_native" &
 
        # write PID to file
        echo $! > "$pid_file"
@@ -89,7 +81,7 @@ kill_lttng_live_server() {
 
 get_cli_output_with_lttng_live_server() {
        local cli_args_template="$1"
-       local server_args="$2"
+       local sessions_file="$2"
        local cli_stdout_file="$3"
        local cli_stderr_file="$4"
        local port_file="$5"
@@ -113,7 +105,7 @@ get_cli_output_with_lttng_live_server() {
        # lttng_live_server() writes its return code to the
        # `$server_retcode_file` file.
        lttng_live_server "$port_file" "$server_pid_file" \
-               "$server_retcode_file" "$server_args" &
+               "$server_retcode_file" "$sessions_file" &
 
        # Get port number
        i=0
@@ -139,8 +131,10 @@ get_cli_output_with_lttng_live_server() {
 
        cli_args=${cli_args_template//@PORT@/$port}
 
-       diag "Running CLI: 'babeltrace2 $cli_args'"
-       if ! "$BT_TESTS_BT2_BIN" $cli_args 1>"$cli_stdout_file" 2>"$cli_stderr_file"; then
+       # Split argument string by spaces into an array.
+       IFS=' ' read -ra cli_args <<< "$cli_args"
+
+       if ! bt_cli "$cli_stdout_file" "$cli_stderr_file" "${cli_args[@]}"; then
                # CLI failed: cancel everything else
                kill_lttng_live_server "$server_pid_file"
                wait
@@ -186,7 +180,7 @@ run_test() {
        local cli_stderr
        local cli_stdout
        local port_file
-        local port
+       local port
 
        cli_stderr="$(mktemp -t test_live_stderr.XXXXXX)"
        cli_stdout="$(mktemp -t test_live_stdout.XXXXXX)"
@@ -218,7 +212,8 @@ test_list_sessions() {
 
        local test_text="CLI prints the expected session list"
        local cli_args_template="-i lttng-live net://localhost:@PORT@"
-       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/' "
+       local sessions_file="$test_data_dir/list_sessions.json"
+       local server_args="--sessions-filename '$sessions_file'"
 
        template_expected=$(<"$test_data_dir/cli-list-sessions.expect")
        cli_stderr="$(mktemp -t test_live_list_sessions_stderr.XXXXXX)"
@@ -253,7 +248,8 @@ test_base() {
        # discarded events.
        local test_text="CLI attach and fetch from single-domains session - no discarded events"
        local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details"
-       local server_args="'trace-with-index,0,hostname,1,0,${trace_dir_native}/trace-with-index/'"
+       local sessions_file="$test_data_dir/base.json"
+       local server_args="--sessions-filename '$sessions_file'"
        local expected_stdout="${test_data_dir}/cli-base.expect"
        local expected_stderr
 
@@ -270,8 +266,9 @@ test_multi_domains() {
        # events.
        local test_text="CLI attach and fetch from multi-domains session - discarded events"
        local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/multi-domains -c sink.text.details"
-       local server_args="'multi-domains,0,hostname,1,0,${trace_dir_native}/multi-domains/kernel/,${trace_dir_native}/multi-domains/ust/'"
-       local expected_stdout="${test_data_dir}/cli-multi-domains.expect"
+       local sessions_file="${test_data_dir}/multi_domains.json"
+       local server_args="--sessions-filename '$sessions_file'"
+       local expected_stdout="$test_data_dir/cli-multi-domains.expect"
        local expected_stderr
 
        # Empty file for stderr expected
@@ -290,7 +287,8 @@ test_rate_limited() {
        # The packet size of the test trace is 4k. Limit requests to 1k.
        local test_text="CLI many requests per packet"
        local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/trace-with-index -c sink.text.details"
-       local server_args="--max-query-data-response-size 1024 'trace-with-index,0,hostname,1,0,${trace_dir_native}/trace-with-index/'"
+       local sessions_file="$test_data_dir/rate_limited.json"
+       local server_args="--max-query-data-response-size 1024 --sessions-filename '$sessions_file'"
        local expected_stdout="${test_data_dir}/cli-base.expect"
        local expected_stderr
 
@@ -309,15 +307,17 @@ test_compare_to_ctf_fs() {
        # that ordering is consistent between live and ctf fs.
        local test_text="CLI src.ctf.fs vs src.ctf.lttng-live"
        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"
-       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/'"
-       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/'"
+       local sessions_file="$test_data_dir/multi_domains.json"
+       local sessions_file_inverse="$test_data_dir/multi_domains_inverse.json"
+       local server_args="--sessions-filename '$sessions_file'"
+       local server_args_inverse="--sessions-filename '$sessions_file_inverse'"
        local expected_stdout
        local expected_stderr
 
        expected_stdout="$(mktemp -t test_live_compare_stdout_expected.XXXXXX)"
        expected_stderr="$(mktemp -t test_live_compare_stderr_expected.XXXXXX)"
 
-       bt_cli "$expected_stdout" "$expected_stderr" "${trace_dir}/multi-domains" -c sink.text.details --params "with-trace-name=false,with-stream-name=false"
+       bt_cli "$expected_stdout" "$expected_stderr" "${trace_dir}/succeed/multi-domains" -c sink.text.details --params "with-trace-name=false,with-stream-name=false"
        bt_remove_cr "${expected_stdout}"
        bt_remove_cr "${expected_stderr}"
        run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
@@ -328,10 +328,78 @@ test_compare_to_ctf_fs() {
        rm -f "$expected_stderr"
 }
 
-plan_tests 12
+test_inactivity_discarded_packet() {
+       # Attach and consume data from a multi-packet trace with discarded
+       # packets and emit an inactivity beacon during the discarded packets
+       # period.
+       #
+       # | pkt seq:0 |<-------discarded packets------>| pkt seq:8 |
+       # 0          20                                121       140
+       #
+       # This test was introduced to cover the following bug:
+       #
+       # When reading this type of trace locally, the CTF source is expected
+       # to introduce a "Discarded packets" message between packets 0 and 8.
+       # The timestamps of this message are [pkt0.end_ts, pkt8.begin_ts].
+       #
+       # In the context of a live source, the tracer could report an inactivity
+       # period during the interval of the "Discarded packets" message.
+       # Those messages eventually translate into a
+       # "Iterator inactivity" message with a timestamp set at the end of the
+       # inactivity period.
+       #
+       # If the tracer reports an inactivity period that ends at a point
+       # between pkt0 and pkt7 (resulting in an "Iterator inactivity" message),
+       # the live source could send a "Discarded packets" message that starts
+       # before the preceding "Iterator inactivity" message. This would break
+       # the monotonicity constraint of the graph.
+       local test_text="CLI attach and fetch from single-domains session - inactivity discarded packet"
+       local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/7_lost_between_2_with_index -c sink.text.details"
+       local sessions_file="$test_data_dir/inactivity_discarded_packet.json"
+       local server_args="--sessions-filename '$sessions_file'"
+       local expected_stdout="$test_data_dir/inactivity_discarded_packet.expect"
+       local expected_stderr
+
+       # Empty file for stderr expected
+       expected_stderr="$(mktemp -t test_live_inactivity_discarded_packet_stderr_expected.XXXXXX)"
+
+       run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
+
+       rm -f "$expected_stderr"
+}
+
+test_split_metadata() {
+       # Consume a metadata stream sent in two parts. This testcase tests the
+       # behaviour of Babeltrace when the tracing session was cleared (lttng
+       # clear) but the metadata is not yet available to the relay. In such
+       # cases, when asked for metadata, the relay will return the
+       # `LTTNG_VIEWER_METADATA_OK` status and a data length of 0. The viewer
+       # need to consider such case as a request to retry fetching metadata.
+       #
+       # This testcase emulates such behaviour by adding empty metadata
+       # packets.
+
+       local test_text="CLI attach and fetch from single-domain session - Receive metadata in two sections separated by a empty section"
+       local cli_args_template="-i lttng-live net://localhost:@PORT@/host/hostname/split_metadata -c sink.text.details"
+       local sessions_file="$test_data_dir/split_metadata.json"
+       local server_args="--sessions-filename '$sessions_file'"
+       local expected_stdout="${test_data_dir}/split_metadata.expect"
+       local expected_stderr
+
+       # Empty file for stderr expected
+       expected_stderr="$(mktemp -t test_live_split_metadata_stderr_expected.XXXXXX)"
+
+       run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
+
+       rm -f "$expected_stderr"
+}
+
+plan_tests 16
 
 test_list_sessions
 test_base
 test_multi_domains
 test_rate_limited
 test_compare_to_ctf_fs
+test_inactivity_discarded_packet
+test_split_metadata
This page took 0.027805 seconds and 4 git commands to generate.