1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/ipdl/test/cxx/TestShutdown.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,235 @@ 1.4 +#include "TestShutdown.h" 1.5 + 1.6 +namespace mozilla { 1.7 +namespace _ipdltest { 1.8 + 1.9 +//----------------------------------------------------------------------------- 1.10 +// Parent side 1.11 +void 1.12 +TestShutdownParent::Main() 1.13 +{ 1.14 + if (!SendStart()) 1.15 + fail("sending Start()"); 1.16 +} 1.17 + 1.18 +void 1.19 +TestShutdownParent::ActorDestroy(ActorDestroyReason why) 1.20 +{ 1.21 + if (AbnormalShutdown != why) 1.22 + fail("should have ended test with crash!"); 1.23 + 1.24 + passed("ok"); 1.25 + 1.26 + QuitParent(); 1.27 +} 1.28 + 1.29 +void 1.30 +TestShutdownSubParent::ActorDestroy(ActorDestroyReason why) 1.31 +{ 1.32 + if (Manager()->ManagedPTestShutdownSubParent().Length() == 0) 1.33 + fail("manager should still have managees!"); 1.34 + 1.35 + if (mExpectCrash && AbnormalShutdown != why) 1.36 + fail("expected crash!"); 1.37 + else if (!mExpectCrash && AbnormalShutdown == why) 1.38 + fail("wasn't expecting crash!"); 1.39 + 1.40 + if (mExpectCrash && 0 == ManagedPTestShutdownSubsubParent().Length()) 1.41 + fail("expected to *still* have kids"); 1.42 +} 1.43 + 1.44 +void 1.45 +TestShutdownSubsubParent::ActorDestroy(ActorDestroyReason why) 1.46 +{ 1.47 + if (Manager()->ManagedPTestShutdownSubsubParent().Length() == 0) 1.48 + fail("manager should still have managees!"); 1.49 + 1.50 + if (mExpectParentDeleted && AncestorDeletion != why) 1.51 + fail("expected ParentDeleted == why"); 1.52 + else if (!mExpectParentDeleted && AncestorDeletion == why) 1.53 + fail("wasn't expecting parent delete"); 1.54 +} 1.55 + 1.56 +//----------------------------------------------------------------------------- 1.57 +// Child side 1.58 + 1.59 +bool 1.60 +TestShutdownChild::RecvStart() 1.61 +{ 1.62 + // test 1: alloc some actors and subactors, delete in 1.63 + // managee-before-manager order 1.64 + { 1.65 + bool expectCrash = false, expectParentDeleted = false; 1.66 + 1.67 + PTestShutdownSubChild* c1 = 1.68 + SendPTestShutdownSubConstructor(expectCrash); 1.69 + if (!c1) 1.70 + fail("problem sending ctor"); 1.71 + 1.72 + PTestShutdownSubChild* c2 = 1.73 + SendPTestShutdownSubConstructor(expectCrash); 1.74 + if (!c2) 1.75 + fail("problem sending ctor"); 1.76 + 1.77 + PTestShutdownSubsubChild* c1s1 = 1.78 + c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.79 + if (!c1s1) 1.80 + fail("problem sending ctor"); 1.81 + PTestShutdownSubsubChild* c1s2 = 1.82 + c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.83 + if (!c1s2) 1.84 + fail("problem sending ctor"); 1.85 + 1.86 + PTestShutdownSubsubChild* c2s1 = 1.87 + c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.88 + if (!c2s1) 1.89 + fail("problem sending ctor"); 1.90 + PTestShutdownSubsubChild* c2s2 = 1.91 + c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.92 + if (!c2s2) 1.93 + fail("problem sending ctor"); 1.94 + 1.95 + if (!PTestShutdownSubsubChild::Send__delete__(c1s1)) 1.96 + fail("problem sending dtor"); 1.97 + if (!PTestShutdownSubsubChild::Send__delete__(c1s2)) 1.98 + fail("problem sending dtor"); 1.99 + if (!PTestShutdownSubsubChild::Send__delete__(c2s1)) 1.100 + fail("problem sending dtor"); 1.101 + if (!PTestShutdownSubsubChild::Send__delete__(c2s2)) 1.102 + fail("problem sending dtor"); 1.103 + 1.104 + if (!c1->CallStackFrame()) 1.105 + fail("problem creating dummy stack frame"); 1.106 + if (!c2->CallStackFrame()) 1.107 + fail("problem creating dummy stack frame"); 1.108 + } 1.109 + 1.110 + // test 2: alloc some actors and subactors, delete managers first 1.111 + { 1.112 + bool expectCrash = false, expectParentDeleted = true; 1.113 + 1.114 + PTestShutdownSubChild* c1 = 1.115 + SendPTestShutdownSubConstructor(expectCrash); 1.116 + if (!c1) 1.117 + fail("problem sending ctor"); 1.118 + 1.119 + PTestShutdownSubChild* c2 = 1.120 + SendPTestShutdownSubConstructor(expectCrash); 1.121 + if (!c2) 1.122 + fail("problem sending ctor"); 1.123 + 1.124 + PTestShutdownSubsubChild* c1s1 = 1.125 + c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.126 + if (!c1s1) 1.127 + fail("problem sending ctor"); 1.128 + PTestShutdownSubsubChild* c1s2 = 1.129 + c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.130 + if (!c1s2) 1.131 + fail("problem sending ctor"); 1.132 + 1.133 + PTestShutdownSubsubChild* c2s1 = 1.134 + c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.135 + if (!c2s1) 1.136 + fail("problem sending ctor"); 1.137 + PTestShutdownSubsubChild* c2s2 = 1.138 + c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.139 + if (!c2s2) 1.140 + fail("problem sending ctor"); 1.141 + 1.142 + // delete parents without deleting kids 1.143 + if (!c1->CallStackFrame()) 1.144 + fail("problem creating dummy stack frame"); 1.145 + if (!c2->CallStackFrame()) 1.146 + fail("problem creating dummy stack frame"); 1.147 + } 1.148 + 1.149 + // test 3: alloc some actors and subactors, then crash 1.150 + { 1.151 + bool expectCrash = true, expectParentDeleted = false; 1.152 + 1.153 + PTestShutdownSubChild* c1 = 1.154 + SendPTestShutdownSubConstructor(expectCrash); 1.155 + if (!c1) 1.156 + fail("problem sending ctor"); 1.157 + 1.158 + PTestShutdownSubChild* c2 = 1.159 + SendPTestShutdownSubConstructor(expectCrash); 1.160 + if (!c2) 1.161 + fail("problem sending ctor"); 1.162 + 1.163 + PTestShutdownSubsubChild* c1s1 = 1.164 + c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.165 + if (!c1s1) 1.166 + fail("problem sending ctor"); 1.167 + PTestShutdownSubsubChild* c1s2 = 1.168 + c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.169 + if (!c1s2) 1.170 + fail("problem sending ctor"); 1.171 + 1.172 + PTestShutdownSubsubChild* c2s1 = 1.173 + c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.174 + if (!c2s1) 1.175 + fail("problem sending ctor"); 1.176 + PTestShutdownSubsubChild* c2s2 = 1.177 + c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); 1.178 + if (!c2s2) 1.179 + fail("problem sending ctor"); 1.180 + 1.181 + // make sure the ctors have been processed by the other side; 1.182 + // the write end of the socket may temporarily be unwriteable 1.183 + if (!SendSync()) 1.184 + fail("can't synchronize with parent"); 1.185 + 1.186 + // "crash", but without tripping tinderbox assert/abort 1.187 + // detectors 1.188 + _exit(0); 1.189 + } 1.190 +} 1.191 + 1.192 +void 1.193 +TestShutdownChild::ActorDestroy(ActorDestroyReason why) 1.194 +{ 1.195 + fail("hey wait ... we should have crashed!"); 1.196 +} 1.197 + 1.198 +bool 1.199 +TestShutdownSubChild::AnswerStackFrame() 1.200 +{ 1.201 + if (!PTestShutdownSubChild::Send__delete__(this)) 1.202 + fail("problem sending dtor"); 1.203 + 1.204 + // WATCH OUT! |this| has just deleted 1.205 + 1.206 + return true; 1.207 +} 1.208 + 1.209 +void 1.210 +TestShutdownSubChild::ActorDestroy(ActorDestroyReason why) 1.211 +{ 1.212 + if (Manager()->ManagedPTestShutdownSubChild().Length() == 0) 1.213 + fail("manager should still have managees!"); 1.214 + 1.215 + if (mExpectCrash && AbnormalShutdown != why) 1.216 + fail("expected crash!"); 1.217 + else if (!mExpectCrash && AbnormalShutdown == why) 1.218 + fail("wasn't expecting crash!"); 1.219 + 1.220 + if (mExpectCrash && 0 == ManagedPTestShutdownSubsubChild().Length()) 1.221 + fail("expected to *still* have kids"); 1.222 +} 1.223 + 1.224 +void 1.225 +TestShutdownSubsubChild::ActorDestroy(ActorDestroyReason why) 1.226 +{ 1.227 + if (Manager()->ManagedPTestShutdownSubsubChild().Length() == 0) 1.228 + fail("manager should still have managees!"); 1.229 + 1.230 + if (mExpectParentDeleted && AncestorDeletion != why) 1.231 + fail("expected ParentDeleted == why"); 1.232 + else if (!mExpectParentDeleted && AncestorDeletion == why) 1.233 + fail("wasn't expecting parent delete"); 1.234 +} 1.235 + 1.236 + 1.237 +} // namespace _ipdltest 1.238 +} // namespace mozilla