diff options
author | Michal Koutný <mkoutny@suse.com> | 2020-06-24 19:50:00 +0200 |
---|---|---|
committer | Michal Koutný <mkoutny@suse.com> | 2020-06-24 23:16:11 +0200 |
commit | d184fb39b680afb23b778f9ea9fd19b894f86e80 (patch) | |
tree | 2486eebd86777e90ed39136643ce5347f2c1f1b5 | |
parent | 67e2baff6be8052f48dfdb2258fb68d63c95fe01 (diff) | |
download | systemd-d184fb39b680afb23b778f9ea9fd19b894f86e80.tar.gz |
test: Test memory limit parsing
This covers parsing from configuration files only. Properties set via
DBus have separate code path whose testing would require DBus setup.
-rw-r--r-- | src/test/test-load-fragment.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/test-load-fragment.c b/src/test/test-load-fragment.c index 7de286436d..0293d1cd0f 100644 --- a/src/test/test-load-fragment.c +++ b/src/test/test-load-fragment.c @@ -27,6 +27,9 @@ #include "tmpfile-util.h" #include "user-util.h" +/* Nontrivial value serves as a placeholder to check that parsing function (didn't) change it */ +#define CGROUP_LIMIT_DUMMY 3 + static int test_unit_file_get_set(void) { int r; Hashmap *h; @@ -773,6 +776,62 @@ static void test_unit_dump_config_items(void) { unit_dump_config_items(stdout); } +static void test_config_parse_memory_limit(void) { + /* int config_parse_memory_limit( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) */ + CGroupContext c; + struct limit_test { + const char *limit; + const char *value; + uint64_t *result; + uint64_t expected; + } limit_tests[]= { + { "MemoryMin", "", &c.memory_min, CGROUP_LIMIT_MIN }, + { "MemoryMin", "0", &c.memory_min, CGROUP_LIMIT_MIN }, + { "MemoryMin", "10", &c.memory_min, 10 }, + { "MemoryMin", "infinity", &c.memory_min, CGROUP_LIMIT_MAX }, + { "MemoryLow", "", &c.memory_low, CGROUP_LIMIT_MIN }, + { "MemoryLow", "0", &c.memory_low, CGROUP_LIMIT_MIN }, + { "MemoryLow", "10", &c.memory_low, 10 }, + { "MemoryLow", "infinity", &c.memory_low, CGROUP_LIMIT_MAX }, + { "MemoryHigh", "", &c.memory_high, CGROUP_LIMIT_MAX }, + { "MemoryHigh", "0", &c.memory_high, CGROUP_LIMIT_DUMMY }, + { "MemoryHigh", "10", &c.memory_high, 10 }, + { "MemoryHigh", "infinity", &c.memory_high, CGROUP_LIMIT_MAX }, + { "MemoryMax", "", &c.memory_max, CGROUP_LIMIT_MAX }, + { "MemoryMax", "0", &c.memory_max, CGROUP_LIMIT_DUMMY }, + { "MemoryMax", "10", &c.memory_max, 10 }, + { "MemoryMax", "infinity", &c.memory_max, CGROUP_LIMIT_MAX }, + }; + size_t i; + int r; + + for (i = 0; i < ELEMENTSOF(limit_tests); i++) { + c.memory_min = CGROUP_LIMIT_DUMMY; + c.memory_low = CGROUP_LIMIT_DUMMY; + c.memory_high = CGROUP_LIMIT_DUMMY; + c.memory_max = CGROUP_LIMIT_DUMMY; + r = config_parse_memory_limit(NULL, "fake", 1, "section", 1, + limit_tests[i].limit, 1, + limit_tests[i].value, &c, NULL); + log_info("%s=%s\t%"PRIu64"==%"PRIu64"\n", + limit_tests[i].limit, limit_tests[i].value, + *limit_tests[i].result, limit_tests[i].expected); + assert_se(r >= 0); + assert_se(*limit_tests[i].result == limit_tests[i].expected); + } + +} + int main(int argc, char *argv[]) { _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL; int r; @@ -793,6 +852,7 @@ int main(int argc, char *argv[]) { test_config_parse_pass_environ(); TEST_REQ_RUNNING_SYSTEMD(test_install_printf()); test_unit_dump_config_items(); + test_config_parse_memory_limit(); return r; } |