ipc/ipdl/test/cxx/TestCrashCleanup.cpp

branch
TOR_BUG_3246
changeset 6
8bccb770b82d
equal deleted inserted replaced
-1:000000000000 0:82dc5e995b6b
1 #include "TestCrashCleanup.h"
2
3 #include "mozilla/CondVar.h"
4 #include "mozilla/Mutex.h"
5
6 #include "IPDLUnitTests.h" // fail etc.
7 #include "IPDLUnitTestSubprocess.h"
8
9 using mozilla::CondVar;
10 using mozilla::Mutex;
11 using mozilla::MutexAutoLock;
12
13 namespace mozilla {
14 namespace _ipdltest {
15
16 //-----------------------------------------------------------------------------
17 // parent
18
19 namespace {
20
21 // NB: this test does its own shutdown, rather than going through
22 // QuitParent(), because it's testing degenerate edge cases
23
24 void DeleteSubprocess(Mutex* mutex, CondVar* cvar)
25 {
26 MutexAutoLock lock(*mutex);
27
28 delete gSubprocess;
29 gSubprocess = nullptr;
30
31 cvar->Notify();
32 }
33
34 void DeleteTheWorld()
35 {
36 delete static_cast<TestCrashCleanupParent*>(gParentActor);
37 gParentActor = nullptr;
38
39 // needs to be synchronous to avoid affecting event ordering on
40 // the main thread
41 Mutex mutex("TestCrashCleanup.DeleteTheWorld.mutex");
42 CondVar cvar(mutex, "TestCrashCleanup.DeleteTheWorld.cvar");
43
44 MutexAutoLock lock(mutex);
45
46 XRE_GetIOMessageLoop()->PostTask(
47 FROM_HERE,
48 NewRunnableFunction(DeleteSubprocess, &mutex, &cvar));
49
50 cvar.Wait();
51 }
52
53 void Done()
54 {
55 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
56 nsCOMPtr<nsIAppShell> appShell (do_GetService(kAppShellCID));
57 appShell->Exit();
58
59 passed(__FILE__);
60 }
61
62 } // namespace <anon>
63
64 TestCrashCleanupParent::TestCrashCleanupParent() : mCleanedUp(false)
65 {
66 MOZ_COUNT_CTOR(TestCrashCleanupParent);
67 }
68
69 TestCrashCleanupParent::~TestCrashCleanupParent()
70 {
71 MOZ_COUNT_DTOR(TestCrashCleanupParent);
72
73 if (!mCleanedUp)
74 fail("should have been ActorDestroy()d!");
75 }
76
77 void
78 TestCrashCleanupParent::Main()
79 {
80 // NB: has to be enqueued before IO thread's error notification
81 MessageLoop::current()->PostTask(
82 FROM_HERE, NewRunnableFunction(DeleteTheWorld));
83
84 if (CallDIEDIEDIE())
85 fail("expected an error!");
86
87 Close();
88
89 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction(Done));
90 }
91
92
93 //-----------------------------------------------------------------------------
94 // child
95
96 TestCrashCleanupChild::TestCrashCleanupChild()
97 {
98 MOZ_COUNT_CTOR(TestCrashCleanupChild);
99 }
100
101 TestCrashCleanupChild::~TestCrashCleanupChild()
102 {
103 MOZ_COUNT_DTOR(TestCrashCleanupChild);
104 }
105
106 bool
107 TestCrashCleanupChild::AnswerDIEDIEDIE()
108 {
109 _exit(0);
110 NS_RUNTIMEABORT("unreached");
111 return false;
112 }
113
114
115 } // namespace _ipdltest
116 } // namespace mozilla

mercurial