summaryrefslogtreecommitdiffstats
path: root/src/udev/test-udev-format.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/udev/test-udev-format.c
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/udev/test-udev-format.c')
-rw-r--r--src/udev/test-udev-format.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/udev/test-udev-format.c b/src/udev/test-udev-format.c
new file mode 100644
index 0000000..d8e3808
--- /dev/null
+++ b/src/udev/test-udev-format.c
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "string-util.h"
+#include "tests.h"
+#include "udev-format.h"
+
+static void test_udev_resolve_subsys_kernel_one(const char *str, bool read_value, int retval, const char *expected) {
+ char result[PATH_MAX] = "";
+ int r;
+
+ r = udev_resolve_subsys_kernel(str, result, sizeof(result), read_value);
+ log_info("\"%s\" → expect: \"%s\", %d, actual: \"%s\", %d", str, strnull(expected), retval, result, r);
+ assert_se(r == retval);
+ if (r >= 0)
+ assert_se(streq(result, expected));
+}
+
+TEST(udev_resolve_subsys_kernel) {
+ test_udev_resolve_subsys_kernel_one("hoge", false, -EINVAL, NULL);
+ test_udev_resolve_subsys_kernel_one("[hoge", false, -EINVAL, NULL);
+ test_udev_resolve_subsys_kernel_one("[hoge/foo", false, -EINVAL, NULL);
+ test_udev_resolve_subsys_kernel_one("[hoge/]", false, -EINVAL, NULL);
+
+ test_udev_resolve_subsys_kernel_one("[net/lo]", false, 0, "/sys/devices/virtual/net/lo");
+ test_udev_resolve_subsys_kernel_one("[net/lo]/", false, 0, "/sys/devices/virtual/net/lo");
+ test_udev_resolve_subsys_kernel_one("[net/lo]hoge", false, 0, "/sys/devices/virtual/net/lo/hoge");
+ test_udev_resolve_subsys_kernel_one("[net/lo]/hoge", false, 0, "/sys/devices/virtual/net/lo/hoge");
+
+ test_udev_resolve_subsys_kernel_one("[net/lo]", true, -EINVAL, NULL);
+ test_udev_resolve_subsys_kernel_one("[net/lo]/", true, -EINVAL, NULL);
+ test_udev_resolve_subsys_kernel_one("[net/lo]hoge", true, 0, "");
+ test_udev_resolve_subsys_kernel_one("[net/lo]/hoge", true, 0, "");
+ test_udev_resolve_subsys_kernel_one("[net/lo]address", true, 0, "00:00:00:00:00:00");
+ test_udev_resolve_subsys_kernel_one("[net/lo]/address", true, 0, "00:00:00:00:00:00");
+}
+
+DEFINE_TEST_MAIN(LOG_DEBUG);