summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/meson.build6
-rw-r--r--src/test/test-conf-parser.c138
-rw-r--r--src/test/test-dlopen.c32
-rw-r--r--src/test/test-process-util.c6
4 files changed, 171 insertions, 11 deletions
diff --git a/src/test/meson.build b/src/test/meson.build
index c811dd675..a923d6144 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -35,10 +35,10 @@ test_libelogind_sym_c = custom_target(
# output : 'test-libudev-sym.c',
# command : [generate_sym_test_py, '@INPUT0@', '@INPUT1@'],
# capture : true)
-#
-# test_dlopen_c = files('test-dlopen.c')
#endif // 0
+test_dlopen_c = files('test-dlopen.c')
+
############################################################
tests += [
@@ -365,6 +365,7 @@ tests += [
[libbasic],
[]],
+#if 0 /// UNNEEDED in elogind
# [['src/test/test-bpf.c',
# 'src/test/test-helper.c'],
# [libcore,
@@ -375,6 +376,7 @@ tests += [
# libseccomp,
# libselinux,
# libblkid]],
+#endif // 0
[['src/test/test-hashmap.c',
'src/test/test-hashmap-plain.c',
diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c
index a66ed1bd3..17d12ec76 100644
--- a/src/test/test-conf-parser.c
+++ b/src/test/test-conf-parser.c
@@ -24,13 +24,15 @@
#include "strv.h"
#include "util.h"
+/// Additional includes needed by elogind
+#include "fd-util.h"
+#include "fileio.h"
+
static void test_config_parse_path_one(const char *rvalue, const char *expected) {
- char *path = NULL;
+ _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));
-
- free(path);
}
static void test_config_parse_log_level_one(const char *rvalue, int expected) {
@@ -80,12 +82,10 @@ static void test_config_parse_unsigned_one(const char *rvalue, unsigned expected
}
static void test_config_parse_strv_one(const char *rvalue, char **expected) {
- char **strv = 0;
+ _cleanup_strv_free_ char **strv = NULL;
assert_se(config_parse_strv("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &strv, NULL) >= 0);
assert_se(strv_equal(expected, strv));
-
- strv_free(strv);
}
static void test_config_parse_mode_one(const char *rvalue, mode_t expected) {
@@ -239,7 +239,130 @@ static void test_config_parse_iec_uint64(void) {
}
#endif // 0
+#define x10(x) x x x x x x x x x x
+#define x100(x) x10(x10(x))
+#define x1000(x) x10(x100(x))
+
+static const char* const config_file[] = {
+ "[Section]\n"
+ "setting1=1\n",
+
+ "[Section]\n"
+ "setting1=1", /* no terminating newline */
+
+ "\n\n\n\n[Section]\n\n\n"
+ "setting1=1", /* some whitespace, no terminating newline */
+
+ "[Section]\n"
+ "[Section]\n"
+ "setting1=1\n"
+ "setting1=2\n"
+ "setting1=1\n", /* repeated settings */
+
+ "[Section]\n"
+ "setting1=1\\\n" /* normal continuation */
+ "2\\\n"
+ "3\n",
+
+ "[Section]\n"
+ "setting1=1\\\\\\\n" /* continuation with trailing escape symbols */
+ "\\\\2\n", /* note that C requires one level of escaping, so the
+ * parser gets "…1 BS BS BS NL BS BS 2 NL", which
+ * it translates into "…1 BS BS SP BS BS 2" */
+
+ "\n[Section]\n\n"
+ "setting1=" /* a line above LINE_MAX length */
+ x1000("ABCD")
+ "\n",
+
+ "[Section]\n"
+ "setting1=" /* a line above LINE_MAX length, with continuation */
+ x1000("ABCD") "\\\n"
+ "foobar",
+
+ "[Section]\n"
+ "setting1=" /* a line above the allowed limit: 9 + 1050000 + 1 */
+ x1000(x1000("x") x10("abcde")) "\n",
+
+ "[Section]\n"
+ "setting1=" /* many continuation lines, together above the limit */
+ x1000(x1000("x") x10("abcde") "\\\n") "xxx",
+};
+
+static void test_config_parse(unsigned i, const char *s) {
+ char name[] = "/tmp/test-conf-parser.XXXXXX";
+ int fd, r;
+ _cleanup_fclose_ FILE *f = NULL;
+ _cleanup_free_ char *setting1 = NULL;
+
+ const ConfigTableItem items[] = {
+ { "Section", "setting1", config_parse_string, 0, &setting1},
+ {}
+ };
+
+ log_info("== %s[%i] ==", __func__, i);
+
+ fd = mkostemp_safe(name);
+ assert_se(fd >= 0);
+ assert_se((size_t) write(fd, s, strlen(s)) == strlen(s));
+
+ assert_se(lseek(fd, 0, SEEK_SET) == 0);
+ assert_se(f = fdopen(fd, "r"));
+
+ /*
+ int config_parse(const char *unit,
+ const char *filename,
+ FILE *f,
+ const char *sections,
+ ConfigItemLookup lookup,
+ const void *table,
+ bool relaxed,
+ bool allow_include,
+ bool warn,
+ void *userdata)
+ */
+
+ r = config_parse(NULL, name, f,
+ "Section\0",
+ config_item_table_lookup, items,
+ false, false, true, NULL);
+
+ switch (i) {
+ case 0 ... 3:
+ assert_se(r == 0);
+ assert_se(streq(setting1, "1"));
+ break;
+
+ case 4:
+ assert_se(r == 0);
+ assert_se(streq(setting1, "1 2 3"));
+ break;
+
+ case 5:
+ assert_se(r == 0);
+ assert_se(streq(setting1, "1\\\\ \\\\2"));
+ break;
+
+ case 6:
+ assert_se(r == 0);
+ assert_se(streq(setting1, x1000("ABCD")));
+ break;
+
+ case 7:
+ assert_se(r == 0);
+ assert_se(streq(setting1, x1000("ABCD") " foobar"));
+ break;
+
+ case 8 ... 9:
+ assert_se(r == -ENOBUFS);
+ assert_se(setting1 == NULL);
+ break;
+ }
+}
+
int main(int argc, char **argv) {
+ unsigned i;
+
log_parse_environment();
log_open();
@@ -262,5 +385,8 @@ int main(int argc, char **argv) {
test_config_parse_iec_uint64();
#endif // 0
+ for (i = 0; i < ELEMENTSOF(config_file); i++)
+ test_config_parse(i, config_file[i]);
+
return 0;
}
diff --git a/src/test/test-dlopen.c b/src/test/test-dlopen.c
new file mode 100644
index 000000000..9f5343a7e
--- /dev/null
+++ b/src/test/test-dlopen.c
@@ -0,0 +1,32 @@
+/***
+ This file is part of systemd.
+
+ Copyright 2016 Zbigniew Jędrzejewski-Szmek
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <dlfcn.h>
+#include <stdlib.h>
+
+#include "macro.h"
+
+int main(int argc, char **argv) {
+ void *handle;
+
+ assert_se((handle = dlopen(argv[1], RTLD_NOW)));
+ assert_se(dlclose(handle) == 0);
+
+ return EXIT_SUCCESS;
+}
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
index 19ffe01d7..c573f4127 100644
--- a/src/test/test-process-util.c
+++ b/src/test/test-process-util.c
@@ -26,7 +26,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
-#ifdef HAVE_VALGRIND_VALGRIND_H
+#if HAVE_VALGRIND_VALGRIND_H
#include <valgrind/valgrind.h>
#endif
@@ -176,7 +176,7 @@ static void test_get_process_cmdline_harder(void) {
if (geteuid() != 0)
return;
-#ifdef HAVE_VALGRIND_VALGRIND_H
+#if HAVE_VALGRIND_VALGRIND_H
/* valgrind patches open(/proc//cmdline)
* so, test_get_process_cmdline_harder fails always
* See https://github.com/systemd/systemd/pull/3555#issuecomment-226564908 */
@@ -376,7 +376,7 @@ static void test_rename_process_now(const char *p, int ret) {
if (r < 0)
return;
-#ifdef HAVE_VALGRIND_VALGRIND_H
+#if HAVE_VALGRIND_VALGRIND_H
/* see above, valgrind is weird, we can't verify what we are doing here */
if (RUNNING_ON_VALGRIND)
return;