From: Edward Liaw via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: kernel-team@android.com
Subject: [LTP] [PATCH v1] controllers.memcg_regression: add trap to clean up directories
Date: Fri, 1 Jul 2022 21:37:49 +0000 [thread overview]
Message-ID: <20220701213749.3744031-1-edliaw@google.com> (raw)
The memcg_regression test creates a memcg/ directory that can be left
behind if the test exits unexpectedly. Use a trap to clean up the
directories on exit.
Signed-off-by: Edward Liaw <edliaw@google.com>
---
.../memcg/regression/memcg_regression_test.sh | 20 +++++++++++--------
.../memcg/regression/memcg_test_4.sh | 11 ++++++----
2 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh b/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh
index c91a4069e..2467ae0e6 100755
--- a/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh
+++ b/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh
@@ -54,6 +54,15 @@ nr_null=0
nr_warning=0
nr_lockdep=0
+clean_up()
+{
+ # remove the cgroup
+ rmdir memcg/0 2> /dev/null
+ # unmount cgroup if still mounted
+ umount memcg/
+ rmdir memcg/
+}
+
# check_kernel_bug - check if some kind of kernel bug happened
check_kernel_bug()
{
@@ -102,12 +111,12 @@ check_kernel_bug()
#---------------------------------------------------------------------------
test_1()
{
- mkdir memcg/0/
+ mkdir memcg/0
echo 0 > memcg/0/memory.limit_in_bytes
./memcg_test_1
- rmdir memcg/0/
+ rmdir memcg/0
check_kernel_bug
if [ $? -eq 1 ]; then
@@ -211,14 +220,12 @@ test_4()
killall -9 memcg_test_4 2> /dev/null
killall -9 memcg_test_4.sh 2> /dev/null
- # if test_4.sh gets killed, it won't clean cgroup it created
- rmdir memcg/0 2> /dev/null
-
swapon -a
}
# main
failed=0
+trap clean_up EXIT
mkdir memcg/
for cur in $(seq 1 $TST_TOTAL); do
@@ -236,7 +243,4 @@ for cur in $(seq 1 $TST_TOTAL); do
umount memcg/
done
-rmdir memcg/
-
exit $failed
-
diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh b/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh
index 620031366..d002601f1 100755
--- a/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh
+++ b/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh
@@ -22,6 +22,13 @@
## ##
################################################################################
+clean_up()
+{
+ # remove the cgroup when exiting
+ rmdir memcg/0
+}
+
+trap clean_up EXIT
# attach current task to memcg/0/
mkdir memcg/0
echo $$ > memcg/0/tasks
@@ -42,7 +49,3 @@ swapoff -a
sleep 1
echo $pid > memcg/tasks 2> /dev/null
echo $$ > memcg/tasks 2> /dev/null
-
-# now remove the cgroup
-rmdir memcg/0
-
--
2.37.0.rc0.161.g10f37bed90-goog
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2022-07-01 21:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-01 21:37 Edward Liaw via ltp [this message]
2022-07-06 6:00 ` [LTP] [PATCH v1] controllers.memcg_regression: add trap to clean up directories Li Wang
2022-07-06 18:42 ` Luke Nowakowski-Krijger
2022-08-09 6:00 ` Petr Vorel
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=20220701213749.3744031-1-edliaw@google.com \
--to=ltp@lists.linux.it \
--cc=edliaw@google.com \
--cc=kernel-team@android.com \
/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