perf test: Avoid use perf_env

The perf_env global variable holds the host perf_env data but its use
is hit and miss. Switch to using local perf_env variables and ensure
scoped perf_env__init and perf_env__exit. This loses command line
setting of the perf_env, but this doesn't matter for tests. So the
perf_env is fully initialized, clear it with memset in perf_env__init.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250724163302.596743-13-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
Ian Rogers
2025-07-24 09:32:52 -07:00
committed by Namhyung Kim
parent b743a1368d
commit 5a156353e5
3 changed files with 33 additions and 23 deletions

View File

@@ -651,11 +651,13 @@ static int do_test_code_reading(bool try_kcore)
struct dso *dso;
const char *events[] = { "cycles", "cycles:u", "cpu-clock", "cpu-clock:u", NULL };
int evidx = 0;
struct perf_env host_env;
pid = getpid();
machine = machine__new_host();
machine->env = &perf_env;
perf_env__init(&host_env);
machine->env = &host_env;
ret = machine__create_kernel_maps(machine);
if (ret < 0) {
@@ -791,6 +793,7 @@ out_err:
perf_cpu_map__put(cpus);
perf_thread_map__put(threads);
machine__delete(machine);
perf_env__exit(&host_env);
return err;
}