diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-09-14 23:13:36 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-09-15 16:32:40 +0200 |
commit | 3448711b7e04cfcda0e0e046b5f94c7f35105185 (patch) | |
tree | a852c21bfea5e7006c8e12463098055da15c5706 /src/test/test-sysctl-util.c | |
parent | 89edc243e4b50094df4cef81a7637a9c6a38962a (diff) | |
download | systemd-3448711b7e04cfcda0e0e046b5f94c7f35105185.tar.gz |
test: add test case for sysctl-util.[ch]
Diffstat (limited to 'src/test/test-sysctl-util.c')
-rw-r--r-- | src/test/test-sysctl-util.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/test-sysctl-util.c b/src/test/test-sysctl-util.c index 991a1e3363..17ec04e732 100644 --- a/src/test/test-sysctl-util.c +++ b/src/test/test-sysctl-util.c @@ -1,5 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-id128.h" + +#include "errno-util.h" +#include "hostname-util.h" #include "strv.h" #include "sysctl-util.h" #include "tests.h" @@ -35,10 +39,44 @@ static void test_sysctl_normalize(void) { } } +static void test_sysctl_read(void) { + _cleanup_free_ char *s = NULL, *h = NULL; + sd_id128_t a, b; + int r; + + assert_se(sysctl_read("kernel/random/boot_id", &s) >= 0); + assert_se(sd_id128_from_string(s, &a) >= 0); + assert_se(sd_id128_get_boot(&b) >= 0); + assert_se(sd_id128_equal(a, b)); + s = mfree(s); + + assert_se(sysctl_read_ip_property(AF_INET, "lo", "forwarding", &s)); + assert_se(STR_IN_SET(s, "0", "1")); + + r = sysctl_write_ip_property(AF_INET, "lo", "forwarding", s); + assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS); + s = mfree(s); + + assert_se(sysctl_read_ip_property(AF_INET, NULL, "ip_forward", &s)); + assert_se(STR_IN_SET(s, "0", "1")); + + r = sysctl_write_ip_property(AF_INET, NULL, "ip_forward", s); + assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS); + s = mfree(s); + + assert_se(sysctl_read("kernel/hostname", &s) >= 0); + assert_se(gethostname_full(GET_HOSTNAME_ALLOW_NONE|GET_HOSTNAME_ALLOW_LOCALHOST, &h) >= 0); + assert_se(streq(s, h)); + + r = sysctl_write("kernel/hostname", s); + assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS); +} + int main(int argc, char *argv[]) { test_setup_logging(LOG_INFO); test_sysctl_normalize(); + test_sysctl_read(); return 0; } |