]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-sd-device: limit the number of iterations when testing device parent/child functions
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Apr 2025 11:51:21 +0000 (13:51 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 17 May 2025 11:43:20 +0000 (12:43 +0100)
The test "hangs" and times out on some arm64 machines. It actually works as
expected, but the machine has 2016 children under /sys/devices/system/memory/,
and the tests do a double loop over this, which is slow enough to hit the 120 s
limit. Add a limit on the number of iterations.

Another option would be to exclude "memory" subsystem. But we may have other
subsystems which have the same problem in the future, so I think it'll be more
robust to not try to limit the fix to a specific subsystem.

(cherry picked from commit 74cb65e45fbf3468cf6b522e4b4fa568d95f12c6)
(cherry picked from commit e35435b0a11e6c61c8c43b0cf8dc65a563b4a670)

src/libsystemd/sd-device/test-sd-device.c

index 9fde1a08143f7f5042d2512c2191e316e05bb931..7576b4485fca6fde6cdec767e8f27339a15e4dd6 100644 (file)
@@ -452,6 +452,8 @@ static void check_parent_match(sd_device_enumerator *e, sd_device *dev) {
 
 TEST(sd_device_enumerator_add_match_parent) {
         _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
+        /* Some devices have thousands of children. Avoid spending too much time in the double loop below. */
+        unsigned iterations = 200;
         int r;
 
         assert_se(sd_device_enumerator_new(&e) >= 0);
@@ -469,6 +471,9 @@ TEST(sd_device_enumerator_add_match_parent) {
                 const char *syspath;
                 sd_device *parent;
 
+                if (iterations-- == 0)
+                        break;
+
                 assert_se(sd_device_get_syspath(dev, &syspath) >= 0);
 
                 r = sd_device_get_parent(dev, &parent);
@@ -497,6 +502,8 @@ TEST(sd_device_enumerator_add_match_parent) {
 
 TEST(sd_device_get_child) {
         _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
+        /* Some devices have thousands of children. Avoid spending too much time in the double loop below. */
+        unsigned iterations = 3000;
         int r;
 
         assert_se(sd_device_enumerator_new(&e) >= 0);
@@ -530,6 +537,9 @@ TEST(sd_device_get_child) {
                 FOREACH_DEVICE_CHILD_WITH_SUFFIX(parent, child, suffix) {
                         const char *s;
 
+                        if (iterations-- == 0)
+                                return;
+
                         assert_se(child);
                         assert_se(suffix);