[1/3] perf dlfilter: Add a test for resolve_address()

Message ID 20230731091857.10681-1-adrian.hunter@intel.com
State New
Headers
Series [1/3] perf dlfilter: Add a test for resolve_address() |

Commit Message

Adrian Hunter July 31, 2023, 9:18 a.m. UTC
  Extend the "dlfilter C API" test to test
perf_dlfilter_fns.resolve_address(). The test currently fails, but passes
after a subsequent patch.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/dlfilters/dlfilter-test-api-v0.c | 26 ++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
  

Comments

Arnaldo Carvalho de Melo Aug. 3, 2023, 8:51 p.m. UTC | #1
Em Mon, Jul 31, 2023 at 12:18:55PM +0300, Adrian Hunter escreveu:
> Extend the "dlfilter C API" test to test
> perf_dlfilter_fns.resolve_address(). The test currently fails, but passes
> after a subsequent patch.

Ian,

	I think this is ok now, can you please take a look and perhaps
provide an Acked-by or Reviewed-by?

- Arnaldo
 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  tools/perf/dlfilters/dlfilter-test-api-v0.c | 26 ++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/dlfilters/dlfilter-test-api-v0.c b/tools/perf/dlfilters/dlfilter-test-api-v0.c
> index b1f51efd67d6..72f263d49121 100644
> --- a/tools/perf/dlfilters/dlfilter-test-api-v0.c
> +++ b/tools/perf/dlfilters/dlfilter-test-api-v0.c
> @@ -254,6 +254,30 @@ static int check_addr_al(void *ctx)
>  	return 0;
>  }
>  
> +static int check_address_al(void *ctx, const struct perf_dlfilter_sample *sample)
> +{
> +	struct perf_dlfilter_al address_al;
> +	const struct perf_dlfilter_al *al;
> +
> +	al = perf_dlfilter_fns.resolve_ip(ctx);
> +	if (!al)
> +		return test_fail("resolve_ip() failed");
> +
> +	address_al.size = sizeof(address_al);
> +	if (perf_dlfilter_fns.resolve_address(ctx, sample->ip, &address_al))
> +		return test_fail("resolve_address() failed");
> +
> +	CHECK(address_al.sym && al->sym);
> +	CHECK(!strcmp(address_al.sym, al->sym));
> +	CHECK(address_al.addr == al->addr);
> +	CHECK(address_al.sym_start == al->sym_start);
> +	CHECK(address_al.sym_end == al->sym_end);
> +	CHECK(address_al.dso && al->dso);
> +	CHECK(!strcmp(address_al.dso, al->dso));
> +
> +	return 0;
> +}
> +
>  static int check_attr(void *ctx)
>  {
>  	struct perf_event_attr *attr = perf_dlfilter_fns.attr(ctx);
> @@ -290,7 +314,7 @@ static int do_checks(void *data, const struct perf_dlfilter_sample *sample, void
>  	if (early && !d->do_early)
>  		return 0;
>  
> -	if (check_al(ctx) || check_addr_al(ctx))
> +	if (check_al(ctx) || check_addr_al(ctx) || check_address_al(ctx, sample))
>  		return -1;
>  
>  	if (early)
> -- 
> 2.34.1
>
  
Arnaldo Carvalho de Melo Aug. 15, 2023, 5:54 p.m. UTC | #2
Em Mon, Aug 14, 2023 at 10:28:29AM -0700, Ian Rogers escreveu:
> On Thu, Aug 3, 2023 at 1:51 PM Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> >
> > Em Mon, Jul 31, 2023 at 12:18:55PM +0300, Adrian Hunter escreveu:
> > > Extend the "dlfilter C API" test to test
> > > perf_dlfilter_fns.resolve_address(). The test currently fails, but passes
> > > after a subsequent patch.
> >
> > Ian,
> >
> >         I think this is ok now, can you please take a look and perhaps
> > provide an Acked-by or Reviewed-by?
> 
> Sorry, found this in my backlog. I'm a little confused over which
> patch series is current but they all lgtm.
> 
> Reviewed-by: Ian Rogers <irogers@google.com>

Thanks, applied.

- Arnaldo

 
> Thanks,
> Ian
> 
> > - Arnaldo
> >
> > > Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> > > ---
> > >  tools/perf/dlfilters/dlfilter-test-api-v0.c | 26 ++++++++++++++++++++-
> > >  1 file changed, 25 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/tools/perf/dlfilters/dlfilter-test-api-v0.c b/tools/perf/dlfilters/dlfilter-test-api-v0.c
> > > index b1f51efd67d6..72f263d49121 100644
> > > --- a/tools/perf/dlfilters/dlfilter-test-api-v0.c
> > > +++ b/tools/perf/dlfilters/dlfilter-test-api-v0.c
> > > @@ -254,6 +254,30 @@ static int check_addr_al(void *ctx)
> > >       return 0;
> > >  }
> > >
> > > +static int check_address_al(void *ctx, const struct perf_dlfilter_sample *sample)
> > > +{
> > > +     struct perf_dlfilter_al address_al;
> > > +     const struct perf_dlfilter_al *al;
> > > +
> > > +     al = perf_dlfilter_fns.resolve_ip(ctx);
> > > +     if (!al)
> > > +             return test_fail("resolve_ip() failed");
> > > +
> > > +     address_al.size = sizeof(address_al);
> > > +     if (perf_dlfilter_fns.resolve_address(ctx, sample->ip, &address_al))
> > > +             return test_fail("resolve_address() failed");
> > > +
> > > +     CHECK(address_al.sym && al->sym);
> > > +     CHECK(!strcmp(address_al.sym, al->sym));
> > > +     CHECK(address_al.addr == al->addr);
> > > +     CHECK(address_al.sym_start == al->sym_start);
> > > +     CHECK(address_al.sym_end == al->sym_end);
> > > +     CHECK(address_al.dso && al->dso);
> > > +     CHECK(!strcmp(address_al.dso, al->dso));
> > > +
> > > +     return 0;
> > > +}
> > > +
> > >  static int check_attr(void *ctx)
> > >  {
> > >       struct perf_event_attr *attr = perf_dlfilter_fns.attr(ctx);
> > > @@ -290,7 +314,7 @@ static int do_checks(void *data, const struct perf_dlfilter_sample *sample, void
> > >       if (early && !d->do_early)
> > >               return 0;
> > >
> > > -     if (check_al(ctx) || check_addr_al(ctx))
> > > +     if (check_al(ctx) || check_addr_al(ctx) || check_address_al(ctx, sample))
> > >               return -1;
> > >
> > >       if (early)
> > > --
> > > 2.34.1
> > >
> >
> > --
> >
> > - Arnaldo
  

Patch

diff --git a/tools/perf/dlfilters/dlfilter-test-api-v0.c b/tools/perf/dlfilters/dlfilter-test-api-v0.c
index b1f51efd67d6..72f263d49121 100644
--- a/tools/perf/dlfilters/dlfilter-test-api-v0.c
+++ b/tools/perf/dlfilters/dlfilter-test-api-v0.c
@@ -254,6 +254,30 @@  static int check_addr_al(void *ctx)
 	return 0;
 }
 
+static int check_address_al(void *ctx, const struct perf_dlfilter_sample *sample)
+{
+	struct perf_dlfilter_al address_al;
+	const struct perf_dlfilter_al *al;
+
+	al = perf_dlfilter_fns.resolve_ip(ctx);
+	if (!al)
+		return test_fail("resolve_ip() failed");
+
+	address_al.size = sizeof(address_al);
+	if (perf_dlfilter_fns.resolve_address(ctx, sample->ip, &address_al))
+		return test_fail("resolve_address() failed");
+
+	CHECK(address_al.sym && al->sym);
+	CHECK(!strcmp(address_al.sym, al->sym));
+	CHECK(address_al.addr == al->addr);
+	CHECK(address_al.sym_start == al->sym_start);
+	CHECK(address_al.sym_end == al->sym_end);
+	CHECK(address_al.dso && al->dso);
+	CHECK(!strcmp(address_al.dso, al->dso));
+
+	return 0;
+}
+
 static int check_attr(void *ctx)
 {
 	struct perf_event_attr *attr = perf_dlfilter_fns.attr(ctx);
@@ -290,7 +314,7 @@  static int do_checks(void *data, const struct perf_dlfilter_sample *sample, void
 	if (early && !d->do_early)
 		return 0;
 
-	if (check_al(ctx) || check_addr_al(ctx))
+	if (check_al(ctx) || check_addr_al(ctx) || check_address_al(ctx, sample))
 		return -1;
 
 	if (early)