From: Chen Ridong <chenridong@huawei.com>
To: <tj@kernel.org>, <lizefan.x@bytedance.com>, <hannes@cmpxchg.org>,
<longman@redhat.com>, <adityakali@google.com>,
<sergeh@kernel.org>, <mkoutny@suse.com>
Cc: <cgroups@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<chenridong@huaweicloud.com>
Subject: [PATCH v1 -next 3/3] cgroup/freezer: Add freeze selftest
Date: Thu, 5 Sep 2024 13:41:30 +0000 [thread overview]
Message-ID: <20240905134130.1176443-4-chenridong@huawei.com> (raw)
In-Reply-To: <20240905134130.1176443-1-chenridong@huawei.com>
Add selftest to test cgroup.freeze and check cgroup.events state.
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
.../testing/selftests/cgroup/test_freezer.sh | 111 ++++++++++++++++++
1 file changed, 111 insertions(+)
create mode 100755 tools/testing/selftests/cgroup/test_freezer.sh
diff --git a/tools/testing/selftests/cgroup/test_freezer.sh b/tools/testing/selftests/cgroup/test_freezer.sh
new file mode 100755
index 000000000000..7178980b1db8
--- /dev/null
+++ b/tools/testing/selftests/cgroup/test_freezer.sh
@@ -0,0 +1,111 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Test freeze hierarchy state
+#
+ROOT_PATH=/sys/fs/cgroup
+skip_test() {
+ echo "$1"
+ echo "Test SKIPPED"
+ exit 4 # ksft_skip
+}
+
+write_freeze() {
+ path=$1
+ value=$2
+ echo $value > $ROOT_PATH/$path/cgroup.freeze
+}
+
+get_event_frozen()
+{
+ path=$1
+ return $(cat $ROOT_PATH/$path/cgroup.events | grep frozen | awk '{print $2}')
+}
+
+# the test subtree:
+# A
+# / \
+# B C
+# / | \ \
+# D E F G
+# /
+# H
+
+PATH_MATRIX=(
+ 'A'
+ 'A/B'
+ 'A/C'
+ 'A/B/D'
+ 'A/B/E'
+ 'A/B/F'
+ 'A/C/G'
+ 'A/B/D/H'
+)
+CGRP_CNT=${#PATH_MATRIX[@]}
+
+# Interface value to set/check
+ITF_MATRIX=(
+ #value write to freeze expect event value
+ #A B C D E F G H | A B C D E F G H
+ '1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1'
+ '1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1'
+ '1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1'
+ '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
+
+ '1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1'
+ '1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1'
+ '1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1'
+ '1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1'
+
+ '0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1'
+ '0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1'
+ '0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1'
+ '0 0 1 1 0 0 0 0 0 0 1 1 0 0 1 1'
+ '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
+)
+
+prepare()
+{
+ for i in "${PATH_MATRIX[@]}" ; do
+ path="$ROOT_PATH/$i"
+ mkdir $path
+ done
+}
+
+do_clean()
+{
+ for(( i=$CGRP_CNT-1; i>=0; i-- ));do
+ path="/sys/fs/cgroup/${PATH_MATRIX[i]}"
+ rmdir $path
+ done
+}
+
+run_test()
+{
+ prepare
+ cgrp_cnt="${PATH_MATRIX[@]}"
+ for i in "${ITF_MATRIX[@]}" ; do
+ args=($i)
+ #write freeze
+ for(( j=0; j<$CGRP_CNT; j++ ));do
+ write_freeze "${PATH_MATRIX[j]}" ${args[j]}
+ done
+ #event frozen should eq expected value
+ for(( j=0; j<$CGRP_CNT; j++ ));do
+ get_event_frozen "${PATH_MATRIX[j]}"
+ if [ $? -ne ${args[j + $CGRP_CNT]} ];then
+ echo "failed: $i"
+ do_clean
+ exit 1
+ fi
+ done
+ done
+ do_clean
+}
+
+start_time=$(date +%s%N)
+run_test
+end_time=$(date +%s%N)
+elapsed_time=$((end_time - start_time))
+echo "Test PASSED, elapsed_time:$elapsed_time (ns)"
+exit 0
--
2.34.1
next prev parent reply other threads:[~2024-09-05 13:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 13:41 [PATCH v1 -next 0/3] Some optimizations about freezer Chen Ridong
2024-09-05 13:41 ` [PATCH v1 -next 1/3] cgroup/freezer: Reduce redundant traversal for cgroup_freeze Chen Ridong
2024-09-09 19:01 ` Michal Koutný
2024-09-10 2:39 ` Chen Ridong
2024-09-05 13:41 ` [PATCH v1 -next 2/3] cgroup/freezer: Reduce redundant propagation for cgroup_propagate_frozen Chen Ridong
2024-09-09 19:02 ` Michal Koutný
2024-09-10 3:08 ` Chen Ridong
2024-09-10 11:33 ` Michal Koutný
2024-09-05 13:41 ` Chen Ridong [this message]
2024-09-09 19:03 ` [PATCH v1 -next 3/3] cgroup/freezer: Add freeze selftest Michal Koutný
2024-09-10 3:09 ` Chen Ridong
2024-09-09 19:04 ` [PATCH v1 -next 0/3] Some optimizations about freezer Michal Koutný
2024-09-10 3:16 ` Chen Ridong
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=20240905134130.1176443-4-chenridong@huawei.com \
--to=chenridong@huawei.com \
--cc=adityakali@google.com \
--cc=cgroups@vger.kernel.org \
--cc=chenridong@huaweicloud.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=longman@redhat.com \
--cc=mkoutny@suse.com \
--cc=sergeh@kernel.org \
--cc=tj@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®