Skip to content

Commit 56be0fe

Browse files
tlfalconacmel
authored andcommitted
perf record: Add auto counter reload parse and regression tests
Include event parsing and regression tests for auto counter reload and ratio-to-prev event term. Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Thomas Falcon <thomas.falcon@intel.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 6b9c026 commit 56be0fe

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

tools/perf/tests/parse-events.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,53 @@ static int test__intel_pt(struct evlist *evlist)
17361736
return TEST_OK;
17371737
}
17381738

1739+
static bool test__acr_valid(void)
1740+
{
1741+
struct perf_pmu *pmu = NULL;
1742+
1743+
while ((pmu = perf_pmus__scan_core(pmu)) != NULL) {
1744+
if (perf_pmu__has_format(pmu, "acr_mask"))
1745+
return true;
1746+
}
1747+
1748+
return false;
1749+
}
1750+
1751+
static int test__ratio_to_prev(struct evlist *evlist)
1752+
{
1753+
struct evsel *evsel;
1754+
int ret;
1755+
1756+
TEST_ASSERT_VAL("wrong number of entries", 2 * perf_pmus__num_core_pmus() == evlist->core.nr_entries);
1757+
1758+
evlist__for_each_entry(evlist, evsel) {
1759+
if (!perf_pmu__has_format(evsel->pmu, "acr_mask"))
1760+
return TEST_OK;
1761+
1762+
if (evsel == evlist__first(evlist)) {
1763+
TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
1764+
TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1765+
TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1766+
TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1767+
ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles");
1768+
} else {
1769+
TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
1770+
TEST_ASSERT_VAL("wrong leader", !evsel__is_group_leader(evsel));
1771+
TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 0);
1772+
TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1773+
ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions");
1774+
}
1775+
if (ret)
1776+
return ret;
1777+
/*
1778+
* The period value gets configured within evlist__config,
1779+
* while this test executes only parse events method.
1780+
*/
1781+
TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
1782+
}
1783+
return TEST_OK;
1784+
}
1785+
17391786
static int test__checkevent_complex_name(struct evlist *evlist)
17401787
{
17411788
struct evsel *evsel = evlist__first(evlist);
@@ -2249,6 +2296,13 @@ static const struct evlist_test test__events[] = {
22492296
.check = test__checkevent_tracepoint,
22502297
/* 4 */
22512298
},
2299+
{
2300+
.name = "{cycles,instructions/period=200000,ratio-to-prev=2.0/}",
2301+
.valid = test__acr_valid,
2302+
.check = test__ratio_to_prev,
2303+
/* 5 */
2304+
},
2305+
22522306
};
22532307

22542308
static const struct evlist_test test__events_pmu[] = {

tools/perf/tests/shell/record.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,45 @@ test_callgraph() {
388388
echo "Callgraph test [Success]"
389389
}
390390

391+
test_ratio_to_prev() {
392+
echo "ratio-to-prev test"
393+
if ! perf record -o /dev/null -e "{instructions, cycles/period=100000,ratio-to-prev=0.5/}" \
394+
true 2> /dev/null
395+
then
396+
echo "ratio-to-prev [Skipped not supported]"
397+
return
398+
fi
399+
if ! perf record -o /dev/null -e "instructions, cycles/period=100000,ratio-to-prev=0.5/" \
400+
true |& grep -q 'Invalid use of ratio-to-prev term without preceding element in group'
401+
then
402+
echo "ratio-to-prev test [Failed elements must be in same group]"
403+
err=1
404+
return
405+
fi
406+
if ! perf record -o /dev/null -e "{instructions,dummy,cycles/period=100000,ratio-to-prev=0.5/}" \
407+
true |& grep -q 'must have same PMU'
408+
then
409+
echo "ratio-to-prev test [Failed elements must have same PMU]"
410+
err=1
411+
return
412+
fi
413+
if ! perf record -o /dev/null -e "{instructions,cycles/ratio-to-prev=0.5/}" \
414+
true |& grep -q 'Event period term or count (-c) must be set when using ratio-to-prev term.'
415+
then
416+
echo "ratio-to-prev test [Failed period must be set]"
417+
err=1
418+
return
419+
fi
420+
if ! perf record -o /dev/null -e "{cycles/ratio-to-prev=0.5/}" \
421+
true |& grep -q 'Invalid use of ratio-to-prev term without preceding element in group'
422+
then
423+
echo "ratio-to-prev test [Failed need 2+ events]"
424+
err=1
425+
return
426+
fi
427+
echo "Basic ratio-to-prev record test [Success]"
428+
}
429+
391430
# raise the limit of file descriptors to minimum
392431
if [[ $default_fd_limit -lt $min_fd_limit ]]; then
393432
ulimit -Sn $min_fd_limit
@@ -404,6 +443,7 @@ test_leader_sampling
404443
test_topdown_leader_sampling
405444
test_precise_max
406445
test_callgraph
446+
test_ratio_to_prev
407447

408448
# restore the default value
409449
ulimit -Sn $default_fd_limit

0 commit comments

Comments
 (0)