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