| 1 |
# Copyright (c) 2026 Oracle and/or its affiliates |
| 2 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
|
| 4 |
from tests.linux_kernel import ( |
| 5 |
fork_and_stop, |
| 6 |
skip_unless_have_stack_tracing, |
| 7 |
skip_unless_have_test_kmod, |
| 8 |
) |
| 9 |
from tests.linux_kernel.crash_commands import CrashCommandTestCase |
| 10 |
|
| 11 |
|
| 12 |
@skip_unless_have_stack_tracing |
| 13 |
class TestBt(CrashCommandTestCase): |
| 14 |
def test_no_options(self): |
| 15 |
with fork_and_stop() as pid: |
| 16 |
self.run_crash_command(f"set {pid}") |
| 17 |
cmd = self.check_crash_command("bt") |
| 18 |
self.assertIn(f"PID: {pid}", cmd.stdout) |
| 19 |
self.assertRegex( |
| 20 |
cmd.stdout, r"(?m).*^ *#\d+ \[[0-9a-f]+\] \w+ at [0-9a-f]+$" |
| 21 |
) |
| 22 |
|
| 23 |
def test_pid(self): |
| 24 |
with fork_and_stop() as pid: |
| 25 |
cmd = self.check_crash_command(f"bt {pid}") |
| 26 |
self.assertIn(f"PID: {pid}", cmd.stdout) |
| 27 |
self.assertRegex( |
| 28 |
cmd.stdout, r"(?m).*^ *#\d+ \[[0-9a-f]+\] \w+ at [0-9a-f]+$" |
| 29 |
) |
| 30 |
|
| 31 |
def test_multiple_pids(self): |
| 32 |
with fork_and_stop() as pid1, fork_and_stop() as pid2: |
| 33 |
cmd = self.check_crash_command(f"bt {pid1} {pid2}") |
| 34 |
self.assertIn(f"PID: {pid1}", cmd.stdout) |
| 35 |
self.assertIn(f"PID: {pid2}", cmd.stdout) |
| 36 |
|
| 37 |
@skip_unless_have_test_kmod |
| 38 |
def test_task_struct(self): |
| 39 |
task = self.prog["drgn_test_kthread"] |
| 40 |
cmd = self.check_crash_command(f"bt 0x{task.value_():x}") |
| 41 |
self.assertIn(f"PID: {task.pid.value_()}", cmd.stdout) |
| 42 |
self.assertIn(f"TASK: {task.value_():x}", cmd.stdout) |
| 43 |
self.assertIn("drgn_test_kthread_fn", cmd.stdout) |
| 44 |
self.assertIn("drgn_test_kthread_fn2", cmd.stdout) |
| 45 |
self.assertIn("drgn_test_kthread_fn3", cmd.stdout) |
| 46 |
self.assertIn("[drgn_test]", cmd.stdout) |
| 47 |
|
| 48 |
@skip_unless_have_test_kmod |
| 49 |
def test_frame_data(self): |
| 50 |
task = self.prog["drgn_test_kthread"] |
| 51 |
cmd = self.check_crash_command(f"bt -f 0x{task.value_():x}") |
| 52 |
self.assertRegex(cmd.stdout, "(?m)^ [0-9a-f]+: [0-9a-f]+") |
| 53 |
|
| 54 |
@skip_unless_have_test_kmod |
| 55 |
def test_frame_data_slab(self): |
| 56 |
task = self.prog["drgn_test_kthread"] |
| 57 |
cmd = self.check_crash_command(f"bt -F 0x{task.value_():x}") |
| 58 |
# We know we will find return address symbols on the stack: |
| 59 |
self.assertIn("drgn_test_kthread_fn+", cmd.stdout) |
| 60 |
self.assertIn("drgn_test_kthread_fn2+", cmd.stdout) |
| 61 |
self.assertIn("drgn_test_kthread_fn3+", cmd.stdout) |
| 62 |
# We also know we will find the drgn small slab object, but whether it |
| 63 |
# can be identified depends on kernel configuration (non-SLOB) |
| 64 |
if self.prog["drgn_test_slob"]: |
| 65 |
self.assertIn("[unknown slab object]", cmd.stdout) |
| 66 |
else: |
| 67 |
self.assertIn("[drgn_test_small]", cmd.stdout) |
| 68 |
|
| 69 |
@skip_unless_have_test_kmod |
| 70 |
def test_frame_data_verbose(self): |
| 71 |
task = self.prog["drgn_test_kthread"] |
| 72 |
cmd = self.check_crash_command(f"bt -FF 0x{task.value_():x}") |
| 73 |
# We know we will find return address symbols on the stack: |
| 74 |
self.assertIn("drgn_test_kthread_fn+", cmd.stdout) |
| 75 |
self.assertIn("drgn_test_kthread_fn2+", cmd.stdout) |
| 76 |
self.assertIn("drgn_test_kthread_fn3+", cmd.stdout) |
| 77 |
# We also know we will find the drgn small slab object, but whether it |
| 78 |
# can be identified depends on kernel configuration (non-SLOB) |
| 79 |
if self.prog["drgn_test_slob"]: |
| 80 |
self.assertRegex(cmd.stdout, r"\[[0-9a-f]+:unknown slab object\]") |
| 81 |
else: |
| 82 |
self.assertRegex(cmd.stdout, r"\[[0-9a-f]+:drgn_test_small\]") |
| 83 |
|
| 84 |
@skip_unless_have_test_kmod |
| 85 |
def test_line_numbers(self): |
| 86 |
task = self.prog["drgn_test_kthread"] |
| 87 |
cmd = self.check_crash_command(f"bt -l 0x{task.value_():x}") |
| 88 |
self.assertIn("drgn_test.c", cmd.stdout) |
| 89 |
|
| 90 |
@skip_unless_have_test_kmod |
| 91 |
def test_variables(self): |
| 92 |
task = self.prog["drgn_test_kthread"] |
| 93 |
cmd = self.check_crash_command(f"bt -V 0x{task.value_():x}") |
| 94 |
self.assertIn("a = (volatile int)1", cmd.stdout) |