michael@0: #include "TestRacyInterruptReplies.h" michael@0: michael@0: #include "IPDLUnitTests.h" // fail etc. michael@0: michael@0: namespace mozilla { michael@0: namespace _ipdltest { michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // parent michael@0: michael@0: TestRacyInterruptRepliesParent::TestRacyInterruptRepliesParent() : mReplyNum(0) michael@0: { michael@0: MOZ_COUNT_CTOR(TestRacyInterruptRepliesParent); michael@0: } michael@0: michael@0: TestRacyInterruptRepliesParent::~TestRacyInterruptRepliesParent() michael@0: { michael@0: MOZ_COUNT_DTOR(TestRacyInterruptRepliesParent); michael@0: } michael@0: michael@0: void michael@0: TestRacyInterruptRepliesParent::Main() michael@0: { michael@0: int replyNum = -1; michael@0: if (!CallR_(&replyNum)) michael@0: fail("calling R()"); michael@0: michael@0: if (1 != replyNum) michael@0: fail("this should have been the first reply to R()"); michael@0: michael@0: if (!SendChildTest()) michael@0: fail("sending ChildStart"); michael@0: } michael@0: michael@0: bool michael@0: TestRacyInterruptRepliesParent::RecvA_() michael@0: { michael@0: int replyNum = -1; michael@0: // this R() call races with the reply being generated by the other michael@0: // side to the R() call from Main(). This is a pretty nasty edge michael@0: // case for which one could argue we're breaking in-order message michael@0: // delivery, since this side will process the second reply to R() michael@0: // before the first. michael@0: if (!CallR_(&replyNum)) michael@0: fail("calling R()"); michael@0: michael@0: if (2 != replyNum) michael@0: fail("this should have been the second reply to R()"); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: TestRacyInterruptRepliesParent::Answer_R(int* replyNum) michael@0: { michael@0: *replyNum = ++mReplyNum; michael@0: michael@0: if (1 == *replyNum) michael@0: if (!Send_A()) michael@0: fail("sending _A()"); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // child michael@0: michael@0: TestRacyInterruptRepliesChild::TestRacyInterruptRepliesChild() : mReplyNum(0) michael@0: { michael@0: MOZ_COUNT_CTOR(TestRacyInterruptRepliesChild); michael@0: } michael@0: michael@0: TestRacyInterruptRepliesChild::~TestRacyInterruptRepliesChild() michael@0: { michael@0: MOZ_COUNT_DTOR(TestRacyInterruptRepliesChild); michael@0: } michael@0: michael@0: bool michael@0: TestRacyInterruptRepliesChild::AnswerR_(int* replyNum) michael@0: { michael@0: *replyNum = ++mReplyNum; michael@0: michael@0: if (1 == *replyNum) michael@0: SendA_(); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: TestRacyInterruptRepliesChild::RecvChildTest() michael@0: { michael@0: int replyNum = -1; michael@0: if (!Call_R(&replyNum)) michael@0: fail("calling R()"); michael@0: michael@0: if (1 != replyNum) michael@0: fail("this should have been the first reply to R()"); michael@0: michael@0: Close(); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: TestRacyInterruptRepliesChild::Recv_A() michael@0: { michael@0: int replyNum = -1; michael@0: michael@0: if (!Call_R(&replyNum)) michael@0: fail("calling _R()"); michael@0: michael@0: if (2 != replyNum) michael@0: fail("this should have been the second reply to R()"); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: } // namespace _ipdltest michael@0: } // namespace mozilla