Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions perf/perf_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import re
import tempfile
from avocado import Test
from avocado.utils import process, distro, dmesg
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils import process, dmesg
from avocado.utils.software_manager.distro_packages import ensure_tool


class PerfBasic(Test):
Expand Down Expand Up @@ -59,28 +59,25 @@ def run_cmd(self, cmd, verbose=True):
'Segmentation fault'])

def setUp(self):
smg = SoftwareManager()
dist = distro.detect()
if dist.name in ['Ubuntu']:
linux_tools = "linux-tools-" + os.uname()[2]
pkgs = [linux_tools]
if dist.name in ['Ubuntu']:
pkgs.extend(['linux-tools-common'])
elif dist.name in ['debian']:
pkgs = ['linux-perf']
elif dist.name in ['centos', 'fedora', 'rhel', 'SuSE']:
pkgs = ['perf']
else:
self.cancel("perf is not supported on %s" % dist.name)
perf_path = self.params.get('perf_bin', default='')
distro_pkg_map = {
"Ubuntu": [f"linux-tools-{os.uname()[2]}", "linux-tools-common", "gcc", "make"],
"debian": ["linux-perf"],
"centos": ["perf"],
"fedora": ["perf"],
"rhel": ["perf"],
"SuSE": ["perf"],
}
try:
perf_version = ensure_tool("perf", custom_path=perf_path, distro_pkg_map=distro_pkg_map)
self.log.info(f"Perf version: {perf_version}")
self.perf_bin = perf_path if perf_path else "perf"
except RuntimeError as e:
self.cancel(str(e))

self.temp_file = tempfile.NamedTemporaryFile().name
dmesg.clear_dmesg()

for pkg in pkgs:
if not smg.check_installed(pkg) and not smg.install(pkg):
self.cancel(
"Package %s is missing/could not be installed" % pkg)

def test_perf_help(self):
self.run_cmd("perf --help", False)

Expand Down
1 change: 1 addition & 0 deletions perf/perf_basic.py.data/perf_basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perf_bin: '/tmp/perf'
36 changes: 18 additions & 18 deletions perf/perf_duplicate_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# Copyright: 2019 IBM
# Author: Shirisha G <shiganta@in.ibm.com>

import platform
import os
from avocado import Test
from avocado.utils import distro, genio, process
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils import process, genio
from avocado.utils.software_manager.distro_packages import ensure_tool


class PerfDuplicateProbe(Test):
Expand All @@ -27,21 +27,21 @@ def setUp(self):
Install the basic packages to support perf and systemtap-sdt-devel
'''
# Check for basic utilities
smm = SoftwareManager()
distro_name = distro.detect().name
deps = []
run_type = self.params.get('type', default='distro')
if 'Ubuntu' in distro_name:
deps.extend(['linux-tools-common', 'linux-tools-%s' %
platform.uname()[2]])
elif distro_name in ['rhel', 'SuSE', 'fedora', 'centos']:
deps.extend(['perf'])
else:
self.cancel("Install the package for perf supported\
by %s" % distro_name)
for package in deps:
if not smm.check_installed(package) and not smm.install(package):
self.cancel('%s is needed for the test to be run' % package)
perf_path = self.params.get('perf_bin', default='')
distro_pkg_map = {
"Ubuntu": [f"linux-tools-{os.uname()[2]}", "linux-tools-common", "gcc", "make"],
"debian": ["linux-perf"],
"centos": ["perf"],
"fedora": ["perf"],
"rhel": ["perf"],
"SuSE": ["perf"],
}
try:
perf_version = ensure_tool("perf", custom_path=perf_path, distro_pkg_map=distro_pkg_map)
self.log.info(f"Perf version: {perf_version}")
self.perf_bin = perf_path if perf_path else "perf"
except RuntimeError as e:
self.cancel(str(e))
self.fail_flag = False

def _check_duplicate_probe(self, outpt):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perf_bin: '/tmp/perf'
35 changes: 17 additions & 18 deletions perf/perf_events_crash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
# Author:Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
#

import platform
import os
from avocado import Test
from avocado.utils import archive, build, process, distro
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils import archive, build, process
from avocado.utils.software_manager.distro_packages import ensure_tool


class Perf_crashevent(Test):
Expand All @@ -40,21 +39,21 @@ def setUp(self):
Install the packages
'''
# Check for basic utilities
smm = SoftwareManager()
detected_distro = distro.detect()
deps = ['gcc', 'make']
if 'Ubuntu' in detected_distro.name:
kernel_ver = platform.uname()[2]
deps.extend(['linux-tools-common', 'linux-tools-%s'
% kernel_ver])
elif detected_distro.name in ['rhel', 'SuSE', 'fedora']:
deps.extend(['perf'])
else:
self.cancel("Install the package for perf supported by %s"
% detected_distro.name)
for package in deps:
if not smm.check_installed(package) and not smm.install(package):
self.cancel('%s is needed for the test to be run' % package)
perf_path = self.params.get('perf_bin', default='')
distro_pkg_map = {
"Ubuntu": [f"linux-tools-{os.uname()[2]}", "linux-tools-common", "gcc", "make"],
"debian": ["linux-perf", "gcc", "make"],
"centos": ["perf", "gcc", "make", "gcc-c++"],
"fedora": ["perf", "gcc", "make", "gcc-c++"],
"rhel": ["perf", "gcc", "make", "gcc-c++"],
"SuSE": ["perf", "gcc", "make", "gcc-c++"],
}
try:
perf_version = ensure_tool("perf", custom_path=perf_path, distro_pkg_map=distro_pkg_map)
self.log.info(f"Perf version: {perf_version}")
self.perf_bin = perf_path if perf_path else "perf"
except RuntimeError as e:
self.cancel(str(e))

def build_perf_test(self):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perf_bin: '/tmp/perf'
39 changes: 17 additions & 22 deletions perf/perf_events_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
# Author:Shriya Kulkarni <shriyak@linux.vnet.ibm.com>
#

import platform
import os
from avocado import Test
from avocado.utils import archive, build, process, distro, genio
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils import archive, build, process, genio
from avocado.utils.software_manager.distro_packages import ensure_tool


class Perf_subsystem(Test):

"""
This series of test is meant to validate
that the perf_event subsystem is working
Expand All @@ -39,24 +37,21 @@ def setUp(self):
Install the packages
'''
# Check for basic utilities
smm = SoftwareManager()
detected_distro = distro.detect()
deps = ['gcc', 'make']
if 'Ubuntu' in detected_distro.name:
kernel_ver = platform.uname()[2]
deps.extend(['linux-tools-common', 'linux-tools-%s'
% kernel_ver])
elif 'debian' in detected_distro.name:
kernel_ver = platform.uname()[2][3]
deps.extend(['linux-tools-%s' % kernel_ver])
elif detected_distro.name in ['rhel', 'SuSE', 'fedora']:
deps.extend(['perf'])
else:
self.cancel("Install the package for perf supported by %s"
% detected_distro.name)
for package in deps:
if not smm.check_installed(package) and not smm.install(package):
self.cancel('%s is needed for the test to be run' % package)
perf_path = self.params.get('perf_bin', default='')
distro_pkg_map = {
"Ubuntu": [f"linux-tools-{os.uname()[2]}", "linux-tools-common", "gcc", "make"],
"debian": ["linux-perf", "gcc", "make"],
"centos": ["perf", "gcc", "make", "gcc-c++"],
"fedora": ["perf", "gcc", "make", "gcc-c++"],
"rhel": ["perf", "gcc", "make", "gcc-c++"],
"SuSE": ["perf", "gcc", "make", "gcc-c++"],
}
try:
perf_version = ensure_tool("perf", custom_path=perf_path, distro_pkg_map=distro_pkg_map)
self.log.info(f"Perf version: {perf_version}")
self.perf_bin = perf_path if perf_path else "perf"
except RuntimeError as e:
self.cancel(str(e))

def build_perf_test(self):
"""
Expand Down
1 change: 1 addition & 0 deletions perf/perf_events_test.py.data/perf_events_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perf_bin: '/tmp/perf'
50 changes: 28 additions & 22 deletions perf/perf_script_bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
# Author: Shirisha <shiganta@in.ibm.com>

import os
import platform
import tempfile
import shutil
import configparser
from avocado import Test
from avocado.utils import build, distro, process
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils import build, process, distro
from avocado.utils.software_manager.distro_packages import ensure_tool


class PerfScript(Test):
Expand All @@ -31,24 +30,28 @@ def setUp(self):
Install the basic packages to support PerfProbe test
'''
# Check for basic utilities
smm = SoftwareManager()
detected_distro = distro.detect()
perf_path = self.params.get('perf_bin', default='')
parser = configparser.ConfigParser()
parser.read(self.get_data('probe.cfg'))
self.perf_probe = parser.get(detected_distro.name, 'probepoint')
deps = ['gcc', 'make']
if detected_distro.name in ['rhel', 'SuSE', 'fedora', 'centos']:
deps.extend(['perf'])
elif detected_distro.name in ['Ubuntu']:
deps.extend(['linux-tools-common', 'linux-tools-%s' %
platform.uname()[2]])
distro_pkg_map = {
"Ubuntu": [f"linux-tools-{os.uname()[2]}", "linux-tools-common", "gcc", "make"],
"debian": ["linux-perf", "gcc", "make"],
"centos": ["perf", "gcc", "make", "gcc-c++"],
"fedora": ["perf", "gcc", "make", "gcc-c++"],
"rhel": ["perf", "gcc", "make", "gcc-c++"],
"SuSE": ["perf", "gcc", "make", "gcc-c++"],
}
try:
perf_version = ensure_tool("perf", custom_path=perf_path, distro_pkg_map=distro_pkg_map)
self.log.info(f"Perf version: {perf_version}")
self.perf_bin = perf_path if perf_path else "perf"
except RuntimeError as e:
self.cancel(str(e))
dist_name = distro.detect().name
if parser.has_section(dist_name):
self.perf_probe = parser.get(dist_name, 'probepoint')
else:
self.cancel("Install the package perf\
for %s" % detected_distro.name)
for package in deps:
if not smm.check_installed(package) and not smm.install(package):
self.cancel('%s is needed for the test to be run' % package)

self.perf_probe = parser.get('Ubuntu', 'probepoint')
shutil.copyfile(self.get_data('perf_test.c'),
os.path.join(self.teststmpdir, 'perf_test.c'))
shutil.copyfile(self.get_data('Makefile'),
Expand All @@ -59,13 +62,16 @@ def setUp(self):
def test_script_probe(self):
# Creating temporary file to collect the perf.data
self.temp_file = tempfile.NamedTemporaryFile().name
probe = "perf probe -x perf_test 'perf_test.c:%s'" % self.perf_probe
probe = "%s probe -x perf_test 'perf_test.c:%s'" % (
self.perf_bin, self.perf_probe)
process.run(probe, sudo=True, shell=True)
record = "perf record -e \'{cpu/cpu-cycles,period=10000/,probe_perf_test:main}:S\' -o %s ./perf_test" % self.temp_file
record = ("%s record -e '{cpu/cpu-cycles,period=10000/,"
"probe_perf_test:main}:S' -o %s ./perf_test" % (
self.perf_bin, self.temp_file))
process.run(record, sudo=True, shell=True)
output = process.run("perf script -i %s" % self.temp_file,
output = process.run("%s script -i %s" % (self.perf_bin, self.temp_file),
ignore_status=True, sudo=True, shell=True)
probe_del = "perf probe -d probe_perf_test:main"
probe_del = "%s probe -d probe_perf_test:main" % self.perf_bin
process.run(probe_del)
if output.exit_status == -11:
self.fail("perf script command segfaulted")
Expand Down
1 change: 1 addition & 0 deletions perf/perf_script_bug.py.data/perf_script_bug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perf_bin: '/tmp/perf'
7 changes: 4 additions & 3 deletions perf/perfmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
class Perfmon(Test):

"""
performance monitoring on Linux : test perf_events on Linux
performance monitoring on Linux : test perf_events on Linux
:avocado: tags=perf,perfmon
"""

def setUp(self):

# Check for basic utilities
smm = SoftwareManager()
dist = distro.detect()

Expand All @@ -55,6 +54,8 @@ def setUp(self):
def test(self):

out = process.system_output('%s ' % os.path.join(
self.workdir, 'tests/validate')).decode("utf-8")
self.workdir, 'tests', 'validate'))
if isinstance(out, bytes):
out = out.decode("utf-8")
if 'fail' in out:
self.fail("test failed:check manually")
43 changes: 22 additions & 21 deletions perf/perftool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
# :Sachin Sant <sachinp@linux.ibm.com>

import os
import platform
from avocado import Test
from avocado.utils import archive, build, distro
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils import archive, build
from avocado.utils.software_manager.distro_packages import ensure_tool


class Perftool(Test):

"""
perftool-testsuite
:avocado: tags=perf,testsuite
Expand All @@ -35,23 +33,26 @@ def setUp(self):
'''

# Check for basic utilities
smm = SoftwareManager()
detected_distro = distro.detect()
deps = ['gcc', 'make']
if 'Ubuntu' in detected_distro.name:
deps.extend(['linux-tools-common', 'linux-tools-%s' %
platform.uname()[2]])
elif 'debian' in detected_distro.name:
deps.extend(['linux-tools-%s' % platform.uname()[2][3]])
elif detected_distro.name in ['rhel', 'SuSE', 'fedora',
'centos']:
deps.extend(['perf', 'gcc-c++'])
else:
self.cancel("Install the package for perf supported\
by %s" % detected_distro.name)
for package in deps:
if not smm.check_installed(package) and not smm.install(package):
self.cancel('%s is needed for the test to be run' % package)
perf_path = self.params.get('perf_bin', default='')

# Define distro-aware package map for perf and build deps
distro_pkg_map = {
"Ubuntu": [f"linux-tools-{os.uname()[2]}", "linux-tools-common", "gcc", "make"],
"debian": [f"linux-tools-{os.uname()[2][3]}", "gcc", "make"],
"centos": ["perf", "gcc", "make", "gcc-c++"],
"fedora": ["perf", "gcc", "make", "gcc-c++"],
"rhel": ["perf", "gcc", "make", "gcc-c++"],
"SuSE": ["perf", "gcc", "make", "gcc-c++"],
}

try:
perf_version = ensure_tool("perf",
custom_path=perf_path,
distro_pkg_map=distro_pkg_map)
self.log.info(f"Perf version: {perf_version}")
self.perf_bin = perf_path if perf_path else "perf"
except RuntimeError as e:
self.cancel(str(e))

locations = ["https://github.com/rfmvh/perftool-testsuite/archive/"
"master.zip"]
Expand Down
1 change: 1 addition & 0 deletions perf/perftool_test.py.data/perftool_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perf_bin: '/tmp/perf'
Loading