Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #include "TestRacyInterruptReplies.h" |
michael@0 | 2 | |
michael@0 | 3 | #include "IPDLUnitTests.h" // fail etc. |
michael@0 | 4 | |
michael@0 | 5 | namespace mozilla { |
michael@0 | 6 | namespace _ipdltest { |
michael@0 | 7 | |
michael@0 | 8 | //----------------------------------------------------------------------------- |
michael@0 | 9 | // parent |
michael@0 | 10 | |
michael@0 | 11 | TestRacyInterruptRepliesParent::TestRacyInterruptRepliesParent() : mReplyNum(0) |
michael@0 | 12 | { |
michael@0 | 13 | MOZ_COUNT_CTOR(TestRacyInterruptRepliesParent); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | TestRacyInterruptRepliesParent::~TestRacyInterruptRepliesParent() |
michael@0 | 17 | { |
michael@0 | 18 | MOZ_COUNT_DTOR(TestRacyInterruptRepliesParent); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | void |
michael@0 | 22 | TestRacyInterruptRepliesParent::Main() |
michael@0 | 23 | { |
michael@0 | 24 | int replyNum = -1; |
michael@0 | 25 | if (!CallR_(&replyNum)) |
michael@0 | 26 | fail("calling R()"); |
michael@0 | 27 | |
michael@0 | 28 | if (1 != replyNum) |
michael@0 | 29 | fail("this should have been the first reply to R()"); |
michael@0 | 30 | |
michael@0 | 31 | if (!SendChildTest()) |
michael@0 | 32 | fail("sending ChildStart"); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | bool |
michael@0 | 36 | TestRacyInterruptRepliesParent::RecvA_() |
michael@0 | 37 | { |
michael@0 | 38 | int replyNum = -1; |
michael@0 | 39 | // this R() call races with the reply being generated by the other |
michael@0 | 40 | // side to the R() call from Main(). This is a pretty nasty edge |
michael@0 | 41 | // case for which one could argue we're breaking in-order message |
michael@0 | 42 | // delivery, since this side will process the second reply to R() |
michael@0 | 43 | // before the first. |
michael@0 | 44 | if (!CallR_(&replyNum)) |
michael@0 | 45 | fail("calling R()"); |
michael@0 | 46 | |
michael@0 | 47 | if (2 != replyNum) |
michael@0 | 48 | fail("this should have been the second reply to R()"); |
michael@0 | 49 | |
michael@0 | 50 | return true; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | bool |
michael@0 | 54 | TestRacyInterruptRepliesParent::Answer_R(int* replyNum) |
michael@0 | 55 | { |
michael@0 | 56 | *replyNum = ++mReplyNum; |
michael@0 | 57 | |
michael@0 | 58 | if (1 == *replyNum) |
michael@0 | 59 | if (!Send_A()) |
michael@0 | 60 | fail("sending _A()"); |
michael@0 | 61 | |
michael@0 | 62 | return true; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | //----------------------------------------------------------------------------- |
michael@0 | 66 | // child |
michael@0 | 67 | |
michael@0 | 68 | TestRacyInterruptRepliesChild::TestRacyInterruptRepliesChild() : mReplyNum(0) |
michael@0 | 69 | { |
michael@0 | 70 | MOZ_COUNT_CTOR(TestRacyInterruptRepliesChild); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | TestRacyInterruptRepliesChild::~TestRacyInterruptRepliesChild() |
michael@0 | 74 | { |
michael@0 | 75 | MOZ_COUNT_DTOR(TestRacyInterruptRepliesChild); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | bool |
michael@0 | 79 | TestRacyInterruptRepliesChild::AnswerR_(int* replyNum) |
michael@0 | 80 | { |
michael@0 | 81 | *replyNum = ++mReplyNum; |
michael@0 | 82 | |
michael@0 | 83 | if (1 == *replyNum) |
michael@0 | 84 | SendA_(); |
michael@0 | 85 | |
michael@0 | 86 | return true; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | bool |
michael@0 | 90 | TestRacyInterruptRepliesChild::RecvChildTest() |
michael@0 | 91 | { |
michael@0 | 92 | int replyNum = -1; |
michael@0 | 93 | if (!Call_R(&replyNum)) |
michael@0 | 94 | fail("calling R()"); |
michael@0 | 95 | |
michael@0 | 96 | if (1 != replyNum) |
michael@0 | 97 | fail("this should have been the first reply to R()"); |
michael@0 | 98 | |
michael@0 | 99 | Close(); |
michael@0 | 100 | |
michael@0 | 101 | return true; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | bool |
michael@0 | 105 | TestRacyInterruptRepliesChild::Recv_A() |
michael@0 | 106 | { |
michael@0 | 107 | int replyNum = -1; |
michael@0 | 108 | |
michael@0 | 109 | if (!Call_R(&replyNum)) |
michael@0 | 110 | fail("calling _R()"); |
michael@0 | 111 | |
michael@0 | 112 | if (2 != replyNum) |
michael@0 | 113 | fail("this should have been the second reply to R()"); |
michael@0 | 114 | |
michael@0 | 115 | return true; |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | } // namespace _ipdltest |
michael@0 | 119 | } // namespace mozilla |