]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add test for sd_device_open()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 30 Mar 2022 18:54:41 +0000 (03:54 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 1 Apr 2022 06:20:48 +0000 (15:20 +0900)
src/libsystemd/sd-device/test-sd-device.c

index 7276305e4f29956922884c4a89815ef73013cb24..8d7cb792d6835584d1128b5159c2f5eaaf5a197f 100644 (file)
@@ -1,10 +1,13 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include <fcntl.h>
+
 #include "device-enumerator-private.h"
 #include "device-internal.h"
 #include "device-private.h"
 #include "device-util.h"
 #include "errno-util.h"
+#include "fd-util.h"
 #include "hashmap.h"
 #include "nulstr-util.h"
 #include "path-util.h"
@@ -65,6 +68,10 @@ static void test_sd_device_one(sd_device *d) {
                         assert_se(sd_device_get_syspath(dev, &val) >= 0);
                         assert_se(streq(syspath, val));
                         dev = sd_device_unref(dev);
+
+                        _cleanup_close_ int fd = -1;
+                        fd = sd_device_open(d, O_CLOEXEC| O_NONBLOCK | (is_block ? O_RDONLY : O_NOCTTY | O_PATH));
+                        assert_se(fd >= 0 || ERRNO_IS_PRIVILEGE(fd));
                 } else
                         assert_se(r == -ENODEV || ERRNO_IS_PRIVILEGE(r));
         } else