ipc/ipdl/test/cxx/TestShutdown.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #include "TestShutdown.h"
michael@0 2
michael@0 3 namespace mozilla {
michael@0 4 namespace _ipdltest {
michael@0 5
michael@0 6 //-----------------------------------------------------------------------------
michael@0 7 // Parent side
michael@0 8 void
michael@0 9 TestShutdownParent::Main()
michael@0 10 {
michael@0 11 if (!SendStart())
michael@0 12 fail("sending Start()");
michael@0 13 }
michael@0 14
michael@0 15 void
michael@0 16 TestShutdownParent::ActorDestroy(ActorDestroyReason why)
michael@0 17 {
michael@0 18 if (AbnormalShutdown != why)
michael@0 19 fail("should have ended test with crash!");
michael@0 20
michael@0 21 passed("ok");
michael@0 22
michael@0 23 QuitParent();
michael@0 24 }
michael@0 25
michael@0 26 void
michael@0 27 TestShutdownSubParent::ActorDestroy(ActorDestroyReason why)
michael@0 28 {
michael@0 29 if (Manager()->ManagedPTestShutdownSubParent().Length() == 0)
michael@0 30 fail("manager should still have managees!");
michael@0 31
michael@0 32 if (mExpectCrash && AbnormalShutdown != why)
michael@0 33 fail("expected crash!");
michael@0 34 else if (!mExpectCrash && AbnormalShutdown == why)
michael@0 35 fail("wasn't expecting crash!");
michael@0 36
michael@0 37 if (mExpectCrash && 0 == ManagedPTestShutdownSubsubParent().Length())
michael@0 38 fail("expected to *still* have kids");
michael@0 39 }
michael@0 40
michael@0 41 void
michael@0 42 TestShutdownSubsubParent::ActorDestroy(ActorDestroyReason why)
michael@0 43 {
michael@0 44 if (Manager()->ManagedPTestShutdownSubsubParent().Length() == 0)
michael@0 45 fail("manager should still have managees!");
michael@0 46
michael@0 47 if (mExpectParentDeleted && AncestorDeletion != why)
michael@0 48 fail("expected ParentDeleted == why");
michael@0 49 else if (!mExpectParentDeleted && AncestorDeletion == why)
michael@0 50 fail("wasn't expecting parent delete");
michael@0 51 }
michael@0 52
michael@0 53 //-----------------------------------------------------------------------------
michael@0 54 // Child side
michael@0 55
michael@0 56 bool
michael@0 57 TestShutdownChild::RecvStart()
michael@0 58 {
michael@0 59 // test 1: alloc some actors and subactors, delete in
michael@0 60 // managee-before-manager order
michael@0 61 {
michael@0 62 bool expectCrash = false, expectParentDeleted = false;
michael@0 63
michael@0 64 PTestShutdownSubChild* c1 =
michael@0 65 SendPTestShutdownSubConstructor(expectCrash);
michael@0 66 if (!c1)
michael@0 67 fail("problem sending ctor");
michael@0 68
michael@0 69 PTestShutdownSubChild* c2 =
michael@0 70 SendPTestShutdownSubConstructor(expectCrash);
michael@0 71 if (!c2)
michael@0 72 fail("problem sending ctor");
michael@0 73
michael@0 74 PTestShutdownSubsubChild* c1s1 =
michael@0 75 c1->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 76 if (!c1s1)
michael@0 77 fail("problem sending ctor");
michael@0 78 PTestShutdownSubsubChild* c1s2 =
michael@0 79 c1->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 80 if (!c1s2)
michael@0 81 fail("problem sending ctor");
michael@0 82
michael@0 83 PTestShutdownSubsubChild* c2s1 =
michael@0 84 c2->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 85 if (!c2s1)
michael@0 86 fail("problem sending ctor");
michael@0 87 PTestShutdownSubsubChild* c2s2 =
michael@0 88 c2->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 89 if (!c2s2)
michael@0 90 fail("problem sending ctor");
michael@0 91
michael@0 92 if (!PTestShutdownSubsubChild::Send__delete__(c1s1))
michael@0 93 fail("problem sending dtor");
michael@0 94 if (!PTestShutdownSubsubChild::Send__delete__(c1s2))
michael@0 95 fail("problem sending dtor");
michael@0 96 if (!PTestShutdownSubsubChild::Send__delete__(c2s1))
michael@0 97 fail("problem sending dtor");
michael@0 98 if (!PTestShutdownSubsubChild::Send__delete__(c2s2))
michael@0 99 fail("problem sending dtor");
michael@0 100
michael@0 101 if (!c1->CallStackFrame())
michael@0 102 fail("problem creating dummy stack frame");
michael@0 103 if (!c2->CallStackFrame())
michael@0 104 fail("problem creating dummy stack frame");
michael@0 105 }
michael@0 106
michael@0 107 // test 2: alloc some actors and subactors, delete managers first
michael@0 108 {
michael@0 109 bool expectCrash = false, expectParentDeleted = true;
michael@0 110
michael@0 111 PTestShutdownSubChild* c1 =
michael@0 112 SendPTestShutdownSubConstructor(expectCrash);
michael@0 113 if (!c1)
michael@0 114 fail("problem sending ctor");
michael@0 115
michael@0 116 PTestShutdownSubChild* c2 =
michael@0 117 SendPTestShutdownSubConstructor(expectCrash);
michael@0 118 if (!c2)
michael@0 119 fail("problem sending ctor");
michael@0 120
michael@0 121 PTestShutdownSubsubChild* c1s1 =
michael@0 122 c1->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 123 if (!c1s1)
michael@0 124 fail("problem sending ctor");
michael@0 125 PTestShutdownSubsubChild* c1s2 =
michael@0 126 c1->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 127 if (!c1s2)
michael@0 128 fail("problem sending ctor");
michael@0 129
michael@0 130 PTestShutdownSubsubChild* c2s1 =
michael@0 131 c2->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 132 if (!c2s1)
michael@0 133 fail("problem sending ctor");
michael@0 134 PTestShutdownSubsubChild* c2s2 =
michael@0 135 c2->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 136 if (!c2s2)
michael@0 137 fail("problem sending ctor");
michael@0 138
michael@0 139 // delete parents without deleting kids
michael@0 140 if (!c1->CallStackFrame())
michael@0 141 fail("problem creating dummy stack frame");
michael@0 142 if (!c2->CallStackFrame())
michael@0 143 fail("problem creating dummy stack frame");
michael@0 144 }
michael@0 145
michael@0 146 // test 3: alloc some actors and subactors, then crash
michael@0 147 {
michael@0 148 bool expectCrash = true, expectParentDeleted = false;
michael@0 149
michael@0 150 PTestShutdownSubChild* c1 =
michael@0 151 SendPTestShutdownSubConstructor(expectCrash);
michael@0 152 if (!c1)
michael@0 153 fail("problem sending ctor");
michael@0 154
michael@0 155 PTestShutdownSubChild* c2 =
michael@0 156 SendPTestShutdownSubConstructor(expectCrash);
michael@0 157 if (!c2)
michael@0 158 fail("problem sending ctor");
michael@0 159
michael@0 160 PTestShutdownSubsubChild* c1s1 =
michael@0 161 c1->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 162 if (!c1s1)
michael@0 163 fail("problem sending ctor");
michael@0 164 PTestShutdownSubsubChild* c1s2 =
michael@0 165 c1->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 166 if (!c1s2)
michael@0 167 fail("problem sending ctor");
michael@0 168
michael@0 169 PTestShutdownSubsubChild* c2s1 =
michael@0 170 c2->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 171 if (!c2s1)
michael@0 172 fail("problem sending ctor");
michael@0 173 PTestShutdownSubsubChild* c2s2 =
michael@0 174 c2->SendPTestShutdownSubsubConstructor(expectParentDeleted);
michael@0 175 if (!c2s2)
michael@0 176 fail("problem sending ctor");
michael@0 177
michael@0 178 // make sure the ctors have been processed by the other side;
michael@0 179 // the write end of the socket may temporarily be unwriteable
michael@0 180 if (!SendSync())
michael@0 181 fail("can't synchronize with parent");
michael@0 182
michael@0 183 // "crash", but without tripping tinderbox assert/abort
michael@0 184 // detectors
michael@0 185 _exit(0);
michael@0 186 }
michael@0 187 }
michael@0 188
michael@0 189 void
michael@0 190 TestShutdownChild::ActorDestroy(ActorDestroyReason why)
michael@0 191 {
michael@0 192 fail("hey wait ... we should have crashed!");
michael@0 193 }
michael@0 194
michael@0 195 bool
michael@0 196 TestShutdownSubChild::AnswerStackFrame()
michael@0 197 {
michael@0 198 if (!PTestShutdownSubChild::Send__delete__(this))
michael@0 199 fail("problem sending dtor");
michael@0 200
michael@0 201 // WATCH OUT! |this| has just deleted
michael@0 202
michael@0 203 return true;
michael@0 204 }
michael@0 205
michael@0 206 void
michael@0 207 TestShutdownSubChild::ActorDestroy(ActorDestroyReason why)
michael@0 208 {
michael@0 209 if (Manager()->ManagedPTestShutdownSubChild().Length() == 0)
michael@0 210 fail("manager should still have managees!");
michael@0 211
michael@0 212 if (mExpectCrash && AbnormalShutdown != why)
michael@0 213 fail("expected crash!");
michael@0 214 else if (!mExpectCrash && AbnormalShutdown == why)
michael@0 215 fail("wasn't expecting crash!");
michael@0 216
michael@0 217 if (mExpectCrash && 0 == ManagedPTestShutdownSubsubChild().Length())
michael@0 218 fail("expected to *still* have kids");
michael@0 219 }
michael@0 220
michael@0 221 void
michael@0 222 TestShutdownSubsubChild::ActorDestroy(ActorDestroyReason why)
michael@0 223 {
michael@0 224 if (Manager()->ManagedPTestShutdownSubsubChild().Length() == 0)
michael@0 225 fail("manager should still have managees!");
michael@0 226
michael@0 227 if (mExpectParentDeleted && AncestorDeletion != why)
michael@0 228 fail("expected ParentDeleted == why");
michael@0 229 else if (!mExpectParentDeleted && AncestorDeletion == why)
michael@0 230 fail("wasn't expecting parent delete");
michael@0 231 }
michael@0 232
michael@0 233
michael@0 234 } // namespace _ipdltest
michael@0 235 } // namespace mozilla

mercurial