// SPDX-License-Identifier: GPL-2.0
#include "parse-events.h"
#include "evsel.h"
#include "evlist.h"
#include <api/fs/fs.h>
#include "tests.h"
#include "debug.h"
#include "pmu.h"
#include "pmus.h"
#include <dirent.h>
#include <errno.h>
#include "fncache.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <linux/kernel.h>
#include <linux/hw_breakpoint.h>
#include <api/fs/tracing_path.h>
#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
static int num_core_entries(void )
{
/*
* If the kernel supports extended type, expect events to be
* opened once for each core PMU type. Otherwise fall back to the legacy
* behavior of opening only one event even though there are multiple
* PMUs
*/
if (perf_pmus__supports_extended_type())
return perf_pmus__num_core_pmus();
return 1;
}
static bool test_config(const struct evsel *evsel, __u64 expected_config)
{
__u32 type = evsel->core.attr.type;
__u64 config = evsel->core.attr.config;
if (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE) {
/*
* HARDWARE and HW_CACHE events encode the PMU's extended type
* in the top 32-bits. Mask in order to ignore.
*/
config &= PERF_HW_EVENT_MASK;
}
return config == expected_config;
}
static bool test_perf_config(const struct perf_evsel *evsel, __u64 expected_config)
{
return (evsel->attr.config & PERF_HW_EVENT_MASK) == expected_config;
}
#if defined (__s390x__)
/* Return true if kvm module is available and loaded. Test this
* and return success when trace point kvm_s390_create_vm
* exists. Otherwise this test always fails.
*/
static bool kvm_s390_create_vm_valid(void )
{
char *eventfile;
bool rc = false ;
eventfile = get_events_file("kvm-s390" );
if (eventfile) {
DIR *mydir = opendir(eventfile);
if (mydir) {
rc = true ;
closedir(mydir);
}
put_events_file(eventfile);
}
return rc;
}
#endif
static int test__checkevent_tracepoint(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong number of groups" , 0 == evlist__nr_groups(evlist));
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong sample_type" ,
PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
TEST_ASSERT_VAL("wrong sample_period" , 1 == evsel->core.attr.sample_period);
return TEST_OK;
}
static int test__checkevent_tracepoint_multi(struct evlist *evlist)
{
struct evsel *evsel;
TEST_ASSERT_VAL("wrong number of entries" , evlist->core.nr_entries > 1);
TEST_ASSERT_VAL("wrong number of groups" , 0 == evlist__nr_groups(evlist));
evlist__for_each_entry(evlist, evsel) {
TEST_ASSERT_VAL("wrong type" ,
PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong sample_type" ,
PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
TEST_ASSERT_VAL("wrong sample_period" ,
1 == evsel->core.attr.sample_period);
}
return TEST_OK;
}
static int test__checkevent_raw(struct evlist *evlist)
{
struct perf_evsel *evsel;
bool raw_type_match = false ;
TEST_ASSERT_VAL("wrong number of entries" , 0 != evlist->core.nr_entries);
perf_evlist__for_each_evsel(&evlist->core, evsel) {
struct perf_pmu *pmu __maybe_unused = NULL;
bool type_matched = false ;
TEST_ASSERT_VAL("wrong config" , test_perf_config(evsel, 0x1a));
TEST_ASSERT_VAL("event not parsed as raw type" ,
evsel->attr.type == PERF_TYPE_RAW);
#if defined (__aarch64__)
/*
* Arm doesn't have a real raw type PMU in sysfs, so raw events
* would never match any PMU. However, RAW events on Arm will
* always successfully open on the first available core PMU
* so no need to test for a matching type here.
*/
type_matched = raw_type_match = true ;
#else
while ((pmu = perf_pmus__scan(pmu)) != NULL) {
if (pmu->type == evsel->attr.type) {
TEST_ASSERT_VAL("PMU type expected once" , !type_matched);
type_matched = true ;
if (pmu->type == PERF_TYPE_RAW)
raw_type_match = true ;
}
}
#endif
TEST_ASSERT_VAL("No PMU found for type" , type_matched);
}
TEST_ASSERT_VAL("Raw PMU not matched" , raw_type_match);
return TEST_OK;
}
static int test__checkevent_numeric(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" , 1 == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 1));
return TEST_OK;
}
static int assert_hw(struct perf_evsel *evsel, enum perf_hw_id id, const char *name)
{
struct perf_pmu *pmu;
if (evsel->attr.type == PERF_TYPE_HARDWARE) {
TEST_ASSERT_VAL("wrong config" , test_perf_config(evsel, id));
return 0;
}
pmu = perf_pmus__find_by_type(evsel->attr.type);
TEST_ASSERT_VAL("unexpected PMU type" , pmu);
TEST_ASSERT_VAL("PMU missing event" , perf_pmu__have_event(pmu, name));
return 0;
}
static int test__checkevent_symbolic_name(struct evlist *evlist)
{
struct perf_evsel *evsel;
TEST_ASSERT_VAL("wrong number of entries" , 0 != evlist->core.nr_entries);
perf_evlist__for_each_evsel(&evlist->core, evsel) {
int ret = assert_hw(evsel, PERF_COUNT_HW_INSTRUCTIONS, "instructions" );
if (ret)
return ret;
}
return TEST_OK;
}
static int test__checkevent_symbolic_name_config(struct evlist *evlist)
{
struct perf_evsel *evsel;
TEST_ASSERT_VAL("wrong number of entries" , 0 != evlist->core.nr_entries);
perf_evlist__for_each_evsel(&evlist->core, evsel) {
int ret = assert_hw(evsel, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
/*
* The period value gets configured within evlist__config,
* while this test executes only parse events method.
*/
TEST_ASSERT_VAL("wrong period" , 0 == evsel->attr.sample_period);
TEST_ASSERT_VAL("wrong config1" , 0 == evsel->attr.config1);
TEST_ASSERT_VAL("wrong config2" , 1 == evsel->attr.config2);
}
return TEST_OK;
}
static int test__checkevent_symbolic_alias(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_SOFTWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS));
return TEST_OK;
}
static int test__checkevent_genhw(struct evlist *evlist)
{
struct perf_evsel *evsel;
TEST_ASSERT_VAL("wrong number of entries" , 0 != evlist->core.nr_entries);
perf_evlist__for_each_entry(&evlist->core, evsel) {
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_HW_CACHE == evsel->attr.type);
TEST_ASSERT_VAL("wrong config" , test_perf_config(evsel, 1 << 16));
}
return TEST_OK;
}
static int test__checkevent_breakpoint(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 0));
TEST_ASSERT_VAL("wrong bp_type" , (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
evsel->core.attr.bp_type);
TEST_ASSERT_VAL("wrong bp_len" , HW_BREAKPOINT_LEN_4 ==
evsel->core.attr.bp_len);
return TEST_OK;
}
static int test__checkevent_breakpoint_x(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 0));
TEST_ASSERT_VAL("wrong bp_type" ,
HW_BREAKPOINT_X == evsel->core.attr.bp_type);
TEST_ASSERT_VAL("wrong bp_len" , default_breakpoint_len() == evsel->core.attr.bp_len);
return TEST_OK;
}
static int test__checkevent_breakpoint_r(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" ,
PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 0));
TEST_ASSERT_VAL("wrong bp_type" ,
HW_BREAKPOINT_R == evsel->core.attr.bp_type);
TEST_ASSERT_VAL("wrong bp_len" ,
HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
return TEST_OK;
}
static int test__checkevent_breakpoint_w(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" ,
PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 0));
TEST_ASSERT_VAL("wrong bp_type" ,
HW_BREAKPOINT_W == evsel->core.attr.bp_type);
TEST_ASSERT_VAL("wrong bp_len" ,
HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
return TEST_OK;
}
static int test__checkevent_breakpoint_rw(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" ,
PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 0));
TEST_ASSERT_VAL("wrong bp_type" ,
(HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->core.attr.bp_type);
TEST_ASSERT_VAL("wrong bp_len" ,
HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
return TEST_OK;
}
static int test__checkevent_tracepoint_modifier(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
return test__checkevent_tracepoint(evlist);
}
static int
test__checkevent_tracepoint_multi_modifier(struct evlist *evlist)
{
struct perf_evsel *evsel;
TEST_ASSERT_VAL("wrong number of entries" , evlist->core.nr_entries > 1);
perf_evlist__for_each_entry(&evlist->core, evsel) {
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->attr.precise_ip);
}
return test__checkevent_tracepoint_multi(evlist);
}
static int test__checkevent_raw_modifier(struct evlist *evlist)
{
struct perf_evsel *evsel;
perf_evlist__for_each_entry(&evlist->core, evsel) {
TEST_ASSERT_VAL("wrong exclude_user" , evsel->attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->attr.precise_ip);
}
return test__checkevent_raw(evlist);
}
static int test__checkevent_numeric_modifier(struct evlist *evlist)
{
struct perf_evsel *evsel;
perf_evlist__for_each_entry(&evlist->core, evsel) {
TEST_ASSERT_VAL("wrong exclude_user" , evsel->attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->attr.precise_ip);
}
return test__checkevent_numeric(evlist);
}
static int test__checkevent_symbolic_name_modifier(struct evlist *evlist)
{
struct perf_evsel *evsel;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == num_core_entries());
perf_evlist__for_each_entry(&evlist->core, evsel) {
TEST_ASSERT_VAL("wrong exclude_user" , evsel->attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->attr.precise_ip);
}
return test__checkevent_symbolic_name(evlist);
}
static int test__checkevent_exclude_host_modifier(struct evlist *evlist)
{
struct perf_evsel *evsel;
perf_evlist__for_each_entry(&evlist->core, evsel) {
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , evsel->attr.exclude_host);
}
return test__checkevent_symbolic_name(evlist);
}
static int test__checkevent_exclude_guest_modifier(struct evlist *evlist)
{
struct perf_evsel *evsel;
perf_evlist__for_each_entry(&evlist->core, evsel) {
TEST_ASSERT_VAL("wrong exclude guest" , evsel->attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->attr.exclude_host);
}
return test__checkevent_symbolic_name(evlist);
}
static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
return test__checkevent_symbolic_alias(evlist);
}
static int test__checkevent_genhw_modifier(struct evlist *evlist)
{
struct perf_evsel *evsel;
perf_evlist__for_each_entry(&evlist->core, evsel) {
TEST_ASSERT_VAL("wrong exclude_user" , evsel->attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->attr.precise_ip);
}
return test__checkevent_genhw(evlist);
}
static int test__checkevent_exclude_idle_modifier(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude idle" , evsel->core.attr.exclude_idle);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
return test__checkevent_symbolic_name(evlist);
}
static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude idle" , evsel->core.attr.exclude_idle);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
return test__checkevent_symbolic_name(evlist);
}
static int test__checkevent_breakpoint_modifier(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "mem:0:u" ));
return test__checkevent_breakpoint(evlist);
}
static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "mem:0:x:k" ));
return test__checkevent_breakpoint_x(evlist);
}
static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "mem:0:r:hp" ));
return test__checkevent_breakpoint_r(evlist);
}
static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "mem:0:w:up" ));
return test__checkevent_breakpoint_w(evlist);
}
static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "mem:0:rw:kp" ));
return test__checkevent_breakpoint_rw(evlist);
}
static int test__checkevent_breakpoint_modifier_name(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "breakpoint" ));
return test__checkevent_breakpoint(evlist);
}
static int test__checkevent_breakpoint_x_modifier_name(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "breakpoint" ));
return test__checkevent_breakpoint_x(evlist);
}
static int test__checkevent_breakpoint_r_modifier_name(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "breakpoint" ));
return test__checkevent_breakpoint_r(evlist);
}
static int test__checkevent_breakpoint_w_modifier_name(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "breakpoint" ));
return test__checkevent_breakpoint_w(evlist);
}
static int test__checkevent_breakpoint_rw_modifier_name(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "breakpoint" ));
return test__checkevent_breakpoint_rw(evlist);
}
static int test__checkevent_breakpoint_2_events(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 2 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "breakpoint1" ));
evsel = evsel__next(evsel);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "breakpoint2" ));
return TEST_OK;
}
static int test__checkevent_pmu(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_RAW == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 10));
TEST_ASSERT_VAL("wrong config1" , 1 == evsel->core.attr.config1);
TEST_ASSERT_VAL("wrong config2" , 3 == evsel->core.attr.config2);
TEST_ASSERT_VAL("wrong config3" , 0 == evsel->core.attr.config3);
/*
* The period value gets configured within evlist__config,
* while this test executes only parse events method.
*/
TEST_ASSERT_VAL("wrong period" , 0 == evsel->core.attr.sample_period);
return TEST_OK;
}
static int test__checkevent_list(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 3 <= evlist->core.nr_entries);
/* r1 */
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_TRACEPOINT != evsel->core.attr.type);
while (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) {
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 1));
TEST_ASSERT_VAL("wrong config1" , 0 == evsel->core.attr.config1);
TEST_ASSERT_VAL("wrong config2" , 0 == evsel->core.attr.config2);
TEST_ASSERT_VAL("wrong config3" , 0 == evsel->core.attr.config3);
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
evsel = evsel__next(evsel);
}
/* syscalls:sys_enter_openat:k */
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong sample_type" ,
PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
TEST_ASSERT_VAL("wrong sample_period" , 1 == evsel->core.attr.sample_period);
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
/* 1:1:hp */
evsel = evsel__next(evsel);
TEST_ASSERT_VAL("wrong type" , 1 == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 1));
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip);
return TEST_OK;
}
static int test__checkevent_pmu_name(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
/* cpu/config=1,name=krava/u */
TEST_ASSERT_VAL("wrong number of entries" , 2 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_RAW == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 1));
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "krava" ));
/* cpu/config=2/u" */
evsel = evsel__next(evsel);
TEST_ASSERT_VAL("wrong number of entries" , 2 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_RAW == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 2));
TEST_ASSERT_VAL("wrong name" , evsel__name_is(evsel, "cpu/config=2/u" ));
return TEST_OK;
}
static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
/* cpu/config=1,call-graph=fp,time,period=100000/ */
TEST_ASSERT_VAL("wrong number of entries" , 2 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_RAW == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 1));
/*
* The period, time and callgraph value gets configured within evlist__config,
* while this test executes only parse events method.
*/
TEST_ASSERT_VAL("wrong period" , 0 == evsel->core.attr.sample_period);
TEST_ASSERT_VAL("wrong callgraph" , !evsel__has_callchain(evsel));
TEST_ASSERT_VAL("wrong time" , !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
/* cpu/config=2,call-graph=no,time=0,period=2000/ */
evsel = evsel__next(evsel);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_RAW == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 2));
/*
* The period, time and callgraph value gets configured within evlist__config,
* while this test executes only parse events method.
*/
TEST_ASSERT_VAL("wrong period" , 0 == evsel->core.attr.sample_period);
TEST_ASSERT_VAL("wrong callgraph" , !evsel__has_callchain(evsel));
TEST_ASSERT_VAL("wrong time" , !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
return TEST_OK;
}
static int test__checkevent_pmu_events(struct evlist *evlist)
{
struct evsel *evsel;
TEST_ASSERT_VAL("wrong number of entries" , 1 <= evlist->core.nr_entries);
evlist__for_each_entry(evlist, evsel) {
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_RAW == evsel->core.attr.type ||
strcmp(evsel->pmu->name, "cpu" ));
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong pinned" , !evsel->core.attr.pinned);
TEST_ASSERT_VAL("wrong exclusive" , !evsel->core.attr.exclusive);
}
return TEST_OK;
}
static int test__checkevent_pmu_events_mix(struct evlist *evlist)
{
struct evsel *evsel = NULL;
/*
* The wild card event will be opened at least once, but it may be
* opened on each core PMU.
*/
TEST_ASSERT_VAL("wrong number of entries" , evlist->core.nr_entries >= 2);
for (int i = 0; i < evlist->core.nr_entries - 1; i++) {
evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
/* pmu-event:u */
TEST_ASSERT_VAL("wrong exclude_user" ,
!evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" ,
evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong pinned" , !evsel->core.attr.pinned);
TEST_ASSERT_VAL("wrong exclusive" , !evsel->core.attr.exclusive);
}
/* cpu/pmu-event/u*/
evsel = evsel__next(evsel);
TEST_ASSERT_VAL("wrong type" , evsel__find_pmu(evsel)->is_core);
TEST_ASSERT_VAL("wrong exclude_user" ,
!evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" ,
evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong pinned" , !evsel->core.attr.pinned);
TEST_ASSERT_VAL("wrong exclusive" , !evsel->core.attr.pinned);
return TEST_OK;
}
static int test__checkterms_simple(struct parse_events_terms *terms)
{
struct parse_events_term *term;
/* config=10 */
term = list_entry(terms->terms.next, struct parse_events_term, list);
TEST_ASSERT_VAL("wrong type term" ,
term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
TEST_ASSERT_VAL("wrong type val" ,
term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
TEST_ASSERT_VAL("wrong val" , term->val.num == 10);
TEST_ASSERT_VAL("wrong config" , !strcmp(term->config, "config" ));
/* config1 */
term = list_entry(term->list.next, struct parse_events_term, list);
TEST_ASSERT_VAL("wrong type term" ,
term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
TEST_ASSERT_VAL("wrong type val" ,
term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
TEST_ASSERT_VAL("wrong val" , term->val.num == 1);
TEST_ASSERT_VAL("wrong config" , !strcmp(term->config, "config1" ));
/* config2=3 */
term = list_entry(term->list.next, struct parse_events_term, list);
TEST_ASSERT_VAL("wrong type term" ,
term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
TEST_ASSERT_VAL("wrong type val" ,
term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
TEST_ASSERT_VAL("wrong val" , term->val.num == 3);
TEST_ASSERT_VAL("wrong config" , !strcmp(term->config, "config2" ));
/* config3=4 */
term = list_entry(term->list.next, struct parse_events_term, list);
TEST_ASSERT_VAL("wrong type term" ,
term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG3);
TEST_ASSERT_VAL("wrong type val" ,
term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
TEST_ASSERT_VAL("wrong val" , term->val.num == 4);
TEST_ASSERT_VAL("wrong config" , !strcmp(term->config, "config3" ));
/* umask=1*/
term = list_entry(term->list.next, struct parse_events_term, list);
TEST_ASSERT_VAL("wrong type term" ,
term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
TEST_ASSERT_VAL("wrong type val" ,
term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
TEST_ASSERT_VAL("wrong val" , term->val.num == 1);
TEST_ASSERT_VAL("wrong config" , !strcmp(term->config, "umask" ));
/*
* read
*
* The perf_pmu__test_parse_init injects 'read' term into
* perf_pmu_events_list, so 'read' is evaluated as read term
* and not as raw event with 'ead' hex value.
*/
term = list_entry(term->list.next, struct parse_events_term, list);
TEST_ASSERT_VAL("wrong type term" ,
term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);
TEST_ASSERT_VAL("wrong type val" ,
term->type_val == PARSE_EVENTS__TERM_TYPE_STR);
TEST_ASSERT_VAL("wrong val" , !strcmp(term->val.str, "read" ));
TEST_ASSERT_VAL("wrong config" , !strcmp(term->config, "raw" ));
/*
* r0xead
*
* To be still able to pass 'ead' value with 'r' syntax,
* we added support to parse 'r0xHEX' event.
*/
term = list_entry(term->list.next, struct parse_events_term, list);
TEST_ASSERT_VAL("wrong type term" ,
term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);
TEST_ASSERT_VAL("wrong type val" ,
term->type_val == PARSE_EVENTS__TERM_TYPE_STR);
TEST_ASSERT_VAL("wrong val" , !strcmp(term->val.str, "r0xead" ));
TEST_ASSERT_VAL("wrong config" , !strcmp(term->config, "raw" ));
return TEST_OK;
}
static int test__group1(struct evlist *evlist)
{
struct evsel *evsel, *leader;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (num_core_entries() * 2));
TEST_ASSERT_VAL("wrong number of groups" ,
evlist__nr_groups(evlist) == num_core_entries());
for (int i = 0; i < num_core_entries(); i++) {
int ret;
/* instructions:k */
evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong core.nr_members" , evsel->core.nr_members == 2);
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 0);
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
/* cycles:upp */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip == 2);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 1);
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
}
return TEST_OK;
}
static int test__group2(struct evlist *evlist)
{
struct evsel *evsel, *leader = NULL;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (2 * num_core_entries() + 1));
/*
* TODO: Currently the software event won't be grouped with the hardware
* event except for 1 PMU.
*/
TEST_ASSERT_VAL("wrong number of groups" , 1 == evlist__nr_groups(evlist));
evlist__for_each_entry(evlist, evsel) {
int ret;
if (evsel->core.attr.type == PERF_TYPE_SOFTWARE) {
/* faults + :ku modifier */
leader = evsel;
TEST_ASSERT_VAL("wrong config" ,
test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS));
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong core.nr_members" , evsel->core.nr_members == 2);
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 0);
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
continue ;
}
if (evsel->core.attr.type == PERF_TYPE_HARDWARE &&
test_config(evsel, PERF_COUNT_HW_BRANCH_INSTRUCTIONS)) {
/* branches + :u modifier */
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
if (evsel__has_leader(evsel, leader))
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 1);
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
continue ;
}
/* cycles:k */
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
}
return TEST_OK;
}
static int test__group3(struct evlist *evlist __maybe_unused)
{
struct evsel *evsel, *group1_leader = NULL, *group2_leader = NULL;
int ret;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (3 * perf_pmus__num_core_pmus() + 2));
/*
* Currently the software event won't be grouped with the hardware event
* except for 1 PMU. This means there are always just 2 groups
* regardless of the number of core PMUs.
*/
TEST_ASSERT_VAL("wrong number of groups" , 2 == evlist__nr_groups(evlist));
evlist__for_each_entry(evlist, evsel) {
if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) {
/* group1 syscalls:sys_enter_openat:H */
group1_leader = evsel;
TEST_ASSERT_VAL("wrong sample_type" ,
evsel->core.attr.sample_type == PERF_TP_SAMPLE_TYPE);
TEST_ASSERT_VAL("wrong sample_period" , 1 == evsel->core.attr.sample_period);
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong group name" , !strcmp(evsel->group_name, "group1" ));
TEST_ASSERT_VAL("wrong core.nr_members" , evsel->core.nr_members == 2);
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 0);
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
continue ;
}
if (evsel->core.attr.type == PERF_TYPE_HARDWARE &&
test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)) {
if (evsel->core.attr.exclude_user) {
/* group1 cycles:kppp */
TEST_ASSERT_VAL("wrong exclude_user" ,
evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" ,
!evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" ,
!evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" ,
!evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" ,
evsel->core.attr.precise_ip == 3);
if (evsel__has_leader(evsel, group1_leader)) {
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong group_idx" ,
evsel__group_idx(evsel) == 1);
}
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
} else {
/* group2 cycles + G modifier */
group2_leader = evsel;
TEST_ASSERT_VAL("wrong exclude_kernel" ,
!evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" ,
!evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" ,
!evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" ,
evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
if (evsel->core.nr_members == 2) {
TEST_ASSERT_VAL("wrong group_idx" ,
evsel__group_idx(evsel) == 0);
}
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
}
continue ;
}
if (evsel->core.attr.type == 1) {
/* group2 1:3 + G modifier */
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 3));
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
if (evsel__has_leader(evsel, group2_leader))
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 1);
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
continue ;
}
/* instructions:u */
ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
}
return TEST_OK;
}
static int test__group4(struct evlist *evlist __maybe_unused)
{
struct evsel *evsel, *leader;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (num_core_entries() * 2));
TEST_ASSERT_VAL("wrong number of groups" ,
num_core_entries() == evlist__nr_groups(evlist));
for (int i = 0; i < num_core_entries(); i++) {
int ret;
/* cycles:u + p */
evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip == 1);
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong core.nr_members" , evsel->core.nr_members == 2);
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 0);
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
/* instructions:kp + p */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip == 2);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 1);
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
}
return TEST_OK;
}
static int test__group5(struct evlist *evlist __maybe_unused)
{
struct evsel *evsel = NULL, *leader;
int ret;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (5 * num_core_entries()));
TEST_ASSERT_VAL("wrong number of groups" ,
evlist__nr_groups(evlist) == (2 * num_core_entries()));
for (int i = 0; i < num_core_entries(); i++) {
/* cycles + G */
evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong core.nr_members" , evsel->core.nr_members == 2);
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 0);
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
/* instructions + G */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 1);
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
}
for (int i = 0; i < num_core_entries(); i++) {
/* cycles:G */
evsel = leader = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong core.nr_members" , evsel->core.nr_members == 2);
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 0);
TEST_ASSERT_VAL("wrong sample_read" , !evsel->sample_read);
/* instructions:G */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 1);
}
for (int i = 0; i < num_core_entries(); i++) {
/* cycles */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
}
return TEST_OK;
}
static int test__group_gh1(struct evlist *evlist)
{
struct evsel *evsel = NULL, *leader;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (2 * num_core_entries()));
TEST_ASSERT_VAL("wrong number of groups" ,
evlist__nr_groups(evlist) == num_core_entries());
for (int i = 0; i < num_core_entries(); i++) {
int ret;
/* cycles + :H group modifier */
evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong core.nr_members" , evsel->core.nr_members == 2);
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 0);
/* cache-misses:G + :H group modifier */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 1);
}
return TEST_OK;
}
static int test__group_gh2(struct evlist *evlist)
{
struct evsel *evsel = NULL, *leader;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (2 * num_core_entries()));
TEST_ASSERT_VAL("wrong number of groups" ,
evlist__nr_groups(evlist) == num_core_entries());
for (int i = 0; i < num_core_entries(); i++) {
int ret;
/* cycles + :G group modifier */
evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong core.nr_members" , evsel->core.nr_members == 2);
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 0);
/* cache-misses:H + :G group modifier */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 1);
}
return TEST_OK;
}
static int test__group_gh3(struct evlist *evlist)
{
struct evsel *evsel = NULL, *leader;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (2 * num_core_entries()));
TEST_ASSERT_VAL("wrong number of groups" ,
evlist__nr_groups(evlist) == num_core_entries());
for (int i = 0; i < num_core_entries(); i++) {
int ret;
/* cycles:G + :u group modifier */
evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong core.nr_members" , evsel->core.nr_members == 2);
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 0);
/* cache-misses:H + :u group modifier */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 1);
}
return TEST_OK;
}
static int test__group_gh4(struct evlist *evlist)
{
struct evsel *evsel = NULL, *leader;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (2 * num_core_entries()));
TEST_ASSERT_VAL("wrong number of groups" ,
evlist__nr_groups(evlist) == num_core_entries());
for (int i = 0; i < num_core_entries(); i++) {
int ret;
/* cycles:G + :uG group modifier */
evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__is_group_leader(evsel));
TEST_ASSERT_VAL("wrong core.nr_members" , evsel->core.nr_members == 2);
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 0);
/* cache-misses:H + :uG group modifier */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong group_idx" , evsel__group_idx(evsel) == 1);
}
return TEST_OK;
}
static int test__leader_sample1(struct evlist *evlist)
{
struct evsel *evsel = NULL, *leader;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (3 * num_core_entries()));
for (int i = 0; i < num_core_entries(); i++) {
int ret;
/* cycles - sampling group leader */
evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong sample_read" , evsel->sample_read);
/* cache-misses - not sampling */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong sample_read" , evsel->sample_read);
/* branch-misses - not sampling */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_BRANCH_MISSES, "branch-misses" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , !evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , !evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong sample_read" , evsel->sample_read);
}
return TEST_OK;
}
static int test__leader_sample2(struct evlist *evlist __maybe_unused)
{
struct evsel *evsel = NULL, *leader;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (2 * num_core_entries()));
for (int i = 0; i < num_core_entries(); i++) {
int ret;
/* instructions - sampling group leader */
evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong sample_read" , evsel->sample_read);
/* branch-misses - not sampling */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_BRANCH_MISSES, "branch-misses" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong exclude guest" , !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host" , !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
TEST_ASSERT_VAL("wrong sample_read" , evsel->sample_read);
}
return TEST_OK;
}
static int test__checkevent_pinned_modifier(struct evlist *evlist)
{
struct evsel *evsel = NULL;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == num_core_entries());
for (int i = 0; i < num_core_entries(); i++) {
evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong pinned" , evsel->core.attr.pinned);
}
return test__checkevent_symbolic_name(evlist);
}
static int test__pinned_group(struct evlist *evlist)
{
struct evsel *evsel = NULL, *leader;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == (3 * num_core_entries()));
for (int i = 0; i < num_core_entries(); i++) {
int ret;
/* cycles - group leader */
evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
/* TODO: The group modifier is not copied to the split group leader. */
if (perf_pmus__num_core_pmus() == 1)
TEST_ASSERT_VAL("wrong pinned" , evsel->core.attr.pinned);
/* cache-misses - can not be pinned, but will go on with the leader */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong pinned" , !evsel->core.attr.pinned);
/* branch-misses - ditto */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_BRANCH_MISSES, "branch-misses" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong pinned" , !evsel->core.attr.pinned);
}
return TEST_OK;
}
static int test__checkevent_exclusive_modifier(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong exclusive" , evsel->core.attr.exclusive);
return test__checkevent_symbolic_name(evlist);
}
static int test__exclusive_group(struct evlist *evlist)
{
struct evsel *evsel = NULL, *leader;
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == 3 * num_core_entries());
for (int i = 0; i < num_core_entries(); i++) {
int ret;
/* cycles - group leader */
evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong group name" , !evsel->group_name);
TEST_ASSERT_VAL("wrong leader" , evsel__has_leader(evsel, leader));
/* TODO: The group modifier is not copied to the split group leader. */
if (perf_pmus__num_core_pmus() == 1)
TEST_ASSERT_VAL("wrong exclusive" , evsel->core.attr.exclusive);
/* cache-misses - can not be pinned, but will go on with the leader */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclusive" , !evsel->core.attr.exclusive);
/* branch-misses - ditto */
evsel = evsel__next(evsel);
ret = assert_hw(&evsel->core, PERF_COUNT_HW_BRANCH_MISSES, "branch-misses" );
if (ret)
return ret;
TEST_ASSERT_VAL("wrong exclusive" , !evsel->core.attr.exclusive);
}
return TEST_OK;
}
static int test__checkevent_breakpoint_len(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 0));
TEST_ASSERT_VAL("wrong bp_type" , (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
evsel->core.attr.bp_type);
TEST_ASSERT_VAL("wrong bp_len" , HW_BREAKPOINT_LEN_1 ==
evsel->core.attr.bp_len);
return TEST_OK;
}
static int test__checkevent_breakpoint_len_w(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" , 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, 0));
TEST_ASSERT_VAL("wrong bp_type" , HW_BREAKPOINT_W ==
evsel->core.attr.bp_type);
TEST_ASSERT_VAL("wrong bp_len" , HW_BREAKPOINT_LEN_2 ==
evsel->core.attr.bp_len);
return TEST_OK;
}
static int
test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user" , !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel" , evsel->core.attr.exclude_kernel);
TEST_ASSERT_VAL("wrong exclude_hv" , evsel->core.attr.exclude_hv);
TEST_ASSERT_VAL("wrong precise_ip" , !evsel->core.attr.precise_ip);
return test__checkevent_breakpoint_rw(evlist);
}
static int test__checkevent_precise_max_modifier(struct evlist *evlist)
{
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries" ,
evlist->core.nr_entries == 1 + num_core_entries());
TEST_ASSERT_VAL("wrong type" , PERF_TYPE_SOFTWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config" , test_config(evsel, PERF_COUNT_SW_TASK_CLOCK));
return TEST_OK;
}
static int test__checkevent_config_symbol(struct evlist *evlist)
{
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5 C=97 H=94 G=95
¤ Dauer der Verarbeitung: 0.45 Sekunden
(vorverarbeitet)
¤
*© Formatika GbR, Deutschland