Re: [PATCH v1 2/5] perf test: Make sure maps to have a machine
From: Namhyung Kim
Date: Mon Oct 19 2026 - 01:36:53 EST
On Sun, Oct 18, 2026 at 01:33:45PM -0700, Ian Rogers wrote:
> On Sun, Oct 18, 2026 at 9:37 AM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> >
> > It's be easier if we could guarantee that maps always have a machine.
> > IIUC this is true for all real use cases, but only the test code has
> > an exception. Let's get rid of it and make sure they have machines.
> >
> > Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
> > ---
> > tools/perf/tests/maps.c | 15 +++++++++++++--
> > 1 file changed, 13 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/perf/tests/maps.c b/tools/perf/tests/maps.c
> > index 2c05d62f40dcdf72..f40b68f5fa5fe2c1 100644
> > --- a/tools/perf/tests/maps.c
> > +++ b/tools/perf/tests/maps.c
> > @@ -1,5 +1,6 @@
> > // SPDX-License-Identifier: GPL-2.0
> > #include <inttypes.h>
> > +#include <unistd.h>
> > #include <linux/compiler.h>
> > #include <linux/kernel.h>
> > #include "tests.h"
> > @@ -100,8 +101,12 @@ static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest
> > };
> > struct map *map_kcore1, *map_kcore2, *map_kcore3;
> > int ret;
> > - struct maps *maps = maps__new(NULL);
> > + struct machine *machine = machine__new_live(/*host_env=*/NULL,
> > + /*kernel_maps=*/false,
> > + getpid());
> > + struct maps *maps = maps__new(machine);
> >
> > + TEST_ASSERT_VAL("failed to create machine", machine);
> > TEST_ASSERT_VAL("failed to create maps", maps);
> >
> > for (i = 0; i < ARRAY_SIZE(bpf_progs); i++) {
> > @@ -159,6 +164,7 @@ static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest
> > map__zput(map_kcore1);
> > map__zput(map_kcore2);
> > map__zput(map_kcore3);
> > + machine__delete(machine);
> > return TEST_OK;
> > }
> >
> > @@ -189,8 +195,12 @@ static int test__maps__fixup_overlap_and_insert(struct test_suite *t __maybe_unu
> > struct map *map_split, *map_eclipse;
> > int ret;
> > unsigned int i;
> > - struct maps *maps = maps__new(NULL);
> > + struct machine *machine = machine__new_live(/*host_env=*/NULL,
> > + /*kernel_maps=*/false,
> > + getpid());
>
> For completeness should we pass in a host_env like in builtin-top.c?
> https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/builtin-top.c?h=perf-tools-next#n1661
Sure, will add in v2.
Thanks,
Namhyung