All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com,
	pvorel@suse.cz, chrubis@suse.cz
Subject: [LTP] [PATCH v2 09/18] testcases/lib: Implement tst_cgctl binary
Date: Thu, 21 Jul 2022 13:52:19 -0700	[thread overview]
Message-ID: <d9b6784f8e3fa3e4d9486bc54a2e230a313edd84.1658433280.git.luke.nowakowskikrijger@canonical.com> (raw)
In-Reply-To: <cover.1658433280.git.luke.nowakowskikrijger@canonical.com>

Implement 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.

Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
---
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

diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index f2de0c832..f4f8c8524 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -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
diff --git a/testcases/lib/tst_cgctl.c b/testcases/lib/tst_cgctl.c
new file mode 100644
index 000000000..4f4fe8542
--- /dev/null
+++ b/testcases/lib/tst_cgctl.c
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 Canonical Ltd.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include "tst_cgroup.h"
+
+#define USAGE "Usage: tst_cgctl require [controller] [test_pid]\n\
+	\t cleanup [config (output of tst_cg_print_config)]\n\
+	\t print\n\
+	\t help\n"
+
+static int cgctl_require(const char *ctrl, int test_pid)
+{
+	struct tst_cg_opts opts;
+
+	memset(&opts, 0, sizeof(opts));
+	opts.test_pid = test_pid;
+
+	tst_cg_require(ctrl, &opts);
+	tst_cg_print_config();
+
+	return 0;
+}
+
+static int cgctl_cleanup(const char *const config)
+{
+	tst_cg_scan();
+	tst_cg_load_config(config);
+	tst_cg_cleanup();
+
+	return 0;
+}
+
+static int cgctl_print(void)
+{
+	tst_cg_scan();
+	tst_cg_print_config();
+
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	int test_pid;
+	const char *cmd_name = argv[1];
+
+	if (argc < 2)
+		goto error;
+
+	if (!strcmp(cmd_name, "require")) {
+		if (argc != 4)
+			goto arg_num_error;
+		test_pid = atoi(argv[3]);
+		if (!test_pid) {
+			fprintf(stderr, "tst_cgctl: Invalid test_pid '%s' given\n",
+				argv[3]);
+			goto error;
+		}
+		return cgctl_require(argv[2], test_pid);
+	} else if (!strcmp(cmd_name, "cleanup")) {
+		if (argc != 3)
+			goto arg_num_error;
+		return cgctl_cleanup(argv[2]);
+	} else if (!strcmp(cmd_name, "print")) {
+		return cgctl_print();
+	} else if (!strcmp(cmd_name, "help")) {
+		printf(USAGE);
+		return 0;
+	}
+
+	fprintf(stderr, "tst_cgctl: Unknown command '%s' given\n", cmd_name);
+	goto error;
+
+arg_num_error:
+	fprintf(stderr,
+		"tst_cgctl: Invalid number of arguments given for command '%s'\n",
+		cmd_name);
+error:
+	fprintf(stderr, USAGE);
+	return 1;
+}
-- 
2.34.1


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

  parent reply	other threads:[~2022-07-21 20:55 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21 20:52 [LTP] [PATCH v5 00/18] Expand Cgroup lib and modify controller tests Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v3 01/18] API/cgroup: Modify tst_cg_print_config for parsing and consumption Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH 02/18] API/cgroup: Add option for specific pid to tst_cg_opts Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v2 03/18] API/cgroup: Add cgroup_find_root helper function Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH 04/18] API/cgroup: Add CTRL_NAME_MAX define Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v2 05/18] tst_test_macros: Add TST_TO_STR and TST_STR macro Luke Nowakowski-Krijger
2022-07-26 14:44   ` Petr Vorel
2022-07-21 20:52 ` [LTP] [PATCH v5 06/18] API/cgroup: Implement tst_cg_load_config Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v3 07/18] API/cgroup: Add more controllers to tst_cgroup Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v2 08/18] API/cgroup: refuse to mount blkio when io controller is mounted Luke Nowakowski-Krijger
2022-07-26 14:40   ` Petr Vorel
2022-07-21 20:52 ` Luke Nowakowski-Krijger [this message]
2022-07-26 12:48   ` [LTP] [PATCH v2 09/18] testcases/lib: Implement tst_cgctl binary Petr Vorel
2022-07-21 20:52 ` [LTP] [PATCH v5 10/18] controllers: Expand cgroup_lib shell library Luke Nowakowski-Krijger
2022-07-26 13:12   ` Petr Vorel
2022-07-26 19:24     ` Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v3 11/18] controllers: Update cgroup_fj_* to use newer cgroup lib and test lib Luke Nowakowski-Krijger
2022-07-25 11:41   ` Richard Palethorpe
2022-07-26  6:36     ` Li Wang
2022-07-21 20:52 ` [LTP] [PATCH v3 12/18] controllers: Update memcg_control_test to newer test lib and cgroup lib Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v3 13/18] controllers: Update memcg/regression/* to new test " Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v2 14/18] controllers: Update memcg_stress_test to use newer " Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v2 15/18] controllers: update memcg/functional " Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v3 16/18] controllers: Update pids.sh " Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v2 17/18] controllers: update cpuset_regression_test.sh " Luke Nowakowski-Krijger
2022-07-21 20:52 ` [LTP] [PATCH v3 18/18] controllers: update cgroup_regression_test " Luke Nowakowski-Krijger
2022-07-26  3:33   ` Li Wang
2022-07-25  8:14 ` [LTP] [PATCH v5 00/18] Expand Cgroup lib and modify controller tests Petr Vorel
2022-07-25 20:25   ` Luke Nowakowski-Krijger
2022-07-26 13:00     ` Petr Vorel
2022-07-26  6:10 ` Li Wang
2022-07-26  8:52   ` Richard Palethorpe
2022-07-26 16:04     ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9b6784f8e3fa3e4d9486bc54a2e230a313edd84.1658433280.git.luke.nowakowskikrijger@canonical.com \
    --to=luke.nowakowskikrijger@canonical.com \
    --cc=chrubis@suse.cz \
    --cc=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    --cc=pvorel@suse.cz \
    --cc=rpalethorpe@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.