From 4aafc74a11da0d3cb1157ac97713709171d81a98 Mon Sep 17 00:00:00 2001 From: Akanksha J N Date: Fri, 15 Mar 2024 17:05:28 +0530 Subject: [PATCH] read_dawr_perf_interface Add new test cases for reading single DAWR register and multiple DAWR registers with perf interface Signed-off-by: Akanksha J N --- trace/dawr.py | 57 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/trace/dawr.py b/trace/dawr.py index 07be8c4f1..395060a02 100644 --- a/trace/dawr.py +++ b/trace/dawr.py @@ -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 @@ -33,7 +33,7 @@ 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") @@ -41,7 +41,7 @@ def setUp(self): 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) @@ -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') @@ -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 @@ -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 @@ -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 @@ -121,7 +145,26 @@ def test_read_dawr_v3(self): % (i, value)])) child.sendline('r') return_value.append(child.expect_exact([pexpect.TIMEOUT, - 'not enough available hardware'])) + 'not enough available hardware'])) 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')