1*fb785877SMichał Górnyimport os
2*fb785877SMichał Górnyimport struct
3*fb785877SMichał Górnyimport subprocess
4*fb785877SMichał Górny
5*fb785877SMichał Górnyimport lldb
6*fb785877SMichał Górnyfrom lldbsuite.test.decorators import *
7*fb785877SMichał Górnyfrom lldbsuite.test.lldbtest import *
8*fb785877SMichał Górnyfrom lldbsuite.test import lldbutil
9*fb785877SMichał Górny
10*fb785877SMichał Górny
11*fb785877SMichał Górnyclass FreeBSDKernelVMCoreTestCase(TestBase):
12*fb785877SMichał Górny    NO_DEBUG_INFO_TESTCASE = True
13*fb785877SMichał Górny
14*fb785877SMichał Górny    def test_mem(self):
15*fb785877SMichał Górny        kernel_exec = "/boot/kernel/kernel"
16*fb785877SMichał Górny        mem_device = "/dev/mem"
17*fb785877SMichał Górny
18*fb785877SMichał Górny        if not os.access(kernel_exec, os.R_OK):
19*fb785877SMichał Górny            self.skipTest("Kernel @ %s is not readable" % (kernel_exec,))
20*fb785877SMichał Górny        if not os.access(mem_device, os.R_OK):
21*fb785877SMichał Górny            self.skipTest("Memory @ %s is not readable" % (mem_device,))
22*fb785877SMichał Górny
23*fb785877SMichał Górny        target = self.dbg.CreateTarget(kernel_exec)
24*fb785877SMichał Górny        process = target.LoadCore(mem_device)
25*fb785877SMichał Górny        hz_value = int(subprocess.check_output(["sysctl", "-n", "kern.hz"]))
26*fb785877SMichał Górny
27*fb785877SMichał Górny        self.assertTrue(process, PROCESS_IS_VALID)
28*fb785877SMichał Górny        self.assertEqual(process.GetNumThreads(), 1)
29*fb785877SMichał Górny        self.assertEqual(process.GetProcessID(), 0)
30*fb785877SMichał Górny
31*fb785877SMichał Górny        # test memory reading
32*fb785877SMichał Górny        self.expect("expr -- *(int *) &hz",
33*fb785877SMichał Górny                    substrs=["(int) $0 = %d" % hz_value])
34*fb785877SMichał Górny
35*fb785877SMichał Górny        main_mod = target.GetModuleAtIndex(0)
36*fb785877SMichał Górny        hz_addr = (main_mod.FindSymbols("hz")[0].symbol.addr
37*fb785877SMichał Górny                   .GetLoadAddress(target))
38*fb785877SMichał Górny        error = lldb.SBError()
39*fb785877SMichał Górny        self.assertEqual(process.ReadMemory(hz_addr, 4, error),
40*fb785877SMichał Górny                         struct.pack("<I", hz_value))
41*fb785877SMichał Górny
42*fb785877SMichał Górny        self.dbg.DeleteTarget(target)
43