tests: use /dev/null instead of empty files in src.ctf.lttng-live test
[babeltrace.git] / tests / plugins / src.ctf.lttng-live / test_live
index deee081a2f02fdfb5919f6feb476f52792bb13a7..301a6a2042f789a6c21310a161cb5c4d8b61c2e5 100755 (executable)
@@ -5,15 +5,16 @@
 # Copyright (C) 2019 Philippe Proulx <pproulx@efficios.com>
 #
 
-# This test validates that a `src.ctf.fs` component successfully reads
-# specific CTF traces and creates the expected messages.
+# This test validates that a `src.ctf.lttng-live` component successfully does
+# various tasks that a `src.ctf.lttng-live` component is expected to do, like
+# listing tracing sessions and receiving live traces / producing the expected
+# messages out of it.
 #
-# Such CTF traces to open either exist (in `tests/ctf-traces/`)
-# or are generated by this test using local trace generators.
+# A mock LTTng live server is used to feed data to the component.
 
 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,16 +48,16 @@ else
 fi
 
 lttng_live_server() {
-       local port_file="$1"
-       local pid_file="$2"
-       local retcode_file="$3"
-       local server_args="$4"
+       local pid_file="$1"
+       local retcode_file="$2"
+       shift 2
+       local server_args=("$@")
+
        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" \
-               --trace-path-prefix "$trace_dir_native" &
+       diag "$BT_TESTS_PYTHON_BIN $server_script ${server_args[*]}"
+       run_python "$BT_TESTS_PYTHON_BIN" "$server_script" "${server_args[@]}" 1>&2 &
 
        # write PID to file
        echo $! > "$pid_file"
@@ -80,10 +81,12 @@ kill_lttng_live_server() {
 
 get_cli_output_with_lttng_live_server() {
        local cli_args_template="$1"
-       local sessions_file="$2"
-       local cli_stdout_file="$3"
-       local cli_stderr_file="$4"
-       local port_file="$5"
+       local cli_stdout_file="$2"
+       local cli_stderr_file="$3"
+       local port_file="$4"
+       local trace_path_prefix="$5"
+       shift 5
+       local server_args=("$@")
 
        local i
        local ret
@@ -92,6 +95,7 @@ get_cli_output_with_lttng_live_server() {
        local server_pid_file
        local server_retcode_file
 
+       server_args+=(--port-file "$port_file" --trace-path-prefix "$trace_path_prefix")
        server_pid_file="$(mktemp -t test_live_server_pid.XXXXXX)"
        server_retcode_file="$(mktemp -t test_live_server_ret.XXXXX)"
 
@@ -103,8 +107,7 @@ get_cli_output_with_lttng_live_server() {
        # `$server_pid_file` file. When the server exits,
        # lttng_live_server() writes its return code to the
        # `$server_retcode_file` file.
-       lttng_live_server "$port_file" "$server_pid_file" \
-               "$server_retcode_file" "$sessions_file" &
+       lttng_live_server "$server_pid_file" "$server_retcode_file" "${server_args[@]}" &
 
        # Get port number
        i=0
@@ -172,9 +175,11 @@ get_cli_output_with_lttng_live_server() {
 run_test() {
        local test_text="$1"
        local cli_args_template="$2"
-       local server_args="$3"
-       local expected_stdout="$4"
-       local expected_stderr="$5"
+       local expected_stdout="$3"
+       local expected_stderr="$4"
+       local trace_path_prefix="$5"
+       shift 5
+       local server_args=("$@")
 
        local cli_stderr
        local cli_stdout
@@ -185,7 +190,8 @@ run_test() {
        cli_stdout="$(mktemp -t test_live_stdout.XXXXXX)"
        port_file="$(mktemp -t test_live_server_port.XXXXXX)"
 
-       get_cli_output_with_lttng_live_server "$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file"
+       get_cli_output_with_lttng_live_server "$cli_args_template" "$cli_stdout" \
+               "$cli_stderr" "$port_file" "$trace_path_prefix" "${server_args[@]}"
        port=$(<"$port_file")
 
        bt_diff "$expected_stdout" "$cli_stdout"
@@ -211,17 +217,16 @@ test_list_sessions() {
 
        local test_text="CLI prints the expected session list"
        local cli_args_template="-i lttng-live net://localhost:@PORT@"
-       local sessions_file="$test_data_dir/list_sessions.json"
-       local server_args="--sessions-filename '$sessions_file'"
+       local server_args=("$test_data_dir/list_sessions.json")
 
        template_expected=$(<"$test_data_dir/cli-list-sessions.expect")
        cli_stderr="$(mktemp -t test_live_list_sessions_stderr.XXXXXX)"
        cli_stdout="$(mktemp -t test_live_list_sessions_stdout.XXXXXX)"
-       empty_file="$(mktemp -t test_live_list_sessions_empty.XXXXXX)"
        port_file="$(mktemp -t test_live_list_sessions_server_port.XXXXXX)"
        tmp_stdout_expected="$(mktemp -t test_live_list_sessions_stdout_expected.XXXXXX)"
 
-       get_cli_output_with_lttng_live_server "$cli_args_template" "$server_args" "$cli_stdout" "$cli_stderr" "$port_file"
+       get_cli_output_with_lttng_live_server "$cli_args_template" "$cli_stdout" \
+               "$cli_stderr" "$port_file" "$trace_dir_native" "${server_args[@]}"
        port=$(<"$port_file")
 
        # Craft the expected output. This is necessary since the port number
@@ -232,12 +237,11 @@ test_list_sessions() {
 
        bt_diff "$tmp_stdout_expected" "$cli_stdout"
        ok $? "$test_text - stdout"
-       bt_diff "$empty_file" "$cli_stderr"
+       bt_diff "/dev/null" "$cli_stderr"
        ok $? "$test_text - stderr"
 
        rm -f "$cli_stderr"
        rm -f "$cli_stdout"
-       rm -f "$empty_file"
        rm -f "$port_file"
        rm -f "$tmp_stdout_expected"
 }
@@ -247,17 +251,12 @@ 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 sessions_file="$test_data_dir/base.json"
-       local server_args="--sessions-filename '$sessions_file'"
+       local server_args=("$test_data_dir/base.json")
        local expected_stdout="${test_data_dir}/cli-base.expect"
-       local expected_stderr
-
-       # Empty file for stderr expected
-       expected_stderr="$(mktemp -t test_live_base_stderr_expected.XXXXXX)"
-
-       run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
+       local expected_stderr="/dev/null"
 
-       rm -f "$expected_stderr"
+       run_test "$test_text" "$cli_args_template" "$expected_stdout" \
+               "$expected_stderr" "$trace_dir_native" "${server_args[@]}"
 }
 
 test_multi_domains() {
@@ -265,17 +264,12 @@ 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 sessions_file="${test_data_dir}/multi_domains.json"
-       local server_args="--sessions-filename '$sessions_file'"
+       local server_args=("${test_data_dir}/multi_domains.json")
        local expected_stdout="$test_data_dir/cli-multi-domains.expect"
-       local expected_stderr
-
-       # Empty file for stderr expected
-       expected_stderr="$(mktemp -t test_live_multi_domains_stderr_expected.XXXXXX)"
+       local expected_stderr="/dev/null"
 
-       run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
-
-       rm -f "$expected_stderr"
+       run_test "$test_text" "$cli_args_template" "$expected_stdout" \
+               "$expected_stderr" "$trace_dir_native" "${server_args[@]}"
 }
 
 test_rate_limited() {
@@ -286,17 +280,12 @@ 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 sessions_file="$test_data_dir/rate_limited.json"
-       local server_args="--max-query-data-response-size 1024 --sessions-filename '$sessions_file'"
+       local server_args=(--max-query-data-response-size 1024 "$test_data_dir/rate_limited.json")
        local expected_stdout="${test_data_dir}/cli-base.expect"
-       local expected_stderr
-
-       # Empty file for stderr expected
-       expected_stderr="$(mktemp -t test_live_rate_limited_stderr_expected.XXXXXX)"
-
-       run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
+       local expected_stderr="/dev/null"
 
-       rm -f "$expected_stderr"
+       run_test "$test_text" "$cli_args_template" "$expected_stdout" \
+               "$expected_stderr" "$trace_dir_native" "${server_args[@]}"
 }
 
 test_compare_to_ctf_fs() {
@@ -306,10 +295,8 @@ 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 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 server_args=("$test_data_dir/multi_domains.json")
+       local server_args_inverse=("$test_data_dir/multi_domains_inverse.json")
        local expected_stdout
        local expected_stderr
 
@@ -319,9 +306,11 @@ test_compare_to_ctf_fs() {
        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"
+       run_test "$test_text" "$cli_args_template" "$expected_stdout" \
+               "$expected_stderr" "$trace_dir_native" "${server_args[@]}"
        diag "Inverse session order from lttng-relayd"
-       run_test "$test_text" "$cli_args_template" "$server_args_inverse" "$expected_stdout" "$expected_stderr"
+       run_test "$test_text" "$cli_args_template" "$expected_stdout" \
+               "$expected_stderr" "$trace_dir_native" "${server_args_inverse[@]}"
 
        rm -f "$expected_stdout"
        rm -f "$expected_stderr"
@@ -354,20 +343,36 @@ test_inactivity_discarded_packet() {
        # 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 server_args=("$test_data_dir/inactivity_discarded_packet.json")
        local expected_stdout="$test_data_dir/inactivity_discarded_packet.expect"
-       local expected_stderr
+       local expected_stderr="/dev/null"
 
-       # Empty file for stderr expected
-       expected_stderr="$(mktemp -t test_live_inactivity_discarded_packet_stderr_expected.XXXXXX)"
+       run_test "$test_text" "$cli_args_template" "$expected_stdout" \
+               "$expected_stderr" "$trace_dir_native" "${server_args[@]}"
+}
+
+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.
 
-       run_test "$test_text" "$cli_args_template" "$server_args" "$expected_stdout" "$expected_stderr"
+       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 server_args=("$test_data_dir/split_metadata.json")
+       local expected_stdout="${test_data_dir}/split_metadata.expect"
+       local expected_stderr="/dev/null"
 
-       rm -f "$expected_stderr"
+       run_test "$test_text" "$cli_args_template" "$expected_stdout" \
+               "$expected_stderr" "$trace_dir_native" "${server_args[@]}"
 }
 
-plan_tests 14
+plan_tests 16
 
 test_list_sessions
 test_base
@@ -375,3 +380,4 @@ test_multi_domains
 test_rate_limited
 test_compare_to_ctf_fs
 test_inactivity_discarded_packet
+test_split_metadata
This page took 0.02633 seconds and 4 git commands to generate.