From dbfe8b162b366d48cae5a13dab11e496843d7035 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 12 Mar 2026 09:19:34 +0900 Subject: [PATCH] test: add test cases for device_get_sysattr_int() and friends --- src/libsystemd/sd-device/test-sd-device.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libsystemd/sd-device/test-sd-device.c b/src/libsystemd/sd-device/test-sd-device.c index 9201919898..13fb9fd25d 100644 --- a/src/libsystemd/sd-device/test-sd-device.c +++ b/src/libsystemd/sd-device/test-sd-device.c @@ -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) {