ipc/ipdl/test/cxx/TestRacyInterruptReplies.cpp

branch
TOR_BUG_3246
changeset 6
8bccb770b82d
equal deleted inserted replaced
-1:000000000000 0:f9385e12a1b2
1 #include "TestRacyInterruptReplies.h"
2
3 #include "IPDLUnitTests.h" // fail etc.
4
5 namespace mozilla {
6 namespace _ipdltest {
7
8 //-----------------------------------------------------------------------------
9 // parent
10
11 TestRacyInterruptRepliesParent::TestRacyInterruptRepliesParent() : mReplyNum(0)
12 {
13 MOZ_COUNT_CTOR(TestRacyInterruptRepliesParent);
14 }
15
16 TestRacyInterruptRepliesParent::~TestRacyInterruptRepliesParent()
17 {
18 MOZ_COUNT_DTOR(TestRacyInterruptRepliesParent);
19 }
20
21 void
22 TestRacyInterruptRepliesParent::Main()
23 {
24 int replyNum = -1;
25 if (!CallR_(&replyNum))
26 fail("calling R()");
27
28 if (1 != replyNum)
29 fail("this should have been the first reply to R()");
30
31 if (!SendChildTest())
32 fail("sending ChildStart");
33 }
34
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()");
46
47 if (2 != replyNum)
48 fail("this should have been the second reply to R()");
49
50 return true;
51 }
52
53 bool
54 TestRacyInterruptRepliesParent::Answer_R(int* replyNum)
55 {
56 *replyNum = ++mReplyNum;
57
58 if (1 == *replyNum)
59 if (!Send_A())
60 fail("sending _A()");
61
62 return true;
63 }
64
65 //-----------------------------------------------------------------------------
66 // child
67
68 TestRacyInterruptRepliesChild::TestRacyInterruptRepliesChild() : mReplyNum(0)
69 {
70 MOZ_COUNT_CTOR(TestRacyInterruptRepliesChild);
71 }
72
73 TestRacyInterruptRepliesChild::~TestRacyInterruptRepliesChild()
74 {
75 MOZ_COUNT_DTOR(TestRacyInterruptRepliesChild);
76 }
77
78 bool
79 TestRacyInterruptRepliesChild::AnswerR_(int* replyNum)
80 {
81 *replyNum = ++mReplyNum;
82
83 if (1 == *replyNum)
84 SendA_();
85
86 return true;
87 }
88
89 bool
90 TestRacyInterruptRepliesChild::RecvChildTest()
91 {
92 int replyNum = -1;
93 if (!Call_R(&replyNum))
94 fail("calling R()");
95
96 if (1 != replyNum)
97 fail("this should have been the first reply to R()");
98
99 Close();
100
101 return true;
102 }
103
104 bool
105 TestRacyInterruptRepliesChild::Recv_A()
106 {
107 int replyNum = -1;
108
109 if (!Call_R(&replyNum))
110 fail("calling _R()");
111
112 if (2 != replyNum)
113 fail("this should have been the second reply to R()");
114
115 return true;
116 }
117
118 } // namespace _ipdltest
119 } // namespace mozilla

mercurial