diff --git a/qemu/deps/watchdog/deadlock_test/Makefile b/qemu/deps/watchdog/deadlock_test/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..63f0b1de9cb40d82094efbe1dc1cf59cce3b57c6 --- /dev/null +++ b/qemu/deps/watchdog/deadlock_test/Makefile @@ -0,0 +1,11 @@ +obj-m := deadlock_test.o + +KVERS = $(shell uname -r) + +build: kernel_modules + +kernel_modules: + make -C /lib/modules/$(KVERS)/build M=$(CURDIR) modules + +clean: + make -C /lib/modules/$(KVERS)/build M=$(CURDIR) clean diff --git a/qemu/deps/watchdog/deadlock_test/deadlock_test.c b/qemu/deps/watchdog/deadlock_test/deadlock_test.c new file mode 100644 index 0000000000000000000000000000000000000000..de2886b646646c305e03dab65eb04fd2ec6bb79e --- /dev/null +++ b/qemu/deps/watchdog/deadlock_test/deadlock_test.c @@ -0,0 +1,33 @@ +#include +#include +#include + +static int __init hello_init(void) +{ + unsigned long current_i, stamp_30; + printk(KERN_INFO "insmod deadlock_test!!!\n"); + current_i = jiffies; + stamp_30 = current_i + 30*HZ; + printk(KERN_INFO "%lu\n", current_i); + printk(KERN_INFO "%lu\n", stamp_30); + local_irq_disable(); + while(current_i != stamp_30) + { + current_i = jiffies; + } + printk(KERN_INFO "30s is over!!!\n"); + return 0; +} + +module_init(hello_init); + +static void __exit hello_exit(void) +{ + printk(KERN_INFO "deadlockup test exit\n"); +} +module_exit(hello_exit); + +MODULE_AUTHOR("zhk "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("deadlockup test module"); +MODULE_ALIAS("a simplest module"); diff --git a/qemu/tests/cfg/pmu_nmi_watchdog.cfg b/qemu/tests/cfg/pmu_nmi_watchdog.cfg new file mode 100644 index 0000000000000000000000000000000000000000..3d882be27fba1ff866f8b30cd44f71780914fbfe --- /dev/null +++ b/qemu/tests/cfg/pmu_nmi_watchdog.cfg @@ -0,0 +1,58 @@ +- pmu_nmi_watchdog: install setup image_copy unattended_install.cdrom + type = pmu_nmi_watchdog + start_vm = no + deadlock_test_link = "watchdog/deadlock_test" + deadlock_test_path = "/root" + pre_cmd = "cd /root/deadlock_test && make" + deadlock_test_cmd = "nohup insmod /root/deadlock_test/deadlock_test.ko >/dev/null 2>&1 &" + rmmod_deadlock_cmd = "rmmod deadlock_test.ko" + monitors = qmp1 + monitor_type = qmp + mem = 2048 + only aarch64 + variants: + - nmi_watchdog_test: + test_type = nmi_watchdog_test + variants: + - 64u16g: + custom_smp = 64 + vcpu_maxcpus = 64 + mem = 16384 + - 1u2g: + custom_smp = 1 + vcpu_maxcpus = 1 + mem = 2048 + - 8u8g_hyper_threads: + custom_smp = 8 + vcpu_maxcpus = 8 + used_cpus = 8 + vcpu_cores = 4 + vcpu_threads = 2 + mem = 8192 + - nmi_watchdog_switch: + test_type = nmi_watchdog_edit + switch_cmd0 = "echo 0 > /proc/sys/kernel/nmi_watchdog" + switch_cmd1 = "echo 1 > /proc/sys/kernel/nmi_watchdog" + - cmdline_test: + test_type = cmdline_test + variants: + - pesudo_nmi_0: + boot_option_removed = "irqchip.gicv3_pseudo_nmi=1" + boot_option_added = "irqchip.gicv3_pseudo_nmi=0" + - del_pesudo_nmi: + boot_option_removed = "irqchip.gicv3_pseudo_nmi=1" + boot_option_added = "" + - del_pmu_nmi_enable: + boot_option_removed = "pmu_nmi_enable" + boot_option_added = "" + - del_hardlockup_cpu_freq: + boot_option_removed = "hardlockup_cpu_freq=auto" + boot_option_added = "" + - nmi_watchdog_0: + boot_option_removed = "nmi_watchdog=1" + boot_option_added = "nmi_watchdog=0" + - del_disable_sdei_nmi_watchdog: + boot_option_removed = "disable_sdei_nmi_watchdog" + boot_option_added = "" + - workwith_i6300esb: + test_type = workwith_i6300esb diff --git a/qemu/tests/pmu_nmi_watchdog.py b/qemu/tests/pmu_nmi_watchdog.py new file mode 100644 index 0000000000000000000000000000000000000000..8e25984158b7ab39550d29e7ab08d918b6453676 --- /dev/null +++ b/qemu/tests/pmu_nmi_watchdog.py @@ -0,0 +1,148 @@ +""" +pmu nmi watchdog +""" +import logging +import time +import os.path + +from virttest import utils_test +from virttest import env_process +from virttest import error_context +from virttest import data_dir + +@error_context.context_aware +def run(test, params, env): + """ + Test the function of pmu nmi watchdog + + Test Step: + 1. see every function step + + :param test: qemu test object + :param params: Dictionary with the test parameters. + :param env: Dictionary with test environment. + """ + # pylint: disable=R0914, C0103, W1201, W0641, R0915 + if "custom_smp" in params: + params["smp"] = params["custom_smp"] + env_process.preprocess(test, params, env) + vm = env.get_vm(params["main_vm"]) + vm.create(params=params) + vm.verify_alive() + timeout = float(params.get("login_timeout", 240)) + session = vm.wait_for_login(timeout=timeout) + end_time = time.time() + timeout + + deadlock_test_link = params.get("deadlock_test_link") + deadlock_test_path = params.get("deadlock_test_path") + src_link = os.path.join(data_dir.get_deps_dir(""), + deadlock_test_link) + vm.copy_files_to(src_link, deadlock_test_path, timeout=60) + pre_cmd = params["pre_cmd"] + session.cmd(pre_cmd) + + deadlock_test_cmd = params["deadlock_test_cmd"] + + def _nmi_watchdog_check(session): + """ + check if pmu_nmi_watchdog run successfully + """ + session.cmd(deadlock_test_cmd, ignore_all_errors=True) + + qmp_monitors = vm.get_monitors_by_type("qmp") + if qmp_monitors: + qmp_monitor = qmp_monitors[0] + else: + test.error("Could not find a QMP monitor, aborting test.") + + while time.time() < end_time: + if qmp_monitor.get_event("RESET"): + logging.info("pmu_nmi_watchdog run successfully.") + return True + + return False + + def nmi_watchdog_test(): + """ + Basic functions + """ + res = _nmi_watchdog_check(session) + if not res: + logging.error("pmu_nmi_watchdog doesn't run successfully.") + + def nmi_watchdog_edit(): + """ + Test whether this switch takes effect. + """ + switch_cmd0 = params["switch_cmd0"] + session.cmd(switch_cmd0) + deadlock_test_cmd = params["deadlock_test_cmd"] + session.cmd(deadlock_test_cmd, ignore_all_errors=True) + + rmmod_deadlock = params["rmmod_deadlock_cmd"] + session.cmd(rmmod_deadlock) + + switch_cmd1 = params["switch_cmd1"] + session.cmd(switch_cmd1) + + res = _nmi_watchdog_check(session) + if not res: + logging.error("pmu_nmi_watchdog doesn't run successfully.") + + def cmdline_test(): + """ + Test pmu nmi watchdog work with different cmdline, + such as set "irqchip.gicv3_pseudo_nmi=0",then pmu nmi watchdog cannot run. + """ + boot_option_added = params.get("boot_option_added") + boot_option_removed = params.get("boot_option_removed") + + utils_test.update_boot_option(vm, + args_removed=boot_option_removed, + args_added=boot_option_added) + + res = _nmi_watchdog_check(session) + if not res: + logging.debug("pmu_nmi_watchdog doesn't run successfully.") + else: + logging.error("pmu_nmi_watchdog run successfully is not our target!") + + def workwith_i6300esb(): + """ + Testing if i6300esb can work with pmu nmi watchdog + """ + trigger_cmd = params.get("trigger_cmd", "echo c > /dev/watchdog") + watchdog_action = params.get("watchdog_action", "reset") + + def _trigger_watchdog(session, trigger_cmd=None): + """ + Trigger watchdog action + Param session: guest connect session. + Param trigger_cmd: cmd trigger the watchdog + """ + if trigger_cmd is not None: + error_context.context(("Trigger Watchdog action using:'%s'." % + trigger_cmd), logging.info) + session.sendline(trigger_cmd) + + # Testing i6300esb + _trigger_watchdog(session, trigger_cmd) + if watchdog_action == "reset": + logging.info("Try to login the guest after reboot") + vm.wait_for_login(timeout=timeout) + logging.info("Watchdog action '%s' come into effect." % + watchdog_action) + + res = _nmi_watchdog_check(session) + if not res: + logging.error("pmu_nmi_watchdog doesn't run successfully.") + + # main procedure + test_type = params.get("test_type") + + if test_type in locals(): + test_running = locals()[test_type] + test_running() + else: + test.error("Oops test %s doesn't exist, have a check please." + % test_type)