tests: improve debuggability of `cli/test-trace-copy.sh`
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 1 Mar 2024 15:49:47 +0000 (10:49 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Mar 2024 18:56:36 +0000 (14:56 -0400)
When something fails in `cli/test-trace-copy.sh`, we don't really know
why, as everything is sent to `/dev/null`.

Make the test record stderr and print it (using tap's `diag`) when
something fails.

Add the `diag_file` helper to make that easy.

Change-Id: I2eb85cd5fffb136cddf2457089681ee57c21e4f7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11963
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
tests/cli/test-trace-copy.sh
tests/utils/utils.sh

index a3fb4544bad0f56e2ca21e99db297dc66ba7e336..5b9f9ad530505f33d1f6426d8810921d00f22dca 100755 (executable)
@@ -17,7 +17,7 @@ fi
 source "$UTILSSH"
 
 clean_tmp() {
-       rm -rf "${out_path}" "${text_output1}" "${text_output2_intermediary}" "${text_output2}"
+       rm -rf "${out_path}" "${text_output1}" "${text_output2_intermediary}" "${text_output2}" "${stderr_file}"
 }
 
 SUCCESS_TRACES=("${BT_CTF_TRACES_PATH}/succeed/"*)
@@ -32,6 +32,7 @@ for path in "${SUCCESS_TRACES[@]}"; do
        text_output1="$(mktemp)"
        text_output2_intermediary="$(mktemp)"
        text_output2="$(mktemp)"
+       stderr_file="$(mktemp)"
        trace="$(basename "${path}")"
        sort_cmd="cat" # by default do not sort the trace
 
@@ -65,16 +66,25 @@ for path in "${SUCCESS_TRACES[@]}"; do
                fi
        fi
 
-       bt_cli "/dev/null" "/dev/null" "${path}" --component sink.ctf.fs "--params=path=\"${out_path}\""
-       ok $? "Copy trace ${trace} with ctf-fs sink"
+       bt_cli "/dev/null" "${stderr_file}" "${path}" --component sink.ctf.fs "--params=path=\"${out_path}\""
+       if ! ok $? "Copy trace ${trace} with ctf-fs sink"; then
+               diag "stderr:"
+               diag_file "${stderr_file}"
+       fi
+
+       bt_cli "/dev/null" "${stderr_file}" "${out_path}"
+       if ! ok $? "Read the new trace in ${out_path}"; then
+               diag "stderr:"
+               diag_file "${stderr_file}"
+       fi
 
-       bt_cli "/dev/null" "/dev/null" "${out_path}"
-       ok $? "Read the new trace in ${out_path}"
+       if ! bt_cli "${text_output2_intermediary}" "${stderr_file}" --no-delta "${out_path}"; then
+               diag "stderr:"
+               diag_file "${stderr_file}"
+       fi
 
-       bt_cli "${text_output2_intermediary}" "/dev/null" --no-delta "${out_path}"
        $sort_cmd "${text_output2_intermediary}" > "${text_output2}"
-       cnt=$(diff "${text_output1}" "${text_output2}" | wc -l)
-       test "${cnt// /}" == 0
+       bt_diff "${text_output1}" "${text_output2}"
        ok $? "Exact same content between the two traces"
 
        clean_tmp
index 5c7b3eeb54e43bb465c1225da9292e258a2a2811..9081a88e2e871324448adfc0620bae33db4cc4fb 100644 (file)
@@ -487,3 +487,9 @@ bt_gen_mctf_trace() {
        echo "Running: \`${cmd[*]}\`" >&2
        bt_run_in_py_utils_env "${cmd[@]}"
 }
+
+# Call `diag` with the contents of file `$1`.
+
+diag_file() {
+       diag "$(cat "$1")"
+}
This page took 0.027796 seconds and 4 git commands to generate.