From c855b1ea85d664c6cbbb8d4d8d246a3afe7dab8a Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 19 Sep 2019 15:45:53 -0400 Subject: [PATCH] tests: make test_intersection use bt_cli, test error cases 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2068 Reviewed-by: Francis Deslauriers Tested-by: jenkins --- src/plugins/ctf/fs-src/query.c | 9 +++++-- tests/cli/test_intersection | 48 +++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/plugins/ctf/fs-src/query.c b/src/plugins/ctf/fs-src/query.c index 3deb0cb1..33d9169c 100644 --- a/src/plugins/ctf/fs-src/query.c +++ b/src/plugins/ctf/fs-src/query.c @@ -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; } diff --git a/tests/cli/test_intersection b/tests/cli/test_intersection index 1f8d20cf..f5be6b70 100755 --- a/tests/cli/test_intersection +++ b/tests/cli/test_intersection @@ -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}" -- 2.34.1