def setUp(self): """ Get the number of cores and threads per core Set the SMT value to 4/8 """ if distro.detect().arch not in ['ppc64', 'ppc64le']: self.cancel("Only supported in powerpc system") self.loop = int(self.params.get('test_loop', default=100)) self.nfail = 0 self.CORES = process.system_output("lscpu | grep 'Core(s) per socket:'" "| awk '{print $4}'", shell=True) self.SOCKETS = process.system_output("lscpu | grep 'Socket(s):'" "| awk '{print $2}'", shell=True) self.THREADS = process.system_output("lscpu | grep 'Thread(s) per core" ":'| awk '{print $4}'", shell=True) self.T_CORES = int(self.CORES) * int(self.SOCKETS) self.log.info(" Cores = %s and threads = %s " % (self.T_CORES, self.THREADS)) genio.write_one_line('/proc/sys/kernel/printk', "8") # Set SMT to max SMT value (restricted at boot time) and get its value process.system("ppc64_cpu --smt=%s" % "on", shell=True) self.max_smt_s = process.system_output("ppc64_cpu --smt", shell=True).decode() self.max_smt = int(self.max_smt_s[4:]) self.path = "/sys/devices/system/cpu"
def execute_perf_test(self): os.chdir(self.sourcedir) genio.write_one_line("/proc/sys/kernel/perf_event_paranoid", "-1") if "-1" not in genio.read_one_line( "/proc/sys/kernel/perf_event_paranoid"): self.cancel("Unable to set perf_event_paranoid to -1 ") self.output = self.run_cmd_out("./run_tests.sh")
def optprobes_disable_test(self): optprobes_file = "/proc/sys/debug/kprobes-optimization" if not self.check_kernel_support(): self.log.info( "No support available for optprobes, skipping optprobes test") return if not os.path.exists(optprobes_file): self.log.info( "optprobes control file %s missing, skipping optprobes test", optprobes_file) return cur_val = genio.read_one_line(optprobes_file) genio.write_one_line(optprobes_file, "0") self.log.info( "================= Disabling optprobes ==================") if "0" not in genio.read_one_line(optprobes_file): self.fail("Not able to disable optprobes") self.execute_test() self.log.info( "================= Restoring optprobes ==================") genio.write_one_line(optprobes_file, cur_val) if cur_val not in genio.read_one_line(optprobes_file): self.fail("Not able to restore optprobes to %s", cur_val)
def _cpu_on_off(self, cpu_number, disable_flag=True): cpu_file = "/sys/bus/cpu/devices/cpu%s/online" % cpu_number if disable_flag: genio.write_one_line(cpu_file, "0") self.log.info("Offline CPU: %s" % cpu_number) else: genio.write_one_line(cpu_file, "1") self.log.info("Online CPU: %s" % cpu_number)
def clear_trace(self): self.debugfs = "/sys/kernel/debug/tracing/" self.tracefs = os.path.join(self.debugfs, "trace") self.uprobes_enable_fs = os.path.join(self.debugfs, "events/uprobes/enable") self.uprobes_event_fs = os.path.join(self.debugfs, "events/uprobes/u_malloc/enable") self.uprobes_events_fs = os.path.join(self.debugfs, "uprobe_events") genio.write_one_line(self.tracefs, "") genio.write_one_line(self.uprobes_events_fs, "")
def execute_perf_fuzzer(self): os.chdir(self.sourcedir) genio.write_one_line("/proc/sys/kernel/perf_event_paranoid", "-1") if "-1" not in genio.read_one_line("/proc/sys/kernel/" "perf_event_paranoid"): self.cancel("Unable to set perf_event_paranoid to -1 ") self.perf_fuzzer = os.path.join(self.sourcedir, "fuzzer/perf_fuzzer") if not os.path.exists(self.perf_fuzzer): self.cancel("fuzzer not found at %s" % self.perf_fuzzer) self.output = self.run_cmd_out(self.perf_fuzzer)
def enable_selinux_enforcing(): """ Enable SELinux Enforcing in system :return: True if SELinux enable in enforcing mode, False if not enabled """ genio.write_one_line("/sys/fs/selinux/enforce", "1") if is_selinux_enforcing(): return True return False
def test(self): self.clear_dmesg() os.chdir(self.sourcedir) genio.write_one_line("/proc/sys/kernel/hung_task_timeout_secs", "0") process.system('./check', ignore_status=True) dmesg = process.system_output('dmesg') match = re.search(br'Call Trace:', dmesg, re.M | re.I) if match: self.fail("some call traces seen please check")
def test(self): self.clear_dmesg() os.chdir(self.sourcedir) genio.write_one_line("/proc/sys/kernel/hung_task_timeout_secs", "0") process.system('./check', ignore_status=True) dmesg = process.system_output('dmesg') match = re.search(r'Call Trace:', dmesg, re.M | re.I) if match: self.fail("some call traces seen please check")
def set_proc_sys(key, value): """ Set values on /proc/sys :param key: A location under /proc/sys :param value: If not None, a value to write into the sysctl. :return: The single-line sysctl value as a string. """ path = os.path.join("/proc/sys/%s", key) genio.write_one_line(path, value) return get_proc_sys(key)
def ena_dis_uprobes(self, prob_value): """ Enable and Disable the uprobes. Enable_uprobes: prob_value = 1 Disable_uprobes: prob_value = 0 """ try: genio.write_one_line(self.uprobes_enable_fs, prob_value) genio.write_one_line(self.uprobes_event_fs, prob_value) except IOError: self.cancel("There is issue with kernel system resources")
def execute_test(self): self.log.info("============== Enabling livepatching =================") self.clear_dmesg() self.is_fail = 0 self.run_cmd("insmod ./livepatch-sample.ko") if self.is_fail >= 1: self.fail("insmod livepatch-sample.ko failed") if "enabling patch" not in self.run_cmd_out( "dmesg |grep -i livepatch_sample"): self.fail( "livepatch couldn't be enabled, check dmesg for more information" ) """ Execute /proc/cmdline, to check if livepatch works """ if "this has been live patched" not in genio.read_one_line( "/proc/cmdline"): self.fail( "livepatching unsuccessful, check dmesg for more information") self.log.info( "============== Disabling livepatching =================") genio.write_one_line("/sys/kernel/livepatch/livepatch_sample/enabled", "0") if "0" not in genio.read_one_line( "/sys/kernel/livepatch/livepatch_sample/enabled"): self.fail( "Unable to disable livepatch for livepatch_sample module") if "unpatching transition" not in self.run_cmd_out( "dmesg |grep -i livepatch_sample"): self.fail( "livepatch couldn't be disabled, check dmesg for more information" ) if "this has been live patched" in genio.read_one_line( "/proc/cmdline"): self.fail( "livepatching disabling unsuccessful, check dmesg for more information" ) """ Wait for 3 minutes before trying to remove the livepatching module """ time.sleep(60 * 3) self.run_cmd("rmmod livepatch-sample") if self.is_fail >= 1: self.log.info( "rmmod livepatch-sample.ko failed, try removing it manual" "after sometime")
def test(self): self.clear_dmesg() os.chdir(self.sourcedir) genio.write_one_line("/proc/sys/kernel/hung_task_timeout_secs", "0") if self.disk: os.environ['TEST_DEVS'] = self.disk cmd = './check %s' % self.dev_type result = process.run(cmd, ignore_status=True, verbose=True) if result.exit_status != 0: self.fail("test failed") dmesg = process.system_output('dmesg') match = re.search(br'Call Trace:', dmesg, re.M | re.I) if match: self.fail("some call traces seen please check")
def clear_trace(self): """ Clear the tracepoint and uprobe events before enable and disable the probe. """ try: self.debugfs = "/sys/kernel/debug/tracing/" self.tracefs = os.path.join(self.debugfs, "trace") uprobes_en = "events/uprobes/enable" self.uprobes_enable_fs = os.path.join(self.debugfs, uprobes_en) uprobes_umall = "events/uprobes/u_malloc/enable" self.uprobes_event_fs = os.path.join(self.debugfs, uprobes_umall) uprobe_eve = "uprobe_events" self.uprobes_events_fs = os.path.join(self.debugfs, uprobe_eve) genio.write_one_line(self.tracefs, "") genio.write_one_line(self.uprobes_events_fs, "") except IOError: self.cancel("There is issue with kernel system resources")
def data_file(self): if self._data_file is None: self._data_file = tempfile.mktemp() genio.write_one_line(self._data_file, self.data) return self._data_file
def disable_uprobes(self): genio.write_one_line(self.uprobes_event_fs, "0") genio.write_one_line(self.uprobes_enable_fs, "0")
def execute_perf_test(self): os.chdir(self.sourcedir) genio.write_one_line("/proc/sys/kernel/perf_event_paranoid", "-1") if "-1" not in genio.read_one_line("/proc/sys/kernel/perf_event_paranoid"): self.cancel("Unable to set perf_event_paranoid to -1 ") self.output = self.run_cmd_out("./run_tests.sh")
def data_file(self, data_file): if os.path.isfile(data_file): self._data = genio.read_one_line(self.data_file) else: genio.write_one_line(data_file, self.data)