tests: factor out discarded packet regex in test-packet-seq-num.sh
authorSimon Marchi <simon.marchi@efficios.com>
Sat, 5 Oct 2024 01:08:40 +0000 (21:08 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 9 Oct 2024 02:56:57 +0000 (22:56 -0400)
The regex used in `test_no_lost()` is outdated, which means that if
Babeltrace were to emit an unexpected discarded packets message, the
test would not catch it.  Fix it by factoring the regex used to look for
discarded packets messages.  At least now, we can have the confidence
that we're looking for the right thing, otherwise the `test_lost()`
tests wouldn't pass.

In general, it's fragile to check for the absence of something, since a
typo or change in what to look can easily make the test uneffective.  I
initially re-wrote this test in Python (the test is in the `cli`
directory, but its intent is more to validate the source's behavior than
to validate the CLI's behavior), but this simple change seems good
enough for now.

Change-Id: I9f8c30a567fa6f5036cadcc4691c3bd6f953ca3d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13309
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
tests/cli/test-packet-seq-num.sh

index 47d0c3d7b8b2bd6603266a051f6c19a53aa5712e..704746bdee38b0c3cc551fa7975fc6fb1c9ec721 100755 (executable)
@@ -20,13 +20,15 @@ NUM_TESTS=10
 
 plan_tests $NUM_TESTS
 
+discarded_re="WARNING: Tracer discarded"
+
 test_no_lost() {
        local trace=$1
 
        bt_cli "/dev/null" "/dev/null" "$trace"
        ok $? "Trace parses"
 
-       bt_cli /dev/null /dev/fd/3 "$trace" 3>&1 | bt_grep "\[warning\] Tracer lost"
+       bt_cli /dev/null /dev/fd/3 "$trace" 3>&1 | bt_grep "$discarded_re"
        isnt $? 0 "No events lost"
 }
 
@@ -41,7 +43,7 @@ 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_cli /dev/null /dev/fd/3 "$trace" 3>&1 | bt_grep "WARNING: Tracer discarded" \
+       bt_cli /dev/null /dev/fd/3 "$trace" 3>&1 | bt_grep "$discarded_re" \
                | cut -d" " -f4 | tr "\n" "," | "${BT_TESTS_SED_BIN}" "s/.$//" | \
                bt_grep "$expectedcountstr" >/dev/null
        ok $? "Lost events string matches $expectedcountstr"
This page took 0.026438 seconds and 4 git commands to generate.