forked from avocado-framework-tests/avocado-misc-tests
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathperf_script_bug.py
More file actions
71 lines (65 loc) Β· 2.82 KB
/
perf_script_bug.py
File metadata and controls
71 lines (65 loc) Β· 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: 2019 IBM
# 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
class PerfScript(Test):
def setUp(self):
'''
Install the basic packages to support PerfProbe test
'''
# Check for basic utilities
smm = SoftwareManager()
detected_distro = distro.detect()
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]])
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)
shutil.copyfile(self.get_data('perf_test.c'),
os.path.join(self.teststmpdir, 'perf_test.c'))
shutil.copyfile(self.get_data('Makefile'),
os.path.join(self.teststmpdir, 'Makefile'))
build.make(self.teststmpdir)
os.chdir(self.teststmpdir)
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
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
process.run(record, sudo=True, shell=True)
output = process.run("perf script -i %s" % self.temp_file,
ignore_status=True, sudo=True, shell=True)
probe_del = "perf probe -d probe_perf_test:main"
process.run(probe_del)
if output.exit_status == -11:
self.fail("perf script command segfaulted")