linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/7] perf testsuite: Add common regex patters
@ 2024-01-31 11:39 Michael Petlan
  2024-01-31 11:39 ` [PATCH 2/7] perf testsuite: Add common setting for shell tests Michael Petlan
                   ` (8 more replies)
  0 siblings, 9 replies; 23+ messages in thread
From: Michael Petlan @ 2024-01-31 11:39 UTC (permalink / raw)
  To: linux-perf-users, vmolnaro, acme, acme; +Cc: mhiramat

From: Veronika Molnarova <vmolnaro@redhat.com>

Unify perf regexes for checking testing output into a single file
to reduce duplicates and prevent errors when editing.

This will be used in upcomming patches in shell tests.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/tests/shell/common/patterns.sh | 256 ++++++++++++++++++++++
 1 file changed, 256 insertions(+)
 create mode 100644 tools/perf/tests/shell/common/patterns.sh

diff --git a/tools/perf/tests/shell/common/patterns.sh b/tools/perf/tests/shell/common/patterns.sh
new file mode 100644
index 000000000000..919a07b8b454
--- /dev/null
+++ b/tools/perf/tests/shell/common/patterns.sh
@@ -0,0 +1,256 @@
+# SPDX-License-Identifier: GPL-2.0
+
+export RE_NUMBER="[0-9\.]+"
+# Number
+# Examples:
+#    123.456
+
+
+export RE_NUMBER_HEX="[0-9A-Fa-f]+"
+# Hexadecimal number
+# Examples:
+#    1234
+#    a58d
+#    aBcD
+#    deadbeef
+
+
+export RE_DATE_YYYYMMDD="[0-9]{4}-(?:(?:01|03|05|07|08|10|12)-(?:[0-2][0-9]|3[0-1])|02-[0-2][0-9]|(?:(?:04|06|09|11)-(?:[0-2][0-9]|30)))"
+# Date in YYYY-MM-DD form
+# Examples:
+#    1990-02-29
+#    0015-07-31
+#    2456-12-31
+#!   2012-13-01
+#!   1963-09-31
+
+
+export RE_TIME="(?:[0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]"
+# Time
+# Examples:
+#    15:12:27
+#    23:59:59
+#!   24:00:00
+#!   11:25:60
+#!   17:60:15
+
+
+export RE_DATE_TIME="\w+\s+\w+\s+$RE_NUMBER\s+$RE_TIME\s+$RE_NUMBER"
+# Time and date
+# Examples:
+#    Wed Feb 12 10:46:26 2020
+#    Mon Mar  2 13:27:06 2020
+#!   St úno 12 10:57:21 CET 2020
+#!   Po úno 14 15:17:32 2010
+
+
+export RE_ADDRESS="0x$RE_NUMBER_HEX"
+# Memory address
+# Examples:
+#    0x123abc
+#    0xffffffff9abe8ae8
+#    0x0
+
+
+export RE_ADDRESS_NOT_NULL="0x[0-9A-Fa-f]*[1-9A-Fa-f]+[0-9A-Fa-f]*"
+# Memory address (not NULL)
+# Examples:
+#    0xffffffff9abe8ae8
+#!   0x0
+#!   0x0000000000000000
+
+export RE_PROCESS_PID="\w+\/\d+"
+# A process with PID
+# Example:
+#    sleep/4102
+
+
+export RE_EVENT_ANY="[\w\-\:\/_=,]+"
+# Name of any event (universal)
+# Examples:
+#    cpu-cycles
+#    cpu/event=12,umask=34/
+#    r41e1
+#    nfs:nfs_getattr_enter
+
+
+export RE_EVENT="[\w\-:_]+"
+# Name of an usual event
+# Examples:
+#    cpu-cycles
+
+
+export RE_EVENT_RAW="r$RE_NUMBER_HEX"
+# Specification of a raw event
+# Examples:
+#    r41e1
+#    r1a
+
+
+export RE_EVENT_CPU="cpu/(\w+=$RE_NUMBER_HEX,?)+/p*"
+# Specification of a CPU event
+# Examples:
+#    cpu/event=12,umask=34/pp
+
+
+export RE_EVENT_UNCORE="uncore/[\w_]+/"
+# Specification of an uncore event
+# Examples:
+#    uncore/qhl_request_local_reads/
+
+
+export RE_EVENT_SUBSYSTEM="[\w\-]+:[\w\-]+"
+# Name of an event from subsystem
+# Examples:
+#    ext4:ext4_ordered_write_end
+#    sched:sched_switch
+
+
+export RE_FILE_NAME="[\w\+\.-]+"
+# A filename
+# Examples:
+#    libstdc++.so.6
+#!   some/path
+
+
+export RE_PATH_ABSOLUTE="(?:\/$RE_FILE_NAME)+"
+# A full filepath
+# Examples:
+#    /usr/lib64/somelib.so.5.4.0
+#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
+#    /usr/bin/mv
+#!   some/relative/path
+#!   ./some/relative/path
+
+
+export RE_PATH="(?:$RE_FILE_NAME)?$RE_PATH_ABSOLUTE"
+# A filepath
+# Examples:
+#    /usr/lib64/somelib.so.5.4.0
+#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
+#    ./.emacs
+#    src/fs/file.c
+
+
+export RE_DSO="(?:$RE_PATH_ABSOLUTE(?: \(deleted\))?|\[kernel\.kallsyms\]|\[unknown\]|\[vdso\]|\[kernel\.vmlinux\][\.\w]*)"
+# A DSO name in various result tables
+# Examples:
+#    /usr/lib64/somelib.so.5.4.0
+#    /usr/bin/somebinart (deleted)
+#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
+#    [kernel.kallsyms]
+#    [kernel.vmlinux]
+#    [vdso]
+#    [unknown]
+
+
+export RE_LINE_COMMENT="^#.*"
+# A comment line
+# Examples:
+#    # Started on Thu Sep 10 11:43:00 2015
+
+
+export RE_LINE_EMPTY="^\s*$"
+# An empty line with possible whitespaces
+# Examples:
+#
+
+
+export RE_LINE_RECORD1="^\[\s+perf\s+record:\s+Woken up $RE_NUMBER times? to write data\s+\].*$"
+# The first line of perf-record "OK" output
+# Examples:
+#    [ perf record: Woken up 1 times to write data ]
+
+
+export RE_LINE_RECORD2="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\.data(?:\.\d+)?\s*\(~?$RE_NUMBER samples\)\s+\].*$"
+# The second line of perf-record "OK" output
+# Examples:
+#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB perf.data (~109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB ./perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB ./perf.data.3 (109 samples) ]
+
+
+export RE_LINE_RECORD2_TOLERANT="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\.data(?:\.\d+)?\s*(?:\(~?$RE_NUMBER samples\))?\s+\].*$"
+# The second line of perf-record "OK" output, even no samples is OK here
+# Examples:
+#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB perf.data (~109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB ./perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB ./perf.data.3 (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB perf.data ]
+
+
+export RE_LINE_RECORD2_TOLERANT_FILENAME="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\w*\.data(?:\.\d+)?\s*\(~?$RE_NUMBER samples\)\s+\].*$"
+# The second line of perf-record "OK" output
+# Examples:
+#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB perf_ls.data (~109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB perf_aNyCaSe.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB ./perfdata.data.3 (109 samples) ]
+#!    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/my_own.data (109 samples) ]
+#!    [ perf record: Captured and wrote 0.405 MB ./UPPERCASE.data (109 samples) ]
+#!    [ perf record: Captured and wrote 0.405 MB ./aNyKiNDoF.data.3 (109 samples) ]
+#!    [ perf record: Captured and wrote 0.405 MB perf.data ]
+
+
+export RE_LINE_TRACE_FULL="^\s*$RE_NUMBER\s*\(\s*$RE_NUMBER\s*ms\s*\):\s*$RE_PROCESS_PID\s+.*\)\s+=\s+\-?$RE_NUMBER|$RE_NUMBER_HEX.*$"
+# A line of perf-trace output
+# Examples:
+#    0.115 ( 0.005 ms): sleep/4102 open(filename: 0xd09e2ab2, flags: CLOEXEC                             ) = 3
+#    0.157 ( 0.005 ms): sleep/4102 mmap(len: 3932736, prot: EXEC|READ, flags: PRIVATE|DENYWRITE, fd: 3   ) = 0x7f89d0605000
+
+export RE_LINE_TRACE_ONE_PROC="^\s*$RE_NUMBER\s*\(\s*$RE_NUMBER\s*ms\s*\):\s*\w+\(.*\)\s+=\s+(?:\-?$RE_NUMBER)|(?:0x$RE_NUMBER_HEX).*$"
+# A line of perf-trace output
+# Examples:
+#    0.115 ( 0.005 ms): open(filename: 0xd09e2ab2, flags: CLOEXEC                             ) = 3
+#    0.157 ( 0.005 ms): mmap(len: 3932736, prot: EXEC|READ, flags: PRIVATE|DENYWRITE, fd: 3   ) = 0x7f89d0605000
+
+export RE_LINE_TRACE_CONTINUED="^\s*$RE_NUMBER\s*\(\s*$RE_NUMBER\s*ms\s*\):\s*\.\.\.\s*\[continued\]:\s+\w+\(\).*\s+=\s+(?:\-?$RE_NUMBER)|(?:0x$RE_NUMBER_HEX).*$"
+# A line of perf-trace output
+# Examples:
+#    0.000 ( 0.000 ms):  ... [continued]: nanosleep()) = 0
+#    0.000 ( 0.000 ms):  ... [continued]: nanosleep()) = 0x00000000
+
+export RE_LINE_TRACE_SUMMARY_HEADER="\s*syscall\s+calls\s+(?:errors\s+)?total\s+min\s+avg\s+max\s+stddev"
+# A header of a perf-trace summary table
+# Example:
+#    syscall            calls    total       min       avg       max      stddev
+#    syscall            calls  errors  total       min       avg       max       stddev
+
+
+export RE_LINE_TRACE_SUMMARY_CONTENT="^\s*\w+\s+(?:$RE_NUMBER\s+){5,6}$RE_NUMBER%"
+# A line of a perf-trace summary table
+# Example:
+#    open                   3     0.017     0.005     0.006     0.007     10.90%
+#    openat                 2      0     0.017     0.008     0.009     0.010     12.29%
+
+
+export RE_LINE_REPORT_CONTENT="^\s+$RE_NUMBER%\s+\w+\s+\S+\s+\S+\s+\S+" # FIXME
+# A line from typicap perf report --stdio output
+# Example:
+#     100.00%  sleep    [kernel.vmlinux]  [k] syscall_return_slowpath
+
+
+export RE_TASK="\s+[\w~\/ \.\+:#-]+(?:\[-1(?:\/\d+)?\]|\[\d+(?:\/\d+)?\])"
+# A name of a task used for perf sched timehist -s
+# Example:
+#     sleep[62755]
+#     runtest.sh[62762]
+#     gmain[705/682]
+#     xfsaild/dm-0[495]
+#     kworker/u8:1-ev[62714]
+#     :-1[-1/62756]
+#     :-1[-1]
+#     :-1[62756]
+
+
+export RE_SEGFAULT=".*(?:Segmentation\sfault|SIGSEGV|\score\s|dumped|segfault).*"
+# Possible variations of the segfault message
+# Example:
+#     /bin/bash: line 1:    32 Segmentation fault      timeout 15s
+#     Segmentation fault (core dumped)
+#     Program terminated with signal SIGSEGV
+#!     WARNING: 12323431 isn't a 'cpu_core', please use a CPU list in the 'cpu_core' range (0-15)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 2/7] perf testsuite: Add common setting for shell tests
  2024-01-31 11:39 [PATCH 1/7] perf testsuite: Add common regex patters Michael Petlan
@ 2024-01-31 11:39 ` Michael Petlan
  2024-01-31 11:39 ` [PATCH 3/7] perf testsuite: Add initialization script " Michael Petlan
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-01-31 11:39 UTC (permalink / raw)
  To: linux-perf-users, vmolnaro, acme, acme; +Cc: mhiramat

From: Veronika Molnarova <vmolnaro@redhat.com>

Add settings defining sample commands later shared by shell tests. This
adds the possibility to globally adjust the default values for the whole
testsuite.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/tests/shell/common/settings.sh | 79 +++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 tools/perf/tests/shell/common/settings.sh

diff --git a/tools/perf/tests/shell/common/settings.sh b/tools/perf/tests/shell/common/settings.sh
new file mode 100644
index 000000000000..361641dbaaad
--- /dev/null
+++ b/tools/perf/tests/shell/common/settings.sh
@@ -0,0 +1,79 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+#	settings.sh
+#	Author: Michael Petlan <mpetlan@redhat.com>
+#
+#	Description:
+#
+#		This file contains global settings for the whole testsuite.
+#	Its purpose is to make it easier when it is necessary i.e. to
+#	change the usual sample command which is used in all of the tests
+#	in many files.
+#
+#		This file is intended to be sourced in the tests.
+#
+
+#### which perf to use in the testing
+export CMD_PERF=${CMD_PERF:-`which perf`}
+
+#### basic programs examinated by perf
+export CMD_BASIC_SLEEP="sleep 0.1"
+export CMD_QUICK_SLEEP="sleep 0.01"
+export CMD_LONGER_SLEEP="sleep 2"
+export CMD_DOUBLE_LONGER_SLEEP="sleep 4"
+export CMD_VERY_LONG_SLEEP="sleep 30"
+export CMD_SIMPLE="true"
+
+#### testsuite run mode
+# define constants:
+export RUNMODE_BASIC=0
+export RUNMODE_STANDARD=1
+export RUNMODE_EXPERIMENTAL=2
+# default runmode is STANDARD
+export PERFTOOL_TESTSUITE_RUNMODE=${PERFTOOL_TESTSUITE_RUNMODE:-$RUNMODE_STANDARD}
+
+#### common settings
+export TESTLOG_VERBOSITY=${TESTLOG_VERBOSITY:-2}
+export TESTLOG_FORCE_COLOR=${TESTLOG_FORCE_COLOR:-n}
+export TESTLOG_ERR_MSG_MAX_LINES=${TESTLOG_ERR_MSG_MAX_LINES:-20}
+export TESTLOG_CLEAN=${TESTLOG_CLEAN:-y}
+
+#### other environment-related settings
+export TEST_IGNORE_MISSING_PMU=${TEST_IGNORE_MISSING_PMU:-n}
+
+#### clear locale
+export LC_ALL=C
+
+#### colors
+if [ -t 1 -o "$TESTLOG_FORCE_COLOR" = "yes" ]; then
+	export MPASS="\e[32m"
+	export MALLPASS="\e[1;32m"
+	export MFAIL="\e[31m"
+	export MALLFAIL="\e[1;31m"
+	export MWARN="\e[1;35m"
+	export MSKIP="\e[33m"
+	export MHIGH="\e[1;33m"
+	export MEND="\e[m"
+else
+	export MPASS=""
+	export MALLPASS=""
+	export MFAIL=""
+	export MALLFAIL=""
+	export MWARN=""
+	export MSKIP=""
+	export MHIGH=""
+	export MEND=""
+fi
+
+
+#### test parametrization
+if [ ! -d ./common ]; then
+	# set parameters based on runmode
+	if [ -f ../common/parametrization.$PERFTOOL_TESTSUITE_RUNMODE.sh ]; then
+		. ../common/parametrization.$PERFTOOL_TESTSUITE_RUNMODE.sh
+	fi
+	# if some parameters haven't been set until now, set them to default
+	if [ -f ../common/parametrization.sh ]; then
+		. ../common/parametrization.sh
+	fi
+fi
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 3/7] perf testsuite: Add initialization script for shell tests
  2024-01-31 11:39 [PATCH 1/7] perf testsuite: Add common regex patters Michael Petlan
  2024-01-31 11:39 ` [PATCH 2/7] perf testsuite: Add common setting for shell tests Michael Petlan
@ 2024-01-31 11:39 ` Michael Petlan
  2024-01-31 11:39 ` [PATCH 4/7] perf testsuite: Add test case for perf probe Michael Petlan
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-01-31 11:39 UTC (permalink / raw)
  To: linux-perf-users, vmolnaro, acme, acme; +Cc: mhiramat

From: Veronika Molnarova <vmolnaro@redhat.com>

Initialize reporting and logging functions that unifies formatting
of the test output used for shell tests.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/tests/shell/common/init.sh | 117 ++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)
 create mode 100644 tools/perf/tests/shell/common/init.sh

diff --git a/tools/perf/tests/shell/common/init.sh b/tools/perf/tests/shell/common/init.sh
new file mode 100644
index 000000000000..aadeaf782e03
--- /dev/null
+++ b/tools/perf/tests/shell/common/init.sh
@@ -0,0 +1,117 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+#	init.sh
+#	Author: Michael Petlan <mpetlan@redhat.com>
+#
+#	Description:
+#
+#		This file should be used for initialization of basic functions
+#	for checking, reporting results etc.
+#
+#
+
+
+. ../common/settings.sh
+. ../common/patterns.sh
+
+THIS_TEST_NAME=`basename $0 .sh`
+
+_echo()
+{
+	test "$TESTLOG_VERBOSITY" -ne 0 && echo -e "$@"
+}
+
+print_results()
+{
+	PERF_RETVAL="$1"; shift
+	CHECK_RETVAL="$1"; shift
+	FAILURE_REASON=""
+	TASK_COMMENT="$@"
+	if [ $PERF_RETVAL -eq 0 -a $CHECK_RETVAL -eq 0 ]; then
+		_echo "$MPASS-- [ PASS ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT"
+		return 0
+	else
+		if [ $PERF_RETVAL -ne 0 ]; then
+			FAILURE_REASON="command exitcode"
+		fi
+		if [ $CHECK_RETVAL -ne 0 ]; then
+			test -n "$FAILURE_REASON" && FAILURE_REASON="$FAILURE_REASON + "
+			FAILURE_REASON="$FAILURE_REASON""output regexp parsing"
+		fi
+		_echo "$MFAIL-- [ FAIL ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT ($FAILURE_REASON)"
+		return 1
+	fi
+}
+
+print_overall_results()
+{
+	RETVAL="$1"; shift
+	if [ $RETVAL -eq 0 ]; then
+		_echo "$MALLPASS## [ PASS ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME SUMMARY"
+	else
+		_echo "$MALLFAIL## [ FAIL ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME SUMMARY :: $RETVAL failures found"
+	fi
+	return $RETVAL
+}
+
+print_testcase_skipped()
+{
+	TASK_COMMENT="$@"
+	_echo "$MSKIP-- [ SKIP ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT :: testcase skipped"
+	return 0
+}
+
+print_overall_skipped()
+{
+	_echo "$MSKIP## [ SKIP ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME :: testcase skipped"
+	return 0
+}
+
+print_warning()
+{
+	WARN_COMMENT="$@"
+	_echo "$MWARN-- [ WARN ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $WARN_COMMENT"
+	return 0
+}
+
+# this function should skip a testcase if the testsuite is not run in
+# a runmode that fits the testcase --> if the suite runs in BASIC mode
+# all STANDARD and EXPERIMENTAL testcases will be skipped; if the suite
+# runs in STANDARD mode, all EXPERIMENTAL testcases will be skipped and
+# if the suite runs in EXPERIMENTAL mode, nothing is skipped
+consider_skipping()
+{
+	TESTCASE_RUNMODE="$1"
+	# the runmode of a testcase needs to be at least the current suite's runmode
+	if [ $PERFTOOL_TESTSUITE_RUNMODE -lt $TESTCASE_RUNMODE ]; then
+		print_overall_skipped
+		exit 0
+	fi
+}
+
+detect_baremetal()
+{
+	# return values:
+	# 0 = bare metal
+	# 1 = virtualization detected
+	# 2 = unknown state
+	VIRT=`systemd-detect-virt 2>/dev/null`
+	test $? -eq 127 && return 2
+	test "$VIRT" = "none"
+}
+
+detect_intel()
+{
+	# return values:
+	# 0 = is Intel
+	# 1 = is not Intel or unknown
+	grep "vendor_id" < /proc/cpuinfo | grep -q "GenuineIntel"
+}
+
+detect_amd()
+{
+	# return values:
+	# 0 = is AMD
+	# 1 = is not AMD or unknown
+	grep "vendor_id" < /proc/cpuinfo | grep -q "AMD"
+}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 4/7] perf testsuite: Add test case for perf probe
  2024-01-31 11:39 [PATCH 1/7] perf testsuite: Add common regex patters Michael Petlan
  2024-01-31 11:39 ` [PATCH 2/7] perf testsuite: Add common setting for shell tests Michael Petlan
  2024-01-31 11:39 ` [PATCH 3/7] perf testsuite: Add initialization script " Michael Petlan
@ 2024-01-31 11:39 ` Michael Petlan
  2024-01-31 11:39 ` [PATCH 5/7] perf testsuite: Add common output checking helpers Michael Petlan
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-01-31 11:39 UTC (permalink / raw)
  To: linux-perf-users, vmolnaro, acme, acme; +Cc: mhiramat

From: Veronika Molnarova <vmolnaro@redhat.com>

Add new perf probe test case that acts as an entry element in perf test
list. Runs multiple subtests from directory "base_probe", which will be
added in incomming patches and can be expanded without further editing.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 .../tests/shell/perftool-testsuite_probe.sh   | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100755 tools/perf/tests/shell/perftool-testsuite_probe.sh

diff --git a/tools/perf/tests/shell/perftool-testsuite_probe.sh b/tools/perf/tests/shell/perftool-testsuite_probe.sh
new file mode 100755
index 000000000000..84ffa84dc6b1
--- /dev/null
+++ b/tools/perf/tests/shell/perftool-testsuite_probe.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# perftool-testsuite_probe
+# SPDX-License-Identifier: GPL-2.0
+
+test -d "$(dirname $0)/base_probe" || exit 2
+cd "$(dirname $0)/base_probe"
+status=0
+
+export PERFSUITE_RUN_DIR=$(mktemp -d /tmp/$(basename $0 .sh).XXX)
+
+for testcase in setup.sh test_*; do                  # skip setup.sh if not present or not executable
+     test -x $testcase || continue
+     ./$testcase
+     (( status += $? ))
+done
+
+if ! [ "$PERFTEST_KEEP_LOGS" = "y" ]; then
+	rm -rf $PERFSUITE_RUN_DIR
+fi
+
+test $status -ne 0 && exit 1
+exit 0
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 5/7] perf testsuite: Add common output checking helpers
  2024-01-31 11:39 [PATCH 1/7] perf testsuite: Add common regex patters Michael Petlan
                   ` (2 preceding siblings ...)
  2024-01-31 11:39 ` [PATCH 4/7] perf testsuite: Add test case for perf probe Michael Petlan
@ 2024-01-31 11:39 ` Michael Petlan
  2024-01-31 11:39 ` [PATCH 6/7] perf testsuite: Add test for kprobe handling Michael Petlan
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-01-31 11:39 UTC (permalink / raw)
  To: linux-perf-users, vmolnaro, acme, acme; +Cc: mhiramat

From: Veronika Molnarova <vmolnaro@redhat.com>

As a form of validation, it is a common practice to check the outputs
of commands whether they contain expected patterns or match a certain
regex.

Add helpers for verifying that all regexes are found in the output, that
all lines match any pattern from a set and that a certain expression is
not present in the output.

In verbose mode these helpers log mismatches for easier failure
investigation.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 .../shell/common/check_all_lines_matched.pl   | 39 +++++++++++++++++++
 .../shell/common/check_all_patterns_found.pl  | 34 ++++++++++++++++
 .../shell/common/check_no_patterns_found.pl   | 34 ++++++++++++++++
 3 files changed, 107 insertions(+)
 create mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.pl

diff --git a/tools/perf/tests/shell/common/check_all_lines_matched.pl b/tools/perf/tests/shell/common/check_all_lines_matched.pl
new file mode 100755
index 000000000000..fded48959a3f
--- /dev/null
+++ b/tools/perf/tests/shell/common/check_all_lines_matched.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+# SPDX-License-Identifier: GPL-2.0
+
+@regexps = @ARGV;
+
+$max_printed_lines = 20;
+$max_printed_lines = $ENV{TESTLOG_ERR_MSG_MAX_LINES} if (defined $ENV{TESTLOG_ERR_MSG_MAX_LINES});
+
+$quiet = 1;
+$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
+
+$passed = 1;
+$lines_printed = 0;
+
+while (<STDIN>)
+{
+	s/\n//;
+
+	$line_matched = 0;
+	for $r (@regexps)
+	{
+		if (/$r/)
+		{
+			$line_matched = 1;
+			last;
+		}
+	}
+
+	unless ($line_matched)
+	{
+		if ($lines_printed++ < $max_printed_lines)
+		{
+			print "Line did not match any pattern: \"$_\"\n" unless $quiet;
+		}
+		$passed = 0;
+	}
+}
+
+exit ($passed == 0);
diff --git a/tools/perf/tests/shell/common/check_all_patterns_found.pl b/tools/perf/tests/shell/common/check_all_patterns_found.pl
new file mode 100755
index 000000000000..11bdf1d3460a
--- /dev/null
+++ b/tools/perf/tests/shell/common/check_all_patterns_found.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+# SPDX-License-Identifier: GPL-2.0
+
+@regexps = @ARGV;
+
+$quiet = 1;
+$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
+
+%found = ();
+$passed = 1;
+
+while (<STDIN>)
+{
+	s/\n//;
+
+	for $r (@regexps)
+	{
+		if (/$r/)
+		{
+			$found{$r} = 1;	# FIXME: maybe add counters -- how many times was the regexp matched
+		}
+	}
+}
+
+for $r (@regexps)
+{
+	unless (exists $found{$r})
+	{
+		print "Regexp not found: \"$r\"\n" unless $quiet;
+		$passed = 0;
+	}
+}
+
+exit ($passed == 0);
diff --git a/tools/perf/tests/shell/common/check_no_patterns_found.pl b/tools/perf/tests/shell/common/check_no_patterns_found.pl
new file mode 100755
index 000000000000..770999e87a5f
--- /dev/null
+++ b/tools/perf/tests/shell/common/check_no_patterns_found.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+# SPDX-License-Identifier: GPL-2.0
+
+@regexps = @ARGV;
+
+$quiet = 1;
+$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
+
+%found = ();
+$passed = 1;
+
+while (<STDIN>)
+{
+	s/\n//;
+
+	for $r (@regexps)
+	{
+		if (/$r/)
+		{
+			$found{$r} = 1;
+		}
+	}
+}
+
+for $r (@regexps)
+{
+	if (exists $found{$r})
+	{
+		print "Regexp found: \"$r\"\n" unless $quiet;
+		$passed = 0;
+	}
+}
+
+exit ($passed == 0);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 6/7] perf testsuite: Add test for kprobe handling
  2024-01-31 11:39 [PATCH 1/7] perf testsuite: Add common regex patters Michael Petlan
                   ` (3 preceding siblings ...)
  2024-01-31 11:39 ` [PATCH 5/7] perf testsuite: Add common output checking helpers Michael Petlan
@ 2024-01-31 11:39 ` Michael Petlan
  2024-01-31 11:39 ` [PATCH 7/7] perf testsuite: Install kprobe tests and common files Michael Petlan
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-01-31 11:39 UTC (permalink / raw)
  To: linux-perf-users, vmolnaro, acme, acme; +Cc: mhiramat

From: Veronika Molnarova <vmolnaro@redhat.com>

Test perf interface to kprobes: listing, adding and removing probes. It
is run as a part of perftool-testsuite_probe test case.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/tests/shell/base_probe/settings.sh |  48 +++
 .../shell/base_probe/test_adding_kernel.sh    | 277 ++++++++++++++++++
 2 files changed, 325 insertions(+)
 create mode 100644 tools/perf/tests/shell/base_probe/settings.sh
 create mode 100755 tools/perf/tests/shell/base_probe/test_adding_kernel.sh

diff --git a/tools/perf/tests/shell/base_probe/settings.sh b/tools/perf/tests/shell/base_probe/settings.sh
new file mode 100644
index 000000000000..123621c7f95e
--- /dev/null
+++ b/tools/perf/tests/shell/base_probe/settings.sh
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+#	settings.sh of perf_probe test
+#	Author: Michael Petlan <mpetlan@redhat.com>
+#	Author: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
+#
+
+export TEST_NAME="perf_probe"
+
+export MY_ARCH=`arch`
+
+if [ -n "$PERFSUITE_RUN_DIR" ]; then
+	# when $PERFSUITE_RUN_DIR is set to something, all the logs and temp files will be placed there
+	# --> the $PERFSUITE_RUN_DIR/perf_something/examples and $PERFSUITE_RUN_DIR/perf_something/logs
+	#     dirs will be used for that
+	export PERFSUITE_RUN_DIR=`readlink -f $PERFSUITE_RUN_DIR`
+	export CURRENT_TEST_DIR="$PERFSUITE_RUN_DIR/$TEST_NAME"
+	export MAKE_TARGET_DIR="$CURRENT_TEST_DIR/examples"
+	test -d "$MAKE_TARGET_DIR" || mkdir -p "$MAKE_TARGET_DIR"
+	export LOGS_DIR="$PERFSUITE_RUN_DIR/$TEST_NAME/logs"
+	test -d "$LOGS_DIR" || mkdir -p "$LOGS_DIR"
+else
+	# when $PERFSUITE_RUN_DIR is not set, logs will be placed here
+	export CURRENT_TEST_DIR="."
+	export LOGS_DIR="."
+fi
+
+check_kprobes_available()
+{
+	test -e /sys/kernel/debug/tracing/kprobe_events
+}
+
+check_uprobes_available()
+{
+	test -e /sys/kernel/debug/tracing/uprobe_events
+}
+
+clear_all_probes()
+{
+	echo 0 > /sys/kernel/debug/tracing/events/enable
+	check_kprobes_available && echo > /sys/kernel/debug/tracing/kprobe_events
+	check_uprobes_available && echo > /sys/kernel/debug/tracing/uprobe_events
+}
+
+check_sdt_support()
+{
+	$CMD_PERF list sdt | grep sdt > /dev/null 2> /dev/null
+}
diff --git a/tools/perf/tests/shell/base_probe/test_adding_kernel.sh b/tools/perf/tests/shell/base_probe/test_adding_kernel.sh
new file mode 100755
index 000000000000..c3a3fb130e8c
--- /dev/null
+++ b/tools/perf/tests/shell/base_probe/test_adding_kernel.sh
@@ -0,0 +1,277 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+#
+#	test_adding_kernel of perf_probe test
+#	Author: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
+#	Author: Michael Petlan <mpetlan@redhat.com>
+#
+#	Description:
+#
+#		This test tests adding of probes, their correct listing
+#		and removing.
+#
+
+# include working environment
+. ../common/init.sh
+. ./settings.sh
+
+THIS_TEST_NAME=`basename $0 .sh`
+TEST_RESULT=0
+
+TEST_PROBE=${TEST_PROBE:-"inode_permission"}
+
+check_kprobes_available
+if [ $? -ne 0 ]; then
+	print_overall_skipped
+	exit 0
+fi
+
+
+### basic probe adding
+
+for opt in "" "-a" "--add"; do
+	clear_all_probes
+	$CMD_PERF probe $opt $TEST_PROBE 2> $LOGS_DIR/adding_kernel_add$opt.err
+	PERF_EXIT_CODE=$?
+
+	../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_add$opt.err
+	CHECK_EXIT_CODE=$?
+
+	print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "adding probe $TEST_PROBE :: $opt"
+	(( TEST_RESULT += $? ))
+done
+
+
+### listing added probe :: perf list
+
+# any added probes should appear in perf-list output
+$CMD_PERF list probe:\* > $LOGS_DIR/adding_kernel_list.log
+PERF_EXIT_CODE=$?
+
+../common/check_all_lines_matched.pl "$RE_LINE_EMPTY" "List of pre-defined events" "probe:${TEST_PROBE}(?:_\d+)?\s+\[Tracepoint event\]" "Metric Groups:" < $LOGS_DIR/adding_kernel_list.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing added probe :: perf list"
+(( TEST_RESULT += $? ))
+
+
+### listing added probe :: perf probe -l
+
+# '-l' should list all the added probes as well
+$CMD_PERF probe -l > $LOGS_DIR/adding_kernel_list-l.log
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "\s*probe:${TEST_PROBE}(?:_\d+)?\s+\(on ${TEST_PROBE}(?:[:\+]$RE_NUMBER_HEX)?@.+\)" < $LOGS_DIR/adding_kernel_list-l.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing added probe :: perf probe -l"
+(( TEST_RESULT += $? ))
+
+
+### using added probe
+
+$CMD_PERF stat -e probe:$TEST_PROBE\* -o $LOGS_DIR/adding_kernel_using_probe.log -- cat /proc/uptime > /dev/null
+PERF_EXIT_CODE=$?
+
+REGEX_STAT_HEADER="\s*Performance counter stats for \'cat /proc/uptime\':"
+REGEX_STAT_VALUES="\s*\d+\s+probe:$TEST_PROBE"
+# the value should be greater than 1
+REGEX_STAT_VALUE_NONZERO="\s*[1-9][0-9]*\s+probe:$TEST_PROBE"
+REGEX_STAT_TIME="\s*$RE_NUMBER\s+seconds (?:time elapsed|user|sys)"
+../common/check_all_lines_matched.pl "$REGEX_STAT_HEADER" "$REGEX_STAT_VALUES" "$REGEX_STAT_TIME" "$RE_LINE_COMMENT" "$RE_LINE_EMPTY" < $LOGS_DIR/adding_kernel_using_probe.log
+CHECK_EXIT_CODE=$?
+../common/check_all_patterns_found.pl "$REGEX_STAT_HEADER" "$REGEX_STAT_VALUE_NONZERO" "$REGEX_STAT_TIME" < $LOGS_DIR/adding_kernel_using_probe.log
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "using added probe"
+(( TEST_RESULT += $? ))
+
+
+### removing added probe
+
+# '-d' should remove the probe
+$CMD_PERF probe -d $TEST_PROBE\* 2> $LOGS_DIR/adding_kernel_removing.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_lines_matched.pl "Removed event: probe:$TEST_PROBE" < $LOGS_DIR/adding_kernel_removing.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "deleting added probe"
+(( TEST_RESULT += $? ))
+
+
+### listing removed probe
+
+# removed probes should NOT appear in perf-list output
+$CMD_PERF list probe:\* > $LOGS_DIR/adding_kernel_list_removed.log
+PERF_EXIT_CODE=$?
+
+../common/check_all_lines_matched.pl "$RE_LINE_EMPTY" "List of pre-defined events" "Metric Groups:" < $LOGS_DIR/adding_kernel_list_removed.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing removed probe (should NOT be listed)"
+(( TEST_RESULT += $? ))
+
+
+### dry run
+
+# the '-n' switch should run it in dry mode
+$CMD_PERF probe -n --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_dryrun.err
+PERF_EXIT_CODE=$?
+
+# check for the output (should be the same as usual)
+../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_dryrun.err
+CHECK_EXIT_CODE=$?
+
+# check that no probe was added in real
+! ( $CMD_PERF probe -l | grep "probe:$TEST_PROBE" )
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "dry run :: adding probe"
+(( TEST_RESULT += $? ))
+
+
+### force-adding probes
+
+# when using '--force' a probe should be added even if it is already there
+$CMD_PERF probe --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_forceadd_01.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_forceadd_01.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "force-adding probes :: first probe adding"
+(( TEST_RESULT += $? ))
+
+# adding existing probe without '--force' should fail
+! $CMD_PERF probe --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_forceadd_02.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "Error: event \"$TEST_PROBE\" already exists." "Error: Failed to add events." < $LOGS_DIR/adding_kernel_forceadd_02.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "force-adding probes :: second probe adding (without force)"
+(( TEST_RESULT += $? ))
+
+# adding existing probe with '--force' should pass
+NO_OF_PROBES=`$CMD_PERF probe -l | wc -l`
+$CMD_PERF probe --force --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_forceadd_03.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "Added new events?:" "probe:${TEST_PROBE}_${NO_OF_PROBES}" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_forceadd_03.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "force-adding probes :: second probe adding (with force)"
+(( TEST_RESULT += $? ))
+
+
+### using doubled probe
+
+# since they are the same, they should produce the same results
+$CMD_PERF stat -e probe:$TEST_PROBE -e probe:${TEST_PROBE}_${NO_OF_PROBES} -x';' -o $LOGS_DIR/adding_kernel_using_two.log -- bash -c 'cat /proc/cpuinfo > /dev/null'
+PERF_EXIT_CODE=$?
+
+REGEX_LINE="$RE_NUMBER;+probe:${TEST_PROBE}_?(?:$NO_OF_PROBES)?;$RE_NUMBER;$RE_NUMBER"
+../common/check_all_lines_matched.pl "$REGEX_LINE" "$RE_LINE_EMPTY" "$RE_LINE_COMMENT" < $LOGS_DIR/adding_kernel_using_two.log
+CHECK_EXIT_CODE=$?
+
+VALUE_1=`grep "$TEST_PROBE;" $LOGS_DIR/adding_kernel_using_two.log | awk -F';' '{print $1}'`
+VALUE_2=`grep "${TEST_PROBE}_${NO_OF_PROBES};" $LOGS_DIR/adding_kernel_using_two.log | awk -F';' '{print $1}'`
+
+test $VALUE_1 -eq $VALUE_2
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "using doubled probe"
+
+
+### removing multiple probes
+
+# using wildcards should remove all matching probes
+$CMD_PERF probe --del \* 2> $LOGS_DIR/adding_kernel_removing_wildcard.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_lines_matched.pl "Removed event: probe:$TEST_PROBE" "Removed event: probe:${TEST_PROBE}_1" < $LOGS_DIR/adding_kernel_removing_wildcard.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "removing multiple probes"
+(( TEST_RESULT += $? ))
+
+
+### wildcard adding support
+
+$CMD_PERF probe -nf --max-probes=512 -a 'vfs_* $params' 2> $LOGS_DIR/adding_kernel_adding_wildcard.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "probe:vfs_mknod" "probe:vfs_create" "probe:vfs_rmdir" "probe:vfs_link" "probe:vfs_write" < $LOGS_DIR/adding_kernel_adding_wildcard.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "wildcard adding support"
+(( TEST_RESULT += $? ))
+
+
+### non-existing variable
+
+# perf probe should survive a non-existing variable probing attempt
+{ $CMD_PERF probe 'vfs_read somenonexistingrandomstuffwhichisalsoprettylongorevenlongertoexceed64' ; } 2> $LOGS_DIR/adding_kernel_nonexisting.err
+PERF_EXIT_CODE=$?
+
+# the exitcode should not be 0 or segfault
+test $PERF_EXIT_CODE -ne 139 -a $PERF_EXIT_CODE -ne 0
+PERF_EXIT_CODE=$?
+
+# check that the error message is reasonable
+../common/check_all_patterns_found.pl "Failed to find" "somenonexistingrandomstuffwhichisalsoprettylongorevenlongertoexceed64" < $LOGS_DIR/adding_kernel_nonexisting.err
+CHECK_EXIT_CODE=$?
+../common/check_all_patterns_found.pl "in this function|at this address" "Error" "Failed to add events" < $LOGS_DIR/adding_kernel_nonexisting.err
+(( CHECK_EXIT_CODE += $? ))
+../common/check_all_lines_matched.pl "Failed to find" "Error" "Probe point .+ not found" "optimized out" "Use.+\-\-range option to show.+location range" < $LOGS_DIR/adding_kernel_nonexisting.err
+(( CHECK_EXIT_CODE += $? ))
+../common/check_no_patterns_found.pl "$RE_SEGFAULT" < $LOGS_DIR/adding_kernel_nonexisting.err
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "non-existing variable"
+(( TEST_RESULT += $? ))
+
+
+### function with return value
+
+# adding probe with return value
+$CMD_PERF probe --add "$TEST_PROBE%return \$retval" 2> $LOGS_DIR/adding_kernel_func_retval_add.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE%return with \\\$retval" < $LOGS_DIR/adding_kernel_func_retval_add.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "function with retval :: add"
+(( TEST_RESULT += $? ))
+
+# recording some data
+$CMD_PERF record -e probe:$TEST_PROBE\* -o $CURRENT_TEST_DIR/perf.data -- cat /proc/cpuinfo > /dev/null 2> $LOGS_DIR/adding_kernel_func_retval_record.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/adding_kernel_func_retval_record.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "function with retval :: record"
+(( TEST_RESULT += $? ))
+
+# perf script should report the function calls with the correct arg values
+$CMD_PERF script -i $CURRENT_TEST_DIR/perf.data > $LOGS_DIR/adding_kernel_func_retval_script.log
+PERF_EXIT_CODE=$?
+
+REGEX_SCRIPT_LINE="\s*cat\s+$RE_NUMBER\s+\[$RE_NUMBER\]\s+$RE_NUMBER:\s+probe:$TEST_PROBE\w*:\s+\($RE_NUMBER_HEX\s+<\-\s+$RE_NUMBER_HEX\)\s+arg1=$RE_NUMBER_HEX"
+../common/check_all_lines_matched.pl "$REGEX_SCRIPT_LINE" < $LOGS_DIR/adding_kernel_func_retval_script.log
+CHECK_EXIT_CODE=$?
+../common/check_all_patterns_found.pl "$REGEX_SCRIPT_LINE" < $LOGS_DIR/adding_kernel_func_retval_script.log
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "function argument probing :: script"
+(( TEST_RESULT += $? ))
+
+
+clear_all_probes
+
+# print overall results
+print_overall_results "$TEST_RESULT"
+exit $?
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 7/7] perf testsuite: Install kprobe tests and common files
  2024-01-31 11:39 [PATCH 1/7] perf testsuite: Add common regex patters Michael Petlan
                   ` (4 preceding siblings ...)
  2024-01-31 11:39 ` [PATCH 6/7] perf testsuite: Add test for kprobe handling Michael Petlan
@ 2024-01-31 11:39 ` Michael Petlan
  2024-01-31 13:47 ` [PATCH 1/7] perf testsuite: Add common regex patters Arnaldo Carvalho de Melo
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-01-31 11:39 UTC (permalink / raw)
  To: linux-perf-users, vmolnaro, acme, acme; +Cc: mhiramat

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/Makefile.perf | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 058c9aecf608..7811a4385586 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -1029,6 +1029,11 @@ install-tests: all install-gtk
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
 		$(INSTALL) tests/shell/lib/*.sh -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
 		$(INSTALL) tests/shell/lib/*.py -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
+		$(INSTALL) tests/shell/common/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
+		$(INSTALL) tests/shell/common/*.pl '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
+		$(INSTALL) tests/shell/base_probe/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/coresight' ; \
 		$(INSTALL) tests/shell/coresight/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/coresight'
 	$(Q)$(MAKE) -C tests/shell/coresight install-tests
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/7] perf testsuite: Add common regex patters
  2024-01-31 11:39 [PATCH 1/7] perf testsuite: Add common regex patters Michael Petlan
                   ` (5 preceding siblings ...)
  2024-01-31 11:39 ` [PATCH 7/7] perf testsuite: Install kprobe tests and common files Michael Petlan
@ 2024-01-31 13:47 ` Arnaldo Carvalho de Melo
  2024-01-31 13:53   ` Arnaldo Carvalho de Melo
  2024-02-01 23:59   ` Namhyung Kim
  2024-02-02  0:05 ` Namhyung Kim
  2024-02-15 11:02 ` [PATCH v2 0/7] Add perf testsuite into perf-test Michael Petlan
  8 siblings, 2 replies; 23+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-01-31 13:47 UTC (permalink / raw)
  To: Michael Petlan; +Cc: linux-perf-users, vmolnaro, acme, mhiramat

Em Wed, Jan 31, 2024 at 12:39:45PM +0100, Michael Petlan escreveu:
> From: Veronika Molnarova <vmolnaro@redhat.com>
> 
> Unify perf regexes for checking testing output into a single file
> to reduce duplicates and prevent errors when editing.
> 
> This will be used in upcomming patches in shell tests.

Thanks for working on this!

The cover letter could've said that this is an effort to upstream a
pre-existing test suite that is being used for quite a long time, that
it is available in github, etc :-)

- Arnaldo
 
> Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
> ---
>  tools/perf/tests/shell/common/patterns.sh | 256 ++++++++++++++++++++++
>  1 file changed, 256 insertions(+)
>  create mode 100644 tools/perf/tests/shell/common/patterns.sh
> 
> diff --git a/tools/perf/tests/shell/common/patterns.sh b/tools/perf/tests/shell/common/patterns.sh
> new file mode 100644
> index 000000000000..919a07b8b454
> --- /dev/null
> +++ b/tools/perf/tests/shell/common/patterns.sh
> @@ -0,0 +1,256 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +export RE_NUMBER="[0-9\.]+"
> +# Number
> +# Examples:
> +#    123.456
> +
> +
> +export RE_NUMBER_HEX="[0-9A-Fa-f]+"
> +# Hexadecimal number
> +# Examples:
> +#    1234
> +#    a58d
> +#    aBcD
> +#    deadbeef
> +
> +
> +export RE_DATE_YYYYMMDD="[0-9]{4}-(?:(?:01|03|05|07|08|10|12)-(?:[0-2][0-9]|3[0-1])|02-[0-2][0-9]|(?:(?:04|06|09|11)-(?:[0-2][0-9]|30)))"
> +# Date in YYYY-MM-DD form
> +# Examples:
> +#    1990-02-29
> +#    0015-07-31
> +#    2456-12-31
> +#!   2012-13-01
> +#!   1963-09-31
> +
> +
> +export RE_TIME="(?:[0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]"
> +# Time
> +# Examples:
> +#    15:12:27
> +#    23:59:59
> +#!   24:00:00
> +#!   11:25:60
> +#!   17:60:15
> +
> +
> +export RE_DATE_TIME="\w+\s+\w+\s+$RE_NUMBER\s+$RE_TIME\s+$RE_NUMBER"
> +# Time and date
> +# Examples:
> +#    Wed Feb 12 10:46:26 2020
> +#    Mon Mar  2 13:27:06 2020
> +#!   St úno 12 10:57:21 CET 2020
> +#!   Po úno 14 15:17:32 2010
> +
> +
> +export RE_ADDRESS="0x$RE_NUMBER_HEX"
> +# Memory address
> +# Examples:
> +#    0x123abc
> +#    0xffffffff9abe8ae8
> +#    0x0
> +
> +
> +export RE_ADDRESS_NOT_NULL="0x[0-9A-Fa-f]*[1-9A-Fa-f]+[0-9A-Fa-f]*"
> +# Memory address (not NULL)
> +# Examples:
> +#    0xffffffff9abe8ae8
> +#!   0x0
> +#!   0x0000000000000000
> +
> +export RE_PROCESS_PID="\w+\/\d+"
> +# A process with PID
> +# Example:
> +#    sleep/4102
> +
> +
> +export RE_EVENT_ANY="[\w\-\:\/_=,]+"
> +# Name of any event (universal)
> +# Examples:
> +#    cpu-cycles
> +#    cpu/event=12,umask=34/
> +#    r41e1
> +#    nfs:nfs_getattr_enter
> +
> +
> +export RE_EVENT="[\w\-:_]+"
> +# Name of an usual event
> +# Examples:
> +#    cpu-cycles
> +
> +
> +export RE_EVENT_RAW="r$RE_NUMBER_HEX"
> +# Specification of a raw event
> +# Examples:
> +#    r41e1
> +#    r1a
> +
> +
> +export RE_EVENT_CPU="cpu/(\w+=$RE_NUMBER_HEX,?)+/p*"
> +# Specification of a CPU event
> +# Examples:
> +#    cpu/event=12,umask=34/pp
> +
> +
> +export RE_EVENT_UNCORE="uncore/[\w_]+/"
> +# Specification of an uncore event
> +# Examples:
> +#    uncore/qhl_request_local_reads/
> +
> +
> +export RE_EVENT_SUBSYSTEM="[\w\-]+:[\w\-]+"
> +# Name of an event from subsystem
> +# Examples:
> +#    ext4:ext4_ordered_write_end
> +#    sched:sched_switch
> +
> +
> +export RE_FILE_NAME="[\w\+\.-]+"
> +# A filename
> +# Examples:
> +#    libstdc++.so.6
> +#!   some/path
> +
> +
> +export RE_PATH_ABSOLUTE="(?:\/$RE_FILE_NAME)+"
> +# A full filepath
> +# Examples:
> +#    /usr/lib64/somelib.so.5.4.0
> +#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
> +#    /usr/bin/mv
> +#!   some/relative/path
> +#!   ./some/relative/path
> +
> +
> +export RE_PATH="(?:$RE_FILE_NAME)?$RE_PATH_ABSOLUTE"
> +# A filepath
> +# Examples:
> +#    /usr/lib64/somelib.so.5.4.0
> +#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
> +#    ./.emacs
> +#    src/fs/file.c
> +
> +
> +export RE_DSO="(?:$RE_PATH_ABSOLUTE(?: \(deleted\))?|\[kernel\.kallsyms\]|\[unknown\]|\[vdso\]|\[kernel\.vmlinux\][\.\w]*)"
> +# A DSO name in various result tables
> +# Examples:
> +#    /usr/lib64/somelib.so.5.4.0
> +#    /usr/bin/somebinart (deleted)
> +#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
> +#    [kernel.kallsyms]
> +#    [kernel.vmlinux]
> +#    [vdso]
> +#    [unknown]
> +
> +
> +export RE_LINE_COMMENT="^#.*"
> +# A comment line
> +# Examples:
> +#    # Started on Thu Sep 10 11:43:00 2015
> +
> +
> +export RE_LINE_EMPTY="^\s*$"
> +# An empty line with possible whitespaces
> +# Examples:
> +#
> +
> +
> +export RE_LINE_RECORD1="^\[\s+perf\s+record:\s+Woken up $RE_NUMBER times? to write data\s+\].*$"
> +# The first line of perf-record "OK" output
> +# Examples:
> +#    [ perf record: Woken up 1 times to write data ]
> +
> +
> +export RE_LINE_RECORD2="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\.data(?:\.\d+)?\s*\(~?$RE_NUMBER samples\)\s+\].*$"
> +# The second line of perf-record "OK" output
> +# Examples:
> +#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB perf.data (~109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/perf.data (109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB ./perf.data (109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB ./perf.data.3 (109 samples) ]
> +
> +
> +export RE_LINE_RECORD2_TOLERANT="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\.data(?:\.\d+)?\s*(?:\(~?$RE_NUMBER samples\))?\s+\].*$"
> +# The second line of perf-record "OK" output, even no samples is OK here
> +# Examples:
> +#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB perf.data (~109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/perf.data (109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB ./perf.data (109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB ./perf.data.3 (109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB perf.data ]
> +
> +
> +export RE_LINE_RECORD2_TOLERANT_FILENAME="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\w*\.data(?:\.\d+)?\s*\(~?$RE_NUMBER samples\)\s+\].*$"
> +# The second line of perf-record "OK" output
> +# Examples:
> +#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB perf_ls.data (~109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB perf_aNyCaSe.data (109 samples) ]
> +#    [ perf record: Captured and wrote 0.405 MB ./perfdata.data.3 (109 samples) ]
> +#!    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/my_own.data (109 samples) ]
> +#!    [ perf record: Captured and wrote 0.405 MB ./UPPERCASE.data (109 samples) ]
> +#!    [ perf record: Captured and wrote 0.405 MB ./aNyKiNDoF.data.3 (109 samples) ]
> +#!    [ perf record: Captured and wrote 0.405 MB perf.data ]
> +
> +
> +export RE_LINE_TRACE_FULL="^\s*$RE_NUMBER\s*\(\s*$RE_NUMBER\s*ms\s*\):\s*$RE_PROCESS_PID\s+.*\)\s+=\s+\-?$RE_NUMBER|$RE_NUMBER_HEX.*$"
> +# A line of perf-trace output
> +# Examples:
> +#    0.115 ( 0.005 ms): sleep/4102 open(filename: 0xd09e2ab2, flags: CLOEXEC                             ) = 3
> +#    0.157 ( 0.005 ms): sleep/4102 mmap(len: 3932736, prot: EXEC|READ, flags: PRIVATE|DENYWRITE, fd: 3   ) = 0x7f89d0605000
> +
> +export RE_LINE_TRACE_ONE_PROC="^\s*$RE_NUMBER\s*\(\s*$RE_NUMBER\s*ms\s*\):\s*\w+\(.*\)\s+=\s+(?:\-?$RE_NUMBER)|(?:0x$RE_NUMBER_HEX).*$"
> +# A line of perf-trace output
> +# Examples:
> +#    0.115 ( 0.005 ms): open(filename: 0xd09e2ab2, flags: CLOEXEC                             ) = 3
> +#    0.157 ( 0.005 ms): mmap(len: 3932736, prot: EXEC|READ, flags: PRIVATE|DENYWRITE, fd: 3   ) = 0x7f89d0605000
> +
> +export RE_LINE_TRACE_CONTINUED="^\s*$RE_NUMBER\s*\(\s*$RE_NUMBER\s*ms\s*\):\s*\.\.\.\s*\[continued\]:\s+\w+\(\).*\s+=\s+(?:\-?$RE_NUMBER)|(?:0x$RE_NUMBER_HEX).*$"
> +# A line of perf-trace output
> +# Examples:
> +#    0.000 ( 0.000 ms):  ... [continued]: nanosleep()) = 0
> +#    0.000 ( 0.000 ms):  ... [continued]: nanosleep()) = 0x00000000
> +
> +export RE_LINE_TRACE_SUMMARY_HEADER="\s*syscall\s+calls\s+(?:errors\s+)?total\s+min\s+avg\s+max\s+stddev"
> +# A header of a perf-trace summary table
> +# Example:
> +#    syscall            calls    total       min       avg       max      stddev
> +#    syscall            calls  errors  total       min       avg       max       stddev
> +
> +
> +export RE_LINE_TRACE_SUMMARY_CONTENT="^\s*\w+\s+(?:$RE_NUMBER\s+){5,6}$RE_NUMBER%"
> +# A line of a perf-trace summary table
> +# Example:
> +#    open                   3     0.017     0.005     0.006     0.007     10.90%
> +#    openat                 2      0     0.017     0.008     0.009     0.010     12.29%
> +
> +
> +export RE_LINE_REPORT_CONTENT="^\s+$RE_NUMBER%\s+\w+\s+\S+\s+\S+\s+\S+" # FIXME
> +# A line from typicap perf report --stdio output
> +# Example:
> +#     100.00%  sleep    [kernel.vmlinux]  [k] syscall_return_slowpath
> +
> +
> +export RE_TASK="\s+[\w~\/ \.\+:#-]+(?:\[-1(?:\/\d+)?\]|\[\d+(?:\/\d+)?\])"
> +# A name of a task used for perf sched timehist -s
> +# Example:
> +#     sleep[62755]
> +#     runtest.sh[62762]
> +#     gmain[705/682]
> +#     xfsaild/dm-0[495]
> +#     kworker/u8:1-ev[62714]
> +#     :-1[-1/62756]
> +#     :-1[-1]
> +#     :-1[62756]
> +
> +
> +export RE_SEGFAULT=".*(?:Segmentation\sfault|SIGSEGV|\score\s|dumped|segfault).*"
> +# Possible variations of the segfault message
> +# Example:
> +#     /bin/bash: line 1:    32 Segmentation fault      timeout 15s
> +#     Segmentation fault (core dumped)
> +#     Program terminated with signal SIGSEGV
> +#!     WARNING: 12323431 isn't a 'cpu_core', please use a CPU list in the 'cpu_core' range (0-15)
> -- 
> 2.43.0
> 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/7] perf testsuite: Add common regex patters
  2024-01-31 13:47 ` [PATCH 1/7] perf testsuite: Add common regex patters Arnaldo Carvalho de Melo
@ 2024-01-31 13:53   ` Arnaldo Carvalho de Melo
  2024-02-01 23:59   ` Namhyung Kim
  1 sibling, 0 replies; 23+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-01-31 13:53 UTC (permalink / raw)
  To: Michael Petlan
  Cc: linux-perf-users, Veronika Molnarova, acme, mhiramat,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Athira Rajeev, Kajol Jain,
	linux-kernel

Em Wed, Jan 31, 2024 at 10:47:23AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Jan 31, 2024 at 12:39:45PM +0100, Michael Petlan escreveu:
> > From: Veronika Molnarova <vmolnaro@redhat.com>

> > Unify perf regexes for checking testing output into a single file
> > to reduce duplicates and prevent errors when editing.

> > This will be used in upcomming patches in shell tests.

> Thanks for working on this!
 
> The cover letter could've said that this is an effort to upstream a
> pre-existing test suite that is being used for quite a long time, that
> it is available in github, etc :-)

Also it should CC the perf tools reviewers and maintainers:

⬢[acme@toolbox perf-tools]$ scripts/get_maintainer.pl tools/perf/tests/shell/
Peter Zijlstra <peterz@infradead.org> (supporter:PERFORMANCE EVENTS SUBSYSTEM)
Ingo Molnar <mingo@redhat.com> (supporter:PERFORMANCE EVENTS SUBSYSTEM)
Arnaldo Carvalho de Melo <acme@kernel.org> (supporter:PERFORMANCE EVENTS SUBSYSTEM,commit_signer:101/122=83%)
Namhyung Kim <namhyung@kernel.org> (supporter:PERFORMANCE EVENTS SUBSYSTEM,commit_signer:40/122=33%,authored:13/122=11%)
Mark Rutland <mark.rutland@arm.com> (reviewer:PERFORMANCE EVENTS SUBSYSTEM)
Alexander Shishkin <alexander.shishkin@linux.intel.com> (reviewer:PERFORMANCE EVENTS SUBSYSTEM)
Jiri Olsa <jolsa@kernel.org> (reviewer:PERFORMANCE EVENTS SUBSYSTEM)
Ian Rogers <irogers@google.com> (reviewer:PERFORMANCE EVENTS SUBSYSTEM,commit_signer:66/122=54%,authored:17/122=14%)
Adrian Hunter <adrian.hunter@intel.com> (reviewer:PERFORMANCE EVENTS SUBSYSTEM,authored:8/122=7%)
Athira Rajeev <atrajeev@linux.vnet.ibm.com> (commit_signer:50/122=41%,authored:20/122=16%)
Kajol Jain <kjain@linux.ibm.com> (commit_signer:31/122=25%,authored:10/122=8%)
linux-perf-users@vger.kernel.org (open list:PERFORMANCE EVENTS SUBSYSTEM)
linux-kernel@vger.kernel.org (open list:PERFORMANCE EVENTS SUBSYSTEM)
⬢[acme@toolbox perf-tools]$

For reviewers, the series of patches can be accessed via the
linux-perf-users mail archive at:

https://lore.kernel.org/linux-perf-users/ZbpPa1ZjoOdGw9Yd@kernel.org/

There are many, many tests in Michael's test suite, its super great that
this work is being done so that people using 'perf test' will have a far
greater tool testing coverage,

Again, thanks a lot!
 
- Arnaldo
  
> > Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
> > Signed-off-by: Michael Petlan <mpetlan@redhat.com>
> > ---
> >  tools/perf/tests/shell/common/patterns.sh | 256 ++++++++++++++++++++++
> >  1 file changed, 256 insertions(+)
> >  create mode 100644 tools/perf/tests/shell/common/patterns.sh
> > 
> > diff --git a/tools/perf/tests/shell/common/patterns.sh b/tools/perf/tests/shell/common/patterns.sh
> > new file mode 100644
> > index 000000000000..919a07b8b454
> > --- /dev/null
> > +++ b/tools/perf/tests/shell/common/patterns.sh
> > @@ -0,0 +1,256 @@
> > +# SPDX-License-Identifier: GPL-2.0
> > +
> > +export RE_NUMBER="[0-9\.]+"
> > +# Number
> > +# Examples:
> > +#    123.456
> > +
> > +
> > +export RE_NUMBER_HEX="[0-9A-Fa-f]+"
> > +# Hexadecimal number
> > +# Examples:
> > +#    1234
> > +#    a58d
> > +#    aBcD
> > +#    deadbeef
> > +
> > +
> > +export RE_DATE_YYYYMMDD="[0-9]{4}-(?:(?:01|03|05|07|08|10|12)-(?:[0-2][0-9]|3[0-1])|02-[0-2][0-9]|(?:(?:04|06|09|11)-(?:[0-2][0-9]|30)))"
> > +# Date in YYYY-MM-DD form
> > +# Examples:
> > +#    1990-02-29
> > +#    0015-07-31
> > +#    2456-12-31
> > +#!   2012-13-01
> > +#!   1963-09-31
> > +
> > +
> > +export RE_TIME="(?:[0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]"
> > +# Time
> > +# Examples:
> > +#    15:12:27
> > +#    23:59:59
> > +#!   24:00:00
> > +#!   11:25:60
> > +#!   17:60:15
> > +
> > +
> > +export RE_DATE_TIME="\w+\s+\w+\s+$RE_NUMBER\s+$RE_TIME\s+$RE_NUMBER"
> > +# Time and date
> > +# Examples:
> > +#    Wed Feb 12 10:46:26 2020
> > +#    Mon Mar  2 13:27:06 2020
> > +#!   St úno 12 10:57:21 CET 2020
> > +#!   Po úno 14 15:17:32 2010
> > +
> > +
> > +export RE_ADDRESS="0x$RE_NUMBER_HEX"
> > +# Memory address
> > +# Examples:
> > +#    0x123abc
> > +#    0xffffffff9abe8ae8
> > +#    0x0
> > +
> > +
> > +export RE_ADDRESS_NOT_NULL="0x[0-9A-Fa-f]*[1-9A-Fa-f]+[0-9A-Fa-f]*"
> > +# Memory address (not NULL)
> > +# Examples:
> > +#    0xffffffff9abe8ae8
> > +#!   0x0
> > +#!   0x0000000000000000
> > +
> > +export RE_PROCESS_PID="\w+\/\d+"
> > +# A process with PID
> > +# Example:
> > +#    sleep/4102
> > +
> > +
> > +export RE_EVENT_ANY="[\w\-\:\/_=,]+"
> > +# Name of any event (universal)
> > +# Examples:
> > +#    cpu-cycles
> > +#    cpu/event=12,umask=34/
> > +#    r41e1
> > +#    nfs:nfs_getattr_enter
> > +
> > +
> > +export RE_EVENT="[\w\-:_]+"
> > +# Name of an usual event
> > +# Examples:
> > +#    cpu-cycles
> > +
> > +
> > +export RE_EVENT_RAW="r$RE_NUMBER_HEX"
> > +# Specification of a raw event
> > +# Examples:
> > +#    r41e1
> > +#    r1a
> > +
> > +
> > +export RE_EVENT_CPU="cpu/(\w+=$RE_NUMBER_HEX,?)+/p*"
> > +# Specification of a CPU event
> > +# Examples:
> > +#    cpu/event=12,umask=34/pp
> > +
> > +
> > +export RE_EVENT_UNCORE="uncore/[\w_]+/"
> > +# Specification of an uncore event
> > +# Examples:
> > +#    uncore/qhl_request_local_reads/
> > +
> > +
> > +export RE_EVENT_SUBSYSTEM="[\w\-]+:[\w\-]+"
> > +# Name of an event from subsystem
> > +# Examples:
> > +#    ext4:ext4_ordered_write_end
> > +#    sched:sched_switch
> > +
> > +
> > +export RE_FILE_NAME="[\w\+\.-]+"
> > +# A filename
> > +# Examples:
> > +#    libstdc++.so.6
> > +#!   some/path
> > +
> > +
> > +export RE_PATH_ABSOLUTE="(?:\/$RE_FILE_NAME)+"
> > +# A full filepath
> > +# Examples:
> > +#    /usr/lib64/somelib.so.5.4.0
> > +#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
> > +#    /usr/bin/mv
> > +#!   some/relative/path
> > +#!   ./some/relative/path
> > +
> > +
> > +export RE_PATH="(?:$RE_FILE_NAME)?$RE_PATH_ABSOLUTE"
> > +# A filepath
> > +# Examples:
> > +#    /usr/lib64/somelib.so.5.4.0
> > +#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
> > +#    ./.emacs
> > +#    src/fs/file.c
> > +
> > +
> > +export RE_DSO="(?:$RE_PATH_ABSOLUTE(?: \(deleted\))?|\[kernel\.kallsyms\]|\[unknown\]|\[vdso\]|\[kernel\.vmlinux\][\.\w]*)"
> > +# A DSO name in various result tables
> > +# Examples:
> > +#    /usr/lib64/somelib.so.5.4.0
> > +#    /usr/bin/somebinart (deleted)
> > +#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
> > +#    [kernel.kallsyms]
> > +#    [kernel.vmlinux]
> > +#    [vdso]
> > +#    [unknown]
> > +
> > +
> > +export RE_LINE_COMMENT="^#.*"
> > +# A comment line
> > +# Examples:
> > +#    # Started on Thu Sep 10 11:43:00 2015
> > +
> > +
> > +export RE_LINE_EMPTY="^\s*$"
> > +# An empty line with possible whitespaces
> > +# Examples:
> > +#
> > +
> > +
> > +export RE_LINE_RECORD1="^\[\s+perf\s+record:\s+Woken up $RE_NUMBER times? to write data\s+\].*$"
> > +# The first line of perf-record "OK" output
> > +# Examples:
> > +#    [ perf record: Woken up 1 times to write data ]
> > +
> > +
> > +export RE_LINE_RECORD2="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\.data(?:\.\d+)?\s*\(~?$RE_NUMBER samples\)\s+\].*$"
> > +# The second line of perf-record "OK" output
> > +# Examples:
> > +#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB perf.data (~109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/perf.data (109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB ./perf.data (109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB ./perf.data.3 (109 samples) ]
> > +
> > +
> > +export RE_LINE_RECORD2_TOLERANT="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\.data(?:\.\d+)?\s*(?:\(~?$RE_NUMBER samples\))?\s+\].*$"
> > +# The second line of perf-record "OK" output, even no samples is OK here
> > +# Examples:
> > +#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB perf.data (~109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/perf.data (109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB ./perf.data (109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB ./perf.data.3 (109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB perf.data ]
> > +
> > +
> > +export RE_LINE_RECORD2_TOLERANT_FILENAME="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\w*\.data(?:\.\d+)?\s*\(~?$RE_NUMBER samples\)\s+\].*$"
> > +# The second line of perf-record "OK" output
> > +# Examples:
> > +#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB perf_ls.data (~109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB perf_aNyCaSe.data (109 samples) ]
> > +#    [ perf record: Captured and wrote 0.405 MB ./perfdata.data.3 (109 samples) ]
> > +#!    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/my_own.data (109 samples) ]
> > +#!    [ perf record: Captured and wrote 0.405 MB ./UPPERCASE.data (109 samples) ]
> > +#!    [ perf record: Captured and wrote 0.405 MB ./aNyKiNDoF.data.3 (109 samples) ]
> > +#!    [ perf record: Captured and wrote 0.405 MB perf.data ]
> > +
> > +
> > +export RE_LINE_TRACE_FULL="^\s*$RE_NUMBER\s*\(\s*$RE_NUMBER\s*ms\s*\):\s*$RE_PROCESS_PID\s+.*\)\s+=\s+\-?$RE_NUMBER|$RE_NUMBER_HEX.*$"
> > +# A line of perf-trace output
> > +# Examples:
> > +#    0.115 ( 0.005 ms): sleep/4102 open(filename: 0xd09e2ab2, flags: CLOEXEC                             ) = 3
> > +#    0.157 ( 0.005 ms): sleep/4102 mmap(len: 3932736, prot: EXEC|READ, flags: PRIVATE|DENYWRITE, fd: 3   ) = 0x7f89d0605000
> > +
> > +export RE_LINE_TRACE_ONE_PROC="^\s*$RE_NUMBER\s*\(\s*$RE_NUMBER\s*ms\s*\):\s*\w+\(.*\)\s+=\s+(?:\-?$RE_NUMBER)|(?:0x$RE_NUMBER_HEX).*$"
> > +# A line of perf-trace output
> > +# Examples:
> > +#    0.115 ( 0.005 ms): open(filename: 0xd09e2ab2, flags: CLOEXEC                             ) = 3
> > +#    0.157 ( 0.005 ms): mmap(len: 3932736, prot: EXEC|READ, flags: PRIVATE|DENYWRITE, fd: 3   ) = 0x7f89d0605000
> > +
> > +export RE_LINE_TRACE_CONTINUED="^\s*$RE_NUMBER\s*\(\s*$RE_NUMBER\s*ms\s*\):\s*\.\.\.\s*\[continued\]:\s+\w+\(\).*\s+=\s+(?:\-?$RE_NUMBER)|(?:0x$RE_NUMBER_HEX).*$"
> > +# A line of perf-trace output
> > +# Examples:
> > +#    0.000 ( 0.000 ms):  ... [continued]: nanosleep()) = 0
> > +#    0.000 ( 0.000 ms):  ... [continued]: nanosleep()) = 0x00000000
> > +
> > +export RE_LINE_TRACE_SUMMARY_HEADER="\s*syscall\s+calls\s+(?:errors\s+)?total\s+min\s+avg\s+max\s+stddev"
> > +# A header of a perf-trace summary table
> > +# Example:
> > +#    syscall            calls    total       min       avg       max      stddev
> > +#    syscall            calls  errors  total       min       avg       max       stddev
> > +
> > +
> > +export RE_LINE_TRACE_SUMMARY_CONTENT="^\s*\w+\s+(?:$RE_NUMBER\s+){5,6}$RE_NUMBER%"
> > +# A line of a perf-trace summary table
> > +# Example:
> > +#    open                   3     0.017     0.005     0.006     0.007     10.90%
> > +#    openat                 2      0     0.017     0.008     0.009     0.010     12.29%
> > +
> > +
> > +export RE_LINE_REPORT_CONTENT="^\s+$RE_NUMBER%\s+\w+\s+\S+\s+\S+\s+\S+" # FIXME
> > +# A line from typicap perf report --stdio output
> > +# Example:
> > +#     100.00%  sleep    [kernel.vmlinux]  [k] syscall_return_slowpath
> > +
> > +
> > +export RE_TASK="\s+[\w~\/ \.\+:#-]+(?:\[-1(?:\/\d+)?\]|\[\d+(?:\/\d+)?\])"
> > +# A name of a task used for perf sched timehist -s
> > +# Example:
> > +#     sleep[62755]
> > +#     runtest.sh[62762]
> > +#     gmain[705/682]
> > +#     xfsaild/dm-0[495]
> > +#     kworker/u8:1-ev[62714]
> > +#     :-1[-1/62756]
> > +#     :-1[-1]
> > +#     :-1[62756]
> > +
> > +
> > +export RE_SEGFAULT=".*(?:Segmentation\sfault|SIGSEGV|\score\s|dumped|segfault).*"
> > +# Possible variations of the segfault message
> > +# Example:
> > +#     /bin/bash: line 1:    32 Segmentation fault      timeout 15s
> > +#     Segmentation fault (core dumped)
> > +#     Program terminated with signal SIGSEGV
> > +#!     WARNING: 12323431 isn't a 'cpu_core', please use a CPU list in the 'cpu_core' range (0-15)
> > -- 
> > 2.43.0
> > 
> 
> -- 
> 
> - Arnaldo

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/7] perf testsuite: Add common regex patters
  2024-01-31 13:47 ` [PATCH 1/7] perf testsuite: Add common regex patters Arnaldo Carvalho de Melo
  2024-01-31 13:53   ` Arnaldo Carvalho de Melo
@ 2024-02-01 23:59   ` Namhyung Kim
  1 sibling, 0 replies; 23+ messages in thread
From: Namhyung Kim @ 2024-02-01 23:59 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Michael Petlan, linux-perf-users, vmolnaro, acme, mhiramat

Hello,

On Wed, Jan 31, 2024 at 5:47 AM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> Em Wed, Jan 31, 2024 at 12:39:45PM +0100, Michael Petlan escreveu:
> > From: Veronika Molnarova <vmolnaro@redhat.com>
> >
> > Unify perf regexes for checking testing output into a single file
> > to reduce duplicates and prevent errors when editing.
> >
> > This will be used in upcomming patches in shell tests.
>
> Thanks for working on this!
>
> The cover letter could've said that this is an effort to upstream a
> pre-existing test suite that is being used for quite a long time, that
> it is available in github, etc :-)

Yep, in general, you'd better have a cover letter when you have
a patch series including more than 5 patches.

Anyway, thanks for your work!

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/7] perf testsuite: Add common regex patters
  2024-01-31 11:39 [PATCH 1/7] perf testsuite: Add common regex patters Michael Petlan
                   ` (6 preceding siblings ...)
  2024-01-31 13:47 ` [PATCH 1/7] perf testsuite: Add common regex patters Arnaldo Carvalho de Melo
@ 2024-02-02  0:05 ` Namhyung Kim
  2024-02-08 16:49   ` Michael Petlan
  2024-02-15 11:02 ` [PATCH v2 0/7] Add perf testsuite into perf-test Michael Petlan
  8 siblings, 1 reply; 23+ messages in thread
From: Namhyung Kim @ 2024-02-02  0:05 UTC (permalink / raw)
  To: Michael Petlan; +Cc: linux-perf-users, vmolnaro, acme, acme, mhiramat

On Wed, Jan 31, 2024 at 3:42 AM Michael Petlan <mpetlan@redhat.com> wrote:
>
> From: Veronika Molnarova <vmolnaro@redhat.com>
>
> Unify perf regexes for checking testing output into a single file
> to reduce duplicates and prevent errors when editing.
>
> This will be used in upcomming patches in shell tests.
>
> Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
> ---
>  tools/perf/tests/shell/common/patterns.sh | 256 ++++++++++++++++++++++
>  1 file changed, 256 insertions(+)
>  create mode 100644 tools/perf/tests/shell/common/patterns.sh
>
> diff --git a/tools/perf/tests/shell/common/patterns.sh b/tools/perf/tests/shell/common/patterns.sh
> new file mode 100644
> index 000000000000..919a07b8b454
> --- /dev/null
> +++ b/tools/perf/tests/shell/common/patterns.sh

We have tests/shell/lib directory, maybe better to put this there.
But maybe we can move it later once we apply the series.


> @@ -0,0 +1,256 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +export RE_NUMBER="[0-9\.]+"
> +# Number
> +# Examples:
> +#    123.456
> +
> +
> +export RE_NUMBER_HEX="[0-9A-Fa-f]+"
> +# Hexadecimal number
> +# Examples:
> +#    1234
> +#    a58d
> +#    aBcD
> +#    deadbeef
> +
> +
> +export RE_DATE_YYYYMMDD="[0-9]{4}-(?:(?:01|03|05|07|08|10|12)-(?:[0-2][0-9]|3[0-1])|02-[0-2][0-9]|(?:(?:04|06|09|11)-(?:[0-2][0-9]|30)))"
> +# Date in YYYY-MM-DD form
> +# Examples:
> +#    1990-02-29
> +#    0015-07-31
> +#    2456-12-31
> +#!   2012-13-01
> +#!   1963-09-31
> +
> +
> +export RE_TIME="(?:[0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]"
> +# Time
> +# Examples:
> +#    15:12:27
> +#    23:59:59
> +#!   24:00:00
> +#!   11:25:60
> +#!   17:60:15
> +
> +
> +export RE_DATE_TIME="\w+\s+\w+\s+$RE_NUMBER\s+$RE_TIME\s+$RE_NUMBER"
> +# Time and date
> +# Examples:
> +#    Wed Feb 12 10:46:26 2020
> +#    Mon Mar  2 13:27:06 2020
> +#!   St úno 12 10:57:21 CET 2020
> +#!   Po úno 14 15:17:32 2010
> +
> +
> +export RE_ADDRESS="0x$RE_NUMBER_HEX"
> +# Memory address
> +# Examples:
> +#    0x123abc
> +#    0xffffffff9abe8ae8
> +#    0x0
> +
> +
> +export RE_ADDRESS_NOT_NULL="0x[0-9A-Fa-f]*[1-9A-Fa-f]+[0-9A-Fa-f]*"
> +# Memory address (not NULL)
> +# Examples:
> +#    0xffffffff9abe8ae8
> +#!   0x0
> +#!   0x0000000000000000
> +
> +export RE_PROCESS_PID="\w+\/\d+"

I'm afraid the process name can have spaces like
"my proc A/9876".

Thanks,
Namhyung


> +# A process with PID
> +# Example:
> +#    sleep/4102
> +

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/7] perf testsuite: Add common regex patters
  2024-02-02  0:05 ` Namhyung Kim
@ 2024-02-08 16:49   ` Michael Petlan
  2024-02-09  7:13     ` Namhyung Kim
  0 siblings, 1 reply; 23+ messages in thread
From: Michael Petlan @ 2024-02-08 16:49 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: linux-perf-users, vmolnaro, acme, acme, mhiramat

[-- Attachment #1: Type: text/plain, Size: 2194 bytes --]

On Thu, 1 Feb 2024, Namhyung Kim wrote:
> On Wed, Jan 31, 2024 at 3:42 AM Michael Petlan <mpetlan@redhat.com> wrote:
> >
> > From: Veronika Molnarova <vmolnaro@redhat.com>
> >
> > Unify perf regexes for checking testing output into a single file
> > to reduce duplicates and prevent errors when editing.
> >
> > This will be used in upcomming patches in shell tests.
> >
> > Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
> > Signed-off-by: Michael Petlan <mpetlan@redhat.com>
> > ---
> >  tools/perf/tests/shell/common/patterns.sh | 256 ++++++++++++++++++++++
> >  1 file changed, 256 insertions(+)
> >  create mode 100644 tools/perf/tests/shell/common/patterns.sh
> >
> > diff --git a/tools/perf/tests/shell/common/patterns.sh b/tools/perf/tests/shell/common/patterns.sh
> > new file mode 100644
> > index 000000000000..919a07b8b454
> > --- /dev/null
> > +++ b/tools/perf/tests/shell/common/patterns.sh
> 
> We have tests/shell/lib directory, maybe better to put this there.
> But maybe we can move it later once we apply the series.

Yes, in case the testsuite gets accepted, I plan to work further
on the integration with the current shell test set, in order to
unify the configuration, output, logging, etc. So, I'd prefer to
merge the directories later.
> 
> > @@ -0,0 +1,256 @@
> > +# SPDX-License-Identifier: GPL-2.0
> > +
[...]

> > +export RE_ADDRESS_NOT_NULL="0x[0-9A-Fa-f]*[1-9A-Fa-f]+[0-9A-Fa-f]*"
> > +# Memory address (not NULL)
> > +# Examples:
> > +#    0xffffffff9abe8ae8
> > +#!   0x0
> > +#!   0x0000000000000000
> > +
> > +export RE_PROCESS_PID="\w+\/\d+"
> 
> I'm afraid the process name can have spaces like
> "my proc A/9876".
> 
> Thanks,
> Namhyung
> 
Good catch! Theoretically yes. It is not used yet (perf-trace tests use
this regexp; we aim to post the rest of the testsuite later). However,
looking at the perf-trace testcase, it runs also `perf trace -a`, so
if there are any processes with non-standard name, they would appear
there. But that's not only space, but also other characters, like '+',
etc. We will try to fix this to match any valid process name. Thanks.

Michael
> > +# A process with PID
> > +# Example:
> > +#    sleep/4102
> > +
> 
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/7] perf testsuite: Add common regex patters
  2024-02-08 16:49   ` Michael Petlan
@ 2024-02-09  7:13     ` Namhyung Kim
  2024-02-09 22:56       ` Namhyung Kim
  0 siblings, 1 reply; 23+ messages in thread
From: Namhyung Kim @ 2024-02-09  7:13 UTC (permalink / raw)
  To: Michael Petlan; +Cc: linux-perf-users, vmolnaro, acme, acme, mhiramat

On Thu, Feb 8, 2024 at 8:49 AM Michael Petlan <mpetlan@redhat.com> wrote:
>
> On Thu, 1 Feb 2024, Namhyung Kim wrote:
> > On Wed, Jan 31, 2024 at 3:42 AM Michael Petlan <mpetlan@redhat.com> wrote:
> > >
> > > From: Veronika Molnarova <vmolnaro@redhat.com>
> > >
> > > Unify perf regexes for checking testing output into a single file
> > > to reduce duplicates and prevent errors when editing.
> > >
> > > This will be used in upcomming patches in shell tests.
> > >
> > > Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
> > > Signed-off-by: Michael Petlan <mpetlan@redhat.com>
> > > ---
> > >  tools/perf/tests/shell/common/patterns.sh | 256 ++++++++++++++++++++++
> > >  1 file changed, 256 insertions(+)
> > >  create mode 100644 tools/perf/tests/shell/common/patterns.sh
> > >
> > > diff --git a/tools/perf/tests/shell/common/patterns.sh b/tools/perf/tests/shell/common/patterns.sh
> > > new file mode 100644
> > > index 000000000000..919a07b8b454
> > > --- /dev/null
> > > +++ b/tools/perf/tests/shell/common/patterns.sh
> >
> > We have tests/shell/lib directory, maybe better to put this there.
> > But maybe we can move it later once we apply the series.
>
> Yes, in case the testsuite gets accepted, I plan to work further
> on the integration with the current shell test set, in order to
> unify the configuration, output, logging, etc. So, I'd prefer to
> merge the directories later.

Sounds good.  I'd like to merge this series to improve the test
coverage.  And then we can work on fixing problems.


> >
> > > @@ -0,0 +1,256 @@
> > > +# SPDX-License-Identifier: GPL-2.0
> > > +
> [...]
>
> > > +export RE_ADDRESS_NOT_NULL="0x[0-9A-Fa-f]*[1-9A-Fa-f]+[0-9A-Fa-f]*"
> > > +# Memory address (not NULL)
> > > +# Examples:
> > > +#    0xffffffff9abe8ae8
> > > +#!   0x0
> > > +#!   0x0000000000000000
> > > +
> > > +export RE_PROCESS_PID="\w+\/\d+"
> >
> > I'm afraid the process name can have spaces like
> > "my proc A/9876".
> >
> > Thanks,
> > Namhyung
> >
> Good catch! Theoretically yes. It is not used yet (perf-trace tests use
> this regexp; we aim to post the rest of the testsuite later). However,
> looking at the perf-trace testcase, it runs also `perf trace -a`, so
> if there are any processes with non-standard name, they would appear
> there. But that's not only space, but also other characters, like '+',
> etc. We will try to fix this to match any valid process name. Thanks.

Ok, I'm looking forward to seeing more test cases.

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/7] perf testsuite: Add common regex patters
  2024-02-09  7:13     ` Namhyung Kim
@ 2024-02-09 22:56       ` Namhyung Kim
  0 siblings, 0 replies; 23+ messages in thread
From: Namhyung Kim @ 2024-02-09 22:56 UTC (permalink / raw)
  To: Michael Petlan; +Cc: linux-perf-users, vmolnaro, acme, acme, mhiramat

On Thu, Feb 8, 2024 at 11:13 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Thu, Feb 8, 2024 at 8:49 AM Michael Petlan <mpetlan@redhat.com> wrote:
> >
> > On Thu, 1 Feb 2024, Namhyung Kim wrote:
> > > On Wed, Jan 31, 2024 at 3:42 AM Michael Petlan <mpetlan@redhat.com> wrote:
> > > >
> > > > From: Veronika Molnarova <vmolnaro@redhat.com>
> > > >
> > > > Unify perf regexes for checking testing output into a single file
> > > > to reduce duplicates and prevent errors when editing.
> > > >
> > > > This will be used in upcomming patches in shell tests.
> > > >
> > > > Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
> > > > Signed-off-by: Michael Petlan <mpetlan@redhat.com>
> > > > ---
> > > >  tools/perf/tests/shell/common/patterns.sh | 256 ++++++++++++++++++++++
> > > >  1 file changed, 256 insertions(+)
> > > >  create mode 100644 tools/perf/tests/shell/common/patterns.sh
> > > >
> > > > diff --git a/tools/perf/tests/shell/common/patterns.sh b/tools/perf/tests/shell/common/patterns.sh
> > > > new file mode 100644
> > > > index 000000000000..919a07b8b454
> > > > --- /dev/null
> > > > +++ b/tools/perf/tests/shell/common/patterns.sh
> > >
> > > We have tests/shell/lib directory, maybe better to put this there.
> > > But maybe we can move it later once we apply the series.
> >
> > Yes, in case the testsuite gets accepted, I plan to work further
> > on the integration with the current shell test set, in order to
> > unify the configuration, output, logging, etc. So, I'd prefer to
> > merge the directories later.
>
> Sounds good.  I'd like to merge this series to improve the test
> coverage.  And then we can work on fixing problems.

I have some shellcheck issues.  Can you please fix them first?

Thanks,
Namhyung


In tests/shell/perftool-testsuite_probe.sh line 6:
cd "$(dirname $0)/base_probe"
^---------------------------^ SC2164 (warning): Use 'cd ... || exit'
or 'cd ... || return' in case cd fails.

Did you mean:
cd "$(dirname $0)/base_probe" || exit


In tests/shell/perftool-testsuite_probe.sh line 9:
export PERFSUITE_RUN_DIR=$(mktemp -d /tmp/$(basename $0 .sh).XXX)
       ^---------------^ SC2155 (warning): Declare and assign
separately to avoid masking return values.
                         ^-- SC2046 (warning): Quote this to prevent
word splitting.
                                          ^----------------^ SC2046
(warning): Quote this to prevent word splitting.


In tests/shell/perftool-testsuite_probe.sh line 14:
     (( status += $? ))
     ^----------------^ SC3006 (warning): In POSIX sh, standalone
((..)) is undefined.

For more information:
  https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt...
  https://www.shellcheck.net/wiki/SC2155 -- Declare and assign separately to ...
  https://www.shellcheck.net/wiki/SC2164 -- Use 'cd ... || exit' or 'cd ... |...

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 0/7] Add perf testsuite into perf-test
  2024-01-31 11:39 [PATCH 1/7] perf testsuite: Add common regex patters Michael Petlan
                   ` (7 preceding siblings ...)
  2024-02-02  0:05 ` Namhyung Kim
@ 2024-02-15 11:02 ` Michael Petlan
  2024-02-15 11:02   ` [PATCH v2 1/7] perf testsuite: Add common regex patters Michael Petlan
                     ` (7 more replies)
  8 siblings, 8 replies; 23+ messages in thread
From: Michael Petlan @ 2024-02-15 11:02 UTC (permalink / raw)
  To: linux-perf-users, acme
  Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, atrajeev, kjain

Hello all,

as Arnaldo said, this is a first patchset of an effort to upstream
the external perftool-testsuite [1] and merge it into perf-test.

The perftool-testsuite originates back to 2015, when there were no
shell-based testcases for perf. At that point, perf-test contained
rather "unit-tests" and there was a need to test perf as a tool too.

Nowadays, as perf-test contains shell tests too, it might make sense
to merge it in...

Apart from ~ 70 test scripts covering quite a lot of perf functionality,
it also brings design patterns that I consider advanced and useful:

  1) A possibility to keep logs and temp files for later fail
     investigation. This is necessary when the tests are running
     on machines that are immediately reinstalled and reused after
     the testrun. With the logs, many fails are easily narrowed
     down even when not having the machine online. Having variable
     PERFTEST_KEEP_LOGS=y keeps the logs in /tmp/.

  2) High level of configurability allows it to be run in deeper,
     thorough mode, as well as an "smoke testing" CI mode. Also,
     switching to different loads measured by perf is easy, just
     by setting CMD_SIMPLE (defaults to command `true`) to a
     user-defined application.

  3) Multi-level structure of the tests and subtests -- the tests
     are organized by perf-subcommands, test scripts and subtests
     within the scripts. Everything is reported in the results,
     when verbose output is enabled, so it is clear that e.g.
     perf-report failed due to preceding perf-record hadn't get
     samples, etc...
 
  4) Shared/unified result checking helpers and regular expressions

The perftool-testsuite is widely used at Red Hat for testing perf,
as far as I know, there are some users also outside of Red Hat,
but merging it into perf-test will help it spread and increase
the test coverage where it's still not known.

My plan is to move the whole testsuite under perf-test, respecting
both structures, as one perf-test "entry" per the perftool-testsuite's
"base_*" directory. Later possibly to align other shell tests with
it. 

[1] https://github.com/rfmvh/perftool-testsuite

========================

This is a v2 of the patchset, addressing the following issues:
  - shellcheck warnings
  - fixed regular expressions RE_LINE_TRACE_*, although they
    are not used yet
  - missing cover-letter
  
========================

Michael Petlan (1):
  perf testsuite: Install kprobe tests and common files

Veronika Molnarova (6):
  perf testsuite: Add common regex patters
  perf testsuite: Add common setting for shell tests
  perf testsuite: Add initialization script for shell tests
  perf testsuite: Add test case for perf probe
  perf testsuite: Add common output checking helpers
  perf testsuite: Add test for kprobe handling

 tools/perf/Makefile.perf                      |   5 +
 tools/perf/tests/shell/base_probe/settings.sh |  48 +++
 .../shell/base_probe/test_adding_kernel.sh    | 278 ++++++++++++++++++
 .../shell/common/check_all_lines_matched.pl   |  39 +++
 .../shell/common/check_all_patterns_found.pl  |  34 +++
 .../shell/common/check_no_patterns_found.pl   |  34 +++
 tools/perf/tests/shell/common/init.sh         | 117 ++++++++
 tools/perf/tests/shell/common/patterns.sh     | 268 +++++++++++++++++
 tools/perf/tests/shell/common/settings.sh     |  79 +++++
 .../tests/shell/perftool-testsuite_probe.sh   |  23 ++
 10 files changed, 925 insertions(+)
 create mode 100644 tools/perf/tests/shell/base_probe/settings.sh
 create mode 100755 tools/perf/tests/shell/base_probe/test_adding_kernel.sh
 create mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.pl
 create mode 100644 tools/perf/tests/shell/common/init.sh
 create mode 100644 tools/perf/tests/shell/common/patterns.sh
 create mode 100644 tools/perf/tests/shell/common/settings.sh
 create mode 100755 tools/perf/tests/shell/perftool-testsuite_probe.sh

-- 
2.43.0


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 1/7] perf testsuite: Add common regex patters
  2024-02-15 11:02 ` [PATCH v2 0/7] Add perf testsuite into perf-test Michael Petlan
@ 2024-02-15 11:02   ` Michael Petlan
  2024-02-15 11:02   ` [PATCH v2 2/7] perf testsuite: Add common setting for shell tests Michael Petlan
                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-02-15 11:02 UTC (permalink / raw)
  To: linux-perf-users, acme
  Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, atrajeev, kjain

From: Veronika Molnarova <vmolnaro@redhat.com>

Unify perf regexes for checking testing output into a single file
to reduce duplicates and prevent errors when editing.

This will be used in upcomming patches in shell tests.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/tests/shell/common/patterns.sh | 268 ++++++++++++++++++++++
 1 file changed, 268 insertions(+)
 create mode 100644 tools/perf/tests/shell/common/patterns.sh

diff --git a/tools/perf/tests/shell/common/patterns.sh b/tools/perf/tests/shell/common/patterns.sh
new file mode 100644
index 000000000000..21dab25c7b7f
--- /dev/null
+++ b/tools/perf/tests/shell/common/patterns.sh
@@ -0,0 +1,268 @@
+# SPDX-License-Identifier: GPL-2.0
+
+export RE_NUMBER="[0-9\.]+"
+# Number
+# Examples:
+#    123.456
+
+
+export RE_NUMBER_HEX="[0-9A-Fa-f]+"
+# Hexadecimal number
+# Examples:
+#    1234
+#    a58d
+#    aBcD
+#    deadbeef
+
+
+export RE_DATE_YYYYMMDD="[0-9]{4}-(?:(?:01|03|05|07|08|10|12)-(?:[0-2][0-9]|3[0-1])|02-[0-2][0-9]|(?:(?:04|06|09|11)-(?:[0-2][0-9]|30)))"
+# Date in YYYY-MM-DD form
+# Examples:
+#    1990-02-29
+#    0015-07-31
+#    2456-12-31
+#!   2012-13-01
+#!   1963-09-31
+
+
+export RE_TIME="(?:[0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]"
+# Time
+# Examples:
+#    15:12:27
+#    23:59:59
+#!   24:00:00
+#!   11:25:60
+#!   17:60:15
+
+
+export RE_DATE_TIME="\w+\s+\w+\s+$RE_NUMBER\s+$RE_TIME\s+$RE_NUMBER"
+# Time and date
+# Examples:
+#    Wed Feb 12 10:46:26 2020
+#    Mon Mar  2 13:27:06 2020
+#!   St úno 12 10:57:21 CET 2020
+#!   Po úno 14 15:17:32 2010
+
+
+export RE_ADDRESS="0x$RE_NUMBER_HEX"
+# Memory address
+# Examples:
+#    0x123abc
+#    0xffffffff9abe8ae8
+#    0x0
+
+
+export RE_ADDRESS_NOT_NULL="0x[0-9A-Fa-f]*[1-9A-Fa-f]+[0-9A-Fa-f]*"
+# Memory address (not NULL)
+# Examples:
+#    0xffffffff9abe8ae8
+#!   0x0
+#!   0x0000000000000000
+
+export RE_PROCESS_PID="[^\/]+\/\d+"
+# A process with PID
+# Example:
+#    sleep/4102
+#    test_overhead./866185
+#    in:imjournal/1096
+#    random#$& test/866607
+
+export RE_EVENT_ANY="[\w\-\:\/_=,]+"
+# Name of any event (universal)
+# Examples:
+#    cpu-cycles
+#    cpu/event=12,umask=34/
+#    r41e1
+#    nfs:nfs_getattr_enter
+
+
+export RE_EVENT="[\w\-:_]+"
+# Name of an usual event
+# Examples:
+#    cpu-cycles
+
+
+export RE_EVENT_RAW="r$RE_NUMBER_HEX"
+# Specification of a raw event
+# Examples:
+#    r41e1
+#    r1a
+
+
+export RE_EVENT_CPU="cpu/(\w+=$RE_NUMBER_HEX,?)+/p*"
+# Specification of a CPU event
+# Examples:
+#    cpu/event=12,umask=34/pp
+
+
+export RE_EVENT_UNCORE="uncore/[\w_]+/"
+# Specification of an uncore event
+# Examples:
+#    uncore/qhl_request_local_reads/
+
+
+export RE_EVENT_SUBSYSTEM="[\w\-]+:[\w\-]+"
+# Name of an event from subsystem
+# Examples:
+#    ext4:ext4_ordered_write_end
+#    sched:sched_switch
+
+
+export RE_FILE_NAME="[\w\+\.-]+"
+# A filename
+# Examples:
+#    libstdc++.so.6
+#!   some/path
+
+
+export RE_PATH_ABSOLUTE="(?:\/$RE_FILE_NAME)+"
+# A full filepath
+# Examples:
+#    /usr/lib64/somelib.so.5.4.0
+#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
+#    /usr/bin/mv
+#!   some/relative/path
+#!   ./some/relative/path
+
+
+export RE_PATH="(?:$RE_FILE_NAME)?$RE_PATH_ABSOLUTE"
+# A filepath
+# Examples:
+#    /usr/lib64/somelib.so.5.4.0
+#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
+#    ./.emacs
+#    src/fs/file.c
+
+
+export RE_DSO="(?:$RE_PATH_ABSOLUTE(?: \(deleted\))?|\[kernel\.kallsyms\]|\[unknown\]|\[vdso\]|\[kernel\.vmlinux\][\.\w]*)"
+# A DSO name in various result tables
+# Examples:
+#    /usr/lib64/somelib.so.5.4.0
+#    /usr/bin/somebinart (deleted)
+#    /lib/modules/4.3.0-rc5/kernel/fs/xfs/xfs.ko
+#    [kernel.kallsyms]
+#    [kernel.vmlinux]
+#    [vdso]
+#    [unknown]
+
+
+export RE_LINE_COMMENT="^#.*"
+# A comment line
+# Examples:
+#    # Started on Thu Sep 10 11:43:00 2015
+
+
+export RE_LINE_EMPTY="^\s*$"
+# An empty line with possible whitespaces
+# Examples:
+#
+
+
+export RE_LINE_RECORD1="^\[\s+perf\s+record:\s+Woken up $RE_NUMBER times? to write data\s+\].*$"
+# The first line of perf-record "OK" output
+# Examples:
+#    [ perf record: Woken up 1 times to write data ]
+
+
+export RE_LINE_RECORD2="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\.data(?:\.\d+)?\s*\(~?$RE_NUMBER samples\)\s+\].*$"
+# The second line of perf-record "OK" output
+# Examples:
+#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB perf.data (~109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB ./perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB ./perf.data.3 (109 samples) ]
+
+
+export RE_LINE_RECORD2_TOLERANT="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\.data(?:\.\d+)?\s*(?:\(~?$RE_NUMBER samples\))?\s+\].*$"
+# The second line of perf-record "OK" output, even no samples is OK here
+# Examples:
+#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB perf.data (~109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB ./perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB ./perf.data.3 (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB perf.data ]
+
+
+export RE_LINE_RECORD2_TOLERANT_FILENAME="^\[\s+perf\s+record:\s+Captured and wrote $RE_NUMBER\s*MB\s+(?:[\w\+\.-]*(?:$RE_PATH)?\/)?perf\w*\.data(?:\.\d+)?\s*\(~?$RE_NUMBER samples\)\s+\].*$"
+# The second line of perf-record "OK" output
+# Examples:
+#    [ perf record: Captured and wrote 0.405 MB perf.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB perf_ls.data (~109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB perf_aNyCaSe.data (109 samples) ]
+#    [ perf record: Captured and wrote 0.405 MB ./perfdata.data.3 (109 samples) ]
+#!    [ perf record: Captured and wrote 0.405 MB /some/temp/dir/my_own.data (109 samples) ]
+#!    [ perf record: Captured and wrote 0.405 MB ./UPPERCASE.data (109 samples) ]
+#!    [ perf record: Captured and wrote 0.405 MB ./aNyKiNDoF.data.3 (109 samples) ]
+#!    [ perf record: Captured and wrote 0.405 MB perf.data ]
+
+
+export RE_LINE_TRACE_FULL="^\s*$RE_NUMBER\s*\(\s*$RE_NUMBER\s*ms\s*\):\s*$RE_PROCESS_PID\s+.*\)\s+=\s+(:?\-?$RE_NUMBER|0x$RE_NUMBER_HEX).*$"
+# A line of perf-trace output
+# Examples:
+#    0.115 ( 0.005 ms): sleep/4102 open(filename: 0xd09e2ab2, flags: CLOEXEC                             ) = 3
+#    0.157 ( 0.005 ms): sleep/4102 mmap(len: 3932736, prot: EXEC|READ, flags: PRIVATE|DENYWRITE, fd: 3   ) = 0x7f89d0605000
+#!    0.115 ( 0.005 ms): sleep/4102 open(filename: 0xd09e2ab2, flags: CLOEXEC                             ) =
+
+export RE_LINE_TRACE_ONE_PROC="^\s*$RE_NUMBER\s*\(\s*$RE_NUMBER\s*ms\s*\):\s*\w+\(.*\)\s+=\s+(?:\-?$RE_NUMBER|0x$RE_NUMBER_HEX).*$"
+# A line of perf-trace output
+# Examples:
+#    0.115 ( 0.005 ms): open(filename: 0xd09e2ab2, flags: CLOEXEC                             ) = 3
+#    0.157 ( 0.005 ms): mmap(len: 3932736, prot: EXEC|READ, flags: PRIVATE|DENYWRITE, fd: 3   ) = 0x7f89d0605000
+#!    0.115 ( 0.005 ms): open(filename: 0xd09e2ab2, flags: CLOEXEC                             ) =
+
+export RE_LINE_TRACE_CONTINUED="^\s*(:?$RE_NUMBER|\?)\s*\(\s*($RE_NUMBER\s*ms\s*)?\):\s*($RE_PROCESS_PID\s*)?\.\.\.\s*\[continued\]:\s+\w+\(\).*\s+=\s+(?:\-?$RE_NUMBER|0x$RE_NUMBER_HEX).*$"
+# A line of perf-trace output
+# Examples:
+#    0.000 ( 0.000 ms):  ... [continued]: nanosleep()) = 0
+#    0.000 ( 0.000 ms):  ... [continued]: nanosleep()) = 0x00000000
+#    ? (         ): packagekitd/94838  ... [continued]: poll())                                             = 0 (Timeout)
+#!    0.000 ( 0.000 ms):  ... [continued]: nanosleep()) =
+
+export RE_LINE_TRACE_UNFINISHED="^\s*$RE_NUMBER\s*\(\s*\):\s*$RE_PROCESS_PID\s+.*\)\s+\.\.\.\s*$"
+# A line of perf-trace output
+# Examples:
+#    901.040 (         ): in:imjournal/1096 ppoll(ufds: 0x7f701a5adb70, nfds: 1, tsp: 0x7f701a5adaf0, sigsetsize: 8) ...
+#    613.727 (         ): gmain/1099 poll(ufds: 0x56248f6b64b0, nfds: 2, timeout_msecs: 3996)           ...
+
+export RE_LINE_TRACE_SUMMARY_HEADER="\s*syscall\s+calls\s+(?:errors\s+)?total\s+min\s+avg\s+max\s+stddev"
+# A header of a perf-trace summary table
+# Example:
+#    syscall            calls    total       min       avg       max      stddev
+#    syscall            calls  errors  total       min       avg       max       stddev
+
+
+export RE_LINE_TRACE_SUMMARY_CONTENT="^\s*\w+\s+(?:$RE_NUMBER\s+){5,6}$RE_NUMBER%"
+# A line of a perf-trace summary table
+# Example:
+#    open                   3     0.017     0.005     0.006     0.007     10.90%
+#    openat                 2      0     0.017     0.008     0.009     0.010     12.29%
+
+
+export RE_LINE_REPORT_CONTENT="^\s+$RE_NUMBER%\s+\w+\s+\S+\s+\S+\s+\S+" # FIXME
+# A line from typicap perf report --stdio output
+# Example:
+#     100.00%  sleep    [kernel.vmlinux]  [k] syscall_return_slowpath
+
+
+export RE_TASK="\s+[\w~\/ \.\+:#-]+(?:\[-1(?:\/\d+)?\]|\[\d+(?:\/\d+)?\])"
+# A name of a task used for perf sched timehist -s
+# Example:
+#     sleep[62755]
+#     runtest.sh[62762]
+#     gmain[705/682]
+#     xfsaild/dm-0[495]
+#     kworker/u8:1-ev[62714]
+#     :-1[-1/62756]
+#     :-1[-1]
+#     :-1[62756]
+
+
+export RE_SEGFAULT=".*(?:Segmentation\sfault|SIGSEGV|\score\s|dumped|segfault).*"
+# Possible variations of the segfault message
+# Example:
+#     /bin/bash: line 1:    32 Segmentation fault      timeout 15s
+#     Segmentation fault (core dumped)
+#     Program terminated with signal SIGSEGV
+#!     WARNING: 12323431 isn't a 'cpu_core', please use a CPU list in the 'cpu_core' range (0-15)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 2/7] perf testsuite: Add common setting for shell tests
  2024-02-15 11:02 ` [PATCH v2 0/7] Add perf testsuite into perf-test Michael Petlan
  2024-02-15 11:02   ` [PATCH v2 1/7] perf testsuite: Add common regex patters Michael Petlan
@ 2024-02-15 11:02   ` Michael Petlan
  2024-02-15 11:02   ` [PATCH v2 3/7] perf testsuite: Add initialization script " Michael Petlan
                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-02-15 11:02 UTC (permalink / raw)
  To: linux-perf-users, acme
  Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, atrajeev, kjain

From: Veronika Molnarova <vmolnaro@redhat.com>

Add settings defining sample commands later shared by shell tests. This
adds the possibility to globally adjust the default values for the whole
testsuite.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/tests/shell/common/settings.sh | 79 +++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 tools/perf/tests/shell/common/settings.sh

diff --git a/tools/perf/tests/shell/common/settings.sh b/tools/perf/tests/shell/common/settings.sh
new file mode 100644
index 000000000000..361641dbaaad
--- /dev/null
+++ b/tools/perf/tests/shell/common/settings.sh
@@ -0,0 +1,79 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+#	settings.sh
+#	Author: Michael Petlan <mpetlan@redhat.com>
+#
+#	Description:
+#
+#		This file contains global settings for the whole testsuite.
+#	Its purpose is to make it easier when it is necessary i.e. to
+#	change the usual sample command which is used in all of the tests
+#	in many files.
+#
+#		This file is intended to be sourced in the tests.
+#
+
+#### which perf to use in the testing
+export CMD_PERF=${CMD_PERF:-`which perf`}
+
+#### basic programs examinated by perf
+export CMD_BASIC_SLEEP="sleep 0.1"
+export CMD_QUICK_SLEEP="sleep 0.01"
+export CMD_LONGER_SLEEP="sleep 2"
+export CMD_DOUBLE_LONGER_SLEEP="sleep 4"
+export CMD_VERY_LONG_SLEEP="sleep 30"
+export CMD_SIMPLE="true"
+
+#### testsuite run mode
+# define constants:
+export RUNMODE_BASIC=0
+export RUNMODE_STANDARD=1
+export RUNMODE_EXPERIMENTAL=2
+# default runmode is STANDARD
+export PERFTOOL_TESTSUITE_RUNMODE=${PERFTOOL_TESTSUITE_RUNMODE:-$RUNMODE_STANDARD}
+
+#### common settings
+export TESTLOG_VERBOSITY=${TESTLOG_VERBOSITY:-2}
+export TESTLOG_FORCE_COLOR=${TESTLOG_FORCE_COLOR:-n}
+export TESTLOG_ERR_MSG_MAX_LINES=${TESTLOG_ERR_MSG_MAX_LINES:-20}
+export TESTLOG_CLEAN=${TESTLOG_CLEAN:-y}
+
+#### other environment-related settings
+export TEST_IGNORE_MISSING_PMU=${TEST_IGNORE_MISSING_PMU:-n}
+
+#### clear locale
+export LC_ALL=C
+
+#### colors
+if [ -t 1 -o "$TESTLOG_FORCE_COLOR" = "yes" ]; then
+	export MPASS="\e[32m"
+	export MALLPASS="\e[1;32m"
+	export MFAIL="\e[31m"
+	export MALLFAIL="\e[1;31m"
+	export MWARN="\e[1;35m"
+	export MSKIP="\e[33m"
+	export MHIGH="\e[1;33m"
+	export MEND="\e[m"
+else
+	export MPASS=""
+	export MALLPASS=""
+	export MFAIL=""
+	export MALLFAIL=""
+	export MWARN=""
+	export MSKIP=""
+	export MHIGH=""
+	export MEND=""
+fi
+
+
+#### test parametrization
+if [ ! -d ./common ]; then
+	# set parameters based on runmode
+	if [ -f ../common/parametrization.$PERFTOOL_TESTSUITE_RUNMODE.sh ]; then
+		. ../common/parametrization.$PERFTOOL_TESTSUITE_RUNMODE.sh
+	fi
+	# if some parameters haven't been set until now, set them to default
+	if [ -f ../common/parametrization.sh ]; then
+		. ../common/parametrization.sh
+	fi
+fi
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 3/7] perf testsuite: Add initialization script for shell tests
  2024-02-15 11:02 ` [PATCH v2 0/7] Add perf testsuite into perf-test Michael Petlan
  2024-02-15 11:02   ` [PATCH v2 1/7] perf testsuite: Add common regex patters Michael Petlan
  2024-02-15 11:02   ` [PATCH v2 2/7] perf testsuite: Add common setting for shell tests Michael Petlan
@ 2024-02-15 11:02   ` Michael Petlan
  2024-02-15 11:02   ` [PATCH v2 4/7] perf testsuite: Add test case for perf probe Michael Petlan
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-02-15 11:02 UTC (permalink / raw)
  To: linux-perf-users, acme
  Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, atrajeev, kjain

From: Veronika Molnarova <vmolnaro@redhat.com>

Initialize reporting and logging functions that unifies formatting
of the test output used for shell tests.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/tests/shell/common/init.sh | 117 ++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)
 create mode 100644 tools/perf/tests/shell/common/init.sh

diff --git a/tools/perf/tests/shell/common/init.sh b/tools/perf/tests/shell/common/init.sh
new file mode 100644
index 000000000000..aadeaf782e03
--- /dev/null
+++ b/tools/perf/tests/shell/common/init.sh
@@ -0,0 +1,117 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+#	init.sh
+#	Author: Michael Petlan <mpetlan@redhat.com>
+#
+#	Description:
+#
+#		This file should be used for initialization of basic functions
+#	for checking, reporting results etc.
+#
+#
+
+
+. ../common/settings.sh
+. ../common/patterns.sh
+
+THIS_TEST_NAME=`basename $0 .sh`
+
+_echo()
+{
+	test "$TESTLOG_VERBOSITY" -ne 0 && echo -e "$@"
+}
+
+print_results()
+{
+	PERF_RETVAL="$1"; shift
+	CHECK_RETVAL="$1"; shift
+	FAILURE_REASON=""
+	TASK_COMMENT="$@"
+	if [ $PERF_RETVAL -eq 0 -a $CHECK_RETVAL -eq 0 ]; then
+		_echo "$MPASS-- [ PASS ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT"
+		return 0
+	else
+		if [ $PERF_RETVAL -ne 0 ]; then
+			FAILURE_REASON="command exitcode"
+		fi
+		if [ $CHECK_RETVAL -ne 0 ]; then
+			test -n "$FAILURE_REASON" && FAILURE_REASON="$FAILURE_REASON + "
+			FAILURE_REASON="$FAILURE_REASON""output regexp parsing"
+		fi
+		_echo "$MFAIL-- [ FAIL ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT ($FAILURE_REASON)"
+		return 1
+	fi
+}
+
+print_overall_results()
+{
+	RETVAL="$1"; shift
+	if [ $RETVAL -eq 0 ]; then
+		_echo "$MALLPASS## [ PASS ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME SUMMARY"
+	else
+		_echo "$MALLFAIL## [ FAIL ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME SUMMARY :: $RETVAL failures found"
+	fi
+	return $RETVAL
+}
+
+print_testcase_skipped()
+{
+	TASK_COMMENT="$@"
+	_echo "$MSKIP-- [ SKIP ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT :: testcase skipped"
+	return 0
+}
+
+print_overall_skipped()
+{
+	_echo "$MSKIP## [ SKIP ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME :: testcase skipped"
+	return 0
+}
+
+print_warning()
+{
+	WARN_COMMENT="$@"
+	_echo "$MWARN-- [ WARN ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $WARN_COMMENT"
+	return 0
+}
+
+# this function should skip a testcase if the testsuite is not run in
+# a runmode that fits the testcase --> if the suite runs in BASIC mode
+# all STANDARD and EXPERIMENTAL testcases will be skipped; if the suite
+# runs in STANDARD mode, all EXPERIMENTAL testcases will be skipped and
+# if the suite runs in EXPERIMENTAL mode, nothing is skipped
+consider_skipping()
+{
+	TESTCASE_RUNMODE="$1"
+	# the runmode of a testcase needs to be at least the current suite's runmode
+	if [ $PERFTOOL_TESTSUITE_RUNMODE -lt $TESTCASE_RUNMODE ]; then
+		print_overall_skipped
+		exit 0
+	fi
+}
+
+detect_baremetal()
+{
+	# return values:
+	# 0 = bare metal
+	# 1 = virtualization detected
+	# 2 = unknown state
+	VIRT=`systemd-detect-virt 2>/dev/null`
+	test $? -eq 127 && return 2
+	test "$VIRT" = "none"
+}
+
+detect_intel()
+{
+	# return values:
+	# 0 = is Intel
+	# 1 = is not Intel or unknown
+	grep "vendor_id" < /proc/cpuinfo | grep -q "GenuineIntel"
+}
+
+detect_amd()
+{
+	# return values:
+	# 0 = is AMD
+	# 1 = is not AMD or unknown
+	grep "vendor_id" < /proc/cpuinfo | grep -q "AMD"
+}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 4/7] perf testsuite: Add test case for perf probe
  2024-02-15 11:02 ` [PATCH v2 0/7] Add perf testsuite into perf-test Michael Petlan
                     ` (2 preceding siblings ...)
  2024-02-15 11:02   ` [PATCH v2 3/7] perf testsuite: Add initialization script " Michael Petlan
@ 2024-02-15 11:02   ` Michael Petlan
  2024-02-15 11:02   ` [PATCH v2 5/7] perf testsuite: Add common output checking helpers Michael Petlan
                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-02-15 11:02 UTC (permalink / raw)
  To: linux-perf-users, acme
  Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, atrajeev, kjain

From: Veronika Molnarova <vmolnaro@redhat.com>

Add new perf probe test case that acts as an entry element in perf test
list. Runs multiple subtests from directory "base_probe", which will be
added in incomming patches and can be expanded without further editing.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 .../tests/shell/perftool-testsuite_probe.sh   | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100755 tools/perf/tests/shell/perftool-testsuite_probe.sh

diff --git a/tools/perf/tests/shell/perftool-testsuite_probe.sh b/tools/perf/tests/shell/perftool-testsuite_probe.sh
new file mode 100755
index 000000000000..a0fec33a0358
--- /dev/null
+++ b/tools/perf/tests/shell/perftool-testsuite_probe.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+# perftool-testsuite_probe
+# SPDX-License-Identifier: GPL-2.0
+
+test -d "$(dirname "$0")/base_probe" || exit 2
+cd "$(dirname "$0")/base_probe" || exit 2
+status=0
+
+PERFSUITE_RUN_DIR=$(mktemp -d /tmp/"$(basename "$0" .sh)".XXX)
+export PERFSUITE_RUN_DIR
+
+for testcase in setup.sh test_*; do                  # skip setup.sh if not present or not executable
+     test -x "$testcase" || continue
+     ./"$testcase"
+     (( status += $? ))
+done
+
+if ! [ "$PERFTEST_KEEP_LOGS" = "y" ]; then
+	rm -rf "$PERFSUITE_RUN_DIR"
+fi
+
+test $status -ne 0 && exit 1
+exit 0
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 5/7] perf testsuite: Add common output checking helpers
  2024-02-15 11:02 ` [PATCH v2 0/7] Add perf testsuite into perf-test Michael Petlan
                     ` (3 preceding siblings ...)
  2024-02-15 11:02   ` [PATCH v2 4/7] perf testsuite: Add test case for perf probe Michael Petlan
@ 2024-02-15 11:02   ` Michael Petlan
  2024-02-15 11:02   ` [PATCH v2 6/7] perf testsuite: Add test for kprobe handling Michael Petlan
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-02-15 11:02 UTC (permalink / raw)
  To: linux-perf-users, acme
  Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, atrajeev, kjain

From: Veronika Molnarova <vmolnaro@redhat.com>

As a form of validation, it is a common practice to check the outputs
of commands whether they contain expected patterns or match a certain
regex.

Add helpers for verifying that all regexes are found in the output, that
all lines match any pattern from a set and that a certain expression is
not present in the output.

In verbose mode these helpers log mismatches for easier failure
investigation.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 .../shell/common/check_all_lines_matched.pl   | 39 +++++++++++++++++++
 .../shell/common/check_all_patterns_found.pl  | 34 ++++++++++++++++
 .../shell/common/check_no_patterns_found.pl   | 34 ++++++++++++++++
 3 files changed, 107 insertions(+)
 create mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.pl

diff --git a/tools/perf/tests/shell/common/check_all_lines_matched.pl b/tools/perf/tests/shell/common/check_all_lines_matched.pl
new file mode 100755
index 000000000000..fded48959a3f
--- /dev/null
+++ b/tools/perf/tests/shell/common/check_all_lines_matched.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+# SPDX-License-Identifier: GPL-2.0
+
+@regexps = @ARGV;
+
+$max_printed_lines = 20;
+$max_printed_lines = $ENV{TESTLOG_ERR_MSG_MAX_LINES} if (defined $ENV{TESTLOG_ERR_MSG_MAX_LINES});
+
+$quiet = 1;
+$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
+
+$passed = 1;
+$lines_printed = 0;
+
+while (<STDIN>)
+{
+	s/\n//;
+
+	$line_matched = 0;
+	for $r (@regexps)
+	{
+		if (/$r/)
+		{
+			$line_matched = 1;
+			last;
+		}
+	}
+
+	unless ($line_matched)
+	{
+		if ($lines_printed++ < $max_printed_lines)
+		{
+			print "Line did not match any pattern: \"$_\"\n" unless $quiet;
+		}
+		$passed = 0;
+	}
+}
+
+exit ($passed == 0);
diff --git a/tools/perf/tests/shell/common/check_all_patterns_found.pl b/tools/perf/tests/shell/common/check_all_patterns_found.pl
new file mode 100755
index 000000000000..11bdf1d3460a
--- /dev/null
+++ b/tools/perf/tests/shell/common/check_all_patterns_found.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+# SPDX-License-Identifier: GPL-2.0
+
+@regexps = @ARGV;
+
+$quiet = 1;
+$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
+
+%found = ();
+$passed = 1;
+
+while (<STDIN>)
+{
+	s/\n//;
+
+	for $r (@regexps)
+	{
+		if (/$r/)
+		{
+			$found{$r} = 1;	# FIXME: maybe add counters -- how many times was the regexp matched
+		}
+	}
+}
+
+for $r (@regexps)
+{
+	unless (exists $found{$r})
+	{
+		print "Regexp not found: \"$r\"\n" unless $quiet;
+		$passed = 0;
+	}
+}
+
+exit ($passed == 0);
diff --git a/tools/perf/tests/shell/common/check_no_patterns_found.pl b/tools/perf/tests/shell/common/check_no_patterns_found.pl
new file mode 100755
index 000000000000..770999e87a5f
--- /dev/null
+++ b/tools/perf/tests/shell/common/check_no_patterns_found.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+# SPDX-License-Identifier: GPL-2.0
+
+@regexps = @ARGV;
+
+$quiet = 1;
+$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
+
+%found = ();
+$passed = 1;
+
+while (<STDIN>)
+{
+	s/\n//;
+
+	for $r (@regexps)
+	{
+		if (/$r/)
+		{
+			$found{$r} = 1;
+		}
+	}
+}
+
+for $r (@regexps)
+{
+	if (exists $found{$r})
+	{
+		print "Regexp found: \"$r\"\n" unless $quiet;
+		$passed = 0;
+	}
+}
+
+exit ($passed == 0);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 6/7] perf testsuite: Add test for kprobe handling
  2024-02-15 11:02 ` [PATCH v2 0/7] Add perf testsuite into perf-test Michael Petlan
                     ` (4 preceding siblings ...)
  2024-02-15 11:02   ` [PATCH v2 5/7] perf testsuite: Add common output checking helpers Michael Petlan
@ 2024-02-15 11:02   ` Michael Petlan
  2024-02-15 11:02   ` [PATCH v2 7/7] perf testsuite: Install kprobe tests and common files Michael Petlan
  2024-02-21  1:58   ` [PATCH v2 0/7] Add perf testsuite into perf-test Namhyung Kim
  7 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-02-15 11:02 UTC (permalink / raw)
  To: linux-perf-users, acme
  Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, atrajeev, kjain

From: Veronika Molnarova <vmolnaro@redhat.com>

Test perf interface to kprobes: listing, adding and removing probes. It
is run as a part of perftool-testsuite_probe test case.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/tests/shell/base_probe/settings.sh |  48 +++
 .../shell/base_probe/test_adding_kernel.sh    | 278 ++++++++++++++++++
 2 files changed, 326 insertions(+)
 create mode 100644 tools/perf/tests/shell/base_probe/settings.sh
 create mode 100755 tools/perf/tests/shell/base_probe/test_adding_kernel.sh

diff --git a/tools/perf/tests/shell/base_probe/settings.sh b/tools/perf/tests/shell/base_probe/settings.sh
new file mode 100644
index 000000000000..123621c7f95e
--- /dev/null
+++ b/tools/perf/tests/shell/base_probe/settings.sh
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+#	settings.sh of perf_probe test
+#	Author: Michael Petlan <mpetlan@redhat.com>
+#	Author: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
+#
+
+export TEST_NAME="perf_probe"
+
+export MY_ARCH=`arch`
+
+if [ -n "$PERFSUITE_RUN_DIR" ]; then
+	# when $PERFSUITE_RUN_DIR is set to something, all the logs and temp files will be placed there
+	# --> the $PERFSUITE_RUN_DIR/perf_something/examples and $PERFSUITE_RUN_DIR/perf_something/logs
+	#     dirs will be used for that
+	export PERFSUITE_RUN_DIR=`readlink -f $PERFSUITE_RUN_DIR`
+	export CURRENT_TEST_DIR="$PERFSUITE_RUN_DIR/$TEST_NAME"
+	export MAKE_TARGET_DIR="$CURRENT_TEST_DIR/examples"
+	test -d "$MAKE_TARGET_DIR" || mkdir -p "$MAKE_TARGET_DIR"
+	export LOGS_DIR="$PERFSUITE_RUN_DIR/$TEST_NAME/logs"
+	test -d "$LOGS_DIR" || mkdir -p "$LOGS_DIR"
+else
+	# when $PERFSUITE_RUN_DIR is not set, logs will be placed here
+	export CURRENT_TEST_DIR="."
+	export LOGS_DIR="."
+fi
+
+check_kprobes_available()
+{
+	test -e /sys/kernel/debug/tracing/kprobe_events
+}
+
+check_uprobes_available()
+{
+	test -e /sys/kernel/debug/tracing/uprobe_events
+}
+
+clear_all_probes()
+{
+	echo 0 > /sys/kernel/debug/tracing/events/enable
+	check_kprobes_available && echo > /sys/kernel/debug/tracing/kprobe_events
+	check_uprobes_available && echo > /sys/kernel/debug/tracing/uprobe_events
+}
+
+check_sdt_support()
+{
+	$CMD_PERF list sdt | grep sdt > /dev/null 2> /dev/null
+}
diff --git a/tools/perf/tests/shell/base_probe/test_adding_kernel.sh b/tools/perf/tests/shell/base_probe/test_adding_kernel.sh
new file mode 100755
index 000000000000..a5d707efad85
--- /dev/null
+++ b/tools/perf/tests/shell/base_probe/test_adding_kernel.sh
@@ -0,0 +1,278 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+#
+#	test_adding_kernel of perf_probe test
+#	Author: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
+#	Author: Michael Petlan <mpetlan@redhat.com>
+#
+#	Description:
+#
+#		This test tests adding of probes, their correct listing
+#		and removing.
+#
+
+# include working environment
+. ../common/init.sh
+. ./settings.sh
+
+# shellcheck disable=SC2034 # the variable is later used after the working environment is included
+THIS_TEST_NAME=`basename $0 .sh`
+TEST_RESULT=0
+
+TEST_PROBE=${TEST_PROBE:-"inode_permission"}
+
+check_kprobes_available
+if [ $? -ne 0 ]; then
+	print_overall_skipped
+	exit 0
+fi
+
+
+### basic probe adding
+
+for opt in "" "-a" "--add"; do
+	clear_all_probes
+	$CMD_PERF probe $opt $TEST_PROBE 2> $LOGS_DIR/adding_kernel_add$opt.err
+	PERF_EXIT_CODE=$?
+
+	../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_add$opt.err
+	CHECK_EXIT_CODE=$?
+
+	print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "adding probe $TEST_PROBE :: $opt"
+	(( TEST_RESULT += $? ))
+done
+
+
+### listing added probe :: perf list
+
+# any added probes should appear in perf-list output
+$CMD_PERF list probe:\* > $LOGS_DIR/adding_kernel_list.log
+PERF_EXIT_CODE=$?
+
+../common/check_all_lines_matched.pl "$RE_LINE_EMPTY" "List of pre-defined events" "probe:${TEST_PROBE}(?:_\d+)?\s+\[Tracepoint event\]" "Metric Groups:" < $LOGS_DIR/adding_kernel_list.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing added probe :: perf list"
+(( TEST_RESULT += $? ))
+
+
+### listing added probe :: perf probe -l
+
+# '-l' should list all the added probes as well
+$CMD_PERF probe -l > $LOGS_DIR/adding_kernel_list-l.log
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "\s*probe:${TEST_PROBE}(?:_\d+)?\s+\(on ${TEST_PROBE}(?:[:\+]$RE_NUMBER_HEX)?@.+\)" < $LOGS_DIR/adding_kernel_list-l.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing added probe :: perf probe -l"
+(( TEST_RESULT += $? ))
+
+
+### using added probe
+
+$CMD_PERF stat -e probe:$TEST_PROBE\* -o $LOGS_DIR/adding_kernel_using_probe.log -- cat /proc/uptime > /dev/null
+PERF_EXIT_CODE=$?
+
+REGEX_STAT_HEADER="\s*Performance counter stats for \'cat /proc/uptime\':"
+REGEX_STAT_VALUES="\s*\d+\s+probe:$TEST_PROBE"
+# the value should be greater than 1
+REGEX_STAT_VALUE_NONZERO="\s*[1-9][0-9]*\s+probe:$TEST_PROBE"
+REGEX_STAT_TIME="\s*$RE_NUMBER\s+seconds (?:time elapsed|user|sys)"
+../common/check_all_lines_matched.pl "$REGEX_STAT_HEADER" "$REGEX_STAT_VALUES" "$REGEX_STAT_TIME" "$RE_LINE_COMMENT" "$RE_LINE_EMPTY" < $LOGS_DIR/adding_kernel_using_probe.log
+CHECK_EXIT_CODE=$?
+../common/check_all_patterns_found.pl "$REGEX_STAT_HEADER" "$REGEX_STAT_VALUE_NONZERO" "$REGEX_STAT_TIME" < $LOGS_DIR/adding_kernel_using_probe.log
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "using added probe"
+(( TEST_RESULT += $? ))
+
+
+### removing added probe
+
+# '-d' should remove the probe
+$CMD_PERF probe -d $TEST_PROBE\* 2> $LOGS_DIR/adding_kernel_removing.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_lines_matched.pl "Removed event: probe:$TEST_PROBE" < $LOGS_DIR/adding_kernel_removing.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "deleting added probe"
+(( TEST_RESULT += $? ))
+
+
+### listing removed probe
+
+# removed probes should NOT appear in perf-list output
+$CMD_PERF list probe:\* > $LOGS_DIR/adding_kernel_list_removed.log
+PERF_EXIT_CODE=$?
+
+../common/check_all_lines_matched.pl "$RE_LINE_EMPTY" "List of pre-defined events" "Metric Groups:" < $LOGS_DIR/adding_kernel_list_removed.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing removed probe (should NOT be listed)"
+(( TEST_RESULT += $? ))
+
+
+### dry run
+
+# the '-n' switch should run it in dry mode
+$CMD_PERF probe -n --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_dryrun.err
+PERF_EXIT_CODE=$?
+
+# check for the output (should be the same as usual)
+../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_dryrun.err
+CHECK_EXIT_CODE=$?
+
+# check that no probe was added in real
+! ( $CMD_PERF probe -l | grep "probe:$TEST_PROBE" )
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "dry run :: adding probe"
+(( TEST_RESULT += $? ))
+
+
+### force-adding probes
+
+# when using '--force' a probe should be added even if it is already there
+$CMD_PERF probe --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_forceadd_01.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_forceadd_01.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "force-adding probes :: first probe adding"
+(( TEST_RESULT += $? ))
+
+# adding existing probe without '--force' should fail
+! $CMD_PERF probe --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_forceadd_02.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "Error: event \"$TEST_PROBE\" already exists." "Error: Failed to add events." < $LOGS_DIR/adding_kernel_forceadd_02.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "force-adding probes :: second probe adding (without force)"
+(( TEST_RESULT += $? ))
+
+# adding existing probe with '--force' should pass
+NO_OF_PROBES=`$CMD_PERF probe -l | wc -l`
+$CMD_PERF probe --force --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_forceadd_03.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "Added new events?:" "probe:${TEST_PROBE}_${NO_OF_PROBES}" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_forceadd_03.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "force-adding probes :: second probe adding (with force)"
+(( TEST_RESULT += $? ))
+
+
+### using doubled probe
+
+# since they are the same, they should produce the same results
+$CMD_PERF stat -e probe:$TEST_PROBE -e probe:${TEST_PROBE}_${NO_OF_PROBES} -x';' -o $LOGS_DIR/adding_kernel_using_two.log -- bash -c 'cat /proc/cpuinfo > /dev/null'
+PERF_EXIT_CODE=$?
+
+REGEX_LINE="$RE_NUMBER;+probe:${TEST_PROBE}_?(?:$NO_OF_PROBES)?;$RE_NUMBER;$RE_NUMBER"
+../common/check_all_lines_matched.pl "$REGEX_LINE" "$RE_LINE_EMPTY" "$RE_LINE_COMMENT" < $LOGS_DIR/adding_kernel_using_two.log
+CHECK_EXIT_CODE=$?
+
+VALUE_1=`grep "$TEST_PROBE;" $LOGS_DIR/adding_kernel_using_two.log | awk -F';' '{print $1}'`
+VALUE_2=`grep "${TEST_PROBE}_${NO_OF_PROBES};" $LOGS_DIR/adding_kernel_using_two.log | awk -F';' '{print $1}'`
+
+test $VALUE_1 -eq $VALUE_2
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "using doubled probe"
+
+
+### removing multiple probes
+
+# using wildcards should remove all matching probes
+$CMD_PERF probe --del \* 2> $LOGS_DIR/adding_kernel_removing_wildcard.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_lines_matched.pl "Removed event: probe:$TEST_PROBE" "Removed event: probe:${TEST_PROBE}_1" < $LOGS_DIR/adding_kernel_removing_wildcard.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "removing multiple probes"
+(( TEST_RESULT += $? ))
+
+
+### wildcard adding support
+
+$CMD_PERF probe -nf --max-probes=512 -a 'vfs_* $params' 2> $LOGS_DIR/adding_kernel_adding_wildcard.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "probe:vfs_mknod" "probe:vfs_create" "probe:vfs_rmdir" "probe:vfs_link" "probe:vfs_write" < $LOGS_DIR/adding_kernel_adding_wildcard.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "wildcard adding support"
+(( TEST_RESULT += $? ))
+
+
+### non-existing variable
+
+# perf probe should survive a non-existing variable probing attempt
+{ $CMD_PERF probe 'vfs_read somenonexistingrandomstuffwhichisalsoprettylongorevenlongertoexceed64' ; } 2> $LOGS_DIR/adding_kernel_nonexisting.err
+PERF_EXIT_CODE=$?
+
+# the exitcode should not be 0 or segfault
+test $PERF_EXIT_CODE -ne 139 -a $PERF_EXIT_CODE -ne 0
+PERF_EXIT_CODE=$?
+
+# check that the error message is reasonable
+../common/check_all_patterns_found.pl "Failed to find" "somenonexistingrandomstuffwhichisalsoprettylongorevenlongertoexceed64" < $LOGS_DIR/adding_kernel_nonexisting.err
+CHECK_EXIT_CODE=$?
+../common/check_all_patterns_found.pl "in this function|at this address" "Error" "Failed to add events" < $LOGS_DIR/adding_kernel_nonexisting.err
+(( CHECK_EXIT_CODE += $? ))
+../common/check_all_lines_matched.pl "Failed to find" "Error" "Probe point .+ not found" "optimized out" "Use.+\-\-range option to show.+location range" < $LOGS_DIR/adding_kernel_nonexisting.err
+(( CHECK_EXIT_CODE += $? ))
+../common/check_no_patterns_found.pl "$RE_SEGFAULT" < $LOGS_DIR/adding_kernel_nonexisting.err
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "non-existing variable"
+(( TEST_RESULT += $? ))
+
+
+### function with return value
+
+# adding probe with return value
+$CMD_PERF probe --add "$TEST_PROBE%return \$retval" 2> $LOGS_DIR/adding_kernel_func_retval_add.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE%return with \\\$retval" < $LOGS_DIR/adding_kernel_func_retval_add.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "function with retval :: add"
+(( TEST_RESULT += $? ))
+
+# recording some data
+$CMD_PERF record -e probe:$TEST_PROBE\* -o $CURRENT_TEST_DIR/perf.data -- cat /proc/cpuinfo > /dev/null 2> $LOGS_DIR/adding_kernel_func_retval_record.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/adding_kernel_func_retval_record.err
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "function with retval :: record"
+(( TEST_RESULT += $? ))
+
+# perf script should report the function calls with the correct arg values
+$CMD_PERF script -i $CURRENT_TEST_DIR/perf.data > $LOGS_DIR/adding_kernel_func_retval_script.log
+PERF_EXIT_CODE=$?
+
+REGEX_SCRIPT_LINE="\s*cat\s+$RE_NUMBER\s+\[$RE_NUMBER\]\s+$RE_NUMBER:\s+probe:$TEST_PROBE\w*:\s+\($RE_NUMBER_HEX\s+<\-\s+$RE_NUMBER_HEX\)\s+arg1=$RE_NUMBER_HEX"
+../common/check_all_lines_matched.pl "$REGEX_SCRIPT_LINE" < $LOGS_DIR/adding_kernel_func_retval_script.log
+CHECK_EXIT_CODE=$?
+../common/check_all_patterns_found.pl "$REGEX_SCRIPT_LINE" < $LOGS_DIR/adding_kernel_func_retval_script.log
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "function argument probing :: script"
+(( TEST_RESULT += $? ))
+
+
+clear_all_probes
+
+# print overall results
+print_overall_results "$TEST_RESULT"
+exit $?
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 7/7] perf testsuite: Install kprobe tests and common files
  2024-02-15 11:02 ` [PATCH v2 0/7] Add perf testsuite into perf-test Michael Petlan
                     ` (5 preceding siblings ...)
  2024-02-15 11:02   ` [PATCH v2 6/7] perf testsuite: Add test for kprobe handling Michael Petlan
@ 2024-02-15 11:02   ` Michael Petlan
  2024-02-21  1:58   ` [PATCH v2 0/7] Add perf testsuite into perf-test Namhyung Kim
  7 siblings, 0 replies; 23+ messages in thread
From: Michael Petlan @ 2024-02-15 11:02 UTC (permalink / raw)
  To: linux-perf-users, acme
  Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, atrajeev, kjain

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/Makefile.perf | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index f8774a9b1377..8ba6399b8c99 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -1048,6 +1048,11 @@ install-tests: all install-gtk
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
 		$(INSTALL) tests/shell/lib/*.sh -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
 		$(INSTALL) tests/shell/lib/*.py -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
+		$(INSTALL) tests/shell/common/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
+		$(INSTALL) tests/shell/common/*.pl '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
+		$(INSTALL) tests/shell/base_probe/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/coresight' ; \
 		$(INSTALL) tests/shell/coresight/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/coresight'
 	$(Q)$(MAKE) -C tests/shell/coresight install-tests
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 0/7] Add perf testsuite into perf-test
  2024-02-15 11:02 ` [PATCH v2 0/7] Add perf testsuite into perf-test Michael Petlan
                     ` (6 preceding siblings ...)
  2024-02-15 11:02   ` [PATCH v2 7/7] perf testsuite: Install kprobe tests and common files Michael Petlan
@ 2024-02-21  1:58   ` Namhyung Kim
  7 siblings, 0 replies; 23+ messages in thread
From: Namhyung Kim @ 2024-02-21  1:58 UTC (permalink / raw)
  To: Michael Petlan, linux-perf-users, acme
  Cc: mingo, adrian.hunter, alexander.shishkin, jolsa, peterz,
	mark.rutland, atrajeev, kjain, irogers, acme

On Thu, 15 Feb 2024 12:02:24 +0100, Michael Petlan wrote:
> as Arnaldo said, this is a first patchset of an effort to upstream
> the external perftool-testsuite [1] and merge it into perf-test.
> 
> The perftool-testsuite originates back to 2015, when there were no
> shell-based testcases for perf. At that point, perf-test contained
> rather "unit-tests" and there was a need to test perf as a tool too.
> 
> [...]

Applied to perf-tools-next.  Looking forward to seeing more tests!

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2024-02-21  1:58 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-31 11:39 [PATCH 1/7] perf testsuite: Add common regex patters Michael Petlan
2024-01-31 11:39 ` [PATCH 2/7] perf testsuite: Add common setting for shell tests Michael Petlan
2024-01-31 11:39 ` [PATCH 3/7] perf testsuite: Add initialization script " Michael Petlan
2024-01-31 11:39 ` [PATCH 4/7] perf testsuite: Add test case for perf probe Michael Petlan
2024-01-31 11:39 ` [PATCH 5/7] perf testsuite: Add common output checking helpers Michael Petlan
2024-01-31 11:39 ` [PATCH 6/7] perf testsuite: Add test for kprobe handling Michael Petlan
2024-01-31 11:39 ` [PATCH 7/7] perf testsuite: Install kprobe tests and common files Michael Petlan
2024-01-31 13:47 ` [PATCH 1/7] perf testsuite: Add common regex patters Arnaldo Carvalho de Melo
2024-01-31 13:53   ` Arnaldo Carvalho de Melo
2024-02-01 23:59   ` Namhyung Kim
2024-02-02  0:05 ` Namhyung Kim
2024-02-08 16:49   ` Michael Petlan
2024-02-09  7:13     ` Namhyung Kim
2024-02-09 22:56       ` Namhyung Kim
2024-02-15 11:02 ` [PATCH v2 0/7] Add perf testsuite into perf-test Michael Petlan
2024-02-15 11:02   ` [PATCH v2 1/7] perf testsuite: Add common regex patters Michael Petlan
2024-02-15 11:02   ` [PATCH v2 2/7] perf testsuite: Add common setting for shell tests Michael Petlan
2024-02-15 11:02   ` [PATCH v2 3/7] perf testsuite: Add initialization script " Michael Petlan
2024-02-15 11:02   ` [PATCH v2 4/7] perf testsuite: Add test case for perf probe Michael Petlan
2024-02-15 11:02   ` [PATCH v2 5/7] perf testsuite: Add common output checking helpers Michael Petlan
2024-02-15 11:02   ` [PATCH v2 6/7] perf testsuite: Add test for kprobe handling Michael Petlan
2024-02-15 11:02   ` [PATCH v2 7/7] perf testsuite: Install kprobe tests and common files Michael Petlan
2024-02-21  1:58   ` [PATCH v2 0/7] Add perf testsuite into perf-test Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).