1*2d584688SIan Rogers#!/bin/bash 2*2d584688SIan Rogers# perf header tests 3*2d584688SIan Rogers# SPDX-License-Identifier: GPL-2.0 4*2d584688SIan Rogers 5*2d584688SIan Rogersset -e 6*2d584688SIan Rogers 7*2d584688SIan Rogerserr=0 8*2d584688SIan Rogersperfdata=$(mktemp /tmp/__perf_test_header.perf.data.XXXXX) 9*2d584688SIan Rogersscript_output=$(mktemp /tmp/__perf_test_header.perf.data.XXXXX.script) 10*2d584688SIan Rogers 11*2d584688SIan Rogerscleanup() { 12*2d584688SIan Rogers rm -f "${perfdata}" 13*2d584688SIan Rogers rm -f "${perfdata}".old 14*2d584688SIan Rogers rm -f "${script_output}" 15*2d584688SIan Rogers 16*2d584688SIan Rogers trap - EXIT TERM INT 17*2d584688SIan Rogers} 18*2d584688SIan Rogers 19*2d584688SIan Rogerstrap_cleanup() { 20*2d584688SIan Rogers echo "Unexpected signal in ${FUNCNAME[1]}" 21*2d584688SIan Rogers cleanup 22*2d584688SIan Rogers exit 1 23*2d584688SIan Rogers} 24*2d584688SIan Rogerstrap trap_cleanup EXIT TERM INT 25*2d584688SIan Rogers 26*2d584688SIan Rogerscheck_header_output() { 27*2d584688SIan Rogers declare -a fields=( 28*2d584688SIan Rogers "captured" 29*2d584688SIan Rogers "hostname" 30*2d584688SIan Rogers "os release" 31*2d584688SIan Rogers "arch" 32*2d584688SIan Rogers "cpuid" 33*2d584688SIan Rogers "nrcpus" 34*2d584688SIan Rogers "event" 35*2d584688SIan Rogers "cmdline" 36*2d584688SIan Rogers "perf version" 37*2d584688SIan Rogers "sibling (cores|dies|threads)" 38*2d584688SIan Rogers "sibling threads" 39*2d584688SIan Rogers "total memory" 40*2d584688SIan Rogers ) 41*2d584688SIan Rogers for i in "${fields[@]}" 42*2d584688SIan Rogers do 43*2d584688SIan Rogers if ! grep -q -E "$i" "${script_output}" 44*2d584688SIan Rogers then 45*2d584688SIan Rogers echo "Failed to find expect $i in output" 46*2d584688SIan Rogers err=1 47*2d584688SIan Rogers fi 48*2d584688SIan Rogers done 49*2d584688SIan Rogers} 50*2d584688SIan Rogers 51*2d584688SIan Rogerstest_file() { 52*2d584688SIan Rogers echo "Test perf header file" 53*2d584688SIan Rogers 54*2d584688SIan Rogers perf record -o "${perfdata}" -g -- perf test -w noploop 55*2d584688SIan Rogers perf report --header-only -I -i "${perfdata}" > "${script_output}" 56*2d584688SIan Rogers check_header_output 57*2d584688SIan Rogers 58*2d584688SIan Rogers echo "Test perf header file [Done]" 59*2d584688SIan Rogers} 60*2d584688SIan Rogers 61*2d584688SIan Rogerstest_pipe() { 62*2d584688SIan Rogers echo "Test perf header pipe" 63*2d584688SIan Rogers 64*2d584688SIan Rogers perf record -o - -g -- perf test -w noploop | perf report --header-only -I -i - > "${script_output}" 65*2d584688SIan Rogers check_header_output 66*2d584688SIan Rogers 67*2d584688SIan Rogers echo "Test perf header pipe [Done]" 68*2d584688SIan Rogers} 69*2d584688SIan Rogers 70*2d584688SIan Rogerstest_file 71*2d584688SIan Rogerstest_pipe 72*2d584688SIan Rogers 73*2d584688SIan Rogerscleanup 74*2d584688SIan Rogersexit $err 75