xref: /linux/tools/perf/tests/shell/c2c.sh (revision ac881007c4bf7be4dae713c36b7f0309f2843611)
1*ac881007SIan Rogers#!/bin/bash
2*ac881007SIan Rogers# perf c2c tests
3*ac881007SIan Rogers# SPDX-License-Identifier: GPL-2.0
4*ac881007SIan Rogers
5*ac881007SIan Rogersset -e
6*ac881007SIan Rogers
7*ac881007SIan Rogerserr=0
8*ac881007SIan Rogersperfdata=$(mktemp /tmp/__perf_c2c_test.perf.data.XXXXX)
9*ac881007SIan Rogers
10*ac881007SIan Rogerscleanup() {
11*ac881007SIan Rogers	rm -f "${perfdata}"
12*ac881007SIan Rogers	rm -f "${perfdata}".old
13*ac881007SIan Rogers	trap - EXIT TERM INT
14*ac881007SIan Rogers}
15*ac881007SIan Rogers
16*ac881007SIan Rogerstrap_cleanup() {
17*ac881007SIan Rogers	echo "Unexpected signal in ${FUNCNAME[1]}"
18*ac881007SIan Rogers	cleanup
19*ac881007SIan Rogers	exit 1
20*ac881007SIan Rogers}
21*ac881007SIan Rogerstrap trap_cleanup EXIT TERM INT
22*ac881007SIan Rogers
23*ac881007SIan Rogerscheck_c2c_support() {
24*ac881007SIan Rogers	# Check if perf c2c record works.
25*ac881007SIan Rogers	if ! perf c2c record -o "${perfdata}" -- true > /dev/null 2>&1 ; then
26*ac881007SIan Rogers		return 1
27*ac881007SIan Rogers	fi
28*ac881007SIan Rogers	return 0
29*ac881007SIan Rogers}
30*ac881007SIan Rogers
31*ac881007SIan Rogerstest_c2c_record_report() {
32*ac881007SIan Rogers	echo "c2c record and report test"
33*ac881007SIan Rogers	if ! check_c2c_support ; then
34*ac881007SIan Rogers		echo "c2c record and report test [Skipped: perf c2c record failed (possibly missing hardware support)]"
35*ac881007SIan Rogers		err=2
36*ac881007SIan Rogers		return
37*ac881007SIan Rogers	fi
38*ac881007SIan Rogers
39*ac881007SIan Rogers	# Run a workload that does some memory operations.
40*ac881007SIan Rogers	if ! perf c2c record -o "${perfdata}" -- perf test -w datasym 1 > /dev/null 2>&1 ; then
41*ac881007SIan Rogers		echo "c2c record and report test [Skipped: perf c2c record failed during workload]"
42*ac881007SIan Rogers		return
43*ac881007SIan Rogers	fi
44*ac881007SIan Rogers
45*ac881007SIan Rogers	if ! perf c2c report -i "${perfdata}" --stdio > /dev/null 2>&1 ; then
46*ac881007SIan Rogers		echo "c2c record and report test [Failed: report failed]"
47*ac881007SIan Rogers		err=1
48*ac881007SIan Rogers		return
49*ac881007SIan Rogers	fi
50*ac881007SIan Rogers
51*ac881007SIan Rogers	if ! perf c2c report -i "${perfdata}" -N > /dev/null 2>&1 ; then
52*ac881007SIan Rogers		echo "c2c record and report test [Failed: report -N failed]"
53*ac881007SIan Rogers		err=1
54*ac881007SIan Rogers		return
55*ac881007SIan Rogers	fi
56*ac881007SIan Rogers
57*ac881007SIan Rogers	echo "c2c record and report test [Success]"
58*ac881007SIan Rogers}
59*ac881007SIan Rogers
60*ac881007SIan Rogerstest_c2c_record_report
61*ac881007SIan Rogerscleanup
62*ac881007SIan Rogersexit $err
63