Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1995895rdb; Wed, 31 Jan 2024 16:16:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEl05h3X53eiw9gJ5bwydVDb5jeU9P5mwlhLXkB2IkCyXDNFqcj8mSH8RQbNR4FEygP2bip X-Received: by 2002:a05:620a:12db:b0:785:4408:2dfc with SMTP id e27-20020a05620a12db00b0078544082dfcmr631479qkl.27.1706746617526; Wed, 31 Jan 2024 16:16:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706746617; cv=pass; d=google.com; s=arc-20160816; b=ptA1u0jF9AL/CNznBrYF86wt+Ca/DLy4dSa1NDm9hB8bYC8hP+NP661qs/Ns8tO9Pe I+G/j+kvVXHN2Ffr8CJlU4WWP0/7TnTQDHQlxx5b45FE7R1rFJIz11aA5MYt5PA7pz+/ UgC5RbJddSts4o4SZ5+WS7WerYi0Fz7UXiYZAaKS7q3JDtJiOrjOPHo7CWUnEJN0c564 EJ97QlRg0pyKz0k4HeBb6bU+5Ui8Ljfp3mQnrz1GxUm+glnJZFvhmmbdrfjAdgwefB/l T1zECfooBNcI7sdG0q5XA8bEabmCFOQkVRrvaAaqHV4EZ3HJcTli6PB0m7flC4BcmMhT Yhzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=VCg4vpA76C3Jfn9u3hAMOW5gqL9ymm8ZCUOykIbRgx8=; fh=KcvAJYm7Y/4BiwYR1PYr1fOntGU4forukKDlM9xbz7w=; b=ibxp2Z2XbAc+TU4t1nIPI4KymVElcpbGz/sPVT3EHuaejdyxgdoROAM1HVzJAJIAml JBV4yMbXMwj912g5jIcj6TGkRR6P4upbUGCvIUBRsYgjwoJFKAEsIjwA3C8VF4zsnbjq FBXbcgxmMno1H2NJpTuzq0h5MSLuwR+PoW0C+Jwecb/cWOG9o4W5pgMrIVzNAHWjoWsA BWQBffvd1aomuNUn07fO1jC35Pd6RRtPB6g7lp1u6CLaFGf+fSPWVnJWCzEtA9MoQUoY VnGoHNaJK25l8JJa5CskMSyk8U71aWt2Mg23lZ0640Yjr+nvepk7VACtWGbhqKaaRUyO /qCg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zl+Fq3vB; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47419-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCXuWAYN5kKlcIljNJa9KgUy4P/6bcGYpowi21hghc6BE8iMxQwaa8Vb5HRcC8vk0qLT3ASd5JXriXq7iMt0w6diaFyirPE2s8jrv98xpA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f11-20020a05620a12eb00b00784029b7e2dsi6593331qkl.467.2024.01.31.16.16.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 16:16:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zl+Fq3vB; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47419-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 16EC71C25AB2 for ; Thu, 1 Feb 2024 00:16:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66E2B6FD8; Thu, 1 Feb 2024 00:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zl+Fq3vB" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06EDB568C for ; Thu, 1 Feb 2024 00:15:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706746538; cv=none; b=suTvDBcM2ZRvLdfng33WO6ljRSccIBaovnwe8T70Zlv1KRDwkWr0WU+s5QaJquvlgr5GV7zzlOcIlwpTR/6FZcw6UO2Y5nhctSTNp9XSOSevt1o3KzXXy/5xld4fNQVxEftjGqRuJ9tl7/caiWgt8Dp2+6iswpJR4hfRj4fG1ss= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706746538; c=relaxed/simple; bh=blfaV8BKQUMZ2pozBzmQJsFC6cDO4+/GbvI0gC83Sec=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=u4QVXzNbKDX6KwrGXEF1Mf+r/ZN0+Su4eqSqxx4XQiH9AH0RU+ZQUPbjMP3wrhgWH90iVGQZWV77v3/4YZT65yIKk4u3bPYNJZE0AlJGj6botMUrqAyPHtKwNufEbmULSbCw53E2lONCKEA7hK3x95/UHU/izPT3d72r8bGrrf8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zl+Fq3vB; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc3645a6790so665404276.0 for ; Wed, 31 Jan 2024 16:15:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706746535; x=1707351335; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=VCg4vpA76C3Jfn9u3hAMOW5gqL9ymm8ZCUOykIbRgx8=; b=zl+Fq3vBbnmkjQuwD7SBWglP2aXrSWVpImnSCIK40VuRkc0mp+1KCsaDQqZLBeM1n/ bUy4fwyLteEn1bfzUAH31qbSZHaS2F8/sa7WHysUHTFL5lzc/UVsd2lpkR4CPOe2dmtM hY9X8FhfVF5QK70+O8b54/aG8ZUb4Oa3ZdgWfiKd9U4JdjiH5zo4GsXo7+72SknRd+F2 yUl+U1Vb4/OkDMUFkSeWCTi3V75B8ReatqzsOMaUInT9RzHSTClgxeejYTBHY3nAcamW DcpD0uuAH5lg81oq002tD6j7piitkgWAswg/xKBtr8QLxamrZjd498zfc4V/rBv3dWDi /wcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706746535; x=1707351335; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VCg4vpA76C3Jfn9u3hAMOW5gqL9ymm8ZCUOykIbRgx8=; b=QFxe/ULCviUbCvgkG4v6oqVDY4yrvjmaiq11HzF5NmIpdm6cgN9qH0Xymt25w81Duf 3OVfQPwebbSr/fg7mqXmtC5cpXe8KbEjWuFmdqXPoCbpbtyRFks71qbhQu4h6ilJl0Fw C4ClGEC8l3ACO6RAO+QSFgGe8c0rKc9fKthFO9GXj/W+Rn/1hHLKuL2RYNDZqOlQq/ud qFckEAFIfq2Pht+VNvCSgY07qIjWmoVc/nSqaG4rGGbpkCqamNJhfwcFKGooiicC3k+S dbBu7+IQx9u5Y+JVJ6StimNIKATBkzjAYykGIvUwBqc+8a/aLNI832TWDkEzGJyovYyy Kqxw== X-Gm-Message-State: AOJu0YyyODDFk6YK3Svo5P9sbZP1FHYlKgZyPrajF/kbTFatT6W9ttkf GO/JuF8RZtRgxyVBIKQbBs52B15QIZoIf0ix2ph2VdS6/WXxp4ehRZwmRTkEjbmJT5jef9HiFne MrI/7MQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a05:6902:1587:b0:dc2:41f8:f50b with SMTP id k7-20020a056902158700b00dc241f8f50bmr887696ybu.1.1706746535032; Wed, 31 Jan 2024 16:15:35 -0800 (PST) Date: Wed, 31 Jan 2024 16:15:01 -0800 In-Reply-To: <20240201001504.1348511-1-irogers@google.com> Message-Id: <20240201001504.1348511-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240201001504.1348511-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 7/9] perf tests: Run time generate shell test suites From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nathan Chancellor , Nick Desaulniers , Tom Rix , Ravi Bangoria , James Clark , Kan Liang , John Garry , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Rather than special shell test logic, do a single pass to create an array of test suites. Hold the shell test file name in the test suite priv field. This makes the special shell test logic in builtin-test.c redundant so remove it. Signed-off-by: Ian Rogers --- tools/perf/tests/builtin-test.c | 91 +---------------------- tools/perf/tests/tests-scripts.c | 120 ++++++++++++++++++------------- tools/perf/tests/tests-scripts.h | 10 +-- 3 files changed, 74 insertions(+), 147 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 6d5001daaf63..c42cb40fc242 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -130,6 +130,7 @@ static struct test_suite *generic_tests[] = { static struct test_suite **tests[] = { generic_tests, arch_tests, + NULL, /* shell tests created at runtime. */ }; static struct test_workload *workloads[] = { @@ -299,74 +300,12 @@ static int test_and_print(struct test_suite *t, int subtest) return err; } -struct shell_test { - const char *file; -}; - -static int shell_test__run(struct test_suite *test, int subdir __maybe_unused) -{ - int err; - struct shell_test *st = test->priv; - char *cmd; - - asprintf(&cmd, "%s%s", st->file, verbose ? " -v" : ""); - if (!cmd) - return TEST_FAIL; - err = system(cmd); - free(cmd); - if (!err) - return TEST_OK; - - return WEXITSTATUS(err) == 2 ? TEST_SKIP : TEST_FAIL; -} - -static int run_shell_tests(int argc, const char *argv[], int i, int width, - struct intlist *skiplist) -{ - struct shell_test st; - const struct script_file *files, *file; - - files = list_script_files(); - if (!files) - return 0; - for (file = files; file->file; file++) { - int curr = i++; - struct test_case test_cases[] = { - { - .desc = file->desc, - .run_case = shell_test__run, - }, - { .name = NULL, } - }; - struct test_suite test_suite = { - .desc = test_cases[0].desc, - .test_cases = test_cases, - .priv = &st, - }; - st.file = file->file; - - if (test_suite.desc == NULL || - !perf_test__matches(test_suite.desc, curr, argc, argv)) - continue; - - pr_info("%3d: %-*s:", i, width, test_suite.desc); - - if (intlist__find(skiplist, i)) { - color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n"); - continue; - } - - test_and_print(&test_suite, 0); - } - return 0; -} - static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) { struct test_suite *t; unsigned int j, k; int i = 0; - int width = list_script_max_width(); + int width = 0; for_each_test(j, k, t) { int len = strlen(test_description(t, -1)); @@ -441,28 +380,6 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) } } } - - return run_shell_tests(argc, argv, i, width, skiplist); -} - -static int perf_test__list_shell(int argc, const char **argv, int i) -{ - const struct script_file *files, *file; - - files = list_script_files(); - if (!files) - return 0; - for (file = files; file->file; file++) { - int curr = i++; - struct test_suite t = { - .desc = file->desc - }; - - if (!perf_test__matches(t.desc, curr, argc, argv)) - continue; - - pr_info("%3d: %s\n", i, t.desc); - } return 0; } @@ -489,9 +406,6 @@ static int perf_test__list(int argc, const char **argv) test_description(t, subi)); } } - - perf_test__list_shell(argc, argv, i); - return 0; } @@ -551,6 +465,7 @@ int cmd_test(int argc, const char **argv) /* Unbuffered output */ setvbuf(stdout, NULL, _IONBF, 0); + tests[2] = create_script_test_suites(); argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0); if (argc >= 1 && !strcmp(argv[0], "list")) return perf_test__list(argc - 1, argv + 1); diff --git a/tools/perf/tests/tests-scripts.c b/tools/perf/tests/tests-scripts.c index 9b3b66dd5508..b92a93c251c6 100644 --- a/tools/perf/tests/tests-scripts.c +++ b/tools/perf/tests/tests-scripts.c @@ -26,16 +26,6 @@ #include "tests.h" #include "util/rlimit.h" - -/* - * As this is a singleton built once for the run of the process, there is - * no value in trying to free it and just let it stay around until process - * exits when it's cleaned up. - */ -static size_t files_num = 0; -static struct script_file *files = NULL; -static int files_max_width = 0; - static int shell_tests__dir_fd(void) { char path[PATH_MAX], *exec_path; @@ -131,12 +121,31 @@ static char *strdup_check(const char *str) return newstr; } -static void append_script(int dir_fd, const char *name, char *desc) +static int shell_test__run(struct test_suite *test, int subtest __maybe_unused) +{ + const char *file = test->priv; + int err; + char *cmd; + + asprintf(&cmd, "%s%s", file, verbose ? " -v" : ""); + if (!cmd) + return TEST_FAIL; + err = system(cmd); + free(cmd); + if (!err) + return TEST_OK; + + return WEXITSTATUS(err) == 2 ? TEST_SKIP : TEST_FAIL; +} + +static void append_script(int dir_fd, const char *name, char *desc, + struct test_suite ***result, + size_t *result_sz) { char filename[PATH_MAX], link[128]; - struct script_file *files_tmp; - size_t files_num_tmp, len; - int width; + struct test_suite *test_suite, **result_tmp; + struct test_case *tests; + size_t len; snprintf(link, sizeof(link), "/proc/%d/fd/%d", getpid(), dir_fd); len = readlink(link, filename, sizeof(filename)); @@ -146,33 +155,43 @@ static void append_script(int dir_fd, const char *name, char *desc) } filename[len++] = '/'; strcpy(&filename[len], name); - files_num_tmp = files_num + 1; - if (files_num_tmp >= SIZE_MAX) { - pr_err("Too many script files\n"); - abort(); + + tests = calloc(2, sizeof(*tests)); + if (!tests) { + pr_err("Out of memory while building script test suite list\n"); + return; + } + tests[0].name = strdup_check(name); + tests[0].desc = strdup_check(desc); + tests[0].run_case = shell_test__run; + + test_suite = zalloc(sizeof(*test_suite)); + if (!test_suite) { + pr_err("Out of memory while building script test suite list\n"); + free(tests); + return; } + test_suite->desc = desc; + test_suite->test_cases = tests; + test_suite->priv = strdup_check(filename); /* Realloc is good enough, though we could realloc by chunks, not that * anyone will ever measure performance here */ - files_tmp = realloc(files, - (files_num_tmp + 1) * sizeof(struct script_file)); - if (files_tmp == NULL) { - pr_err("Out of memory while building test list\n"); - abort(); + result_tmp = realloc(*result, (*result_sz + 1) * sizeof(*result_tmp)); + if (result_tmp == NULL) { + pr_err("Out of memory while building script test suite list\n"); + free(tests); + free(test_suite); + return; } /* Add file to end and NULL terminate the struct array */ - files = files_tmp; - files_num = files_num_tmp; - files[files_num - 1].file = strdup_check(filename); - files[files_num - 1].desc = desc; - files[files_num].file = NULL; - files[files_num].desc = NULL; - - width = strlen(desc); /* Track max width of desc */ - if (width > files_max_width) - files_max_width = width; + *result = result_tmp; + (*result)[*result_sz] = test_suite; + (*result_sz)++; } -static void append_scripts_in_dir(int dir_fd) +static void append_scripts_in_dir(int dir_fd, + struct test_suite ***result, + size_t *result_sz) { struct dirent **entlist; struct dirent *ent; @@ -191,7 +210,7 @@ static void append_scripts_in_dir(int dir_fd) char *desc = shell_test__description(dir_fd, ent->d_name); if (desc) /* It has a desc line - valid script */ - append_script(dir_fd, ent->d_name, desc); + append_script(dir_fd, ent->d_name, desc, result, result_sz); continue; } if (ent->d_type != DT_DIR) { @@ -204,32 +223,31 @@ static void append_scripts_in_dir(int dir_fd) continue; } fd = openat(dir_fd, ent->d_name, O_PATH); - append_scripts_in_dir(fd); + append_scripts_in_dir(fd, result, result_sz); } for (i = 0; i < n_dirs; i++) /* Clean up */ zfree(&entlist[i]); free(entlist); } -const struct script_file *list_script_files(void) +struct test_suite **create_script_test_suites(void) { - int dir_fd; - - if (files) - return files; /* Singleton - we already know our list */ + struct test_suite **result = NULL, **result_tmp; + size_t result_sz = 0; + int dir_fd = shell_tests__dir_fd(); /* Walk dir */ - dir_fd = shell_tests__dir_fd(); /* Walk dir */ if (dir_fd < 0) return NULL; - append_scripts_in_dir(dir_fd); + append_scripts_in_dir(dir_fd, &result, &result_sz); + result_tmp = realloc(result, (result_sz + 1) * sizeof(*result_tmp)); + if (result_tmp == NULL) { + pr_err("Out of memory while building script test suite list\n"); + abort(); + } + /* NULL terminate the test suite array. */ + result = result_tmp; + result[result_sz] = NULL; close(dir_fd); - - return files; -} - -int list_script_max_width(void) -{ - list_script_files(); /* Ensure we have scanned all scripts */ - return files_max_width; + return result; } diff --git a/tools/perf/tests/tests-scripts.h b/tools/perf/tests/tests-scripts.h index 3508a293aaf9..b553ad26ea17 100644 --- a/tools/perf/tests/tests-scripts.h +++ b/tools/perf/tests/tests-scripts.h @@ -2,14 +2,8 @@ #ifndef TESTS_SCRIPTS_H #define TESTS_SCRIPTS_H -struct script_file { - char *file; - char *desc; -}; +#include "tests.h" -/* List available script tests to run - singleton - never freed */ -const struct script_file *list_script_files(void); -/* Get maximum width of description string */ -int list_script_max_width(void); +struct test_suite **create_script_test_suites(void); #endif /* TESTS_SCRIPTS_H */ -- 2.43.0.429.g432eaa2c6b-goog