parse-events.c (70c90e4a6b2fbe775b662eafefae51f64d627790) | parse-events.c (ae4aa00a1a9358e0007f6edc71b018a0b0d21190) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2#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" | 1// SPDX-License-Identifier: GPL-2.0 2#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 "pmu-hybrid.h" | |
10#include "pmus.h" 11#include <dirent.h> 12#include <errno.h> 13#include "fncache.h" 14#include <sys/types.h> 15#include <sys/stat.h> 16#include <unistd.h> 17#include <linux/kernel.h> --- 1500 unchanged lines hidden (view full) --- 1518{ 1519 TEST_ASSERT_VAL("wrong events count", 1520 count_tracepoints() == evlist->core.nr_entries); 1521 1522 return test__checkevent_tracepoint_multi(evlist); 1523} 1524#endif /* HAVE_LIBTRACEVENT */ 1525 | 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> --- 1500 unchanged lines hidden (view full) --- 1517{ 1518 TEST_ASSERT_VAL("wrong events count", 1519 count_tracepoints() == evlist->core.nr_entries); 1520 1521 return test__checkevent_tracepoint_multi(evlist); 1522} 1523#endif /* HAVE_LIBTRACEVENT */ 1524 |
1526static int test__hybrid_hw_event_with_pmu(struct evlist *evlist) 1527{ 1528 struct evsel *evsel = evlist__first(evlist); 1529 1530 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 1531 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 1532 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x3c)); 1533 return TEST_OK; 1534} 1535 1536static int test__hybrid_hw_group_event(struct evlist *evlist) 1537{ 1538 struct evsel *evsel, *leader; 1539 1540 evsel = leader = evlist__first(evlist); 1541 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries); 1542 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 1543 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x3c)); 1544 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1545 1546 evsel = evsel__next(evsel); 1547 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 1548 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0xc0)); 1549 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1550 return TEST_OK; 1551} 1552 1553static int test__hybrid_sw_hw_group_event(struct evlist *evlist) 1554{ 1555 struct evsel *evsel, *leader; 1556 1557 evsel = leader = evlist__first(evlist); 1558 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries); 1559 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type); 1560 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1561 1562 evsel = evsel__next(evsel); 1563 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 1564 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x3c)); 1565 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1566 return TEST_OK; 1567} 1568 1569static int test__hybrid_hw_sw_group_event(struct evlist *evlist) 1570{ 1571 struct evsel *evsel, *leader; 1572 1573 evsel = leader = evlist__first(evlist); 1574 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries); 1575 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 1576 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x3c)); 1577 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1578 1579 evsel = evsel__next(evsel); 1580 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type); 1581 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1582 return TEST_OK; 1583} 1584 1585static int test__hybrid_group_modifier1(struct evlist *evlist) 1586{ 1587 struct evsel *evsel, *leader; 1588 1589 evsel = leader = evlist__first(evlist); 1590 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries); 1591 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 1592 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x3c)); 1593 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1594 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); 1595 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1596 1597 evsel = evsel__next(evsel); 1598 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 1599 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0xc0)); 1600 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); 1601 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1602 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1603 return TEST_OK; 1604} 1605 1606static int test__hybrid_raw1(struct evlist *evlist) 1607{ 1608 struct evsel *evsel = evlist__first(evlist); 1609 1610 if (!perf_pmu__hybrid_mounted("cpu_atom")) { 1611 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 1612 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 1613 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x1a)); 1614 return TEST_OK; 1615 } 1616 1617 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries); 1618 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 1619 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x1a)); 1620 1621 /* The type of second event is randome value */ 1622 evsel = evsel__next(evsel); 1623 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x1a)); 1624 return TEST_OK; 1625} 1626 1627static int test__hybrid_raw2(struct evlist *evlist) 1628{ 1629 struct evsel *evsel = evlist__first(evlist); 1630 1631 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 1632 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type); 1633 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x1a)); 1634 return TEST_OK; 1635} 1636 1637static int test__hybrid_cache_event(struct evlist *evlist) 1638{ 1639 struct evsel *evsel = evlist__first(evlist); 1640 1641 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 1642 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->core.attr.type); 1643 TEST_ASSERT_VAL("wrong config", 0x2 == (evsel->core.attr.config & 0xffffffff)); 1644 return TEST_OK; 1645} 1646 | |
1647struct evlist_test { 1648 const char *name; 1649 bool (*valid)(void); 1650 int (*check)(struct evlist *evlist); 1651}; 1652 1653static const struct evlist_test test__events[] = { 1654#ifdef HAVE_LIBTRACEEVENT --- 351 unchanged lines hidden (view full) --- 2006 2007static const struct terms_test test__terms[] = { 2008 [0] = { 2009 .str = "config=10,config1,config2=3,config3=4,umask=1,read,r0xead", 2010 .check = test__checkterms_simple, 2011 }, 2012}; 2013 | 1525struct evlist_test { 1526 const char *name; 1527 bool (*valid)(void); 1528 int (*check)(struct evlist *evlist); 1529}; 1530 1531static const struct evlist_test test__events[] = { 1532#ifdef HAVE_LIBTRACEEVENT --- 351 unchanged lines hidden (view full) --- 1884 1885static const struct terms_test test__terms[] = { 1886 [0] = { 1887 .str = "config=10,config1,config2=3,config3=4,umask=1,read,r0xead", 1888 .check = test__checkterms_simple, 1889 }, 1890}; 1891 |
2014static const struct evlist_test test__hybrid_events[] = { 2015 { 2016 .name = "cpu_core/cpu-cycles/", 2017 .check = test__hybrid_hw_event_with_pmu, 2018 /* 0 */ 2019 }, 2020 { 2021 .name = "{cpu_core/cpu-cycles/,cpu_core/instructions/}", 2022 .check = test__hybrid_hw_group_event, 2023 /* 1 */ 2024 }, 2025 { 2026 .name = "{cpu-clock,cpu_core/cpu-cycles/}", 2027 .check = test__hybrid_sw_hw_group_event, 2028 /* 2 */ 2029 }, 2030 { 2031 .name = "{cpu_core/cpu-cycles/,cpu-clock}", 2032 .check = test__hybrid_hw_sw_group_event, 2033 /* 3 */ 2034 }, 2035 { 2036 .name = "{cpu_core/cpu-cycles/k,cpu_core/instructions/u}", 2037 .check = test__hybrid_group_modifier1, 2038 /* 4 */ 2039 }, 2040 { 2041 .name = "r1a", 2042 .check = test__hybrid_raw1, 2043 /* 5 */ 2044 }, 2045 { 2046 .name = "cpu_core/r1a/", 2047 .check = test__hybrid_raw2, 2048 /* 6 */ 2049 }, 2050 { 2051 .name = "cpu_core/config=10,config1,config2=3,period=1000/u", 2052 .check = test__checkevent_pmu, 2053 /* 7 */ 2054 }, 2055 { 2056 .name = "cpu_core/LLC-loads/", 2057 .check = test__hybrid_cache_event, 2058 /* 8 */ 2059 }, 2060}; 2061 | |
2062static int test_event(const struct evlist_test *e) 2063{ 2064 struct parse_events_error err; 2065 struct evlist *evlist; 2066 int ret; 2067 2068 if (e->valid && !e->valid()) { 2069 pr_debug("... SKIP\n"); --- 262 unchanged lines hidden (view full) --- 2332 2333 return true; 2334 } 2335 2336 closedir(dir); 2337 return false; 2338} 2339 | 1892static int test_event(const struct evlist_test *e) 1893{ 1894 struct parse_events_error err; 1895 struct evlist *evlist; 1896 int ret; 1897 1898 if (e->valid && !e->valid()) { 1899 pr_debug("... SKIP\n"); --- 262 unchanged lines hidden (view full) --- 2162 2163 return true; 2164 } 2165 2166 closedir(dir); 2167 return false; 2168} 2169 |
2340static int test__hybrid(struct test_suite *test __maybe_unused, int subtest __maybe_unused) 2341{ 2342 if (!perf_pmu__has_hybrid()) 2343 return TEST_SKIP; 2344 2345 return test_events(test__hybrid_events, ARRAY_SIZE(test__hybrid_events)); 2346} 2347 | |
2348static int test__checkevent_pmu_events_alias(struct evlist *evlist) 2349{ 2350 struct evsel *evsel1 = evlist__first(evlist); 2351 struct evsel *evsel2 = evlist__last(evlist); 2352 2353 TEST_ASSERT_VAL("wrong type", evsel1->core.attr.type == evsel2->core.attr.type); 2354 TEST_ASSERT_VAL("wrong config", evsel1->core.attr.config == evsel2->core.attr.config); 2355 return TEST_OK; --- 47 unchanged lines hidden (view full) --- 2403 2404 return ret; 2405} 2406 2407static struct test_case tests__parse_events[] = { 2408 TEST_CASE_REASON("Test event parsing", 2409 events2, 2410 "permissions"), | 2170static int test__checkevent_pmu_events_alias(struct evlist *evlist) 2171{ 2172 struct evsel *evsel1 = evlist__first(evlist); 2173 struct evsel *evsel2 = evlist__last(evlist); 2174 2175 TEST_ASSERT_VAL("wrong type", evsel1->core.attr.type == evsel2->core.attr.type); 2176 TEST_ASSERT_VAL("wrong config", evsel1->core.attr.config == evsel2->core.attr.config); 2177 return TEST_OK; --- 47 unchanged lines hidden (view full) --- 2225 2226 return ret; 2227} 2228 2229static struct test_case tests__parse_events[] = { 2230 TEST_CASE_REASON("Test event parsing", 2231 events2, 2232 "permissions"), |
2411 TEST_CASE_REASON("Test parsing of \"hybrid\" CPU events", 2412 hybrid, 2413 "not hybrid"), | |
2414 TEST_CASE_REASON("Parsing of all PMU events from sysfs", 2415 pmu_events, 2416 "permissions"), 2417 TEST_CASE_REASON("Parsing of given PMU events from sysfs", 2418 pmu_events2, 2419 "permissions"), 2420 TEST_CASE_REASON("Parsing of aliased events from sysfs", alias, 2421 "no aliases in sysfs"), 2422 TEST_CASE("Parsing of aliased events", pmu_events_alias2), 2423 TEST_CASE("Parsing of terms (event modifiers)", terms2), 2424 { .name = NULL, } 2425}; 2426 2427struct test_suite suite__parse_events = { 2428 .desc = "Parse event definition strings", 2429 .test_cases = tests__parse_events, 2430}; | 2233 TEST_CASE_REASON("Parsing of all PMU events from sysfs", 2234 pmu_events, 2235 "permissions"), 2236 TEST_CASE_REASON("Parsing of given PMU events from sysfs", 2237 pmu_events2, 2238 "permissions"), 2239 TEST_CASE_REASON("Parsing of aliased events from sysfs", alias, 2240 "no aliases in sysfs"), 2241 TEST_CASE("Parsing of aliased events", pmu_events_alias2), 2242 TEST_CASE("Parsing of terms (event modifiers)", terms2), 2243 { .name = NULL, } 2244}; 2245 2246struct test_suite suite__parse_events = { 2247 .desc = "Parse event definition strings", 2248 .test_cases = tests__parse_events, 2249}; |