From: Ian Rogers <irogers@google.com>
To: irogers@google.com, acme@kernel.org, ak@kernel.org,
ak@linux.intel.com, andi@firstfloor.org, namhyung@kernel.org
Cc: linux-perf-users@vger.kernel.org
Subject: [PATCH v2 9/9] perf test: Isolate test suite from user .perfconfig natively
Date: Tue, 15 Sep 2026 23:52:48 -0700 [thread overview]
Message-ID: <20260916065248.3153556-10-irogers@google.com> (raw)
In-Reply-To: <20260916065248.3153556-1-irogers@google.com>
Running 'perf test' should not inherit the user's ~/.perfconfig
environment as customizing core properties (like core.hybrid-merge)
will trivially break stdout matching checks across the shell suite.
Explicitly set PERF_CONFIG to /dev/null inside cmd_test to globally
sandbox the environment for the entire test workflow. Test specific
config, like annotate.objdump, is read before the sandboxing so that
'perf test' still honors it.
Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/tests/builtin-test.c | 49 +++++++++++++++++++++++++++++----
1 file changed, 44 insertions(+), 5 deletions(-)
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 6293b37266cf..2d53414d8271 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -14,6 +14,8 @@
#include <stdlib.h>
#include <string.h>
+#include "util/config.h"
+
#include <dirent.h>
#include <linux/kernel.h>
#include <linux/string.h>
@@ -1655,11 +1657,30 @@ static int run_workload(const char *work, int argc, const char **argv)
return -1;
}
+/*
+ * Owns the string test_objdump_path points at when it came from the config. It
+ * is reachable for the lifetime of the process so leak checking won't report
+ * it.
+ */
+static char *test_objdump_config_path;
+
static int perf_test__config(const char *var, const char *value,
void *data __maybe_unused)
{
- if (!strcmp(var, "annotate.objdump"))
- test_objdump_path = value;
+ if (!strcmp(var, "annotate.objdump")) {
+ /*
+ * The config, and so value, is freed by perf_config__exit()
+ * below, take a copy that lives as long as the tests.
+ */
+ char *dup = strdup(value);
+
+ if (!dup)
+ return -ENOMEM;
+
+ free(test_objdump_config_path);
+ test_objdump_config_path = dup;
+ test_objdump_path = dup;
+ }
return 0;
}
@@ -1755,13 +1776,31 @@ int cmd_test(int argc, const char **argv)
};
const char * const test_subcommands[] = { "list", NULL };
struct intlist *skiplist = NULL;
- int ret = hists__init();
struct test_suite **suites;
+ int ret;
- if (ret < 0)
+ ret = hists__init();
+ if (ret < 0)
return ret;
- perf_config(perf_test__config, NULL);
+ /* Read test related config, like annotate.objdump, before isolating. */
+ ret = perf_config(perf_test__config, NULL);
+ if (ret < 0)
+ return ret;
+
+ /*
+ * Isolate the test suite from the user's ~/.perfconfig to ensure
+ * behavior isn't impacted by custom variables (e.g. core.hybrid-merge).
+ * Setting PERF_CONFIG isolates the perf commands run by the shell
+ * tests, config_exclusive_filename does the same for this process.
+ * Config values already read by main's perf_config are reset here, so
+ * far only the hybrid-merge value is known to alter test output.
+ */
+ if (setenv("PERF_CONFIG", "/dev/null", 1) < 0)
+ return -1;
+ config_exclusive_filename = "/dev/null";
+ perf_config__exit();
+ symbol_conf.hybrid_merge = false;
/* Unbuffered output */
setvbuf(stdout, NULL, _IONBF, 0);
--
2.55.0.1032.g73a4cd73de-goog
next prev parent reply other threads:[~2026-09-16 6:53 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 6:52 [PATCH v2 0/9] perf report/top: Add opt-in --hybrid-merge Ian Rogers
2026-09-16 6:52 ` [PATCH v2 1/9] perf evlist: Implement evlist__can_merge_hybrid using first_wildcard_match Ian Rogers
2026-09-16 7:02 ` sashiko-bot
2026-09-16 6:52 ` [PATCH v2 2/9] perf ui hist: Add support for aggregated total_period and merging entries Ian Rogers
2026-09-16 7:04 ` sashiko-bot
2026-09-16 6:52 ` [PATCH v2 3/9] perf tools: Expose opt-in --hybrid-merge Ian Rogers
2026-09-16 7:04 ` sashiko-bot
2026-09-16 6:52 ` [PATCH v2 4/9] perf Documentation: Add tip for hybrid event merging Ian Rogers
2026-09-16 6:59 ` sashiko-bot
2026-09-16 6:52 ` [PATCH v2 5/9] perf evlist: Toggle merged_hybrid_group properly in enable/disable Ian Rogers
2026-09-16 7:06 ` sashiko-bot
2026-09-16 6:52 ` [PATCH v2 6/9] perf tools: Add TUI hints for --hybrid-merge Ian Rogers
2026-09-16 7:01 ` sashiko-bot
2026-09-16 6:52 ` [PATCH v2 7/9] perf config: Add core.hybrid-merge to configure event merging Ian Rogers
2026-09-16 6:59 ` sashiko-bot
2026-09-16 6:52 ` [PATCH v2 8/9] perf test: Expand tests for --hybrid-merge Ian Rogers
2026-09-16 7:04 ` sashiko-bot
2026-09-16 6:52 ` Ian Rogers [this message]
2026-09-16 7:08 ` [PATCH v2 9/9] perf test: Isolate test suite from user .perfconfig natively sashiko-bot
2026-09-16 23:46 ` [PATCH v3 0/9] perf report/top: Add opt-in --hybrid-merge Ian Rogers
2026-09-16 23:46 ` [PATCH v3 1/9] perf evlist: Implement evlist__can_merge_hybrid using first_wildcard_match Ian Rogers
2026-09-16 23:58 ` sashiko-bot
2026-09-16 23:46 ` [PATCH v3 2/9] perf ui hist: Add support for aggregated total_period and merging entries Ian Rogers
2026-09-16 23:57 ` sashiko-bot
2026-09-16 23:46 ` [PATCH v3 3/9] perf tools: Expose opt-in --hybrid-merge Ian Rogers
2026-09-16 23:57 ` sashiko-bot
2026-09-16 23:46 ` [PATCH v3 4/9] perf Documentation: Add tip for hybrid event merging Ian Rogers
2026-09-16 23:48 ` sashiko-bot
2026-09-16 23:46 ` [PATCH v3 5/9] perf evlist: Toggle merged_hybrid_group properly in enable/disable Ian Rogers
2026-09-16 23:53 ` sashiko-bot
2026-09-16 23:46 ` [PATCH v3 6/9] perf tools: Add TUI hints for --hybrid-merge Ian Rogers
2026-09-16 23:53 ` sashiko-bot
2026-09-16 23:46 ` [PATCH v3 7/9] perf config: Add core.hybrid-merge to configure event merging Ian Rogers
2026-09-16 23:57 ` sashiko-bot
2026-09-16 23:46 ` [PATCH v3 8/9] perf test: Expand tests for --hybrid-merge Ian Rogers
2026-09-16 23:53 ` sashiko-bot
2026-09-16 23:46 ` [PATCH v3 9/9] perf test: Isolate test suite from user .perfconfig natively Ian Rogers
2026-09-16 23:57 ` sashiko-bot
2026-09-17 5:06 ` [PATCH v4 0/9] perf report/top: Add opt-in --hybrid-merge Ian Rogers
2026-09-17 5:07 ` [PATCH v4 1/9] perf evlist: Implement evlist__can_merge_hybrid using first_wildcard_match Ian Rogers
2026-09-17 5:14 ` sashiko-bot
2026-09-17 5:07 ` [PATCH v4 2/9] perf ui hist: Add support for aggregated total_period and merging entries Ian Rogers
2026-09-17 5:16 ` sashiko-bot
2026-09-17 5:07 ` [PATCH v4 3/9] perf tools: Expose opt-in --hybrid-merge Ian Rogers
2026-09-17 5:16 ` sashiko-bot
2026-09-18 20:31 ` Arnaldo Carvalho de Melo
2026-09-18 20:51 ` Ian Rogers
2026-09-17 5:07 ` [PATCH v4 4/9] perf Documentation: Add tip for hybrid event merging Ian Rogers
2026-09-17 5:10 ` sashiko-bot
2026-09-17 5:07 ` [PATCH v4 5/9] perf evlist: Toggle merged_hybrid_group properly in enable/disable Ian Rogers
2026-09-17 5:13 ` sashiko-bot
2026-09-17 5:07 ` [PATCH v4 6/9] perf tools: Add TUI hints for --hybrid-merge Ian Rogers
2026-09-17 5:14 ` sashiko-bot
2026-09-17 5:07 ` [PATCH v4 7/9] perf config: Add core.hybrid-merge to configure event merging Ian Rogers
2026-09-17 5:16 ` sashiko-bot
2026-09-17 5:07 ` [PATCH v4 8/9] perf test: Expand tests for --hybrid-merge Ian Rogers
2026-09-17 5:18 ` sashiko-bot
2026-09-17 5:07 ` [PATCH v4 9/9] perf test: Isolate test suite from user .perfconfig natively Ian Rogers
2026-09-17 5:17 ` sashiko-bot
2026-09-18 20:40 ` [PATCH v4 0/9] perf report/top: Add opt-in --hybrid-merge Arnaldo Carvalho de Melo
2026-09-18 21:58 ` Arnaldo Carvalho de Melo
2026-09-18 22:07 ` Ian Rogers
2026-09-18 22:11 ` Ian Rogers
2026-09-18 23:04 ` Arnaldo Melo
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=20260916065248.3153556-10-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=ak@kernel.org \
--cc=ak@linux.intel.com \
--cc=andi@firstfloor.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox