On Tue, Oct 30, 2012 at 11:01:44PM +0100, Jiri Olsa wrote:
> Adding automated test to check event's perf_event_attr values.
> 
> The idea is run perf session with kidnapping sys_perf_event_open
> function. For each sys_perf_event_open call we store the
> perf_event_attr data to the file to be checked later against what
> we expect.
> 
> You can run this by:
>   $ python ./tests/attr.py -d ./tests/attr/ -p ./perf -v
> 
> Signed-off-by: Jiri Olsa <jo...@redhat.com>
> Cc: Arnaldo Carvalho de Melo <a...@ghostprotocols.net>
> Cc: Peter Zijlstra <a.p.zijls...@chello.nl>
> Cc: Ingo Molnar <mi...@elte.hu>
> Cc: Paul Mackerras <pau...@samba.org>
> Cc: Corey Ashford <cjash...@linux.vnet.ibm.com>
> Cc: Frederic Weisbecker <fweis...@gmail.com>
> ---
>  tools/perf/Makefile      |   1 +
>  tools/perf/perf.c        |   2 +
>  tools/perf/perf.h        |  16 ++-
>  tools/perf/tests/attr.c  | 136 ++++++++++++++++++++
>  tools/perf/tests/attr.py | 313 
> +++++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 466 insertions(+), 2 deletions(-)
>  create mode 100644 tools/perf/tests/attr.c
>  create mode 100644 tools/perf/tests/attr.py
> 
> diff --git a/tools/perf/Makefile b/tools/perf/Makefile
> index 2d3427f..1da87a3 100644
> --- a/tools/perf/Makefile
> +++ b/tools/perf/Makefile
> @@ -430,6 +430,7 @@ LIB_OBJS += $(OUTPUT)arch/common.o
>  
>  LIB_OBJS += $(OUTPUT)tests/parse-events.o
>  LIB_OBJS += $(OUTPUT)tests/dso-data.o
> +LIB_OBJS += $(OUTPUT)tests/attr.o
>  
>  BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
>  BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
> diff --git a/tools/perf/perf.c b/tools/perf/perf.c
> index e968373..a0ae290 100644
> --- a/tools/perf/perf.c
> +++ b/tools/perf/perf.c
> @@ -484,6 +484,8 @@ int main(int argc, const char **argv)
>       }
>       cmd = argv[0];
>  
> +     test_attr__init();
> +
>       /*
>        * We use PATH to find perf commands, but we prepend some higher
>        * precedence paths: the "--exec-path" option, the PERF_EXEC_PATH
> diff --git a/tools/perf/perf.h b/tools/perf/perf.h
> index 469fbf2..0047264 100644
> --- a/tools/perf/perf.h
> +++ b/tools/perf/perf.h
> @@ -174,13 +174,25 @@ static inline unsigned long long rdclock(void)
>       (void) (&_min1 == &_min2);              \
>       _min1 < _min2 ? _min1 : _min2; })
>  
> +extern bool test_attr__enabled;
> +void test_attr__init(void);
> +void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
> +                  int fd, int group_fd, unsigned long flags);
> +
>  static inline int
>  sys_perf_event_open(struct perf_event_attr *attr,
>                     pid_t pid, int cpu, int group_fd,
>                     unsigned long flags)
>  {
> -     return syscall(__NR_perf_event_open, attr, pid, cpu,
> -                    group_fd, flags);
> +     int fd;
> +
> +     fd = syscall(__NR_perf_event_open, attr, pid, cpu,
> +                  group_fd, flags);
> +
> +     if (unlikely(test_attr__enabled))
> +             test_attr__open(attr, pid, cpu, fd, group_fd, flags);
> +
> +     return fd;
>  }
>  

SNIP

> +
> +void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
> +                  int fd, int group_fd, unsigned long flags)
> +{
> +     if (store_event(attr, pid, cpu, fd, group_fd, flags))
> +             die("test attr FAILED");
> +}

ahh crap, I forgot the errno value preservation fix.. 

I'd send it later with another fix I have for perf stat or v2 if needed ;-)

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to