Skip to content

Commit 0925275

Browse files
Werkovhtejun
authored andcommitted
selftests: cgroup_util: Add helpers for testing named v1 hierarchies
Non-functional change, the control variable will be wired in a separate commit. Signed-off-by: Michal Koutný <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 38b9342 commit 0925275

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

tools/testing/selftests/cgroup/lib/cgroup_util.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "cgroup_util.h"
2020
#include "../../clone3/clone3_selftests.h"
2121

22+
bool cg_test_v1_named;
23+
2224
/* Returns read len on success, or -errno on failure. */
2325
ssize_t read_text(const char *path, char *buf, size_t max_len)
2426
{
@@ -361,7 +363,7 @@ int cg_enter_current(const char *cgroup)
361363

362364
int cg_enter_current_thread(const char *cgroup)
363365
{
364-
return cg_write(cgroup, "cgroup.threads", "0");
366+
return cg_write(cgroup, CG_THREADS_FILE, "0");
365367
}
366368

367369
int cg_run(const char *cgroup,

tools/testing/selftests/cgroup/lib/include/cgroup_util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
#define TEST_UID 65534 /* usually nobody, any !root is fine */
1515

16+
#define CG_THREADS_FILE (!cg_test_v1_named ? "cgroup.threads" : "tasks")
17+
#define CG_NAMED_NAME "selftest"
18+
#define CG_PATH_FORMAT (!cg_test_v1_named ? "0::%s" : (":name=" CG_NAMED_NAME ":%s"))
19+
1620
/*
1721
* Checks if two given values differ by less than err% of their sum.
1822
*/
@@ -65,3 +69,4 @@ extern int dirfd_open_opath(const char *dir);
6569
extern int cg_prepare_for_wait(const char *cgroup);
6670
extern int memcg_prepare_for_wait(const char *cgroup);
6771
extern int cg_wait_for(int fd);
72+
extern bool cg_test_v1_named;

tools/testing/selftests/cgroup/test_core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static int test_cgcore_proc_migration(const char *root)
573573
}
574574

575575
cg_enter_current(dst);
576-
if (cg_read_lc(dst, "cgroup.threads") != n_threads + 1)
576+
if (cg_read_lc(dst, CG_THREADS_FILE) != n_threads + 1)
577577
goto cleanup;
578578

579579
ret = KSFT_PASS;
@@ -605,7 +605,7 @@ static void *migrating_thread_fn(void *arg)
605605
char lines[3][PATH_MAX];
606606

607607
for (g = 1; g < 3; ++g)
608-
snprintf(lines[g], sizeof(lines[g]), "0::%s", grps[g] + strlen(grps[0]));
608+
snprintf(lines[g], sizeof(lines[g]), CG_PATH_FORMAT, grps[g] + strlen(grps[0]));
609609

610610
for (i = 0; i < n_iterations; ++i) {
611611
cg_enter_current_thread(grps[(i % 2) + 1]);
@@ -659,7 +659,7 @@ static int test_cgcore_thread_migration(const char *root)
659659
if (retval)
660660
goto cleanup;
661661

662-
snprintf(line, sizeof(line), "0::%s", grps[1] + strlen(grps[0]));
662+
snprintf(line, sizeof(line), CG_PATH_FORMAT, grps[1] + strlen(grps[0]));
663663
if (proc_read_strstr(0, 1, "cgroup", line))
664664
goto cleanup;
665665

0 commit comments

Comments
 (0)