-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test-case for kernel crash dump threads
- Loading branch information
1 parent
195d31d
commit ffb97e8
Showing
3 changed files
with
47 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from pathlib import Path | ||
import unittest | ||
|
||
import drgn | ||
from tests import TestCase | ||
|
||
VMCORE_PATH = Path("/proc/vmcore") | ||
|
||
|
||
@unittest.skipUnless(VMCORE_PATH.exists(), "not running in kdump") | ||
class LinuxVMCoreTestCase(TestCase): | ||
prog = None | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
# We only want to create the Program once for all tests, so it's cached | ||
# as a class variable (in the base class). | ||
if LinuxVMCoreTestCase.prog is None: | ||
prog = drgn.Program() | ||
prog.set_core_dump(VMCORE_PATH) | ||
prog.load_default_debug_info() | ||
LinuxVMCoreTestCase.prog = prog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
from pathlib import Path | ||
import unittest | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from drgn import Program, ProgramFlags | ||
from drgn import ProgramFlags | ||
from tests.linux_kernel.vmcore import LinuxVMCoreTestCase | ||
|
||
VMCORE_PATH = Path("/proc/vmcore") | ||
|
||
class TestVMCore(LinuxVMCoreTestCase): | ||
def test_program_flags(self): | ||
self.assertFalse(self.prog.flags & ProgramFlags.IS_LIVE) | ||
self.assertTrue(self.prog.flags & ProgramFlags.IS_LINUX_KERNEL) | ||
|
||
@unittest.skipUnless(VMCORE_PATH.exists(), "not running in kdump") | ||
class TestAttachToVMCore(unittest.TestCase): | ||
def test_attach_to_vmcore(self): | ||
prog = Program() | ||
prog.set_core_dump("/proc/vmcore") | ||
self.assertFalse(prog.flags & ProgramFlags.IS_LIVE) | ||
self.assertTrue(prog.flags & ProgramFlags.IS_LINUX_KERNEL) | ||
def test_threads(self): | ||
crashed_thread_tid = self.prog.crashed_thread().tid | ||
self.assertGreater(crashed_thread_tid, 0) | ||
self.assertIn(1, (thread.tid for thread in self.prog.threads())) | ||
self.assertEqual(self.prog.thread(crashed_thread_tid).tid, crashed_thread_tid) | ||
self.assertEqual(self.prog.thread(1).tid, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters