From 753e9fc21d5424f24227c3f6fec776f54702f218 Mon Sep 17 00:00:00 2001 From: Akanksha J N Date: Mon, 12 Aug 2024 15:40:44 +0530 Subject: [PATCH] Read dawr with 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 | 68 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/trace/dawr.py b/trace/dawr.py index 43b567306..064856a77 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, genio +from avocado.utils import build, distro, cpu, process from avocado.utils.software_manager.manager import SoftwareManager @@ -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") # 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) @@ -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') @@ -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, '']) child.sendline('awatch a') return_value.append(child.expect_exact(['watchpoint 1: a', pexpect.TIMEOUT])) @@ -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, '']) for value in ['a', 'b']: i = i+1 child.sendline('awatch %s' % value) @@ -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 @@ -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')