|
1 #include "TestRPC.h" |
|
2 |
|
3 #include "IPDLUnitTests.h" // fail etc. |
|
4 #if defined(OS_POSIX) |
|
5 #include <unistd.h> |
|
6 #else |
|
7 #include <windows.h> |
|
8 #endif |
|
9 |
|
10 namespace mozilla { |
|
11 namespace _ipdltest { |
|
12 |
|
13 //----------------------------------------------------------------------------- |
|
14 // parent |
|
15 |
|
16 TestRPCParent::TestRPCParent() |
|
17 : reentered_(false), |
|
18 resolved_first_cpow_(false) |
|
19 { |
|
20 MOZ_COUNT_CTOR(TestRPCParent); |
|
21 } |
|
22 |
|
23 TestRPCParent::~TestRPCParent() |
|
24 { |
|
25 MOZ_COUNT_DTOR(TestRPCParent); |
|
26 } |
|
27 |
|
28 void |
|
29 TestRPCParent::Main() |
|
30 { |
|
31 if (!SendStart()) |
|
32 fail("sending Start"); |
|
33 } |
|
34 |
|
35 bool |
|
36 TestRPCParent::AnswerTest1_Start(uint32_t* aResult) |
|
37 { |
|
38 uint32_t result; |
|
39 if (!CallTest1_InnerQuery(&result)) |
|
40 fail("CallTest1_InnerQuery"); |
|
41 if (result != 300) |
|
42 fail("Wrong result (expected 300)"); |
|
43 |
|
44 *aResult = 100; |
|
45 return true; |
|
46 } |
|
47 |
|
48 bool |
|
49 TestRPCParent::AnswerTest1_InnerEvent(uint32_t* aResult) |
|
50 { |
|
51 uint32_t result; |
|
52 if (!CallTest1_NoReenter(&result)) |
|
53 fail("CallTest1_NoReenter"); |
|
54 if (result != 400) |
|
55 fail("Wrong result (expected 400)"); |
|
56 |
|
57 *aResult = 200; |
|
58 return true; |
|
59 } |
|
60 |
|
61 bool |
|
62 TestRPCParent::RecvTest2_Start() |
|
63 { |
|
64 // Send a CPOW. During this time, we must NOT process the RPC message, as |
|
65 // we could start receiving CPOW replies out-of-order. |
|
66 if (!CallTest2_FirstUrgent()) |
|
67 fail("CallTest2_FirstUrgent"); |
|
68 |
|
69 MOZ_ASSERT(!reentered_); |
|
70 resolved_first_cpow_ = true; |
|
71 return true; |
|
72 } |
|
73 |
|
74 bool |
|
75 TestRPCParent::AnswerTest2_OutOfOrder() |
|
76 { |
|
77 // Send a CPOW. If this RPC call was initiated while waiting for the first |
|
78 // CPOW to resolve, replies will be processed out of order, and we'll crash. |
|
79 if (!CallTest2_SecondUrgent()) |
|
80 fail("CallTest2_SecondUrgent"); |
|
81 |
|
82 reentered_ = true; |
|
83 return true; |
|
84 } |
|
85 |
|
86 bool |
|
87 TestRPCParent::RecvTest3_Start(uint32_t* aResult) |
|
88 { |
|
89 if (!CallTest3_WakeUp(aResult)) |
|
90 fail("CallTest3_WakeUp"); |
|
91 |
|
92 return true; |
|
93 } |
|
94 |
|
95 bool |
|
96 TestRPCParent::AnswerTest3_InnerEvent(uint32_t* aResult) |
|
97 { |
|
98 *aResult = 200; |
|
99 return true; |
|
100 } |
|
101 |
|
102 bool |
|
103 TestRPCParent::AnswerTest4_Start(uint32_t* aResult) |
|
104 { |
|
105 if (!CallTest4_WakeUp(aResult)) |
|
106 fail("CallTest4_WakeUp"); |
|
107 |
|
108 return true; |
|
109 } |
|
110 |
|
111 bool |
|
112 TestRPCParent::AnswerTest4_Inner(uint32_t* aResult) |
|
113 { |
|
114 *aResult = 700; |
|
115 return true; |
|
116 } |
|
117 |
|
118 //----------------------------------------------------------------------------- |
|
119 // child |
|
120 |
|
121 |
|
122 TestRPCChild::TestRPCChild() |
|
123 { |
|
124 MOZ_COUNT_CTOR(TestRPCChild); |
|
125 } |
|
126 |
|
127 TestRPCChild::~TestRPCChild() |
|
128 { |
|
129 MOZ_COUNT_DTOR(TestRPCChild); |
|
130 } |
|
131 |
|
132 bool |
|
133 TestRPCChild::RecvStart() |
|
134 { |
|
135 uint32_t result; |
|
136 if (!CallTest1_Start(&result)) |
|
137 fail("CallTest1_Start"); |
|
138 if (result != 100) |
|
139 fail("Wrong result (expected 100)"); |
|
140 |
|
141 if (!SendTest2_Start()) |
|
142 fail("SendTest2_Start"); |
|
143 |
|
144 if (!CallTest2_OutOfOrder()) |
|
145 fail("CallTest2_OutOfOrder"); |
|
146 |
|
147 result = 0; |
|
148 if (!SendTest3_Start(&result)) |
|
149 fail("SendTest3_Start"); |
|
150 if (result != 200) |
|
151 fail("Wrong result (expected 200)"); |
|
152 |
|
153 // See bug 937216 (RPC calls within interrupts). |
|
154 if (!CallTest4_Start(&result)) |
|
155 fail("SendTest4_Start"); |
|
156 if (result != 700) |
|
157 fail("Wrong result (expected 700)"); |
|
158 |
|
159 Close(); |
|
160 return true; |
|
161 } |
|
162 |
|
163 bool |
|
164 TestRPCChild::AnswerTest1_InnerQuery(uint32_t* aResult) |
|
165 { |
|
166 uint32_t result; |
|
167 if (!CallTest1_InnerEvent(&result)) |
|
168 fail("CallTest1_InnerEvent"); |
|
169 if (result != 200) |
|
170 fail("Wrong result (expected 200)"); |
|
171 |
|
172 *aResult = 300; |
|
173 return true; |
|
174 } |
|
175 |
|
176 bool |
|
177 TestRPCChild::AnswerTest1_NoReenter(uint32_t* aResult) |
|
178 { |
|
179 *aResult = 400; |
|
180 return true; |
|
181 } |
|
182 |
|
183 bool |
|
184 TestRPCChild::AnswerTest2_FirstUrgent() |
|
185 { |
|
186 return true; |
|
187 } |
|
188 |
|
189 bool |
|
190 TestRPCChild::AnswerTest2_SecondUrgent() |
|
191 { |
|
192 return true; |
|
193 } |
|
194 |
|
195 bool |
|
196 TestRPCChild::AnswerTest3_WakeUp(uint32_t* aResult) |
|
197 { |
|
198 if (!CallTest3_InnerEvent(aResult)) |
|
199 fail("CallTest3_InnerEvent"); |
|
200 |
|
201 return true; |
|
202 } |
|
203 |
|
204 bool |
|
205 TestRPCChild::AnswerTest4_WakeUp(uint32_t* aResult) |
|
206 { |
|
207 if (!CallTest4_Inner(aResult)) |
|
208 fail("CallTest4_Inner"); |
|
209 |
|
210 return true; |
|
211 } |
|
212 |
|
213 } // namespace _ipdltest |
|
214 } // namespace mozilla |