ipc/ipdl/test/cxx/TestShutdown.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial