162306a36Sopenharmony_ci#!/bin/sh
262306a36Sopenharmony_ci# perf all libpfm4 events test
362306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciif perf version --build-options | grep HAVE_LIBPFM | grep -q OFF
662306a36Sopenharmony_cithen
762306a36Sopenharmony_ci  echo "Skipping, no libpfm4 support"
862306a36Sopenharmony_ci  exit 2
962306a36Sopenharmony_cifi
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_cierr=0
1262306a36Sopenharmony_cifor p in $(perf list --raw-dump pfm)
1362306a36Sopenharmony_cido
1462306a36Sopenharmony_ci  if echo "$p" | grep -q unc_
1562306a36Sopenharmony_ci  then
1662306a36Sopenharmony_ci    echo "Skipping uncore event '$p' that may require additional options."
1762306a36Sopenharmony_ci    continue
1862306a36Sopenharmony_ci  fi
1962306a36Sopenharmony_ci  echo "Testing $p"
2062306a36Sopenharmony_ci  result=$(perf stat --pfm-events "$p" true 2>&1)
2162306a36Sopenharmony_ci  x=$?
2262306a36Sopenharmony_ci  if echo "$result" | grep -q "failed to parse event $p : invalid or missing unit mask"
2362306a36Sopenharmony_ci  then
2462306a36Sopenharmony_ci    continue
2562306a36Sopenharmony_ci  fi
2662306a36Sopenharmony_ci  if test "$x" -ne "0"
2762306a36Sopenharmony_ci  then
2862306a36Sopenharmony_ci    echo "Unexpected exit code '$x'"
2962306a36Sopenharmony_ci    err=1
3062306a36Sopenharmony_ci  fi
3162306a36Sopenharmony_ci  if ! echo "$result" | grep -q "$p" && ! echo "$result" | grep -q "<not supported>"
3262306a36Sopenharmony_ci  then
3362306a36Sopenharmony_ci    # We failed to see the event and it is supported. Possibly the workload was
3462306a36Sopenharmony_ci    # too small so retry with something longer.
3562306a36Sopenharmony_ci    result=$(perf stat --pfm-events "$p" perf bench internals synthesize 2>&1)
3662306a36Sopenharmony_ci    x=$?
3762306a36Sopenharmony_ci    if test "$x" -ne "0"
3862306a36Sopenharmony_ci    then
3962306a36Sopenharmony_ci      echo "Unexpected exit code '$x'"
4062306a36Sopenharmony_ci      err=1
4162306a36Sopenharmony_ci    fi
4262306a36Sopenharmony_ci    if ! echo "$result" | grep -q "$p"
4362306a36Sopenharmony_ci    then
4462306a36Sopenharmony_ci      echo "Event '$p' not printed in:"
4562306a36Sopenharmony_ci      echo "$result"
4662306a36Sopenharmony_ci      err=1
4762306a36Sopenharmony_ci    fi
4862306a36Sopenharmony_ci  fi
4962306a36Sopenharmony_cidone
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ciexit "$err"
52