Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read dawr with perf interface #2869

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
68 changes: 51 additions & 17 deletions trace/dawr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import shutil
import pexpect
from avocado import Test
from avocado.utils import build, distro, genio
from avocado.utils import build, distro, cpu, process
from avocado.utils.software_manager.manager import SoftwareManager


Expand All @@ -33,17 +33,15 @@ class Dawr(Test):

def setUp(self):
'''
Install the basic packages to support gdb
Install the basic packages to support gdb and perf
'''
val = genio.read_file("/proc/cpuinfo")
power_ver = ['POWER10', 'Power11']
if not any(x in val for x in power_ver):
self.cancel("LPAR on Power10 and above is required for this test.")
if "power10" not in cpu.get_family():
self.cancel("Test is supported only on IBM POWER10 platform")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will revert the power11 support changes. Can you rebase the code?

# Check for basic utilities
smm = SoftwareManager()
self.detected_distro = distro.detect()
self.distro_name = self.detected_distro.name
deps = ['gcc', 'make', 'gdb']
deps = ['gcc', 'make', 'gdb', 'perf']
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)
Expand All @@ -55,6 +53,7 @@ def setUp(self):
os.path.join(self.teststmpdir, 'Makefile'))
build.make(self.teststmpdir)
os.chdir(self.teststmpdir)
self.output_file = "perf.data"

def run_cmd(self, bin_var):
child = pexpect.spawn('gdb ./%s' % bin_var, encoding='utf-8')
Expand All @@ -64,16 +63,35 @@ def run_cmd(self, bin_var):
return_value = []
return child, return_value

def test_read_dawr_v1(self):
def run_test(self, cmd):
return process.run(cmd, shell=True)

def perf_cmd(self, perf_record):
process.run(perf_record, shell=True, ignore_status=True,
verbose=True, ignore_bg_processes=True)
report = "perf report --input=%s" % self.output_file
self.run_test(report)
if not os.stat(self.output_file).st_size:
self.fail("%s sample not captured" % self.output_file)

def address_v1(self):
# Get memory address of single variable
output = self.run_test('./dawr_v1')
data = output.stdout.decode("utf-8")
return data

def address_v2(self):
# Get memory address of two variables
output = self.run_test('./dawr_v2')
data = output.stdout.decode("utf-8").split(',')
return data

def test_read_dawr_v1_gdb(self):
"""
Setting Read/Write watchpoint on single variable using awatch and
executing the program
"""
child, return_value = self.run_cmd('dawr_v1')
i = 0
if self.distro_name == "fedora":
child.sendline('set debuginfod enabled on')
child.expect_exact([pexpect.TIMEOUT, ''])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same. This will revert code added via trace: Add Fedora Support to trace testing. Can you rebase?

child.sendline('awatch a')
return_value.append(child.expect_exact(['watchpoint 1: a',
pexpect.TIMEOUT]))
Expand All @@ -87,16 +105,13 @@ def test_read_dawr_v1(self):
if i != 0:
self.fail('Test case failed for 1 variable')

def test_read_dawr_v2(self):
def test_read_dawr_v2_gdb(self):
"""
Setting Read/Write watchpoints on two variables using awatch and
executing the program
"""
child, return_value = self.run_cmd('dawr_v2')
i = 0
if self.distro_name == "fedora":
child.sendline('set debuginfod enabled on')
child.expect_exact([pexpect.TIMEOUT, ''])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

for value in ['a', 'b']:
i = i+1
child.sendline('awatch %s' % value)
Expand All @@ -115,7 +130,7 @@ def test_read_dawr_v2(self):
if i == 0:
self.fail('Test case failed for 2 variables')

def test_read_dawr_v3(self):
def test_read_dawr_v3_gdb(self):
"""
Setting Read/Write watchpoints on three variables using awatch and
executing the program
Expand All @@ -134,3 +149,22 @@ def test_read_dawr_v3(self):
for i in return_value:
if i == 0:
self.fail('Test case failed for 3 variables')

def test_read_dawr_v1_perf(self):
# Read single dawr register with perf interface
data = self.address_v1()
perf_record = 'perf record -o %s -e mem:%s ./dawr_v1' % (
self.output_file, data)
self.perf_cmd(perf_record)

def test_read_dawr_v2_perf(self):
# Read two dawr registers with perf interface
data = self.address_v2()
perf_record = 'perf record -o %s -e mem:%s -e mem:%s ./dawr_v2' % (
self.output_file, data[0], data[1][1:11])
self.perf_cmd(perf_record)

def tearDown(self):
# Delete the temporary file
if os.path.isfile("perf.data"):
process.run('rm -f perf.data')
Loading