ipc/ipdl/test/cxx/TestRacyInterruptReplies.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 "TestRacyInterruptReplies.h"
     3 #include "IPDLUnitTests.h"      // fail etc.
     5 namespace mozilla {
     6 namespace _ipdltest {
     8 //-----------------------------------------------------------------------------
     9 // parent
    11 TestRacyInterruptRepliesParent::TestRacyInterruptRepliesParent() : mReplyNum(0)
    12 {
    13     MOZ_COUNT_CTOR(TestRacyInterruptRepliesParent);
    14 }
    16 TestRacyInterruptRepliesParent::~TestRacyInterruptRepliesParent()
    17 {
    18     MOZ_COUNT_DTOR(TestRacyInterruptRepliesParent);
    19 }
    21 void
    22 TestRacyInterruptRepliesParent::Main()
    23 {
    24     int replyNum = -1;
    25     if (!CallR_(&replyNum))
    26         fail("calling R()");
    28     if (1 != replyNum)
    29         fail("this should have been the first reply to R()");
    31     if (!SendChildTest())
    32         fail("sending ChildStart");
    33 }
    35 bool
    36 TestRacyInterruptRepliesParent::RecvA_()
    37 {
    38     int replyNum = -1;
    39     // this R() call races with the reply being generated by the other
    40     // side to the R() call from Main().  This is a pretty nasty edge
    41     // case for which one could argue we're breaking in-order message
    42     // delivery, since this side will process the second reply to R()
    43     // before the first.
    44     if (!CallR_(&replyNum))
    45         fail("calling R()");
    47     if (2 != replyNum)
    48         fail("this should have been the second reply to R()");
    50     return true;
    51 }
    53 bool
    54 TestRacyInterruptRepliesParent::Answer_R(int* replyNum)
    55 {
    56     *replyNum = ++mReplyNum;
    58     if (1 == *replyNum)
    59         if (!Send_A())
    60             fail("sending _A()");
    62     return true;
    63 }
    65 //-----------------------------------------------------------------------------
    66 // child
    68 TestRacyInterruptRepliesChild::TestRacyInterruptRepliesChild() : mReplyNum(0)
    69 {
    70     MOZ_COUNT_CTOR(TestRacyInterruptRepliesChild);
    71 }
    73 TestRacyInterruptRepliesChild::~TestRacyInterruptRepliesChild()
    74 {
    75     MOZ_COUNT_DTOR(TestRacyInterruptRepliesChild);
    76 }
    78 bool
    79 TestRacyInterruptRepliesChild::AnswerR_(int* replyNum)
    80 {
    81     *replyNum = ++mReplyNum;
    83     if (1 == *replyNum)
    84         SendA_();
    86     return true;
    87 }
    89 bool
    90 TestRacyInterruptRepliesChild::RecvChildTest()
    91 {
    92     int replyNum = -1;
    93     if (!Call_R(&replyNum))
    94         fail("calling R()");
    96     if (1 != replyNum)
    97         fail("this should have been the first reply to R()");
    99     Close();
   101     return true;
   102 }
   104 bool
   105 TestRacyInterruptRepliesChild::Recv_A()
   106 {
   107     int replyNum = -1;
   109     if (!Call_R(&replyNum))
   110         fail("calling _R()");
   112     if (2 != replyNum)
   113         fail("this should have been the second reply to R()");
   115     return true;
   116 }
   118 } // namespace _ipdltest
   119 } // namespace mozilla

mercurial