All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 4/4] ksm: cleanup work and make use of .save_restore
Date: Tue,  8 Mar 2022 15:37:09 +0800	[thread overview]
Message-ID: <20220308073709.4125677-5-liwang@redhat.com> (raw)
In-Reply-To: <20220308073709.4125677-1-liwang@redhat.com>

Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/kernel/mem/ksm/ksm01.c      | 38 ++++++++++-----------------
 testcases/kernel/mem/ksm/ksm02.c      | 25 +++++-------------
 testcases/kernel/mem/ksm/ksm03.c      | 25 +++++-------------
 testcases/kernel/mem/ksm/ksm04.c      | 24 +++++------------
 testcases/kernel/mem/ksm/ksm05.c      | 29 ++++++--------------
 testcases/kernel/mem/ksm/ksm_common.h |  2 --
 6 files changed, 43 insertions(+), 100 deletions(-)

diff --git a/testcases/kernel/mem/ksm/ksm01.c b/testcases/kernel/mem/ksm/ksm01.c
index 0a81e2016..301c4d3c2 100644
--- a/testcases/kernel/mem/ksm/ksm01.c
+++ b/testcases/kernel/mem/ksm/ksm01.c
@@ -66,30 +66,7 @@ static void verify_ksm(void)
 
 static void setup(void)
 {
-	if (access(PATH_KSM, F_OK) == -1)
-		tst_brk(TCONF, "KSM configuration is not enabled");
-
 	parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
-
-	/*
-	 * kernel commit 90bd6fd introduced a new KSM sysfs knob
-	 * /sys/kernel/mm/ksm/merge_across_nodes, setting it to '0'
-	 * will prevent KSM pages being merged across numa nodes,
-	 * which will cause the case fail, so we need to make sure
-	 * it is enabled before testing.
-	 */
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
-		SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
-				"%d", &merge_across_nodes);
-		SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
-	}
-}
-
-static void cleanup(void)
-{
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
-		FILE_PRINTF(PATH_KSM "merge_across_nodes",
-				 "%d", merge_across_nodes);
 }
 
 static struct tst_test test = {
@@ -102,11 +79,24 @@ static struct tst_test test = {
 		{}
 	},
 	.setup = setup,
-	.cleanup = cleanup,
 	.save_restore = (const struct tst_path_val const[]) {
+		{"!/sys/kernel/mm/ksm/run", NULL},
+		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
 		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+		/*
+		 * kernel commit 90bd6fd introduced a new KSM sysfs knob
+		 * /sys/kernel/mm/ksm/merge_across_nodes, setting it to '0'
+		 * will prevent KSM pages being merged across numa nodes,
+		 * which will cause the case fail, so we need to make sure
+		 * it is enabled before testing.
+		 */
+		{"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
 		NULL,
 	},
+	.needs_kconfigs = (const char *const[]){
+		"CONFIG_KSM=y",
+		NULL
+	},
 	.test_all = verify_ksm,
 	.min_kver = "2.6.32",
 };
diff --git a/testcases/kernel/mem/ksm/ksm02.c b/testcases/kernel/mem/ksm/ksm02.c
index 6ba6ee868..6ad7bcadb 100644
--- a/testcases/kernel/mem/ksm/ksm02.c
+++ b/testcases/kernel/mem/ksm/ksm02.c
@@ -82,26 +82,9 @@ static void verify_ksm(void)
 	SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid());
 }
 
-static void cleanup(void)
-{
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
-		FILE_PRINTF(PATH_KSM "merge_across_nodes",
-				 "%d", merge_across_nodes);
-	}
-}
-
 static void setup(void)
 {
-	if (access(PATH_KSM, F_OK) == -1)
-		tst_brk(TCONF, "KSM configuration is not enabled");
-
 	parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
-
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
-		SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
-				"%d", &merge_across_nodes);
-		SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
-	}
 }
 
 static struct tst_test test = {
@@ -114,11 +97,17 @@ static struct tst_test test = {
 		{}
 	},
 	.setup = setup,
-	.cleanup = cleanup,
 	.save_restore = (const struct tst_path_val const[]) {
+		{"!/sys/kernel/mm/ksm/run", NULL},
+		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
 		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+		{"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
 		NULL,
 	},
+	.needs_kconfigs = (const char *const[]){
+		"CONFIG_KSM=y",
+		NULL
+	},
 	.test_all = verify_ksm,
 	.min_kver = "2.6.32",
 	.needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
diff --git a/testcases/kernel/mem/ksm/ksm03.c b/testcases/kernel/mem/ksm/ksm03.c
index 71d2d8bd9..94223e332 100644
--- a/testcases/kernel/mem/ksm/ksm03.c
+++ b/testcases/kernel/mem/ksm/ksm03.c
@@ -66,29 +66,12 @@ static void verify_ksm(void)
 
 static void setup(void)
 {
-	if (access(PATH_KSM, F_OK) == -1)
-		tst_brk(TCONF, "KSM configuration is not enabled");
-
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
-		SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
-				"%d", &merge_across_nodes);
-		SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
-	}
-
 	parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
 
 	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
 	SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
 }
 
-static void cleanup(void)
-{
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
-		FILE_PRINTF(PATH_KSM "merge_across_nodes",
-				 "%d", merge_across_nodes);
-	}
-}
-
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
@@ -99,11 +82,17 @@ static struct tst_test test = {
 		{}
 	},
 	.setup = setup,
-	.cleanup = cleanup,
 	.save_restore = (const struct tst_path_val const[]) {
+		{"!/sys/kernel/mm/ksm/run", NULL},
+		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
 		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+		{"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
 		NULL,
 	},
+	.needs_kconfigs = (const char *const[]){
+		"CONFIG_KSM=y",
+		NULL
+	},
 	.test_all = verify_ksm,
 	.min_kver = "2.6.32",
 	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
diff --git a/testcases/kernel/mem/ksm/ksm04.c b/testcases/kernel/mem/ksm/ksm04.c
index 8429f4843..3e8a77bec 100644
--- a/testcases/kernel/mem/ksm/ksm04.c
+++ b/testcases/kernel/mem/ksm/ksm04.c
@@ -82,24 +82,8 @@ static void verify_ksm(void)
 	create_same_memory(size, num, unit);
 }
 
-static void cleanup(void)
-{
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
-		FILE_PRINTF(PATH_KSM "merge_across_nodes",
-				 "%d", merge_across_nodes);
-}
-
 static void setup(void)
 {
-	if (access(PATH_KSM, F_OK) == -1)
-		tst_brk(TCONF, "KSM configuration is not enabled");
-
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
-		SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
-				"%d", &merge_across_nodes);
-		SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
-	}
-
 	parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
 
 	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
@@ -115,11 +99,17 @@ static struct tst_test test = {
 		{}
 	},
 	.setup = setup,
-	.cleanup = cleanup,
 	.save_restore = (const struct tst_path_val const[]) {
+		{"!/sys/kernel/mm/ksm/run", NULL},
+		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
 		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+		{"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
 		NULL,
 	},
+	.needs_kconfigs = (const char *const[]){
+		"CONFIG_KSM=y",
+		NULL
+	},
 	.test_all = verify_ksm,
 	.min_kver = "2.6.32",
 	.needs_cgroup_ctrls = (const char *const []){
diff --git a/testcases/kernel/mem/ksm/ksm05.c b/testcases/kernel/mem/ksm/ksm05.c
index 380bb0202..33721d388 100644
--- a/testcases/kernel/mem/ksm/ksm05.c
+++ b/testcases/kernel/mem/ksm/ksm05.c
@@ -83,32 +83,19 @@ static void sighandler(int sig)
 	_exit((sig == SIGSEGV) ? 0 : sig);
 }
 
-static void setup(void)
-{
-	if (access(PATH_KSM, F_OK) == -1)
-		tst_brk(TCONF, "KSM configuration is not enabled");
-
-	/* save original /sys/kernel/mm/ksm/run value */
-	SAFE_FILE_SCANF(PATH_KSM "run", "%d", &ksm_run_orig);
-
-	/* echo 1 > /sys/kernel/mm/ksm/run */
-	SAFE_FILE_PRINTF(PATH_KSM "run", "1");
-}
-
-static void cleanup(void)
-{
-	/* restore /sys/kernel/mm/ksm/run value */
-	if (ksm_run_orig > 0)
-		FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig);
-}
-
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
-	.setup = setup,
-	.cleanup = cleanup,
 	.test_all = test_ksm,
 	.min_kver = "2.6.32",
+	.save_restore = (const struct tst_path_val const[]) {
+		{"!/sys/kernel/mm/ksm/run", "1"},
+		NULL,
+	},
+	.needs_kconfigs = (const char *const[]){
+		"CONFIG_KSM=y",
+		NULL
+	},
 };
 
 #else
diff --git a/testcases/kernel/mem/ksm/ksm_common.h b/testcases/kernel/mem/ksm/ksm_common.h
index e6d5387c8..56faf01e4 100644
--- a/testcases/kernel/mem/ksm/ksm_common.h
+++ b/testcases/kernel/mem/ksm/ksm_common.h
@@ -9,8 +9,6 @@
 
 #include "tst_test.h"
 
-int merge_across_nodes;
-
 int size = 128, num = 3, unit = 1;
 char *opt_sizestr, *opt_numstr, *opt_unitstr;
 
-- 
2.31.1


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

  parent reply	other threads:[~2022-03-08  7:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08  7:37 [LTP] [PATCH 0/4] enhance .save_restore to support set value Li Wang
2022-03-08  7:37 ` [LTP] [PATCH 1/4] lib: move struct tst_sys_conf to internal Li Wang
2022-03-08 12:25   ` Cyril Hrubis
2022-03-08  7:37 ` [LTP] [PATCH 2/4] lib: enhance .save_restore to support set expected value Li Wang
2022-03-08 13:02   ` Cyril Hrubis
2022-03-09  2:27     ` Li Wang
2022-03-08  7:37 ` [LTP] [PATCH 3/4] testcase: switch to the new .save_restore Li Wang
2022-03-08 13:05   ` Cyril Hrubis
2022-03-08  7:37 ` Li Wang [this message]
2022-03-08 13:20   ` [LTP] [PATCH 4/4] ksm: cleanup work and make use of .save_restore Cyril Hrubis
2022-03-09  3:04 ` [LTP] [PATCH v2 1/3] lib: move struct tst_sys_conf to internal Li Wang
2022-03-09  3:04   ` [LTP] [PATCH v2 2/3] lib: enhance .save_restore to support set expected value Li Wang
2022-03-09 10:00     ` Cyril Hrubis
2022-03-10  1:26       ` Li Wang
2022-03-10  7:43     ` xuyang2018.jy
2022-03-10  7:53       ` Li Wang
2022-03-10  8:01         ` xuyang2018.jy
2022-03-09  3:04   ` [LTP] [PATCH v2 3/3] ksm: cleanup work and make use of .save_restore 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=20220308073709.4125677-5-liwang@redhat.com \
    --to=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /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.