]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-sd-device: dedeplicate common setup fragment
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Apr 2025 11:34:52 +0000 (13:34 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Apr 2025 11:59:27 +0000 (13:59 +0200)
src/libsystemd/sd-device/test-sd-device.c

index 86926ec48465ace0626ddacc458aeb813a8998ab..d08e5914a29cc18c4b206def3b4494c3b3929b7a 100644 (file)
@@ -221,11 +221,7 @@ static void test_sd_device_one(sd_device *d) {
         }
 }
 
-TEST(sd_device_enumerator_devices) {
-        _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
-
-        ASSERT_OK(sd_device_enumerator_new(&e));
-        ASSERT_OK(sd_device_enumerator_allow_uninitialized(e));
+static void exclude_problematic_devices(sd_device_enumerator *e) {
         /* On some CI environments, it seems some loop block devices and corresponding bdi devices sometimes
          * disappear during running this test. Let's exclude them here for stability. */
         ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "bdi", false));
@@ -233,6 +229,15 @@ TEST(sd_device_enumerator_devices) {
         /* On CentOS CI, systemd-networkd-tests.py may be running when this test is invoked. The networkd
          * test creates and removes many network interfaces, and may interfere with this test. */
         ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "net", false));
+}
+
+TEST(sd_device_enumerator_devices) {
+        _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
+
+        ASSERT_OK(sd_device_enumerator_new(&e));
+        ASSERT_OK(sd_device_enumerator_allow_uninitialized(e));
+        exclude_problematic_devices(e);
+
         FOREACH_DEVICE(e, d)
                 test_sd_device_one(d);
 }
@@ -300,10 +305,7 @@ static bool test_sd_device_enumerator_filter_subsystem_trial(void) {
 
         ASSERT_NOT_NULL((subsystems = hashmap_new(&string_hash_ops)));
         ASSERT_OK(sd_device_enumerator_new(&e));
-        /* See comments in TEST(sd_device_enumerator_devices). */
-        ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "bdi", false));
-        ASSERT_OK(sd_device_enumerator_add_nomatch_sysname(e, "loop*"));
-        ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "net", false));
+        exclude_problematic_devices(e);
 
         FOREACH_DEVICE(e, d) {
                 const char *syspath, *subsystem;
@@ -482,10 +484,7 @@ TEST(sd_device_enumerator_add_match_parent) {
 
         ASSERT_OK(sd_device_enumerator_new(&e));
         ASSERT_OK(sd_device_enumerator_allow_uninitialized(e));
-        /* See comments in TEST(sd_device_enumerator_devices). */
-        ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "bdi", false));
-        ASSERT_OK(sd_device_enumerator_add_nomatch_sysname(e, "loop*"));
-        ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "net", false));
+        exclude_problematic_devices(e);
 
         if (!slow_tests_enabled())
                 ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "block", true));
@@ -564,10 +563,7 @@ TEST(sd_device_get_child) {
 
         ASSERT_OK(sd_device_enumerator_new(&e));
         ASSERT_OK(sd_device_enumerator_allow_uninitialized(e));
-        /* See comments in TEST(sd_device_enumerator_devices). */
-        ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "bdi", false));
-        ASSERT_OK(sd_device_enumerator_add_nomatch_sysname(e, "loop*"));
-        ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "net", false));
+        exclude_problematic_devices(e);
 
         if (!slow_tests_enabled())
                 ASSERT_OK(sd_device_enumerator_add_match_subsystem(e, "block", true));