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