* [PATCH] selftests/cgroup: allow running a specific test with test_memcontrol
@ 2023-06-19 5:17 Yosry Ahmed
2023-06-19 5:18 ` Yosry Ahmed
0 siblings, 1 reply; 2+ messages in thread
From: Yosry Ahmed @ 2023-06-19 5:17 UTC (permalink / raw)
To: Roman Gushchin, Andrew Morton
Cc: Johannes Weiner, Michal Hocko, Shakeel Butt, Muchun Song,
cgroups, linux-mm, linux-kselftest, linux-kernel, Yosry Ahmed
It is handy during testing and/or debugging to be able to run a single
test from test_memcontrol. Allow passing in a test name through a
command line argument (e.g. ./test_memcontrol -t test_memcg_recharge).
Change-Id: I0e0d74d81fdd9d997987389085a816715160467f
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
---
.../selftests/cgroup/test_memcontrol.c | 30 +++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
index a2a90f4bfe9f..d8f8a13bc6c4 100644
--- a/tools/testing/selftests/cgroup/test_memcontrol.c
+++ b/tools/testing/selftests/cgroup/test_memcontrol.c
@@ -1308,9 +1308,36 @@ struct memcg_test {
int main(int argc, char **argv)
{
+ int opt;
char root[PATH_MAX];
+ int selected_test = -1;
int i, proc_status, ret = EXIT_SUCCESS;
+ while ((opt = getopt(argc, argv, "ht:")) != -1) {
+ switch (opt) {
+ case 't':
+ for (i = 0; i < ARRAY_SIZE(tests); i++) {
+ if (!strcmp(tests[i].name, optarg)) {
+ selected_test = i;
+ break;
+ }
+ }
+ if (selected_test >= 0)
+ break;
+ fprintf(stderr, "test %s not found\n", optarg);
+ return EXIT_FAILURE;
+ case 'h':
+ fprintf(stderr,
+ "Usage: %s [-h] [-t name]\n"
+ "\t-h print help\n"
+ "\t-t name run specific test\n"
+ , argv[0]);
+ return ret;
+ default:
+ break;
+ }
+ }
+
if (cg_find_unified_root(root, sizeof(root)))
ksft_exit_skip("cgroup v2 isn't mounted\n");
@@ -1336,6 +1363,9 @@ int main(int argc, char **argv)
has_localevents = proc_status;
for (i = 0; i < ARRAY_SIZE(tests); i++) {
+ if (selected_test >= 0 && selected_test != i)
+ continue;
+
switch (tests[i].fn(root)) {
case KSFT_PASS:
ksft_test_result_pass("%s\n", tests[i].name);
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] selftests/cgroup: allow running a specific test with test_memcontrol
2023-06-19 5:17 [PATCH] selftests/cgroup: allow running a specific test with test_memcontrol Yosry Ahmed
@ 2023-06-19 5:18 ` Yosry Ahmed
0 siblings, 0 replies; 2+ messages in thread
From: Yosry Ahmed @ 2023-06-19 5:18 UTC (permalink / raw)
To: Roman Gushchin, Andrew Morton
Cc: Johannes Weiner, Michal Hocko, Shakeel Butt, Muchun Song,
cgroups, linux-mm, linux-kselftest, linux-kernel
On Sun, Jun 18, 2023 at 10:17 PM Yosry Ahmed <yosryahmed@google.com> wrote:
>
> It is handy during testing and/or debugging to be able to run a single
> test from test_memcontrol. Allow passing in a test name through a
> command line argument (e.g. ./test_memcontrol -t test_memcg_recharge).
>
> Change-Id: I0e0d74d81fdd9d997987389085a816715160467f
I missed removing this gerrit tag, sorry. Will fix it if/when I respin.
> Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
> ---
> .../selftests/cgroup/test_memcontrol.c | 30 +++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
> diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
> index a2a90f4bfe9f..d8f8a13bc6c4 100644
> --- a/tools/testing/selftests/cgroup/test_memcontrol.c
> +++ b/tools/testing/selftests/cgroup/test_memcontrol.c
> @@ -1308,9 +1308,36 @@ struct memcg_test {
>
> int main(int argc, char **argv)
> {
> + int opt;
> char root[PATH_MAX];
> + int selected_test = -1;
> int i, proc_status, ret = EXIT_SUCCESS;
>
> + while ((opt = getopt(argc, argv, "ht:")) != -1) {
> + switch (opt) {
> + case 't':
> + for (i = 0; i < ARRAY_SIZE(tests); i++) {
> + if (!strcmp(tests[i].name, optarg)) {
> + selected_test = i;
> + break;
> + }
> + }
> + if (selected_test >= 0)
> + break;
> + fprintf(stderr, "test %s not found\n", optarg);
> + return EXIT_FAILURE;
> + case 'h':
> + fprintf(stderr,
> + "Usage: %s [-h] [-t name]\n"
> + "\t-h print help\n"
> + "\t-t name run specific test\n"
> + , argv[0]);
> + return ret;
> + default:
> + break;
> + }
> + }
> +
> if (cg_find_unified_root(root, sizeof(root)))
> ksft_exit_skip("cgroup v2 isn't mounted\n");
>
> @@ -1336,6 +1363,9 @@ int main(int argc, char **argv)
> has_localevents = proc_status;
>
> for (i = 0; i < ARRAY_SIZE(tests); i++) {
> + if (selected_test >= 0 && selected_test != i)
> + continue;
> +
> switch (tests[i].fn(root)) {
> case KSFT_PASS:
> ksft_test_result_pass("%s\n", tests[i].name);
> --
> 2.41.0.162.gfafddb0af9-goog
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-19 5:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-19 5:17 [PATCH] selftests/cgroup: allow running a specific test with test_memcontrol Yosry Ahmed
2023-06-19 5:18 ` Yosry Ahmed
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox