Skip to content

Commit 1b68554

Browse files
Merge pull request #972 from shirishaganta1/kexec-dtb-initrd
OpTestKexec.py:Add test kexec with both initrd and dtb
2 parents 6cda52a + e2fa865 commit 1b68554

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

testcases/OpTestKexec.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,68 @@ def test_kexec_unsigned_kernel(self):
498498
else:
499499
self.skipTest("secure boot is disabled.")
500500

501+
def test_kexec_with_initrd_and_dtb(self):
502+
"""
503+
Test kexec with both initrd and DTB (Device Tree Blob) for SLES 16.1.
504+
505+
This test performs the following steps:
506+
1. Check if dtc package is installed, install if not present
507+
2. Generate live.dtb from /proc/device-tree using dtc command
508+
3. Load kexec kernel with initrd and DTB
509+
4. Execute kexec to boot into the new kernel
510+
511+
Test passes if kexec kernel boots successfully with both initrd and DTB;
512+
otherwise, it fails.
513+
"""
514+
# Skip test for non-SLES distributions
515+
if self.distro != "sles":
516+
self.skipTest("This test is specific to SLES distribution")
517+
518+
log.info("Starting kexec test with initrd and DTB for SLES")
519+
try:
520+
dtc_check = self.cv_HOST.host_run_command("which dtc", timeout=30)
521+
if not dtc_check or "dtc" not in dtc_check[0]:
522+
log.info("dtc package not found, installing...")
523+
install_cmd = "zypper install -y dtc"
524+
self.cv_HOST.host_run_command(install_cmd, timeout=300)
525+
log.info("dtc package installed successfully")
526+
else:
527+
log.info("dtc package is already installed")
528+
except CommandFailed as e:
529+
self.fail("Failed to check or install dtc package: %s" % str(e))
530+
try:
531+
log.info("Generating live.dtb from /proc/device-tree")
532+
dtb_cmd = "dtc -I fs -O dtb -o /tmp/live.dtb /proc/device-tree"
533+
self.cv_HOST.host_run_command(dtb_cmd, timeout=60)
534+
log.info("live.dtb generated successfully at /tmp/live.dtb")
535+
except CommandFailed as e:
536+
self.fail("Failed to generate live.dtb: %s" % str(e))
537+
try:
538+
self.cv_HOST.host_run_command("ls -lh /tmp/live.dtb", timeout=30)
539+
except CommandFailed:
540+
self.fail("live.dtb file was not created")
541+
try:
542+
k_ver = self.cv_HOST.host_run_command("uname -r")[0]
543+
log.info("Current kernel version: %s" % k_ver)
544+
except CommandFailed:
545+
self.fail("Unable to determine kernel version")
546+
kexec_cmd = "kexec -lc /boot/vmlinux-%s --initrd=/boot/initrd-%s --dtb=/tmp/live.dtb --append=\"`cat /proc/cmdline`\"" % (k_ver, k_ver)
547+
log.info("Kexec load command: %s" % kexec_cmd)
548+
ret = self.load_kexec_kernel(kexec_cmd)
549+
self.assertTrue(ret, "Kexec load with initrd and DTB failed")
550+
log.info("Kexec kernel loaded successfully with initrd and DTB")
551+
kexec_exec_cmd = self.get_kexec_exec_command(exec_opt=True)
552+
log.info("Executing kexec: %s" % kexec_exec_cmd)
553+
ret = self.execute_kexec_cmd(kexec_exec_cmd, raw_pty_console=True)
554+
self.assertTrue(ret, "kexec exec failed with initrd and DTB: %s" % kexec_exec_cmd)
555+
log.info("Kexec with initrd and DTB completed successfully")
556+
501557
def tearDown(self):
558+
# Clean up live.dtb file if it exists
559+
try:
560+
self.cv_HOST.host_run_command("rm -f /tmp/live.dtb", timeout=30)
561+
except:
562+
pass
502563
unsigned_kernel = "%s.unsigned" % self.kernel_image
503564
if 'boot' not in unsigned_kernel:
504565
unsigned_kernel = "/boot/%s" % unsigned_kernel
@@ -521,4 +582,5 @@ def kexec_suite():
521582
suite.addTest(OpTestKexec('test_syscall_load_and_exec'))
522583
suite.addTest(OpTestKexec('test_kexec_in_loop'))
523584
suite.addTest(OpTestKexec('test_kexec_unsigned_kernel'))
585+
suite.addTest(OpTestKexec('test_kexec_with_initrd_and_dtb'))
524586
return suite

0 commit comments

Comments
 (0)