diff options
author | Anita Zhang <the.anitazha@gmail.com> | 2020-06-04 11:13:29 +0200 |
---|---|---|
committer | Anita Zhang <the.anitazha@gmail.com> | 2020-10-08 01:17:24 +0200 |
commit | 510ca79cf2443bba5089f34e1fec2466cf5312ac (patch) | |
tree | a2701a5bfb07973a0f2e876a8191fde963fb3741 /src/test/test-parse-util.c | |
parent | core: add varlink call to get cgroup paths of units using ManagedOOM*= (diff) | |
download | systemd-510ca79cf2443bba5089f34e1fec2466cf5312ac.tar.xz systemd-510ca79cf2443bba5089f34e1fec2466cf5312ac.zip |
parse-util: add parse_loadavg_fixed_point
Diffstat (limited to '')
-rw-r--r-- | src/test/test-parse-util.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c index 3806c3f8cf..d4f908f5d4 100644 --- a/src/test/test-parse-util.c +++ b/src/test/test-parse-util.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #include <errno.h> +#include <linux/loadavg.h> #include <locale.h> #include <math.h> #include <sys/socket.h> @@ -929,6 +930,42 @@ static void test_parse_mtu(void) { assert_se(parse_mtu(AF_UNSPEC, "", &mtu) == -EINVAL); } +static void test_parse_loadavg_fixed_point(void) { + loadavg_t fp; + + assert_se(parse_loadavg_fixed_point("1.23", &fp) == 0); + assert_se(LOAD_INT(fp) == 1); + assert_se(LOAD_FRAC(fp) == 23); + + assert_se(parse_loadavg_fixed_point("1.80", &fp) == 0); + assert_se(LOAD_INT(fp) == 1); + assert_se(LOAD_FRAC(fp) == 80); + + assert_se(parse_loadavg_fixed_point("0.07", &fp) == 0); + assert_se(LOAD_INT(fp) == 0); + assert_se(LOAD_FRAC(fp) == 7); + + assert_se(parse_loadavg_fixed_point("0.00", &fp) == 0); + assert_se(LOAD_INT(fp) == 0); + assert_se(LOAD_FRAC(fp) == 0); + + assert_se(parse_loadavg_fixed_point("4096.57", &fp) == 0); + assert_se(LOAD_INT(fp) == 4096); + assert_se(LOAD_FRAC(fp) == 57); + + /* Caps out at 2 digit fracs */ + assert_se(parse_loadavg_fixed_point("1.100", &fp) == -ERANGE); + + assert_se(parse_loadavg_fixed_point("4096.4096", &fp) == -ERANGE); + assert_se(parse_loadavg_fixed_point("-4000.5", &fp) == -ERANGE); + assert_se(parse_loadavg_fixed_point("18446744073709551615.5", &fp) == -ERANGE); + assert_se(parse_loadavg_fixed_point("foobar", &fp) == -EINVAL); + assert_se(parse_loadavg_fixed_point("3333", &fp) == -EINVAL); + assert_se(parse_loadavg_fixed_point("1.2.3", &fp) == -EINVAL); + assert_se(parse_loadavg_fixed_point(".", &fp) == -EINVAL); + assert_se(parse_loadavg_fixed_point("", &fp) == -EINVAL); +} + int main(int argc, char *argv[]) { log_parse_environment(); log_open(); @@ -955,6 +992,7 @@ int main(int argc, char *argv[]) { test_parse_errno(); test_parse_syscall_and_errno(); test_parse_mtu(); + test_parse_loadavg_fixed_point(); return 0; } |