enhance .save_restore to support set value
cover enhance .save_restore to support set value
This makes .save_restore to support set expected value after saving the knob's original to be possible, the main change is convert the NULL-terminated string to struct tst_path_val.
And the rest part is preparing and cleanup work.
Li Wang (4):
lib: move struct tst_sys_conf to internal
lib: enhance .save_restore to support set expected value
testcase: switch to the new .save_restore
ksm: cleanup work and make use of .save_restore
doc/c-test-api.txt | 16 +++---- include/tst_sys_conf.h | 8 ++-- include/tst_test.h | 2 +- lib/newlib_tests/test19.c | 14 +++---- lib/newlib_tests/test20.c | 10 ++--- lib/tst_sys_conf.c | 19 +++++++++ lib/tst_test.c | 9 ++-- testcases/cve/icmp_rate_limit01.c | 4 +- testcases/kernel/containers/userns/userns08.c | 4 +- testcases/kernel/mem/ksm/ksm01.c | 42 +++++++------------ testcases/kernel/mem/ksm/ksm02.c | 29 ++++--------- testcases/kernel/mem/ksm/ksm03.c | 29 ++++--------- testcases/kernel/mem/ksm/ksm04.c | 28 ++++--------- testcases/kernel/mem/ksm/ksm05.c | 29 ++++--------- testcases/kernel/mem/ksm/ksm06.c | 10 ++--- testcases/kernel/mem/ksm/ksm_common.h | 2 - testcases/kernel/syscalls/add_key/add_key05.c | 16 ++----- testcases/kernel/syscalls/bind/bind06.c | 4 +- testcases/kernel/syscalls/madvise/madvise08.c | 4 +- .../syscalls/migrate_pages/migrate_pages02.c | 5 +-- testcases/kernel/syscalls/sendto/sendto03.c | 4 +- .../kernel/syscalls/setsockopt/setsockopt05.c | 4 +- .../kernel/syscalls/setsockopt/setsockopt06.c | 4 +- .../kernel/syscalls/setsockopt/setsockopt07.c | 4 +- .../kernel/syscalls/setsockopt/setsockopt08.c | 4 +- .../kernel/syscalls/setsockopt/setsockopt09.c | 4 +- 26 files changed, 130 insertions(+), 178 deletions(-)
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/4 lib: move struct tst_sys_conf to internal
As it only used in tst_sys_conf library interanlly, there is unnecessary to put in header file.
--- include/tst_sys_conf.h | 6 ------ lib/tst_sys_conf.c | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-)
include/tst_sys_conf.h +0 -6
@@ -5,12 +5,6 @@#ifndef TST_SYS_CONF_H__ #define TST_SYS_CONF_H__ -struct tst_sys_conf { -char path[PATH_MAX ]; -char value[PATH_MAX ]; -struct tst_sys_conf *next; -}; -int tst_sys_conf_save_str (const char *path,const char *value);int tst_sys_conf_save (const char *path);void tst_sys_conf_restore (int verbose);
lib/tst_sys_conf.c +6 -0
@@ -12,6 +12,12 @@#include "tst_test.h" #include "tst_sys_conf.h" +struct tst_sys_conf { +char path[PATH_MAX ]; +char value[PATH_MAX ]; +struct tst_sys_conf *next; +}; +static struct tst_sys_conf *save_restore_data;void tst_sys_conf_dump (void )
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/4] lib: move struct tst_sys_conf to internal
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/4 lib: enhance .save_restore to support set expected value
In reply to Li WangThis extends that .save_restore support set new expected value after saving the knob's original, which also avoids additionally checking before using the file at other places.
And, export function tst_sys_conf_set() can be singly used for setting new value of knob in the whole LTP.
--- doc/c-test-api.txt | 16 +++++++++------- include/tst_sys_conf.h | 6 ++++++ include/tst_test.h | 2 +- lib/tst_sys_conf.c | 13 +++++++++++++ lib/tst_test.c | 9 +++++---- 5 files changed, 34 insertions(+), 12 deletions(-)
doc/c-test-api.txt +9 -7
@@ -1559,12 +1559,14 @@ itself is not available on the system. 1.27 Saving & restoring /proc|sys values ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -LTP library can be instructed to save and restore value of specified +LTP library can be instructed to save and restore the value of specified (/proc|sys) files. This is achieved by initialized tst_test struct -field 'save_restore'. It is a 'NULL' terminated array of strings where -each string represents a file, whose value is saved at the beginning -and restored at the end of the test. Only first line of a specified -file is saved and restored. +field 'save_restore'. It is a NULL-terminated array of struct +'tst_path_val' where each tst_path_val.path represents a file, whose +value is saved at the beginning and restored at the end of the test. +If pass a value to tst_path_val.value that will be set to the knob +correspondingly, NULL means do nothing else but save the original value. +Only the first line of a specified file is saved and restored. Pathnames can be optionally prefixed to specify how strictly (during 'store') are handled errors:
@@ -1578,8 +1580,8 @@ Pathnames can be optionally prefixed to specify how strictly (during [source,c] ------------------------------------------------------------------------------- -static const char *save_restore[] = { - "/proc/sys/kernel/core_pattern", +static const struct tst_path_val save_restore[] = { + {"/proc/sys/kernel/core_pattern", NULL}, NULL, };
include/tst_sys_conf.h +6 -0
@@ -5,8 +5,14 @@#ifndef TST_SYS_CONF_H__ #define TST_SYS_CONF_H__ +struct tst_path_val { +const char *path; +const char *val; +}; +int tst_sys_conf_save_str (const char *path,const char *value);int tst_sys_conf_save (const char *path); +void tst_sys_conf_set (const char *path,const char *value);void tst_sys_conf_restore (int verbose);void tst_sys_conf_dump (void );
include/tst_test.h +1 -1
@@ -259,7 +259,7 @@ struct tst_test {* NULL terminated array of (/proc, /sys) files to save * before setup and restore after cleanup */ -const char *const *save_restore; +const struct tst_path_val const *save_restore;/* * NULL terminated array of kernel config options required for the
lib/tst_sys_conf.c +13 -0
@@ -96,6 +96,19 @@ int tst_sys_conf_save(const char *path)return tst_sys_conf_save_str (path, line); } +void tst_sys_conf_set (const char *path,const char *value) +{ +char flag = path[0 ]; +if (flag =='?' || flag =='!' ) + path++; + +if (access (path,F_OK ) !=0 ) +tst_brk (TBROK |TERRNO ," The path %s is not exist" , path); + +if (value) +SAFE_FILE_PRINTF (path,"%s" , value); +} +void tst_sys_conf_restore (int verbose) {struct tst_sys_conf *i;
lib/tst_test.c +5 -4
@@ -1105,11 +1105,12 @@ static void do_setup(int argc, char *argv[])tst_tmpdir ();if (tst_test->save_restore) { -const char *const *name = tst_test->save_restore; +const struct tst_path_val const *pvl = tst_test->save_restore; -while (*name) { -tst_sys_conf_save (*name); - name++; +while (pvl->path) { +if (!tst_sys_conf_save (pvl->path)) +tst_sys_conf_set (pvl->path, pvl->val); + pvl++; } }
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/4] lib: enhance .save_restore to support set expected value
Hi!
Quoted 24 lines
This extends that .save_restore support set new expected value after saving the knob's original, which also avoids additionally checking before using the file at other places.
And, export function
tst_sys_conf_set()can be singly used for setting new value of knob in the whole LTP.Reported-by Bruno Goncalves <[email protected]>Suggested-by Cyril Hrubis <[email protected]>Signed-off-by Li Wang <[email protected]>Cc Jan Stancek <[email protected]>--- doc/c-test-api.txt | 16 +++++++++------- include/tst_sys_conf.h | 6 ++++++ include/tst_test.h | 2 +- lib/tst_sys_conf.c | 13 +++++++++++++ lib/tst_test.c | 9 +++++---- 5 files changed, 34 insertions(+), 12 deletions(-)doc/c-test-api.txt +0
-0
doc/c-test-api.txt itself is not available on the system. · line 1562
Quoted 5 lines
doc/c-test-api.txt +1
-1@@ -1559,12 +1559,14 @@ itself is not available on the system. 1.27 Saving & restoring /proc|sys values ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -LTP library can be instructed to save and restore value of specified +LTP library can be instructed to save and restore the value of specified
^
This shouldn't be here as we do not talk about specific proc/sys files but about any proc/sys file
doc/c-test-api.txt itself is not available on the system. · line 1568
Quoted 10 lines
doc/c-test-api.txt +5
-4(/proc|sys) files. This is achieved by initialized tst_test struct -field 'save_restore'. It is a 'NULL' terminated array of strings where -each string represents a file, whose value is saved at the beginning -and restored at the end of the test. Only first line of a specified -file is saved and restored. +field 'save_restore'. It is a NULL-terminated array of struct +'tst_path_val' where each tst_path_val.path represents a file, whose +value is saved at the beginning and restored at the end of the test. +If pass a value to tst_path_val.value that will be set to the knob +correspondingly, NULL means do nothing else but save the original value.
"If non-NULL value is passed it is written to the respective file at the beginning of the test."
Quoted 53 lines
doc/c-test-api.txt +3
-2+Only the first line of a specified file is saved and restored. Pathnames can be optionally prefixed to specify how strictly (during 'store') are handled errors:@@ -1578,8 +1580,8 @@ Pathnames can be optionally prefixed to specify how strictly (during [source,c] ------------------------------------------------------------------------------- -static const char *save_restore[] = { - "/proc/sys/kernel/core_pattern", +static const struct tst_path_val save_restore[] = { + {"/proc/sys/kernel/core_pattern", NULL}, NULL, };include/tst_sys_conf.h +6
-0@@ -5,8 +5,14 @@#ifndef TST_SYS_CONF_H__ #define TST_SYS_CONF_H__ +struct tst_path_val { +const char *path; +const char *val; +}; +int tst_sys_conf_save_str (const char *path,const char *value);int tst_sys_conf_save (const char *path); +void tst_sys_conf_set (const char *path,const char *value);void tst_sys_conf_restore (int verbose);void tst_sys_conf_dump (void );include/tst_test.h +1
-1@@ -259,7 +259,7 @@ struct tst_test {* NULL terminated array of (/proc, /sys) files to save * before setup and restore after cleanup */ -const char *const *save_restore; +const struct tst_path_val const *save_restore;/* * NULL terminated array of kernel config options required for the lib/tst_sys_conf.c +0
-0@@ -96,6 +96,19 @@ int tst_sys_conf_save(const char *path)return tst_sys_conf_save_str (path, line);
lib/tst_sys_conf.c int tst_sys_conf_save(const char *path) · line 106
Quoted 10 lines
lib/tst_sys_conf.c +8
-0} +void tst_sys_conf_set (const char *path,const char *value) +{ +char flag = path[0 ]; +if (flag =='?' || flag =='!' ) + path++; + +if (access (path,F_OK ) !=0 ) +tst_brk (TBROK |TERRNO ," The path %s is not exist" , path);
^ ^
| does
useless space?
Also do we really have to check for the file existence here? The SAFE_FILE_PRINTF() will TBROK if the fopen() fails anyways.
Quoted 14 lines
lib/tst_sys_conf.c +4
-0+if (value) +SAFE_FILE_PRINTF (path,"%s" , value); +} +void tst_sys_conf_restore (int verbose) {struct tst_sys_conf *i;lib/tst_test.c +0
-0@@ -1105,11 +1105,12 @@ static void do_setup(int argc, char *argv[])tst_tmpdir ();
lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1112
Quoted 10 lines
lib/tst_test.c +4
-4if (tst_test->save_restore) { -const char *const *name = tst_test->save_restore; +const struct tst_path_val const *pvl = tst_test->save_restore; -while (*name) { -tst_sys_conf_save (*name); - name++; +while (pvl->path) { +if (!tst_sys_conf_save (pvl->path)) +tst_sys_conf_set (pvl->path, pvl->val);
Maybe it would be cleaner if we added tst_sys_conf_save_set() function instead of tst_sys_conf_set() that would do both, saved the value and set new one if non-NULL.
Quoted 7 lines
lib/tst_test.c +1
-0+ pvl++; } }Signature · 1 line
2.31.1
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/4] lib: enhance .save_restore to support set expected value
Quoted 19 lines · Cyril Hrubis
lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1108
Quoted 10 lines
lib/tst_test.c +1
-1@@ -1105,11 +1105,12 @@ static void do_setup(int argc, char *argv[])tst_tmpdir ();if (tst_test->save_restore) { -const char *const *name = tst_test->save_restore; + const struct tst_path_val const *pvl =
tst_test->save_restore;lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1112
Quoted 7 lines
lib/tst_test.c +3
-3-while (*name) { -tst_sys_conf_save (*name); - name++; +while (pvl->path) { +if (!tst_sys_conf_save (pvl->path)) +tst_sys_conf_set (pvl->path, pvl->val);
Quoted 4 lines
Maybe it would be cleaner if we added
tst_sys_conf_save_set()function instead oftst_sys_conf_set()that would do both, saved the value and set new one if non-NULL.
Yes, it can be. Actually, I started writing like that at the beginning.
But I feel that tst_sys_conf_save_set() looks a bit longer and does more things. To split the set into a separate function is to respect the UNIX design
philosophy (one function does one thing). Another important reason is to export tst_sys_conf_set() to global use instead of low-level macros for knob settings.
The rest suggestions sound good to me, thanks for reviewing!
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/4 testcase: switch to the new .save_restore
In reply to Li Wang--- lib/newlib_tests/test19.c | 14 ++++++-------- lib/newlib_tests/test20.c | 10 ++++------ testcases/cve/icmp_rate_limit01.c | 4 ++-- testcases/kernel/containers/userns/userns08.c | 4 ++-- testcases/kernel/mem/ksm/ksm01.c | 4 ++-- testcases/kernel/mem/ksm/ksm02.c | 4 ++-- testcases/kernel/mem/ksm/ksm03.c | 4 ++-- testcases/kernel/mem/ksm/ksm04.c | 4 ++-- testcases/kernel/mem/ksm/ksm06.c | 10 +++++----- testcases/kernel/syscalls/add_key/add_key05.c | 16 ++++------------ testcases/kernel/syscalls/bind/bind06.c | 4 ++-- testcases/kernel/syscalls/madvise/madvise08.c | 4 ++-- .../syscalls/migrate_pages/migrate_pages02.c | 5 ++--- testcases/kernel/syscalls/sendto/sendto03.c | 4 ++-- .../kernel/syscalls/setsockopt/setsockopt05.c | 4 ++-- .../kernel/syscalls/setsockopt/setsockopt06.c | 4 ++-- .../kernel/syscalls/setsockopt/setsockopt07.c | 4 ++-- .../kernel/syscalls/setsockopt/setsockopt08.c | 4 ++-- .../kernel/syscalls/setsockopt/setsockopt09.c | 4 ++-- 19 files changed, 49 insertions(+), 62 deletions(-)
lib/newlib_tests/test19.c +6 -8
@@ -8,13 +8,6 @@#include "tst_test.h" #include "tst_sys_conf.h" -static const char *const save_restore[] = { -"?/proc/nonexistent" , -"!/proc/sys/kernel/numa_balancing" , -"/proc/sys/kernel/core_pattern" , -NULL , -}; -static void setup (void ) {SAFE_FILE_PRINTF ("/proc/sys/kernel/core_pattern" ,"changed" );
@@ -30,5 +23,10 @@ static struct tst_test test = { .needs_root = 1, .test_all = run, .setup = setup, - .save_restore = save_restore, + .save_restore = (const struct tst_path_val const []) { + {"?/proc/nonexistent" ,NULL }, + {"!/proc/sys/kernel/numa_balancing" ,NULL }, + {"/proc/sys/kernel/core_pattern" ,NULL }, +NULL , + }, };
lib/newlib_tests/test20.c +4 -6
@@ -11,11 +11,6 @@#include "tst_hugepage.h" #include "tst_sys_conf.h" -static const char *const save_restore[] = { -"!/proc/sys/kernel/numa_balancing" , -NULL , -}; -static void do_test (void ) {unsigned long val, hpages;
@@ -41,5 +36,8 @@ static void do_test(void) {static struct tst_test test = { .test_all = do_test, .request_hugepages =2 , - .save_restore = save_restore, + .save_restore = (const struct tst_path_val const []) { + {"!/proc/sys/kernel/numa_balancing" ,"0" }, +NULL , + }, };
testcases/cve/icmp_rate_limit01.c +2 -2
@@ -268,8 +268,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/containers/userns/userns08.c +2 -2
@@ -134,8 +134,8 @@ static struct tst_test test = {"CONFIG_USER_NS" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/mem/ksm/ksm01.c +2 -2
@@ -103,8 +103,8 @@ static struct tst_test test = { }, .setup = setup, .cleanup = cleanup, - .save_restore = (const char *const []) { -"?/sys/kernel/mm/ksm/max_page_sharing" , + .save_restore = (const struct tst_path_val const []) { + {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL },NULL , }, .test_all = verify_ksm,
testcases/kernel/mem/ksm/ksm02.c +2 -2
@@ -115,8 +115,8 @@ static struct tst_test test = { }, .setup = setup, .cleanup = cleanup, - .save_restore = (const char *const []) { -"?/sys/kernel/mm/ksm/max_page_sharing" , + .save_restore = (const struct tst_path_val const []) { + {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL },NULL , }, .test_all = verify_ksm,
testcases/kernel/mem/ksm/ksm03.c +2 -2
@@ -100,8 +100,8 @@ static struct tst_test test = { }, .setup = setup, .cleanup = cleanup, - .save_restore = (const char *const []) { -"?/sys/kernel/mm/ksm/max_page_sharing" , + .save_restore = (const struct tst_path_val const []) { + {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL },NULL , }, .test_all = verify_ksm,
testcases/kernel/mem/ksm/ksm04.c +2 -2
@@ -116,8 +116,8 @@ static struct tst_test test = { }, .setup = setup, .cleanup = cleanup, - .save_restore = (const char *const []) { -"?/sys/kernel/mm/ksm/max_page_sharing" , + .save_restore = (const struct tst_path_val const []) { + {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL },NULL , }, .test_all = verify_ksm,
testcases/kernel/mem/ksm/ksm06.c +5 -5
@@ -136,11 +136,11 @@ static struct tst_test test = { {} }, .setup = setup, - .save_restore = (const char *const []) { -"?/sys/kernel/mm/ksm/max_page_sharing" , -"!/sys/kernel/mm/ksm/run" , -"!/sys/kernel/mm/ksm/sleep_millisecs" , -"/sys/kernel/mm/ksm/merge_across_nodes" , + .save_restore = (const struct tst_path_val const []) { + {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, + {"!/sys/kernel/mm/ksm/run" ,NULL }, + {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,NULL },NULL , }, .needs_kconfigs = (const char *const []){
testcases/kernel/syscalls/add_key/add_key05.c +4 -12
@@ -202,13 +202,6 @@ static void do_test(unsigned int n)return ; } -static void setup (void ) -{ -SAFE_FILE_PRINTF ("/proc/sys/kernel/keys/gc_delay" ,"1" ); -SAFE_FILE_PRINTF ("/proc/sys/kernel/keys/maxkeys" ,"200" ); -SAFE_FILE_PRINTF ("/proc/sys/kernel/keys/maxbytes" ,"20000" ); -} -static void cleanup (void ) {while (usern--)
@@ -220,12 +213,11 @@ static struct tst_test test = { .tcnt = 2, .needs_root = 1, .forks_child = 1, - .setup = setup, .cleanup = cleanup, - .save_restore = (const char *const []) { -"?/proc/sys/kernel/keys/gc_delay" , -"?/proc/sys/kernel/keys/maxkeys" , -"?/proc/sys/kernel/keys/maxbytes" , + .save_restore = (const struct tst_path_val const []) { + {"?/proc/sys/kernel/keys/gc_delay" ,"1" }, + {"?/proc/sys/kernel/keys/maxkeys" ,"200" }, + {"?/proc/sys/kernel/keys/maxbytes" ,"20000" },NULL , }, .bufs = (struct tst_buffers []) {
testcases/kernel/syscalls/bind/bind06.c +2 -2
@@ -109,8 +109,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/madvise/madvise08.c +2 -2
@@ -213,8 +213,8 @@ static struct tst_test test = { .needs_tmpdir = 1, .needs_root = 1, .forks_child = 1, - .save_restore = (const char *const []) { -CORE_PATTERN , + .save_restore = (const struct tst_path_val const []) { + {CORE_PATTERN ,NULL },NULL , }, };
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c +2 -3
@@ -276,7 +276,6 @@ static void setup(void)else if (tst_kvercmp (2 ,6 ,18 ) <0 )tst_brk (TCONF ,"2.6.18 or greater kernel required" ); -FILE_PRINTF ("/proc/sys/kernel/numa_balancing" ,"0" );/* * find 2 nodes, which can hold NODE_MIN_FREEMEM bytes * The reason is that:
@@ -327,8 +326,8 @@ static struct tst_test test = { .forks_child = 1, .test_all = run, .setup = setup, - .save_restore = (const char *const []) { -"?/proc/sys/kernel/numa_balancing" , + .save_restore = (const struct tst_path_val const []) { + {"?/proc/sys/kernel/numa_balancing" ,"0" },NULL , }, };
testcases/kernel/syscalls/sendto/sendto03.c +2 -2
@@ -217,8 +217,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/setsockopt/setsockopt05.c +2 -2
@@ -101,8 +101,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/setsockopt/setsockopt06.c +2 -2
@@ -129,8 +129,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/setsockopt/setsockopt07.c +2 -2
@@ -141,8 +141,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/setsockopt/setsockopt08.c +2 -2
@@ -158,8 +158,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/setsockopt/setsockopt09.c +2 -2
@@ -105,8 +105,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/4] testcase: switch to the new .save_restore
Hi!
Looks obviously correct, but should have been part of the previous patch, otherwise we break bisectability.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/4 ksm: cleanup work and make use of .save_restore
In reply to Li Wang--- 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(-)
testcases/kernel/mem/ksm/ksm01.c +14 -24
@@ -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", };
testcases/kernel/mem/ksm/ksm02.c +7 -18
@@ -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 },
testcases/kernel/mem/ksm/ksm03.c +7 -18
@@ -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 },
testcases/kernel/mem/ksm/ksm04.c +7 -17
@@ -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 []){
testcases/kernel/mem/ksm/ksm05.c +8 -21
@@ -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
testcases/kernel/mem/ksm/ksm_common.h +0 -2
@@ -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;
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 4/4] ksm: cleanup work and make use of .save_restore
Hi!
Quoted 41 lines
testcases/kernel/mem/ksm/ksm01.c +0
-24@@ -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 []) {
testcases/kernel/mem/ksm/ksm01.c static struct tst_test test = { · line 92
Quoted 10 lines
testcases/kernel/mem/ksm/ksm01.c +9
-0+ {"!/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. + */
I would have removed this comment, it's not in the rest of the tests either way...
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/3 lib: move struct tst_sys_conf to internal
In reply to Li WangAs it only used in tst_sys_conf library internally, there is unnecessary to put in header file.
--- include/tst_sys_conf.h | 6 ------ lib/tst_sys_conf.c | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-)
include/tst_sys_conf.h +0 -6
@@ -5,12 +5,6 @@#ifndef TST_SYS_CONF_H__ #define TST_SYS_CONF_H__ -struct tst_sys_conf { -char path[PATH_MAX ]; -char value[PATH_MAX ]; -struct tst_sys_conf *next; -}; -int tst_sys_conf_save_str (const char *path,const char *value);int tst_sys_conf_save (const char *path);void tst_sys_conf_restore (int verbose);
lib/tst_sys_conf.c +6 -0
@@ -12,6 +12,12 @@#include "tst_test.h" #include "tst_sys_conf.h" +struct tst_sys_conf { +char path[PATH_MAX ]; +char value[PATH_MAX ]; +struct tst_sys_conf *next; +}; +static struct tst_sys_conf *save_restore_data;void tst_sys_conf_dump (void )
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/3 lib: enhance .save_restore to support set expected value
This extends that .save_restore support set new expected value after saving the knob's original, which also avoids additionally checking before using the file at other places.
And, export function tst_sys_conf_set() can be singly used for setting new value of knob in the whole LTP.
---
Notes:
v1 --> v2
* refine the description in doc as suggested by Cyril
* remove redundant file check in tst_sys_conf_set
* merge patch 3/4 into 2/4 for bisectability reason
doc/c-test-api.txt | 14 ++++++++------ include/tst_sys_conf.h | 6 ++++++ include/tst_test.h | 2 +- lib/newlib_tests/test19.c | 14 ++++++-------- lib/newlib_tests/test20.c | 10 ++++------ lib/tst_sys_conf.c | 10 ++++++++++ lib/tst_test.c | 9 +++++---- testcases/cve/icmp_rate_limit01.c | 4 ++-- testcases/kernel/containers/userns/userns08.c | 4 ++-- testcases/kernel/mem/ksm/ksm01.c | 4 ++-- testcases/kernel/mem/ksm/ksm02.c | 4 ++-- testcases/kernel/mem/ksm/ksm03.c | 4 ++-- testcases/kernel/mem/ksm/ksm04.c | 4 ++-- testcases/kernel/mem/ksm/ksm06.c | 10 +++++----- testcases/kernel/syscalls/add_key/add_key05.c | 16 ++++------------ testcases/kernel/syscalls/bind/bind06.c | 4 ++-- testcases/kernel/syscalls/madvise/madvise08.c | 4 ++-- .../syscalls/migrate_pages/migrate_pages02.c | 5 ++--- testcases/kernel/syscalls/sendto/sendto03.c | 4 ++-- .../kernel/syscalls/setsockopt/setsockopt05.c | 4 ++-- .../kernel/syscalls/setsockopt/setsockopt06.c | 4 ++-- .../kernel/syscalls/setsockopt/setsockopt07.c | 4 ++-- .../kernel/syscalls/setsockopt/setsockopt08.c | 4 ++-- .../kernel/syscalls/setsockopt/setsockopt09.c | 4 ++-- 24 files changed, 79 insertions(+), 73 deletions(-)
doc/c-test-api.txt +8 -6
@@ -1561,10 +1561,12 @@ itself is not available on the system. LTP library can be instructed to save and restore value of specified (/proc|sys) files. This is achieved by initialized tst_test struct -field 'save_restore'. It is a 'NULL' terminated array of strings where -each string represents a file, whose value is saved at the beginning -and restored at the end of the test. Only first line of a specified -file is saved and restored. +field 'save_restore'. It is a NULL-terminated array of struct +'tst_path_val' where each tst_path_val.path represents a file, whose +value is saved at the beginning and restored at the end of the test. +If non-NULL value is passed it is written to the respective file at +the beginning of the test. Only the first line of a specified file +is saved and restored. Pathnames can be optionally prefixed to specify how strictly (during 'store') are handled errors:
@@ -1578,8 +1580,8 @@ Pathnames can be optionally prefixed to specify how strictly (during [source,c] ------------------------------------------------------------------------------- -static const char *save_restore[] = { - "/proc/sys/kernel/core_pattern", +static const struct tst_path_val save_restore[] = { + {"/proc/sys/kernel/core_pattern", NULL}, NULL, };
include/tst_sys_conf.h +6 -0
@@ -5,8 +5,14 @@#ifndef TST_SYS_CONF_H__ #define TST_SYS_CONF_H__ +struct tst_path_val { +const char *path; +const char *val; +}; +int tst_sys_conf_save_str (const char *path,const char *value);int tst_sys_conf_save (const char *path); +void tst_sys_conf_set (const char *path,const char *value);void tst_sys_conf_restore (int verbose);void tst_sys_conf_dump (void );
include/tst_test.h +1 -1
@@ -259,7 +259,7 @@ struct tst_test {* NULL terminated array of (/proc, /sys) files to save * before setup and restore after cleanup */ -const char *const *save_restore; +const struct tst_path_val const *save_restore;/* * NULL terminated array of kernel config options required for the
lib/newlib_tests/test19.c +6 -8
@@ -8,13 +8,6 @@#include "tst_test.h" #include "tst_sys_conf.h" -static const char *const save_restore[] = { -"?/proc/nonexistent" , -"!/proc/sys/kernel/numa_balancing" , -"/proc/sys/kernel/core_pattern" , -NULL , -}; -static void setup (void ) {SAFE_FILE_PRINTF ("/proc/sys/kernel/core_pattern" ,"changed" );
@@ -30,5 +23,10 @@ static struct tst_test test = { .needs_root = 1, .test_all = run, .setup = setup, - .save_restore = save_restore, + .save_restore = (const struct tst_path_val const []) { + {"?/proc/nonexistent" ,NULL }, + {"!/proc/sys/kernel/numa_balancing" ,NULL }, + {"/proc/sys/kernel/core_pattern" ,NULL }, +NULL , + }, };
lib/newlib_tests/test20.c +4 -6
@@ -11,11 +11,6 @@#include "tst_hugepage.h" #include "tst_sys_conf.h" -static const char *const save_restore[] = { -"!/proc/sys/kernel/numa_balancing" , -NULL , -}; -static void do_test (void ) {unsigned long val, hpages;
@@ -41,5 +36,8 @@ static void do_test(void) {static struct tst_test test = { .test_all = do_test, .request_hugepages =2 , - .save_restore = save_restore, + .save_restore = (const struct tst_path_val const []) { + {"!/proc/sys/kernel/numa_balancing" ,"0" }, +NULL , + }, };
lib/tst_sys_conf.c +10 -0
@@ -96,6 +96,16 @@ int tst_sys_conf_save(const char *path)return tst_sys_conf_save_str (path, line); } +void tst_sys_conf_set (const char *path,const char *value) +{ +char flag = path[0 ]; +if (flag =='?' || flag =='!' ) + path++; + +if (value) +SAFE_FILE_PRINTF (path,"%s" , value); +} +void tst_sys_conf_restore (int verbose) {struct tst_sys_conf *i;
lib/tst_test.c +5 -4
@@ -1105,11 +1105,12 @@ static void do_setup(int argc, char *argv[])tst_tmpdir ();if (tst_test->save_restore) { -const char *const *name = tst_test->save_restore; +const struct tst_path_val const *pvl = tst_test->save_restore; -while (*name) { -tst_sys_conf_save (*name); - name++; +while (pvl->path) { +if (!tst_sys_conf_save (pvl->path)) +tst_sys_conf_set (pvl->path, pvl->val); + pvl++; } }
testcases/cve/icmp_rate_limit01.c +2 -2
@@ -268,8 +268,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/containers/userns/userns08.c +2 -2
@@ -134,8 +134,8 @@ static struct tst_test test = {"CONFIG_USER_NS" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/mem/ksm/ksm01.c +2 -2
@@ -103,8 +103,8 @@ static struct tst_test test = { }, .setup = setup, .cleanup = cleanup, - .save_restore = (const char *const []) { -"?/sys/kernel/mm/ksm/max_page_sharing" , + .save_restore = (const struct tst_path_val const []) { + {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL },NULL , }, .test_all = verify_ksm,
testcases/kernel/mem/ksm/ksm02.c +2 -2
@@ -115,8 +115,8 @@ static struct tst_test test = { }, .setup = setup, .cleanup = cleanup, - .save_restore = (const char *const []) { -"?/sys/kernel/mm/ksm/max_page_sharing" , + .save_restore = (const struct tst_path_val const []) { + {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL },NULL , }, .test_all = verify_ksm,
testcases/kernel/mem/ksm/ksm03.c +2 -2
@@ -100,8 +100,8 @@ static struct tst_test test = { }, .setup = setup, .cleanup = cleanup, - .save_restore = (const char *const []) { -"?/sys/kernel/mm/ksm/max_page_sharing" , + .save_restore = (const struct tst_path_val const []) { + {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL },NULL , }, .test_all = verify_ksm,
testcases/kernel/mem/ksm/ksm04.c +2 -2
@@ -116,8 +116,8 @@ static struct tst_test test = { }, .setup = setup, .cleanup = cleanup, - .save_restore = (const char *const []) { -"?/sys/kernel/mm/ksm/max_page_sharing" , + .save_restore = (const struct tst_path_val const []) { + {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL },NULL , }, .test_all = verify_ksm,
testcases/kernel/mem/ksm/ksm06.c +5 -5
@@ -136,11 +136,11 @@ static struct tst_test test = { {} }, .setup = setup, - .save_restore = (const char *const []) { -"?/sys/kernel/mm/ksm/max_page_sharing" , -"!/sys/kernel/mm/ksm/run" , -"!/sys/kernel/mm/ksm/sleep_millisecs" , -"/sys/kernel/mm/ksm/merge_across_nodes" , + .save_restore = (const struct tst_path_val const []) { + {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, + {"!/sys/kernel/mm/ksm/run" ,NULL }, + {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,NULL },NULL , }, .needs_kconfigs = (const char *const []){
testcases/kernel/syscalls/add_key/add_key05.c +4 -12
@@ -202,13 +202,6 @@ static void do_test(unsigned int n)return ; } -static void setup (void ) -{ -SAFE_FILE_PRINTF ("/proc/sys/kernel/keys/gc_delay" ,"1" ); -SAFE_FILE_PRINTF ("/proc/sys/kernel/keys/maxkeys" ,"200" ); -SAFE_FILE_PRINTF ("/proc/sys/kernel/keys/maxbytes" ,"20000" ); -} -static void cleanup (void ) {while (usern--)
@@ -220,12 +213,11 @@ static struct tst_test test = { .tcnt = 2, .needs_root = 1, .forks_child = 1, - .setup = setup, .cleanup = cleanup, - .save_restore = (const char *const []) { -"?/proc/sys/kernel/keys/gc_delay" , -"?/proc/sys/kernel/keys/maxkeys" , -"?/proc/sys/kernel/keys/maxbytes" , + .save_restore = (const struct tst_path_val const []) { + {"?/proc/sys/kernel/keys/gc_delay" ,"1" }, + {"?/proc/sys/kernel/keys/maxkeys" ,"200" }, + {"?/proc/sys/kernel/keys/maxbytes" ,"20000" },NULL , }, .bufs = (struct tst_buffers []) {
testcases/kernel/syscalls/bind/bind06.c +2 -2
@@ -109,8 +109,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/madvise/madvise08.c +2 -2
@@ -213,8 +213,8 @@ static struct tst_test test = { .needs_tmpdir = 1, .needs_root = 1, .forks_child = 1, - .save_restore = (const char *const []) { -CORE_PATTERN , + .save_restore = (const struct tst_path_val const []) { + {CORE_PATTERN ,NULL },NULL , }, };
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c +2 -3
@@ -276,7 +276,6 @@ static void setup(void)else if (tst_kvercmp (2 ,6 ,18 ) <0 )tst_brk (TCONF ,"2.6.18 or greater kernel required" ); -FILE_PRINTF ("/proc/sys/kernel/numa_balancing" ,"0" );/* * find 2 nodes, which can hold NODE_MIN_FREEMEM bytes * The reason is that:
@@ -327,8 +326,8 @@ static struct tst_test test = { .forks_child = 1, .test_all = run, .setup = setup, - .save_restore = (const char *const []) { -"?/proc/sys/kernel/numa_balancing" , + .save_restore = (const struct tst_path_val const []) { + {"?/proc/sys/kernel/numa_balancing" ,"0" },NULL , }, };
testcases/kernel/syscalls/sendto/sendto03.c +2 -2
@@ -217,8 +217,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/setsockopt/setsockopt05.c +2 -2
@@ -101,8 +101,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/setsockopt/setsockopt06.c +2 -2
@@ -129,8 +129,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/setsockopt/setsockopt07.c +2 -2
@@ -141,8 +141,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/setsockopt/setsockopt08.c +2 -2
@@ -158,8 +158,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
testcases/kernel/syscalls/setsockopt/setsockopt09.c +2 -2
@@ -105,8 +105,8 @@ static struct tst_test test = {"CONFIG_NET_NS=y" ,NULL }, - .save_restore = (const char * const[]) { -"?/proc/sys/user/max_user_namespaces" , + .save_restore = (const struct tst_path_val const[]) { + {"?/proc/sys/user/max_user_namespaces" ,NULL },NULL , }, .tags = (const struct tst_tag[]) {
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] lib: enhance .save_restore to support set expected value
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] lib: enhance .save_restore to support set expected value
Quoted 3 lines · Cyril Hrubis
Hi!
Reviewed-by Cyril Hrubis <[email protected]>
Patchset applied, thanks!
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] lib: enhance .save_restore to support set expected value
In reply to Li WangHi Li
include/tst_test.h struct tst_test { · line 262
Quoted 11 lines
include/tst_test.h +1
-1@@ -259,7 +259,7 @@ struct tst_test {* NULL terminated array of (/proc, /sys) files to save * before setup and restore after cleanup */ -const char *const *save_restore; +const struct tst_path_val const *save_restore;
Ci complains about duplicate const see the following url
https://github.com/linux-test-project/ltp/runs/5491806027?check_suite_focus=true#step:10:19
How about using const struct tst_path_val *save_restore like other struct pointer( struct tst_cap *caps, const struct tst_tag *tags)?
Best Regards
Yang Xu
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] lib: enhance .save_restore to support set expected value
Quoted 10 lines
include/tst_test.h struct tst_test { · line 262
Quoted 8 lines
include/tst_test.h +1
-1@@ -259,7 +259,7 @@ struct tst_test {* NULL terminated array of (/proc, /sys) files to save * before setup and restore after cleanup */ -const char *const *save_restore; +const struct tst_path_val const *save_restore;Ci complains about duplicate const see the following url
Quoted 5 lines
https://github.com/linux-test-project/ltp/runs/5491806027?check_suite_focus=true#step:10:19
How about using const struct
tst_path_val*save_restorelike other structpointer( struct tst_cap *caps, const struct tst_tag *tags)?
Yes, good catch. Can you send a patch to fix the compiling issue or I do that?
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] lib: enhance .save_restore to support set expected value
Hi Li
Quoted 15 lines
> --- a/include/tst_test.h
> +++ b/include/tst_test.h
> @@ -259,7 +259,7 @@ struct tst_test {
> * NULL terminated array of (/proc, /sys) files to save
> * before setup and restore after cleanup
> */
> - const char * const *save_restore;
> + const struct tst_path_val const *save_restore;
Ci complains about duplicate const see the following url
https://github.com/linux-test-project/ltp/runs/5491806027?check_suite_focus=true#step:10:19
How about using const struct tst_path_val *save_restore like
other struct pointer( struct tst_cap *caps, const struct tst_tag *tags)?Quoted 2 lines
Yes, good catch. Can you send a patch to fix the compiling issue or I do that?
Of course, you can do it.
Best Regards
Yang Xu
Quoted 4 lines
--
Regards,
Li Wang
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/3 ksm: cleanup work and make use of .save_restore
In reply to Li Wang---
Notes:
v1 --> v2
remove the code comments from ksm01.c
testcases/kernel/mem/ksm/ksm01.c | 31 ++++++--------------------- 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, 36 insertions(+), 100 deletions(-)
testcases/kernel/mem/ksm/ksm01.c +7 -24
@@ -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,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", };
testcases/kernel/mem/ksm/ksm02.c +7 -18
@@ -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 },
testcases/kernel/mem/ksm/ksm03.c +7 -18
@@ -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 },
testcases/kernel/mem/ksm/ksm04.c +7 -17
@@ -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 []){
testcases/kernel/mem/ksm/ksm05.c +8 -21
@@ -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
testcases/kernel/mem/ksm/ksm_common.h +0 -2
@@ -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;
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp