2017-06-22 07:36:38

by Thomas-Mich Richter

[permalink] [raw]
Subject: [PATCH] [PATCH v2] perf test: add platform dependency to test 15

This patch adds platform dependency into the
test case 15 (perf_event_attr). It is based on a suggestion from
Jiri Olsa.
Add a new optional attribute named 'arch' in the [config] section
of the test case file. It is a comma separated list of architecture
names this test can be executed on. For example:

arch = x86_64,alpha,ppc

If this attribute is missing the test is executed on any platform.
This does not break existing behavior.
The values listed for this attribute should be identical to
uname -m output.
If the list starts with an exclamation mark (!) the comparison is
inverted, for example for

arch = !s390x,ppc

the test is not executed on s390x or ppc platforms.
The exclamation mark must be at the beginnning of the list.

Here is an example debug output:
[root@s35lp76]# fgrep arch tests/attr/test-stat-C2
arch = x86_64,alpha,ppc
[root@s35lp76]# PERF_TEST_ATTR=/tmp /usr/bin/python2 ./tests/attr.py \
-d ./tests/attr/ -p ./perf -vvvvv -t test-stat-C1

provides the following output:

running './tests/attr//test-stat-C1'
test limitation 'x86_64,alpha,ppc' <--- new
loading expected events
Event event:base-stat
fd = 1
group_fd = -1
.....

Here is the output when a test is skipped:
[root@s35lp76]# fgrep arch tests/attr/test-stat-C1
arch = !s390x
[root@s35lp76]# PERF_TEST_ATTR=/tmp /usr/bin/python2 ./tests/attr.py \
-d ./tests/attr/ -p ./perf -vvvvv -t test-stat-C1

provides the following output:
test limitation '!s390x' <--- new

skipped [s390x] './tests/attr//test-stat-C1' <--- new

The test is skipped with return code 0.

Suggested-by: Jiri Olsa <[email protected]>
Signed-off-by: Thomas Richter <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Reviwed-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/tests/attr.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)

diff --git a/tools/perf/tests/attr.py b/tools/perf/tests/attr.py
index 1091bd4..cdf21a9 100644
--- a/tools/perf/tests/attr.py
+++ b/tools/perf/tests/attr.py
@@ -16,6 +16,13 @@ class Fail(Exception):
def getMsg(self):
return '\'%s\' - %s' % (self.test.path, self.msg)

+class Notest(Exception):
+ def __init__(self, test, arch):
+ self.arch = arch
+ self.test = test
+ def getMsg(self):
+ return '[%s] \'%s\'' % (self.arch, self.test.path)
+
class Unsup(Exception):
def __init__(self, test):
self.test = test
@@ -112,6 +119,9 @@ class Event(dict):
# 'command' - perf command name
# 'args' - special command arguments
# 'ret' - expected command return value (0 by default)
+# 'arch' - architecture specific test (optional)
+# comma separated list, ! at the beginning
+# negates it.
#
# [eventX:base]
# - one or multiple instances in file
@@ -134,6 +144,12 @@ class Test(object):
except:
self.ret = 0

+ try:
+ self.arch = parser.get('config', 'arch')
+ log.warning("test limitation '%s'" % self.arch)
+ except:
+ self.arch = ''
+
self.expect = {}
self.result = {}
log.debug(" loading expected events");
@@ -145,6 +161,31 @@ class Test(object):
else:
return True

+ def skip_test(self, myarch):
+ # If architecture not set always run test
+ if self.arch == '':
+ # log.warning("test for arch %s is ok" % myarch)
+ return False
+
+ # Allow multiple values in assignment separated by ','
+ arch_list = self.arch.split(',')
+
+ # Handle negated list such as !s390x,ppc
+ if arch_list[0][0] == '!':
+ arch_list[0] = arch_list[0][1:]
+ log.warning("excluded architecture list %s" % arch_list)
+ for arch_item in arch_list:
+ # log.warning("test for %s arch is %s" % (arch_item, myarch))
+ if arch_item == myarch:
+ return True
+ return False
+
+ for arch_item in arch_list:
+ # log.warning("test for architecture '%s' current '%s'" % (arch_item, myarch))
+ if arch_item == myarch:
+ return False
+ return True
+
def load_events(self, path, events):
parser_event = ConfigParser.SafeConfigParser()
parser_event.read(path)
@@ -168,6 +209,11 @@ class Test(object):
events[section] = e

def run_cmd(self, tempdir):
+ junk1, junk2, junk3, junk4, myarch = (os.uname())
+
+ if self.skip_test(myarch):
+ raise Notest(self, myarch)
+
cmd = "PERF_TEST_ATTR=%s %s %s -o %s/perf.data %s" % (tempdir,
self.perf, self.command, tempdir, self.args)
ret = os.WEXITSTATUS(os.system(cmd))
@@ -265,6 +311,8 @@ def run_tests(options):
Test(f, options).run()
except Unsup, obj:
log.warning("unsupp %s" % obj.getMsg())
+ except Notest, obj:
+ log.warning("skipped %s" % obj.getMsg())

def setup_log(verbose):
global log
--
2.9.3


2017-06-26 22:58:40

by Jiri Olsa

[permalink] [raw]
Subject: Re: [PATCH] [PATCH v2] perf test: add platform dependency to test 15

On Thu, Jun 22, 2017 at 09:36:25AM +0200, Thomas Richter wrote:
> This patch adds platform dependency into the
> test case 15 (perf_event_attr). It is based on a suggestion from
> Jiri Olsa.
> Add a new optional attribute named 'arch' in the [config] section
> of the test case file. It is a comma separated list of architecture
> names this test can be executed on. For example:
>
> arch = x86_64,alpha,ppc
>
> If this attribute is missing the test is executed on any platform.
> This does not break existing behavior.
> The values listed for this attribute should be identical to
> uname -m output.
> If the list starts with an exclamation mark (!) the comparison is
> inverted, for example for
>
> arch = !s390x,ppc
>
> the test is not executed on s390x or ppc platforms.
> The exclamation mark must be at the beginnning of the list.
>
> Here is an example debug output:
> [root@s35lp76]# fgrep arch tests/attr/test-stat-C2
> arch = x86_64,alpha,ppc
> [root@s35lp76]# PERF_TEST_ATTR=/tmp /usr/bin/python2 ./tests/attr.py \
> -d ./tests/attr/ -p ./perf -vvvvv -t test-stat-C1
>
> provides the following output:
>
> running './tests/attr//test-stat-C1'
> test limitation 'x86_64,alpha,ppc' <--- new
> loading expected events
> Event event:base-stat
> fd = 1
> group_fd = -1
> .....
>
> Here is the output when a test is skipped:
> [root@s35lp76]# fgrep arch tests/attr/test-stat-C1
> arch = !s390x
> [root@s35lp76]# PERF_TEST_ATTR=/tmp /usr/bin/python2 ./tests/attr.py \
> -d ./tests/attr/ -p ./perf -vvvvv -t test-stat-C1
>
> provides the following output:
> test limitation '!s390x' <--- new
>
> skipped [s390x] './tests/attr//test-stat-C1' <--- new
>
> The test is skipped with return code 0.
>
> Suggested-by: Jiri Olsa <[email protected]>
> Signed-off-by: Thomas Richter <[email protected]>
> Reviewed-by: Jiri Olsa <[email protected]>
> Reviwed-by: Arnaldo Carvalho de Melo <[email protected]>

Acked-by: Jiri Olsa <[email protected]>

sorry for delay, I finished my attr tests fixes, you can check
them in my perf/attr_test_2 branch.. still need to write changelogs ;-)

it passes for me now, however we still might need few fixes
due to different HW and supported events.. could you please
test that on your system?

I'll post the changes soon

thanks,
jirka

2017-06-27 00:44:40

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] [PATCH v2] perf test: add platform dependency to test 15

Em Tue, Jun 27, 2017 at 12:58:29AM +0200, Jiri Olsa escreveu:
> On Thu, Jun 22, 2017 at 09:36:25AM +0200, Thomas Richter wrote:
> > This patch adds platform dependency into the
> > test case 15 (perf_event_attr). It is based on a suggestion from
> > Jiri Olsa.
> > Add a new optional attribute named 'arch' in the [config] section
> > of the test case file. It is a comma separated list of architecture
> > names this test can be executed on. For example:
> >
> > arch = x86_64,alpha,ppc
> >
> > If this attribute is missing the test is executed on any platform.
> > This does not break existing behavior.
> > The values listed for this attribute should be identical to
> > uname -m output.
> > If the list starts with an exclamation mark (!) the comparison is
> > inverted, for example for
> >
> > arch = !s390x,ppc
> >
> > the test is not executed on s390x or ppc platforms.
> > The exclamation mark must be at the beginnning of the list.
> >
> > Here is an example debug output:
> > [root@s35lp76]# fgrep arch tests/attr/test-stat-C2
> > arch = x86_64,alpha,ppc
> > [root@s35lp76]# PERF_TEST_ATTR=/tmp /usr/bin/python2 ./tests/attr.py \
> > -d ./tests/attr/ -p ./perf -vvvvv -t test-stat-C1
> >
> > provides the following output:
> >
> > running './tests/attr//test-stat-C1'
> > test limitation 'x86_64,alpha,ppc' <--- new
> > loading expected events
> > Event event:base-stat
> > fd = 1
> > group_fd = -1
> > .....
> >
> > Here is the output when a test is skipped:
> > [root@s35lp76]# fgrep arch tests/attr/test-stat-C1
> > arch = !s390x
> > [root@s35lp76]# PERF_TEST_ATTR=/tmp /usr/bin/python2 ./tests/attr.py \
> > -d ./tests/attr/ -p ./perf -vvvvv -t test-stat-C1
> >
> > provides the following output:
> > test limitation '!s390x' <--- new
> >
> > skipped [s390x] './tests/attr//test-stat-C1' <--- new
> >
> > The test is skipped with return code 0.
> >
> > Suggested-by: Jiri Olsa <[email protected]>
> > Signed-off-by: Thomas Richter <[email protected]>
> > Reviewed-by: Jiri Olsa <[email protected]>
> > Reviwed-by: Arnaldo Carvalho de Melo <[email protected]>
>
> Acked-by: Jiri Olsa <[email protected]>
>
> sorry for delay, I finished my attr tests fixes, you can check
> them in my perf/attr_test_2 branch.. still need to write changelogs ;-)
>
> it passes for me now, however we still might need few fixes
> due to different HW and supported events.. could you please
> test that on your system?
>
> I'll post the changes soon

Thanks, applied.

- Arnaldo

Subject: [tip:perf/core] perf tests: Add platform dependency to test 15

Commit-ID: 19508c048a2f90facb64624340bf1b7ee555442e
Gitweb: http://git.kernel.org/tip/19508c048a2f90facb64624340bf1b7ee555442e
Author: Thomas Richter <[email protected]>
AuthorDate: Thu, 22 Jun 2017 09:36:25 +0200
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 26 Jun 2017 21:42:00 -0300

perf tests: Add platform dependency to test 15

This patch adds platform dependency into the test case 15
(perf_event_attr). It is based on a suggestion from Jiri Olsa.

Add a new optional attribute named 'arch' in the [config] section of the
test case file. It is a comma separated list of architecture names this
test can be executed on. For example:

arch = x86_64,alpha,ppc

If this attribute is missing the test is executed on any platform. This
does not break existing behavior.

The values listed for this attribute should be identical to uname -m
output.

If the list starts with an exclamation mark (!) the comparison is
inverted, for example for

arch = !s390x,ppc

the test is not executed on s390x or ppc platforms. The exclamation
mark must be at the beginnning of the list.

Here is an example debug output:

[root@s35lp76]# fgrep arch tests/attr/test-stat-C2
arch = x86_64,alpha,ppc
[root@s35lp76]# PERF_TEST_ATTR=/tmp /usr/bin/python2 ./tests/attr.py \
-d ./tests/attr/ -p ./perf -vvvvv -t test-stat-C1

provides the following output:

running './tests/attr//test-stat-C1'
test limitation 'x86_64,alpha,ppc' <--- new
loading expected events
Event event:base-stat
fd = 1
group_fd = -1
.....

Here is the output when a test is skipped:

[root@s35lp76]# fgrep arch tests/attr/test-stat-C1
arch = !s390x
[root@s35lp76]# PERF_TEST_ATTR=/tmp /usr/bin/python2 ./tests/attr.py \
-d ./tests/attr/ -p ./perf -vvvvv -t test-stat-C1

provides the following output:

test limitation '!s390x' <--- new

skipped [s390x] './tests/attr//test-stat-C1' <--- new

The test is skipped with return code 0.

Suggested-and-Acked-by: Jiri Olsa <[email protected]>
Reviewed-by: Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by: Thomas Richter <[email protected]>
Cc: Hendrik Brueckner <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/tests/attr.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)

diff --git a/tools/perf/tests/attr.py b/tools/perf/tests/attr.py
index 1091bd4..cdf21a9 100644
--- a/tools/perf/tests/attr.py
+++ b/tools/perf/tests/attr.py
@@ -16,6 +16,13 @@ class Fail(Exception):
def getMsg(self):
return '\'%s\' - %s' % (self.test.path, self.msg)

+class Notest(Exception):
+ def __init__(self, test, arch):
+ self.arch = arch
+ self.test = test
+ def getMsg(self):
+ return '[%s] \'%s\'' % (self.arch, self.test.path)
+
class Unsup(Exception):
def __init__(self, test):
self.test = test
@@ -112,6 +119,9 @@ class Event(dict):
# 'command' - perf command name
# 'args' - special command arguments
# 'ret' - expected command return value (0 by default)
+# 'arch' - architecture specific test (optional)
+# comma separated list, ! at the beginning
+# negates it.
#
# [eventX:base]
# - one or multiple instances in file
@@ -134,6 +144,12 @@ class Test(object):
except:
self.ret = 0

+ try:
+ self.arch = parser.get('config', 'arch')
+ log.warning("test limitation '%s'" % self.arch)
+ except:
+ self.arch = ''
+
self.expect = {}
self.result = {}
log.debug(" loading expected events");
@@ -145,6 +161,31 @@ class Test(object):
else:
return True

+ def skip_test(self, myarch):
+ # If architecture not set always run test
+ if self.arch == '':
+ # log.warning("test for arch %s is ok" % myarch)
+ return False
+
+ # Allow multiple values in assignment separated by ','
+ arch_list = self.arch.split(',')
+
+ # Handle negated list such as !s390x,ppc
+ if arch_list[0][0] == '!':
+ arch_list[0] = arch_list[0][1:]
+ log.warning("excluded architecture list %s" % arch_list)
+ for arch_item in arch_list:
+ # log.warning("test for %s arch is %s" % (arch_item, myarch))
+ if arch_item == myarch:
+ return True
+ return False
+
+ for arch_item in arch_list:
+ # log.warning("test for architecture '%s' current '%s'" % (arch_item, myarch))
+ if arch_item == myarch:
+ return False
+ return True
+
def load_events(self, path, events):
parser_event = ConfigParser.SafeConfigParser()
parser_event.read(path)
@@ -168,6 +209,11 @@ class Test(object):
events[section] = e

def run_cmd(self, tempdir):
+ junk1, junk2, junk3, junk4, myarch = (os.uname())
+
+ if self.skip_test(myarch):
+ raise Notest(self, myarch)
+
cmd = "PERF_TEST_ATTR=%s %s %s -o %s/perf.data %s" % (tempdir,
self.perf, self.command, tempdir, self.args)
ret = os.WEXITSTATUS(os.system(cmd))
@@ -265,6 +311,8 @@ def run_tests(options):
Test(f, options).run()
except Unsup, obj:
log.warning("unsupp %s" % obj.getMsg())
+ except Notest, obj:
+ log.warning("skipped %s" % obj.getMsg())

def setup_log(verbose):
global log