tests: make test_intersection use bt_cli, test error cases
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 19 Sep 2019 19:45:53 +0000 (15:45 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Tue, 15 Oct 2019 18:09:56 +0000 (14:09 -0400)
The way test_intersection is written doesn't make it check whether the
babeltrace2 binary exits with success or failure.  In two cases
(nointersect and nostream), the babeltrace2 binary errors out, but it
isn't explicitly validated by the test, so it's unclear whether this is
the behavior we want.  The test just validates that nothing is output on
stdout, but that could happen because the process prints nothing and
exits with success, or because it prints an error on stderr and exits
with a failure status code.

This patch improves the test by making it use bt_cli instead of running
the babeltrace2 binary directly.  This helps when troubleshooting the
test, since bt_cli prints the full command line with which it invokes
babeltrace2.

Then, it makes the test check the exit status of babeltrace2.  In the
cases nointersect and nostream, we validate that it exits with a
non-zero status code, and that it prints an expected error string on
stderr.  It adds a relatively trivial call to
BT_COMP_CLASS_LOGE_APPEND_CAUSE in the src.ctf.fs query code to make the
error message clearer in the nostream case.

I don't know if the current behavior of babeltrace2 in these two cases
is the one we want, but the goal of this patch is merely to update the
test to better test the current behavior.  If we'd like a different
behavior, we can always modify babeltrace2 and the test later.

Change-Id: I1d6e616005369e397c98bdb1e40407e4e3959cc9
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2068
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/fs-src/query.c
tests/cli/test_intersection

index 3deb0cb18f6b7d324b7fb78b75d9d36e9759ffd5..33d9169c5b21805c5474d6ea0440e2a687c5f2e5 100644 (file)
@@ -278,7 +278,9 @@ end:
 }
 
 static
-int populate_trace_info(const struct ctf_fs_trace *trace, bt_value *trace_info)
+int populate_trace_info(const struct ctf_fs_trace *trace, bt_value *trace_info,
+               bt_logging_level log_level,
+               bt_self_component_class *self_comp_class)
 {
        int ret = 0;
        size_t group_idx;
@@ -290,6 +292,8 @@ int populate_trace_info(const struct ctf_fs_trace *trace, bt_value *trace_info)
        /* Add trace range info only if it contains streams. */
        if (trace->ds_file_groups->len == 0) {
                ret = -1;
+               BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
+                       "Trace has no streams: trace-path=%s", trace->path->str);
                goto end;
        }
 
@@ -383,7 +387,8 @@ bt_component_class_query_method_status trace_infos_query(
                goto error;
        }
 
-       ret = populate_trace_info(ctf_fs->trace, trace_info);
+       ret = populate_trace_info(ctf_fs->trace, trace_info, log_level,
+               self_comp_class);
        if (ret) {
                goto error;
        }
index 1f8d20cfd376f24fe73d218d659d9331f0ac4d66..f5be6b70d4430eb17d0037258688e0d7cee9fcf1 100755 (executable)
@@ -26,9 +26,10 @@ fi
 # shellcheck source=../utils/utils.sh
 source "$UTILSSH"
 
-NUM_TESTS=10
+plan_tests 20
 
-plan_tests $NUM_TESTS
+stdout=$(mktemp -t test_intersection_stdout.XXXXXX)
+stderr=$(mktemp -t test_intersection_stderr.XXXXXX)
 
 test_intersect() {
        local trace="$1"
@@ -37,13 +38,38 @@ test_intersect() {
 
        local cnt
 
-       cnt=$("${BT_TESTS_BT2_BIN}" "$trace" | wc -l)
+       bt_cli "${stdout}" "/dev/null" "${trace}"
+       ok $? "run without --stream-intersection"
+
+       cnt=$(wc -l < "${stdout}")
        test "${cnt// /}" = "$totalevents"
        ok $? "$totalevents events in the whole trace"
 
-       cnt=$("${BT_TESTS_BT2_BIN}" --stream-intersection "$trace" 2>/dev/null| wc -l)
+       bt_cli "${stdout}" "/dev/null" --stream-intersection "${trace}"
+       ok $? "run with --stream-intersection"
+
+       cnt=$(wc -l < "${stdout}")
        test "${cnt// /}" = "$intersect"
-       ok $? "$intersect events in packets intersecting"
+       ok $? "$intersect events in streams intersecting"
+}
+
+test_intersect_fails() {
+       local trace="$1"
+       local totalevents="$2"
+       local expected_error_message="$3"
+
+       bt_cli "${stdout}" "/dev/null" "${trace}"
+       ok $? "run without --stream-intersection"
+
+       cnt=$(wc -l < "${stdout}")
+       test "${cnt// /}" = "$totalevents"
+       ok $? "$totalevents events in the whole trace"
+
+       bt_cli "${stdout}" "${stderr}" --stream-intersection "${trace}"
+       isnt "$?" 0 "run with --stream-intersection fails"
+
+       grep --silent "${expected_error_message}" "${stderr}"
+       ok $? "stderr contains expected error message"
 }
 
 diag "Test the stream intersection feature"
@@ -54,11 +80,15 @@ test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersect" 8 3
 diag "2 streams offsetted with 3 packets intersecting (exchanged file names)"
 test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersectreverse" 8 3
 
-diag "No intersection between 2 streams"
-test_intersect "${BT_CTF_TRACES_PATH}/intersection/nointersect" 6 0
-
 diag "Only 1 stream"
 test_intersect "${BT_CTF_TRACES_PATH}/intersection/onestream" 3 3
 
+diag "No intersection between 2 streams"
+test_intersect_fails "${BT_CTF_TRACES_PATH}/intersection/nointersect" 6 \
+       "Trimming time range's beginning time is greater than end time: "
+
 diag "No stream at all"
-test_intersect "${BT_CTF_TRACES_PATH}/intersection/nostream" 0 0
+test_intersect_fails "${BT_CTF_TRACES_PATH}/intersection/nostream" 0 \
+       "Trace has no streams: "
+
+rm -f "${stdout}" "${stderr}"
This page took 0.026351 seconds and 4 git commands to generate.