summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-11-21 09:29:34 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-11-21 09:31:22 +0100
commit4ec739f19f705d1447f684c9e77e368a065e353c (patch)
treeeabd32f6c775a15d3ab95a83355794bbf9603075 /src
parentlibudev: make util_resolve_subsys_kernel() return negative errno (diff)
downloadsystemd-4ec739f19f705d1447f684c9e77e368a065e353c.tar.xz
systemd-4ec739f19f705d1447f684c9e77e368a065e353c.zip
test: add tests for util_resolve_subsys_kernel()
Diffstat (limited to 'src')
-rw-r--r--src/test/test-libudev.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c
index 258b77b430..c7cc453f7e 100644
--- a/src/test/test-libudev.c
+++ b/src/test/test-libudev.c
@@ -375,6 +375,35 @@ static void test_util_replace_whitespace(void) {
test_util_replace_whitespace_one_len(" hoge hoge ", 0, "");
}
+static void test_util_resolve_subsys_kernel_one(const char *str, bool read_value, int retval, const char *expected) {
+ char result[UTIL_PATH_SIZE];
+ int r;
+
+ r = util_resolve_subsys_kernel(str, result, sizeof(result), read_value);
+ assert_se(r == retval);
+ if (r >= 0)
+ assert_se(streq(result, expected));
+}
+
+static void test_util_resolve_subsys_kernel(void) {
+ test_util_resolve_subsys_kernel_one("hoge", false, -EINVAL, NULL);
+ test_util_resolve_subsys_kernel_one("[hoge", false, -EINVAL, NULL);
+ test_util_resolve_subsys_kernel_one("[hoge/foo", false, -EINVAL, NULL);
+ test_util_resolve_subsys_kernel_one("[hoge/]", false, -ENODEV, NULL);
+
+ test_util_resolve_subsys_kernel_one("[net/lo]", false, 0, "/sys/devices/virtual/net/lo");
+ test_util_resolve_subsys_kernel_one("[net/lo]/", false, 0, "/sys/devices/virtual/net/lo");
+ test_util_resolve_subsys_kernel_one("[net/lo]hoge", false, 0, "/sys/devices/virtual/net/lo/hoge");
+ test_util_resolve_subsys_kernel_one("[net/lo]/hoge", false, 0, "/sys/devices/virtual/net/lo/hoge");
+
+ test_util_resolve_subsys_kernel_one("[net/lo]", true, -EINVAL, NULL);
+ test_util_resolve_subsys_kernel_one("[net/lo]/", true, -EINVAL, NULL);
+ test_util_resolve_subsys_kernel_one("[net/lo]hoge", true, 0, "");
+ test_util_resolve_subsys_kernel_one("[net/lo]/hoge", true, 0, "");
+ test_util_resolve_subsys_kernel_one("[net/lo]address", true, 0, "00:00:00:00:00:00");
+ test_util_resolve_subsys_kernel_one("[net/lo]/address", true, 0, "00:00:00:00:00:00");
+}
+
int main(int argc, char *argv[]) {
_cleanup_(udev_unrefp) struct udev *udev = NULL;
bool arg_monitor = false;
@@ -455,6 +484,7 @@ int main(int argc, char *argv[]) {
test_monitor(udev);
test_util_replace_whitespace();
+ test_util_resolve_subsys_kernel();
return EXIT_SUCCESS;
}