1 # Copyright 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
9 from .trace_test import *
15 Sadly, you can't @trace toplevel functions, as it prevents them
16 from being called in the child process. :(
18 So, we wrap the function of interest.
21 trace_begin("do_work")
26 def AssertTracingEnabled():
27 assert trace_is_enabled()
29 def AssertTracingDisabled():
30 assert not trace_is_enabled()
32 def TryToDisableTracing():
35 class MultiprocessingShimTest(TraceTest):
36 def test_shimmed(self):
37 p = multiprocessing.Process()
38 self.assertTrue(hasattr(p, "_shimmed_by_trace_event"))
40 def test_trace_enable_throws_in_child(self):
43 p = multiprocessing.Pool(1)
44 self.assertRaises(Exception, lambda: p.apply(TryToDisableTracing, ()))
51 def test_trace_enabled_in_child(self):
54 p = multiprocessing.Pool(1)
55 p.apply(AssertTracingEnabled, ())
62 def test_one_func(self):
65 p = multiprocessing.Pool(1)
72 work_events = res.findByName('work')
73 do_work_events = res.findByName('do_work')
74 self.assertEquals(2, len(work_events))
75 self.assertEquals(2, len(do_work_events))