Debian Codegraph @

tests/linux_kernel/vmcore/test_crash_commands.py

raw
1 # Copyright (c) 2026 Oracle and/or its affiliates
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 from _drgn_util.platform import NORMALIZED_MACHINE_NAME
5 import drgn.commands._crash # noqa # needed to register crash commands
6 from drgn.helpers.linux.cpumask import for_each_online_cpu
7 from tests.linux_kernel import skip_unless_have_stack_tracing
8 from tests.linux_kernel.vmcore import LinuxVMCoreCrashCommandTestCase
9
10
11 @skip_unless_have_stack_tracing
12 class TestBtVMCore(LinuxVMCoreCrashCommandTestCase):
13 # When CPU 0 panics on s390x, the kernel switches to a different stack that
14 # we don't know how to unwind through. This is a bug. For now,
15 # vmtest.enter_kdump tries to avoid this so we can get some test coverage,
16 # and we skip the tests otherwise.
17 def _skip_if_cpu0_on_s390x(self):
18 if NORMALIZED_MACHINE_NAME == "s390x" and self.prog["panic_cpu"].counter == 0:
19 self.skipTest("drgn can't unwind s390x panic stack on CPU 0")
20
21 def test_cpu(self):
22 self._skip_if_cpu0_on_s390x()
23 cmd = self.check_crash_command("bt -c 0")
24 self.assertIn("CPU: 0", cmd.stdout)
25 self.assertNotIn("(active)", cmd.stdout)
26
27 def test_panic(self):
28 self._skip_if_cpu0_on_s390x()
29 tid = self.prog.crashed_thread().tid
30 for cmd in ("bt", "bt -p"):
31 with self.subTest(cmd=cmd):
32 res = self.check_crash_command(cmd)
33 self.assertIn("drgn_test_crash_func", res.stdout)
34 self.assertIn(f"PID: {tid}", res.stdout)
35 self.assertNotIn("(active)", res.stdout)
36
37 def test_all(self):
38 self._skip_if_cpu0_on_s390x()
39 cmd = self.check_crash_command("bt -a")
40 self.assertNotIn("(active)", cmd.stdout)
41 for cpu in for_each_online_cpu(self.prog):
42 self.assertIn(f"CPU: {cpu}", cmd.stdout)