All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com
Subject: [LTP] [PATCH v2 16/19] controllers: update memcg/functional to use newer cgroup lib
Date: Thu, 28 Apr 2022 13:39:41 -0700	[thread overview]
Message-ID: <9e502f4277c73e17487ac325b8c16384c9526b8b.1651176646.git.luke.nowakowskikrijger@canonical.com> (raw)
In-Reply-To: <cover.1651176645.git.luke.nowakowskikrijger@canonical.com>

Update memcg_lib.sh to uses the newer cgroup lib to cleanup the mounting
and checking of the memory controller.

There are still some tests that make sense for v2 and should be modified
in a future patch, but since most of the tests are testing specific v1
memory controller features lets just skip it for now if v2 is mounted.

Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
---
v2: Use version number 2 instead of v2

 .../memcg/functional/memcg_force_empty.sh     |  2 +-
 .../controllers/memcg/functional/memcg_lib.sh | 54 ++++++++++---------
 2 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh b/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh
index 92ac25938..6252e46bf 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh
@@ -51,7 +51,7 @@ test6()
 {
 	# writing to non-empty top mem cgroup's force_empty
 	# should return failure
-	EXPECT_FAIL echo 1 \> /dev/memcg/memory.force_empty
+	EXPECT_FAIL echo 1 \> "$mount_point/memory.force_empty"
 }
 
 tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
index 1b76b6597..c7d6b42b0 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
@@ -45,20 +45,20 @@ orig_shmmax=
 
 memcg_require_memsw()
 {
-	if ! [ -e /dev/memcg/memory.limit_in_bytes ]; then
-		tst_brk TBROK "/dev/memcg must be mounted before calling memcg_require_memsw"
+	if ! [ -e "$mount_point/memory.limit_in_bytes" ]; then
+		tst_brk TBROK "$mount_point must be mounted before calling memcg_require_memsw"
 	fi
-	if ! [ -e /dev/memcg/memory.memsw.limit_in_bytes ]; then
+	if ! [ -e "$mount_point/memory.memsw.limit_in_bytes" ]; then
 		tst_brk TCONF "mem+swap is not enabled"
 	fi
 }
 
 memcg_require_hierarchy_disabled()
 {
-	if [ ! -e "/dev/memcg/memory.use_hierarchy" ]; then
-		tst_brk TBROK "/dev/memcg must be mounted before calling memcg_require_hierarchy_disabled"
+	if [ ! -e "$mount_point/memory.use_hierarchy" ]; then
+		tst_brk TBROK "$mount_point must be mounted before calling memcg_require_hierarchy_disabled"
 	fi
-	if [ $(cat /dev/memcg/memory.use_hierarchy) -eq 1 ]; then
+	if [ "$(cat "$mount_point/memory.use_hierarchy")" -eq 1 ]; then
 		tst_brk TCONF "Test requires root cgroup memory.use_hierarchy=0"
 	fi
 }
@@ -100,12 +100,19 @@ memcg_adjust_limit_for_kmem()
 
 memcg_setup()
 {
-	if ! is_cgroup_subsystem_available_and_enabled "memory"; then
-		tst_brk TCONF "Either kernel does not support Memory Resource Controller or feature not enabled"
+	cgroup_require "memory"
+	cgroup_version=$(cgroup_get_version "memory")
+
+	# Most of the tests here are testing specific parts of the cgroup v1 memory interface that is
+	# not present for cgroup2, so if it is already mounted on a cgroup v2 hierarchy we should skip
+	# the test.
+	# Some tests still make sense in v2 and should be modified in a future patch
+	if [ "$cgroup_version" = "2" ]; then
+		tst_brk TCONF "memory controller mounted on cgroup v2 hierarchy, skipping test."
 	fi
 
-	ROD mkdir /dev/memcg
-	ROD mount -t cgroup -omemory memcg /dev/memcg
+	mount_point=$(cgroup_get_mountpoint "memory")
+	test_dir=$(cgroup_get_test_path "memory")
 
 	# For kernels older than v5.11 the default value for
 	# memory.use_hierarchy is 0 and some of tests (memcg_stat_test.sh and
@@ -118,15 +125,15 @@ memcg_setup()
 	# Starting with kernel v5.11, the non-hierarchical mode is not
 	# available. See Linux kernel commit bef8620cd8e0 ("mm: memcg:
 	# deprecate the non-hierarchical mode").
-	orig_memory_use_hierarchy=$(cat /dev/memcg/memory.use_hierarchy)
+	orig_memory_use_hierarchy=$(cat "$mount_point/memory.use_hierarchy")
 	if [ -z "$orig_memory_use_hierarchy" ];then
-		tst_res TINFO "cat /dev/memcg/ failed"
+		tst_res TINFO "cat $mount_point failed"
 	elif [ "$orig_memory_use_hierarchy" = "0" ];then
 		orig_memory_use_hierarchy=""
 	else
-		echo 0 > /dev/memcg/memory.use_hierarchy 2>/dev/null
+		echo 0 > "$mount_point/memory.use_hierarchy" 2>/dev/null
 		if [ $? -ne 0 ];then
-			tst_res TINFO "set /dev/memcg/memory.use_hierarchy to 0 failed"
+			tst_res TINFO "set $mount_point/memory.use_hierarchy to 0 failed"
 		fi
 	fi
 
@@ -139,22 +146,19 @@ memcg_cleanup()
 
 	cd $TST_TMPDIR
 	# In order to remove all subgroups, we have to remove them recursively
-	if [ -e /dev/memcg/ltp_$$ ]; then
-		ROD find /dev/memcg/ltp_$$ -depth -type d -delete
+	if [ -e $test_dir ]; then
+		ROD find $test_dir -depth -type d -delete
 	fi
 
 	if [ -n "$orig_memory_use_hierarchy" ];then
-		echo $orig_memory_use_hierarchy > /dev/memcg/memory.use_hierarchy
+		echo $orig_memory_use_hierarchy > $mount_point/memory.use_hierarchy
 		if [ $? -ne 0 ];then
-			tst_res TINFO "restore /dev/memcg/memory.use_hierarchy failed"
+			tst_res TINFO "restore $mount_point/memory.use_hierarchy failed"
 		fi
 		orig_memory_use_hierarchy=""
 	fi
 
-	if [ -e "/dev/memcg" ]; then
-		umount /dev/memcg
-		rmdir /dev/memcg
-	fi
+	cgroup_cleanup
 
 	[ "$MEMCG_SHMMAX" = "1" ] && shmmax_cleanup
 }
@@ -398,8 +402,8 @@ test_limit_in_bytes()
 
 memcg_testfunc()
 {
-	ROD mkdir /dev/memcg/ltp_$$
-	cd /dev/memcg/ltp_$$
+	ROD mkdir $test_dir/ltp_$$
+	cd $test_dir/ltp_$$
 
 	if type ${MEMCG_TESTFUNC}1 > /dev/null 2>&1; then
 		${MEMCG_TESTFUNC}$1 $1 "$2"
@@ -408,7 +412,7 @@ memcg_testfunc()
 	fi
 
 	cd $TST_TMPDIR
-	ROD rmdir /dev/memcg/ltp_$$
+	ROD rmdir $test_dir/ltp_$$
 }
 
 memcg_no_testfunc()
-- 
2.32.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2022-04-28 20:43 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28 20:39 [LTP] [PATCH v4 00/19] Expand Cgroup lib and modify controller tests Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH v3 01/19] API/cgroup: Modify tst_cg_print_config for parsing and consumption Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH 02/19] API/cgroup: Add option for specific pid to tst_cg_opts Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH v2 03/19] API/cgroup: Add cgroup_find_root helper function Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH 04/19] API/cgroup: Add CTRL_NAME_MAX define Luke Nowakowski-Krijger
2022-05-03 14:26   ` Petr Vorel
2022-04-28 20:39 ` [LTP] [PATCH 05/19] tst_test_macros: Add TST_TOSTR macro Luke Nowakowski-Krijger
2022-05-03 14:38   ` Petr Vorel
2022-05-05 13:34   ` Cyril Hrubis
2022-04-28 20:39 ` [LTP] [PATCH v4 06/19] API/cgroup: Implement tst_cg_load_config Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH v3 07/19] API/cgroup: Add more controllers to tst_cgroup Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH 08/19] API/cgroup: refuse to mount blkio when io controller is mounted Luke Nowakowski-Krijger
2022-05-03 15:10   ` Petr Vorel
2022-04-28 20:39 ` [LTP] [PATCH v2 09/19] testcases/lib: Implement tst_cgctl binary Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH 10/19] testcases/lib: Add tst_flag2mask function Luke Nowakowski-Krijger
2022-05-05  8:01   ` Petr Vorel
2022-04-28 20:39 ` [LTP] [PATCH v4 11/19] controllers: Expand cgroup_lib shell library Luke Nowakowski-Krijger
2022-05-05  8:16   ` Petr Vorel
2022-05-05 13:53     ` Cyril Hrubis
2022-05-10 11:19       ` Petr Vorel
2022-05-13 20:15         ` Luke Nowakowski-Krijger
2022-07-21 21:01           ` Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH v2 12/19] controllers: Update cgroup_fj_* to use newer cgroup lib and test lib Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH v2 13/19] controllers: Update memcg_control_test to newer test lib and cgroup lib Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH v2 14/19] controllers: Update memcg/regression/* to new test " Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH v2 15/19] controllers: Update memcg_stress_test to use newer " Luke Nowakowski-Krijger
2022-04-28 20:39 ` Luke Nowakowski-Krijger [this message]
2022-04-28 20:39 ` [LTP] [PATCH v2 17/19] controllers: Update pids.sh " Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH v2 18/19] controllers: update cpuset_regression_test.sh " Luke Nowakowski-Krijger
2022-04-28 20:39 ` [LTP] [PATCH v2 19/19] controllers: update cgroup_regression_test " Luke Nowakowski-Krijger
2022-05-02  9:19 ` [LTP] [PATCH v4 00/19] Expand Cgroup lib and modify controller tests Richard Palethorpe
2022-05-05  7:49 ` Petr Vorel
2022-07-06  6:17   ` Li Wang
2022-07-06  6:25     ` Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9e502f4277c73e17487ac325b8c16384c9526b8b.1651176646.git.luke.nowakowskikrijger@canonical.com \
    --to=luke.nowakowskikrijger@canonical.com \
    --cc=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    --cc=rpalethorpe@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.