brintos

brintos / linux-shallow public Read only

0
0
Text · 89.8 KiB · 9e3086d Raw
2882 lines · c
1// SPDX-License-Identifier: GPL-2.02#include "parse-events.h"3#include "evsel.h"4#include "evlist.h"5#include <api/fs/fs.h>6#include "tests.h"7#include "debug.h"8#include "pmu.h"9#include "pmus.h"10#include <dirent.h>11#include <errno.h>12#include "fncache.h"13#include <sys/types.h>14#include <sys/stat.h>15#include <unistd.h>16#include <linux/kernel.h>17#include <linux/hw_breakpoint.h>18#include <api/fs/tracing_path.h>19 20#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \21			     PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)22 23static int num_core_entries(void)24{25	/*26	 * If the kernel supports extended type, expect events to be27	 * opened once for each core PMU type. Otherwise fall back to the legacy28	 * behavior of opening only one event even though there are multiple29	 * PMUs30	 */31	if (perf_pmus__supports_extended_type())32		return perf_pmus__num_core_pmus();33 34	return 1;35}36 37static bool test_config(const struct evsel *evsel, __u64 expected_config)38{39	__u32 type = evsel->core.attr.type;40	__u64 config = evsel->core.attr.config;41 42	if (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE) {43		/*44		 * HARDWARE and HW_CACHE events encode the PMU's extended type45		 * in the top 32-bits. Mask in order to ignore.46		 */47		config &= PERF_HW_EVENT_MASK;48	}49	return config == expected_config;50}51 52static bool test_perf_config(const struct perf_evsel *evsel, __u64 expected_config)53{54	return (evsel->attr.config & PERF_HW_EVENT_MASK) == expected_config;55}56 57#ifdef HAVE_LIBTRACEEVENT58 59#if defined(__s390x__)60/* Return true if kvm module is available and loaded. Test this61 * and return success when trace point kvm_s390_create_vm62 * exists. Otherwise this test always fails.63 */64static bool kvm_s390_create_vm_valid(void)65{66	char *eventfile;67	bool rc = false;68 69	eventfile = get_events_file("kvm-s390");70 71	if (eventfile) {72		DIR *mydir = opendir(eventfile);73 74		if (mydir) {75			rc = true;76			closedir(mydir);77		}78		put_events_file(eventfile);79	}80 81	return rc;82}83#endif84 85static int test__checkevent_tracepoint(struct evlist *evlist)86{87	struct evsel *evsel = evlist__first(evlist);88 89	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);90	TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist));91	TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);92	TEST_ASSERT_VAL("wrong sample_type",93		PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);94	TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);95	return TEST_OK;96}97 98static int test__checkevent_tracepoint_multi(struct evlist *evlist)99{100	struct evsel *evsel;101 102	TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);103	TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist));104 105	evlist__for_each_entry(evlist, evsel) {106		TEST_ASSERT_VAL("wrong type",107			PERF_TYPE_TRACEPOINT == evsel->core.attr.type);108		TEST_ASSERT_VAL("wrong sample_type",109			PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);110		TEST_ASSERT_VAL("wrong sample_period",111			1 == evsel->core.attr.sample_period);112	}113	return TEST_OK;114}115#endif /* HAVE_LIBTRACEEVENT */116 117static int test__checkevent_raw(struct evlist *evlist)118{119	struct perf_evsel *evsel;120	bool raw_type_match = false;121 122	TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);123 124	perf_evlist__for_each_evsel(&evlist->core, evsel) {125		struct perf_pmu *pmu __maybe_unused = NULL;126		bool type_matched = false;127 128		TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a));129		TEST_ASSERT_VAL("event not parsed as raw type",130				evsel->attr.type == PERF_TYPE_RAW);131#if defined(__aarch64__)132		/*133		 * Arm doesn't have a real raw type PMU in sysfs, so raw events134		 * would never match any PMU. However, RAW events on Arm will135		 * always successfully open on the first available core PMU136		 * so no need to test for a matching type here.137		 */138		type_matched = raw_type_match = true;139#else140		while ((pmu = perf_pmus__scan(pmu)) != NULL) {141			if (pmu->type == evsel->attr.type) {142				TEST_ASSERT_VAL("PMU type expected once", !type_matched);143				type_matched = true;144				if (pmu->type == PERF_TYPE_RAW)145					raw_type_match = true;146			}147		}148#endif149		TEST_ASSERT_VAL("No PMU found for type", type_matched);150	}151	TEST_ASSERT_VAL("Raw PMU not matched", raw_type_match);152	return TEST_OK;153}154 155static int test__checkevent_numeric(struct evlist *evlist)156{157	struct evsel *evsel = evlist__first(evlist);158 159	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);160	TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);161	TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));162	return TEST_OK;163}164 165 166static int assert_hw(struct perf_evsel *evsel, enum perf_hw_id id, const char *name)167{168	struct perf_pmu *pmu;169 170	if (evsel->attr.type == PERF_TYPE_HARDWARE) {171		TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, id));172		return 0;173	}174	pmu = perf_pmus__find_by_type(evsel->attr.type);175 176	TEST_ASSERT_VAL("unexpected PMU type", pmu);177	TEST_ASSERT_VAL("PMU missing event", perf_pmu__have_event(pmu, name));178	return 0;179}180 181static int test__checkevent_symbolic_name(struct evlist *evlist)182{183	struct perf_evsel *evsel;184 185	TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);186 187	perf_evlist__for_each_evsel(&evlist->core, evsel) {188		int ret = assert_hw(evsel, PERF_COUNT_HW_INSTRUCTIONS, "instructions");189 190		if (ret)191			return ret;192	}193 194	return TEST_OK;195}196 197static int test__checkevent_symbolic_name_config(struct evlist *evlist)198{199	struct perf_evsel *evsel;200 201	TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);202 203	perf_evlist__for_each_evsel(&evlist->core, evsel) {204		int ret = assert_hw(evsel, PERF_COUNT_HW_CPU_CYCLES, "cycles");205 206		if (ret)207			return ret;208		/*209		 * The period value gets configured within evlist__config,210		 * while this test executes only parse events method.211		 */212		TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);213		TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);214		TEST_ASSERT_VAL("wrong config2", 1 == evsel->attr.config2);215	}216	return TEST_OK;217}218 219static int test__checkevent_symbolic_alias(struct evlist *evlist)220{221	struct evsel *evsel = evlist__first(evlist);222 223	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);224	TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);225	TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS));226	return TEST_OK;227}228 229static int test__checkevent_genhw(struct evlist *evlist)230{231	struct perf_evsel *evsel;232 233	TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);234 235	perf_evlist__for_each_entry(&evlist->core, evsel) {236		TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);237		TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 1 << 16));238	}239	return TEST_OK;240}241 242static int test__checkevent_breakpoint(struct evlist *evlist)243{244	struct evsel *evsel = evlist__first(evlist);245 246	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);247	TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);248	TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));249	TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==250					 evsel->core.attr.bp_type);251	TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==252					evsel->core.attr.bp_len);253	return TEST_OK;254}255 256static int test__checkevent_breakpoint_x(struct evlist *evlist)257{258	struct evsel *evsel = evlist__first(evlist);259 260	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);261	TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);262	TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));263	TEST_ASSERT_VAL("wrong bp_type",264			HW_BREAKPOINT_X == evsel->core.attr.bp_type);265	TEST_ASSERT_VAL("wrong bp_len", default_breakpoint_len() == evsel->core.attr.bp_len);266	return TEST_OK;267}268 269static int test__checkevent_breakpoint_r(struct evlist *evlist)270{271	struct evsel *evsel = evlist__first(evlist);272 273	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);274	TEST_ASSERT_VAL("wrong type",275			PERF_TYPE_BREAKPOINT == evsel->core.attr.type);276	TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));277	TEST_ASSERT_VAL("wrong bp_type",278			HW_BREAKPOINT_R == evsel->core.attr.bp_type);279	TEST_ASSERT_VAL("wrong bp_len",280			HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);281	return TEST_OK;282}283 284static int test__checkevent_breakpoint_w(struct evlist *evlist)285{286	struct evsel *evsel = evlist__first(evlist);287 288	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);289	TEST_ASSERT_VAL("wrong type",290			PERF_TYPE_BREAKPOINT == evsel->core.attr.type);291	TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));292	TEST_ASSERT_VAL("wrong bp_type",293			HW_BREAKPOINT_W == evsel->core.attr.bp_type);294	TEST_ASSERT_VAL("wrong bp_len",295			HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);296	return TEST_OK;297}298 299static int test__checkevent_breakpoint_rw(struct evlist *evlist)300{301	struct evsel *evsel = evlist__first(evlist);302 303	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);304	TEST_ASSERT_VAL("wrong type",305			PERF_TYPE_BREAKPOINT == evsel->core.attr.type);306	TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));307	TEST_ASSERT_VAL("wrong bp_type",308		(HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->core.attr.bp_type);309	TEST_ASSERT_VAL("wrong bp_len",310			HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);311	return TEST_OK;312}313 314#ifdef HAVE_LIBTRACEEVENT315static int test__checkevent_tracepoint_modifier(struct evlist *evlist)316{317	struct evsel *evsel = evlist__first(evlist);318 319	TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);320	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);321	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);322	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);323 324	return test__checkevent_tracepoint(evlist);325}326 327static int328test__checkevent_tracepoint_multi_modifier(struct evlist *evlist)329{330	struct perf_evsel *evsel;331 332	TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);333 334	perf_evlist__for_each_entry(&evlist->core, evsel) {335		TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);336		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);337		TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);338		TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);339	}340 341	return test__checkevent_tracepoint_multi(evlist);342}343#endif /* HAVE_LIBTRACEEVENT */344 345static int test__checkevent_raw_modifier(struct evlist *evlist)346{347	struct perf_evsel *evsel;348 349	perf_evlist__for_each_entry(&evlist->core, evsel) {350		TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);351		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);352		TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);353		TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);354	}355	return test__checkevent_raw(evlist);356}357 358static int test__checkevent_numeric_modifier(struct evlist *evlist)359{360	struct perf_evsel *evsel;361 362	perf_evlist__for_each_entry(&evlist->core, evsel) {363		TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);364		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);365		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);366		TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);367	}368	return test__checkevent_numeric(evlist);369}370 371static int test__checkevent_symbolic_name_modifier(struct evlist *evlist)372{373	struct perf_evsel *evsel;374 375	TEST_ASSERT_VAL("wrong number of entries",376			evlist->core.nr_entries == num_core_entries());377 378	perf_evlist__for_each_entry(&evlist->core, evsel) {379		TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);380		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);381		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);382		TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);383	}384	return test__checkevent_symbolic_name(evlist);385}386 387static int test__checkevent_exclude_host_modifier(struct evlist *evlist)388{389	struct perf_evsel *evsel;390 391	perf_evlist__for_each_entry(&evlist->core, evsel) {392		TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);393		TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);394	}395	return test__checkevent_symbolic_name(evlist);396}397 398static int test__checkevent_exclude_guest_modifier(struct evlist *evlist)399{400	struct perf_evsel *evsel;401 402	perf_evlist__for_each_entry(&evlist->core, evsel) {403		TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);404		TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);405	}406	return test__checkevent_symbolic_name(evlist);407}408 409static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist)410{411	struct evsel *evsel = evlist__first(evlist);412 413	TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);414	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);415	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);416	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);417 418	return test__checkevent_symbolic_alias(evlist);419}420 421static int test__checkevent_genhw_modifier(struct evlist *evlist)422{423	struct perf_evsel *evsel;424 425	perf_evlist__for_each_entry(&evlist->core, evsel) {426		TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);427		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);428		TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);429		TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);430	}431	return test__checkevent_genhw(evlist);432}433 434static int test__checkevent_exclude_idle_modifier(struct evlist *evlist)435{436	struct evsel *evsel = evlist__first(evlist);437 438	TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);439	TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);440	TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);441	TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);442	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);443	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);444	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);445 446	return test__checkevent_symbolic_name(evlist);447}448 449static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist)450{451	struct evsel *evsel = evlist__first(evlist);452 453	TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);454	TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);455	TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);456	TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);457	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);458	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);459	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);460 461	return test__checkevent_symbolic_name(evlist);462}463 464static int test__checkevent_breakpoint_modifier(struct evlist *evlist)465{466	struct evsel *evsel = evlist__first(evlist);467 468 469	TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);470	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);471	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);472	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);473	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "mem:0:u"));474 475	return test__checkevent_breakpoint(evlist);476}477 478static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)479{480	struct evsel *evsel = evlist__first(evlist);481 482	TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);483	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);484	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);485	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);486	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "mem:0:x:k"));487 488	return test__checkevent_breakpoint_x(evlist);489}490 491static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)492{493	struct evsel *evsel = evlist__first(evlist);494 495	TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);496	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);497	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);498	TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);499	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "mem:0:r:hp"));500 501	return test__checkevent_breakpoint_r(evlist);502}503 504static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)505{506	struct evsel *evsel = evlist__first(evlist);507 508	TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);509	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);510	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);511	TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);512	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "mem:0:w:up"));513 514	return test__checkevent_breakpoint_w(evlist);515}516 517static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)518{519	struct evsel *evsel = evlist__first(evlist);520 521	TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);522	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);523	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);524	TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);525	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "mem:0:rw:kp"));526 527	return test__checkevent_breakpoint_rw(evlist);528}529 530static int test__checkevent_breakpoint_modifier_name(struct evlist *evlist)531{532	struct evsel *evsel = evlist__first(evlist);533 534	TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);535	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);536	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);537	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);538	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint"));539 540	return test__checkevent_breakpoint(evlist);541}542 543static int test__checkevent_breakpoint_x_modifier_name(struct evlist *evlist)544{545	struct evsel *evsel = evlist__first(evlist);546 547	TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);548	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);549	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);550	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);551	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint"));552 553	return test__checkevent_breakpoint_x(evlist);554}555 556static int test__checkevent_breakpoint_r_modifier_name(struct evlist *evlist)557{558	struct evsel *evsel = evlist__first(evlist);559 560	TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);561	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);562	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);563	TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);564	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint"));565 566	return test__checkevent_breakpoint_r(evlist);567}568 569static int test__checkevent_breakpoint_w_modifier_name(struct evlist *evlist)570{571	struct evsel *evsel = evlist__first(evlist);572 573	TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);574	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);575	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);576	TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);577	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint"));578 579	return test__checkevent_breakpoint_w(evlist);580}581 582static int test__checkevent_breakpoint_rw_modifier_name(struct evlist *evlist)583{584	struct evsel *evsel = evlist__first(evlist);585 586	TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);587	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);588	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);589	TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);590	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint"));591 592	return test__checkevent_breakpoint_rw(evlist);593}594 595static int test__checkevent_breakpoint_2_events(struct evlist *evlist)596{597	struct evsel *evsel = evlist__first(evlist);598 599	TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);600 601	TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);602	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint1"));603 604	evsel = evsel__next(evsel);605 606	TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);607	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "breakpoint2"));608 609	return TEST_OK;610}611 612static int test__checkevent_pmu(struct evlist *evlist)613{614 615	struct evsel *evsel = evlist__first(evlist);616 617	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);618	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);619	TEST_ASSERT_VAL("wrong config",    test_config(evsel, 10));620	TEST_ASSERT_VAL("wrong config1",    1 == evsel->core.attr.config1);621	TEST_ASSERT_VAL("wrong config2",    3 == evsel->core.attr.config2);622	TEST_ASSERT_VAL("wrong config3",    0 == evsel->core.attr.config3);623	/*624	 * The period value gets configured within evlist__config,625	 * while this test executes only parse events method.626	 */627	TEST_ASSERT_VAL("wrong period",     0 == evsel->core.attr.sample_period);628 629	return TEST_OK;630}631 632#ifdef HAVE_LIBTRACEEVENT633static int test__checkevent_list(struct evlist *evlist)634{635	struct evsel *evsel = evlist__first(evlist);636 637	TEST_ASSERT_VAL("wrong number of entries", 3 <= evlist->core.nr_entries);638 639	/* r1 */640	TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT != evsel->core.attr.type);641	while (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) {642		TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));643		TEST_ASSERT_VAL("wrong config1", 0 == evsel->core.attr.config1);644		TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);645		TEST_ASSERT_VAL("wrong config3", 0 == evsel->core.attr.config3);646		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);647		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);648		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);649		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);650		evsel = evsel__next(evsel);651	}652 653	/* syscalls:sys_enter_openat:k */654	TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);655	TEST_ASSERT_VAL("wrong sample_type",656		PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);657	TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);658	TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);659	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);660	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);661	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);662 663	/* 1:1:hp */664	evsel = evsel__next(evsel);665	TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);666	TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));667	TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);668	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);669	TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);670	TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);671 672	return TEST_OK;673}674#endif675 676static int test__checkevent_pmu_name(struct evlist *evlist)677{678	struct evsel *evsel = evlist__first(evlist);679 680	/* cpu/config=1,name=krava/u */681	TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);682	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);683	TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));684	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "krava"));685 686	/* cpu/config=2/u" */687	evsel = evsel__next(evsel);688	TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);689	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);690	TEST_ASSERT_VAL("wrong config", test_config(evsel, 2));691	TEST_ASSERT_VAL("wrong name", evsel__name_is(evsel, "cpu/config=2/u"));692 693	return TEST_OK;694}695 696static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist)697{698	struct evsel *evsel = evlist__first(evlist);699 700	/* cpu/config=1,call-graph=fp,time,period=100000/ */701	TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);702	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);703	TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));704	/*705	 * The period, time and callgraph value gets configured within evlist__config,706	 * while this test executes only parse events method.707	 */708	TEST_ASSERT_VAL("wrong period",     0 == evsel->core.attr.sample_period);709	TEST_ASSERT_VAL("wrong callgraph",  !evsel__has_callchain(evsel));710	TEST_ASSERT_VAL("wrong time",  !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));711 712	/* cpu/config=2,call-graph=no,time=0,period=2000/ */713	evsel = evsel__next(evsel);714	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);715	TEST_ASSERT_VAL("wrong config", test_config(evsel, 2));716	/*717	 * The period, time and callgraph value gets configured within evlist__config,718	 * while this test executes only parse events method.719	 */720	TEST_ASSERT_VAL("wrong period",     0 == evsel->core.attr.sample_period);721	TEST_ASSERT_VAL("wrong callgraph",  !evsel__has_callchain(evsel));722	TEST_ASSERT_VAL("wrong time",  !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));723 724	return TEST_OK;725}726 727static int test__checkevent_pmu_events(struct evlist *evlist)728{729	struct evsel *evsel = evlist__first(evlist);730 731	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);732	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type ||733				      strcmp(evsel->pmu_name, "cpu"));734	TEST_ASSERT_VAL("wrong exclude_user",735			!evsel->core.attr.exclude_user);736	TEST_ASSERT_VAL("wrong exclude_kernel",737			evsel->core.attr.exclude_kernel);738	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);739	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);740	TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);741	TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);742 743	return TEST_OK;744}745 746 747static int test__checkevent_pmu_events_mix(struct evlist *evlist)748{749	struct evsel *evsel = NULL;750 751	/*752	 * The wild card event will be opened at least once, but it may be753	 * opened on each core PMU.754	 */755	TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries >= 2);756	for (int i = 0; i < evlist->core.nr_entries - 1; i++) {757		evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));758		/* pmu-event:u */759		TEST_ASSERT_VAL("wrong exclude_user",760				!evsel->core.attr.exclude_user);761		TEST_ASSERT_VAL("wrong exclude_kernel",762				evsel->core.attr.exclude_kernel);763		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);764		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);765		TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);766		TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);767	}768	/* cpu/pmu-event/u*/769	evsel = evsel__next(evsel);770	TEST_ASSERT_VAL("wrong type", evsel__find_pmu(evsel)->is_core);771	TEST_ASSERT_VAL("wrong exclude_user",772			!evsel->core.attr.exclude_user);773	TEST_ASSERT_VAL("wrong exclude_kernel",774			evsel->core.attr.exclude_kernel);775	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);776	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);777	TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);778	TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.pinned);779 780	return TEST_OK;781}782 783static int test__checkterms_simple(struct parse_events_terms *terms)784{785	struct parse_events_term *term;786 787	/* config=10 */788	term = list_entry(terms->terms.next, struct parse_events_term, list);789	TEST_ASSERT_VAL("wrong type term",790			term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);791	TEST_ASSERT_VAL("wrong type val",792			term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);793	TEST_ASSERT_VAL("wrong val", term->val.num == 10);794	TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config"));795 796	/* config1 */797	term = list_entry(term->list.next, struct parse_events_term, list);798	TEST_ASSERT_VAL("wrong type term",799			term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);800	TEST_ASSERT_VAL("wrong type val",801			term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);802	TEST_ASSERT_VAL("wrong val", term->val.num == 1);803	TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config1"));804 805	/* config2=3 */806	term = list_entry(term->list.next, struct parse_events_term, list);807	TEST_ASSERT_VAL("wrong type term",808			term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);809	TEST_ASSERT_VAL("wrong type val",810			term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);811	TEST_ASSERT_VAL("wrong val", term->val.num == 3);812	TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config2"));813 814	/* config3=4 */815	term = list_entry(term->list.next, struct parse_events_term, list);816	TEST_ASSERT_VAL("wrong type term",817			term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG3);818	TEST_ASSERT_VAL("wrong type val",819			term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);820	TEST_ASSERT_VAL("wrong val", term->val.num == 4);821	TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config3"));822 823	/* umask=1*/824	term = list_entry(term->list.next, struct parse_events_term, list);825	TEST_ASSERT_VAL("wrong type term",826			term->type_term == PARSE_EVENTS__TERM_TYPE_USER);827	TEST_ASSERT_VAL("wrong type val",828			term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);829	TEST_ASSERT_VAL("wrong val", term->val.num == 1);830	TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));831 832	/*833	 * read834	 *835	 * The perf_pmu__test_parse_init injects 'read' term into836	 * perf_pmu_events_list, so 'read' is evaluated as read term837	 * and not as raw event with 'ead' hex value.838	 */839	term = list_entry(term->list.next, struct parse_events_term, list);840	TEST_ASSERT_VAL("wrong type term",841			term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);842	TEST_ASSERT_VAL("wrong type val",843			term->type_val == PARSE_EVENTS__TERM_TYPE_STR);844	TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "read"));845	TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw"));846 847	/*848	 * r0xead849	 *850	 * To be still able to pass 'ead' value with 'r' syntax,851	 * we added support to parse 'r0xHEX' event.852	 */853	term = list_entry(term->list.next, struct parse_events_term, list);854	TEST_ASSERT_VAL("wrong type term",855			term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);856	TEST_ASSERT_VAL("wrong type val",857			term->type_val == PARSE_EVENTS__TERM_TYPE_STR);858	TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "r0xead"));859	TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw"));860	return TEST_OK;861}862 863static int test__group1(struct evlist *evlist)864{865	struct evsel *evsel, *leader;866 867	TEST_ASSERT_VAL("wrong number of entries",868			evlist->core.nr_entries == (num_core_entries() * 2));869	TEST_ASSERT_VAL("wrong number of groups",870			evlist__nr_groups(evlist) == num_core_entries());871 872	for (int i = 0; i < num_core_entries(); i++) {873		int ret;874 875		/* instructions:k */876		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));877		ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions");878		if (ret)879			return ret;880 881		TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);882		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);883		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);884		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);885		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);886		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);887		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));888		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);889		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);890		TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);891 892		/* cycles:upp */893		evsel = evsel__next(evsel);894		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");895		if (ret)896			return ret;897 898		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);899		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);900		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);901		/* use of precise requires exclude_guest */902		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);903		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);904		TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);905		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));906		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);907		TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);908	}909	return TEST_OK;910}911 912static int test__group2(struct evlist *evlist)913{914	struct evsel *evsel, *leader = NULL;915 916	TEST_ASSERT_VAL("wrong number of entries",917			evlist->core.nr_entries == (2 * num_core_entries() + 1));918	/*919	 * TODO: Currently the software event won't be grouped with the hardware920	 * event except for 1 PMU.921	 */922	TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));923 924	evlist__for_each_entry(evlist, evsel) {925		int ret;926 927		if (evsel->core.attr.type == PERF_TYPE_SOFTWARE) {928			/* faults + :ku modifier */929			leader = evsel;930			TEST_ASSERT_VAL("wrong config",931					test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS));932			TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);933			TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);934			TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);935			TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);936			TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);937			TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);938			TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));939			TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);940			TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);941			TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);942			continue;943		}944		if (evsel->core.attr.type == PERF_TYPE_HARDWARE &&945		    test_config(evsel, PERF_COUNT_HW_BRANCH_INSTRUCTIONS)) {946			/* branches + :u modifier */947			TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);948			TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);949			TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);950			TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);951			TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);952			TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);953			if (evsel__has_leader(evsel, leader))954				TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);955			TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);956			continue;957		}958		/* cycles:k */959		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");960		if (ret)961			return ret;962 963		TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);964		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);965		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);966		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);967		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);968		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);969		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));970		TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);971	}972	return TEST_OK;973}974 975#ifdef HAVE_LIBTRACEEVENT976static int test__group3(struct evlist *evlist __maybe_unused)977{978	struct evsel *evsel, *group1_leader = NULL, *group2_leader = NULL;979	int ret;980 981	TEST_ASSERT_VAL("wrong number of entries",982			evlist->core.nr_entries == (3 * perf_pmus__num_core_pmus() + 2));983	/*984	 * Currently the software event won't be grouped with the hardware event985	 * except for 1 PMU. This means there are always just 2 groups986	 * regardless of the number of core PMUs.987	 */988	TEST_ASSERT_VAL("wrong number of groups", 2 == evlist__nr_groups(evlist));989 990	evlist__for_each_entry(evlist, evsel) {991		if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) {992			/* group1 syscalls:sys_enter_openat:H */993			group1_leader = evsel;994			TEST_ASSERT_VAL("wrong sample_type",995					evsel->core.attr.sample_type == PERF_TP_SAMPLE_TYPE);996			TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);997			TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);998			TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);999			TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1000			TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1001			TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1002			TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1003			TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));1004			TEST_ASSERT_VAL("wrong group name", !strcmp(evsel->group_name, "group1"));1005			TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);1006			TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);1007			TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);1008			continue;1009		}1010		if (evsel->core.attr.type == PERF_TYPE_HARDWARE &&1011		    test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)) {1012			if (evsel->core.attr.exclude_user) {1013				/* group1 cycles:kppp */1014				TEST_ASSERT_VAL("wrong exclude_user",1015						evsel->core.attr.exclude_user);1016				TEST_ASSERT_VAL("wrong exclude_kernel",1017						!evsel->core.attr.exclude_kernel);1018				TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1019				/* use of precise requires exclude_guest */1020				TEST_ASSERT_VAL("wrong exclude guest",1021						evsel->core.attr.exclude_guest);1022				TEST_ASSERT_VAL("wrong exclude host",1023						!evsel->core.attr.exclude_host);1024				TEST_ASSERT_VAL("wrong precise_ip",1025						evsel->core.attr.precise_ip == 3);1026				if (evsel__has_leader(evsel, group1_leader)) {1027					TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1028					TEST_ASSERT_VAL("wrong group_idx",1029							evsel__group_idx(evsel) == 1);1030				}1031				TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);1032			} else {1033				/* group2 cycles + G modifier */1034				group2_leader = evsel;1035				TEST_ASSERT_VAL("wrong exclude_kernel",1036						!evsel->core.attr.exclude_kernel);1037				TEST_ASSERT_VAL("wrong exclude_hv",1038						!evsel->core.attr.exclude_hv);1039				TEST_ASSERT_VAL("wrong exclude guest",1040						!evsel->core.attr.exclude_guest);1041				TEST_ASSERT_VAL("wrong exclude host",1042						evsel->core.attr.exclude_host);1043				TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1044				TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));1045				if (evsel->core.nr_members == 2) {1046					TEST_ASSERT_VAL("wrong group_idx",1047							evsel__group_idx(evsel) == 0);1048				}1049				TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);1050			}1051			continue;1052		}1053		if (evsel->core.attr.type == 1) {1054			/* group2 1:3 + G modifier */1055			TEST_ASSERT_VAL("wrong config", test_config(evsel, 3));1056			TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1057			TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1058			TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1059			TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);1060			TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);1061			TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1062			if (evsel__has_leader(evsel, group2_leader))1063				TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);1064			TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);1065			continue;1066		}1067		/* instructions:u */1068		ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions");1069		if (ret)1070			return ret;1071 1072		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1073		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1074		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1075		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1076		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1077		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1078		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));1079		TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);1080	}1081	return TEST_OK;1082}1083#endif1084 1085static int test__group4(struct evlist *evlist __maybe_unused)1086{1087	struct evsel *evsel, *leader;1088 1089	TEST_ASSERT_VAL("wrong number of entries",1090			evlist->core.nr_entries == (num_core_entries() * 2));1091	TEST_ASSERT_VAL("wrong number of groups",1092			num_core_entries() == evlist__nr_groups(evlist));1093 1094	for (int i = 0; i < num_core_entries(); i++) {1095		int ret;1096 1097		/* cycles:u + p */1098		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));1099		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1100		if (ret)1101			return ret;1102 1103		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1104		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1105		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1106		/* use of precise requires exclude_guest */1107		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1108		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1109		TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 1);1110		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1111		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));1112		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);1113		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);1114		TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);1115 1116		/* instructions:kp + p */1117		evsel = evsel__next(evsel);1118		ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions");1119		if (ret)1120			return ret;1121 1122		TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);1123		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1124		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1125		/* use of precise requires exclude_guest */1126		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1127		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1128		TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);1129		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1130		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);1131		TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);1132	}1133	return TEST_OK;1134}1135 1136static int test__group5(struct evlist *evlist __maybe_unused)1137{1138	struct evsel *evsel = NULL, *leader;1139	int ret;1140 1141	TEST_ASSERT_VAL("wrong number of entries",1142			evlist->core.nr_entries == (5 * num_core_entries()));1143	TEST_ASSERT_VAL("wrong number of groups",1144			evlist__nr_groups(evlist) == (2 * num_core_entries()));1145 1146	for (int i = 0; i < num_core_entries(); i++) {1147		/* cycles + G */1148		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));1149		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1150		if (ret)1151			return ret;1152 1153		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1154		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1155		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1156		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);1157		TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);1158		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1159		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1160		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));1161		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);1162		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);1163		TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);1164 1165		/* instructions + G */1166		evsel = evsel__next(evsel);1167		ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions");1168		if (ret)1169			return ret;1170 1171		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1172		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1173		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1174		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);1175		TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);1176		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1177		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1178		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);1179		TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);1180	}1181	for (int i = 0; i < num_core_entries(); i++) {1182		/* cycles:G */1183		evsel = leader = evsel__next(evsel);1184		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1185		if (ret)1186			return ret;1187 1188		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1189		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1190		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1191		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);1192		TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);1193		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1194		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1195		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));1196		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);1197		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);1198		TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);1199 1200		/* instructions:G */1201		evsel = evsel__next(evsel);1202		ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions");1203		if (ret)1204			return ret;1205 1206		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1207		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1208		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1209		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);1210		TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);1211		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1212		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1213		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);1214	}1215	for (int i = 0; i < num_core_entries(); i++) {1216		/* cycles */1217		evsel = evsel__next(evsel);1218		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1219		if (ret)1220			return ret;1221 1222		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1223		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1224		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1225		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1226		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1227		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1228		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));1229	}1230	return TEST_OK;1231}1232 1233static int test__group_gh1(struct evlist *evlist)1234{1235	struct evsel *evsel = NULL, *leader;1236 1237	TEST_ASSERT_VAL("wrong number of entries",1238			evlist->core.nr_entries == (2 * num_core_entries()));1239	TEST_ASSERT_VAL("wrong number of groups",1240			evlist__nr_groups(evlist) == num_core_entries());1241 1242	for (int i = 0; i < num_core_entries(); i++) {1243		int ret;1244 1245		/* cycles + :H group modifier */1246		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));1247		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1248		if (ret)1249			return ret;1250 1251		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1252		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1253		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1254		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1255		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1256		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1257		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1258		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));1259		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);1260		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);1261 1262		/* cache-misses:G + :H group modifier */1263		evsel = evsel__next(evsel);1264		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses");1265		if (ret)1266			return ret;1267 1268		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1269		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1270		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1271		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);1272		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1273		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1274		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1275		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);1276	}1277	return TEST_OK;1278}1279 1280static int test__group_gh2(struct evlist *evlist)1281{1282	struct evsel *evsel = NULL, *leader;1283 1284	TEST_ASSERT_VAL("wrong number of entries",1285			evlist->core.nr_entries == (2 * num_core_entries()));1286	TEST_ASSERT_VAL("wrong number of groups",1287			evlist__nr_groups(evlist) == num_core_entries());1288 1289	for (int i = 0; i < num_core_entries(); i++) {1290		int ret;1291 1292		/* cycles + :G group modifier */1293		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));1294		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1295		if (ret)1296			return ret;1297 1298		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1299		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1300		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1301		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);1302		TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);1303		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1304		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1305		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));1306		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);1307		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);1308 1309		/* cache-misses:H + :G group modifier */1310		evsel = evsel__next(evsel);1311		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses");1312		if (ret)1313			return ret;1314 1315		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1316		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1317		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1318		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);1319		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1320		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1321		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1322		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);1323	}1324	return TEST_OK;1325}1326 1327static int test__group_gh3(struct evlist *evlist)1328{1329	struct evsel *evsel = NULL, *leader;1330 1331	TEST_ASSERT_VAL("wrong number of entries",1332			evlist->core.nr_entries == (2 * num_core_entries()));1333	TEST_ASSERT_VAL("wrong number of groups",1334			evlist__nr_groups(evlist) == num_core_entries());1335 1336	for (int i = 0; i < num_core_entries(); i++) {1337		int ret;1338 1339		/* cycles:G + :u group modifier */1340		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));1341		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1342		if (ret)1343			return ret;1344 1345		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1346		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1347		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1348		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);1349		TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);1350		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1351		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1352		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));1353		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);1354		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);1355 1356		/* cache-misses:H + :u group modifier */1357		evsel = evsel__next(evsel);1358		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses");1359		if (ret)1360			return ret;1361 1362		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1363		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1364		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1365		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1366		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1367		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1368		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1369		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);1370	}1371	return TEST_OK;1372}1373 1374static int test__group_gh4(struct evlist *evlist)1375{1376	struct evsel *evsel = NULL, *leader;1377 1378	TEST_ASSERT_VAL("wrong number of entries",1379			evlist->core.nr_entries == (2 * num_core_entries()));1380	TEST_ASSERT_VAL("wrong number of groups",1381			evlist__nr_groups(evlist) == num_core_entries());1382 1383	for (int i = 0; i < num_core_entries(); i++) {1384		int ret;1385 1386		/* cycles:G + :uG group modifier */1387		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));1388		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1389		if (ret)1390			return ret;1391 1392		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1393		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1394		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1395		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);1396		TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);1397		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1398		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1399		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));1400		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);1401		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);1402 1403		/* cache-misses:H + :uG group modifier */1404		evsel = evsel__next(evsel);1405		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses");1406		if (ret)1407			return ret;1408 1409		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1410		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1411		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1412		TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);1413		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1414		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1415		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1416		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);1417	}1418	return TEST_OK;1419}1420 1421static int test__leader_sample1(struct evlist *evlist)1422{1423	struct evsel *evsel = NULL, *leader;1424 1425	TEST_ASSERT_VAL("wrong number of entries",1426			evlist->core.nr_entries == (3 * num_core_entries()));1427 1428	for (int i = 0; i < num_core_entries(); i++) {1429		int ret;1430 1431		/* cycles - sampling group leader */1432		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));1433		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1434		if (ret)1435			return ret;1436 1437		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1438		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1439		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1440		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1441		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1442		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1443		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1444		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1445		TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);1446 1447		/* cache-misses - not sampling */1448		evsel = evsel__next(evsel);1449		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses");1450		if (ret)1451			return ret;1452 1453		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1454		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1455		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1456		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1457		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1458		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1459		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1460		TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);1461 1462		/* branch-misses - not sampling */1463		evsel = evsel__next(evsel);1464		ret = assert_hw(&evsel->core, PERF_COUNT_HW_BRANCH_MISSES, "branch-misses");1465		if (ret)1466			return ret;1467 1468		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1469		TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);1470		TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);1471		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1472		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1473		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1474		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1475		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1476		TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);1477	}1478	return TEST_OK;1479}1480 1481static int test__leader_sample2(struct evlist *evlist __maybe_unused)1482{1483	struct evsel *evsel = NULL, *leader;1484 1485	TEST_ASSERT_VAL("wrong number of entries",1486			evlist->core.nr_entries == (2 * num_core_entries()));1487 1488	for (int i = 0; i < num_core_entries(); i++) {1489		int ret;1490 1491		/* instructions - sampling group leader */1492		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));1493		ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions");1494		if (ret)1495			return ret;1496 1497		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1498		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1499		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1500		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1501		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1502		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1503		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1504		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1505		TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);1506 1507		/* branch-misses - not sampling */1508		evsel = evsel__next(evsel);1509		ret = assert_hw(&evsel->core, PERF_COUNT_HW_BRANCH_MISSES, "branch-misses");1510		if (ret)1511			return ret;1512 1513		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1514		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1515		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1516		TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);1517		TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);1518		TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1519		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1520		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1521		TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);1522	}1523	return TEST_OK;1524}1525 1526static int test__checkevent_pinned_modifier(struct evlist *evlist)1527{1528	struct evsel *evsel = NULL;1529 1530	TEST_ASSERT_VAL("wrong number of entries",1531			evlist->core.nr_entries == num_core_entries());1532 1533	for (int i = 0; i < num_core_entries(); i++) {1534		evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));1535		TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1536		TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1537		TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1538		TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);1539		TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);1540	}1541	return test__checkevent_symbolic_name(evlist);1542}1543 1544static int test__pinned_group(struct evlist *evlist)1545{1546	struct evsel *evsel = NULL, *leader;1547 1548	TEST_ASSERT_VAL("wrong number of entries",1549			evlist->core.nr_entries == (3 * num_core_entries()));1550 1551	for (int i = 0; i < num_core_entries(); i++) {1552		int ret;1553 1554		/* cycles - group leader */1555		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));1556		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1557		if (ret)1558			return ret;1559 1560		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1561		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1562		/* TODO: The group modifier is not copied to the split group leader. */1563		if (perf_pmus__num_core_pmus() == 1)1564			TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);1565 1566		/* cache-misses - can not be pinned, but will go on with the leader */1567		evsel = evsel__next(evsel);1568		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses");1569		if (ret)1570			return ret;1571 1572		TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);1573 1574		/* branch-misses - ditto */1575		evsel = evsel__next(evsel);1576		ret = assert_hw(&evsel->core, PERF_COUNT_HW_BRANCH_MISSES, "branch-misses");1577		if (ret)1578			return ret;1579 1580		TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);1581	}1582	return TEST_OK;1583}1584 1585static int test__checkevent_exclusive_modifier(struct evlist *evlist)1586{1587	struct evsel *evsel = evlist__first(evlist);1588 1589	TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1590	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1591	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1592	TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);1593	TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);1594 1595	return test__checkevent_symbolic_name(evlist);1596}1597 1598static int test__exclusive_group(struct evlist *evlist)1599{1600	struct evsel *evsel = NULL, *leader;1601 1602	TEST_ASSERT_VAL("wrong number of entries",1603			evlist->core.nr_entries == 3 * num_core_entries());1604 1605	for (int i = 0; i < num_core_entries(); i++) {1606		int ret;1607 1608		/* cycles - group leader */1609		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));1610		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1611		if (ret)1612			return ret;1613 1614		TEST_ASSERT_VAL("wrong group name", !evsel->group_name);1615		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));1616		/* TODO: The group modifier is not copied to the split group leader. */1617		if (perf_pmus__num_core_pmus() == 1)1618			TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);1619 1620		/* cache-misses - can not be pinned, but will go on with the leader */1621		evsel = evsel__next(evsel);1622		ret = assert_hw(&evsel->core, PERF_COUNT_HW_CACHE_MISSES, "cache-misses");1623		if (ret)1624			return ret;1625 1626		TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);1627 1628		/* branch-misses - ditto */1629		evsel = evsel__next(evsel);1630		ret = assert_hw(&evsel->core, PERF_COUNT_HW_BRANCH_MISSES, "branch-misses");1631		if (ret)1632			return ret;1633 1634		TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);1635	}1636	return TEST_OK;1637}1638static int test__checkevent_breakpoint_len(struct evlist *evlist)1639{1640	struct evsel *evsel = evlist__first(evlist);1641 1642	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);1643	TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);1644	TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));1645	TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==1646					 evsel->core.attr.bp_type);1647	TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==1648					evsel->core.attr.bp_len);1649 1650	return TEST_OK;1651}1652 1653static int test__checkevent_breakpoint_len_w(struct evlist *evlist)1654{1655	struct evsel *evsel = evlist__first(evlist);1656 1657	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);1658	TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);1659	TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));1660	TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==1661					 evsel->core.attr.bp_type);1662	TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==1663					evsel->core.attr.bp_len);1664 1665	return TEST_OK;1666}1667 1668static int1669test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist)1670{1671	struct evsel *evsel = evlist__first(evlist);1672 1673	TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);1674	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1675	TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);1676	TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);1677 1678	return test__checkevent_breakpoint_rw(evlist);1679}1680 1681static int test__checkevent_precise_max_modifier(struct evlist *evlist)1682{1683	struct evsel *evsel = evlist__first(evlist);1684 1685	TEST_ASSERT_VAL("wrong number of entries",1686			evlist->core.nr_entries == 1 + num_core_entries());1687	TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);1688	TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_TASK_CLOCK));1689	return TEST_OK;1690}1691 1692static int test__checkevent_config_symbol(struct evlist *evlist)1693{1694	struct evsel *evsel = evlist__first(evlist);1695 1696	TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "insn"));1697	return TEST_OK;1698}1699 1700static int test__checkevent_config_raw(struct evlist *evlist)1701{1702	struct evsel *evsel = evlist__first(evlist);1703 1704	TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "rawpmu"));1705	return TEST_OK;1706}1707 1708static int test__checkevent_config_num(struct evlist *evlist)1709{1710	struct evsel *evsel = evlist__first(evlist);1711 1712	TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "numpmu"));1713	return TEST_OK;1714}1715 1716static int test__checkevent_config_cache(struct evlist *evlist)1717{1718	struct evsel *evsel = evlist__first(evlist);1719 1720	TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "cachepmu"));1721	return test__checkevent_genhw(evlist);1722}1723 1724static bool test__pmu_cpu_valid(void)1725{1726	return !!perf_pmus__find("cpu");1727}1728 1729static bool test__pmu_cpu_event_valid(void)1730{1731	struct perf_pmu *pmu = perf_pmus__find("cpu");1732 1733	if (!pmu)1734		return false;1735 1736	return perf_pmu__has_format(pmu, "event");1737}1738 1739static bool test__intel_pt_valid(void)1740{1741	return !!perf_pmus__find("intel_pt");1742}1743 1744static int test__intel_pt(struct evlist *evlist)1745{1746	struct evsel *evsel = evlist__first(evlist);1747 1748	TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "intel_pt//u"));1749	return TEST_OK;1750}1751 1752static int test__checkevent_complex_name(struct evlist *evlist)1753{1754	struct evsel *evsel = evlist__first(evlist);1755 1756	TEST_ASSERT_VAL("wrong complex name parsing",1757			evsel__name_is(evsel,1758				       "COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks"));1759	return TEST_OK;1760}1761 1762static int test__checkevent_raw_pmu(struct evlist *evlist)1763{1764	struct evsel *evsel = evlist__first(evlist);1765 1766	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);1767	TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);1768	TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x1a));1769	return TEST_OK;1770}1771 1772static int test__sym_event_slash(struct evlist *evlist)1773{1774	struct evsel *evsel = evlist__first(evlist);1775	int ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1776 1777	if (ret)1778		return ret;1779 1780	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);1781	return TEST_OK;1782}1783 1784static int test__sym_event_dc(struct evlist *evlist)1785{1786	struct evsel *evsel = evlist__first(evlist);1787	int ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1788 1789	if (ret)1790		return ret;1791 1792	TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);1793	return TEST_OK;1794}1795 1796static int test__term_equal_term(struct evlist *evlist)1797{1798	struct evsel *evsel = evlist__first(evlist);1799	int ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1800 1801	if (ret)1802		return ret;1803 1804	TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "name") == 0);1805	return TEST_OK;1806}1807 1808static int test__term_equal_legacy(struct evlist *evlist)1809{1810	struct evsel *evsel = evlist__first(evlist);1811	int ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");1812 1813	if (ret)1814		return ret;1815 1816	TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "l1d") == 0);1817	return TEST_OK;1818}1819 1820#ifdef HAVE_LIBTRACEEVENT1821static int count_tracepoints(void)1822{1823	struct dirent *events_ent;1824	DIR *events_dir;1825	int cnt = 0;1826 1827	events_dir = tracing_events__opendir();1828 1829	TEST_ASSERT_VAL("Can't open events dir", events_dir);1830 1831	while ((events_ent = readdir(events_dir))) {1832		char *sys_path;1833		struct dirent *sys_ent;1834		DIR *sys_dir;1835 1836		if (!strcmp(events_ent->d_name, ".")1837		    || !strcmp(events_ent->d_name, "..")1838		    || !strcmp(events_ent->d_name, "enable")1839		    || !strcmp(events_ent->d_name, "header_event")1840		    || !strcmp(events_ent->d_name, "header_page"))1841			continue;1842 1843		sys_path = get_events_file(events_ent->d_name);1844		TEST_ASSERT_VAL("Can't get sys path", sys_path);1845 1846		sys_dir = opendir(sys_path);1847		TEST_ASSERT_VAL("Can't open sys dir", sys_dir);1848 1849		while ((sys_ent = readdir(sys_dir))) {1850			if (!strcmp(sys_ent->d_name, ".")1851			    || !strcmp(sys_ent->d_name, "..")1852			    || !strcmp(sys_ent->d_name, "enable")1853			    || !strcmp(sys_ent->d_name, "filter"))1854				continue;1855 1856			cnt++;1857		}1858 1859		closedir(sys_dir);1860		put_events_file(sys_path);1861	}1862 1863	closedir(events_dir);1864	return cnt;1865}1866 1867static int test__all_tracepoints(struct evlist *evlist)1868{1869	TEST_ASSERT_VAL("wrong events count",1870			count_tracepoints() == evlist->core.nr_entries);1871 1872	return test__checkevent_tracepoint_multi(evlist);1873}1874#endif /* HAVE_LIBTRACEVENT */1875 1876struct evlist_test {1877	const char *name;1878	bool (*valid)(void);1879	int (*check)(struct evlist *evlist);1880};1881 1882static const struct evlist_test test__events[] = {1883#ifdef HAVE_LIBTRACEEVENT1884	{1885		.name  = "syscalls:sys_enter_openat",1886		.check = test__checkevent_tracepoint,1887		/* 0 */1888	},1889	{1890		.name  = "syscalls:*",1891		.check = test__checkevent_tracepoint_multi,1892		/* 1 */1893	},1894#endif1895	{1896		.name  = "r1a",1897		.check = test__checkevent_raw,1898		/* 2 */1899	},1900	{1901		.name  = "1:1",1902		.check = test__checkevent_numeric,1903		/* 3 */1904	},1905	{1906		.name  = "instructions",1907		.check = test__checkevent_symbolic_name,1908		/* 4 */1909	},1910	{1911		.name  = "cycles/period=100000,config2/",1912		.check = test__checkevent_symbolic_name_config,1913		/* 5 */1914	},1915	{1916		.name  = "faults",1917		.check = test__checkevent_symbolic_alias,1918		/* 6 */1919	},1920	{1921		.name  = "L1-dcache-load-miss",1922		.check = test__checkevent_genhw,1923		/* 7 */1924	},1925	{1926		.name  = "mem:0",1927		.check = test__checkevent_breakpoint,1928		/* 8 */1929	},1930	{1931		.name  = "mem:0:x",1932		.check = test__checkevent_breakpoint_x,1933		/* 9 */1934	},1935	{1936		.name  = "mem:0:r",1937		.check = test__checkevent_breakpoint_r,1938		/* 0 */1939	},1940	{1941		.name  = "mem:0:w",1942		.check = test__checkevent_breakpoint_w,1943		/* 1 */1944	},1945#ifdef HAVE_LIBTRACEEVENT1946	{1947		.name  = "syscalls:sys_enter_openat:k",1948		.check = test__checkevent_tracepoint_modifier,1949		/* 2 */1950	},1951	{1952		.name  = "syscalls:*:u",1953		.check = test__checkevent_tracepoint_multi_modifier,1954		/* 3 */1955	},1956#endif1957	{1958		.name  = "r1a:kp",1959		.check = test__checkevent_raw_modifier,1960		/* 4 */1961	},1962	{1963		.name  = "1:1:hp",1964		.check = test__checkevent_numeric_modifier,1965		/* 5 */1966	},1967	{1968		.name  = "instructions:h",1969		.check = test__checkevent_symbolic_name_modifier,1970		/* 6 */1971	},1972	{1973		.name  = "faults:u",1974		.check = test__checkevent_symbolic_alias_modifier,1975		/* 7 */1976	},1977	{1978		.name  = "L1-dcache-load-miss:kp",1979		.check = test__checkevent_genhw_modifier,1980		/* 8 */1981	},1982	{1983		.name  = "mem:0:u",1984		.check = test__checkevent_breakpoint_modifier,1985		/* 9 */1986	},1987	{1988		.name  = "mem:0:x:k",1989		.check = test__checkevent_breakpoint_x_modifier,1990		/* 0 */1991	},1992	{1993		.name  = "mem:0:r:hp",1994		.check = test__checkevent_breakpoint_r_modifier,1995		/* 1 */1996	},1997	{1998		.name  = "mem:0:w:up",1999		.check = test__checkevent_breakpoint_w_modifier,2000		/* 2 */2001	},2002#ifdef HAVE_LIBTRACEEVENT2003	{2004		.name  = "r1,syscalls:sys_enter_openat:k,1:1:hp",2005		.check = test__checkevent_list,2006		/* 3 */2007	},2008#endif2009	{2010		.name  = "instructions:G",2011		.check = test__checkevent_exclude_host_modifier,2012		/* 4 */2013	},2014	{2015		.name  = "instructions:H",2016		.check = test__checkevent_exclude_guest_modifier,2017		/* 5 */2018	},2019	{2020		.name  = "mem:0:rw",2021		.check = test__checkevent_breakpoint_rw,2022		/* 6 */2023	},2024	{2025		.name  = "mem:0:rw:kp",2026		.check = test__checkevent_breakpoint_rw_modifier,2027		/* 7 */2028	},2029	{2030		.name  = "{instructions:k,cycles:upp}",2031		.check = test__group1,2032		/* 8 */2033	},2034	{2035		.name  = "{faults:k,branches}:u,cycles:k",2036		.check = test__group2,2037		/* 9 */2038	},2039#ifdef HAVE_LIBTRACEEVENT2040	{2041		.name  = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",2042		.check = test__group3,2043		/* 0 */2044	},2045#endif2046	{2047		.name  = "{cycles:u,instructions:kp}:p",2048		.check = test__group4,2049		/* 1 */2050	},2051	{2052		.name  = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",2053		.check = test__group5,2054		/* 2 */2055	},2056#ifdef HAVE_LIBTRACEEVENT2057	{2058		.name  = "*:*",2059		.check = test__all_tracepoints,2060		/* 3 */2061	},2062#endif2063	{2064		.name  = "{cycles,cache-misses:G}:H",2065		.check = test__group_gh1,2066		/* 4 */2067	},2068	{2069		.name  = "{cycles,cache-misses:H}:G",2070		.check = test__group_gh2,2071		/* 5 */2072	},2073	{2074		.name  = "{cycles:G,cache-misses:H}:u",2075		.check = test__group_gh3,2076		/* 6 */2077	},2078	{2079		.name  = "{cycles:G,cache-misses:H}:uG",2080		.check = test__group_gh4,2081		/* 7 */2082	},2083	{2084		.name  = "{cycles,cache-misses,branch-misses}:S",2085		.check = test__leader_sample1,2086		/* 8 */2087	},2088	{2089		.name  = "{instructions,branch-misses}:Su",2090		.check = test__leader_sample2,2091		/* 9 */2092	},2093	{2094		.name  = "instructions:uDp",2095		.check = test__checkevent_pinned_modifier,2096		/* 0 */2097	},2098	{2099		.name  = "{cycles,cache-misses,branch-misses}:D",2100		.check = test__pinned_group,2101		/* 1 */2102	},2103	{2104		.name  = "mem:0/1",2105		.check = test__checkevent_breakpoint_len,2106		/* 2 */2107	},2108	{2109		.name  = "mem:0/2:w",2110		.check = test__checkevent_breakpoint_len_w,2111		/* 3 */2112	},2113	{2114		.name  = "mem:0/4:rw:u",2115		.check = test__checkevent_breakpoint_len_rw_modifier,2116		/* 4 */2117	},2118#if defined(__s390x__) && defined(HAVE_LIBTRACEEVENT)2119	{2120		.name  = "kvm-s390:kvm_s390_create_vm",2121		.check = test__checkevent_tracepoint,2122		.valid = kvm_s390_create_vm_valid,2123		/* 0 */2124	},2125#endif2126	{2127		.name  = "instructions:I",2128		.check = test__checkevent_exclude_idle_modifier,2129		/* 5 */2130	},2131	{2132		.name  = "instructions:kIG",2133		.check = test__checkevent_exclude_idle_modifier_1,2134		/* 6 */2135	},2136	{2137		.name  = "task-clock:P,cycles",2138		.check = test__checkevent_precise_max_modifier,2139		/* 7 */2140	},2141	{2142		.name  = "instructions/name=insn/",2143		.check = test__checkevent_config_symbol,2144		/* 8 */2145	},2146	{2147		.name  = "r1234/name=rawpmu/",2148		.check = test__checkevent_config_raw,2149		/* 9 */2150	},2151	{2152		.name  = "4:0x6530160/name=numpmu/",2153		.check = test__checkevent_config_num,2154		/* 0 */2155	},2156	{2157		.name  = "L1-dcache-misses/name=cachepmu/",2158		.check = test__checkevent_config_cache,2159		/* 1 */2160	},2161	{2162		.name  = "intel_pt//u",2163		.valid = test__intel_pt_valid,2164		.check = test__intel_pt,2165		/* 2 */2166	},2167	{2168		.name  = "cycles/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks'/Duk",2169		.check = test__checkevent_complex_name,2170		/* 3 */2171	},2172	{2173		.name  = "cycles//u",2174		.check = test__sym_event_slash,2175		/* 4 */2176	},2177	{2178		.name  = "cycles:k",2179		.check = test__sym_event_dc,2180		/* 5 */2181	},2182	{2183		.name  = "instructions:uep",2184		.check = test__checkevent_exclusive_modifier,2185		/* 6 */2186	},2187	{2188		.name  = "{cycles,cache-misses,branch-misses}:e",2189		.check = test__exclusive_group,2190		/* 7 */2191	},2192	{2193		.name  = "cycles/name=name/",2194		.check = test__term_equal_term,2195		/* 8 */2196	},2197	{2198		.name  = "cycles/name=l1d/",2199		.check = test__term_equal_legacy,2200		/* 9 */2201	},2202	{2203		.name  = "mem:0/name=breakpoint/",2204		.check = test__checkevent_breakpoint,2205		/* 0 */2206	},2207	{2208		.name  = "mem:0:x/name=breakpoint/",2209		.check = test__checkevent_breakpoint_x,2210		/* 1 */2211	},2212	{2213		.name  = "mem:0:r/name=breakpoint/",2214		.check = test__checkevent_breakpoint_r,2215		/* 2 */2216	},2217	{2218		.name  = "mem:0:w/name=breakpoint/",2219		.check = test__checkevent_breakpoint_w,2220		/* 3 */2221	},2222	{2223		.name  = "mem:0/name=breakpoint/u",2224		.check = test__checkevent_breakpoint_modifier_name,2225		/* 4 */2226	},2227	{2228		.name  = "mem:0:x/name=breakpoint/k",2229		.check = test__checkevent_breakpoint_x_modifier_name,2230		/* 5 */2231	},2232	{2233		.name  = "mem:0:r/name=breakpoint/hp",2234		.check = test__checkevent_breakpoint_r_modifier_name,2235		/* 6 */2236	},2237	{2238		.name  = "mem:0:w/name=breakpoint/up",2239		.check = test__checkevent_breakpoint_w_modifier_name,2240		/* 7 */2241	},2242	{2243		.name  = "mem:0:rw/name=breakpoint/",2244		.check = test__checkevent_breakpoint_rw,2245		/* 8 */2246	},2247	{2248		.name  = "mem:0:rw/name=breakpoint/kp",2249		.check = test__checkevent_breakpoint_rw_modifier_name,2250		/* 9 */2251	},2252	{2253		.name  = "mem:0/1/name=breakpoint/",2254		.check = test__checkevent_breakpoint_len,2255		/* 0 */2256	},2257	{2258		.name  = "mem:0/2:w/name=breakpoint/",2259		.check = test__checkevent_breakpoint_len_w,2260		/* 1 */2261	},2262	{2263		.name  = "mem:0/4:rw/name=breakpoint/u",2264		.check = test__checkevent_breakpoint_len_rw_modifier,2265		/* 2 */2266	},2267	{2268		.name  = "mem:0/1/name=breakpoint1/,mem:0/4:rw/name=breakpoint2/",2269		.check = test__checkevent_breakpoint_2_events,2270		/* 3 */2271	},2272#ifdef HAVE_LIBTRACEEVENT2273	{2274		.name = "9p:9p_client_req",2275		.check = test__checkevent_tracepoint,2276		/* 4 */2277	},2278#endif2279};2280 2281static const struct evlist_test test__events_pmu[] = {2282	{2283		.name  = "cpu/config=10,config1=1,config2=3,period=1000/u",2284		.valid = test__pmu_cpu_valid,2285		.check = test__checkevent_pmu,2286		/* 0 */2287	},2288	{2289		.name  = "cpu/config=1,name=krava/u,cpu/config=2/u",2290		.valid = test__pmu_cpu_valid,2291		.check = test__checkevent_pmu_name,2292		/* 1 */2293	},2294	{2295		.name  = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",2296		.valid = test__pmu_cpu_valid,2297		.check = test__checkevent_pmu_partial_time_callgraph,2298		/* 2 */2299	},2300	{2301		.name  = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",2302		.valid = test__pmu_cpu_event_valid,2303		.check = test__checkevent_complex_name,2304		/* 3 */2305	},2306	{2307		.name  = "software/r1a/",2308		.check = test__checkevent_raw_pmu,2309		/* 4 */2310	},2311	{2312		.name  = "software/r0x1a/",2313		.check = test__checkevent_raw_pmu,2314		/* 5 */2315	},2316	{2317		.name  = "cpu/L1-dcache-load-miss/",2318		.valid = test__pmu_cpu_valid,2319		.check = test__checkevent_genhw,2320		/* 6 */2321	},2322	{2323		.name  = "cpu/L1-dcache-load-miss/kp",2324		.valid = test__pmu_cpu_valid,2325		.check = test__checkevent_genhw_modifier,2326		/* 7 */2327	},2328	{2329		.name  = "cpu/L1-dcache-misses,name=cachepmu/",2330		.valid = test__pmu_cpu_valid,2331		.check = test__checkevent_config_cache,2332		/* 8 */2333	},2334	{2335		.name  = "cpu/instructions/",2336		.valid = test__pmu_cpu_valid,2337		.check = test__checkevent_symbolic_name,2338		/* 9 */2339	},2340	{2341		.name  = "cpu/cycles,period=100000,config2/",2342		.valid = test__pmu_cpu_valid,2343		.check = test__checkevent_symbolic_name_config,2344		/* 0 */2345	},2346	{2347		.name  = "cpu/instructions/h",2348		.valid = test__pmu_cpu_valid,2349		.check = test__checkevent_symbolic_name_modifier,2350		/* 1 */2351	},2352	{2353		.name  = "cpu/instructions/G",2354		.valid = test__pmu_cpu_valid,2355		.check = test__checkevent_exclude_host_modifier,2356		/* 2 */2357	},2358	{2359		.name  = "cpu/instructions/H",2360		.valid = test__pmu_cpu_valid,2361		.check = test__checkevent_exclude_guest_modifier,2362		/* 3 */2363	},2364	{2365		.name  = "{cpu/instructions/k,cpu/cycles/upp}",2366		.valid = test__pmu_cpu_valid,2367		.check = test__group1,2368		/* 4 */2369	},2370	{2371		.name  = "{cpu/cycles/u,cpu/instructions/kp}:p",2372		.valid = test__pmu_cpu_valid,2373		.check = test__group4,2374		/* 5 */2375	},2376	{2377		.name  = "{cpu/cycles/,cpu/cache-misses/G}:H",2378		.valid = test__pmu_cpu_valid,2379		.check = test__group_gh1,2380		/* 6 */2381	},2382	{2383		.name  = "{cpu/cycles/,cpu/cache-misses/H}:G",2384		.valid = test__pmu_cpu_valid,2385		.check = test__group_gh2,2386		/* 7 */2387	},2388	{2389		.name  = "{cpu/cycles/G,cpu/cache-misses/H}:u",2390		.valid = test__pmu_cpu_valid,2391		.check = test__group_gh3,2392		/* 8 */2393	},2394	{2395		.name  = "{cpu/cycles/G,cpu/cache-misses/H}:uG",2396		.valid = test__pmu_cpu_valid,2397		.check = test__group_gh4,2398		/* 9 */2399	},2400	{2401		.name  = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:S",2402		.valid = test__pmu_cpu_valid,2403		.check = test__leader_sample1,2404		/* 0 */2405	},2406	{2407		.name  = "{cpu/instructions/,cpu/branch-misses/}:Su",2408		.valid = test__pmu_cpu_valid,2409		.check = test__leader_sample2,2410		/* 1 */2411	},2412	{2413		.name  = "cpu/instructions/uDp",2414		.valid = test__pmu_cpu_valid,2415		.check = test__checkevent_pinned_modifier,2416		/* 2 */2417	},2418	{2419		.name  = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:D",2420		.valid = test__pmu_cpu_valid,2421		.check = test__pinned_group,2422		/* 3 */2423	},2424	{2425		.name  = "cpu/instructions/I",2426		.valid = test__pmu_cpu_valid,2427		.check = test__checkevent_exclude_idle_modifier,2428		/* 4 */2429	},2430	{2431		.name  = "cpu/instructions/kIG",2432		.valid = test__pmu_cpu_valid,2433		.check = test__checkevent_exclude_idle_modifier_1,2434		/* 5 */2435	},2436	{2437		.name  = "cpu/cycles/u",2438		.valid = test__pmu_cpu_valid,2439		.check = test__sym_event_slash,2440		/* 6 */2441	},2442	{2443		.name  = "cpu/cycles/k",2444		.valid = test__pmu_cpu_valid,2445		.check = test__sym_event_dc,2446		/* 7 */2447	},2448	{2449		.name  = "cpu/instructions/uep",2450		.valid = test__pmu_cpu_valid,2451		.check = test__checkevent_exclusive_modifier,2452		/* 8 */2453	},2454	{2455		.name  = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:e",2456		.valid = test__pmu_cpu_valid,2457		.check = test__exclusive_group,2458		/* 9 */2459	},2460	{2461		.name  = "cpu/cycles,name=name/",2462		.valid = test__pmu_cpu_valid,2463		.check = test__term_equal_term,2464		/* 0 */2465	},2466	{2467		.name  = "cpu/cycles,name=l1d/",2468		.valid = test__pmu_cpu_valid,2469		.check = test__term_equal_legacy,2470		/* 1 */2471	},2472};2473 2474struct terms_test {2475	const char *str;2476	int (*check)(struct parse_events_terms *terms);2477};2478 2479static const struct terms_test test__terms[] = {2480	[0] = {2481		.str   = "config=10,config1,config2=3,config3=4,umask=1,read,r0xead",2482		.check = test__checkterms_simple,2483	},2484};2485 2486static int test_event(const struct evlist_test *e)2487{2488	struct parse_events_error err;2489	struct evlist *evlist;2490	int ret;2491 2492	if (e->valid && !e->valid()) {2493		pr_debug("... SKIP\n");2494		return TEST_OK;2495	}2496 2497	evlist = evlist__new();2498	if (evlist == NULL) {2499		pr_err("Failed allocation");2500		return TEST_FAIL;2501	}2502	parse_events_error__init(&err);2503	ret = __parse_events(evlist, e->name, /*pmu_filter=*/NULL, &err, /*fake_pmu=*/false,2504			     /*warn_if_reordered=*/true, /*fake_tp=*/true);2505	if (ret) {2506		pr_debug("failed to parse event '%s', err %d\n", e->name, ret);2507		parse_events_error__print(&err, e->name);2508		ret = TEST_FAIL;2509		if (parse_events_error__contains(&err, "can't access trace events"))2510			ret = TEST_SKIP;2511	} else {2512		ret = e->check(evlist);2513	}2514	parse_events_error__exit(&err);2515	evlist__delete(evlist);2516 2517	return ret;2518}2519 2520static int test_event_fake_pmu(const char *str)2521{2522	struct parse_events_error err;2523	struct evlist *evlist;2524	int ret;2525 2526	evlist = evlist__new();2527	if (!evlist)2528		return -ENOMEM;2529 2530	parse_events_error__init(&err);2531	ret = __parse_events(evlist, str, /*pmu_filter=*/NULL, &err,2532			     /*fake_pmu=*/true, /*warn_if_reordered=*/true,2533			     /*fake_tp=*/true);2534	if (ret) {2535		pr_debug("failed to parse event '%s', err %d\n",2536			 str, ret);2537		parse_events_error__print(&err, str);2538	}2539 2540	parse_events_error__exit(&err);2541	evlist__delete(evlist);2542 2543	return ret;2544}2545 2546static int combine_test_results(int existing, int latest)2547{2548	if (existing == TEST_FAIL)2549		return TEST_FAIL;2550	if (existing == TEST_SKIP)2551		return latest == TEST_OK ? TEST_SKIP : latest;2552	return latest;2553}2554 2555static int test_events(const struct evlist_test *events, int cnt)2556{2557	int ret = TEST_OK;2558 2559	for (int i = 0; i < cnt; i++) {2560		const struct evlist_test *e = &events[i];2561		int test_ret;2562 2563		pr_debug("running test %d '%s'\n", i, e->name);2564		test_ret = test_event(e);2565		if (test_ret != TEST_OK) {2566			pr_debug("Event test failure: test %d '%s'", i, e->name);2567			ret = combine_test_results(ret, test_ret);2568		}2569	}2570 2571	return ret;2572}2573 2574static int test__events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)2575{2576	return test_events(test__events, ARRAY_SIZE(test__events));2577}2578 2579static int test_term(const struct terms_test *t)2580{2581	struct parse_events_terms terms;2582	int ret;2583 2584 2585	parse_events_terms__init(&terms);2586	ret = parse_events_terms(&terms, t->str, /*input=*/ NULL);2587	if (ret) {2588		pr_debug("failed to parse terms '%s', err %d\n",2589			 t->str , ret);2590		return ret;2591	}2592 2593	ret = t->check(&terms);2594	parse_events_terms__exit(&terms);2595 2596	return ret;2597}2598 2599static int test_terms(const struct terms_test *terms, int cnt)2600{2601	int ret = 0;2602 2603	for (int i = 0; i < cnt; i++) {2604		const struct terms_test *t = &terms[i];2605 2606		pr_debug("running test %d '%s'\n", i, t->str);2607		ret = test_term(t);2608		if (ret)2609			break;2610	}2611 2612	return ret;2613}2614 2615static int test__terms2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)2616{2617	return test_terms(test__terms, ARRAY_SIZE(test__terms));2618}2619 2620static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)2621{2622	struct perf_pmu *pmu = NULL;2623	int ret = TEST_OK;2624 2625	while ((pmu = perf_pmus__scan(pmu)) != NULL) {2626		struct stat st;2627		char path[PATH_MAX];2628		char pmu_event[PATH_MAX];2629		char *buf = NULL;2630		FILE *file;2631		struct dirent *ent;2632		size_t len = 0;2633		DIR *dir;2634		int err;2635		int n;2636 2637		snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/",2638			sysfs__mountpoint(), pmu->name);2639 2640		err = stat(path, &st);2641		if (err) {2642			pr_debug("skipping PMU %s events tests: %s\n", pmu->name, path);2643			continue;2644		}2645 2646		dir = opendir(path);2647		if (!dir) {2648			pr_debug("can't open pmu event dir: %s\n", path);2649			ret = combine_test_results(ret, TEST_SKIP);2650			continue;2651		}2652 2653		while ((ent = readdir(dir))) {2654			struct evlist_test e = { .name = NULL, };2655			char name[2 * NAME_MAX + 1 + 12 + 3];2656			int test_ret;2657			bool is_event_parameterized = 0;2658 2659			/* Names containing . are special and cannot be used directly */2660			if (strchr(ent->d_name, '.'))2661				continue;2662 2663			/* exclude parameterized ones (name contains '?') */2664			n = snprintf(pmu_event, sizeof(pmu_event), "%s%s", path, ent->d_name);2665			if (n >= PATH_MAX) {2666				pr_err("pmu event name crossed PATH_MAX(%d) size\n", PATH_MAX);2667				continue;2668			}2669 2670			file = fopen(pmu_event, "r");2671			if (!file) {2672				pr_debug("can't open pmu event file for '%s'\n", ent->d_name);2673				ret = combine_test_results(ret, TEST_FAIL);2674				continue;2675			}2676 2677			if (getline(&buf, &len, file) < 0) {2678				pr_debug(" pmu event: %s is a null event\n", ent->d_name);2679				ret = combine_test_results(ret, TEST_FAIL);2680				fclose(file);2681				continue;2682			}2683 2684			if (strchr(buf, '?'))2685				is_event_parameterized = 1;2686 2687			free(buf);2688			buf = NULL;2689			fclose(file);2690 2691			if (is_event_parameterized == 1) {2692				pr_debug("skipping parameterized PMU event: %s which contains ?\n", pmu_event);2693				continue;2694			}2695 2696			snprintf(name, sizeof(name), "%s/event=%s/u", pmu->name, ent->d_name);2697 2698			e.name  = name;2699			e.check = test__checkevent_pmu_events;2700 2701			test_ret = test_event(&e);2702			if (test_ret != TEST_OK) {2703				pr_debug("Test PMU event failed for '%s'", name);2704				ret = combine_test_results(ret, test_ret);2705			}2706 2707			if (!is_pmu_core(pmu->name))2708				continue;2709 2710			/*2711			 * Names containing '-' are recognized as prefixes and suffixes2712			 * due to '-' being a legacy PMU separator. This fails when the2713			 * prefix or suffix collides with an existing legacy token. For2714			 * example, branch-brs has a prefix (branch) that collides with2715			 * a PE_NAME_CACHE_TYPE token causing a parse error as a suffix2716			 * isn't expected after this. As event names in the config2717			 * slashes are allowed a '-' in the name we check this works2718			 * above.2719			 */2720			if (strchr(ent->d_name, '-'))2721				continue;2722 2723			snprintf(name, sizeof(name), "%s:u,%s/event=%s/u",2724				 ent->d_name, pmu->name, ent->d_name);2725			e.name  = name;2726			e.check = test__checkevent_pmu_events_mix;2727			test_ret = test_event(&e);2728			if (test_ret != TEST_OK) {2729				pr_debug("Test PMU event failed for '%s'", name);2730				ret = combine_test_results(ret, test_ret);2731			}2732		}2733 2734		closedir(dir);2735	}2736	return ret;2737}2738 2739static int test__pmu_events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)2740{2741	return test_events(test__events_pmu, ARRAY_SIZE(test__events_pmu));2742}2743 2744static bool test_alias(char **event, char **alias)2745{2746	char path[PATH_MAX];2747	DIR *dir;2748	struct dirent *dent;2749	const char *sysfs = sysfs__mountpoint();2750	char buf[128];2751	FILE *file;2752 2753	if (!sysfs)2754		return false;2755 2756	snprintf(path, PATH_MAX, "%s/bus/event_source/devices/", sysfs);2757	dir = opendir(path);2758	if (!dir)2759		return false;2760 2761	while ((dent = readdir(dir))) {2762		if (!strcmp(dent->d_name, ".") ||2763		    !strcmp(dent->d_name, ".."))2764			continue;2765 2766		snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/alias",2767			 sysfs, dent->d_name);2768 2769		if (!file_available(path))2770			continue;2771 2772		file = fopen(path, "r");2773		if (!file)2774			continue;2775 2776		if (!fgets(buf, sizeof(buf), file)) {2777			fclose(file);2778			continue;2779		}2780 2781		/* Remove the last '\n' */2782		buf[strlen(buf) - 1] = 0;2783 2784		fclose(file);2785		*event = strdup(dent->d_name);2786		*alias = strdup(buf);2787		closedir(dir);2788 2789		if (*event == NULL || *alias == NULL) {2790			free(*event);2791			free(*alias);2792			return false;2793		}2794 2795		return true;2796	}2797 2798	closedir(dir);2799	return false;2800}2801 2802static int test__checkevent_pmu_events_alias(struct evlist *evlist)2803{2804	struct evsel *evsel1 = evlist__first(evlist);2805	struct evsel *evsel2 = evlist__last(evlist);2806 2807	TEST_ASSERT_VAL("wrong type", evsel1->core.attr.type == evsel2->core.attr.type);2808	TEST_ASSERT_VAL("wrong config", evsel1->core.attr.config == evsel2->core.attr.config);2809	return TEST_OK;2810}2811 2812static int test__pmu_events_alias(char *event, char *alias)2813{2814	struct evlist_test e = { .name = NULL, };2815	char name[2 * NAME_MAX + 20];2816 2817	snprintf(name, sizeof(name), "%s/event=1/,%s/event=1/",2818		 event, alias);2819 2820	e.name  = name;2821	e.check = test__checkevent_pmu_events_alias;2822	return test_event(&e);2823}2824 2825static int test__alias(struct test_suite *test __maybe_unused, int subtest __maybe_unused)2826{2827	char *event, *alias;2828	int ret;2829 2830	if (!test_alias(&event, &alias))2831		return TEST_SKIP;2832 2833	ret = test__pmu_events_alias(event, alias);2834 2835	free(event);2836	free(alias);2837	return ret;2838}2839 2840static int test__pmu_events_alias2(struct test_suite *test __maybe_unused,2841				   int subtest __maybe_unused)2842{2843	static const char events[][30] = {2844			"event-hyphen",2845			"event-two-hyph",2846	};2847	int ret = TEST_OK;2848 2849	for (unsigned int i = 0; i < ARRAY_SIZE(events); i++) {2850		int test_ret = test_event_fake_pmu(&events[i][0]);2851 2852		if (test_ret != TEST_OK) {2853			pr_debug("check_parse_fake %s failed\n", &events[i][0]);2854			ret = combine_test_results(ret, test_ret);2855		}2856	}2857 2858	return ret;2859}2860 2861static struct test_case tests__parse_events[] = {2862	TEST_CASE_REASON("Test event parsing",2863			 events2,2864			 "permissions"),2865	TEST_CASE_REASON("Parsing of all PMU events from sysfs",2866			 pmu_events,2867			 "permissions"),2868	TEST_CASE_REASON("Parsing of given PMU events from sysfs",2869			 pmu_events2,2870			 "permissions"),2871	TEST_CASE_REASON("Parsing of aliased events from sysfs", alias,2872			 "no aliases in sysfs"),2873	TEST_CASE("Parsing of aliased events", pmu_events_alias2),2874	TEST_CASE("Parsing of terms (event modifiers)", terms2),2875	{	.name = NULL, }2876};2877 2878struct test_suite suite__parse_events = {2879	.desc = "Parse event definition strings",2880	.test_cases = tests__parse_events,2881};2882