diff --git a/perf/perf_pmu.py b/perf/perf_pmu.py index 578316f95..abe911642 100644 --- a/perf/perf_pmu.py +++ b/perf/perf_pmu.py @@ -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 @@ -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 @@ -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