linux-stable/tools/perf/tests/attr
Thomas Richter f677ec94f6 perf test: Test 17 fails with make LIBPFM4=1 on s390 z/VM
This test case fails on s390 virtual machine z/VM which has no PMU support
when the perf tool is built with LIBPFM4=1.

Using make LIBPFM4=1 builds the perf tool with support for libpfm
event notation. The command line flag --pfm-events is valid:
 # ./perf record --pfm-events cycles -- true
 [ perf record: Woken up 1 times to write data ]
 [ perf record: Captured and wrote 0.001 MB perf.data (2 samples) ]
 #

However the command 'perf test -Fv 17' fails on s390 z/VM virtual machine
with LIBPFM4=1:
  # perf test -Fv 17
  17: Setup struct perf_event_attr                                    :
  --- start ---
  .....
  running './tests/attr/test-record-group2'
  unsupp  './tests/attr/test-record-group2'
  running './tests/attr/test-record-pfm-period'
  expected exclude_hv=0, got 1
 FAILED './tests/attr/test-record-pfm-period' - match failure
 ---- end ----
 Setup struct perf_event_attr: FAILED!

When --pfm-event system is not supported, the test returns unsupported
and continues. Here is an example using a virtual machine on x86 and
Fedora 34:
 [root@f33 perf]# perf test -Fv 17
 17: Setup struct perf_event_attr                                    :
 --- start ---
 .....
 running './tests/attr/test-record-group2'
 unsupp  './tests/attr/test-record-group2'
 running './tests/attr/test-record-pfm-period'
 unsupp  './tests/attr/test-record-pfm-period'
 ....

The issue is file ./tests/attr/test-record-pfm-period
which requires perf event attribute member exclude_hv to be zero.
This is not the case on s390 where the value of exclude_hv is one when
executing on a z/VM virtual machine without PMU hardware support.

Fix this by allowing value exlucde_hv to be zero or one.

Output before:
 # /usr/bin/python ./tests/attr.py -d ./tests/attr/ -t \
	test-record-pfm-period -p ./perf  -vvv 2>&1| fgrep match
    matching [event:base-record]
    match: [event:base-record] matches []
 FAILED './tests/attr//test-record-pfm-period' - match failure
 #

Output after:
 # /usr/bin/python ./tests/attr.py -d ./tests/attr/ -t \
	test-record-pfm-period -p ./perf  -vvv 2>&1| fgrep match
    matching [event:base-record]
    match: [event:base-record] matches ['event-1-0-6', 'event-1-0-5']
  matched

Background:
Using libpfm library ends up in this function call sequence

pfm_get_perf_event_encoding()
+-- pfm_get_os_event_encoding()
    +-- pfmlib_perf_event_encode()

is called when no hardware specific PMU unit can be detected
as in the s390 z/VM virtual machine case. This uses the
"perf_events generic PMU" data structure which sets exclude_hv
to 1 per default.  Using this PMU that test case always fails.

That is the reason why exclude_hv attribute setting varies.

Version 2:

   As suggested by Ian Rogers make perf_event_attribute member
   exclude_hv more robust and accept value 0 or 1 to handle more
   test cases which might fail on s390 virtual machine z/VM.

Suggested-by: Ian Rogers <irogers@google.com>
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Link: http://lore.kernel.org/lkml/20210528091050.245838-1-tmricht@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-01 10:57:39 -03:00
..
README perf test: Leader sampling shouldn't clear sample period 2020-09-14 19:35:22 -03:00
base-record perf test: Test 17 fails with make LIBPFM4=1 on s390 z/VM 2021-06-01 10:57:39 -03:00
base-stat tools headers UAPI: Sync perf_event.h with the kernel sources 2021-05-10 09:01:01 -03:00
system-wide-dummy tools headers UAPI: Sync perf_event.h with the kernel sources 2021-05-10 09:01:01 -03:00
test-record-C0 perf record: Add dummy event during system wide synthesis 2020-05-28 10:03:25 -03:00
test-record-basic perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-branch-any perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-branch-filter-any perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-branch-filter-any_call perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-branch-filter-any_ret perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-branch-filter-hv perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-branch-filter-ind_call perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-branch-filter-k perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-branch-filter-u perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-count perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-data perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-freq perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-graph-default perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-graph-dwarf perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-graph-fp perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-group perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-group-sampling perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-group1 perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-group2 perf test: Leader sampling shouldn't clear sample period 2020-09-14 19:35:22 -03:00
test-record-no-buffering perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-no-inherit perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-no-samples perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-period perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-record-pfm-period perf test: Ensure sample_period is set libpfm4 events 2020-07-30 07:01:49 -03:00
test-record-raw perf tools: Save bpf_prog_info and BTF of new BPF programs 2019-03-21 11:27:04 -03:00
test-stat-C0 perf tests attr: Make hw events optional 2017-10-23 11:20:54 -03:00
test-stat-basic perf tests attr: Make hw events optional 2017-10-23 11:20:54 -03:00
test-stat-default perf tests attr: Make hw events optional 2017-10-23 11:20:54 -03:00
test-stat-detailed-1 perf tests attr: Make hw events optional 2017-10-23 11:20:54 -03:00
test-stat-detailed-2 perf tests attr: Make hw events optional 2017-10-23 11:20:54 -03:00
test-stat-detailed-3 perf tests attr: Make hw events optional 2017-10-23 11:20:54 -03:00
test-stat-group perf tests attr: Fix group stat tests 2017-10-03 09:41:45 -03:00
test-stat-group1 perf tests attr: Fix group stat tests 2017-10-03 09:41:45 -03:00
test-stat-no-inherit perf tests attr: Make hw events optional 2017-10-23 11:20:54 -03:00

README

The struct perf_event_attr test (attr tests) support
====================================================
This testing support is embedded into perf directly and is governed
by the PERF_TEST_ATTR environment variable and hook inside the
sys_perf_event_open function.

The general idea is to store 'struct perf_event_attr' details for
each event created within single perf command. Each event details
are stored into separate text file. Once perf command is finished
these files are checked for values we expect for command.

The attr tests consist of following parts:

tests/attr.c
------------
This is the sys_perf_event_open hook implementation. The hook
is triggered when the PERF_TEST_ATTR environment variable is
defined. It must contain name of existing directory with access
and write permissions.

For each sys_perf_event_open call event details are stored in
separate file. Besides 'struct perf_event_attr' values we also
store 'fd' and 'group_fd' values to allow checking for groups.

tests/attr.py
-------------
This is the python script that does all the hard work. It reads
the test definition, executes it and checks results.

tests/attr/
-----------
Directory containing all attr test definitions.
Following tests are defined (with perf commands):

  perf record kill                              (test-record-basic)
  perf record -b kill                           (test-record-branch-any)
  perf record -j any kill                       (test-record-branch-filter-any)
  perf record -j any_call kill                  (test-record-branch-filter-any_call)
  perf record -j any_ret kill                   (test-record-branch-filter-any_ret)
  perf record -j hv kill                        (test-record-branch-filter-hv)
  perf record -j ind_call kill                  (test-record-branch-filter-ind_call)
  perf record -j k kill                         (test-record-branch-filter-k)
  perf record -j u kill                         (test-record-branch-filter-u)
  perf record -c 123 kill                       (test-record-count)
  perf record -d kill                           (test-record-data)
  perf record -F 100 kill                       (test-record-freq)
  perf record -g kill                           (test-record-graph-default)
  perf record --call-graph dwarf kill		(test-record-graph-dwarf)
  perf record --call-graph fp kill              (test-record-graph-fp)
  perf record --group -e cycles,instructions kill (test-record-group)
  perf record -e '{cycles,instructions}' kill   (test-record-group1)
  perf record -e '{cycles/period=1/,instructions/period=2/}:S' kill (test-record-group2)
  perf record -D kill                           (test-record-no-delay)
  perf record -i kill                           (test-record-no-inherit)
  perf record -n kill                           (test-record-no-samples)
  perf record -c 100 -P kill                    (test-record-period)
  perf record -c 1 --pfm-events=cycles:period=2 (test-record-pfm-period)
  perf record -R kill                           (test-record-raw)
  perf stat -e cycles kill                      (test-stat-basic)
  perf stat kill                                (test-stat-default)
  perf stat -d kill                             (test-stat-detailed-1)
  perf stat -dd kill                            (test-stat-detailed-2)
  perf stat -ddd kill                           (test-stat-detailed-3)
  perf stat --group -e cycles,instructions kill (test-stat-group)
  perf stat -e '{cycles,instructions}' kill     (test-stat-group1)
  perf stat -i -e cycles kill                   (test-stat-no-inherit)