summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/meson.build18
-rw-r--r--src/test/test-libudev.c89
-rw-r--r--src/test/test-udev-util.c89
3 files changed, 98 insertions, 98 deletions
diff --git a/src/test/meson.build b/src/test/meson.build
index 3afe5d58cb..0cfc709f44 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -52,7 +52,6 @@ tests += [
[['src/test/test-engine.c'],
[libcore,
- libudev,
libshared],
[threads,
librt,
@@ -520,8 +519,7 @@ tests += [
'src/journal/journald-server.h'],
[libcore,
libjournal_core,
- libudev_core,
- libudev_static,
+ libudevd_core,
libshared],
[threads,
libseccomp,
@@ -529,7 +527,7 @@ tests += [
libxz,
liblz4,
libblkid],
- '', '', [], libudev_core_includes],
+ '', '', [], libudevd_core_includes],
[['src/test/test-prioq.c'],
[],
@@ -751,12 +749,13 @@ tests += [
[]],
[['src/test/test-libudev.c'],
- [libshared],
- []],
+ [libshared,
+ libudev_static],
+ [],
+ '', '', [], libudev_includes],
[['src/test/test-udev.c'],
- [libudev_core,
- libudev_static,
+ [libudevd_core,
libshared],
[threads,
librt,
@@ -1067,7 +1066,8 @@ tests += [
[libbasic,
libshared_static,
libudev],
- [threads]],
+ [threads],
+ '', '', [], libudev_includes],
[['src/libsystemd/sd-device/test-sd-device-monitor.c'],
[],
diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c
index d162abaea0..12bd0d6299 100644
--- a/src/test/test-libudev.c
+++ b/src/test/test-libudev.c
@@ -345,92 +345,6 @@ static void test_hwdb(struct udev *udev, const char *modalias) {
assert_se(hwdb == NULL);
}
-static void test_util_replace_whitespace_one_len(const char *str, size_t len, const char *expected) {
- _cleanup_free_ char *result = NULL;
- int r;
-
- result = new(char, len + 1);
- assert_se(result);
- r = util_replace_whitespace(str, result, len);
- assert_se((size_t) r == strlen(expected));
- assert_se(streq(result, expected));
-}
-
-static void test_util_replace_whitespace_one(const char *str, const char *expected) {
- test_util_replace_whitespace_one_len(str, strlen(str), expected);
-}
-
-static void test_util_replace_whitespace(void) {
- log_info("/* %s */", __func__);
-
- test_util_replace_whitespace_one("hogehoge", "hogehoge");
- test_util_replace_whitespace_one("hoge hoge", "hoge_hoge");
- test_util_replace_whitespace_one(" hoge hoge ", "hoge_hoge");
- test_util_replace_whitespace_one(" ", "");
- test_util_replace_whitespace_one("hoge ", "hoge");
-
- test_util_replace_whitespace_one_len("hoge hoge ", 9, "hoge_hoge");
- test_util_replace_whitespace_one_len("hoge hoge ", 8, "hoge_hog");
- test_util_replace_whitespace_one_len("hoge hoge ", 7, "hoge_ho");
- test_util_replace_whitespace_one_len("hoge hoge ", 6, "hoge_h");
- test_util_replace_whitespace_one_len("hoge hoge ", 5, "hoge");
- test_util_replace_whitespace_one_len("hoge hoge ", 4, "hoge");
- test_util_replace_whitespace_one_len("hoge hoge ", 3, "hog");
- test_util_replace_whitespace_one_len("hoge hoge ", 2, "ho");
- test_util_replace_whitespace_one_len("hoge hoge ", 1, "h");
- test_util_replace_whitespace_one_len("hoge hoge ", 0, "");
-
- test_util_replace_whitespace_one_len(" hoge hoge ", 16, "hoge_hoge");
- test_util_replace_whitespace_one_len(" hoge hoge ", 15, "hoge_hoge");
- test_util_replace_whitespace_one_len(" hoge hoge ", 14, "hoge_hog");
- test_util_replace_whitespace_one_len(" hoge hoge ", 13, "hoge_ho");
- test_util_replace_whitespace_one_len(" hoge hoge ", 12, "hoge_h");
- test_util_replace_whitespace_one_len(" hoge hoge ", 11, "hoge");
- test_util_replace_whitespace_one_len(" hoge hoge ", 10, "hoge");
- test_util_replace_whitespace_one_len(" hoge hoge ", 9, "hoge");
- test_util_replace_whitespace_one_len(" hoge hoge ", 8, "hoge");
- test_util_replace_whitespace_one_len(" hoge hoge ", 7, "hog");
- test_util_replace_whitespace_one_len(" hoge hoge ", 6, "ho");
- test_util_replace_whitespace_one_len(" hoge hoge ", 5, "h");
- test_util_replace_whitespace_one_len(" hoge hoge ", 4, "");
- test_util_replace_whitespace_one_len(" hoge hoge ", 3, "");
- test_util_replace_whitespace_one_len(" hoge hoge ", 2, "");
- test_util_replace_whitespace_one_len(" hoge hoge ", 1, "");
- 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);
- 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));
-}
-
-static void test_util_resolve_subsys_kernel(void) {
- log_info("/* %s */", __func__);
-
- 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");
-}
-
static void test_list(void) {
_cleanup_(udev_list_freep) struct udev_list *list = NULL;
struct udev_list_entry *e;
@@ -573,9 +487,6 @@ static int run(int argc, char *argv[]) {
if (arg_monitor)
test_monitor(udev);
- test_util_replace_whitespace();
- test_util_resolve_subsys_kernel();
-
test_list();
return 0;
diff --git a/src/test/test-udev-util.c b/src/test/test-udev-util.c
index b0213f8c39..f34c5c27d3 100644
--- a/src/test/test-udev-util.c
+++ b/src/test/test-udev-util.c
@@ -181,6 +181,92 @@ static void test_parse_value_unicode(void) {
);
}
+static void test_udev_replace_whitespace_one_len(const char *str, size_t len, const char *expected) {
+ _cleanup_free_ char *result = NULL;
+ int r;
+
+ result = new(char, len + 1);
+ assert_se(result);
+ r = udev_replace_whitespace(str, result, len);
+ assert_se((size_t) r == strlen(expected));
+ assert_se(streq(result, expected));
+}
+
+static void test_udev_replace_whitespace_one(const char *str, const char *expected) {
+ test_udev_replace_whitespace_one_len(str, strlen(str), expected);
+}
+
+static void test_udev_replace_whitespace(void) {
+ log_info("/* %s */", __func__);
+
+ test_udev_replace_whitespace_one("hogehoge", "hogehoge");
+ test_udev_replace_whitespace_one("hoge hoge", "hoge_hoge");
+ test_udev_replace_whitespace_one(" hoge hoge ", "hoge_hoge");
+ test_udev_replace_whitespace_one(" ", "");
+ test_udev_replace_whitespace_one("hoge ", "hoge");
+
+ test_udev_replace_whitespace_one_len("hoge hoge ", 9, "hoge_hoge");
+ test_udev_replace_whitespace_one_len("hoge hoge ", 8, "hoge_hog");
+ test_udev_replace_whitespace_one_len("hoge hoge ", 7, "hoge_ho");
+ test_udev_replace_whitespace_one_len("hoge hoge ", 6, "hoge_h");
+ test_udev_replace_whitespace_one_len("hoge hoge ", 5, "hoge");
+ test_udev_replace_whitespace_one_len("hoge hoge ", 4, "hoge");
+ test_udev_replace_whitespace_one_len("hoge hoge ", 3, "hog");
+ test_udev_replace_whitespace_one_len("hoge hoge ", 2, "ho");
+ test_udev_replace_whitespace_one_len("hoge hoge ", 1, "h");
+ test_udev_replace_whitespace_one_len("hoge hoge ", 0, "");
+
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 16, "hoge_hoge");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 15, "hoge_hoge");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 14, "hoge_hog");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 13, "hoge_ho");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 12, "hoge_h");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 11, "hoge");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 10, "hoge");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 9, "hoge");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 8, "hoge");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 7, "hog");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 6, "ho");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 5, "h");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 4, "");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 3, "");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 2, "");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 1, "");
+ test_udev_replace_whitespace_one_len(" hoge hoge ", 0, "");
+}
+
+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));
+}
+
+static void test_udev_resolve_subsys_kernel(void) {
+ log_info("/* %s */", __func__);
+
+ 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, -ENODEV, 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");
+}
+
int main(int argc, char **argv) {
test_parse_value();
test_parse_value_with_backslashes();
@@ -198,5 +284,8 @@ int main(int argc, char **argv) {
test_parse_value_invalid_termination();
test_parse_value_unicode();
+ test_udev_replace_whitespace();
+ test_udev_resolve_subsys_kernel();
+
return EXIT_SUCCESS;
}