From b605cf820c4831451fd009825a914d6f98045219 Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Tue, 18 Oct 2016 17:57:10 +0200 Subject: Add abstraction model for BPF programs This object takes a number of bpf_insn members and wraps them together with the in-kernel reference id. Will be needed by the firewall code. --- src/test/meson.build | 4 +- src/test/test-cgroup.c | 1 - src/test/test-conf-parser.c | 136 ++------------------------------------------ src/test/test-log.c | 1 - src/test/test-signal-util.c | 1 - 5 files changed, 8 insertions(+), 135 deletions(-) (limited to 'src/test') diff --git a/src/test/meson.build b/src/test/meson.build index e39ab46e8..7e1adb3d1 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -300,11 +300,11 @@ tests += [ # [], # []], # -# [['src/test/test-barrier.c'], +# [['src/test/test-in-addr-util.c'], # [], # []], # -# [['src/test/test-in-addr-util.c'], +# [['src/test/test-barrier.c'], # [], # []], # diff --git a/src/test/test-cgroup.c b/src/test/test-cgroup.c index 2ed91c780..71e318a15 100644 --- a/src/test/test-cgroup.c +++ b/src/test/test-cgroup.c @@ -22,7 +22,6 @@ #include "cgroup-util.h" #include "path-util.h" -#include "process-util.h" #include "string-util.h" #include "util.h" diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c index fe94b336a..a66ed1bd3 100644 --- a/src/test/test-conf-parser.c +++ b/src/test/test-conf-parser.c @@ -18,8 +18,6 @@ ***/ #include "conf-parser.h" -#include "fd-util.h" -#include "fileio.h" #include "log.h" #include "macro.h" #include "string-util.h" @@ -27,10 +25,12 @@ #include "util.h" static void test_config_parse_path_one(const char *rvalue, const char *expected) { - _cleanup_free_ char *path = NULL; + 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,10 +80,12 @@ static void test_config_parse_unsigned_one(const char *rvalue, unsigned expected } static void test_config_parse_strv_one(const char *rvalue, char **expected) { - _cleanup_strv_free_ char **strv = NULL; + char **strv = 0; 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) { @@ -237,130 +239,7 @@ 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(); @@ -383,8 +262,5 @@ 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-log.c b/src/test/test-log.c index ec1bc2a63..8ab569f47 100644 --- a/src/test/test-log.c +++ b/src/test/test-log.c @@ -22,7 +22,6 @@ #include "format-util.h" #include "log.h" -#include "process-util.h" #include "util.h" assert_cc(LOG_REALM_REMOVE_LEVEL(LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, LOG_FTP | LOG_DEBUG)) diff --git a/src/test/test-signal-util.c b/src/test/test-signal-util.c index 1830396ac..92e392778 100644 --- a/src/test/test-signal-util.c +++ b/src/test/test-signal-util.c @@ -21,7 +21,6 @@ #include #include "macro.h" -#include "process-util.h" #include "signal-util.h" static void test_block_signals(void) { -- cgit v1.2.3