diff --git a/src/libsystemd/sd-device/test-sd-device.c b/src/libsystemd/sd-device/test-sd-device.c index d08e5914a2..85c3beb04f 100644 --- a/src/libsystemd/sd-device/test-sd-device.c +++ b/src/libsystemd/sd-device/test-sd-device.c @@ -480,12 +480,16 @@ 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_OK(sd_device_enumerator_new(&e)); ASSERT_OK(sd_device_enumerator_allow_uninitialized(e)); exclude_problematic_devices(e); + ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "memory", false)); + if (!slow_tests_enabled()) ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "block", true)); @@ -494,6 +498,9 @@ TEST(sd_device_enumerator_add_match_parent) { const char *syspath; sd_device *parent; + if (iterations-- == 0) + break; + ASSERT_OK(sd_device_get_syspath(dev, &syspath)); r = sd_device_get_parent(dev, &parent); @@ -559,6 +566,8 @@ TEST(sd_device_enumerator_add_all_parents) { 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_OK(sd_device_enumerator_new(&e)); @@ -589,6 +598,9 @@ TEST(sd_device_get_child) { FOREACH_DEVICE_CHILD_WITH_SUFFIX(parent, child, suffix) { const char *s; + if (iterations-- == 0) + return; + ASSERT_NOT_NULL(child); ASSERT_NOT_NULL(suffix);