summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lowmem-limit-env.cpp22
-rw-r--r--tests/lowmem-limit-env.hpp1
-rw-r--r--tests/lowmem-limit-mock.cpp3
-rw-r--r--tests/lowmem-system-env.cpp10
-rw-r--r--tests/lowmem-system-env.hpp1
-rw-r--r--tests/lowmem-system-mock.cpp3
-rw-r--r--tests/lowmem-system-test.cpp21
7 files changed, 55 insertions, 6 deletions
diff --git a/tests/lowmem-limit-env.cpp b/tests/lowmem-limit-env.cpp
index af60a94e..44596b2c 100644
--- a/tests/lowmem-limit-env.cpp
+++ b/tests/lowmem-limit-env.cpp
@@ -324,6 +324,28 @@ int LowmemLimitEnv::cgroup_read_node_uint32(const char *cgroup_name, const char
return 0;
}
+int LowmemLimitEnv::cgroup_read_node_uint64(const char *cgroup_name, const char *file_name, uint64_t *value)
+{
+ std::cerr << " cgroup_name=" << cgroup_name << ", file_name=" << file_name << std::endl;
+ std::cerr << " -> ";
+ auto it = cgroup_memory.find(cgroup_name);
+ if (it == cgroup_memory.end()) {
+ std::cerr << "cgroup " << cgroup_name << " not found\n";
+ return -1;
+ }
+
+ auto it_file = it->second.files.find(std::string(file_name));
+ if (it_file == it->second.files.end()) {
+ std::cerr << "file " << file_name << " not found\n";
+ return -1;
+ }
+
+ *value = std::stoi(it_file->second);
+ std::cerr << *value << std::endl;
+
+ return 0;
+}
+
int LowmemLimitEnv::cgroup_get_memory_stat(const char *name, struct cgroup_memory_stat **mem_stat)
{
std::cerr << " name=" << name << std::endl;
diff --git a/tests/lowmem-limit-env.hpp b/tests/lowmem-limit-env.hpp
index 655ce07f..c1b45851 100644
--- a/tests/lowmem-limit-env.hpp
+++ b/tests/lowmem-limit-env.hpp
@@ -115,6 +115,7 @@ public:
int cgroup_get_pids(const char *name, GArray **pids);
int cgroup_write_node_uint32(const char *cgroup_name, const char *file_name, uint32_t value);
int cgroup_read_node_uint32(const char *cgroup_name, const char *file_name, uint32_t *value);
+ int cgroup_read_node_uint64(const char *cgroup_name, const char *file_name, uint64_t *value);
int cgroup_get_memory_stat(const char *name, struct cgroup_memory_stat **mem_stat);
int cgroup_make_subdir(const char* parentdir, const char* cgroup_name, bool *already);
diff --git a/tests/lowmem-limit-mock.cpp b/tests/lowmem-limit-mock.cpp
index fb8f0306..f70532e2 100644
--- a/tests/lowmem-limit-mock.cpp
+++ b/tests/lowmem-limit-mock.cpp
@@ -46,6 +46,9 @@ MOCK_LIMIT(int, cgroup_write_node_uint32,
MOCK_LIMIT(int, cgroup_read_node_uint32,
(const char *cgroup_name, const char *file_name, uint32_t *value),
(cgroup_name, file_name, value))
+MOCK_LIMIT(int, cgroup_read_node_uint64,
+ (const char *cgroup_name, const char *file_name, uint64_t *value),
+ (cgroup_name, file_name, value))
MOCK_LIMIT(int, cgroup_get_memory_stat,
(const char *name, struct cgroup_memory_stat **mem_stat),
(name, mem_stat))
diff --git a/tests/lowmem-system-env.cpp b/tests/lowmem-system-env.cpp
index b2ed8411..f76ec4d7 100644
--- a/tests/lowmem-system-env.cpp
+++ b/tests/lowmem-system-env.cpp
@@ -77,6 +77,16 @@ int LowmemSystemEnv::cgroup_read_node_uint32(const char *cgroup_name, const char
return RESOURCED_ERROR_NONE;
}
+int LowmemSystemEnv::cgroup_read_node_uint64(const char *cgroup_name, const char *file_name, uint64_t *value)
+{
+ std::cerr << " cgroup_name=" << cgroup_name << ", file_name=" << file_name << std::endl;
+ check_expected(cgroup_name);
+ check_expected(file_name);
+ *value = static_cast<uint64_t>(mock());
+ std::cerr << " -> " << *value << std::endl;
+ return RESOURCED_ERROR_NONE;
+}
+
void LowmemSystemEnv::g_source_destroy(GSource *source)
{
delete source;
diff --git a/tests/lowmem-system-env.hpp b/tests/lowmem-system-env.hpp
index 145c16b7..0607ba0e 100644
--- a/tests/lowmem-system-env.hpp
+++ b/tests/lowmem-system-env.hpp
@@ -34,6 +34,7 @@ public:
int cgroup_read_node_int32(const char *cgroup_name, const char *file_name, int32_t *value);
int cgroup_write_node_uint32(const char *cgroup_name, const char *file_name, uint32_t value);
int cgroup_read_node_uint32(const char *cgroup_name, const char *file_name, uint32_t *value);
+ int cgroup_read_node_uint64(const char *cgroup_name, const char *file_name, uint64_t *value);
void g_source_destroy(GSource *source);
GSource *g_timeout_source_new_seconds(guint interval);
diff --git a/tests/lowmem-system-mock.cpp b/tests/lowmem-system-mock.cpp
index ff88ade2..6b652058 100644
--- a/tests/lowmem-system-mock.cpp
+++ b/tests/lowmem-system-mock.cpp
@@ -33,6 +33,9 @@ MOCK_SYSTEM(int, cgroup_write_node_uint32,
MOCK_SYSTEM(int, cgroup_read_node_uint32,
(const char *cgroup_name, const char *file_name, uint32_t *value),
(cgroup_name, file_name, value))
+MOCK_SYSTEM(int, cgroup_read_node_uint64,
+ (const char *cgroup_name, const char *file_name, uint64_t *value),
+ (cgroup_name, file_name, value))
MOCK_SYSTEM(void, g_source_destroy, (GSource *source), (source))
MOCK_SYSTEM(GSource *, g_timeout_source_new_seconds, (guint interval), (interval))
diff --git a/tests/lowmem-system-test.cpp b/tests/lowmem-system-test.cpp
index ad5239a0..d3ede872 100644
--- a/tests/lowmem-system-test.cpp
+++ b/tests/lowmem-system-test.cpp
@@ -32,17 +32,17 @@ extern "C" {
class Subdir {
public:
- Subdir(const char *subdir, const char *dir, uint32_t l)
+ Subdir(const char *subdir, const char *dir, uint64_t l)
: subdir_name{subdir}, full_name{std::string{dir}+"/"+subdir}, limit{l} {}
const char *get_subdir() const { return subdir_name.c_str(); }
const char *get_subdir_full() const { return full_name.c_str(); }
- uint32_t get_limit() const { return limit; }
+ uint64_t get_limit() const { return limit; }
private:
std::string subdir_name;
std::string full_name;
- uint32_t limit;
+ uint64_t limit;
};
typedef std::vector<Subdir> Subdirs;
@@ -63,6 +63,14 @@ void mock_cgroup_read_node_uint32(const char *cgroup_name, const char *file_name
will_return(cgroup_read_node_uint32, value);
}
+void mock_cgroup_read_node_uint64(const char *cgroup_name, const char *file_name, uint64_t value)
+{
+ std::cerr << "mocking cgroup read: " << cgroup_name << " " << file_name << " " << value << std::endl;
+ expect_string(cgroup_read_node_uint64, cgroup_name, cgroup_name);
+ expect_string(cgroup_read_node_uint64, file_name, file_name);
+ will_return(cgroup_read_node_uint64, value);
+}
+
void expect_cgroup_write_node_uint32(const char *cgroup_name, const char *file_name, uint32_t value)
{
std::cerr << "expecting cgroup write: " << cgroup_name << " " << file_name << " " << value << std::endl;
@@ -87,7 +95,7 @@ void mock_search_systemd_cgroup(const char *dir, int32_t root_swappiness, int32_
// mock subdir
will_return(readdir, subdir.get_subdir());
- mock_cgroup_read_node_uint32(subdir.get_subdir_full(), MEMCG_LIMIT_PATH, subdir.get_limit());
+ mock_cgroup_read_node_uint64(subdir.get_subdir_full(), MEMCG_LIMIT_PATH, subdir.get_limit());
if (subdir.get_limit() > 0) {
expect_cgroup_write_node_uint32(subdir.get_subdir_full(), MEMCG_SWAPPINESS_PATH, root_swappiness);
@@ -123,8 +131,9 @@ void simple_system_with_subdirs_test(void **)
lowmem_system_init();
env.trigger_booting_done();
-
+
const int32_t SWAPPINESS_CHANGE_TO = 1000;
+
const Subdirs subdirs_system{
{"my.sweet.dir", MEMORY_SYSTEMD_SYSTEM, 0},
{"my.sweeter.dir", MEMORY_SYSTEMD_SYSTEM, SWAPPINESS_CHANGE_TO},
@@ -134,7 +143,7 @@ void simple_system_with_subdirs_test(void **)
mock_search_systemd_cgroup(MEMORY_SYSTEMD_SYSTEM,
SWAPPINESS_CHANGE_TO, SWAPPINESS_CHANGE_TO*SWAPPINESS_CHANGE_TO,
subdirs_system);
-
+
const Subdirs subdirs_user{
{"my.user.dir", MEMORY_SYSTEMD_USER, 0},
{"my.userer.dir", MEMORY_SYSTEMD_USER, SWAPPINESS_CHANGE_TO},