| 1 |
# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
|
| 4 |
import os |
| 5 |
|
| 6 |
from drgn import Object, ObjectNotFoundError, Program |
| 7 |
from tests.linux_kernel import LinuxKernelTestCase, skip_unless_have_test_kmod |
| 8 |
|
| 9 |
|
| 10 |
class TestJiffies(LinuxKernelTestCase): |
| 11 |
def test_jiffies(self): |
| 12 |
self.assertIdentical( |
| 13 |
self.prog["jiffies"], |
| 14 |
Object( |
| 15 |
self.prog, |
| 16 |
"volatile unsigned long", |
| 17 |
address=self.prog.symbol("jiffies").address, |
| 18 |
), |
| 19 |
) |
| 20 |
|
| 21 |
|
| 22 |
class TestUts(LinuxKernelTestCase): |
| 23 |
def test_uts_release(self): |
| 24 |
self.assertEqual( |
| 25 |
self.prog["UTS_RELEASE"].string_().decode(), os.uname().release |
| 26 |
) |
| 27 |
|
| 28 |
def test_uts_release_no_debug_info(self): |
| 29 |
prog = Program() |
| 30 |
prog.set_kernel() |
| 31 |
self.assertEqual(prog["UTS_RELEASE"].string_().decode(), os.uname().release) |
| 32 |
|
| 33 |
|
| 34 |
class TestVmcoreinfo(LinuxKernelTestCase): |
| 35 |
def test_vmcoreinfo(self): |
| 36 |
vmcoreinfo_data = dict( |
| 37 |
line.split("=", 1) |
| 38 |
for line in self.prog["VMCOREINFO"].string_().decode().strip().split("\n") |
| 39 |
) |
| 40 |
self.assertEqual( |
| 41 |
int(vmcoreinfo_data["SYMBOL(init_uts_ns)"], 16), |
| 42 |
self.prog.symbol("init_uts_ns").address, |
| 43 |
) |
| 44 |
|
| 45 |
def test_vmcoreinfo_no_debug_info(self): |
| 46 |
prog = Program() |
| 47 |
prog.set_kernel() |
| 48 |
vmcoreinfo_data = dict( |
| 49 |
line.split("=", 1) |
| 50 |
for line in prog["VMCOREINFO"].string_().decode().strip().split("\n") |
| 51 |
) |
| 52 |
self.assertEqual( |
| 53 |
vmcoreinfo_data["OSRELEASE"], |
| 54 |
os.uname().release, |
| 55 |
) |
| 56 |
|
| 57 |
@skip_unless_have_test_kmod |
| 58 |
def test_constants(self): |
| 59 |
for constant in ( |
| 60 |
"THREAD_SIZE", |
| 61 |
"NR_SECTION_ROOTS", |
| 62 |
"SECTIONS_PER_ROOT", |
| 63 |
"SECTION_SIZE_BITS", |
| 64 |
"MAX_PHYSMEM_BITS", |
| 65 |
"ARCH_PFN_OFFSET", |
| 66 |
): |
| 67 |
with self.subTest(constant=constant): |
| 68 |
try: |
| 69 |
expected = self.prog["drgn_test_" + constant].read_() |
| 70 |
except ObjectNotFoundError: |
| 71 |
with self.assertRaises(ObjectNotFoundError): |
| 72 |
self.prog[constant] |
| 73 |
else: |
| 74 |
self.assertEqual(self.prog[constant], expected) |