Tests: Make notifier discard count test more robust
authorroot <root@ideal-dove>
Wed, 28 Aug 2024 18:52:09 +0000 (18:52 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 3 Sep 2024 19:28:17 +0000 (19:28 +0000)
Observed issue
==============

In the CI, this test would intermittently fail. During failures,
the calculated pipe size from the `default_pipe_size_getter`
application was 8192, while in other cases it was 65536.

```
ERROR: tools/notification/test_notification_notifier_discarded_count
====================================================================

1..41
ok 1 - Add trigger my_trigger
PASS: tools/notification/test_notification_notifier_discarded_count 1 - Add trigger my_trigger
  ---
    duration_ms: 1323.966137
  ...
ok 2 - No discarded tracer notification
PASS: tools/notification/test_notification_notifier_discarded_count 2 - No discarded tracer notification
  ---
    duration_ms: 22.021590
  ...
ok 3 - Generating 390 tracer notifications
PASS: tools/notification/test_notification_notifier_discarded_count 3 - Generating 390 tracer notifications
  ---
    duration_ms: 154.790871
  ...
not ok 4 - Discarded tracer notification number non-zero (0) as expected
FAIL: tools/notification/test_notification_notifier_discarded_count 4 - Discarded tracer notification number non-zero (0) as expected
  ---
    duration_ms: 24.323759
  ...
```

Cause
=====

The initial size of pipes in linux may have different values:

1) `16 * PAGE_SIZE` (as documented in `man 7 pipe`) (since Linux 2.6.11)
2) When a user has many pipes open and is above a soft limit:

  * `2 * PAGE_SIZE` (undocumented, see[1]), as of Linux 5.14[2]
  * `1 * PAGE_SIZE` since linux 2.6.35[3]

As the program `default_pipe_size_getter` opened a pipe to check it's
size, there could be times in a system where a user has many pipe
buffers open beyond the soft limit and the lower value would be
returned; however, the previously opened sessiond may have had a pipe
opened with the larger default pipe size.

Solution
========

Use the maximum page size (on Linux, from
`/proc/sys/fs/pipe-max-size`) for the estimated pipe size rather than
opening a pipe and checking it's size.

Known drawbacks
===============

When the maximum pipe size value is much larger than the actual size
of the notification pipe, many more events are emitted than is
necessary to complete the test.

References
==========

[1]: https://gitlab.com/linux-kernel/stable/-/blob/3e9bff3bbe1355805de919f688bef4baefbfd436/fs/pipe.c#L809
[2]: See upstream commit 46c4c9d1beb7f5b4cec4dd90e7728720583ee348
[3]: See upstream commit 6a6ca57de92fcae34603551ac944aa74758c30d4

Change-Id: Id547a1d772b5a7f9b18ffa686ff6644afca4ab15
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/regression/tools/notification/test_notification_notifier_discarded_count
tests/utils/utils.sh

index 25ef370fad0641bafee60a64b56fd3f33c627253..8d8841faac72d8f7d75790efca52a6d68136d156 100755 (executable)
@@ -155,12 +155,7 @@ function test_ust_notifier_discarded_count
 
        diag "UST event notifer error counter"
 
-       PIPE_SIZE=$("$CURDIR"/default_pipe_size_getter)
-       if [ $? -ne 0 ]; then
-               BAIL_OUT "Failed to get system default pipe size"
-       else
-               diag "Default system pipe size: $PIPE_SIZE bytes"
-       fi
+       PIPE_SIZE=$(get_pipe_max_size)
 
        # Find the number of events needed to overflow the event notification
        # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
@@ -259,12 +254,7 @@ function test_ust_notifier_discarded_count_multi_uid
        useradd --no-create-home "$new_user"
        new_uid=$(id -u "$new_user")
 
-       PIPE_SIZE=$("$CURDIR"/default_pipe_size_getter)
-       if [ $? -ne 0 ]; then
-               BAIL_OUT "Failed to get system default pipe size"
-       else
-               diag "Default system pipe size: $PIPE_SIZE bytes"
-       fi
+       PIPE_SIZE=$(get_pipe_max_size)
 
        # Find the number of events needed to overflow the event notification
        # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
@@ -333,12 +323,7 @@ function test_ust_notifier_discarded_regardless_trigger_owner
        local NR_ITER
        local new_user="dummy_lttng_test_user"
 
-       PIPE_SIZE=$("$CURDIR"/default_pipe_size_getter)
-       if [ $? -ne 0 ]; then
-               BAIL_OUT "Failed to get system default pipe size"
-       else
-               diag "Default system pipe size: $PIPE_SIZE bytes"
-       fi
+       PIPE_SIZE=$(get_pipe_max_size)
 
        # Find the number of events needed to overflow the event notification
        # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
index fcca7ac4fb28978d9347bdbe00d55d9cfb2ad46c..83c0bb4a2b2cc1b4b106aeba723e2077439cc0d7 100644 (file)
@@ -214,6 +214,17 @@ function randstring()
        echo
 }
 
+function get_pipe_max_size()
+{
+       if grep -q 'FreeBSD' /etc/os-release ; then
+               # Kernel configuration dependant, but defaults to 64 * 1024
+               # https://github.com/freebsd/freebsd-src/blob/5b0dc991093c82824f6fe566af947f64f5072264/sys/sys/pipe.h#L33
+               echo 65536
+       else
+               cat /proc/sys/fs/pipe-max-size
+       fi
+}
+
 # Return a space-separated string of online CPU IDs, based on
 # /sys/devices/system/cpu/online, or from 0 to nproc - 1 otherwise.
 function get_online_cpus()
This page took 0.028835 seconds and 4 git commands to generate.