michael@0: #include "TestShutdown.h" michael@0: michael@0: namespace mozilla { michael@0: namespace _ipdltest { michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // Parent side michael@0: void michael@0: TestShutdownParent::Main() michael@0: { michael@0: if (!SendStart()) michael@0: fail("sending Start()"); michael@0: } michael@0: michael@0: void michael@0: TestShutdownParent::ActorDestroy(ActorDestroyReason why) michael@0: { michael@0: if (AbnormalShutdown != why) michael@0: fail("should have ended test with crash!"); michael@0: michael@0: passed("ok"); michael@0: michael@0: QuitParent(); michael@0: } michael@0: michael@0: void michael@0: TestShutdownSubParent::ActorDestroy(ActorDestroyReason why) michael@0: { michael@0: if (Manager()->ManagedPTestShutdownSubParent().Length() == 0) michael@0: fail("manager should still have managees!"); michael@0: michael@0: if (mExpectCrash && AbnormalShutdown != why) michael@0: fail("expected crash!"); michael@0: else if (!mExpectCrash && AbnormalShutdown == why) michael@0: fail("wasn't expecting crash!"); michael@0: michael@0: if (mExpectCrash && 0 == ManagedPTestShutdownSubsubParent().Length()) michael@0: fail("expected to *still* have kids"); michael@0: } michael@0: michael@0: void michael@0: TestShutdownSubsubParent::ActorDestroy(ActorDestroyReason why) michael@0: { michael@0: if (Manager()->ManagedPTestShutdownSubsubParent().Length() == 0) michael@0: fail("manager should still have managees!"); michael@0: michael@0: if (mExpectParentDeleted && AncestorDeletion != why) michael@0: fail("expected ParentDeleted == why"); michael@0: else if (!mExpectParentDeleted && AncestorDeletion == why) michael@0: fail("wasn't expecting parent delete"); michael@0: } michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // Child side michael@0: michael@0: bool michael@0: TestShutdownChild::RecvStart() michael@0: { michael@0: // test 1: alloc some actors and subactors, delete in michael@0: // managee-before-manager order michael@0: { michael@0: bool expectCrash = false, expectParentDeleted = false; michael@0: michael@0: PTestShutdownSubChild* c1 = michael@0: SendPTestShutdownSubConstructor(expectCrash); michael@0: if (!c1) michael@0: fail("problem sending ctor"); michael@0: michael@0: PTestShutdownSubChild* c2 = michael@0: SendPTestShutdownSubConstructor(expectCrash); michael@0: if (!c2) michael@0: fail("problem sending ctor"); michael@0: michael@0: PTestShutdownSubsubChild* c1s1 = michael@0: c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c1s1) michael@0: fail("problem sending ctor"); michael@0: PTestShutdownSubsubChild* c1s2 = michael@0: c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c1s2) michael@0: fail("problem sending ctor"); michael@0: michael@0: PTestShutdownSubsubChild* c2s1 = michael@0: c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c2s1) michael@0: fail("problem sending ctor"); michael@0: PTestShutdownSubsubChild* c2s2 = michael@0: c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c2s2) michael@0: fail("problem sending ctor"); michael@0: michael@0: if (!PTestShutdownSubsubChild::Send__delete__(c1s1)) michael@0: fail("problem sending dtor"); michael@0: if (!PTestShutdownSubsubChild::Send__delete__(c1s2)) michael@0: fail("problem sending dtor"); michael@0: if (!PTestShutdownSubsubChild::Send__delete__(c2s1)) michael@0: fail("problem sending dtor"); michael@0: if (!PTestShutdownSubsubChild::Send__delete__(c2s2)) michael@0: fail("problem sending dtor"); michael@0: michael@0: if (!c1->CallStackFrame()) michael@0: fail("problem creating dummy stack frame"); michael@0: if (!c2->CallStackFrame()) michael@0: fail("problem creating dummy stack frame"); michael@0: } michael@0: michael@0: // test 2: alloc some actors and subactors, delete managers first michael@0: { michael@0: bool expectCrash = false, expectParentDeleted = true; michael@0: michael@0: PTestShutdownSubChild* c1 = michael@0: SendPTestShutdownSubConstructor(expectCrash); michael@0: if (!c1) michael@0: fail("problem sending ctor"); michael@0: michael@0: PTestShutdownSubChild* c2 = michael@0: SendPTestShutdownSubConstructor(expectCrash); michael@0: if (!c2) michael@0: fail("problem sending ctor"); michael@0: michael@0: PTestShutdownSubsubChild* c1s1 = michael@0: c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c1s1) michael@0: fail("problem sending ctor"); michael@0: PTestShutdownSubsubChild* c1s2 = michael@0: c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c1s2) michael@0: fail("problem sending ctor"); michael@0: michael@0: PTestShutdownSubsubChild* c2s1 = michael@0: c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c2s1) michael@0: fail("problem sending ctor"); michael@0: PTestShutdownSubsubChild* c2s2 = michael@0: c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c2s2) michael@0: fail("problem sending ctor"); michael@0: michael@0: // delete parents without deleting kids michael@0: if (!c1->CallStackFrame()) michael@0: fail("problem creating dummy stack frame"); michael@0: if (!c2->CallStackFrame()) michael@0: fail("problem creating dummy stack frame"); michael@0: } michael@0: michael@0: // test 3: alloc some actors and subactors, then crash michael@0: { michael@0: bool expectCrash = true, expectParentDeleted = false; michael@0: michael@0: PTestShutdownSubChild* c1 = michael@0: SendPTestShutdownSubConstructor(expectCrash); michael@0: if (!c1) michael@0: fail("problem sending ctor"); michael@0: michael@0: PTestShutdownSubChild* c2 = michael@0: SendPTestShutdownSubConstructor(expectCrash); michael@0: if (!c2) michael@0: fail("problem sending ctor"); michael@0: michael@0: PTestShutdownSubsubChild* c1s1 = michael@0: c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c1s1) michael@0: fail("problem sending ctor"); michael@0: PTestShutdownSubsubChild* c1s2 = michael@0: c1->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c1s2) michael@0: fail("problem sending ctor"); michael@0: michael@0: PTestShutdownSubsubChild* c2s1 = michael@0: c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c2s1) michael@0: fail("problem sending ctor"); michael@0: PTestShutdownSubsubChild* c2s2 = michael@0: c2->SendPTestShutdownSubsubConstructor(expectParentDeleted); michael@0: if (!c2s2) michael@0: fail("problem sending ctor"); michael@0: michael@0: // make sure the ctors have been processed by the other side; michael@0: // the write end of the socket may temporarily be unwriteable michael@0: if (!SendSync()) michael@0: fail("can't synchronize with parent"); michael@0: michael@0: // "crash", but without tripping tinderbox assert/abort michael@0: // detectors michael@0: _exit(0); michael@0: } michael@0: } michael@0: michael@0: void michael@0: TestShutdownChild::ActorDestroy(ActorDestroyReason why) michael@0: { michael@0: fail("hey wait ... we should have crashed!"); michael@0: } michael@0: michael@0: bool michael@0: TestShutdownSubChild::AnswerStackFrame() michael@0: { michael@0: if (!PTestShutdownSubChild::Send__delete__(this)) michael@0: fail("problem sending dtor"); michael@0: michael@0: // WATCH OUT! |this| has just deleted michael@0: michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: TestShutdownSubChild::ActorDestroy(ActorDestroyReason why) michael@0: { michael@0: if (Manager()->ManagedPTestShutdownSubChild().Length() == 0) michael@0: fail("manager should still have managees!"); michael@0: michael@0: if (mExpectCrash && AbnormalShutdown != why) michael@0: fail("expected crash!"); michael@0: else if (!mExpectCrash && AbnormalShutdown == why) michael@0: fail("wasn't expecting crash!"); michael@0: michael@0: if (mExpectCrash && 0 == ManagedPTestShutdownSubsubChild().Length()) michael@0: fail("expected to *still* have kids"); michael@0: } michael@0: michael@0: void michael@0: TestShutdownSubsubChild::ActorDestroy(ActorDestroyReason why) michael@0: { michael@0: if (Manager()->ManagedPTestShutdownSubsubChild().Length() == 0) michael@0: fail("manager should still have managees!"); michael@0: michael@0: if (mExpectParentDeleted && AncestorDeletion != why) michael@0: fail("expected ParentDeleted == why"); michael@0: else if (!mExpectParentDeleted && AncestorDeletion == why) michael@0: fail("wasn't expecting parent delete"); michael@0: } michael@0: michael@0: michael@0: } // namespace _ipdltest michael@0: } // namespace mozilla