|
1 #include "TestInterruptRaces.h" |
|
2 |
|
3 #include "IPDLUnitTests.h" // fail etc. |
|
4 |
|
5 using mozilla::ipc::MessageChannel; |
|
6 |
|
7 template<> |
|
8 struct RunnableMethodTraits<mozilla::_ipdltest::TestInterruptRacesParent> |
|
9 { |
|
10 static void RetainCallee(mozilla::_ipdltest::TestInterruptRacesParent* obj) { } |
|
11 static void ReleaseCallee(mozilla::_ipdltest::TestInterruptRacesParent* obj) { } |
|
12 }; |
|
13 |
|
14 |
|
15 namespace mozilla { |
|
16 namespace _ipdltest { |
|
17 |
|
18 ipc::RacyInterruptPolicy |
|
19 MediateRace(const MessageChannel::Message& parent, |
|
20 const MessageChannel::Message& child) |
|
21 { |
|
22 return (PTestInterruptRaces::Msg_Child__ID == parent.type()) ? |
|
23 ipc::RIPParentWins : ipc::RIPChildWins; |
|
24 } |
|
25 |
|
26 //----------------------------------------------------------------------------- |
|
27 // parent |
|
28 void |
|
29 TestInterruptRacesParent::Main() |
|
30 { |
|
31 if (!SendStart()) |
|
32 fail("sending Start()"); |
|
33 } |
|
34 |
|
35 bool |
|
36 TestInterruptRacesParent::RecvStartRace() |
|
37 { |
|
38 MessageLoop::current()->PostTask( |
|
39 FROM_HERE, |
|
40 NewRunnableMethod(this, &TestInterruptRacesParent::OnRaceTime)); |
|
41 return true; |
|
42 } |
|
43 |
|
44 void |
|
45 TestInterruptRacesParent::OnRaceTime() |
|
46 { |
|
47 if (!CallRace(&mChildHasReply)) |
|
48 fail("problem calling Race()"); |
|
49 |
|
50 if (!mChildHasReply) |
|
51 fail("child should have got a reply already"); |
|
52 |
|
53 mHasReply = true; |
|
54 |
|
55 MessageLoop::current()->PostTask( |
|
56 FROM_HERE, |
|
57 NewRunnableMethod(this, &TestInterruptRacesParent::Test2)); |
|
58 } |
|
59 |
|
60 bool |
|
61 TestInterruptRacesParent::AnswerRace(bool* hasReply) |
|
62 { |
|
63 if (mHasReply) |
|
64 fail("apparently the parent won the Interrupt race!"); |
|
65 *hasReply = hasReply; |
|
66 return true; |
|
67 } |
|
68 |
|
69 void |
|
70 TestInterruptRacesParent::Test2() |
|
71 { |
|
72 puts(" passed"); |
|
73 puts("Test 2"); |
|
74 |
|
75 mHasReply = false; |
|
76 mChildHasReply = false; |
|
77 |
|
78 if (!CallStackFrame()) |
|
79 fail("can't set up a stack frame"); |
|
80 |
|
81 puts(" passed"); |
|
82 |
|
83 MessageLoop::current()->PostTask( |
|
84 FROM_HERE, |
|
85 NewRunnableMethod(this, &TestInterruptRacesParent::Test3)); |
|
86 } |
|
87 |
|
88 bool |
|
89 TestInterruptRacesParent::AnswerStackFrame() |
|
90 { |
|
91 if (!SendWakeup()) |
|
92 fail("can't wake up the child"); |
|
93 |
|
94 if (!CallRace(&mChildHasReply)) |
|
95 fail("can't set up race condition"); |
|
96 mHasReply = true; |
|
97 |
|
98 if (!mChildHasReply) |
|
99 fail("child should have got a reply already"); |
|
100 |
|
101 return true; |
|
102 } |
|
103 |
|
104 void |
|
105 TestInterruptRacesParent::Test3() |
|
106 { |
|
107 puts("Test 3"); |
|
108 |
|
109 if (!CallStackFrame3()) |
|
110 fail("can't set up a stack frame"); |
|
111 |
|
112 puts(" passed"); |
|
113 |
|
114 Close(); |
|
115 } |
|
116 |
|
117 bool |
|
118 TestInterruptRacesParent::AnswerStackFrame3() |
|
119 { |
|
120 if (!SendWakeup3()) |
|
121 fail("can't wake up the child"); |
|
122 |
|
123 if (!CallChild()) |
|
124 fail("can't set up race condition"); |
|
125 |
|
126 return true; |
|
127 } |
|
128 |
|
129 bool |
|
130 TestInterruptRacesParent::AnswerParent() |
|
131 { |
|
132 mAnsweredParent = true; |
|
133 return true; |
|
134 } |
|
135 |
|
136 bool |
|
137 TestInterruptRacesParent::RecvGetAnsweredParent(bool* answeredParent) |
|
138 { |
|
139 *answeredParent = mAnsweredParent; |
|
140 return true; |
|
141 } |
|
142 |
|
143 //----------------------------------------------------------------------------- |
|
144 // child |
|
145 bool |
|
146 TestInterruptRacesChild::RecvStart() |
|
147 { |
|
148 puts("Test 1"); |
|
149 |
|
150 if (!SendStartRace()) |
|
151 fail("problem sending StartRace()"); |
|
152 |
|
153 bool dontcare; |
|
154 if (!CallRace(&dontcare)) |
|
155 fail("problem calling Race()"); |
|
156 |
|
157 mHasReply = true; |
|
158 return true; |
|
159 } |
|
160 |
|
161 bool |
|
162 TestInterruptRacesChild::AnswerRace(bool* hasReply) |
|
163 { |
|
164 if (!mHasReply) |
|
165 fail("apparently the child lost the Interrupt race!"); |
|
166 |
|
167 *hasReply = mHasReply; |
|
168 |
|
169 return true; |
|
170 } |
|
171 |
|
172 bool |
|
173 TestInterruptRacesChild::AnswerStackFrame() |
|
174 { |
|
175 // reset for the second test |
|
176 mHasReply = false; |
|
177 |
|
178 if (!CallStackFrame()) |
|
179 fail("can't set up stack frame"); |
|
180 |
|
181 if (!mHasReply) |
|
182 fail("should have had reply by now"); |
|
183 |
|
184 return true; |
|
185 } |
|
186 |
|
187 bool |
|
188 TestInterruptRacesChild::RecvWakeup() |
|
189 { |
|
190 bool dontcare; |
|
191 if (!CallRace(&dontcare)) |
|
192 fail("can't set up race condition"); |
|
193 |
|
194 mHasReply = true; |
|
195 return true; |
|
196 } |
|
197 |
|
198 bool |
|
199 TestInterruptRacesChild::AnswerStackFrame3() |
|
200 { |
|
201 if (!CallStackFrame3()) |
|
202 fail("can't set up stack frame"); |
|
203 return true; |
|
204 } |
|
205 |
|
206 bool |
|
207 TestInterruptRacesChild::RecvWakeup3() |
|
208 { |
|
209 if (!CallParent()) |
|
210 fail("can't set up race condition"); |
|
211 return true; |
|
212 } |
|
213 |
|
214 bool |
|
215 TestInterruptRacesChild::AnswerChild() |
|
216 { |
|
217 bool parentAnsweredParent; |
|
218 // the parent is supposed to win the race, which means its |
|
219 // message, Child(), is supposed to be processed before the |
|
220 // child's message, Parent() |
|
221 if (!SendGetAnsweredParent(&parentAnsweredParent)) |
|
222 fail("sending GetAnsweredParent"); |
|
223 |
|
224 if (parentAnsweredParent) |
|
225 fail("parent was supposed to win the race!"); |
|
226 |
|
227 return true; |
|
228 } |
|
229 |
|
230 } // namespace _ipdltest |
|
231 } // namespace mozilla |