12d584688SIan Rogers#!/bin/bash 22d584688SIan Rogers# perf header tests 32d584688SIan Rogers# SPDX-License-Identifier: GPL-2.0 42d584688SIan Rogers 52d584688SIan Rogersset -e 62d584688SIan Rogers 72d584688SIan Rogerserr=0 82d584688SIan Rogersperfdata=$(mktemp /tmp/__perf_test_header.perf.data.XXXXX) 92d584688SIan Rogersscript_output=$(mktemp /tmp/__perf_test_header.perf.data.XXXXX.script) 102d584688SIan Rogers 112d584688SIan Rogerscleanup() { 122d584688SIan Rogers rm -f "${perfdata}" 132d584688SIan Rogers rm -f "${perfdata}".old 142d584688SIan Rogers rm -f "${script_output}" 152d584688SIan Rogers 162d584688SIan Rogers trap - EXIT TERM INT 172d584688SIan Rogers} 182d584688SIan Rogers 192d584688SIan Rogerstrap_cleanup() { 202d584688SIan Rogers echo "Unexpected signal in ${FUNCNAME[1]}" 212d584688SIan Rogers cleanup 222d584688SIan Rogers exit 1 232d584688SIan Rogers} 242d584688SIan Rogerstrap trap_cleanup EXIT TERM INT 252d584688SIan Rogers 262d584688SIan Rogerscheck_header_output() { 272d584688SIan Rogers declare -a fields=( 282d584688SIan Rogers "captured" 292d584688SIan Rogers "hostname" 302d584688SIan Rogers "os release" 312d584688SIan Rogers "arch" 322d584688SIan Rogers "cpuid" 332d584688SIan Rogers "nrcpus" 342d584688SIan Rogers "event" 352d584688SIan Rogers "cmdline" 362d584688SIan Rogers "perf version" 372d584688SIan Rogers "sibling (cores|dies|threads)" 382d584688SIan Rogers "sibling threads" 392d584688SIan Rogers "total memory" 402d584688SIan Rogers ) 412d584688SIan Rogers for i in "${fields[@]}" 422d584688SIan Rogers do 432d584688SIan Rogers if ! grep -q -E "$i" "${script_output}" 442d584688SIan Rogers then 45*6c21316eSIan Rogers echo "Failed to find expected $i in output" 462d584688SIan Rogers err=1 472d584688SIan Rogers fi 482d584688SIan Rogers done 492d584688SIan Rogers} 502d584688SIan Rogers 512d584688SIan Rogerstest_file() { 522d584688SIan Rogers echo "Test perf header file" 532d584688SIan Rogers 54844f962cSThomas Richter perf record -o "${perfdata}" -- perf test -w noploop 552d584688SIan Rogers perf report --header-only -I -i "${perfdata}" > "${script_output}" 562d584688SIan Rogers check_header_output 572d584688SIan Rogers 582d584688SIan Rogers echo "Test perf header file [Done]" 592d584688SIan Rogers} 602d584688SIan Rogers 612d584688SIan Rogerstest_pipe() { 622d584688SIan Rogers echo "Test perf header pipe" 632d584688SIan Rogers 64844f962cSThomas Richter perf record -o - -- perf test -w noploop | perf report --header-only -I -i - > "${script_output}" 652d584688SIan Rogers check_header_output 662d584688SIan Rogers 672d584688SIan Rogers echo "Test perf header pipe [Done]" 682d584688SIan Rogers} 692d584688SIan Rogers 702d584688SIan Rogerstest_file 712d584688SIan Rogerstest_pipe 722d584688SIan Rogers 732d584688SIan Rogerscleanup 742d584688SIan Rogersexit $err 75