From 95a55aae0538540fff5fa3574c589ee83fab7827 Mon Sep 17 00:00:00 2001 From: Sachin P Bappalige Date: Wed, 20 Sep 2023 06:03:41 -0500 Subject: [PATCH] Add softlockup scenario for kdump/Fadump testing KernelCrash_KdumpSoftlockup testcase use source files(softlockup.c and Makefile).These files added to op-tests framework's directory "op-test/test_binaries". This testcase activates the kernel panic on soft lockup and copy softlockup.c and Makefile to /tmp directory to build kernel module. The command insmod used to insert generated kernel module(softlockup.ko) into the kernel and verify the dump file created after kernel panic on soft lockup. Signed-off-by: Sachin P Bappalige --- test_binaries/Makefile | 7 +++++++ test_binaries/softlockup.c | 35 +++++++++++++++++++++++++++++++++++ testcases/PowerNVDump.py | 26 ++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 test_binaries/Makefile create mode 100644 test_binaries/softlockup.c diff --git a/test_binaries/Makefile b/test_binaries/Makefile new file mode 100644 index 000000000..d6a9e9e7a --- /dev/null +++ b/test_binaries/Makefile @@ -0,0 +1,7 @@ +obj-m += softlockup.o + +all: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + +clean: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean diff --git a/test_binaries/softlockup.c b/test_binaries/softlockup.c new file mode 100644 index 000000000..964e85be6 --- /dev/null +++ b/test_binaries/softlockup.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("LIKHITHA"); +MODULE_DESCRIPTION("Kernel Module for softlockups"); + +static spinlock_t my_lock; + +int a; + +static int __init my_init(void) +{ + spin_lock_init(&my_lock); + printk(KERN_INFO "softlockup module: Initialized spinlock\n"); + + /* Perform critical section operations */ + spin_lock(&my_lock); + while (1) { + a+=1; + } + spin_unlock(&my_lock); + + return 0; +} + +static void __exit my_exit(void) +{ + printk(KERN_INFO "Exiting module\n"); +} + +module_init(my_init); +module_exit(my_exit); diff --git a/testcases/PowerNVDump.py b/testcases/PowerNVDump.py index 9b1db455b..6b39237ef 100644 --- a/testcases/PowerNVDump.py +++ b/testcases/PowerNVDump.py @@ -370,6 +370,8 @@ def kernel_crash(self, crash_type="echo_c"): elif crash_type == "hmc": self.cv_HMC.run_command("chsysstate -r lpar -m %s -n %s -o dumprestart" % (self.system_name, self.lpar_name), timeout=300) + elif crash_type == "softlockup": + self.c.pty.sendline("insmod /tmp/softlockup.ko") done = False boot_type = BootType.NORMAL rc = -1 @@ -1323,6 +1325,29 @@ def runTest(self): if not obj.update_kernel_cmdline(self.distro, remove_args="fadump=nocma", reboot=True, reboot_cmd=True): self.fail("KernelArgTest failed to update kernel args") +class KernelCrash_KdumpSoftlockup(PowerNVDump): + + ''' + This test verifies kdump/fadump after inserting softlockup kernel module. + ''' + + def runTest(self): + self.setup_test() + # Make sure softlockup related file does not exist + self.c.run_command("cd /tmp; ls -1; rm -rf soft* Makefile", timeout=60) + + #copy the source files from test_binaries to /tmp + self.cv_HOST.copy_test_file_to_host("softlockup.c") + self.cv_HOST.copy_test_file_to_host("Makefile") + + #compile source files to get kernel modules + self.c.run_command("cd /tmp; make", timeout=60) + + #Enable softlockup + self.c.run_command("sysctl -w kernel.softlockup_panic=1") + + boot_type = self.kernel_crash(crash_type="softlockup") + self.verify_dump_file(boot_type) def crash_suite(): s = unittest.TestSuite() @@ -1354,5 +1379,6 @@ def crash_suite(): s.addTest(KernelCrash_DisableAll()) s.addTest(SkirootKernelCrash()) s.addTest(OPALCrash_MPIPL()) + s.addTest(KernelCrash_KdumpSoftlockup()) return s