From 93e04eb43bed6cd1cea344f8fb1002b62155fae2 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 23 Mar 2022 14:51:22 +0900 Subject: [PATCH] test: add tests for device id --- src/libsystemd/sd-device/test-sd-device.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libsystemd/sd-device/test-sd-device.c b/src/libsystemd/sd-device/test-sd-device.c index 2d2157ba70a..8a534ca8ef2 100644 --- a/src/libsystemd/sd-device/test-sd-device.c +++ b/src/libsystemd/sd-device/test-sd-device.c @@ -12,7 +12,8 @@ #include "time-util.h" static void test_sd_device_one(sd_device *d) { - const char *syspath, *subsystem, *val; + _cleanup_(sd_device_unrefp) sd_device *device_from_id = NULL; + const char *syspath, *subsystem, *id, *val; dev_t devnum; usec_t usec; int i, r; @@ -57,7 +58,17 @@ static void test_sd_device_one(sd_device *d) { r = sd_device_get_property_value(d, "ID_NET_DRIVER", &val); assert_se(r >= 0 || r == -ENOENT); - log_info("syspath:%s subsystem:%s initialized:%s", syspath, strna(subsystem), yes_no(i)); + r = device_get_device_id(d, &id); + assert_se(r >= 0); + + r = sd_device_new_from_device_id(&device_from_id, id); + assert_se(r >= 0); + + r = sd_device_get_syspath(device_from_id, &val); + assert_se(r >= 0); + assert_se(streq(syspath, val)); + + log_info("syspath:%s subsystem:%s id:%s initialized:%s", syspath, strna(subsystem), id, yes_no(i)); } TEST(sd_device_enumerator_devices) { -- 2.47.3