tests: move --port-file and --trace-path-prefix arguments up one level
[babeltrace.git] / tests / plugins / src.ctf.lttng-live / test_live
index deee081a2f02fdfb5919f6feb476f52792bb13a7..cb4cfc0f7d1f46ce96d42e986f8b97139d56da84 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"
@@ -54,9 +55,8 @@ 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" \
-               --trace-path-prefix "$trace_dir_native" &
+       diag "$BT_TESTS_PYTHON_BIN $server_script $server_args"
+       echo "$server_args" | run_python xargs "$BT_TESTS_PYTHON_BIN" "$server_script" 1>&2 &
 
        # write PID to file
        echo $! > "$pid_file"
@@ -80,7 +80,7 @@ kill_lttng_live_server() {
 
 get_cli_output_with_lttng_live_server() {
        local cli_args_template="$1"
-       local sessions_file="$2"
+       local server_args="$2"
        local cli_stdout_file="$3"
        local cli_stderr_file="$4"
        local port_file="$5"
@@ -91,7 +91,8 @@ get_cli_output_with_lttng_live_server() {
        local cli_args
        local server_pid_file
        local server_retcode_file
-
+       
+       server_args="--port-file $port_file --trace-path-prefix \"$trace_dir_native\" $server_args"
        server_pid_file="$(mktemp -t test_live_server_pid.XXXXXX)"
        server_retcode_file="$(mktemp -t test_live_server_ret.XXXXX)"
 
@@ -104,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" "$sessions_file" &
+               "$server_retcode_file" "$server_args" &
 
        # Get port number
        i=0
@@ -212,7 +213,7 @@ 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="'$sessions_file'"
 
        template_expected=$(<"$test_data_dir/cli-list-sessions.expect")
        cli_stderr="$(mktemp -t test_live_list_sessions_stderr.XXXXXX)"
@@ -248,7 +249,7 @@ test_base() {
        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="'$sessions_file'"
        local expected_stdout="${test_data_dir}/cli-base.expect"
        local expected_stderr
 
@@ -266,7 +267,7 @@ test_multi_domains() {
        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="'$sessions_file'"
        local expected_stdout="$test_data_dir/cli-multi-domains.expect"
        local expected_stderr
 
@@ -287,7 +288,7 @@ test_rate_limited() {
        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 '$sessions_file'"
        local expected_stdout="${test_data_dir}/cli-base.expect"
        local expected_stderr
 
@@ -308,8 +309,8 @@ test_compare_to_ctf_fs() {
        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="'$sessions_file'"
+       local server_args_inverse="'$sessions_file_inverse'"
        local expected_stdout
        local expected_stderr
 
@@ -355,7 +356,7 @@ test_inactivity_discarded_packet() {
        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="'$sessions_file'"
        local expected_stdout="$test_data_dir/inactivity_discarded_packet.expect"
        local expected_stderr
 
@@ -367,7 +368,33 @@ test_inactivity_discarded_packet() {
        rm -f "$expected_stderr"
 }
 
-plan_tests 14
+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_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
@@ -375,3 +402,4 @@ test_multi_domains
 test_rate_limited
 test_compare_to_ctf_fs
 test_inactivity_discarded_packet
+test_split_metadata
This page took 0.025615 seconds and 4 git commands to generate.