From patchwork Fri Feb 16 23:52:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 202451 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp60984dyc; Fri, 16 Feb 2024 16:00:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUSZQKpF30aTac9ASpKweBDNIwCmr0yfFA23DVUzsmglAE7nwn/+ojXHAIAAmSudz3Stkwe0FMOfSV32uqXNUIw5F1DKA== X-Google-Smtp-Source: AGHT+IGQsBOZyJsyWKrjRIoTAmB5+TUQ/DhJFx3XB9wMpDBgTFqqpKPSOTN3edssqIOCqY72HkN5 X-Received: by 2002:a05:6808:3006:b0:3c0:32f9:8a38 with SMTP id ay6-20020a056808300600b003c032f98a38mr6615685oib.52.1708128016312; Fri, 16 Feb 2024 16:00:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708128016; cv=pass; d=google.com; s=arc-20160816; b=WejF2ipgi8WhJjX9RH201WoPu+tFO0nK3eAEfAta0rWggjytNbEtcxgQTqIwJsD55I 46vh8XagNisX7VbTYpR9JiBU0EoFEVlPNVi8H17npaKjaRfYkr2J0/uZJUyyD0JHrK2g /PtBNbiNzj6SAdp1/4MbvZWazG3b1BWJY30roMB9qKBDLiRqg89Qgo4fx/J5wYeIniMg zNClIsW0HCVBydXMk5B7LWhC/M+FhQYDOyovAEyELGJHfERqhGRSS9D1opWqbqJVqAP4 GPer6BU+5lhO6Yu2AcVITHCESo6gU2zns0+2AOGSl9Y4JPhF0Ccl7liARLAoMROTQwV5 qVgg== 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=poJvPdqYu3wRi085PL1Kek3TRdO+XaNmw3RkdStDr4c=; fh=4EGySIOEOaKA+L8CsO/AmqQaOFKOeWUiBZrwZivZWdM=; b=B1XolktX6uy7hd5Ru2UFk1tSnm+2b0zuy9W6xu7WRhebPNmZ9D7nLEibb6GqC6gQrN e0e1Nj/mGElyqrEK2+TWKq70uCe2i10TV4mu/LQfZ2uCe0ICQJtNxTMJ6vYMK1Yep34v B9Q0aINpMbGOlIJvNnvETbsY7rJgjn28m0g1pgHb1h2Dq+vdiOdV53NLH/sj0HYbtJ/U CzyBjsJlQgqLSpiQUlSc2P2+LtSWWw61LFypYYPEMP2FlEc2gl5CSNkFwrDums+4BmoD DxGdoAha5wLnpUSG3iV+jxceDb8Wttffkekjys16HsGubtObPY48ejYsLUn6DEshx02N 2N5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="n01txE/T"; 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-69515-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69515-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h1-20020a0562140da100b0068cb07848a0si1011203qvh.477.2024.02.16.16.00.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:00:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69515-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="n01txE/T"; 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-69515-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69515-ouuuleilei=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 EE9541C21D9D for ; Sat, 17 Feb 2024 00:00:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60C27154432; Fri, 16 Feb 2024 23:55:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="n01txE/T" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 8FCAE153BD4 for ; Fri, 16 Feb 2024 23:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127731; cv=none; b=n8HsfFNP1c2bP2dwy4srM48NJ2Zk9EMDU/QU2K9grGV0tBLTzATRfU4yl4te42uERBgbWiK8UHsxeJrnjAFRAFJDZFo9903foo+KQPfgM2MBipKGOnObwhRJgxkFglYR+FM8D7jTTpzGN7VR+kVYi966A/L4nYr8MU79+gDg/0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127731; c=relaxed/simple; bh=bFrvnWICKZ7AZF3dktZ2KHx1E9RGrF6vgCjDjEm+vlk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=DMXAO2Am+c9VikAgdpuXNamBjffQ0o8WDYib2cWHA+oGGTjFVysJ9U6q2rnDrrCDdFN2iyGhYtZngHUYcxSHx9149xzet0Zisw+DUZCnBj4Ng03/3qNS2XAPHdCqfAAoFHWwAGK4yfOU7lMf9P9OaAaTda9Eu549ikunW9Vtin4= 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=n01txE/T; arc=none smtp.client-ip=209.85.128.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-yw1-f202.google.com with SMTP id 00721157ae682-607cef709dcso43647247b3.1 for ; Fri, 16 Feb 2024 15:55:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708127728; x=1708732528; 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=poJvPdqYu3wRi085PL1Kek3TRdO+XaNmw3RkdStDr4c=; b=n01txE/TGcn6iP/DugKR85/L0K1Au9W0sxLwbsiI4PC4WPPpFOc+Dpk4MdGdbEE5rf t9qq3og0Ej811AxJiWLdENdLDgFU7YNhK2I6+XkZuDhouAPsCfPaQLKjEfPEH3+U//Ay opJz/wL63OGmSSYC5Lg44nZUabqYJ0j7VCfH6THxI5mPVo7eAO8DvRhLCIv249+dBE+1 y3tjr3NlhkWJaj5H4SqFlXRQ4OOuKxZP0i98dYiRAtNSI2kQwebiC6W9qfQd2PgjC6f5 VOxFN4Pa8c/7yWu8WBoz2+17X723k5+VA98fDqO/rLxe/WBKjg6u4BBXDr2m5GRCEWKQ OYPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708127728; x=1708732528; 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=poJvPdqYu3wRi085PL1Kek3TRdO+XaNmw3RkdStDr4c=; b=LduuhFzzy21mEzD++wNUxCQB7voEpm9UlpbIWSFfPoPCJbduA4jFZC3iNew5EkqFeO nM87FAZEQxZEODVMQk8lQvos6k2NHtUQt+rrzsZCgPOSEbPg4E7T2O5cBxSyPEEbWLBD oKCF+PXXdIX+Ytil+X4cdxeaY1kVj47iT8GUKqh1gvpFUlwQEBEUNYzT/6rtzEBS1jjh rJl9SH6D6ZgFJskqyXS7VCxlDh8VUxLOz/LouIv3c9OOM56aGUs6Bu8LtXEgtjV+wd4i IoxxNA/Xk3EbVUldnl+TBI/Utj3yVqLr6bn7VH6SpN2/yK5IO0C6kkr7sUuY8G6D4Env xjwQ== X-Forwarded-Encrypted: i=1; AJvYcCU3qfUJmopaXMB7ozi3QgyAhKJYwKm8T6fnjpEe5bovXAFtLF0DgCyvq55ev03zGn/7UsqUsLARAvJwxqz1tdLLj12GY9tRm2GVesTD X-Gm-Message-State: AOJu0Yz4jiUohfLlaELoNBpDAqvwD7KrPqS2nY1MXp+WBSgn6+wSW3vp lSyjt51d1qHuzKW/JjSvTVx1o8g5277giC/R2JdaH1D3WeaMXalx80bt2kLzUSBSSdaTMR4rgXD 4bQqADw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4b5c:352:4272:e34e]) (user=irogers job=sendgmr) by 2002:a0d:cc81:0:b0:604:103:567d with SMTP id o123-20020a0dcc81000000b006040103567dmr1503270ywd.0.1708127728643; Fri, 16 Feb 2024 15:55:28 -0800 (PST) Date: Fri, 16 Feb 2024 15:52:01 -0800 In-Reply-To: <20240216235203.229256-1-irogers@google.com> Message-Id: <20240216235203.229256-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240216235203.229256-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v5 7/8] perf tests: Run time generate shell test suites From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Athira Jajeev , James Clark , Kan Liang , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791102042610624493 X-GMAIL-MSGID: 1791102042610624493 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 | 90 +-------------------- tools/perf/tests/tests-scripts.c | 129 ++++++++++++++++++------------- tools/perf/tests/tests-scripts.h | 10 +-- 3 files changed, 80 insertions(+), 149 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 162f9eb090ac..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,73 +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 = NULL; - - if (asprintf(&cmd, "%s%s", st->file, verbose ? " -v" : "") < 0) - 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)); @@ -440,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; } @@ -488,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; } @@ -550,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..1b99af5c353e 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,30 @@ 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 = NULL; + + if (asprintf(&cmd, "%s%s", file, verbose ? " -v" : "") < 0) + 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 +154,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 +209,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 +222,35 @@ 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 */ - - dir_fd = shell_tests__dir_fd(); /* Walk dir */ - if (dir_fd < 0) - return NULL; + struct test_suite **result = NULL, **result_tmp; + size_t result_sz = 0; + int dir_fd = shell_tests__dir_fd(); /* Walk dir */ - append_scripts_in_dir(dir_fd); - close(dir_fd); + /* + * Append scripts if fd is good, otherwise return a NULL terminated zero + * length array. + */ + if (dir_fd >= 0) + append_scripts_in_dir(dir_fd, &result, &result_sz); - return files; -} - -int list_script_max_width(void) -{ - list_script_files(); /* Ensure we have scanned all scripts */ - return files_max_width; + 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; + if (dir_fd >= 0) + close(dir_fd); + 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 */