linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Petlan <mpetlan@redhat.com>
To: linux-perf-users@vger.kernel.org, vmolnaro@redhat.com,
	acme@redhat.com, acme@kernel.org
Cc: mhiramat@kernel.org
Subject: [PATCH 5/7] perf testsuite: Add common output checking helpers
Date: Wed, 31 Jan 2024 12:39:49 +0100	[thread overview]
Message-ID: <20240131113951.17077-5-mpetlan@redhat.com> (raw)
In-Reply-To: <20240131113951.17077-1-mpetlan@redhat.com>

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


  parent reply	other threads:[~2024-01-31 11:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Michael Petlan [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240131113951.17077-5-mpetlan@redhat.com \
    --to=mpetlan@redhat.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=vmolnaro@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).