Skip to content

Commit

Permalink
read_dawr_perf_interface
Browse files Browse the repository at this point in the history
Add new test cases for reading single DAWR register and
multiple DAWR registers with perf interface

Signed-off-by: Akanksha J N <[email protected]>
  • Loading branch information
akanksha216 committed Mar 19, 2024
1 parent 07464d2 commit 6eae462
Showing 1 changed file with 49 additions and 6 deletions.
55 changes: 49 additions & 6 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, cpu
from avocado.utils import build, distro, cpu, process
from avocado.utils.software_manager.manager import SoftwareManager


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

def setUp(self):
'''
Install the basic packages to support gdb
Install the basic packages to support gdb and perf
'''
if "power10" not in cpu.get_family():
self.cancel("Test is supported only on IBM POWER10 platform")
# 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 @@ -53,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 @@ -62,7 +63,30 @@ 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
Expand All @@ -81,7 +105,7 @@ 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
Expand All @@ -106,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 @@ -125,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')

0 comments on commit 6eae462

Please sign in to comment.