Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libperf: Add perf_evsel__enable/disable test

Add simple perf_evsel enable/disable test together with evsel counter
reading interface.

Committer testing:

# make -C tools/perf/lib tests
make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-threadmap-a
LINK test-evlist-a
LINK test-evsel-a
LINK test-cpumap-so
LINK test-threadmap-so
LINK test-evlist-so
LINK test-evsel-so
running static:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...OK
- running test-evsel.c...OK
running dynamic:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...OK
- running test-evsel.c...OK
make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
#

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20190721112506.12306-79-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
02266a2d 6bda376f

+43
+43
tools/perf/lib/tests/test-evsel.c
··· 70 70 return 0; 71 71 } 72 72 73 + static int test_stat_thread_enable(void) 74 + { 75 + struct perf_counts_values counts = { .val = 0 }; 76 + struct perf_thread_map *threads; 77 + struct perf_evsel *evsel; 78 + struct perf_event_attr attr = { 79 + .type = PERF_TYPE_SOFTWARE, 80 + .config = PERF_COUNT_SW_TASK_CLOCK, 81 + .disabled = 1, 82 + }; 83 + int err; 84 + 85 + threads = perf_thread_map__new_dummy(); 86 + __T("failed to create threads", threads); 87 + 88 + perf_thread_map__set_pid(threads, 0, 0); 89 + 90 + evsel = perf_evsel__new(&attr); 91 + __T("failed to create evsel", evsel); 92 + 93 + err = perf_evsel__open(evsel, NULL, threads); 94 + __T("failed to open evsel", err == 0); 95 + 96 + perf_evsel__read(evsel, 0, 0, &counts); 97 + __T("failed to read value for evsel", counts.val == 0); 98 + 99 + err = perf_evsel__enable(evsel); 100 + __T("failed to enable evsel", err == 0); 101 + 102 + perf_evsel__read(evsel, 0, 0, &counts); 103 + __T("failed to read value for evsel", counts.val != 0); 104 + 105 + err = perf_evsel__disable(evsel); 106 + __T("failed to enable evsel", err == 0); 107 + 108 + perf_evsel__close(evsel); 109 + perf_evsel__delete(evsel); 110 + 111 + perf_thread_map__put(threads); 112 + return 0; 113 + } 114 + 73 115 int main(int argc, char **argv) 74 116 { 75 117 __T_START; 76 118 77 119 test_stat_cpu(); 78 120 test_stat_thread(); 121 + test_stat_thread_enable(); 79 122 80 123 __T_OK; 81 124 return 0;