]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-sysctl-util.c
Merge pull request #16080 from YmrDtnJu/9p
[thirdparty/systemd.git] / src / test / test-sysctl-util.c
CommitLineData
f3b136a4
ZJS
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include "strv.h"
4#include "sysctl-util.h"
5#include "tests.h"
6
7static const char* cases[] = {
8 "a.b.c", "a/b/c",
9 "a/b/c", "a/b/c",
10 "a/b.c/d", "a/b.c/d",
11 "a.b/c.d", "a/b.c/d",
12
13 "net.ipv4.conf.enp3s0/200.forwarding", "net/ipv4/conf/enp3s0.200/forwarding",
14 "net/ipv4/conf/enp3s0.200/forwarding", "net/ipv4/conf/enp3s0.200/forwarding",
15
16 "a...b...c", "a/b/c",
17 "a///b///c", "a/b/c",
18 ".a...b...c", "a/b/c",
19 "/a///b///c", "a/b/c",
20 NULL,
21};
22
23static void test_sysctl_normalize(void) {
24 log_info("/* %s */", __func__);
25
26 const char **s, **expected;
27 STRV_FOREACH_PAIR(s, expected, cases) {
28 _cleanup_free_ char *t;
29
30 assert_se(t = strdup(*s));
31 assert_se(sysctl_normalize(t) == t);
32
33 log_info("\"%s\" → \"%s\", expected \"%s\"", *s, t, *expected);
34 assert_se(streq(t, *expected));
35 }
36}
37
38int main(int argc, char *argv[]) {
39 test_setup_logging(LOG_INFO);
40
41 test_sysctl_normalize();
42
43 return 0;
44}