tests: add and use bt_grep
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 6 Nov 2023 18:36:59 +0000 (18:36 +0000)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 9 Nov 2023 16:14:34 +0000 (11:14 -0500)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11248
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Michael Jeanson <mjeanson@efficios.com>

13 files changed:
tests/cli/convert/test-auto-source-discovery-grouping.sh
tests/cli/convert/test-convert-args.sh
tests/cli/list-plugins/test-list-plugins.sh
tests/cli/query/test-query.sh
tests/cli/test-help.sh
tests/cli/test-intersection.sh
tests/cli/test-packet-seq-num.sh
tests/cli/test-trace-copy.sh
tests/plugins/src.ctf.fs/fail/test-fail.sh
tests/plugins/src.ctf.fs/query/test-query-metadata-info.sh
tests/plugins/src.ctf.fs/succeed/test-succeed.sh
tests/plugins/src.ctf.fs/test-deterministic-ordering.sh
tests/utils/utils.sh

index e476c96cb435a6448575c444c9b28d37c48df25b..0e2666c2431935cfb9563e062a8e409f769472df 100755 (executable)
@@ -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"
index eee251dee7d518e24693750bbcec16bba010262e..ac4c2b523c75c41ca57a999c8167cd2363d1b5de 100755 (executable)
@@ -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
index a0720ace2a439926bf6e2c51ed797d849b7a2f5c..c6e7166cdbad7fd443acca2ed2ecc2b31a2723ce 100755 (executable)
@@ -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
index 170749ab2bbf52dc42f962a238bed759c16d9da7..b5e023749820aadd0272a5d5aae4da9304f5d67c 100755 (executable)
@@ -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"
 }
 
index dabd0c2b56689b642ac43213f91fb1b8472d0bbf..a950adc633672bff5f85bd0adb4c9ba405856244 100755 (executable)
@@ -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}"
index 32a63d584919af77b8c14bf10e8c4d6bb3d8f915..4ed9c107291447c86d734002a637949f73087c61 100755 (executable)
@@ -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"
 }
 
index 89a830e57cf298b992cb6475123cbe7293279e42..8c8380587aa4c961d6366d4a377079172f1ef019 100755 (executable)
@@ -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"
 
 }
index e8c9b2c86210a391089953e89733a240ed341d34..a3fb4544bad0f56e2ca21e99db297dc66ba7e336 100755 (executable)
@@ -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)"
index ee9e954191b9d9afa360d212ad46427bb9272f25..c15e067ecfab219bd79ac37e73195b4b3773244f 100755 (executable)
@@ -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"
 }
 
index 5915e29d2812504f6c1f9d24322912b49c77e63d..1a0d27cb02b5b7233f620ed020cd394f732f7a5a 100755 (executable)
@@ -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"
 
index 655963590e00aa156e9941aeee0b0b76e2a50bee..5a00601ca1e48b8c243f616c2bdcc5c5cbbe3ddf 100755 (executable)
@@ -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=$?
index a641eb53812e5a42134b191a832b4d248deddf9a..6d2eb3a98023cb6120ac2c775d7721259783623b 100755 (executable)
@@ -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"
 }
 
index e2b730923685828301a158ecbba35a19e3fc1402..24f1b2d26b6c9af59655bf303c4f5e324935d476 100644 (file)
@@ -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
This page took 0.032326 seconds and 4 git commands to generate.