Skip to contentSkip to conversation

Add cgroup core selftests

PATCH In review Claudio 4 participants 4 messages Jul 18, 2018 – Jul 24, 2018

Subsystems (2)
lore
Share & tools
lore

Claudio

author
#0 lore raw

PATCH 1/1 Add cgroup core selftests

This commit adds tests for some of the core functionalities of cgroups v2.

The commit adds tests for some core principles of croup V2 API:

- test_cgcore_internal_process_constraint

Tests internal process constraint.
You can't add a pid to a domain parent if a controller is enabled.

- test_cgcore_top_down_constraint_enable

Tests that you can't enable a controller on a child if it's not enabled on the parent.

- test_cgcore_top_down_constraint_disable

Tests that you can't disable a controller on a parent if it's enabled in a child.

- test_cgcore_no_internal_process_constraint_on_threads

Tests that there's no internal process constrain on threaded cgroups. You can add threads/processes on a parent with a controller enabled.

- test_cgcore_parent_becomes_threaded

Tests that when a child becomes threaded the parent type becomes domain threaded.

- test_cgcore_invalid_domain

In a situation like:

A (domain threaded) - B (threaded) - C (domain)

it tests that C can't be used until it is turned into a threaded cgroup. The "cgroup.type" file will report "domain (invalid)" in these cases. Operations which fail due to invalid topology use EOPNOTSUPP as the errno.

- test_cgcore_populated

In a situation like:

A(0) - B(0) - C(1)

         \ D(0)

It tests that A, B and C's "populated" fields would be 1 while D's 0. It tests that after the one process in C is moved to root, A,B and C's "populated" fields would flip to "0" and file modified events will be generated on the "cgroup.events" files of both cgroups.

---
 tools/testing/selftests/cgroup/Makefile      |   2 +
 tools/testing/selftests/cgroup/cgroup_util.c |   8 +
 tools/testing/selftests/cgroup/cgroup_util.h |   1 +
 tools/testing/selftests/cgroup/test_core.c   | 395 +++++++++++++++++++++++++++
 4 files changed, 406 insertions(+)
 create mode 100644 tools/testing/selftests/cgroup/test_core.c
tools/testing/selftests/cgroup/Makefile +2 -0
index f7a31392eb2f..23fbaa4a9630 100644
@@ -4,7 +4,9 @@ CFLAGS += -Wall
 all:
 
 TEST_GEN_PROGS = test_memcontrol
+TEST_GEN_PROGS += test_core
 
 include ../lib.mk
 
 $(OUTPUT)/test_memcontrol: cgroup_util.c
+$(OUTPUT)/test_core: cgroup_util.c
tools/testing/selftests/cgroup/cgroup_util.c +8 -0
index 1e9e3c470561..1c5d2b2a583b 100644
@@ -229,6 +229,14 @@ int cg_destroy(const char *cgroup)
 	return ret;
 }
 
+int cg_enter_current(const char *cgroup)
+{
+	char pidbuf[64];
+
+	snprintf(pidbuf, sizeof(pidbuf), "%d", getpid());
+	return cg_write(cgroup, "cgroup.procs", pidbuf);
+}
+
 int cg_run(const char *cgroup,
 	   int (*fn)(const char *cgroup, void *arg),
 	   void *arg)
tools/testing/selftests/cgroup/cgroup_util.h +1 -0
index fe82a297d4e0..1ff6f9f1abdc 100644
@@ -32,6 +32,7 @@ extern int cg_write(const char *cgroup, const char *control, char *buf);
 extern int cg_run(const char *cgroup,
 		  int (*fn)(const char *cgroup, void *arg),
 		  void *arg);
+extern int cg_enter_current(const char *cgroup);
 extern int cg_run_nowait(const char *cgroup,
 			 int (*fn)(const char *cgroup, void *arg),
 			 void *arg);
tools/testing/selftests/cgroup/test_core.c new file +395 -0

395 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Claudio

This commit adds tests for some of the core functionalities of cgroups v2.

The commit adds tests for some core principles of croup V2 API:

Thanks, Claudio.

Signature · 1 line
tejun
Reviewed-by on v1 1/1
#2 lore raw
In reply to Claudio
Quoted 52 lines · Claudio

This commit adds tests for some of the core functionalities of cgroups v2.

The commit adds tests for some core principles of croup V2 API:

- test_cgcore_internal_process_constraint

Tests internal process constraint.
You can't add a pid to a domain parent if a controller is enabled.

- test_cgcore_top_down_constraint_enable

Tests that you can't enable a controller on a child if it's not enabled on the parent.

- test_cgcore_top_down_constraint_disable

Tests that you can't disable a controller on a parent if it's enabled in a child.

- test_cgcore_no_internal_process_constraint_on_threads

Tests that there's no internal process constrain on threaded cgroups. You can add threads/processes on a parent with a controller enabled.

- test_cgcore_parent_becomes_threaded

Tests that when a child becomes threaded the parent type becomes domain threaded.

- test_cgcore_invalid_domain

In a situation like:

A (domain threaded) - B (threaded) - C (domain)

it tests that C can't be used until it is turned into a threaded cgroup. The "cgroup.type" file will report "domain (invalid)" in these cases. Operations which fail due to invalid topology use EOPNOTSUPP as the errno.

- test_cgcore_populated

In a situation like:

A(0) - B(0) - C(1)

         \ D(0)

It tests that A, B and C's "populated" fields would be 1 while D's 0. It tests that after the one process in C is moved to root, A,B and C's "populated" fields would flip to "0" and file modified events will be generated on the "cgroup.events" files of both cgroups.

Quoted 5 lines

Looks good to me!

Thank you!

maintainer
#3 lore raw
Quoted 59 lines · Roman Gushchin
Quoted 52 lines · Claudio

This commit adds tests for some of the core functionalities of cgroups v2.

The commit adds tests for some core principles of croup V2 API:

- test_cgcore_internal_process_constraint

Tests internal process constraint.
You can't add a pid to a domain parent if a controller is enabled.

- test_cgcore_top_down_constraint_enable

Tests that you can't enable a controller on a child if it's not enabled on the parent.

- test_cgcore_top_down_constraint_disable

Tests that you can't disable a controller on a parent if it's enabled in a child.

- test_cgcore_no_internal_process_constraint_on_threads

Tests that there's no internal process constrain on threaded cgroups. You can add threads/processes on a parent with a controller enabled.

- test_cgcore_parent_becomes_threaded

Tests that when a child becomes threaded the parent type becomes domain threaded.

- test_cgcore_invalid_domain

In a situation like:

A (domain threaded) - B (threaded) - C (domain)

it tests that C can't be used until it is turned into a threaded cgroup. The "cgroup.type" file will report "domain (invalid)" in these cases. Operations which fail due to invalid topology use EOPNOTSUPP as the errno.

- test_cgcore_populated

In a situation like:

A(0) - B(0) - C(1)

         \ D(0)

It tests that A, B and C's "populated" fields would be 1 while D's 0. It tests that after the one process in C is moved to root, A,B and C's "populated" fields would flip to "0" and file modified events will be generated on the "cgroup.events" files of both cgroups.

Quoted 5 lines
Quoted 6 lines

Looks good to me!

Thank you!

Thanks for the new test. I will queue this up for 4.19-rc1

-- Shuah