mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
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.
This commit is contained in:
parent
67e2baff6b
commit
d184fb39b6
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user