summaryrefslogtreecommitdiffstats
path: root/src/test/test-conf-parser.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:42 +0000
commit78e9bb837c258ac0ec7712b3d612cc2f407e731e (patch)
treef515d16b6efd858a9aeb5b0ef5d6f90bf288283d /src/test/test-conf-parser.c
parentAdding debian version 255.5-1. (diff)
downloadsystemd-78e9bb837c258ac0ec7712b3d612cc2f407e731e.tar.xz
systemd-78e9bb837c258ac0ec7712b3d612cc2f407e731e.zip
Merging upstream version 256.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-conf-parser.c')
-rw-r--r--src/test/test-conf-parser.c116
1 files changed, 108 insertions, 8 deletions
diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c
index 0acb413..4e236bd 100644
--- a/src/test/test-conf-parser.c
+++ b/src/test/test-conf-parser.c
@@ -3,8 +3,10 @@
#include "conf-parser.h"
#include "fd-util.h"
#include "fs-util.h"
+#include "fileio.h"
#include "log.h"
#include "macro.h"
+#include "mkdir.h"
#include "string-util.h"
#include "strv.h"
#include "tests.h"
@@ -14,7 +16,7 @@ static void test_config_parse_path_one(const char *rvalue, const char *expected)
_cleanup_free_ char *path = NULL;
assert_se(config_parse_path("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &path, NULL) >= 0);
- assert_se(streq_ptr(expected, path));
+ ASSERT_STREQ(expected, path);
}
static void test_config_parse_log_level_one(const char *rvalue, int expected) {
@@ -350,37 +352,37 @@ static void test_config_parse_one(unsigned i, const char *s) {
switch (i) {
case 0 ... 4:
assert_se(r == 1);
- assert_se(streq(setting1, "1"));
+ ASSERT_STREQ(setting1, "1");
break;
case 5 ... 10:
assert_se(r == 1);
- assert_se(streq(setting1, "1 2 3"));
+ ASSERT_STREQ(setting1, "1 2 3");
break;
case 11:
assert_se(r == 1);
- assert_se(streq(setting1, "1\\\\ \\\\2"));
+ ASSERT_STREQ(setting1, "1\\\\ \\\\2");
break;
case 12:
assert_se(r == 1);
- assert_se(streq(setting1, x1000("ABCD")));
+ ASSERT_STREQ(setting1, x1000("ABCD"));
break;
case 13 ... 14:
assert_se(r == 1);
- assert_se(streq(setting1, x1000("ABCD") " foobar"));
+ ASSERT_STREQ(setting1, x1000("ABCD") " foobar");
break;
case 15 ... 16:
assert_se(r == -ENOBUFS);
- assert_se(setting1 == NULL);
+ ASSERT_NULL(setting1);
break;
case 17:
assert_se(r == 1);
- assert_se(streq(setting1, "2"));
+ ASSERT_STREQ(setting1, "2");
break;
}
}
@@ -390,4 +392,102 @@ TEST(config_parse) {
test_config_parse_one(i, config_file[i]);
}
+TEST(config_parse_standard_file_with_dropins_full) {
+ _cleanup_(rmdir_and_freep) char *root = NULL;
+ _cleanup_close_ int rfd = -EBADF;
+ int r;
+
+ assert_se(mkdtemp_malloc(NULL, &root) >= 0);
+ assert_se(mkdir_p_root(root, "/etc/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755));
+ assert_se(mkdir_p_root(root, "/run/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755));
+ assert_se(mkdir_p_root(root, "/usr/lib/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755));
+ assert_se(mkdir_p_root(root, "/usr/local/lib/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755));
+
+ rfd = open(root, O_CLOEXEC|O_DIRECTORY);
+ assert_se(rfd >= 0);
+
+ assert_se(write_string_file_at(rfd, "usr/lib/kernel/install.conf", /* this one is ignored */
+ "A=!!!", WRITE_STRING_FILE_CREATE) == 0);
+ assert_se(write_string_file_at(rfd, "usr/local/lib/kernel/install.conf",
+ "A=aaa", WRITE_STRING_FILE_CREATE) == 0);
+ assert_se(write_string_file_at(rfd, "usr/local/lib/kernel/install.conf.d/drop1.conf",
+ "B=bbb", WRITE_STRING_FILE_CREATE) == 0);
+ assert_se(write_string_file_at(rfd, "usr/local/lib/kernel/install.conf.d/drop2.conf",
+ "C=c1", WRITE_STRING_FILE_CREATE) == 0);
+ assert_se(write_string_file_at(rfd, "usr/lib/kernel/install.conf.d/drop2.conf", /* this one is ignored */
+ "C=c2", WRITE_STRING_FILE_CREATE) == 0);
+ assert_se(write_string_file_at(rfd, "run/kernel/install.conf.d/drop3.conf",
+ "D=ddd", WRITE_STRING_FILE_CREATE) == 0);
+ assert_se(write_string_file_at(rfd, "etc/kernel/install.conf.d/drop4.conf",
+ "E=eee", WRITE_STRING_FILE_CREATE) == 0);
+
+ _cleanup_free_ char *A = NULL, *B = NULL, *C = NULL, *D = NULL, *E = NULL, *F = NULL;
+ _cleanup_strv_free_ char **dropins = NULL;
+
+ const ConfigTableItem items[] = {
+ { NULL, "A", config_parse_string, 0, &A},
+ { NULL, "B", config_parse_string, 0, &B},
+ { NULL, "C", config_parse_string, 0, &C},
+ { NULL, "D", config_parse_string, 0, &D},
+ { NULL, "E", config_parse_string, 0, &E},
+ { NULL, "F", config_parse_string, 0, &F},
+ {}
+ };
+
+ r = config_parse_standard_file_with_dropins_full(
+ root, "kernel/install.conf",
+ /* sections= */ NULL,
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN,
+ /* userdata= */ NULL,
+ /* ret_stats_by_path= */ NULL,
+ /* ret_dropin_files= */ &dropins);
+ assert_se(r >= 0);
+ ASSERT_STREQ(A, "aaa");
+ ASSERT_STREQ(B, "bbb");
+ ASSERT_STREQ(C, "c1");
+ ASSERT_STREQ(D, "ddd");
+ ASSERT_STREQ(E, "eee");
+ ASSERT_STREQ(F, NULL);
+
+ A = mfree(A);
+ B = mfree(B);
+ C = mfree(C);
+ D = mfree(D);
+ E = mfree(E);
+
+ assert_se(strv_length(dropins) == 4);
+
+ /* Make sure that we follow symlinks */
+ assert_se(mkdir_p_root(root, "/etc/kernel/install2.conf.d", UID_INVALID, GID_INVALID, 0755));
+ assert_se(mkdir_p_root(root, "/run/kernel/install2.conf.d", UID_INVALID, GID_INVALID, 0755));
+ assert_se(mkdir_p_root(root, "/usr/lib/kernel/install2.conf.d", UID_INVALID, GID_INVALID, 0755));
+ assert_se(mkdir_p_root(root, "/usr/local/lib/kernel/install2.conf.d", UID_INVALID, GID_INVALID, 0755));
+
+ /* (Those symlinks are only useful relative to <root>. */
+ assert_se(symlinkat("/usr/lib/kernel/install.conf", rfd, "usr/lib/kernel/install2.conf") == 0);
+ assert_se(symlinkat("/usr/local/lib/kernel/install.conf", rfd, "usr/local/lib/kernel/install2.conf") == 0);
+ assert_se(symlinkat("/usr/local/lib/kernel/install.conf.d/drop1.conf", rfd, "usr/local/lib/kernel/install2.conf.d/drop1.conf") == 0);
+ assert_se(symlinkat("/usr/local/lib/kernel/install.conf.d/drop2.conf", rfd, "usr/local/lib/kernel/install2.conf.d/drop2.conf") == 0);
+ assert_se(symlinkat("/usr/lib/kernel/install.conf.d/drop2.conf", rfd, "usr/lib/kernel/install2.conf.d/drop2.conf") == 0);
+ assert_se(symlinkat("/run/kernel/install.conf.d/drop3.conf", rfd, "run/kernel/install2.conf.d/drop3.conf") == 0);
+ assert_se(symlinkat("/etc/kernel/install.conf.d/drop4.conf", rfd, "etc/kernel/install2.conf.d/drop4.conf") == 0);
+
+ r = config_parse_standard_file_with_dropins_full(
+ root, "kernel/install2.conf",
+ /* sections= */ NULL,
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN,
+ /* userdata= */ NULL,
+ /* ret_stats_by_path= */ NULL,
+ /* ret_dropin_files= */ NULL);
+ assert_se(r >= 0);
+ ASSERT_STREQ(A, "aaa");
+ ASSERT_STREQ(B, "bbb");
+ ASSERT_STREQ(C, "c1");
+ ASSERT_STREQ(D, "ddd");
+ ASSERT_STREQ(E, "eee");
+ ASSERT_STREQ(F, NULL);
+}
+
DEFINE_TEST_MAIN(LOG_INFO);