From nobody Sun Feb 8 07:25:23 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45583EB64D9 for ; Thu, 15 Jun 2023 13:55:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344754AbjFONzs (ORCPT ); Thu, 15 Jun 2023 09:55:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344641AbjFONyq (ORCPT ); Thu, 15 Jun 2023 09:54:46 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AD0D1FD4; Thu, 15 Jun 2023 06:54:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686837284; x=1718373284; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=815xhyqBJVkUcTa8Wnb+dhIrshSrEjCMA06FFhOLA18=; b=kmXuT3ujwTcmvUdRvX4h+dVAgbOY5t3ACG20eWo3smlgfNTBOpBHQMZD 2D9XqijUdcNJEgBSMCa4g+A0Fy+T8Zb1sTJ84Nj/H0BD4cXmFxfB1BwpK f+LldfKonXADpSibh/lksv2p27AhHUP6yz7+VoDvkodfHvd2RSOU9wRtr 1Gl/Bv2PvpOl+5dyelAqVgPaiD2MltHgZOjc22paFZhmozAvqypB2AHf+ phgksY9Xph7ZduabuvhKgSg/REkX2uXDjplYFJhltBMJsGSwf1gUVF1ZD uQRM/lvflUoptMfwLVriqw8Bp5MELRh8Gtaf5F2+z+DcHQg9ALRr6zwZa Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="356411436" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="356411436" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 06:54:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="782527077" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="782527077" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by fmsmga004.fm.intel.com with ESMTP; 15 Jun 2023 06:54:42 -0700 From: kan.liang@linux.intel.com To: acme@kernel.org, mingo@redhat.com, peterz@infradead.org, irogers@google.com, namhyung@kernel.org, jolsa@kernel.org, adrian.hunter@intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ak@linux.intel.com, eranian@google.com, ahmad.yasin@intel.com, Kan Liang Subject: [PATCH V3 8/8] perf test: Add test case for the standard perf stat output Date: Thu, 15 Jun 2023 06:53:15 -0700 Message-Id: <20230615135315.3662428-9-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230615135315.3662428-1-kan.liang@linux.intel.com> References: <20230615135315.3662428-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kan Liang Add a new test case to verify the standard perf stat output with different options. Reviewed-by: Ian Rogers Signed-off-by: Kan Liang --- tools/perf/tests/shell/stat+std_output.sh | 108 ++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 tools/perf/tests/shell/stat+std_output.sh diff --git a/tools/perf/tests/shell/stat+std_output.sh b/tools/perf/tests/s= hell/stat+std_output.sh new file mode 100755 index 000000000000..98cc3356a04a --- /dev/null +++ b/tools/perf/tests/shell/stat+std_output.sh @@ -0,0 +1,108 @@ +#!/bin/bash +# perf stat STD output linter +# SPDX-License-Identifier: GPL-2.0 +# Tests various perf stat STD output commands for +# default event and metricgroup + +set -e + +. $(dirname $0)/lib/stat_output.sh + +stat_output=3D$(mktemp /tmp/__perf_test.stat_output.std.XXXXX) + +event_name=3D(cpu-clock task-clock context-switches cpu-migrations page-fa= ults cycles instructions branches branch-misses stalled-cycles-frontend sta= lled-cycles-backend) +event_metric=3D("CPUs utilized" "CPUs utilized" "/sec" "/sec" "/sec" "GHz"= "insn per cycle" "/sec" "of all branches" "frontend cycles idle" "backend = cycles idle") + +metricgroup_name=3D(TopdownL1 TopdownL2) + +cleanup() { + rm -f "${stat_output}" + + trap - EXIT TERM INT +} + +trap_cleanup() { + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +function commachecker() +{ + local -i cnt=3D0 + local prefix=3D1 + + case "$1" + in "--interval") prefix=3D2 + ;; "--per-thread") prefix=3D2 + ;; "--system-wide-no-aggr") prefix=3D2 + ;; "--per-core") prefix=3D3 + ;; "--per-socket") prefix=3D3 + ;; "--per-node") prefix=3D3 + ;; "--per-die") prefix=3D3 + ;; "--per-cache") prefix=3D3 + esac + + while read line + do + # Ignore initial "started on" comment. + x=3D${line:0:1} + [ "$x" =3D "#" ] && continue + # Ignore initial blank line. + [ "$line" =3D "" ] && continue + # Ignore "Performance counter stats" + x=3D${line:0:25} + [ "$x" =3D "Performance counter stats" ] && continue + # Ignore "seconds time elapsed" and break + [[ "$line" =3D=3D *"time elapsed"* ]] && break + + main_body=3D$(echo $line | cut -d' ' -f$prefix-) + x=3D${main_body%#*} + # Check default metricgroup + y=3D$(echo $x | tr -d ' ') + [ "$y" =3D "" ] && continue + for i in "${!metricgroup_name[@]}"; do + [[ "$y" =3D=3D *"${metricgroup_name[$i]}"* ]] && break + done + [[ "$y" =3D=3D *"${metricgroup_name[$i]}"* ]] && continue + + # Check default event + for i in "${!event_name[@]}"; do + [[ "$x" =3D=3D *"${event_name[$i]}"* ]] && break + done + + [[ ! "$x" =3D=3D *"${event_name[$i]}"* ]] && { + echo "Unknown event name in $line" 1>&2 + exit 1; + } + + # Check event metric if it exists + [[ ! "$main_body" =3D=3D *"#"* ]] && continue + [[ ! "$main_body" =3D=3D *"${event_metric[$i]}"* ]] && { + echo "wrong event metric. expected ${event_metric[$i]} in $line" 1>&2 + exit 1; + } + done < "${stat_output}" + return 0 +} + +perf_cmd=3D"-o ${stat_output}" + +skip_test=3D$(check_for_topology) +check_no_args "STD" "$perf_cmd" +check_system_wide "STD" "$perf_cmd" +check_interval "STD" "$perf_cmd" +check_per_thread "STD" "$perf_cmd" +check_per_node "STD" "$perf_cmd" +if [ $skip_test -ne 1 ] +then + check_system_wide_no_aggr "STD" "$perf_cmd" + check_per_core "STD" "$perf_cmd" + check_per_cache_instance "STD" "$perf_cmd" + check_per_die "STD" "$perf_cmd" + check_per_socket "STD" "$perf_cmd" +else + echo "[Skip] Skipping tests for system_wide_no_aggr, per_core, per_die an= d per_socket since socket id exposed via topology is invalid" +fi +cleanup +exit 0 --=20 2.35.1