tests/src.ctf.fs/test_fail: test with both autodiscovery and explicit component insta...
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 10 Nov 2023 16:33:48 +0000 (16:33 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
Specifying a path to a failing trace like this:

  babeltrace2 mytrace

vs

  babeltrace2 -c src.ctf.fs -p 'inputs=["mytrace"]'

... exercises different code paths.  If the failure is due to bad
metadata, the first one will error out during the support-info query
phrase, whereas the second one will error out in the component
initialization.  I think it would be good to exercise both in the test
with failing traces.

Rename the test_fail function to test_fail_method, and add a parameter
indicating which method of passing the trace path to use (autodisc vs
component).  Add a new test_fail function that tries with both methods.

Change-Id: Ieb65504a773b0915946f8ef543a7d0930ca0a7d7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12750
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
tests/plugins/src.ctf.fs/fail/test-fail.sh
tests/utils/utils.sh

index 1eb91971de1a7c0a4c447c8c964f65f429303731..330302405658717e18fdefff2748bc28067776b8 100755 (executable)
@@ -31,22 +31,35 @@ fail_trace_path() {
        echo "$BT_CTF_TRACES_PATH/$ctf_version/fail/$name"
 }
 
-# Parameters: <trace-name> <ctf-version> <expected-stdout-file> <expected-error-msg>
-test_fail() {
+# Parameters: <trace-name> <ctf-version> <method> <expected-stdout-file> <expected-error-msg>
+#
+# <method> can be either "autodisc" or "component".  "autodisc" passes the trace
+# path directly to babeltrace2, making it use the auto-discovery mechanism.
+# "component" instantiates a `src.ctf.fs` component explicitly.
+test_fail_method() {
        local name="$1"
-       local ctf_version=$2
-       local expected_stdout_file="$3"
-       local expected_error_msg="$4"
+       local ctf_version="$2"
+       local method="$3"
+       local expected_stdout_file="$4"
+       local expected_error_msg="$5"
        local trace_path
 
        trace_path=$(fail_trace_path "$name" "$ctf_version")
 
-       bt_cli "${stdout_file}" "${stderr_file}" \
-               -c sink.text.details -p "with-trace-name=no,with-stream-name=no" "$trace_path"
-       isnt $? 0 "Trace ${name}: babeltrace exits with an error"
+       if [ "$method" = "autodisc" ]; then
+               bt_cli "${stdout_file}" "${stderr_file}" \
+                       -c sink.text.details -p "with-trace-name=no,with-stream-name=no" "$trace_path"
+       elif [ "$method" = "component" ]; then
+               bt_cli "${stdout_file}" "${stderr_file}" \
+                       -c sink.text.details -p "with-trace-name=no,with-stream-name=no" -c src.ctf.fs -p "inputs=[\"$(bt_maybe_cygpath_m "$trace_path")\"]"
+       else
+               echo "invalid method: $method"
+               exit 1
+       fi
+       isnt $? 0 "Trace ${name}: method $method: babeltrace exits with an error"
 
        bt_diff "${expected_stdout_file}" "${stdout_file}"
-       ok $? "Trace ${name}: babeltrace produces the expected stdout"
+       ok $? "Trace ${name}: method $method: babeltrace produces the expected stdout"
 
        # The expected error message will likely be found in the error stream
        # even if Babeltrace aborts (e.g. hits an assert).  Check that the
@@ -55,16 +68,27 @@ test_fail() {
        bt_grep_ok \
                "^CAUSED BY " \
                "$stderr_file" \
-               "Trace $name: babeltrace produces an error stack"
+               "Trace ${name}: method $method: babeltrace produces an error stack"
 
        bt_grep_ok \
                "$expected_error_msg" \
                "$stderr_file" \
-               "Trace $name: babeltrace produces the expected error message"
+               "Trace ${name}: method $method: babeltrace produces the expected error message"
 }
 
+# Parameters: <trace-name> <ctf-version> <expected-stdout-file> <expected-error-msg>
+test_fail() {
+       local name="$1"
+       local ctf_version="$2"
+       local expected_stdout_file="$3"
+       local expected_error_msg="$4"
+       for method in autodisc component; do
+               test_fail_method "$name" "$ctf_version" "$method" \
+                       "$expected_stdout_file" "$expected_error_msg"
+       done
+}
 
-plan_tests 20
+plan_tests 40
 
 test_fail \
        "invalid-packet-size/trace" \
@@ -73,7 +97,7 @@ test_fail \
        "Failed to index CTF stream file '.*channel0_3'"
 
 test_fail \
-       "valid-events-then-invalid-events" \
+       "valid-events-then-invalid-events/trace" \
        1 \
        "${data_dir}/valid-events-then-invalid-events.expect" \
        "At 24 bits: no event record class exists with ID 255 within the data stream class with ID 0."
index c597418b24eed550ee2ddbae59d0b7717bfa7f20..37ffc1e1109a023320cf312915f27138b2bb874c 100644 (file)
@@ -510,3 +510,15 @@ bt_gen_mctf_trace() {
 diag_file() {
        diag "$(cat "$1")"
 }
+
+# On MinGW, prints `$1` passed through `cygpath -m`. Otherwise, print `$1`
+# unmodified.
+bt_maybe_cygpath_m() {
+       local path=$1
+
+       if [[ $BT_TESTS_OS_TYPE == mingw ]]; then
+               path=$(cygpath -m "$path")
+       fi
+
+       echo "$path"
+}
This page took 0.025932 seconds and 4 git commands to generate.