summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-02-04 00:04:28 +0100
committerGitHub <noreply@github.com>2020-02-04 00:04:28 +0100
commit2f1fc899ce4025dd89bc04a9769dc3623c8c5cf4 (patch)
treeb70b83e99e78a7e76b4cb4c5626ab96c3d6170f9 /src/test
parentl10n: update Czech Translation (diff)
parentsysctl: set ipv4 settings in a race-free way (diff)
downloadsystemd-2f1fc899ce4025dd89bc04a9769dc3623c8c5cf4.tar.xz
systemd-2f1fc899ce4025dd89bc04a9769dc3623c8c5cf4.zip
Merge pull request #14589 from keszybz/sysctl-downgrade-messages
sysctl: add glob patterns to set network settings more flexibly
Diffstat (limited to 'src/test')
-rw-r--r--src/test/meson.build4
-rw-r--r--src/test/test-sysctl-util.c44
2 files changed, 48 insertions, 0 deletions
diff --git a/src/test/meson.build b/src/test/meson.build
index 5df1366561..b79b197c16 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -325,6 +325,10 @@ tests += [
[],
[]],
+ [['src/test/test-sysctl-util.c'],
+ [],
+ []],
+
[['src/test/test-user-util.c'],
[],
[]],
diff --git a/src/test/test-sysctl-util.c b/src/test/test-sysctl-util.c
new file mode 100644
index 0000000000..2b957dd4d6
--- /dev/null
+++ b/src/test/test-sysctl-util.c
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "strv.h"
+#include "sysctl-util.h"
+#include "tests.h"
+
+static const char* cases[] = {
+ "a.b.c", "a/b/c",
+ "a/b/c", "a/b/c",
+ "a/b.c/d", "a/b.c/d",
+ "a.b/c.d", "a/b.c/d",
+
+ "net.ipv4.conf.enp3s0/200.forwarding", "net/ipv4/conf/enp3s0.200/forwarding",
+ "net/ipv4/conf/enp3s0.200/forwarding", "net/ipv4/conf/enp3s0.200/forwarding",
+
+ "a...b...c", "a/b/c",
+ "a///b///c", "a/b/c",
+ ".a...b...c", "a/b/c",
+ "/a///b///c", "a/b/c",
+ NULL,
+};
+
+static void test_sysctl_normalize(void) {
+ log_info("/* %s */", __func__);
+
+ const char **s, **expected;
+ STRV_FOREACH_PAIR(s, expected, cases) {
+ _cleanup_free_ char *t;
+
+ assert_se(t = strdup(*s));
+ assert_se(sysctl_normalize(t) == t);
+
+ log_info("\"%s\" → \"%s\", expected \"%s\"", *s, t, *expected);
+ assert_se(streq(t, *expected));
+ }
+}
+
+int main(int argc, char *argv[]) {
+ test_setup_logging(LOG_INFO);
+
+ test_sysctl_normalize();
+
+ return 0;
+}