]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add test cases for device_get_sysattr_int() and friends
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 12 Mar 2026 00:19:34 +0000 (09:19 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 17 May 2026 17:55:56 +0000 (02:55 +0900)
src/libsystemd/sd-device/test-sd-device.c

index 9201919898a025065f2774c68a93210da09dcfef..13fb9fd25d24e984ae841de22dc1cb52f5ebf794 100644 (file)
@@ -312,6 +312,24 @@ static void test_sd_device_one(sd_device *d) {
                 ASSERT_OK(device_get_sysattr_safe_string(d, "uevent", &uevent_safe));
                 ASSERT_STREQ(uevent, uevent_safe);
         }
+
+        if (sd_device_get_ifindex(d, &ifindex) >= 0) {
+                int i;
+                ASSERT_OK_POSITIVE(device_get_sysattr_int(d, "ifindex", &i));
+                ASSERT_EQ(i, ifindex);
+
+                unsigned u;
+                ASSERT_OK_POSITIVE(device_get_sysattr_unsigned(d, "ifindex", &u));
+                ASSERT_EQ(u, (unsigned) ifindex);
+
+                uint64_t u64;
+                ASSERT_OK_POSITIVE(device_get_sysattr_u64(d, "ifindex", &u64));
+                ASSERT_EQ(u64, (uint64_t) ifindex);
+
+                uint32_t u32;
+                ASSERT_OK_POSITIVE(device_get_sysattr_u32(d, "ifindex", &u32));
+                ASSERT_EQ(u32, (uint32_t) ifindex);
+        }
 }
 
 static void exclude_problematic_devices(sd_device_enumerator *e) {