1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/ipdl/test/cxx/TestRacyInterruptReplies.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 1.4 +#include "TestRacyInterruptReplies.h" 1.5 + 1.6 +#include "IPDLUnitTests.h" // fail etc. 1.7 + 1.8 +namespace mozilla { 1.9 +namespace _ipdltest { 1.10 + 1.11 +//----------------------------------------------------------------------------- 1.12 +// parent 1.13 + 1.14 +TestRacyInterruptRepliesParent::TestRacyInterruptRepliesParent() : mReplyNum(0) 1.15 +{ 1.16 + MOZ_COUNT_CTOR(TestRacyInterruptRepliesParent); 1.17 +} 1.18 + 1.19 +TestRacyInterruptRepliesParent::~TestRacyInterruptRepliesParent() 1.20 +{ 1.21 + MOZ_COUNT_DTOR(TestRacyInterruptRepliesParent); 1.22 +} 1.23 + 1.24 +void 1.25 +TestRacyInterruptRepliesParent::Main() 1.26 +{ 1.27 + int replyNum = -1; 1.28 + if (!CallR_(&replyNum)) 1.29 + fail("calling R()"); 1.30 + 1.31 + if (1 != replyNum) 1.32 + fail("this should have been the first reply to R()"); 1.33 + 1.34 + if (!SendChildTest()) 1.35 + fail("sending ChildStart"); 1.36 +} 1.37 + 1.38 +bool 1.39 +TestRacyInterruptRepliesParent::RecvA_() 1.40 +{ 1.41 + int replyNum = -1; 1.42 + // this R() call races with the reply being generated by the other 1.43 + // side to the R() call from Main(). This is a pretty nasty edge 1.44 + // case for which one could argue we're breaking in-order message 1.45 + // delivery, since this side will process the second reply to R() 1.46 + // before the first. 1.47 + if (!CallR_(&replyNum)) 1.48 + fail("calling R()"); 1.49 + 1.50 + if (2 != replyNum) 1.51 + fail("this should have been the second reply to R()"); 1.52 + 1.53 + return true; 1.54 +} 1.55 + 1.56 +bool 1.57 +TestRacyInterruptRepliesParent::Answer_R(int* replyNum) 1.58 +{ 1.59 + *replyNum = ++mReplyNum; 1.60 + 1.61 + if (1 == *replyNum) 1.62 + if (!Send_A()) 1.63 + fail("sending _A()"); 1.64 + 1.65 + return true; 1.66 +} 1.67 + 1.68 +//----------------------------------------------------------------------------- 1.69 +// child 1.70 + 1.71 +TestRacyInterruptRepliesChild::TestRacyInterruptRepliesChild() : mReplyNum(0) 1.72 +{ 1.73 + MOZ_COUNT_CTOR(TestRacyInterruptRepliesChild); 1.74 +} 1.75 + 1.76 +TestRacyInterruptRepliesChild::~TestRacyInterruptRepliesChild() 1.77 +{ 1.78 + MOZ_COUNT_DTOR(TestRacyInterruptRepliesChild); 1.79 +} 1.80 + 1.81 +bool 1.82 +TestRacyInterruptRepliesChild::AnswerR_(int* replyNum) 1.83 +{ 1.84 + *replyNum = ++mReplyNum; 1.85 + 1.86 + if (1 == *replyNum) 1.87 + SendA_(); 1.88 + 1.89 + return true; 1.90 +} 1.91 + 1.92 +bool 1.93 +TestRacyInterruptRepliesChild::RecvChildTest() 1.94 +{ 1.95 + int replyNum = -1; 1.96 + if (!Call_R(&replyNum)) 1.97 + fail("calling R()"); 1.98 + 1.99 + if (1 != replyNum) 1.100 + fail("this should have been the first reply to R()"); 1.101 + 1.102 + Close(); 1.103 + 1.104 + return true; 1.105 +} 1.106 + 1.107 +bool 1.108 +TestRacyInterruptRepliesChild::Recv_A() 1.109 +{ 1.110 + int replyNum = -1; 1.111 + 1.112 + if (!Call_R(&replyNum)) 1.113 + fail("calling _R()"); 1.114 + 1.115 + if (2 != replyNum) 1.116 + fail("this should have been the second reply to R()"); 1.117 + 1.118 + return true; 1.119 +} 1.120 + 1.121 +} // namespace _ipdltest 1.122 +} // namespace mozilla