1#!/bin/bash 2# perf timechart tests 3# SPDX-License-Identifier: GPL-2.0 4 5set -e 6 7err=0 8perfdata=$(mktemp /tmp/__perf_timechart_test.perf.data.XXXXX) 9output=$(mktemp /tmp/__perf_timechart_test.output.XXXXX.svg) 10 11cleanup() { 12 rm -f "${perfdata}" 13 rm -f "${output}" 14 trap - EXIT TERM INT 15} 16 17trap_cleanup() { 18 echo "Unexpected signal in ${FUNCNAME[1]}" 19 cleanup 20 exit 1 21} 22trap trap_cleanup EXIT TERM INT 23 24test_timechart() { 25 echo "Basic perf timechart test" 26 27 # Try to record timechart data. 28 # perf timechart record uses system-wide recording and specific tracepoints. 29 # If it fails (e.g. permissions, missing tracepoints), skip the test. 30 if ! perf timechart record -o "${perfdata}" true > /dev/null 2>&1; then 31 echo "Basic perf timechart test [Skipped: perf timechart record failed (permissions/events?)]" 32 return 33 fi 34 35 # Generate the timechart 36 if ! perf timechart -i "${perfdata}" -o "${output}" > /dev/null 2>&1; then 37 echo "Basic perf timechart test [Failed: perf timechart command failed]" 38 err=1 39 return 40 fi 41 42 # Check if output file exists and is not empty 43 if [ ! -s "${output}" ]; then 44 echo "Basic perf timechart test [Failed: output file is empty or missing]" 45 err=1 46 return 47 fi 48 49 # Check if it looks like an SVG 50 if ! grep -q "svg" "${output}"; then 51 echo "Basic perf timechart test [Failed: output doesn't look like SVG]" 52 err=1 53 return 54 fi 55 56 echo "Basic perf timechart test [Success]" 57} 58 59if ! perf check feature -q libtraceevent ; then 60 echo "perf timechart is not supported. Skip." 61 cleanup 62 exit 2 63fi 64 65test_timechart 66cleanup 67exit $err 68