Expand Cgroup lib and modify controller tests
v2 cover Expand Cgroup lib and modify controller tests
This patchset aims to expand the cgroup_lib shell library to simplify and centralize the whole mounting and cleanup process that can get rather confusing and redundant when writing cgroup controller tests from a shell environment. This is done by having the shell library make calls to the C cgroup API from a binary utility.
In this patch set there are a few tests that have been extensively rewritten to work with the new test API and to use the new functionality from the cgroup lib. Because the test Cgroup lib handles mounting for v1 and v2 controllers, some tests were modified to also work under cgroup v2. Some tests that were written for v1 controller also effictively test v2 controllers, while others were written to test v2 controllers in the spirit of the test or skipped outright.
Luke Nowakowski-Krijger (16):
API/cgroup: Modify tst_cg_print_config for parsing and consumption API/cgroup: Add option for specific pid to tst_cg_opts API/cgroup: Add cgroup_find_root helper function API/cgroup: Implement tst_cg_load_config
API/cgroup: Add more controllers to tst_cgroup
API/cgroup: refuse to mount blkio when io controller is mounted testcases/lib: Implement tst_cgctl binary
controllers: Expand cgroup_lib shell library
controllers: Update cgroup_fj_* to use newer cgroup lib and test lib
controllers: Update memcg_control_test to newer test lib and cgroup
lib
controllers: Update memcg/regression/* to new test and cgroup lib
controllers: Update memcg_stress_test to use newer cgroup lib
controllers: update memcg/functional to use newer cgroup lib
controllers: Update pids.sh to use newer cgroup lib
controllers: update cpuset_regression_test.sh to use newer cgroup lib
controllers: update cgroup_regression_test to use newer cgroup lib
include/tst_cgroup.h | 17 +- lib/tst_cgroup.c | 203 +++++++++++++++++- .../cgroup/cgroup_regression_test.sh | 17 +- .../controllers/cgroup_fj/cgroup_fj_common.sh | 113 +++------- .../cgroup_fj/cgroup_fj_function.sh | 169 ++++++++------- .../controllers/cgroup_fj/cgroup_fj_proc.c | 24 +-- .../controllers/cgroup_fj/cgroup_fj_stress.sh | 168 +++++++-------- testcases/kernel/controllers/cgroup_lib.sh | 129 +++++++++-- .../cpuset/cpuset_regression_test.sh | 26 +-- .../controllers/memcg/control/mem_process.c | 28 +-- .../memcg/control/memcg_control_test.sh | 150 ++++--------- .../memcg/functional/memcg_force_empty.sh | 2 +- .../controllers/memcg/functional/memcg_lib.sh | 54 ++--- .../memcg/regression/memcg_regression_test.sh | 202 ++++++++--------- .../memcg/regression/memcg_test_1.c | 40 ++-- .../memcg/regression/memcg_test_2.c | 24 +-- .../memcg/regression/memcg_test_3.c | 38 ++-- .../memcg/regression/memcg_test_4.c | 24 +-- .../memcg/regression/memcg_test_4.sh | 50 ++--- .../memcg/stress/memcg_stress_test.sh | 32 ++- testcases/kernel/controllers/pids/pids.sh | 67 +----- testcases/lib/Makefile | 2 +- testcases/lib/tst_cgctl.c | 87 ++++++++ 23 files changed, 883 insertions(+), 783 deletions(-) create mode 100644 testcases/lib/tst_cgctl.c
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/16 API/cgroup: Add option for specific pid to tst_cg_opts
Add an option that would allow to create a test directory with a specified pid, as opposed to the calling processes pid.
--- include/tst_cgroup.h | 4 ++++ lib/tst_cgroup.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-)
include/tst_cgroup.h +4 -0
@@ -97,6 +97,10 @@ struct tst_cg_opts {* version. Defautls to zero to accept any version. */ enum tst_cg_ver needs_ver; +/* Pass in a specific pid to create and identify the test +* directory as opposed to the default pid of the calling process. +*/ +int test_pid; };/* A Control Group in LTP's aggregated hierarchy */
lib/tst_cgroup.c +5 -1
@@ -698,7 +698,11 @@ mkdirs:cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir); -sprintf (cgroup_test_dir,"test-%d" ,getpid ()); +if (options->test_pid) +sprintf (cgroup_test_dir,"test-%d" , options->test_pid); +else +sprintf (cgroup_test_dir,"test-%d" ,getpid ()); +cgroup_dir_mk (&root->ltp_dir, cgroup_test_dir, &root->test_dir); }
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/16 API/cgroup: Modify tst_cg_print_config for parsing and consumption
In reply to Luke Nowakowski-KrijgerModify tst_cg_print_config to be easily parsed by sscanf so that it can later be consumed by tst_cg_load_config.
Prints out root info of each controller found as well as the minimal associated state needed to cleanup mounts and dirs made my tst_cg_require.
---
v2: Remove "mounted_drain_dir" as mounting ltp dir and drain dir happen at the same time
v3: Print config to be scanf friendly to be much easier to consume. Rename variables to reflect the variables used in the library for simplicity.
include/tst_cgroup.h | 6 +++++- lib/tst_cgroup.c | 25 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-)
include/tst_cgroup.h +5 -1
@@ -110,7 +110,11 @@ extern const struct tst_cg_group *const tst_cg_drain;* controllers. Called automatically by tst_cg_require. */ void tst_cg_scan (void ); -/* Print the config detected by tst_cg_scan */ +/* Print the config detected by tst_cg_scan and print the internal +* state associated with each controller. Output can be passed to +* tst_cg_load_config to configure the internal state to that of the +* config between program invocations. +*/ void tst_cg_print_config (void );/* Ensure the specified controller is available in the test's default
lib/tst_cgroup.c +18 -7
@@ -309,24 +309,35 @@ opendir: O_PATH | O_DIRECTORY); } +#define CONFIG_HEADER "ctrl_name ver we_require_it mnt_path we_mounted_it ltp_dir.we_created_it test_dir.dir_name" +#define CONFIG_FORMAT "%s\t%d\t%d\t%s\t%d\t%d\t%s" +/* Prints out the state associated with each controller to be consumed by +* tst_cg_load_config. +* +* The config keeps track of the minimal state needed for tst_cg_cleanup +* to cleanup mounts and directories made by tst_cg_require. +*/ void tst_cg_print_config (void ) { -struct cgroup_root *root;const struct cgroup_ctrl *ctrl; -tst_res (TINFO ,"Detected Controllers:" ); +printf ("%s\n" ,CONFIG_HEADER );for_each_ctrl (ctrl) { - root = ctrl->ctrl_root; +struct cgroup_root *root = ctrl->ctrl_root;if (!root)continue ; -tst_res (TINFO ,"\t%.10s %s @ %s:%s" , +printf (CONFIG_FORMAT , ctrl->ctrl_name, - root->no_cpuset_prefix ?"[noprefix]" :"" , - root->ver ==TST_CG_V1 ?"V1" :"V2" , - root->mnt_path); + root->ver, + ctrl->we_require_it, + root->mnt_path, + root->we_mounted_it, + root->ltp_dir.we_created_it, + root->test_dir.dir_name ? root->test_dir.dir_name :"NULL" ); +printf ("\n" ); } }
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/16 API/cgroup: Add cgroup_find_root helper function
In reply to Luke Nowakowski-KrijgerAdd a helper function similar to cgroup_find_ctrl to make matching paths to roots more convenient.
---
v2: Use the for_each_root() macro to properly loop over v1 roots
lib/tst_cgroup.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
lib/tst_cgroup.c +13 -0
@@ -354,6 +354,19 @@ static struct cgroup_ctrl *cgroup_find_ctrl(const char *const ctrl_name)return NULL ; } +static struct cgroup_root *cgroup_find_root (const char *const mnt_path) +{ +struct cgroup_root *root; + +for_each_root (root) { +if (!strcmp (root->mnt_path, mnt_path)) +return root; + } + +return NULL ; +} + +/* Determine if a mounted cgroup hierarchy is unique and record it if so. * * For CGroups V2 this is very simple as there is only one
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 5/16 API/cgroup: Add more controllers to tst_cgroup
In reply to Luke Nowakowski-KrijgerAdd the rest of the controllers that are tested in LTP controller tests so that they can be mounted using the cgroup api.
Control files should be added on an as needed basis.
---
v2: remove rdma controller as that is not used in any LTP tests. Remove control files that should be added on an as needed basis.
lib/tst_cgroup.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-)
lib/tst_cgroup.c +91 -1
@@ -83,8 +83,19 @@ enum cgroup_ctrl_indx {CTRL_MEMORY =1 ,CTRL_CPU ,CTRL_CPUSET , +CTRL_IO , +CTRL_PIDS , +CTRL_HUGETLB , +CTRL_CPUACCT , +CTRL_DEVICES , +CTRL_FREEZER , +CTRL_NETCLS , +CTRL_NETPRIO , +CTRL_BLKIO , +CTRL_MISC , +CTRL_PERFEVENT }; -#define CTRLS_MAX CTRL_CPUSET +#define CTRLS_MAX CTRL_PERFEVENT/* At most we can have one cgroup V1 tree for each controller and one * (empty) v2 tree.
@@ -191,6 +202,52 @@ static const struct cgroup_file cpuset_ctrl_files[] = { { } }; +static const struct cgroup_file pids_ctrl_files[] = { + {"pids.max" ,"pids.max" ,CTRL_PIDS }, + {"pids.current" ,"pids.current" ,CTRL_PIDS }, + { } +}; + +static const struct cgroup_file io_ctrl_files[] = { + { } +}; + +static const struct cgroup_file hugetlb_ctrl_files[] = { + { } +}; + +static const struct cgroup_file cpuacct_ctrl_files[] = { + { } +}; + +static const struct cgroup_file devices_ctrl_files[] = { + { } +}; + +static const struct cgroup_file freezer_ctrl_files[] = { + { } +}; + +static const struct cgroup_file netcls_ctrl_files[] = { + { } +}; + +static const struct cgroup_file netprio_ctrl_files[] = { + { } +}; + +static const struct cgroup_file blkio_ctrl_files[] = { + { } +}; + +static const struct cgroup_file misc_ctrl_files[] = { + { } +}; + +static const struct cgroup_file perf_event_ctrl_files[] = { + { } +}; +/* Lookup tree for item names. */ static struct cgroup_ctrl controllers[] = { [0 ] = {"cgroup" , cgroup_ctrl_files,0 ,NULL ,0 },
@@ -203,6 +260,39 @@ static struct cgroup_ctrl controllers[] = { [CTRL_CPUSET ] = {"cpuset" , cpuset_ctrl_files,CTRL_CPUSET ,NULL ,0 }, + [CTRL_PIDS ] = { +"pids" , pids_ctrl_files,CTRL_PIDS ,NULL ,0 + }, + [CTRL_IO ] = { +"io" , io_ctrl_files,CTRL_IO ,NULL ,0 + }, + [CTRL_HUGETLB ] = { +"hugetlb" , hugetlb_ctrl_files,CTRL_HUGETLB ,NULL ,0 + }, + [CTRL_CPUACCT ] = { +"cpuacct" , cpuacct_ctrl_files,CTRL_CPUACCT ,NULL ,0 + }, + [CTRL_DEVICES ] = { +"devices" , devices_ctrl_files,CTRL_DEVICES ,NULL ,0 + }, + [CTRL_FREEZER ] = { +"freezer" , freezer_ctrl_files,CTRL_FREEZER ,NULL ,0 + }, + [CTRL_NETCLS ] = { +"net_cls" , netcls_ctrl_files,CTRL_NETCLS ,NULL ,0 + }, + [CTRL_NETPRIO ] = { +"net_prio" , netprio_ctrl_files,CTRL_NETPRIO ,NULL ,0 + }, + [CTRL_BLKIO ] = { +"blkio" , blkio_ctrl_files,CTRL_BLKIO ,NULL ,0 + }, + [CTRL_MISC ] = { +"misc" , misc_ctrl_files,CTRL_MISC ,NULL ,0 + }, + [CTRL_PERFEVENT ] = { +"perf_event" , perf_event_ctrl_files,CTRL_PERFEVENT ,NULL ,0 + }, { } };
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 05/16] API/cgroup: Add more controllers to tst_cgroup
Hello Luke,
Quoted 22 lines · Luke Nowakowski-Krijger
Add the rest of the controllers that are tested in LTP controller tests so that they can be mounted using the cgroup api.
Control files should be added on an as needed basis.
Signed-off-by Luke Nowakowski-Krijger <[email protected]>---
v2: remove rdma controller as that is not used in any LTP tests. Remove control files that should be added on an as needed basis.lib/tst_cgroup.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-)lib/tst_cgroup.c +1
-0@@ -83,8 +83,19 @@ enum cgroup_ctrl_indx {CTRL_MEMORY =1 ,CTRL_CPU ,CTRL_CPUSET , + CTRL_IO,
lib/tst_cgroup.c enum cgroup_ctrl_indx { · line 96
Quoted 10 lines
lib/tst_cgroup.c +10
-0+CTRL_PIDS , +CTRL_HUGETLB , +CTRL_CPUACCT , +CTRL_DEVICES , +CTRL_FREEZER , +CTRL_NETCLS , +CTRL_NETPRIO , +CTRL_BLKIO , +CTRL_MISC , +CTRL_PERFEVENT
I think we need the debug controller as cgroup_fj_function is called with that in runtest/controllers.
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 05/16] API/cgroup: Add more controllers to tst_cgroup
Quoted 12 lines · Richard Palethorpe
Quoted 12 lines
lib/tst_cgroup.c +6
-0@@ -83,8 +83,19 @@ enum cgroup_ctrl_indx {CTRL_MEMORY =1 ,CTRL_CPU ,CTRL_CPUSET , +CTRL_IO , +CTRL_PIDS , +CTRL_HUGETLB , +CTRL_CPUACCT , +CTRL_DEVICES , + CTRL_FREEZER,
Quoted 9 lines
lib/tst_cgroup.c enum cgroup_ctrl_indx { · line 96
Quoted 5 lines
lib/tst_cgroup.c +5
-0+CTRL_NETCLS , +CTRL_NETPRIO , +CTRL_BLKIO , +CTRL_MISC , +CTRL_PERFEVENT I think we need the debug controller as
cgroup_fj_functionis called with that in runtest/controllers.
+1
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 4/16 API/cgroup: Implement tst_cg_load_config
In reply to Luke Nowakowski-KrijgerImplement tst_cg_load_config which consumes the state given by tst_cg_print_config to update the internal test state to reflect the given config.
This allows for programs using the cgroup C API to load and reload state, allowing functionality such as calling tst_cg_require and tst_cg_cleanup to function properly between programs or between invocations of a binary using the C API.
---
v2: Add root null check in parse_root_config.
Remove checking for ltp_drain_dir key from config as it was redundant.
Remove unsued variable in parse_ctrl_config.
Cleanup some compiler warnings.
v3: Rewrite to consume each line of the config with a scanf to make
the parsing much simpler while using new config variables.
include/tst_cgroup.h | 7 +++++ lib/tst_cgroup.c | 62 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
include/tst_cgroup.h +7 -0
@@ -121,6 +121,13 @@ void tst_cg_scan(void);*/ void tst_cg_print_config (void ); +/* Load the config printed out by tst_cg_print_config and configure the internal +* libary state to match the config. Used to allow tst_cg_cleanup to properly +* cleanup mounts and directories created by tst_cg_require between program +* invocations. +*/ +void tst_cg_load_config (const char *const config); +/* Ensure the specified controller is available in the test's default * CGroup, mounting/enabling it if necessary. Usually this is not * necesary use tst_test.needs_cgroup_controllers instead.
lib/tst_cgroup.c +62 -0
68 lines not on this page · raw message
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 04/16] API/cgroup: Implement tst_cg_load_config
Hello Luke,
Really great work for the patch series in general! However see comments below.
Quoted 46 lines · Luke Nowakowski-Krijger
Implement
tst_cg_load_configwhich consumes the state given bytst_cg_print_configto update the internal test state to reflect the given config.This allows for programs using the cgroup C API to load and reload state, allowing functionality such as calling
tst_cg_requireandtst_cg_cleanupto function properly between programs or between invocations of a binary using the C API.Signed-off-by Luke Nowakowski-Krijger <[email protected]>---
v2: Add root null check inparse_root_config.
Remove checking forltp_drain_dirkey from config as it was redundant.
Remove unsued variable inparse_ctrl_config.
Cleanup some compiler warnings.
v3: Rewrite to consume each line of the config with a scanf to make
the parsing much simpler while using new config variables.include/tst_cgroup.h | 7 +++++ lib/tst_cgroup.c | 62 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)include/tst_cgroup.h +7
-0@@ -121,6 +121,13 @@ void tst_cg_scan(void);*/ void tst_cg_print_config (void ); +/* Load the config printed out by tst_cg_print_config and configure the internal +* libary state to match the config. Used to allow tst_cg_cleanup to properly +* cleanup mounts and directories created by tst_cg_require between program +* invocations. +*/ +void tst_cg_load_config (const char *const config); +/* Ensure the specified controller is available in the test's default * CGroup, mounting/enabling it if necessary. Usually this is not * necesary use tst_test.needs_cgroup_controllers instead. lib/tst_cgroup.c +0
-0
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path) · line 369
Quoted 4 lines
lib/tst_cgroup.c +1
-0@@ -366,6 +366,68 @@ static struct cgroup_root *cgroup_find_root(const char *const mnt_path)return NULL ; } +static void parse_config (const char *const config_entry)
cgroup_parse_config_line perhaps? or cgroup_parse_ctrl?
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path) · line 372
Quoted 3 lines
lib/tst_cgroup.c +2
-0+{ +const char ctrl_name[32 ], mnt_path[PATH_MAX ], test_dir_name[NAME_MAX +1 ];
These buffers are not const.
I have lsp and clangd setup in emacs which warns about this. It's easy to miss the warning in the compiler output.
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path) · line 378
Quoted 7 lines
lib/tst_cgroup.c +7
-0+int ver, we_require_it, we_mounted_it, ltp_dir_we_created_it; +struct cgroup_root *root; +struct cgroup_ctrl *ctrl; + +sscanf (config_entry,CONFIG_FORMAT , + ctrl_name, &ver, &we_require_it, mnt_path, &we_mounted_it, + <p_dir_we_created_it, test_dir_name);
You need to run 'make check-tst_cgroup' in ltp/lib. The sscanf return value is not checked which could result in segfaults and other confusing errors if parsing fails.
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path) · line 381
Quoted 2 lines
lib/tst_cgroup.c +2
-0+ +if (!(ctrl =cgroup_find_ctrl (ctrl_name)))
check_patch.pl forbids assignments in if statements (it makes static analysis difficult). Again this is caught with 'make check'.
Quoted 11 lines
lib/tst_cgroup.c +11
-0+tst_brk (TBROK ,"Could not find ctrl from config. Ctrls changing between calls?" ); + + ctrl->we_require_it = we_require_it; + +if (!(root =cgroup_find_root (mnt_path))) +tst_brk (TBROK ,"Could not find root from config. Config possibly malformed?" ); + +if (we_mounted_it) + root->we_mounted_it =1 ; + +if (!root->ltp_dir.dir_name) {
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path) · line 401
Quoted 10 lines
lib/tst_cgroup.c +10
-0+cgroup_dir_mk (&root->mnt_dir, cgroup_ltp_dir, &root->ltp_dir); +cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir); +if (ltp_dir_we_created_it) { + root->ltp_dir.we_created_it =1 ; + root->drain_dir.we_created_it =1 ; + } + } + +if (!root->test_dir.dir_name &&strcmp (test_dir_name,"NULL" )) { +strncpy (cgroup_test_dir, test_dir_name,NAME_MAX );
I think this could result in an unterminated string. strncpy does not add a null char after the string that was copied. Note also that the format string passed to sscanf does not limit the field width so it could overwrite root and ctrl on the stack if the input is long enough.
Quoted 13 lines
lib/tst_cgroup.c +13
-0+cgroup_dir_mk (&root->ltp_dir, cgroup_test_dir, &root->test_dir); + root->test_dir.we_created_it =1 ; + } +} + +/* Load the test state config provided by tst_cg_print_config +* +* This will reload some internal tst_cgroup state given by the config +* that might otherwise have been lost between calls or between different +* processes. In particular this is used by testcases/lib/tst_cgctl to +* provide access to this C api to shell scripts. +* +* The config keeps track of the minimal state needed for tst_cg_cleanup
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path) · line 424
Quoted 10 lines
lib/tst_cgroup.c +10
-0+* to cleanup mounts and directories created by tst_cg_require. +*/ +void tst_cg_load_config (const char *const config) +{ +char temp_config[BUFSIZ ]; +char *line; + +if (strlen (config) >=BUFSIZ ) +tst_brk (TBROK ,"Config has exceeded buffer size?" ); +strncpy (temp_config, config,BUFSIZ );
Again, this won't copy the null byte from config if strlen(config) == BUFSIZ. You could use memcpy here anyway if you know the string length.
Quoted 9 lines
lib/tst_cgroup.c +6
-0+ + line =strtok (temp_config,"\n" ); +/* Make sure to consume the header. */ +for (line =strtok (NULL ,"\n" ); line; line =strtok (NULL ,"\n" )) +parse_config (line); +}/* Determine if a mounted cgroup hierarchy is unique and record it if so. *
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 04/16] API/cgroup: Implement tst_cg_load_config
Hi Richard,
Quoted 118 lines · Richard Palethorpe
Hello Luke,
Really great work for the patch series in general! However see comments below.
Quoted 10 lines · Luke Nowakowski-Krijger
Implement
tst_cg_load_configwhich consumes the state given bytst_cg_print_configto update the internal test state to reflect the given config.This allows for programs using the cgroup C API to load and reload state, allowing functionality such as calling
tst_cg_requireandtst_cg_cleanupto function properly between programs or between invocations of a binary using the C API.Signed-off-by Luke Nowakowski-Krijger <Quoted 18 lines
---
v2: Add root null check inparse_root_config.
Remove checking forltp_drain_dirkey from config as it was redundant.
Remove unsued variable inparse_ctrl_config.
Cleanup some compiler warnings.
v3: Rewrite to consume each line of the config with a scanf to make
the parsing much simpler while using new config variables.include/tst_cgroup.h | 7 +++++ lib/tst_cgroup.c | 62 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)include/tst_cgroup.h +0
-0include/tst_cgroup.h void tst_cg_scan(void); · line 124
Quoted 4 lines
include/tst_cgroup.h +1
-0@@ -121,6 +121,13 @@ void tst_cg_scan(void);*/ void tst_cg_print_config (void ); +/* Load the config printed out by tst_cg_print_config and configure the internal
include/tst_cgroup.h void tst_cg_scan(void); · line 125
Quoted 1 line
include/tst_cgroup.h +1
-0+* libary state to match the config. Used to allow tst_cg_cleanup to properly
include/tst_cgroup.h void tst_cg_scan(void); · line 126
Quoted 1 line
include/tst_cgroup.h +1
-0+* cleanup mounts and directories created by tst_cg_require between program
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const
Quoted 12 lines
include/tst_cgroup.h +4
-0+* invocations. +*/ +void tst_cg_load_config (const char *const config); +/* Ensure the specified controller is available in the test's default * CGroup, mounting/enabling it if necessary. Usually this is not * necesary use tst_test.needs_cgroup_controllers instead. lib/tst_cgroup.c +0
-0@@ -366,6 +366,68 @@ static struct cgroup_root *cgroup_find_root(constchar *const
mnt_path)lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path) · line 369
Quoted 4 lines
lib/tst_cgroup.c +1
-0return NULL ; } +static void parse_config (const char *const config_entry)
cgroup_parse_config_lineperhaps? orcgroup_parse_ctrl?lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const · line 372
Quoted 3 lines
lib/tst_cgroup.c +2
-0+{ +const char ctrl_name[32 ], mnt_path[PATH_MAX ], test_dir_name[NAME_MAX +1 ];These buffers are not const.
I have lsp and clangd setup in emacs which warns about this. It's easy to miss the warning in the compiler output.
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path) · line 378
Quoted 7 lines
lib/tst_cgroup.c +7
-0+int ver, we_require_it, we_mounted_it, ltp_dir_we_created_it; +struct cgroup_root *root; +struct cgroup_ctrl *ctrl; + +sscanf (config_entry,CONFIG_FORMAT , + ctrl_name, &ver, &we_require_it, mnt_path, &we_mounted_it, + <p_dir_we_created_it, test_dir_name);You need to run 'make check-tst_cgroup' in ltp/lib. The sscanf return value is not checked which could result in segfaults and other confusing errors if parsing fails.
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const · line 381
Quoted 2 lines
lib/tst_cgroup.c +2
-0+ +if (!(ctrl =cgroup_find_ctrl (ctrl_name)))check_patch.pl forbids assignments in if statements (it makes static analysis difficult). Again this is caught with 'make check'.
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const · line 382
Quoted 1 line
lib/tst_cgroup.c +1
-0+ tst_brk(TBROK, "Could not find ctrl from config. Ctrlschanging between calls?");
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path)
Quoted 5 lines
lib/tst_cgroup.c +5
-0+ + ctrl->we_require_it = we_require_it; + +if (!(root =cgroup_find_root (mnt_path))) + tst_brk(TBROK, "Could not find root from config. Configpossibly malformed?");
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path)
Quoted 6 lines
lib/tst_cgroup.c +6
-0+ +if (we_mounted_it) + root->we_mounted_it =1 ; + +if (!root->ltp_dir.dir_name) { + cgroup_dir_mk(&root->mnt_dir, cgroup_ltp_dir,
&root->ltp_dir);lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const · line 394
Quoted 1 line
lib/tst_cgroup.c +1
-0+ cgroup_dir_mk(&root->ltp_dir, cgroup_ltp_drain_dir,
&root->drain_dir);lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path) · line 401
Quoted 8 lines
lib/tst_cgroup.c +8
-0+if (ltp_dir_we_created_it) { + root->ltp_dir.we_created_it =1 ; + root->drain_dir.we_created_it =1 ; + } + } + +if (!root->test_dir.dir_name &&strcmp (test_dir_name,"NULL" )) { +strncpy (cgroup_test_dir, test_dir_name,NAME_MAX );
Quoted 6 lines
I think this could result in an unterminated string. strncpy does not add a null char after the string that was copied. Note also that the format string passed to sscanf does not limit the field width so it could overwrite root and ctrl on the stack if the input is long enough.
Thank you for pointing all these things out. I forgot about all the shenanigans that can happen when you don't sanity check string stuff :)
A few solutions to creating the scanff format are:
1) pre-processor trick to concatenate defines into a string, something like this
#define _tostr(str) #str
#define tostr(str) _tostr(str)
#define CONFIG_FORMAT "%" tostr(CTRL_NAME_MAX) "s\t%d\t%d\t%" tostr(PATH_MAX) "s\t%d\t%d\t%" tostr(NAME_MAX) "s"
2) just hardcode the lengths to avoid all of this nonsense above
3) just create the format at runtime
I'm more or less asking what you think is best to avoid sending out all of the patches and then discussing this / if there is a better way.
Quoted 36 lines
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const · line 403
Quoted 1 line
lib/tst_cgroup.c +1
-0+ cgroup_dir_mk(&root->ltp_dir, cgroup_test_dir,
&root->test_dir);lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path)
Quoted 8 lines
lib/tst_cgroup.c +8
-0+ root->test_dir.we_created_it =1 ; + } +} + +/* Load the test state config provided by tst_cg_print_config +* +* This will reload some internal tst_cgroup state given by the config +* that might otherwise have been lost between calls or between different
Quoted 4 lines
lib/tst_cgroup.c +4
-0+* processes. In particular this is used by testcases/lib/tst_cgctl to +* provide access to this C api to shell scripts. +* +* The config keeps track of the minimal state needed for tst_cg_cleanup lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const char *const mnt_path) · line 424
Quoted 10 lines
lib/tst_cgroup.c +10
-0+* to cleanup mounts and directories created by tst_cg_require. +*/ +void tst_cg_load_config (const char *const config) +{ +char temp_config[BUFSIZ ]; +char *line; + +if (strlen (config) >=BUFSIZ ) +tst_brk (TBROK ,"Config has exceeded buffer size?" ); +strncpy (temp_config, config,BUFSIZ );Again, this won't copy the null byte from config if strlen(config) == BUFSIZ. You could use memcpy here anyway if you know the string length.
Quoted 7 lines
lib/tst_cgroup.c +6
-0+ + line =strtok (temp_config,"\n" ); +/* Make sure to consume the header. */ +for (line =strtok (NULL ,"\n" ); line; line =strtok (NULL ,"\n" )) +parse_config (line); +}
Quoted 5 lines
lib/tst_cgroup.c static struct cgroup_root *cgroup_find_root(const · line 433
Quoted 1 line
lib/tst_cgroup.c +0
-0/* Determine if a mounted cgroup hierarchy is unique and record it if so.
Quoted 1 line
*
I will take all of the other things you mentioned and clean them up. Thanks for the review!
Quoted 5 lines
--
Thank you,
Richard.
Thanks,
- Luke
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 04/16] API/cgroup: Implement tst_cg_load_config
Hello Luke,
Quoted 10 lines
Thank you for pointing all these things out. I forgot about all the shenanigans that can happen when you don't sanity check string stuff :)
A few solutions to creating the scanff format are:
1) pre-processor trick to concatenate defines into a string, something like this
#define_tostr(str)#str
#define tostr(str)_tostr(str)
#defineCONFIG_FORMAT"%"tostr(CTRL_NAME_MAX)"s\t%d\t%d\t%"tostr(PATH_MAX)"s\t%d\t%d\t%"tostr(NAME_MAX)"s"2) just hardcode the lengths to avoid all of this nonsense above
I would have done 2 in this case, but you figured out 1, so feel free to use that. In fact that would be a nice addition to LTP's standard macros (but with TST_ prefix).
Just note that the maximum conversion length doesn't include the null character. scanf will write the null character after the maximum conversion length. Also I'm not sure the field length comes after '%' or that you use 's' with a length; possibly it should be '%c63' to scan a 64 byte null terminated string. However please double check the man page.
Quoted 2 lines
3) just create the format at runtime
IIRC this is considered unsafe and will result in warnings and errors.
Quoted 3 lines
I'm more or less asking what you think is best to avoid sending out all of the patches and then discussing this / if there is a better way.
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 04/16] API/cgroup: Implement tst_cg_load_config
Hi Richard and Li,
Quoted 20 lines · Richard Palethorpe
Hello Luke,
Quoted 2 lines
Thank you for pointing all these things out. I forgot about all the
shenanigans that can happen when you don't sanity check string stuff :)
Quoted 3 lines
A few solutions to creating the scanff format are:
1) pre-processor trick to concatenate defines into a string, somethinglike this
Quoted 3 lines
#define
_tostr(str)#str
#define tostr(str)_tostr(str)
#defineCONFIG_FORMAT"%"tostr(CTRL_NAME_MAX)"s\t%d\t%d\t%"
tostr(PATH_MAX)"s\t%d\t%d\t%"tostr(NAME_MAX)"s"Quoted 2 lines
2) just hardcode the lengths to avoid all of this nonsense above
I would have done 2 in this case, but you figured out 1, so feel free to use that. In fact that would be a nice addition to LTP's standard macros (but with
TST_prefix).
Quoted 8 lines
Just note that the maximum conversion length doesn't include the null character. scanf will write the null character after the maximum conversion length. Also I'm not sure the field length comes after '%' or that you use 's' with a length; possibly it should be '%c63' to scan a 64 byte null terminated string. However please double check the man page.
You can use %s with a length which makes things easier and automatically
appends the null character.
Quoted 11 lines
Quoted 2 lines
3) just create the format at runtime
IIRC this is considered unsafe and will result in warnings and errors.
Quoted 2 lines
I'm more or less asking what you think is best to avoid sending out all
of the patches and then discussing this / if there is a better way.
Quoted 1 line
Sorry for the delay on these patches, got caught up in many other things again.
I have submitted a pull request for review, didn't want to spam 19 patches on the ML. Its my first time doing a pull request.. are you guys able to review and accept from there? If so here it is
https://github.com/linux-test-project/ltp/pull/933
Quoted 4 lines
--
Thank you,
Richard.
Thanks,
- Luke
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 04/16] API/cgroup: Implement tst_cg_load_config
Quoted 4 lines · Luke Nowakowski-Krijger
Sorry for the delay on these patches, got caught up in many other things again.
No problem with the delay, most of us (at least myself) are part-time working on this.
Quoted 6 lines
I have submitted a pull request for review, didn't want to spam 19 patches on the ML. Its my first time doing a pull request.. are you guys able to review and accept from there? If so here it is
https://github.com/linux-test-project/ltp/pull/933
Good job, I will look into them later. But I'd still suggest sending out to ML as well, in case of other maintainers might interested in the latest patchset.
Ps: AFAIK doing code review in ML is the recommended way of LTP.
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 6/16 API/cgroup: refuse to mount blkio when io controller is mounted
In reply to Luke Nowakowski-KrijgerMounting the v1 blkio controller while v2 io controller is mounted unmounts the io controller, triggering a tst_brk that the number of controller has gone down.
Because these controllers don't seem to be compatible, tst_brk with TCONF and report that we refused to mount the blkio controller while the io controller is mounted.
--- lib/tst_cgroup.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/tst_cgroup.c +5 -0
@@ -691,6 +691,11 @@ static void cgroup_mount_v1(struct cgroup_ctrl *const ctrl)char mnt_path[PATH_MAX ];int made_dir =0 ; +if (ctrl->ctrl_indx ==CTRL_BLKIO && controllers[CTRL_IO ].ctrl_root) { +tst_brk (TCONF , +"IO controller found on V2 root, skipping blkio mount that would unmount IO controller" ); + } +sprintf (mnt_path,"%s%s" , cgroup_mount_ltp_prefix, ctrl->ctrl_name);if (!mkdir (mnt_path,0777 )) {
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 06/16] API/cgroup: refuse to mount blkio when io controller is mounted
Quoted 20 lines · Luke Nowakowski-Krijger
Mounting the v1 blkio controller while v2 io controller is mounted unmounts the io controller, triggering a
tst_brkthat the number of controller has gone down.Because these controllers don't seem to be compatible,
tst_brkwith TCONF and report that we refused to mount the blkio controller while the io controller is mounted.Signed-off-by: Luke Nowakowski-Krijger <
[email protected]>--- lib/tst_cgroup.c | 5 +++++ 1 file changed, 5 insertions(+)lib/tst_cgroup.c +0
-0
lib/tst_cgroup.c static void cgroup_mount_v1(struct cgroup_ctrl *const · line 700
Quoted 10 lines
lib/tst_cgroup.c +4
-0@@ -691,6 +691,11 @@ static void cgroup_mount_v1(struct cgroup_ctrl *const ctrl)char mnt_path[PATH_MAX ];int made_dir =0 ; + if (ctrl->ctrl_indx == CTRL_BLKIO && controllers[CTRL_IO].ctrl_root) { + tst_brk(TCONF, + "IO controller found on V2 root, skipping blkio mount that would unmount IO controller"); + }
Although we do a TCONF break here, there is still a need to check tst_cgctl return value in cgroup_require(). Otherwise, test report failure like below:
tst_cgroup.c:702: TCONF: IO controller found on V2 root, skipping blkio mount that would unmount IO controllercgroup_fj_function 1 TBROK: cgroup_require: No state was set after call. Controller 'blkio' maybe does not exist?
Quoted 9 lines
lib/tst_cgroup.c +1
-0+sprintf(mnt_path, "%s%s",
cgroup_mount_ltp_prefix,ctrl->ctrl_name);if (!mkdir(mnt_path, 0777)) {--
2.32.0
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 7/16 testcases/lib: Implement tst_cgctl binary
In reply to Luke Nowakowski-KrijgerImplement a binary utility that creates an interface to make calls to the cgroup C API.
This will effectively allow shell scripts to make calls to the cgroup C api.
---
v2: Add license identifier and copyright.
Reformat with tabs instead of spaces.
Add help format message and help function.
Add error gotos to streamline error messaging.
testcases/lib/Makefile | 2 +- testcases/lib/tst_cgctl.c | 87 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 testcases/lib/tst_cgctl.c
testcases/lib/Makefile +1 -1
@@ -12,6 +12,6 @@ MAKE_TARGETS := tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\ tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\ tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\ tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\ - tst_check_kconfigs + tst_check_kconfigs tst_cgctl include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/lib/tst_cgctl.c new file +87 -0
87 lines not on this page · raw message
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 9/16 controllers: Update cgroup_fj_* to use newer cgroup lib and test lib
In reply to Luke Nowakowski-KrijgerUpdate the cgroup_fj_* tests to use the newer test lib and to use the updated version of the cgroup lib which handles mounting and unmounting for both v1 and v2 controllers.
The tests were modified to accommodate testing the v2 controller interfaces where it still made sense, and in other places tests were skipped as they were testing using specific parts of the v1 interface that doesn't exist on v2 controllers.
Also updated the licensing info at the beginning of the file with SPDX license identifier.
---
v2: Remove exist_subsystem() function.
Correct spelling mistakes in commit message.
Change version numbers to "2" instead of "v2"
.../controllers/cgroup_fj/cgroup_fj_common.sh | 113 ++++-------- .../cgroup_fj/cgroup_fj_function.sh | 169 ++++++++++-------- .../controllers/cgroup_fj/cgroup_fj_proc.c | 24 +-- .../controllers/cgroup_fj/cgroup_fj_stress.sh | 168 ++++++++--------- 4 files changed, 214 insertions(+), 260 deletions(-)
testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh +31 -82
@@ -1,43 +1,19 @@ #!/bin/sh - -################################################################################ -## ## -## Copyright (c) 2009 FUJITSU LIMITED ## -## Author: Shi Weihua <[email protected]> ## -## Copyright (c) 2015 Cedric Hnyda <[email protected]> ## -## Copyright (c) 2015-2016 Cyril Hrubis <[email protected]> ## -## ## -## This program is free software; you can redistribute it and#or modify ## -## it under the terms of the GNU General Public License as published by ## -## the Free Software Foundation; either version 2 of the License, or ## -## (at your option) any later version. ## -## ## -## This program is distributed in the hope that it will be useful, but ## -## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## -## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## -## for more details. ## -## ## -## You should have received a copy of the GNU General Public License ## -## along with this program; if not, write to the Free Software Foundation, ## -## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## -## ## -################################################################################ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2009 FUJITSU LIMITED +# Copyright (c) 2015 Cedric Hnyda <[email protected]> +# Copyright (c) 2015-2016 Cyril Hrubis <[email protected]> +# Author: Shi Weihua <[email protected]> for arg; do TCID="${TCID}_$arg" done -. test.sh - -exist_subsystem() -{ - local subsystem="$1" - local exist=`grep -w $subsystem /proc/cgroups | cut -f1` +TST_NEEDS_CMDS="rmdir killall" +TST_NEEDS_ROOT=1 +TST_NEEDS_TMPDIR=1 - if [ -z "$exist" ]; then - tst_brkm TCONF "Subsystem $subsystem not supported" - fi -} +. cgroup_lib.sh attach_and_check() {
@@ -46,13 +22,13 @@ attach_and_check() local task shift - tst_resm TINFO "Attaching task $pid to $path" + tst_res TINFO "Attaching task $pid to $path" - ROD echo "$pid" \> "$path/tasks" + ROD echo "$pid" \> "$path/$task_list" - for task in $(cat "$path/tasks"); do + for task in $(cat "$path/$task_list"); do if [ "$task" -ne "$pid" ]; then - tst_resm TINFO "Unexpected pid $task in $path/tasks, expected $pid" + tst_res TINFO "Unexpected pid $task in $path/$task_list, expected $pid" return 1 fi done
@@ -64,11 +40,13 @@ create_subgroup() { path="$1" - ROD mkdir "$path" + [ ! -d "$path" ] && ROD mkdir "$path" # cpuset.cpus and cpuset.mems must be initialized with suitable value - # before any pids are attached - if [ "$subsystem" = "cpuset" ]; then + # before any pids are attached. + # Only needs to be done for cgroup v1 as sets are inherited from parents + # by default in cgroup v2. + if [ "$cgroup_version" = "1" ] && [ "$subsystem" = "cpuset" ]; then if [ -e "$mount_point/cpus" ]; then ROD cat "$mount_point/cpus" \> "$path/cpus" ROD cat "$mount_point/mems" \> "$path/mems"
@@ -79,54 +57,25 @@ create_subgroup() fi } - -setup() +common_setup() { - tst_require_root - tst_require_cmds killall - - if [ ! -f /proc/cgroups ]; then - tst_brkm TCONF "Kernel does not support for control groups" - fi - - exist_subsystem "$subsystem" - - tst_tmpdir - TST_CLEANUP=cleanup - - mount_point=`grep -w $subsystem /proc/mounts | grep -w "cgroup" | \ - cut -f 2 | cut -d " " -f2` - - if [ -z "$mount_point" ]; then - try_umount=1 - mount_point="/dev/cgroup" - tst_resm TINFO "Subsystem $subsystem is not mounted, mounting it at $mount_point" - ROD mkdir $mount_point - ROD mount -t cgroup -o "$subsystem" "ltp_cgroup" "$mount_point" - else - tst_resm TINFO "Subsystem $subsystem is mounted at $mount_point" - fi + cgroup_require "$subsystem" + mount_point=$(cgroup_get_mountpoint "$subsystem") + start_path=$(cgroup_get_test_path "$subsystem") + cgroup_version=$(cgroup_get_version "$subsystem") + task_list=$(cgroup_get_task_list "$subsystem") + + [ "$cgroup_version" = "2" ] && ROD echo "+$subsystem" \> "$start_path/cgroup.subtree_control" + tst_res TINFO "test starts with cgroup version $cgroup_version" } -cleanup() +common_cleanup() { - tst_rmdir - killall -9 cgroup_fj_proc >/dev/null 2>&1 - tst_resm TINFO "Removing all ltp subgroups..." + tst_res TINFO "Removing all ltp subgroups..." - find "$mount_point/ltp/" -depth -type d -exec rmdir '{}' \; + [ -d "$start_path" ] && find "$start_path" -depth -type d -exec rmdir '{}' \; - if [ -z "$try_umount" ]; then - return - fi - - if grep -q "$mount_point" /proc/mounts; then - EXPECT_PASS umount "$mount_point" - fi - - if [ -e "$mount_point" ]; then - EXPECT_PASS rmdir "$mount_point" - fi + cgroup_cleanup }
testcases/kernel/controllers/cgroup_fj/cgroup_fj_function.sh +96 -73
296 lines not on this page · raw message
testcases/kernel/controllers/cgroup_fj/cgroup_fj_proc.c +3 -21
@@ -1,24 +1,6 @@ -/******************************************************************************/ -/* */ -/* Copyright (c) 2009 FUJITSU LIMITED */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* Author: Shi Weihua <[email protected]> */ -/* */ -/******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2009 FUJITSU LIMITED +// Author: Shi Weihua <[email protected]> #include <sys/types.h> #include <sys/wait.h>
testcases/kernel/controllers/cgroup_fj/cgroup_fj_stress.sh +84 -84
209 lines not on this page · raw message
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 10/16 controllers: Update memcg_control_test to newer test lib and cgroup lib
In reply to Luke Nowakowski-KrijgerUpdate memcg_control_test to use the newer test lib and to use the newer cgroup lib which enables the memory v1 and v2 controller to be tested.
Also updated to newer SPDX license identifier.
---
v2: Change version numbers to 2 instead of v2
.../controllers/memcg/control/mem_process.c | 28 +--- .../memcg/control/memcg_control_test.sh | 150 +++++------------- 2 files changed, 40 insertions(+), 138 deletions(-)
testcases/kernel/controllers/memcg/control/mem_process.c +3 -25
@@ -1,28 +1,6 @@ -/*****************************************************************************/ -/* */ -/* Copyright (c) 2010 Mohamed Naufal Basheer */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* File: mem_process.c */ -/* */ -/* Purpose: act as a memory hog for the memcg_control tests */ -/* */ -/* Author: Mohamed Naufal Basheer <[email protected] > */ -/* */ -/*****************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2010 Mohamed Naufal Basheer +// Author: Mohamed Naufal Basheer #include <sys/types.h> #include <sys/mman.h>
testcases/kernel/controllers/memcg/control/memcg_control_test.sh +37 -113
189 lines not on this page · raw message
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 11/16 controllers: Update memcg/regression/* to new test and cgroup lib
In reply to Luke Nowakowski-KrijgerUpdate the tests in memcg/regression/* to use the new test lib and the newer cgroup lib to enable testing when either v1 or v2 memory controller is mounted. Only some tests still made sense to be testing with the v2 memory controller, otherwise they were skipped.
Also updated to the newer SPDX license identifier.
---
v2: change version numbers to 2 instead of v2.
Update to use new cg_init() and test_cg variable in memcg_test_3.c
.../memcg/regression/memcg_regression_test.sh | 202 +++++++++--------- .../memcg/regression/memcg_test_1.c | 40 ++-- .../memcg/regression/memcg_test_2.c | 24 +-- .../memcg/regression/memcg_test_3.c | 38 ++-- .../memcg/regression/memcg_test_4.c | 24 +-- .../memcg/regression/memcg_test_4.sh | 50 ++--- 6 files changed, 160 insertions(+), 218 deletions(-)
testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh +104 -98
@@ -1,50 +1,18 @@ #! /bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2009 FUJITSU LIMITED +# Author: Li Zefan <[email protected]> +# Added memcg enable/disable functionality: Rishikesh K Rajak <[email protected]> -################################################################################ -## ## -## Copyright (c) 2009 FUJITSU LIMITED ## -## ## -## This program is free software; you can redistribute it and#or modify ## -## it under the terms of the GNU General Public License as published by ## -## the Free Software Foundation; either version 2 of the License, or ## -## (at your option) any later version. ## -## ## -## This program is distributed in the hope that it will be useful, but ## -## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## -## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## -## for more details. ## -## ## -## You should have received a copy of the GNU General Public License ## -## along with this program; if not, write to the Free Software ## -## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## -## ## -## Author: Li Zefan <[email protected]> ## -## Added memcg enable/disable functinality: Rishikesh K Rajak ## -## <[email protected] ## -## ## -################################################################################ - -cd $LTPROOT/testcases/bin - -export TCID="memcg_regression_test" -export TST_TOTAL=4 -export TST_COUNT=1 - -if [ "$(id -ru)" != 0 ]; then - tst_brkm TBROK ignored "Test must be run as root" - exit 0 -fi - -if [ "x$(grep -w memory /proc/cgroups | cut -f4)" != "x1" ]; then - tst_resm TCONF "Either memory resource controller kernel support absent" - tst_resm TCONF "or feature is not enabled; skipping all memcgroup testcases." - exit 0 -fi - -if tst_kvcmp -lt "2.6.30"; then - tst_brkm TBROK ignored "Test should be run with kernel 2.6.30 or newer" - exit 0 -fi +TST_ID="memcg_regression_test" +TST_CLEANUP=cleanup +TST_SETUP=setup +TST_TESTFUNC=test_ +TST_NEEDS_ROOT=1 +TST_NEEDS_CMDS="killall kill" +TST_CNT=4 + +. cgroup_lib.sh #buffer can rotate and number of found bugs can actually go down #so clear the buffer to avoid this
@@ -70,16 +38,16 @@ check_kernel_bug() # some kernel bug is detected if [ $new_bug -gt $nr_bug ]; then - tst_resm TFAIL "kernel BUG was detected!" + tst_res TFAIL "kernel BUG was detected!" fi if [ $new_warning -gt $nr_warning ]; then - tst_resm TFAIL "kernel WARNING was detected!" + tst_res TFAIL "kernel WARNING was detected!" fi if [ $new_null -gt $nr_null ]; then - tst_resm "kernel NULL pointer dereference!" + tst_res TWARN "kernel NULL pointer dereference!" fi if [ $new_lockdep -gt $nr_lockdep ]; then - tst_resm "kernel lockdep warning was detected!" + tst_res TWARN "kernel lockdep warning was detected!" fi nr_bug=$new_bug
@@ -89,10 +57,49 @@ check_kernel_bug() echo "check_kernel_bug found something!" dmesg - failed=1 return 0 } +setup() +{ + if tst_kvcmp -lt "2.6.30"; then + tst_brk TBROK "Test should be run with kernel 2.6.30 or newer" + fi + + cgroup_require "memory" + cgroup_version=$(cgroup_get_version "memory") + mount_point=$(cgroup_get_mountpoint "memory") + test_dir=$(cgroup_get_test_path "memory") + task_list=$(cgroup_get_task_list "memory") + if [ "$cgroup_version" = "2" ]; then + memory_limit="memory.max" + else + memory_limit="memory.limit_in_bytes" + fi + + [ "$cgroup_version" = "2" ] && ROD echo "+memory" \> "$test_dir/cgroup.subtree_control" + + tst_res TINFO "test starts with cgroup version $cgroup_version" +} + +cleanup() +{ + cleanup_testpath "$test_dir/0" + cgroup_cleanup +} + +create_testpath() +{ + local path="$1" + [ ! -e "$path" ] && ROD mkdir "$path" +} + +cleanup_testpath() +{ + local path="$1" + [ -e "$path" ] && ROD rmdir "$path" +} + #--------------------------------------------------------------------------- # Bug: The bug was, while forking mass processes, trigger memcgroup OOM, # then NULL pointer dereference may be hit.
@@ -102,16 +109,19 @@ check_kernel_bug() #--------------------------------------------------------------------------- test_1() { - mkdir memcg/0/ - echo 0 > memcg/0/memory.limit_in_bytes + local test_path + test_path="$test_dir/0" - ./memcg_test_1 + create_testpath "$test_path" + ROD echo 0 > "$test_path/$memory_limit" - rmdir memcg/0/ + ./memcg_test_1 "$test_path/$task_list" + + cleanup_testpath "$test_path" check_kernel_bug if [ $? -eq 1 ]; then - tst_resm TPASS "no kernel bug was found" + tst_res TPASS "no kernel bug was found" fi }
@@ -124,19 +134,31 @@ test_1() #--------------------------------------------------------------------------- test_2() { + local test_path + + # for cgroup2 writing to memory.max first checks the new limit against the + # current usage and will start killing processes if oom, therefore we do not + # expect EBUSY to be returned by the shrink operation. + if [ "$cgroup_version" = "2" ]; then + tst_res TCONF "Cgroup v2 found, skipping test" + return + fi + + test_path="$test_dir/0" + ./memcg_test_2 & pid1=$! sleep 1 - mkdir memcg/0 - echo $pid1 > memcg/0/tasks + create_testpath "$test_path" + ROD echo $pid1 > "$test_path"/tasks # let pid1 'test_2' allocate memory /bin/kill -SIGUSR1 $pid1 sleep 1 # shrink memory - echo 1 > memcg/0/memory.limit_in_bytes 2>&1 & + echo 1 > "$test_path"/memory.limit_in_bytes 2>&1 & pid2=$! # check if 'echo' will exit and exit with failure
@@ -146,26 +168,25 @@ test_2() if [ $? -ne 0 ]; then wait $pid2 if [ $? -eq 0 ]; then - tst_resm TFAIL "echo should return failure" - failed=1 + tst_res TFAIL "echo should return failure" kill -9 $pid1 $pid2 > /dev/null 2>&1 wait $pid1 $pid2 - rmdir memcg/0 + cleanup_testpath "$test_path" + return fi break fi done if [ $tmp -eq 5 ]; then - tst_resm TFAIL "'echo' doesn't exit!" - failed=1 + tst_res TFAIL "'echo' doesn't exit!" else - tst_resm TPASS "EBUSY was returned as expected" + tst_res TPASS "EBUSY was returned as expected" fi kill -9 $pid1 $pid2 > /dev/null 2>&1 wait $pid1 $pid2 > /dev/null 2>&1 - rmdir memcg/0 + cleanup_testpath "$test_path" } #---------------------------------------------------------------------------
@@ -176,19 +197,22 @@ test_2() #--------------------------------------------------------------------------- test_3() { - mkdir memcg/0 - for pid in `cat memcg/tasks`; do - echo $pid > memcg/0/tasks 2> /dev/null + local test_path + test_path="$test_dir/0" + create_testpath "$test_path" + + for pid in $(cat "$mount_point/$task_list"); do + echo $pid > "$test_path/$task_list" 2> /dev/null done - for pid in `cat memcg/0/tasks`; do - echo $pid > memcg/tasks 2> /dev/null + for pid in $(cat "$test_path/$task_list"); do + echo $pid > "$mount_point/$task_list" 2> /dev/null done - rmdir memcg/0 + cleanup_testpath "$test_path" check_kernel_bug if [ $? -eq 1 ]; then - tst_resm TPASS "no kernel bug was found" + tst_res TPASS "no kernel bug was found" fi }
@@ -200,11 +224,15 @@ test_3() #--------------------------------------------------------------------------- test_4() { - ./memcg_test_4.sh + local test_path + test_path="$test_dir/0" + create_testpath "$test_path" + + ./memcg_test_4.sh "$cgroup_version" "$mount_point" "$test_path" check_kernel_bug if [ $? -eq 1 ]; then - tst_resm TPASS "no kernel bug was found" + tst_res TPASS "no kernel bug was found" fi # test_4.sh might be killed by oom, so do clean up here
@@ -212,31 +240,9 @@ test_4() 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 + cleanup_testpath "$test_path" swapon -a } -# main -failed=0 -mkdir memcg/ - -for cur in $(seq 1 $TST_TOTAL); do - export TST_COUNT=$cur - - mount -t cgroup -o memory xxx memcg/ - if [ $? -ne 0 ]; then - tst_resm TFAIL "failed to mount memory subsystem" - failed=1 - continue - fi - - test_$cur - - umount memcg/ -done - -rmdir memcg/ - -exit $failed - +tst_run
testcases/kernel/controllers/memcg/regression/memcg_test_1.c +15 -25
@@ -1,24 +1,6 @@ -/******************************************************************************/ -/* */ -/* Copyright (c) 2009 FUJITSU LIMITED */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* Author: Li Zefan <[email protected]> */ -/* */ -/******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2009 FUJITSU LIMITED +// Author: Li Zefan <[email protected]> #include <stdio.h> #include <stdlib.h>
@@ -33,17 +15,25 @@#define FORKED_PROC_COUNT 10 -int main (void ) +int main (int argc,char *argv[]) {char buf[10 ];int i;int loop;int pid; +int fd;int size =getpagesize (); -int fd =open ("memcg/0/tasks" ,O_WRONLY ); -if (fd <0 ) -return 1 ; +if (argc !=2 ) { +perror ("Invalid num of args" ); +exit (1 ); + } + + fd =open (argv[1 ],O_WRONLY ); +if (fd <0 ) { +perror ("Could not open tasklist" ); +exit (1 ); + }for (loop =0 ; loop <LOOP ; loop++) {for (i =0 ; i <FORKED_PROC_COUNT ; i++) {
testcases/kernel/controllers/memcg/regression/memcg_test_2.c +3 -21
@@ -1,24 +1,6 @@ -/******************************************************************************/ -/* */ -/* Copyright (c) 2009 FUJITSU LIMITED */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* Author: Li Zefan <[email protected]> */ -/* */ -/******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2009 FUJITSU LIMITED +// Author: Li Zefan <[email protected]> #include <sys/mman.h> #include <signal.h>
testcases/kernel/controllers/memcg/regression/memcg_test_3.c +15 -23
@@ -17,12 +17,10 @@#include <sys/types.h> #include <sys/mount.h> #include "tst_test.h" +#include "tst_cgroup.h" -#define MNTPOINT "memcg" -#define SUBDIR "memcg/testdir" - -static int mount_flag;static volatile int sigcounter; +static struct tst_cg_group *test_cg; static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) {
@@ -48,9 +46,10 @@ static void do_test(void)do_child ();while (sigcounter <50000 ) { -if (access (SUBDIR ,F_OK )) -SAFE_MKDIR (SUBDIR ,0644 ); -rmdir (SUBDIR ); + test_cg =tst_cg_group_mk (tst_cg,"test" ); + +if (test_cg) + test_cg =tst_cg_group_rm (test_cg); }SAFE_KILL (cpid,SIGKILL );
@@ -61,32 +60,25 @@ static void do_test(void)static void setup (void ) { -int ret; - -SAFE_MKDIR (MNTPOINT ,0644 ); +struct tst_cg_opts opts; +memset (&opts,0 ,sizeof (opts)); - ret =mount ("memcg" ,MNTPOINT ,"cgroup" ,0 ,"memory" ); -if (ret) { -if (errno ==ENOENT ) -tst_brk (TCONF |TERRNO ,"memcg not supported" ); - -tst_brk (TCONF |TERRNO ,"mounting memcg failed" ); - } - mount_flag =1 ; +tst_cg_require ("memory" , &opts); +tst_cg_init (); +if (TST_CG_VER (tst_cg,"memory" ) !=TST_CG_V1 ) +SAFE_CG_PRINT (tst_cg,"cgroup.subtree_control" ,"+memory" ); }static void cleanup (void ) { -if (!access (SUBDIR ,F_OK )) -SAFE_RMDIR (SUBDIR ); +if (test_cg) + test_cg =tst_cg_group_rm (test_cg); -if (mount_flag) -tst_umount (MNTPOINT ); +tst_cg_cleanup (); }static struct tst_test test = { .needs_root =1 , - .needs_tmpdir =1 , .forks_child =1 , .min_kver ="2.6.24" , .setup = setup,
testcases/kernel/controllers/memcg/regression/memcg_test_4.c +3 -21
@@ -1,24 +1,6 @@ -/******************************************************************************/ -/* */ -/* Copyright (c) 2009 FUJITSU LIMITED */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* Author: Li Zefan <[email protected]> */ -/* */ -/******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2009 FUJITSU LIMITED +// Author: Li Zefan <[email protected]> #include <sys/mman.h> #include <err.h>
testcases/kernel/controllers/memcg/regression/memcg_test_4.sh +20 -30
64 lines not on this page · raw message
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 12/16 controllers: Update memcg_stress_test to use newer cgroup lib
In reply to Luke Nowakowski-KrijgerUpdate the test to use the newer cgroup lib which enables the testing of both v1 and v2 memory controllers and makes the setup and cleanup much simpler.
---
v2: Use version number 2 instead of v2
.../memcg/stress/memcg_stress_test.sh | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-)
testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh +12 -20
@@ -23,10 +23,16 @@ TST_TIMEOUT=2100 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") + test_path=$(cgroup_get_test_path "memory") + task_list=$(cgroup_get_task_list "memory") + if [ "$cgroup_version" = "2" ]; then + ROD echo "+memory" > "$test_path/cgroup.subtree_control" fi + tst_res TINFO "test starts with cgroup version $cgroup_version" + echo 3 > /proc/sys/vm/drop_caches sleep 2 local mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'`
@@ -43,18 +49,7 @@ setup() cleanup() { - if [ -e /dev/memcg ]; then - EXPECT_PASS umount /dev/memcg - EXPECT_PASS rmdir /dev/memcg - fi -} - -do_mount() -{ - cleanup - - EXPECT_PASS mkdir /dev/memcg - EXPECT_PASS mount -t cgroup -omemory memcg /dev/memcg + cgroup_cleanup } # $1 Number of cgroups
@@ -71,13 +66,11 @@ run_stress() tst_res TINFO "Testing $cgroups cgroups, using $mem_size MB, interval $interval" - do_mount - tst_res TINFO "Starting cgroups" for i in $(seq 0 $(($cgroups-1))); do - mkdir /dev/memcg/$i 2> /dev/null + ROD mkdir "$test_path/$i" memcg_process_stress $mem_size $interval & - echo $! > /dev/memcg/$i/tasks + ROD echo $! > "$test_path/$i/$task_list" pids="$pids $!" done
@@ -93,12 +86,11 @@ run_stress() for pid in $pids; do kill -KILL $pid 2> /dev/null wait $pid 2> /dev/null - rmdir /dev/memcg/$i 2> /dev/null + ROD rmdir "$test_path/$i" i=$((i+1)) done tst_res TPASS "Test passed" - cleanup } test1()
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 13/16 controllers: update memcg/functional to use newer cgroup lib
In reply to Luke Nowakowski-KrijgerUpdate 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.
---
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(-)
testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh +1 -1
@@ -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
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +29 -25
113 lines not on this page · raw message
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 8/16 controllers: Expand cgroup_lib shell library
In reply to Luke Nowakowski-KrijgerExpand the cgroup_lib library by using the tst_cgctl binary utility to make calls to the Cgroup C API to simplify and centralize the mounting and cleanup process of Cgroups
---
v2: Add "^" to propery grep the correct mountpoint.
Removed is_cgroup_enabled_and_available function and put the check in cgroup_require().
Check if /proc/cgroups exists in cgroup_require(). Change to TCONF if controllers not available.
v3: Add copyright.
Change awks to grab new config variables.
Change version from v2 to just 2 to match config variables.
testcases/kernel/controllers/cgroup_lib.sh | 129 +++++++++++++++++---- 1 file changed, 109 insertions(+), 20 deletions(-)
testcases/kernel/controllers/cgroup_lib.sh +109 -20
@@ -2,38 +2,127 @@ # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (c) 2019 Petr Vorel <[email protected]> # Copyright (c) 2018-2019 ARM Ltd. All Rights Reserved. +# Copyright (c) 2022 Canonical Ltd. . tst_test.sh -# Find mountpoint to given subsystem -# get_cgroup_mountpoint SUBSYSTEM -# RETURN: 0 if mountpoint found, otherwise 1 -get_cgroup_mountpoint() +_cgroup_state= + +# Find mountpoint of the given controller +# USAGE: cgroup_get_mountpoint CONTROLLER +# RETURNS: Prints the mountpoint of the given controller +# Must call cgroup_require before calling +cgroup_get_mountpoint() +{ + local ctrl=$1 + local mountpoint + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_mountpoint: controller not defined" + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_get_mountpoint: No previous state found. Forgot to call cgroup_require?" + + mountpoint=$(echo "$_cgroup_state" | grep -w "^$ctrl" | awk '{ print $4 }') + echo "$mountpoint" + + return 0 +} + +# Get the test path of a given controller that has been created by the cgroup C API +# USAGE: cgroup_get_test_path CONTROLLER +# RETURNS: Prints the path to the test direcory +# Must call cgroup_require before calling +cgroup_get_test_path() +{ + local ctrl="$1" + local mountpoint + local test_path + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_test_path: controller not defined" + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_get_test_path: No previous state found. Forgot to call cgroup_require?" + + mountpoint=$(cgroup_get_mountpoint "$ctrl") + + test_path="$mountpoint/ltp/test-$$" + + [ ! -e "$test_path" ] && tst_brk TBROK "cgroup_get_test_path: No test path found. Forgot to call cgroup_require?" + + echo "$test_path" + + return 0 +} + +# Gets the cgroup version of the given controller +# USAGE: cgroup_get_version CONTROLLER +# RETURNS: "1" if version 1 and "2" if version 2 +# Must call cgroup_require before calling +cgroup_get_version() +{ + local ctrl="$1" + local version + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_version: controller not defined" + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_get_version: No previous state found. Forgot to call cgroup_require?" + + version=$(echo "$_cgroup_state" | grep -w "^$ctrl" | awk '{ print $2 }') + [ "$version" = "" ] && tst_brk TBROK "cgroup_get_version: Could not find controller $ctrl" + + echo "$version" + + return 0 +} + +# Cleans up any setup done by calling cgroup_require. +# USAGE: cgroup_cleanup +# Can be safely called even when no setup has been done +cgroup_cleanup() { - local subsystem=$1 - local mntpoint + [ "$_cgroup_state" = "" ] && return 0 - [ $# -eq 0 ] && tst_brk TBROK "get_cgroup_mountpoint: subsystem not defined" + tst_cgctl cleanup "$_cgroup_state" - mntpoint=$(grep cgroup /proc/mounts | grep -w $subsystem | awk '{ print $2 }') - [ -z "$mntpoint" ] && return 1 + _cgroup_state="" - echo $mntpoint return 0 } -# Check if given subsystem is supported and enabled -# is_cgroup_subsystem_available_and_enabled SUBSYSTEM -# RETURN: 0 if subsystem supported and enabled, otherwise 1 -is_cgroup_subsystem_available_and_enabled() +# Get the task list of the given controller +# USAGE: cgroup_get_task_list CONTROLLER +# RETURNS: prints out "cgroup.procs" if version 2 otherwise "tasks" +# Must call cgroup_require before calling +cgroup_get_task_list() { - local val - local subsystem=$1 + local ctrl="$1" + local version + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_task_list: controller not defined" - [ $# -eq 0 ] && tst_brk TBROK "is_cgroup_subsystem_available_and_enabled: subsystem not defined" + version=$(cgroup_get_version "$ctrl") - val=$(grep -w $subsystem /proc/cgroups | awk '{ print $4 }') - [ "$val" = "1" ] && return 0 + if [ "$version" = "2" ]; then + echo "cgroup.procs" + else + echo "tasks" + fi - return 1 + return 0 +} + +# Mounts and configures the given controller +# USAGE: cgroup_require CONTROLLER +cgroup_require() +{ + local ctrl="$1" + local exists + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_require: controller not defined" + + [ ! -f /proc/cgroups ] && tst_brk TCONF "Kernel does not support control groups" + + exists=$(grep -w $ctrl /proc/cgroups | awk '{ print $4 }') + [ "$exists" != "1" ] && tst_brk TCONF "cgroup_require: Controller not available or not enabled" + + _cgroup_state=$(tst_cgctl require "$ctrl" $$) + + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_require: No state was set after call. Controller '$ctrl' maybe does not exist?" + + return 0 }
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 08/16] controllers: Expand cgroup_lib shell library
Hello Luke,
Quoted 160 lines · Luke Nowakowski-Krijger
Expand the
cgroup_liblibrary by using thetst_cgctlbinary utility to make calls to the Cgroup C API to simplify and centralize the mounting and cleanup process of CgroupsSigned-off-by Luke Nowakowski-Krijger <[email protected]>---
v2: Add "^" to propery grep the correct mountpoint.
Removedis_cgroup_enabled_and_availablefunction and put the check incgroup_require().
Check if/proc/cgroupsexists incgroup_require(). Change to TCONF if controllers not available.
v3: Add copyright.
Change awks to grab new config variables.
Change version from v2 to just 2 to match config variables.testcases/kernel/controllers/cgroup_lib.sh | 129 +++++++++++++++++---- 1 file changed, 109 insertions(+), 20 deletions(-)testcases/kernel/controllers/cgroup_lib.sh +100
-20@@ -2,38 +2,127 @@ # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (c) 2019 Petr Vorel <[email protected]> # Copyright (c) 2018-2019 ARM Ltd. All Rights Reserved. +# Copyright (c) 2022 Canonical Ltd. . tst_test.sh -# Find mountpoint to given subsystem -# get_cgroup_mountpoint SUBSYSTEM -# RETURN: 0 if mountpoint found, otherwise 1 -get_cgroup_mountpoint() +_cgroup_state= + +# Find mountpoint of the given controller +# USAGE: cgroup_get_mountpoint CONTROLLER +# RETURNS: Prints the mountpoint of the given controller +# Must call cgroup_require before calling +cgroup_get_mountpoint() +{ + local ctrl=$1 + local mountpoint + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_mountpoint: controller not defined" + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_get_mountpoint: No previous state found. Forgot to call cgroup_require?" + + mountpoint=$(echo "$_cgroup_state" | grep -w "^$ctrl" | awk '{ print $4 }') + echo "$mountpoint" + + return 0 +} + +# Get the test path of a given controller that has been created by the cgroup C API +# USAGE: cgroup_get_test_path CONTROLLER +# RETURNS: Prints the path to the test direcory +# Must call cgroup_require before calling +cgroup_get_test_path() +{ + local ctrl="$1" + local mountpoint + local test_path + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_test_path: controller not defined" + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_get_test_path: No previous state found. Forgot to call cgroup_require?" + + mountpoint=$(cgroup_get_mountpoint "$ctrl") + + test_path="$mountpoint/ltp/test-$$" + + [ ! -e "$test_path" ] && tst_brk TBROK "cgroup_get_test_path: No test path found. Forgot to call cgroup_require?" + + echo "$test_path" + + return 0 +} + +# Gets the cgroup version of the given controller +# USAGE: cgroup_get_version CONTROLLER +# RETURNS: "1" if version 1 and "2" if version 2 +# Must call cgroup_require before calling +cgroup_get_version() +{ + local ctrl="$1" + local version + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_version: controller not defined" + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_get_version: No previous state found. Forgot to call cgroup_require?" + + version=$(echo "$_cgroup_state" | grep -w "^$ctrl" | awk '{ print $2 }') + [ "$version" = "" ] && tst_brk TBROK "cgroup_get_version: Could not find controller $ctrl" + + echo "$version" + + return 0 +} + +# Cleans up any setup done by calling cgroup_require. +# USAGE: cgroup_cleanup +# Can be safely called even when no setup has been done +cgroup_cleanup() { - local subsystem=$1 - local mntpoint + [ "$_cgroup_state" = "" ] && return 0 - [ $# -eq 0 ] && tst_brk TBROK "get_cgroup_mountpoint: subsystem not defined" + tst_cgctl cleanup "$_cgroup_state" - mntpoint=$(grep cgroup /proc/mounts | grep -w $subsystem | awk '{ print $2 }') - [ -z "$mntpoint" ] && return 1 + _cgroup_state="" - echo $mntpoint return 0 } -# Check if given subsystem is supported and enabled -# is_cgroup_subsystem_available_and_enabled SUBSYSTEM -# RETURN: 0 if subsystem supported and enabled, otherwise 1 -is_cgroup_subsystem_available_and_enabled() +# Get the task list of the given controller +# USAGE: cgroup_get_task_list CONTROLLER +# RETURNS: prints out "cgroup.procs" if version 2 otherwise "tasks" +# Must call cgroup_require before calling +cgroup_get_task_list() { - local val - local subsystem=$1 + local ctrl="$1" + local version + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_task_list: controller not defined" - [ $# -eq 0 ] && tst_brk TBROK "is_cgroup_subsystem_available_and_enabled: subsystem not defined" + version=$(cgroup_get_version "$ctrl") - val=$(grep -w $subsystem /proc/cgroups | awk '{ print $4 }') - [ "$val" = "1" ] && return 0 + if [ "$version" = "2" ]; then + echo "cgroup.procs" + else + echo "tasks" + fi - return 1 + return 0 +} + +# Mounts and configures the given controller +# USAGE: cgroup_require CONTROLLER +cgroup_require() +{ + local ctrl="$1" + local exists + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_require: controller not defined" + + [ ! -f /proc/cgroups ] && tst_brk TCONF "Kernel does not support
Quoted 1 line
control groups"
The tst_cgroup lib can handle this. Also is it guaranteed that /proc/cgroups exists if cgroups are enabled?
Quoted 4 lines
testcases/kernel/controllers/cgroup_lib.sh +3
-0+ + exists=$(grep -w $ctrl /proc/cgroups | awk '{ print $4 }') + [ "$exists" != "1" ] && tst_brk TCONF "cgroup_require:Controller not available or not enabled"
For some reason this fails on my VM where no cgroups are mounted already. Also it's redundant because tst_cgroup should handle it.
Quoted 7 lines
testcases/kernel/controllers/cgroup_lib.sh +6
-0+ + _cgroup_state=$(tst_cgctl require "$ctrl" $$) + + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_require: No state was set after call. Controller '$ctrl' maybe does not exist?" + + return 0 }
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 08/16] controllers: Expand cgroup_lib shell library
Hello,
Quoted 24 lines
Quoted 11 lines
testcases/kernel/controllers/cgroup_lib.sh +11
-0+ +# Mounts and configures the given controller +# USAGE: cgroup_require CONTROLLER +cgroup_require() +{ + local ctrl="$1" + local exists + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_require: controller not defined" + + [ ! -f /proc/cgroups ] && tst_brk TCONF "Kernel does not supportQuoted 1 line
control groups"
The
tst_cgrouplib can handle this. Also is it guaranteed that/proc/cgroupsexists if cgroups are enabled?Quoted 4 lines
testcases/kernel/controllers/cgroup_lib.sh +3
-0+ + exists=$(grep -w $ctrl /proc/cgroups | awk '{ print $4 }') + [ "$exists" != "1" ] && tst_brk TCONF "cgroup_require:Controller not available or not enabled"
For some reason this fails on my VM where no cgroups are mounted already. Also it's redundant because
tst_cgroupshould handle it.
Quoted 5 lines
testcases/kernel/controllers/cgroup_lib.sh
Quoted 4 lines
testcases/kernel/controllers/cgroup_lib.sh +4
-0+ + _cgroup_state=$(tst_cgctl require "$ctrl" $$) + + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_require: Nostate was set after call. Controller '$ctrl' maybe does not exist?"
Perhaps we can just check the return status of tst_cgctl and exit the script if it is >0?
Quoted 3 lines
Quoted 3 lines
testcases/kernel/controllers/cgroup_lib.sh +2
-0+ + return 0 }
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 08/16] controllers: Expand cgroup_lib shell library
Quoted 9 lines · Richard Palethorpe
Quoted 5 lines
testcases/kernel/controllers/cgroup_lib.sh
Quoted 4 lines
testcases/kernel/controllers/cgroup_lib.sh +4
-0+ + _cgroup_state=$(tst_cgctl require "$ctrl" $$) + + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_require: Nostate was set after call. Controller '$ctrl' maybe does not exist?"
Perhaps we can just check the return status of
tst_cgctland exit the script if it is >0?
That should be work, but we need to check the _cgrou_state at other places because many shell APIs require getting Cgroup info, I guess this does not make things more easily if check the return value only one time.
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 08/16] controllers: Expand cgroup_lib shell library
Hi Richard and Li,
Quoted 10 lines · Li Wang
Quoted 6 lines · Richard Palethorpe
Quoted 5 lines
testcases/kernel/controllers/cgroup_lib.sh
Quoted 4 lines
testcases/kernel/controllers/cgroup_lib.sh +4
-0+ + _cgroup_state=$(tst_cgctl require "$ctrl" $$) + + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_require: Nostate was set after call. Controller '$ctrl' maybe does not exist?"
Quoted 11 lines
Quoted 3 lines
Perhaps we can just check the return status of
tst_cgctland exit the script if it is >0?That should be work, but we need to check the
_cgrou_stateat other places because many shell APIs require getting Cgroup info, I guess this does not make things more easily if check the return value only one time.
An idea I had to make the failure of tst_cgctl more graceful when there is a tst_brk and when it exits is to check the return of tst_cgctl and basically just mirror the error with a better message. E.g.
tst_cgroup.c:702: TCONF: IO controller found on V2 root, skipping blkio mount that would unmount IO controllercgroup_fj_function 1 TCONF: cgroup_require: tst_cgtl require exited
Something that would look like this:
_cgroup_state=$(tst_cgctl require "$ctrl" $$)
_cgroup_check_return "$?" "cgroup_require: tst_cgctl require exited"
[ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_require: No state was set after call to tst_cgctl require?"
Where in _cgroup_check_return we would do the appropriate tst_brk for the return and then return a nice message (not exactly sure what it should be but it should be obvious that one error is caused by the other). Because if there was an error in tst_cgroup we would definitely want to break the test because the _cgroup_state was most likely not set. Then it would fall through to checking the _cgroup_state if everything looked good per normal which now should never happen if tst_cgctl returned a non error.
Let me know what you think :)
Quoted 3 lines
Regards,
Li Wang
Thanks,
- Luke
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 08/16] controllers: Expand cgroup_lib shell library
Hi Luke,
Quoted 49 lines · Luke Nowakowski-Krijger
Hi Richard and Li,
Quoted 10 lines · Li Wang
Quoted 6 lines · Richard Palethorpe
Quoted 5 lines
testcases/kernel/controllers/cgroup_lib.sh
Quoted 4 lines
testcases/kernel/controllers/cgroup_lib.sh +4
-0+ + _cgroup_state=$(tst_cgctl require "$ctrl" $$) + + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_require: Nostate was set after call. Controller '$ctrl' maybe does not exist?"
Quoted 11 lines
Quoted 3 lines
Perhaps we can just check the return status of
tst_cgctland exit the script if it is >0?That should be work, but we need to check the
_cgrou_stateat other places because many shell APIs require getting Cgroup info, I guess this does not make things more easily if check the return value only one time.An idea I had to make the failure of
tst_cgctlmore graceful when there is atst_brkand when it exits is to check the return oftst_cgctland basically just mirror the error with a better message. E.g.tst_cgroup.c:702: TCONF: IO controller found on V2 root, skipping blkio mount that would unmount IO controller
cgroup_fj_function1 TCONF:cgroup_require:tst_cgtlrequire exitedSomething that would look like this:
_cgroup_state=$(tst_cgctl require "$ctrl" $$)
_cgroup_check_return"$?" "cgroup_require:tst_cgctlrequire exited"[ "$_cgroup_state" = "" ] &&
tst_brkTBROK "cgroup_require: No state was set after call totst_cgctlrequire?"Where in
_cgroup_check_returnwe would do the appropriatetst_brkfor the return and then return a nice message (not exactly sure what it should be but it should be obvious that one error is caused by the other). Because if there was an error intst_cgroupwe would definitely want to break the test because the_cgroup_statewas most likely not set. Then it would fall through to checking the_cgroup_stateif everything looked good per normal which now should never happen iftst_cgctlreturned a non error.
Quoted 2 lines
Let me know what you think :)
That sounds good to me.
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 14/16 controllers: Update pids.sh to use newer cgroup lib
In reply to Luke Nowakowski-KrijgerUpdated to use the newer cgroup_lib to make mounting and cleanup nicer.
---
v2: Use version number 2 instead of v2
testcases/kernel/controllers/pids/pids.sh | 67 +++-------------------- 1 file changed, 9 insertions(+), 58 deletions(-)
testcases/kernel/controllers/pids/pids.sh +9 -58
@@ -13,7 +13,7 @@ TST_USAGE=usage TST_NEEDS_ROOT=1 TST_NEEDS_CMDS="killall" -. tst_test.sh +. cgroup_lib.sh caseno=$1 max=$2
@@ -38,66 +38,17 @@ cleanup() { killall -9 pids_task2 >/dev/null 2>&1 - tst_res TINFO "removing created directories" - rmdir $testpath - if [ "$mounted" -ne "1" ]; then - tst_res TINFO "Umounting pids" - umount $mount_point - rmdir $mount_point - fi -} - -setup_cgroupv2() -{ - mount_point=$(grep -w cgroup2 /proc/mounts | cut -f 2 | cut -d " " -f2) - if ! grep -q pids "$mount_point"/cgroup.controllers; then - tst_res TINFO "pids not supported on cgroup v2." - return - fi - - testpath="$mount_point/ltp_pids_$caseno" - ROD mkdir -p "$testpath" - task_list="cgroup.procs" - cgroup_v="v2" -} - -setup_cgroupv1() -{ - exist=`grep -w pids /proc/cgroups | cut -f1`; - if [ "$exist" = "" ]; then - tst_brk TCONF NULL "pids not supported" - fi - - mount_point=`grep -w pids /proc/mounts | cut -f 2 | cut -d " " -f2` - - if [ "$mount_point" = "" ]; then - mounted=0 - mount_point=/dev/cgroup - fi - - testpath=$mount_point/ltp_pids_$caseno - - if [ "$mounted" -eq "0" ]; then - ROD mkdir -p $mount_point - ROD mount -t cgroup -o pids none $mount_point - fi - ROD mkdir -p $testpath - task_list="tasks" - cgroup_v="v1" + cgroup_cleanup } setup() { - # If cgroup2 is mounted already, then let's - # try to start with cgroup v2. - if grep -q cgroup2 /proc/mounts; then - setup_cgroupv2 - fi - if [ -z "$cgroup_v" ]; then - setup_cgroupv1 - fi + cgroup_require "pids" + cgroup_version=$(cgroup_get_version "pids") + testpath=$(cgroup_get_test_path "pids") + task_list=$(cgroup_get_task_list "pids") - tst_res TINFO "test starts with cgroup $cgroup_v" + tst_res TINFO "test starts with cgroup version $cgroup_version" } start_pids_tasks2()
@@ -298,7 +249,7 @@ case8() { tst_res TINFO "set child cgroup limit smaller than its parent limit" ROD echo $max \> $testpath/pids.max - if [ "$cgroup_v" = "v2" ]; then + if [ "$cgroup_version" = "2" ]; then ROD echo +pids \> "$testpath"/cgroup.subtree_control fi mkdir $testpath/child
@@ -328,7 +279,7 @@ case9() tst_res TINFO "migrate cgroup" lim=$((max - 1)) - if [ "$cgroup_v" = "v2" ]; then + if [ "$cgroup_version" = "2" ]; then ROD echo +pids \> "$testpath"/cgroup.subtree_control fi for i in 1 2; do
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 15/16 controllers: update cpuset_regression_test.sh to use newer cgroup lib
In reply to Luke Nowakowski-KrijgerUpdate the test to use the newer cgroup lib which handles mounting for v1 and v2 controllers enabling them both to be tested and cleaning up the mounting and cleanup process.
---
v2: Change variable cgroup_v to cgroup_version
.../cpuset/cpuset_regression_test.sh | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-)
testcases/kernel/controllers/cpuset/cpuset_regression_test.sh +7 -19
@@ -123,18 +123,13 @@ cpuset_restore() setup() { - if ! is_cgroup_subsystem_available_and_enabled "cpuset"; then - tst_brk TCONF "Either kernel does not support cpuset controller or feature not enabled" - fi - - # We need to mount cpuset if it is not found. - root_cpuset_dir=$(get_cgroup_mountpoint cpuset) - if [ -z "$root_cpuset_dir" ]; then - root_cpuset_dir="$LOCAL_MOUNTPOINT" + cgroup_require "cpuset" + cgroup_version=$(cgroup_get_version "cpuset") + root_cpuset_dir=$(cgroup_get_mountpoint "cpuset") + testpath=$(cgroup_get_test_path "cpuset") + task_list=$(cgroup_get_task_list "cpuset") - ROD_SILENT mkdir -p ${root_cpuset_dir} - ROD_SILENT mount -t cpuset cpuset ${root_cpuset_dir} - fi + tst_res TINFO "test starts with cgroup version $cgroup_version" if ! [ -f ${root_cpuset_dir}/${cpu_exclusive} ]; then cpu_exclusive=cpu_exclusive
@@ -181,14 +176,7 @@ cleanup() echo ${old_cpu_exclusive_value} > ${root_cpuset_dir}/${cpu_exclusive} fi - if [ -d "$LOCAL_MOUNTPOINT" ]; then - umount ${LOCAL_MOUNTPOINT} - if [ $? -ne 0 ]; then - tst_res TWARN "'umount ${LOCAL_MOUNTPOINT}' failed" - fi - - rmdir ${LOCAL_MOUNTPOINT} - fi + cgroup_cleanup } test()
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 16/16 controllers: update cgroup_regression_test to use newer cgroup lib
In reply to Luke Nowakowski-KrijgerThe older function in the cgroup lib 'get_cgroup_mountpoint' has been removed, so instead replace it with its old functionaility to get mountpoint.
Also use the newer cgroup lib require operation to mount and cleanup a cpu controller.
--- .../cgroup/cgroup_regression_test.sh | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
testcases/kernel/controllers/cgroup/cgroup_regression_test.sh +4 -13
@@ -170,17 +170,8 @@ test3() return fi - cpu_subsys_path=$(get_cgroup_mountpoint "cpu") - - # Run the test for 30 secs - if [ -z "$cpu_subsys_path" ]; then - mount -t cgroup -o cpu xxx cgroup/ - if [ $? -ne 0 ]; then - tst_res TFAIL "Failed to mount cpu subsys" - return - fi - cpu_subsys_path=cgroup - fi + cgroup_require "cpu" + cpu_subsys_path=$(cgroup_get_mountpoint "cpu") cgroup_regression_3_1.sh $cpu_subsys_path & pid1=$!
@@ -193,7 +184,7 @@ test3() wait $pid2 2>/dev/null rmdir $cpu_subsys_path/0 2> /dev/null - tst_umount $PWD/cgroup + cgroup_cleanup check_kernel_bug }
@@ -310,7 +301,7 @@ test_7_1() # could be passed here as params and this will lead to ambiguity and # errors when grepping simply for 'debug' in /proc/mounts since we'll # find also /sys/kernel/debug. Helper takes care of this. - local subsys_path=$(get_cgroup_mountpoint $subsys) + local subsys_path=$(grep cgroup /proc/mounts | grep -w $subsys | awk '{ print $2 }') if [ -z "$subsys_path" ]; then mount -t cgroup -o $subsys xxx cgroup/
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 16/16] controllers: update cgroup_regression_test to use newer cgroup lib
Quoted 55 lines · Luke Nowakowski-Krijger
The older function in the cgroup lib '
get_cgroup_mountpoint' has been removed, so instead replace it with its old functionaility to get mountpoint.Also use the newer cgroup lib require operation to mount and cleanup a cpu controller.
Signed-off-by: Luke Nowakowski-Krijger <
[email protected]>--- .../cgroup/cgroup_regression_test.sh | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)testcases/kernel/controllers/cgroup/cgroup_regression_test.sh +3
-12@@ -170,17 +170,8 @@ test3() return fi - cpu_subsys_path=$(get_cgroup_mountpoint "cpu") - - # Run the test for 30 secs - if [ -z "$cpu_subsys_path" ]; then - mount -t cgroup -o cpu xxx cgroup/ - if [ $? -ne 0 ]; then - tst_res TFAIL "Failed to mount cpu subsys" - return - fi - cpu_subsys_path=cgroup - fi + cgroup_require "cpu" + cpu_subsys_path=$(cgroup_get_mountpoint "cpu") cgroup_regression_3_1.sh $cpu_subsys_path & pid1=$!@@ -193,7 +184,7 @@ test3() wait $pid2 2>/dev/null rmdir $cpu_subsys_path/0 2> /dev/null - tst_umount $PWD/cgroup + cgroup_cleanup check_kernel_bug }@@ -310,7 +301,7 @@ test_7_1() # could be passed here as params and this will lead to ambiguityand
# errors when grepping simply for 'debug' in /proc/mounts since we'll # find also /sys/kernel/debug. Helper takes care of this.testcases/kernel/controllers/cgroup/cgroup_regression_test.sh +1
-1- local subsys_path=$(get_cgroup_mountpoint $subsys) + local subsys_path=$(grep cgroup /proc/mounts | grep -w $subsys |
Quoted 2 lines
awk '{ print $2 }')
Why not use 'cgroup_get_mountpoint' like test3 but switch back to grep for getting the subsys path? The grep way won't work on Cgroup V2, isn't it?
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp