Skip to content

Commit

Permalink
Merge pull request avocado-framework-tests#2860 from akanksha216/perf…
Browse files Browse the repository at this point in the history
…_pmu_test_enhancement

perf_pmu_test_enhancement
  • Loading branch information
PraveenPenguin authored Sep 3, 2024
2 parents 8711899 + e7c3641 commit 0b283bd
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions perf/perf_pmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import os
import configparser
import glob
import random
import re
from avocado import Test
from avocado.utils import cpu, dmesg, genio, linux_modules, process
from avocado import skipIf, skipUnless
Expand Down Expand Up @@ -84,6 +86,22 @@ def _remove_temp_user(self):
process.system('userdel -r test_pmu', sudo=True,
ignore_status=True)

def get_random_filenames(self, directory, num_files=3):
files = os.listdir(directory)
random_files = random.sample(files, num_files)
return random_files

def check_ProcessorCompatMode(self, file_path, patterns):
found_patterns = set()
with open(file_path, 'r') as file:
content = file.read()
for pattern in patterns:
if re.search(pattern, content):
found_patterns.add(pattern)
compat_mode = str(found_patterns)
compat_mode = compat_mode.strip('{}').strip("'")
return compat_mode

def _check_kernel_config(self, config_option):
# This function checks the kernel configuration with the input
# 'config_option' a string. If the required configuration not set then
Expand Down Expand Up @@ -207,6 +225,34 @@ def test_cpu_event_count(self):
# cpu events count
self._check_count('cpu')

def test_sysfs_events(self):
devices_events = ['cpu', 'hv_24x7', 'hv_gpci']
self._create_temp_user()
for type_events in devices_events:
directory_base = '/sys/bus/event_source/devices'
directory = os.path.join(directory_base, type_events, 'events')
print(directory)
random_files = self.get_random_filenames(directory)
if not process.system('id test_pmu', sudo=True, ignore_status=True):
for file in random_files:
eventdir = os.path.join(directory, file)
result = process.run("su - test_pmu -c 'echo 1 > %s'" % eventdir,
shell=True, ignore_status=True)
output = result.stdout.decode() + result.stderr.decode()
else:
self.log.warn('User test_pmu does not exist, skipping test')
self._remove_temp_user()

def test_caps_feat(self):
modes = ['power10', 'power11']
if self.model in modes:
cmd = "cat /sys/bus/event_source/devices/cpu/caps/pmu_name"
sysfs_value = process.system_output(cmd, shell=True,
ignore_status=True).decode()
self.log.info(" Sysfs caps version : %s " % sysfs_value)
else:
self.cancel("This test is supported only for Power10 and above")

@skipIf(IS_POWER_NV or IS_KVM_GUEST, "This test is for PowerVM")
def test_hv_24x7_event_count(self):
# This test checks for the sysfs event_source directory and checks for
Expand Down

0 comments on commit 0b283bd

Please sign in to comment.