diff mbox series

[v2,01/16] API/cgroup: Modify tst_cgroup_print_config for easier parsing and consumption

Message ID 3e412686c9cd82cd58697b8200b6d961d7fe4af9.1642601554.git.luke.nowakowskikrijger@canonical.com
State Superseded
Headers show
Series Expand Cgroup lib and modify controller tests | expand

Commit Message

Luke Nowakowski-Krijger Jan. 19, 2022, 2:44 p.m. UTC
Prepare tst_cgroup_print_config to be more easily parsed and consumed by
shell scripts and other programs.

Also add any detected root information as well as the relevant state
associated with the roots that would be needed by the test to properly
cleanup.

Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
---
v2: Remove "mounted_drain_dir" as mounting ltp dir and drain dir happen
at the same time

 lib/tst_cgroup.c | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

Comments

Richard Palethorpe Jan. 24, 2022, 11:16 a.m. UTC | #1
Hello Luke,

Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com> writes:

> Prepare tst_cgroup_print_config to be more easily parsed and consumed by
> shell scripts and other programs.
>
> Also add any detected root information as well as the relevant state
> associated with the roots that would be needed by the test to properly
> cleanup.
>
> Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
> ---
> v2: Remove "mounted_drain_dir" as mounting ltp dir and drain dir happen
> at the same time
>
>  lib/tst_cgroup.c | 35 +++++++++++++++++++++++++++++++----
>  1 file changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
> index 2ef599d9e..704e64030 100644
> --- a/lib/tst_cgroup.c
> +++ b/lib/tst_cgroup.c
> @@ -301,12 +301,26 @@ opendir:
>  				  O_PATH | O_DIRECTORY);
>  }
>  
> +#define CONFIG_LTPDIR_KEY "Created_Ltp_Dir"
> +#define CONFIG_MOUNTROOT_KEY "Mounted_Root"
> +#define CONFIG_TESTID_KEY "Test_Id"
> +#define CONFIG_CTRL_REQUIRED "Required"
> +#define CONFIG_CTRL_HEADER "Detected Controllers:"
> +#define CONFIG_ROOT_HEADER "Detected Roots:"

Do we really need to configure these? Also why not just use the same
variable names as the C? It makes grepping them easier.

> +
> +/* Prints out the minimal internal state of the test to be consumed
> + * by tst_cgroup_load_config().
> + *
> + * The config keeps track of the minimal state needed for tst_cgroup_cleanup
> + * to cleanup after a test and does not keep track of the creation of
> + * test cgroups that might be created through tst_cgroup_group_mk().
> + */
>  void tst_cgroup_print_config(void)
>  {
>  	struct cgroup_root *root;
>  	const struct cgroup_ctrl *ctrl;
>  
> -	tst_res(TINFO, "Detected Controllers:");
> +	printf("%s\n", CONFIG_CTRL_HEADER);
>  
>  	for_each_ctrl(ctrl) {
>  		root = ctrl->ctrl_root;
> @@ -314,11 +328,24 @@ void tst_cgroup_print_config(void)
>  		if (!root)
>  			continue;
>  
> -		tst_res(TINFO, "\t%.10s %s @ %s:%s",
> +		printf("%s %s @ %s %s\n",
>  			ctrl->ctrl_name,
> -			root->no_cpuset_prefix ? "[noprefix]" : "",
>  			root->ver == TST_CGROUP_V1 ? "V1" : "V2",
> -			root->mnt_path);
> +			root->mnt_path,
> +			ctrl->we_require_it ? CONFIG_CTRL_REQUIRED : "");
> +	}
> +
> +	printf("%s\n", CONFIG_ROOT_HEADER);
> +
> +	for_each_root(root) {
> +		printf("%s %s=%s %s=%s %s=%s\n",

Perhaps we could just use tab separated values? The first row could be
the column names.

> +			root->mnt_path,
> +			CONFIG_MOUNTROOT_KEY,
> +			root->we_mounted_it ? "yes" : "no",
> +			CONFIG_LTPDIR_KEY,
> +			root->ltp_dir.we_created_it ? "yes" : "no",
> +			CONFIG_TESTID_KEY,
> +			root->test_dir.dir_name ? root->test_dir.dir_name : "NULL");
>  	}
>  }
diff mbox series

Patch

diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 2ef599d9e..704e64030 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -301,12 +301,26 @@  opendir:
 				  O_PATH | O_DIRECTORY);
 }
 
+#define CONFIG_LTPDIR_KEY "Created_Ltp_Dir"
+#define CONFIG_MOUNTROOT_KEY "Mounted_Root"
+#define CONFIG_TESTID_KEY "Test_Id"
+#define CONFIG_CTRL_REQUIRED "Required"
+#define CONFIG_CTRL_HEADER "Detected Controllers:"
+#define CONFIG_ROOT_HEADER "Detected Roots:"
+
+/* Prints out the minimal internal state of the test to be consumed
+ * by tst_cgroup_load_config().
+ *
+ * The config keeps track of the minimal state needed for tst_cgroup_cleanup
+ * to cleanup after a test and does not keep track of the creation of
+ * test cgroups that might be created through tst_cgroup_group_mk().
+ */
 void tst_cgroup_print_config(void)
 {
 	struct cgroup_root *root;
 	const struct cgroup_ctrl *ctrl;
 
-	tst_res(TINFO, "Detected Controllers:");
+	printf("%s\n", CONFIG_CTRL_HEADER);
 
 	for_each_ctrl(ctrl) {
 		root = ctrl->ctrl_root;
@@ -314,11 +328,24 @@  void tst_cgroup_print_config(void)
 		if (!root)
 			continue;
 
-		tst_res(TINFO, "\t%.10s %s @ %s:%s",
+		printf("%s %s @ %s %s\n",
 			ctrl->ctrl_name,
-			root->no_cpuset_prefix ? "[noprefix]" : "",
 			root->ver == TST_CGROUP_V1 ? "V1" : "V2",
-			root->mnt_path);
+			root->mnt_path,
+			ctrl->we_require_it ? CONFIG_CTRL_REQUIRED : "");
+	}
+
+	printf("%s\n", CONFIG_ROOT_HEADER);
+
+	for_each_root(root) {
+		printf("%s %s=%s %s=%s %s=%s\n",
+			root->mnt_path,
+			CONFIG_MOUNTROOT_KEY,
+			root->we_mounted_it ? "yes" : "no",
+			CONFIG_LTPDIR_KEY,
+			root->ltp_dir.we_created_it ? "yes" : "no",
+			CONFIG_TESTID_KEY,
+			root->test_dir.dir_name ? root->test_dir.dir_name : "NULL");
 	}
 }