perf test: Add perf_event_attr tests
cover perf test: Add perf_event_attr tests
hi,
this code tests the link between perf stat/record command line options and final perf_event_attr struct values. Also it tests the group fd linkage.
It's probably missing many command line option combinations worth testing. I wanted to check with others for more ideas before diving into this.
You can check this also here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/linux.git
perf/attr_tests4
thanks,
jirka
--- tools/perf/Makefile | 1 + tools/perf/builtin-test.c | 4 + tools/perf/perf.c | 2 + tools/perf/perf.h | 11 ++ tools/perf/util/test-attr.c | 142 ++++++++++++++++++++++++++ tools/perf/util/test-attr.py | 272 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/test-attr/base-record | 39 ++++++++ tools/perf/util/test-attr/base-stat | 39 ++++++++ tools/perf/util/test-attr/test-record-basic | 5 + tools/perf/util/test-attr/test-record-count | 8 ++ tools/perf/util/test-attr/test-record-freq | 6 ++ tools/perf/util/test-attr/test-record-graph-default | 6 ++ tools/perf/util/test-attr/test-record-graph-dwarf | 6 ++ tools/perf/util/test-attr/test-record-graph-fp | 6 ++ tools/perf/util/test-attr/test-record-group | 17 ++++ tools/perf/util/test-attr/test-record-no-inherit | 7 ++ tools/perf/util/test-attr/test-record-no-samples | 6 ++ tools/perf/util/test-attr/test-record-period | 7 ++ tools/perf/util/test-attr/test-stat-basic | 6 ++ tools/perf/util/test-attr/test-stat-group | 15 +++ tools/perf/util/test-attr/test-stat-no-inherit | 7 ++ 21 files changed, 612 insertions(+)
PATCH 1/13 perf test: Add framework for atomated perf_event_attr tests
Adding automated test to check event's perf_event_attr values.
The idea is run perf session with kidnaping 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 ./util/test-attr.py -d ./util/test-attr/ -p ./perf -v
--- tools/perf/Makefile | 1 + tools/perf/perf.c | 2 + tools/perf/perf.h | 10 ++ tools/perf/util/test-attr.c | 128 ++++++++++++++++++++ tools/perf/util/test-attr.py | 272 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 413 insertions(+) create mode 100644 tools/perf/util/test-attr.c create mode 100644 tools/perf/util/test-attr.py
tools/perf/Makefile +1 -0
@@ -405,6 +405,7 @@ LIB_OBJS += $(OUTPUT)util/rblist.o LIB_OBJS += $(OUTPUT)util/intlist.o LIB_OBJS += $(OUTPUT)ui/helpline.o LIB_OBJS += $(OUTPUT)ui/stdio/hist.o +LIB_OBJS += $(OUTPUT)util/test-attr.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/perf.c +2 -0
@@ -477,6 +477,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
tools/perf/perf.h +10 -0
@@ -5,6 +5,7 @@ struct winsize;void get_term_dimensions (struct winsize *ws); +#if defined(__i386__)#include "../../arch/x86/include/asm/unistd.h" #define rmb () asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
@@ -168,11 +169,20 @@ static inline unsigned long long rdclock(void) (void ) (&_min1 == &_min2); \ _min1 < _min2 ? _min1 : _min2; }) +extern bool test_attr__enabled; +void test_attr__init (void ); +int test_attr__open (struct perf_event_attr *attr, +pid_t pid,int cpu,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) { +if (unlikely (test_attr__enabled)) +return test_attr__open (attr, pid, cpu, group_fd, flags); +return syscall (__NR_perf_event_open, attr, pid, cpu, group_fd, flags); }
tools/perf/util/test-attr.c new file +128 -0
128 lines not on this page · raw message
tools/perf/util/test-attr.py new file +272 -0
272 lines not on this page · raw message
Signature · 1 line
1.7.11.4
PATCH 2/13 perf test: Add perf_event_attr record basic test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'record'
--- tools/perf/util/test-attr/base-record | 39 +++++++++++++++++++++++++++++ tools/perf/util/test-attr/test-record-basic | 5 ++++ 2 files changed, 44 insertions(+) create mode 100644 tools/perf/util/test-attr/base-record create mode 100644 tools/perf/util/test-attr/test-record-basic
tools/perf/util/test-attr/base-record new file +39 -0
@@ -0,0 +1,39 @@ +[event] +fd=1 +group_fd=-1 +flags=0 +type=0 +size=96 +config=0 +sample_period=4000 +sample_type=263 +read_format=7 +disabled=1 +inherit=1 +pinned=0 +exclusive=0 +exclude_user=0 +exclude_kernel=0 +exclude_hv=0 +exclude_idle=0 +mmap=1 +comm=1 +freq=1 +inherit_stat=0 +enable_on_exec=1 +task=0 +watermask=0 +precise_ip=0 +mmap_data=0 +sample_id_all=1 +exclude_host=0 +exclude_guest=1 +exclude_callchain_kernel=0 +exclude_callchain_user=0 +wakeup_events=0 +bp_type=0 +config1=0 +config2=0 +branch_sample_type=0 +sample_regs_user=0 +sample_stack_user=0
tools/perf/util/test-attr/test-record-basic new file +5 -0
@@ -0,0 +1,5 @@ +[config] +command = record +args = kill >/dev/null 2>&1 + +[event:base-record]
Signature · 1 line
1.7.11.4
PATCH 3/13 perf test: Add perf_event_attr record group test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'record --group -e cycles,instructions'
--- tools/perf/util/test-attr/test-record-group | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tools/perf/util/test-attr/test-record-group
tools/perf/util/test-attr/test-record-group new file +17 -0
@@ -0,0 +1,17 @@ +[config] +command = record +args = --group -e cycles,instructions kill 2>/dev/null + +[event-1:base-record] +fd=1 +group_fd=-1 +sample_type=327 + +[event-2:base-record] +fd=2 +group_fd=1 +config=1 +sample_type=327 +mmap=0 +comm=0 +enable_on_exec=0
Signature · 1 line
1.7.11.4
PATCH 4/13 perf test: Add perf_event_attr record freq test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'record -F 100'
--- tools/perf/util/test-attr/test-record-freq | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tools/perf/util/test-attr/test-record-freq
tools/perf/util/test-attr/test-record-freq new file +6 -0
@@ -0,0 +1,6 @@ +[config] +command = record +args = -F 100 kill >/dev/null 2>&1 + +[event:base-record] +sample_period=100
Signature · 1 line
1.7.11.4
PATCH 5/13 perf test: Add perf_event_attr record count test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'record -c 123'
--- tools/perf/util/test-attr/test-record-count | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tools/perf/util/test-attr/test-record-count
tools/perf/util/test-attr/test-record-count new file +8 -0
@@ -0,0 +1,8 @@ +[config] +command = record +args = -c 123 kill >/dev/null 2>&1 + +[event:base-record] +sample_period=123 +sample_type=7 +freq=0
Signature · 1 line
1.7.11.4
PATCH 6/13 perf test: Add perf_event_attr record graph test
In reply to Jiri OlsaAdding tests to validate perf_event_attr data for commands:
'record -g --'
'record -g fp
'record -g dwarf
graph
--- tools/perf/util/test-attr/test-record-graph-default | 6 ++++++ tools/perf/util/test-attr/test-record-graph-dwarf | 6 ++++++ tools/perf/util/test-attr/test-record-graph-fp | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 tools/perf/util/test-attr/test-record-graph-default create mode 100644 tools/perf/util/test-attr/test-record-graph-dwarf create mode 100644 tools/perf/util/test-attr/test-record-graph-fp
tools/perf/util/test-attr/test-record-graph-default new file +6 -0
@@ -0,0 +1,6 @@ +[config] +command = record +args = -g -- kill >/dev/null 2>&1 + +[event:base-record] +sample_type=295
tools/perf/util/test-attr/test-record-graph-dwarf new file +6 -0
@@ -0,0 +1,6 @@ +[config] +command = record +args = -g dwarf -- kill >/dev/null 2>&1 + +[event:base-record] +sample_type=295
tools/perf/util/test-attr/test-record-graph-fp new file +6 -0
@@ -0,0 +1,6 @@ +[config] +command = record +args = -g fp kill >/dev/null 2>&1 + +[event:base-record] +sample_type=295
Signature · 1 line
1.7.11.4
PATCH 7/13 perf test: Add perf_event_attr record period test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'record -c 100 -P'
--- tools/perf/util/test-attr/test-record-period | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tools/perf/util/test-attr/test-record-period
tools/perf/util/test-attr/test-record-period new file +7 -0
@@ -0,0 +1,7 @@ +[config] +command = record +args = -c 100 -P kill >/dev/null 2>&1 + +[event:base-record] +sample_period=100 +freq=0
Signature · 1 line
1.7.11.4
PATCH 8/13 perf test: Add perf_event_attr record no samples test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'record -n'
--- tools/perf/util/test-attr/test-record-no-samples | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tools/perf/util/test-attr/test-record-no-samples
tools/perf/util/test-attr/test-record-no-samples new file +6 -0
@@ -0,0 +1,6 @@ +[config] +command = record +args = -n kill >/dev/null 2>&1 + +[event:base-record] +sample_period=0
Signature · 1 line
1.7.11.4
PATCH 9/13 perf test: Add perf_event_attr record no-inherit test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'record -i'
--- tools/perf/util/test-attr/test-record-no-inherit | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tools/perf/util/test-attr/test-record-no-inherit
tools/perf/util/test-attr/test-record-no-inherit new file +7 -0
@@ -0,0 +1,7 @@ +[config] +command = record +args = -i kill >/dev/null 2>&1 + +[event:base-record] +sample_type=259 +inherit=0
Signature · 1 line
1.7.11.4
PATCH 10/13 perf test: Add perf_event_attr stat basic test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'stat'
--- tools/perf/util/test-attr/base-stat | 39 +++++++++++++++++++++++++++++++ tools/perf/util/test-attr/test-stat-basic | 6 +++++ 2 files changed, 45 insertions(+) create mode 100644 tools/perf/util/test-attr/base-stat create mode 100644 tools/perf/util/test-attr/test-stat-basic
tools/perf/util/test-attr/base-stat new file +39 -0
@@ -0,0 +1,39 @@ +[event] +fd=1 +group_fd=-1 +flags=0 +type=0 +size=96 +config=0 +sample_period=0 +sample_type=0 +read_format=3 +disabled=1 +inherit=1 +pinned=0 +exclusive=0 +exclude_user=0 +exclude_kernel=0 +exclude_hv=0 +exclude_idle=0 +mmap=0 +comm=0 +freq=0 +inherit_stat=0 +enable_on_exec=1 +task=0 +watermask=0 +precise_ip=0 +mmap_data=0 +sample_id_all=0 +exclude_host=0 +exclude_guest=1 +exclude_callchain_kernel=0 +exclude_callchain_user=0 +wakeup_events=0 +bp_type=0 +config1=0 +config2=0 +branch_sample_type=0 +sample_regs_user=0 +sample_stack_user=0
tools/perf/util/test-attr/test-stat-basic new file +6 -0
@@ -0,0 +1,6 @@ +[config] +command = stat +args = -e cycles kill >/dev/null 2>&1 +ret = 1 + +[event:base-stat]
Signature · 1 line
1.7.11.4
PATCH 11/13 perf test: Add perf_event_attr stat no-inherit test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'stat -i'
--- tools/perf/util/test-attr/test-stat-no-inherit | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tools/perf/util/test-attr/test-stat-no-inherit
tools/perf/util/test-attr/test-stat-no-inherit new file +7 -0
@@ -0,0 +1,7 @@ +[config] +command = stat +args = -i -e cycles kill >/dev/null 2>&1 +ret = 1 + +[event:base-stat] +inherit=0
Signature · 1 line
1.7.11.4
PATCH 12/13 perf test: Add perf_event_attr stat group test
In reply to Jiri OlsaAdding test to validate perf_event_attr data for command:
'stat --group -e cycles,instructions'
--- tools/perf/util/test-attr/test-stat-group | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tools/perf/util/test-attr/test-stat-group
tools/perf/util/test-attr/test-stat-group new file +15 -0
@@ -0,0 +1,15 @@ +[config] +command = stat +args = --group -e cycles,instructions kill >/dev/null 2>&1 +ret = 1 + +[event-1:base-stat] +fd=1 +group_fd=-1 + +[event-2:base-stat] +fd=2 +group_fd=1 +config=1 +disabled=0 +enable_on_exec=0
Signature · 1 line
1.7.11.4
PATCH 13/13 perf test: Add attr tests under builtin test command
In reply to Jiri OlsaThe test attr suite is run only if it's run under perf source directory, because test attr files are not installed.
If run elsewhere, tests are ommited (notification is displayed) and finished as successfull.
--- tools/perf/builtin-test.c | 4 ++++ tools/perf/perf.h | 1 + tools/perf/util/test-attr.c | 14 ++++++++++++++ 3 files changed, 19 insertions(+)
tools/perf/builtin-test.c +4 -0
@@ -1135,6 +1135,10 @@ static struct test { .func = dso__test_data, }, { + .desc = "Test perf attr", + .func = test_attr__run, + }, + { .func = NULL, }, };
tools/perf/perf.h +1 -0
@@ -174,6 +174,7 @@ void test_attr__init(void);int test_attr__open (struct perf_event_attr *attr,pid_t pid,int cpu,int group_fd,unsigned long flags); +int test_attr__run (void ); static inline int sys_perf_event_open(struct perf_event_attr *attr,
tools/perf/util/test-attr.c +14 -0
@@ -126,3 +126,17 @@ int test_attr__open(struct perf_event_attr *attr,return fd; } + +int test_attr__run (void ) +{ +struct stat st; +const char *run; + + run ="python ./util/test-attr.py -d ./util/test-attr/ -p ./perf" ; + +if (!lstat ("./util/" , &st)) +return system (run); + +fprintf (stderr," (ommitted)" ); +return 0 ; +}
Signature · 1 line
1.7.11.4
Em Fri, Aug 24, 2012 at 11:00:31AM +0200, Jiri Olsa escreveu:
Quoted 3 lines
tools/perf/util/test-attr.c | 142 ++++++++++++++++++++++++++ tools/perf/util/test-attr.py | 272 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/test-attr/base-record | 39 ++++++++
I suggest we move all this to:
tools/perf/tests/attr/
Quoted 15 lines
tools/perf/util/test-attr/base-stat | 39 ++++++++ tools/perf/util/test-attr/test-record-basic | 5 + tools/perf/util/test-attr/test-record-count | 8 ++ tools/perf/util/test-attr/test-record-freq | 6 ++ tools/perf/util/test-attr/test-record-graph-default | 6 ++ tools/perf/util/test-attr/test-record-graph-dwarf | 6 ++ tools/perf/util/test-attr/test-record-graph-fp | 6 ++ tools/perf/util/test-attr/test-record-group | 17 ++++ tools/perf/util/test-attr/test-record-no-inherit | 7 ++ tools/perf/util/test-attr/test-record-no-samples | 6 ++ tools/perf/util/test-attr/test-record-period | 7 ++ tools/perf/util/test-attr/test-stat-basic | 6 ++ tools/perf/util/test-attr/test-stat-group | 15 +++ tools/perf/util/test-attr/test-stat-no-inherit | 7 ++ 21 files changed, 612 insertions(+)
Quoted 9 lines · Arnaldo Carvalho de Melo
Em Fri, Aug 24, 2012 at 11:00:31AM +0200, Jiri Olsa escreveu:
Quoted 3 lines
tools/perf/util/test-attr.c | 142 ++++++++++++++++++++++++++ tools/perf/util/test-attr.py | 272 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/test-attr/base-record | 39 ++++++++I suggest we move all this to:
tools/perf/tests/attr/
Yes!
I'd even strongly suggest increasing perf test's prominence within the project: if the tests are quick enough to run we could run them during the build of perf and warn if perf test fails in an unexpected way with the new perf binary.
( Running new perf on older kernel should never cause an
unexpected failure and thus a build warning. )
So as people are working on new perf patches, the default build will run perf test and will catch some errors. As the number of testcases grows it might catch a wide range of bugs. It will also help us find regressions sooner, when users/testers build perf they'll always run perf test as well and report new warnings/failures.
Thanks,
Ingo