From 407d3b1055a8457c8927fb4ae79841774c1872d1 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 6 Nov 2023 18:36:59 +0000 Subject: [PATCH] tests: add and use bt_grep Add the `bt_grep` function, which passes all its arguments to the grep binary specified by BT_TESTS_GREP_BIN. Use everywhere where applicable in the testsuite. Change-Id: Ia166106fd85312e681fa2692e1f5409c9556f897 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/11248 Tested-by: jenkins Reviewed-by: Michael Jeanson Reviewed-by: Philippe Proulx CI-Build: Michael Jeanson --- .../test-auto-source-discovery-grouping.sh | 2 +- tests/cli/convert/test-convert-args.sh | 2 +- tests/cli/list-plugins/test-list-plugins.sh | 2 +- tests/cli/query/test-query.sh | 4 ++-- tests/cli/test-help.sh | 16 ++++++++-------- tests/cli/test-intersection.sh | 2 +- tests/cli/test-packet-seq-num.sh | 6 +++--- tests/cli/test-trace-copy.sh | 2 +- tests/plugins/src.ctf.fs/fail/test-fail.sh | 4 ++-- .../src.ctf.fs/query/test-query-metadata-info.sh | 4 ++-- tests/plugins/src.ctf.fs/succeed/test-succeed.sh | 2 +- .../src.ctf.fs/test-deterministic-ordering.sh | 4 ++-- tests/utils/utils.sh | 6 +++++- 13 files changed, 30 insertions(+), 26 deletions(-) diff --git a/tests/cli/convert/test-auto-source-discovery-grouping.sh b/tests/cli/convert/test-auto-source-discovery-grouping.sh index e476c96c..0e2666c2 100755 --- a/tests/cli/convert/test-auto-source-discovery-grouping.sh +++ b/tests/cli/convert/test-auto-source-discovery-grouping.sh @@ -39,7 +39,7 @@ ok "$?" "expected components are instantiated with expected inputs" # Check that expected warning is printed. # shellcheck disable=SC2016 -grep -q 'No trace was found based on input `some_other_non_opt`' "$stderr_actual_file" +bt_grep -q 'No trace was found based on input `some_other_non_opt`' "$stderr_actual_file" ok "$?" "warning is printed" rm -f "$stdout_actual_file" diff --git a/tests/cli/convert/test-convert-args.sh b/tests/cli/convert/test-convert-args.sh index eee251de..ac4c2b52 100755 --- a/tests/cli/convert/test-convert-args.sh +++ b/tests/cli/convert/test-convert-args.sh @@ -57,7 +57,7 @@ test_bt_convert_fails() { ok $? "$what: nothing is printed on stdout" # Check for expected error string in stderr. - grep --quiet --fixed-strings -e "$expected_error_str" "$tmp_stderr" + bt_grep --quiet --fixed-strings -e "$expected_error_str" "$tmp_stderr" local status=$? ok "$status" "$what: expected error message" if [ "$status" -ne 0 ]; then diff --git a/tests/cli/list-plugins/test-list-plugins.sh b/tests/cli/list-plugins/test-list-plugins.sh index a0720ace..c6e7166c 100755 --- a/tests/cli/list-plugins/test-list-plugins.sh +++ b/tests/cli/list-plugins/test-list-plugins.sh @@ -31,7 +31,7 @@ bt_cli "$stdout_file" "$stderr_file" \ ok "$?" "exit code is 0" # Extract the section about our custom this-is-a-plugin Python plugin. -grep --after-context=11 '^this-is-a-plugin:$' "${stdout_file}" > "${grep_stdout_file}" +bt_grep --after-context=11 '^this-is-a-plugin:$' "${stdout_file}" > "${grep_stdout_file}" ok "$?" "entry for this-is-a-plugin is present" if [ "$BT_TESTS_OS_TYPE" = "mingw" ]; then diff --git a/tests/cli/query/test-query.sh b/tests/cli/query/test-query.sh index 170749ab..b5e02374 100755 --- a/tests/cli/query/test-query.sh +++ b/tests/cli/query/test-query.sh @@ -58,10 +58,10 @@ expect_failure() { # Ensure that a CLI error stack is printed (and that babeltrace doesn't # abort before that). - grep --silent "^ERROR: " "${stderr_file}" + bt_grep --silent "^ERROR: " "${stderr_file}" ok $? "${test_name}: babeltrace produces an error stack" - grep --silent "${expected_str}" "${stderr_file}" + bt_grep --silent "${expected_str}" "${stderr_file}" ok "$?" "${test_name}: expect \`${expected_str}\` error message on stderr" } diff --git a/tests/cli/test-help.sh b/tests/cli/test-help.sh index dabd0c2b..a950adc6 100755 --- a/tests/cli/test-help.sh +++ b/tests/cli/test-help.sh @@ -32,7 +32,7 @@ is_empty() bt_cli "${stdout}" "${stderr}" help ctf ok $? "help ctf plugin exit status" -grep --silent 'Description: CTF input and output' "${stdout}" +bt_grep --silent 'Description: CTF input and output' "${stdout}" ok $? "help ctf plugin expected output" is_empty "${stderr}" @@ -42,7 +42,7 @@ ok $? "help ctf plugin produces no error" bt_cli "${stdout}" "${stderr}" help src.ctf.fs ok $? "help src.ctf.fs component class exit status" -grep --silent 'Description: Read CTF traces from the file system.' "${stdout}" +bt_grep --silent 'Description: Read CTF traces from the file system.' "${stdout}" ok $? "help src.ctf.fs component class expected output" is_empty "${stderr}" @@ -52,7 +52,7 @@ ok $? "help src.ctf.fs component class produces no error" bt_cli "${stdout}" "${stderr}" help isnt $? 0 "help without parameter exit status" -grep --silent "Missing plugin name or component class descriptor." "${stderr}" +bt_grep --silent "Missing plugin name or component class descriptor." "${stderr}" ok $? "help without parameter produces expected error" is_empty "${stdout}" @@ -62,7 +62,7 @@ ok $? "help without parameter produces no output" bt_cli "${stdout}" "${stderr}" help ctf fs isnt $? 0 "help with too many parameters exit status" -grep --silent "Extraneous command-line argument specified to \`help\` command:" "${stderr}" +bt_grep --silent "Extraneous command-line argument specified to \`help\` command:" "${stderr}" ok $? "help with too many parameters produces expected error" is_empty "${stdout}" @@ -72,7 +72,7 @@ ok $? "help with too many parameters produces no output" bt_cli "${stdout}" "${stderr}" help zigotos isnt $? 0 "help with unknown plugin name" -grep --silent 'Cannot find plugin: plugin-name="zigotos"' "${stderr}" +bt_grep --silent 'Cannot find plugin: plugin-name="zigotos"' "${stderr}" ok $? "help with unknown plugin name produces expected error" is_empty "${stdout}" @@ -82,17 +82,17 @@ ok $? "help with unknown plugin name produces no output" bt_cli "${stdout}" "${stderr}" help src.ctf.bob isnt $? 0 "help with unknown component class name" -grep --silent 'Cannot find component class: plugin-name="ctf", comp-cls-name="bob", comp-cls-type=SOURCE' "${stderr}" +bt_grep --silent 'Cannot find component class: plugin-name="ctf", comp-cls-name="bob", comp-cls-type=SOURCE' "${stderr}" ok $? "help with unknown component class name produces expected error" -grep --silent 'Description: CTF input and output' "${stdout}" +bt_grep --silent 'Description: CTF input and output' "${stdout}" ok $? "help with unknown component class name prints plugin help" # Test with unknown component class plugin bt_cli "${stdout}" "${stderr}" help src.bob.fs isnt $? 0 "help with unknown component class plugin" -grep --silent 'Cannot find plugin: plugin-name="bob"' "${stderr}" +bt_grep --silent 'Cannot find plugin: plugin-name="bob"' "${stderr}" ok $? "help with unknown component class plugin produces expected error" is_empty "${stdout}" diff --git a/tests/cli/test-intersection.sh b/tests/cli/test-intersection.sh index 32a63d58..4ed9c107 100755 --- a/tests/cli/test-intersection.sh +++ b/tests/cli/test-intersection.sh @@ -58,7 +58,7 @@ test_intersect_fails() { bt_cli "${stdout}" "${stderr}" --stream-intersection "${trace}" isnt "$?" 0 "run with --stream-intersection fails" - grep --silent "${expected_error_message}" "${stderr}" + bt_grep --silent "${expected_error_message}" "${stderr}" ok $? "stderr contains expected error message" } diff --git a/tests/cli/test-packet-seq-num.sh b/tests/cli/test-packet-seq-num.sh index 89a830e5..8c838058 100755 --- a/tests/cli/test-packet-seq-num.sh +++ b/tests/cli/test-packet-seq-num.sh @@ -25,7 +25,7 @@ test_no_lost() { "${BT_TESTS_BT2_BIN}" "$trace" >/dev/null 2>&1 ok $? "Trace parses" - "${BT_TESTS_BT2_BIN}" "$trace" 2>&1 >/dev/null | "${BT_TESTS_GREP_BIN}" "\[warning\] Tracer lost" + "${BT_TESTS_BT2_BIN}" "$trace" 2>&1 >/dev/null | bt_grep "\[warning\] Tracer lost" if test $? = 0; then fail 1 "Should not find any lost events" else @@ -44,9 +44,9 @@ test_lost() { # WARNING: Tracer discarded 2 trace packets between .... # WARNING: Tracer discarded 3 trace packets between .... # into "2,3" and make sure it matches the expected result - "${BT_TESTS_BT2_BIN}" "$trace" 2>&1 >/dev/null | "${BT_TESTS_GREP_BIN}" "WARNING: Tracer discarded" \ + "${BT_TESTS_BT2_BIN}" "$trace" 2>&1 >/dev/null | bt_grep "WARNING: Tracer discarded" \ | cut -d" " -f4 | tr "\n" "," | "${BT_TESTS_SED_BIN}" "s/.$//" | \ - "${BT_TESTS_GREP_BIN}" "$expectedcountstr" >/dev/null + bt_grep "$expectedcountstr" >/dev/null ok $? "Lost events string matches $expectedcountstr" } diff --git a/tests/cli/test-trace-copy.sh b/tests/cli/test-trace-copy.sh index e8c9b2c8..a3fb4544 100755 --- a/tests/cli/test-trace-copy.sh +++ b/tests/cli/test-trace-copy.sh @@ -48,7 +48,7 @@ for path in "${SUCCESS_TRACES[@]}"; do # duplicate timestamps in the output. # If there are, we have to sort the text output to make sure it is # always the same. - head -1 "${text_output1}" | "${BT_TESTS_GREP_BIN}" "^\[" >/dev/null + head -1 "${text_output1}" | bt_grep "^\[" >/dev/null if test $? = 0; then # shellcheck disable=SC2016 uniq_ts_cnt="$("${BT_TESTS_AWK_BIN}" '{ print $1 }' < "${text_output1}" | sort | uniq | wc -l)" diff --git a/tests/plugins/src.ctf.fs/fail/test-fail.sh b/tests/plugins/src.ctf.fs/fail/test-fail.sh index ee9e9541..c15e067e 100755 --- a/tests/plugins/src.ctf.fs/fail/test-fail.sh +++ b/tests/plugins/src.ctf.fs/fail/test-fail.sh @@ -41,10 +41,10 @@ test_fail() { # even if Babeltrace aborts (e.g. hits an assert). Check that the # Babeltrace CLI finishes gracefully by checking that the error stream # contains an error stack printed by the CLI. - grep --silent "^CAUSED BY " "${stderr_file}" + bt_grep --silent "^CAUSED BY " "${stderr_file}" ok $? "Trace ${name}: babeltrace produces an error stack" - grep --silent "${expected_error_msg}" "${stderr_file}" + bt_grep --silent "${expected_error_msg}" "${stderr_file}" ok $? "Trace ${name}: babeltrace produces the expected error message" } diff --git a/tests/plugins/src.ctf.fs/query/test-query-metadata-info.sh b/tests/plugins/src.ctf.fs/query/test-query-metadata-info.sh index 5915e29d..1a0d27cb 100755 --- a/tests/plugins/src.ctf.fs/query/test-query-metadata-info.sh +++ b/tests/plugins/src.ctf.fs/query/test-query-metadata-info.sh @@ -68,10 +68,10 @@ test_non_existent_trace_dir() { bt_diff "/dev/null" "${stdout_file}" ok $? "non existent trace dir: babeltrace produces the expected stdout" - grep --silent "^CAUSED BY " "${stderr_file}" + bt_grep --silent "^CAUSED BY " "${stderr_file}" ok $? "non existent trace dir: babeltrace produces an error stack" - grep --silent "Failed to open metadata file: No such file or directory: path=\".*metadata\"" \ + bt_grep --silent "Failed to open metadata file: No such file or directory: path=\".*metadata\"" \ "${stderr_file}" ok $? "non existent trace dir: babeltrace produces the expected error message" diff --git a/tests/plugins/src.ctf.fs/succeed/test-succeed.sh b/tests/plugins/src.ctf.fs/succeed/test-succeed.sh index 65596359..5a00601c 100755 --- a/tests/plugins/src.ctf.fs/succeed/test-succeed.sh +++ b/tests/plugins/src.ctf.fs/succeed/test-succeed.sh @@ -67,7 +67,7 @@ test_packet_end() { "$succeed_trace_dir/$name" "${details_comp[@]}" \ "${details_args[@]}" - "$BT_TESTS_GREP_BIN" "Packet end" "$temp_stdout_output_file" > "$temp_greped_stdout_output_file" + bt_grep "Packet end" "$temp_stdout_output_file" > "$temp_greped_stdout_output_file" bt_diff "$expected_stdout" "$temp_greped_stdout_output_file" ret_stdout=$? diff --git a/tests/plugins/src.ctf.fs/test-deterministic-ordering.sh b/tests/plugins/src.ctf.fs/test-deterministic-ordering.sh index a641eb53..6d2eb3a9 100755 --- a/tests/plugins/src.ctf.fs/test-deterministic-ordering.sh +++ b/tests/plugins/src.ctf.fs/test-deterministic-ordering.sh @@ -66,10 +66,10 @@ expect_failure() { -c src.ctf.fs -p "inputs=[${inputs}]" isnt 0 "$?" "${test_name}: exit status is not 0" - grep --silent "^ERROR: " "${stderr_file}" + bt_grep --silent "^ERROR: " "${stderr_file}" ok "$?" "${test_name}: error stack is produced" - grep --silent "No event class with ID of event class ID to use in stream class" "${stderr_file}" + bt_grep --silent "No event class with ID of event class ID to use in stream class" "${stderr_file}" ok "$?" "${test_name}: expected error message is present" } diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index e2b73092..24f1b2d2 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -297,6 +297,10 @@ bt_diff_details_ctf_gen_single() { return $ret } +# Run the grep binary configured for the tests. +bt_grep() { + "$BT_TESTS_GREP_BIN" "$@" +} ### Functions ### @@ -358,7 +362,7 @@ run_python_bt2() { # existing ASAN_OPTIONS, such that we override the user's value if it # contains detect_leaks=1. if [ "${BT_TESTS_ENABLE_ASAN:-}" = "1" ]; then - if ${BT_TESTS_CC_BIN} --version | head -n 1 | grep -q '^gcc'; then + if ${BT_TESTS_CC_BIN} --version | head -n 1 | bt_grep -q '^gcc'; then lib_asan="$(${BT_TESTS_CC_BIN} -print-file-name=libasan.so)" local -x LD_PRELOAD="${lib_asan}${LD_PRELOAD:+:}${LD_PRELOAD:-}" fi -- 2.34.1