1*043036a2SApple OSS Distributions## 2*043036a2SApple OSS Distributions# Copyright (c) 2023 Apple Inc. All rights reserved. 3*043036a2SApple OSS Distributions# 4*043036a2SApple OSS Distributions# @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*043036a2SApple OSS Distributions# 6*043036a2SApple OSS Distributions# This file contains Original Code and/or Modifications of Original Code 7*043036a2SApple OSS Distributions# as defined in and that are subject to the Apple Public Source License 8*043036a2SApple OSS Distributions# Version 2.0 (the 'License'). You may not use this file except in 9*043036a2SApple OSS Distributions# compliance with the License. The rights granted to you under the License 10*043036a2SApple OSS Distributions# may not be used to create, or enable the creation or redistribution of, 11*043036a2SApple OSS Distributions# unlawful or unlicensed copies of an Apple operating system, or to 12*043036a2SApple OSS Distributions# circumvent, violate, or enable the circumvention or violation of, any 13*043036a2SApple OSS Distributions# terms of an Apple operating system software license agreement. 14*043036a2SApple OSS Distributions# 15*043036a2SApple OSS Distributions# Please obtain a copy of the License at 16*043036a2SApple OSS Distributions# http://www.opensource.apple.com/apsl/ and read it before using this file. 17*043036a2SApple OSS Distributions# 18*043036a2SApple OSS Distributions# The Original Code and all software distributed under the License are 19*043036a2SApple OSS Distributions# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*043036a2SApple OSS Distributions# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*043036a2SApple OSS Distributions# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*043036a2SApple OSS Distributions# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*043036a2SApple OSS Distributions# Please see the License for the specific language governing rights and 24*043036a2SApple OSS Distributions# limitations under the License. 25*043036a2SApple OSS Distributions# 26*043036a2SApple OSS Distributions# @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*043036a2SApple OSS Distributions## 28*043036a2SApple OSS Distributions 29*043036a2SApple OSS Distributions# pylint: disable=invalid-name 30*043036a2SApple OSS Distributions 31*043036a2SApple OSS Distributions""" Tests that ScriptedProcess mock behaves as expected. """ 32*043036a2SApple OSS Distributions 33*043036a2SApple OSS Distributionsimport unittest.mock 34*043036a2SApple OSS Distributionsimport io 35*043036a2SApple OSS Distributions 36*043036a2SApple OSS Distributionsimport lldb 37*043036a2SApple OSS Distributionsfrom lldbtest.testcase import LLDBTestCase 38*043036a2SApple OSS Distributionsfrom lldbmock.memorymock import RawMock 39*043036a2SApple OSS Distributionsfrom lldbmock.utils import lookup_type 40*043036a2SApple OSS Distributions 41*043036a2SApple OSS Distributions 42*043036a2SApple OSS Distributionsclass ScriptedProcessTest(LLDBTestCase): 43*043036a2SApple OSS Distributions """ Scripted process unit test. """ 44*043036a2SApple OSS Distributions 45*043036a2SApple OSS Distributions def test_RawMock(self): 46*043036a2SApple OSS Distributions """ Install simple raw memory mock into a target. """ 47*043036a2SApple OSS Distributions 48*043036a2SApple OSS Distributions RAWMOCK_ADDR = 0xffffffff00000000 49*043036a2SApple OSS Distributions 50*043036a2SApple OSS Distributions mock = RawMock(100) 51*043036a2SApple OSS Distributions mock.setData(b"lldb-process-mock\x00") 52*043036a2SApple OSS Distributions self.add_mock(RAWMOCK_ADDR, mock) 53*043036a2SApple OSS Distributions 54*043036a2SApple OSS Distributions # Test is using LLDB command intentionaly. 55*043036a2SApple OSS Distributions res = self.run_command(f'x/s {RAWMOCK_ADDR:#x}') 56*043036a2SApple OSS Distributions 57*043036a2SApple OSS Distributions self.assertTrue(res.Succeeded()) 58*043036a2SApple OSS Distributions self.assertEqual( 59*043036a2SApple OSS Distributions res.GetOutput(), 60*043036a2SApple OSS Distributions f'{RAWMOCK_ADDR:#x}: "lldb-process-mock"\n' 61*043036a2SApple OSS Distributions ) 62*043036a2SApple OSS Distributions 63*043036a2SApple OSS Distributions def test_RawMockIO(self): 64*043036a2SApple OSS Distributions """ Populate simple raw memory mock from provided IO. """ 65*043036a2SApple OSS Distributions 66*043036a2SApple OSS Distributions RAWMOCK_ADDR = 0xffffffff50000000 67*043036a2SApple OSS Distributions 68*043036a2SApple OSS Distributions mock = RawMock.fromBufferedIO(io.BytesIO(b"lldb-io-mock\x00")) 69*043036a2SApple OSS Distributions self.add_mock(RAWMOCK_ADDR, mock) 70*043036a2SApple OSS Distributions 71*043036a2SApple OSS Distributions # Test is using LLDB command intentionaly. 72*043036a2SApple OSS Distributions res = self.run_command(f'x/s {RAWMOCK_ADDR:#x}') 73*043036a2SApple OSS Distributions 74*043036a2SApple OSS Distributions self.assertTrue(res.Succeeded()) 75*043036a2SApple OSS Distributions self.assertEqual( 76*043036a2SApple OSS Distributions res.GetOutput(), 77*043036a2SApple OSS Distributions f'{RAWMOCK_ADDR:#x}: "lldb-io-mock"\n' 78*043036a2SApple OSS Distributions ) 79*043036a2SApple OSS Distributions 80*043036a2SApple OSS Distributions def test_DuplicateMock(self): 81*043036a2SApple OSS Distributions """ Install same simple mock to two VA locations. """ 82*043036a2SApple OSS Distributions 83*043036a2SApple OSS Distributions mock = RawMock(100) 84*043036a2SApple OSS Distributions mock.setData(b"shared-mock\x00") 85*043036a2SApple OSS Distributions self.add_mock(0xffffffff10000000, mock) 86*043036a2SApple OSS Distributions self.add_mock(0xffffffff20000000, mock) 87*043036a2SApple OSS Distributions 88*043036a2SApple OSS Distributions # Test both locations 89*043036a2SApple OSS Distributions for addr in ('0xffffffff10000000', '0xffffffff20000000'): 90*043036a2SApple OSS Distributions res = self.run_command(f'x/s {addr}') 91*043036a2SApple OSS Distributions 92*043036a2SApple OSS Distributions self.assertTrue(res.Succeeded()) 93*043036a2SApple OSS Distributions self.assertEqual( 94*043036a2SApple OSS Distributions res.GetOutput(), 95*043036a2SApple OSS Distributions f'{addr}: "shared-mock"\n' 96*043036a2SApple OSS Distributions ) 97*043036a2SApple OSS Distributions 98*043036a2SApple OSS Distributions def test_MockConflict(self): 99*043036a2SApple OSS Distributions """ Check that we can't add overlapping mocks. """ 100*043036a2SApple OSS Distributions 101*043036a2SApple OSS Distributions mock = RawMock(16) 102*043036a2SApple OSS Distributions self.add_mock(0x12345, mock) 103*043036a2SApple OSS Distributions with self.assertRaises(ValueError): 104*043036a2SApple OSS Distributions mock = RawMock(16) 105*043036a2SApple OSS Distributions self.add_mock(0x12346, mock) 106*043036a2SApple OSS Distributions 107*043036a2SApple OSS Distributions def test_SimpleMock(self): 108*043036a2SApple OSS Distributions """ Mock instance of a simple type. """ 109*043036a2SApple OSS Distributions 110*043036a2SApple OSS Distributions UINT_ADDR = 0xffffffff11223344 111*043036a2SApple OSS Distributions 112*043036a2SApple OSS Distributions self.create_mock('uint32_t', UINT_ADDR).setData(0x1234) 113*043036a2SApple OSS Distributions 114*043036a2SApple OSS Distributions res = self.run_command(f'p/x *((uint32_t *){UINT_ADDR:#x})') 115*043036a2SApple OSS Distributions 116*043036a2SApple OSS Distributions self.assertTrue(res.Succeeded()) 117*043036a2SApple OSS Distributions self.assertEqual(res.GetOutput(), "(uint32_t) 0x00001234\n") 118*043036a2SApple OSS Distributions 119*043036a2SApple OSS Distributions @unittest.skipIf(LLDBTestCase.kernel().startswith('mach.release'), 120*043036a2SApple OSS Distributions "Not available in RELEASE embedded") 121*043036a2SApple OSS Distributions def test_CompoundMock(self): 122*043036a2SApple OSS Distributions """ Mock instance of simple structure. """ 123*043036a2SApple OSS Distributions 124*043036a2SApple OSS Distributions DOFHELPER_ADDR = 0xffffffff11220000 125*043036a2SApple OSS Distributions 126*043036a2SApple OSS Distributions # Construct simple data structure mock. 127*043036a2SApple OSS Distributions self.create_mock('struct dof_helper', DOFHELPER_ADDR).fromDict({ 128*043036a2SApple OSS Distributions 'dofhp_mod': b'mock-mod', 129*043036a2SApple OSS Distributions 'dofhp_addr': 0x1234, 130*043036a2SApple OSS Distributions 'dofhp_dof': 0x5678 131*043036a2SApple OSS Distributions }) 132*043036a2SApple OSS Distributions 133*043036a2SApple OSS Distributions # Construct SBValue on top of the mock. 134*043036a2SApple OSS Distributions addr = self.target.ResolveLoadAddress(DOFHELPER_ADDR) 135*043036a2SApple OSS Distributions sbv = self.target.CreateValueFromAddress( 136*043036a2SApple OSS Distributions 'test', addr, lookup_type('dof_helper_t')) 137*043036a2SApple OSS Distributions 138*043036a2SApple OSS Distributions self.assertTrue(sbv.IsValid() and sbv.error.success) 139*043036a2SApple OSS Distributions 140*043036a2SApple OSS Distributions # Check that LLDB SBAPI returns correct values from mock. 141*043036a2SApple OSS Distributions err = lldb.SBError() 142*043036a2SApple OSS Distributions self.assertEqual( 143*043036a2SApple OSS Distributions sbv.GetChildMemberWithName('dofhp_mod').GetData() 144*043036a2SApple OSS Distributions .GetString(err, 0), 145*043036a2SApple OSS Distributions "mock-mod" 146*043036a2SApple OSS Distributions ) 147*043036a2SApple OSS Distributions self.assertEqual( 148*043036a2SApple OSS Distributions sbv.GetChildMemberWithName('dofhp_addr').GetValueAsUnsigned(), 149*043036a2SApple OSS Distributions 0x1234 150*043036a2SApple OSS Distributions ) 151*043036a2SApple OSS Distributions self.assertEqual( 152*043036a2SApple OSS Distributions sbv.GetChildMemberWithName('dofhp_dof').GetValueAsUnsigned(), 153*043036a2SApple OSS Distributions 0x5678 154*043036a2SApple OSS Distributions ) 155*043036a2SApple OSS Distributions 156*043036a2SApple OSS Distributions @unittest.skipIf(LLDBTestCase.kernel().startswith('mach.release'), 157*043036a2SApple OSS Distributions "Not available in RELEASE embedded") 158*043036a2SApple OSS Distributions def test_CompoundMock_UpdateProperty(self): 159*043036a2SApple OSS Distributions """ Test that mock can deserilize properties from update. """ 160*043036a2SApple OSS Distributions 161*043036a2SApple OSS Distributions mock = self.create_mock('struct dof_helper', 0xffffffff55555555) 162*043036a2SApple OSS Distributions mock.setData( 163*043036a2SApple OSS Distributions b'hello-mock' + b'\x00'*54 + 164*043036a2SApple OSS Distributions 0xfeedface.to_bytes(length=8, byteorder='little') + 165*043036a2SApple OSS Distributions 0xdeadbeef.to_bytes(length=8, byteorder='little')) 166*043036a2SApple OSS Distributions 167*043036a2SApple OSS Distributions # Test that mock has de-serialized correctly whole blob above. 168*043036a2SApple OSS Distributions self.assertEqual(mock.dofhp_mod[:10], b'hello-mock') 169*043036a2SApple OSS Distributions self.assertEqual(mock.dofhp_addr, 0xfeedface) 170*043036a2SApple OSS Distributions self.assertEqual(mock.dofhp_dof, 0xdeadbeef) 171*043036a2SApple OSS Distributions 172*043036a2SApple OSS Distributions def test_UnionMock(self): 173*043036a2SApple OSS Distributions """ Test that simple union/bitfield propagates property updates. """ 174*043036a2SApple OSS Distributions 175*043036a2SApple OSS Distributions mock = self.create_mock('kds_ptr', 0xffffffff30000000) 176*043036a2SApple OSS Distributions 177*043036a2SApple OSS Distributions mock.buffer_index = 0b111111111111111111111 # 21-bits 178*043036a2SApple OSS Distributions self.assertEqual(mock.raw, 0x001fffff) 179*043036a2SApple OSS Distributions 180*043036a2SApple OSS Distributions mock.buffer_index = 0 181*043036a2SApple OSS Distributions mock.offset = 0b11111111111 # 11-bits 182*043036a2SApple OSS Distributions self.assertEqual(mock.raw, 0xffe00000) 183*043036a2SApple OSS Distributions 184*043036a2SApple OSS Distributions mock.raw = 0xffdffffe 185*043036a2SApple OSS Distributions self.assertEqual(mock.buffer_index, 0x001ffffe) 186*043036a2SApple OSS Distributions self.assertEqual(mock.offset, 0x7fe) 187*043036a2SApple OSS Distributions 188*043036a2SApple OSS Distributions def test_MockArray(self): 189*043036a2SApple OSS Distributions """ Test simple mock of char array. """ 190*043036a2SApple OSS Distributions 191*043036a2SApple OSS Distributions STR_ADDR = 0xffffffff33004400 192*043036a2SApple OSS Distributions PTR_ADDR = 0xffffffff44000000 193*043036a2SApple OSS Distributions 194*043036a2SApple OSS Distributions # Construct an array in memory. 195*043036a2SApple OSS Distributions arrtype = lookup_type('char').GetArrayType(256) 196*043036a2SApple OSS Distributions marray = self.create_mock(arrtype, STR_ADDR) 197*043036a2SApple OSS Distributions marray.setData(b'Hello World\x00') 198*043036a2SApple OSS Distributions 199*043036a2SApple OSS Distributions # Create a pointer to the array 200*043036a2SApple OSS Distributions ptrtype = lookup_type('char').GetPointerType() 201*043036a2SApple OSS Distributions mstr = self.create_mock(ptrtype, PTR_ADDR) 202*043036a2SApple OSS Distributions mstr.setData(STR_ADDR) 203*043036a2SApple OSS Distributions 204*043036a2SApple OSS Distributions # Let LLDB print it. 205*043036a2SApple OSS Distributions addr = self.target.ResolveLoadAddress(PTR_ADDR) 206*043036a2SApple OSS Distributions sbv = self.target.CreateValueFromAddress('str', addr, ptrtype) 207*043036a2SApple OSS Distributions self.assertTrue(sbv.IsValid() and sbv.error.success) 208*043036a2SApple OSS Distributions 209*043036a2SApple OSS Distributions err = lldb.SBError() 210*043036a2SApple OSS Distributions self.assertEqual(sbv.GetPointeeData(0, 256).GetString(err, 0), 211*043036a2SApple OSS Distributions 'Hello World') 212*043036a2SApple OSS Distributions 213*043036a2SApple OSS Distributions def test_MockTypedArray(self): 214*043036a2SApple OSS Distributions """ Test array of compound types. """ 215*043036a2SApple OSS Distributions 216*043036a2SApple OSS Distributions ARRAY_ADDR = 0xffffffff44003300 217*043036a2SApple OSS Distributions 218*043036a2SApple OSS Distributions arrtype = lookup_type('proc').GetArrayType(10) 219*043036a2SApple OSS Distributions self.create_mock(arrtype, ARRAY_ADDR).fromDict({ 220*043036a2SApple OSS Distributions '0': { 221*043036a2SApple OSS Distributions 'p_comm': b'bar-foo\x00' 222*043036a2SApple OSS Distributions }, 223*043036a2SApple OSS Distributions '1': { 224*043036a2SApple OSS Distributions 'p_comm': b'foo-bar\x00' 225*043036a2SApple OSS Distributions } 226*043036a2SApple OSS Distributions }) 227*043036a2SApple OSS Distributions 228*043036a2SApple OSS Distributions res = self.run_command(f'p/x ((proc_t){ARRAY_ADDR:#x})[1].p_comm') 229*043036a2SApple OSS Distributions self.assertTrue(res.Succeeded()) 230*043036a2SApple OSS Distributions 231*043036a2SApple OSS Distributions # Check that elements don't overlap somehow 232*043036a2SApple OSS Distributions # (use SBValue to exercise LLDB's internals) 233*043036a2SApple OSS Distributions addr = self.target.ResolveLoadAddress(ARRAY_ADDR) 234*043036a2SApple OSS Distributions sbv = self.target.CreateValueFromAddress('proc_arr', addr, arrtype) 235*043036a2SApple OSS Distributions self.assertTrue(sbv.IsValid() and sbv.error.success) 236*043036a2SApple OSS Distributions 237*043036a2SApple OSS Distributions err = lldb.SBError() 238*043036a2SApple OSS Distributions self.assertEqual( 239*043036a2SApple OSS Distributions sbv.GetChildAtIndex(0).GetChildMemberWithName('p_comm') 240*043036a2SApple OSS Distributions .GetData().GetString(err, 0), 241*043036a2SApple OSS Distributions 'bar-foo' 242*043036a2SApple OSS Distributions ) 243*043036a2SApple OSS Distributions self.assertEqual( 244*043036a2SApple OSS Distributions sbv.GetChildAtIndex(1).GetChildMemberWithName('p_comm') 245*043036a2SApple OSS Distributions .GetData().GetString(err, 0), 246*043036a2SApple OSS Distributions 'foo-bar' 247*043036a2SApple OSS Distributions ) 248*043036a2SApple OSS Distributions 249*043036a2SApple OSS Distributions def test_NoNewAttributes(self): 250*043036a2SApple OSS Distributions """ Test that mock instances are properly frozen after creation. """ 251*043036a2SApple OSS Distributions 252*043036a2SApple OSS Distributions mock = self.create_mock(lookup_type('uint32_t')) 253*043036a2SApple OSS Distributions 254*043036a2SApple OSS Distributions with self.assertRaises(TypeError): 255*043036a2SApple OSS Distributions mock.foo = 5 256*043036a2SApple OSS Distributions 257*043036a2SApple OSS Distributions @unittest.skipIf(LLDBTestCase.kernel().startswith('mach.release'), 258*043036a2SApple OSS Distributions "Not available in RELEASE embedded") 259*043036a2SApple OSS Distributions def test_NestedStruct(self): 260*043036a2SApple OSS Distributions """ Test that nested mocks properly serialize. """ 261*043036a2SApple OSS Distributions 262*043036a2SApple OSS Distributions PROVNAME_ADDR = 0xffffffff70707070 263*043036a2SApple OSS Distributions DTHELPER_ADDR = 0xffffffff80808080 264*043036a2SApple OSS Distributions 265*043036a2SApple OSS Distributions # Setup mock with fake values. 266*043036a2SApple OSS Distributions arrtype = lookup_type('char').GetArrayType(256) 267*043036a2SApple OSS Distributions marray = self.create_mock(arrtype, PROVNAME_ADDR) 268*043036a2SApple OSS Distributions marray.setData(b'test-prov\x00') 269*043036a2SApple OSS Distributions 270*043036a2SApple OSS Distributions sbtype = lookup_type('dtrace_helper_provdesc_t') 271*043036a2SApple OSS Distributions mock = self.create_mock(sbtype, DTHELPER_ADDR) 272*043036a2SApple OSS Distributions 273*043036a2SApple OSS Distributions mock.dthpv_provname = PROVNAME_ADDR 274*043036a2SApple OSS Distributions mock.dthpv_pattr.dtpa_mod.dtat_name = 0x5 275*043036a2SApple OSS Distributions 276*043036a2SApple OSS Distributions # Serializer should prevent overflowing a member's size. 277*043036a2SApple OSS Distributions with self.assertRaises(OverflowError): 278*043036a2SApple OSS Distributions mock.dthpv_pattr.dtpa_args.dtat_class = 0x7777 279*043036a2SApple OSS Distributions 280*043036a2SApple OSS Distributions mock.dthpv_pattr.dtpa_args.dtat_class = 0x77 281*043036a2SApple OSS Distributions 282*043036a2SApple OSS Distributions # Obtain SBValue and check modified members 283*043036a2SApple OSS Distributions addr = self.target.ResolveLoadAddress(DTHELPER_ADDR) 284*043036a2SApple OSS Distributions sbv = self.target.CreateValueFromAddress('test', addr, sbtype) 285*043036a2SApple OSS Distributions self.assertTrue(sbv.IsValid() and sbv.error.success) 286*043036a2SApple OSS Distributions 287*043036a2SApple OSS Distributions err = lldb.SBError() 288*043036a2SApple OSS Distributions self.assertEqual( 289*043036a2SApple OSS Distributions sbv.GetChildMemberWithName('dthpv_provname') 290*043036a2SApple OSS Distributions .GetPointeeData(0, 256).GetString(err, 0), 291*043036a2SApple OSS Distributions 'test-prov' 292*043036a2SApple OSS Distributions ) 293*043036a2SApple OSS Distributions self.assertEqual( 294*043036a2SApple OSS Distributions sbv.GetValueForExpressionPath('.dthpv_pattr.dtpa_mod.dtat_name') 295*043036a2SApple OSS Distributions .GetValueAsUnsigned(), 296*043036a2SApple OSS Distributions 0x5 297*043036a2SApple OSS Distributions ) 298*043036a2SApple OSS Distributions self.assertEqual( 299*043036a2SApple OSS Distributions sbv.GetValueForExpressionPath('.dthpv_pattr.dtpa_args.dtat_class') 300*043036a2SApple OSS Distributions .GetValueAsUnsigned(), 301*043036a2SApple OSS Distributions 0x77 302*043036a2SApple OSS Distributions ) 303*043036a2SApple OSS Distributions 304*043036a2SApple OSS Distributions @unittest.mock.patch('xnu.kern.globals.proc_struct_size', 2048) 305*043036a2SApple OSS Distributions def test_ProxyMock(self): 306*043036a2SApple OSS Distributions """ Test anonymous members forwarding. """ 307*043036a2SApple OSS Distributions 308*043036a2SApple OSS Distributions PROC_ADDR = 0xffffffff90909090 309*043036a2SApple OSS Distributions PROC_RO_ADDR = 0xffffff0040404040 310*043036a2SApple OSS Distributions 311*043036a2SApple OSS Distributions mock = self.create_mock('proc', PROC_ADDR) 312*043036a2SApple OSS Distributions 313*043036a2SApple OSS Distributions mock.p_list.le_next = 0x12345678 314*043036a2SApple OSS Distributions mock.p_smr_node.smrn_next = 0x12345678 315*043036a2SApple OSS Distributions mock.p_pid = 12345 316*043036a2SApple OSS Distributions mock.p_argc = 0x5 317*043036a2SApple OSS Distributions mock.p_textvp = 0xfeedface 318*043036a2SApple OSS Distributions mock.p_lflag = 0x00000002 319*043036a2SApple OSS Distributions 320*043036a2SApple OSS Distributions mock.p_comm = b'foobar' # Use forwarding property 321*043036a2SApple OSS Distributions 322*043036a2SApple OSS Distributions task = self.create_mock('task', PROC_ADDR + 2048) 323*043036a2SApple OSS Distributions 324*043036a2SApple OSS Distributions task.effective_policy.tep_sup_active = 0 325*043036a2SApple OSS Distributions task.effective_policy.tep_darwinbg = 0 326*043036a2SApple OSS Distributions task.effective_policy.tep_lowpri_cpu = 1 327*043036a2SApple OSS Distributions task.t_flags = 0x00800000 328*043036a2SApple OSS Distributions 329*043036a2SApple OSS Distributions self.create_mock('proc_ro', PROC_RO_ADDR) 330*043036a2SApple OSS Distributions 331*043036a2SApple OSS Distributions mock.p_proc_ro = PROC_RO_ADDR 332*043036a2SApple OSS Distributions task.bsd_info_ro = PROC_RO_ADDR 333*043036a2SApple OSS Distributions 334*043036a2SApple OSS Distributions # Populate and test mock. 335*043036a2SApple OSS Distributions res = self.run_command(f'p/x ((proc_t){PROC_ADDR:#x})->p_comm') 336*043036a2SApple OSS Distributions self.assertEqual(res.GetOutput(), '(command_t) "foobar"\n') 337*043036a2SApple OSS Distributions self.assertTrue(res.Succeeded()) 338*043036a2SApple OSS Distributions 339*043036a2SApple OSS Distributions # Modify mock and test again. 340*043036a2SApple OSS Distributions mock.p_forkcopy.p_comm = b'barfoo' # Sub-mock prop wins 341*043036a2SApple OSS Distributions self.invalidate_cache() 342*043036a2SApple OSS Distributions 343*043036a2SApple OSS Distributions res = self.run_command(f'p/x ((proc_t){PROC_ADDR:#x})->p_comm') 344*043036a2SApple OSS Distributions self.assertEqual(res.GetOutput(), '(command_t) "barfoo"\n') 345*043036a2SApple OSS Distributions self.assertTrue(res.Succeeded()) 346