|
1 #include "TestLatency.h" |
|
2 |
|
3 #include "IPDLUnitTests.h" // fail etc. |
|
4 |
|
5 // A ping/pong trial takes O(100us) or more, so if we don't have 10us |
|
6 // resolution or better, the results will not be terribly useful |
|
7 static const double kTimingResolutionCutoff = 0.00001; // 10us |
|
8 |
|
9 namespace mozilla { |
|
10 namespace _ipdltest { |
|
11 |
|
12 //----------------------------------------------------------------------------- |
|
13 // parent |
|
14 |
|
15 TestLatencyParent::TestLatencyParent() : |
|
16 mStart(), |
|
17 mPPTimeTotal(), |
|
18 mPP5TimeTotal(), |
|
19 mRpcTimeTotal(), |
|
20 mPPTrialsToGo(NR_TRIALS), |
|
21 mPP5TrialsToGo(NR_TRIALS), |
|
22 mNumChildProcessedCompressedSpams(0) |
|
23 { |
|
24 MOZ_COUNT_CTOR(TestLatencyParent); |
|
25 } |
|
26 |
|
27 TestLatencyParent::~TestLatencyParent() |
|
28 { |
|
29 MOZ_COUNT_DTOR(TestLatencyParent); |
|
30 } |
|
31 |
|
32 void |
|
33 TestLatencyParent::Main() |
|
34 { |
|
35 TimeDuration resolution = TimeDuration::Resolution(); |
|
36 if (resolution.ToSeconds() > kTimingResolutionCutoff) { |
|
37 puts(" (skipping TestLatency, timing resolution is too poor)"); |
|
38 Close(); |
|
39 return; |
|
40 } |
|
41 |
|
42 printf(" timing resolution: %g seconds\n", |
|
43 resolution.ToSecondsSigDigits()); |
|
44 |
|
45 if (mozilla::ipc::LoggingEnabled()) |
|
46 NS_RUNTIMEABORT("you really don't want to log all IPC messages during this test, trust me"); |
|
47 |
|
48 PingPongTrial(); |
|
49 } |
|
50 |
|
51 void |
|
52 TestLatencyParent::PingPongTrial() |
|
53 { |
|
54 mStart = TimeStamp::Now(); |
|
55 if (!SendPing()) |
|
56 fail("sending Ping()"); |
|
57 } |
|
58 |
|
59 void |
|
60 TestLatencyParent::Ping5Pong5Trial() |
|
61 { |
|
62 mStart = TimeStamp::Now(); |
|
63 |
|
64 if (!SendPing5() || |
|
65 !SendPing5() || |
|
66 !SendPing5() || |
|
67 !SendPing5() || |
|
68 !SendPing5()) |
|
69 fail("sending Ping5()"); |
|
70 } |
|
71 |
|
72 bool |
|
73 TestLatencyParent::RecvPong() |
|
74 { |
|
75 TimeDuration thisTrial = (TimeStamp::Now() - mStart); |
|
76 mPPTimeTotal += thisTrial; |
|
77 |
|
78 if (0 == (mPPTrialsToGo % 1000)) |
|
79 printf(" PP trial %d: %g\n", |
|
80 mPPTrialsToGo, thisTrial.ToSecondsSigDigits()); |
|
81 |
|
82 if (--mPPTrialsToGo > 0) |
|
83 PingPongTrial(); |
|
84 else |
|
85 Ping5Pong5Trial(); |
|
86 return true; |
|
87 } |
|
88 |
|
89 bool |
|
90 TestLatencyParent::RecvPong5() |
|
91 { |
|
92 if (PTestLatency::PING5 != state()) |
|
93 return true; |
|
94 |
|
95 TimeDuration thisTrial = (TimeStamp::Now() - mStart); |
|
96 mPP5TimeTotal += thisTrial; |
|
97 |
|
98 if (0 == (mPP5TrialsToGo % 1000)) |
|
99 printf(" PP5 trial %d: %g\n", |
|
100 mPP5TrialsToGo, thisTrial.ToSecondsSigDigits()); |
|
101 |
|
102 if (0 < --mPP5TrialsToGo) |
|
103 Ping5Pong5Trial(); |
|
104 else |
|
105 RpcTrials(); |
|
106 |
|
107 return true; |
|
108 } |
|
109 |
|
110 void |
|
111 TestLatencyParent::RpcTrials() |
|
112 { |
|
113 TimeStamp start = TimeStamp::Now(); |
|
114 for (int i = 0; i < NR_TRIALS; ++i) { |
|
115 if (!CallRpc()) |
|
116 fail("can't call Rpc()"); |
|
117 if (0 == (i % 1000)) |
|
118 printf(" Rpc trial %d\n", i); |
|
119 } |
|
120 mRpcTimeTotal = (TimeStamp::Now() - start); |
|
121 |
|
122 SpamTrial(); |
|
123 } |
|
124 |
|
125 void |
|
126 TestLatencyParent::SpamTrial() |
|
127 { |
|
128 TimeStamp start = TimeStamp::Now(); |
|
129 for (int i = 0; i < NR_SPAMS - 1; ++i) { |
|
130 if (!SendSpam()) |
|
131 fail("sending Spam()"); |
|
132 if (0 == (i % 10000)) |
|
133 printf(" Spam trial %d\n", i); |
|
134 } |
|
135 |
|
136 // Synchronize with the child process to ensure all messages have |
|
137 // been processed. This adds the overhead of a reply message from |
|
138 // child-->here, but should be insignificant compared to >> |
|
139 // NR_SPAMS. |
|
140 if (!CallSynchro()) |
|
141 fail("calling Synchro()"); |
|
142 |
|
143 mSpamTimeTotal = (TimeStamp::Now() - start); |
|
144 |
|
145 CompressedSpamTrial(); |
|
146 } |
|
147 |
|
148 void |
|
149 TestLatencyParent::CompressedSpamTrial() |
|
150 { |
|
151 for (int i = 0; i < NR_SPAMS; ++i) { |
|
152 if (!SendCompressedSpam(i + 1)) |
|
153 fail("sending CompressedSpam()"); |
|
154 if (0 == (i % 10000)) |
|
155 printf(" CompressedSpam trial %d\n", i); |
|
156 } |
|
157 |
|
158 uint32_t lastSeqno; |
|
159 if (!CallSynchro2(&lastSeqno, &mNumChildProcessedCompressedSpams)) |
|
160 fail("calling Synchro2()"); |
|
161 |
|
162 if (lastSeqno != NR_SPAMS) |
|
163 fail("last seqno was %u, expected %u", lastSeqno, NR_SPAMS); |
|
164 |
|
165 // NB: since this is testing an optimization, it's somewhat bogus. |
|
166 // Need to make a warning if it actually intermittently fails in |
|
167 // practice, which is doubtful. |
|
168 if (!(mNumChildProcessedCompressedSpams < NR_SPAMS)) |
|
169 fail("Didn't compress any messages?"); |
|
170 |
|
171 Exit(); |
|
172 } |
|
173 |
|
174 void |
|
175 TestLatencyParent::Exit() |
|
176 { |
|
177 Close(); |
|
178 } |
|
179 |
|
180 //----------------------------------------------------------------------------- |
|
181 // child |
|
182 |
|
183 TestLatencyChild::TestLatencyChild() |
|
184 : mLastSeqno(0) |
|
185 , mNumProcessedCompressedSpams(0) |
|
186 { |
|
187 MOZ_COUNT_CTOR(TestLatencyChild); |
|
188 } |
|
189 |
|
190 TestLatencyChild::~TestLatencyChild() |
|
191 { |
|
192 MOZ_COUNT_DTOR(TestLatencyChild); |
|
193 } |
|
194 |
|
195 bool |
|
196 TestLatencyChild::RecvPing() |
|
197 { |
|
198 SendPong(); |
|
199 return true; |
|
200 } |
|
201 |
|
202 bool |
|
203 TestLatencyChild::RecvPing5() |
|
204 { |
|
205 if (PTestLatency::PONG1 != state()) |
|
206 return true; |
|
207 |
|
208 if (!SendPong5() || |
|
209 !SendPong5() || |
|
210 !SendPong5() || |
|
211 !SendPong5() || |
|
212 !SendPong5()) |
|
213 fail("sending Pong5()"); |
|
214 |
|
215 return true; |
|
216 } |
|
217 |
|
218 bool |
|
219 TestLatencyChild::AnswerRpc() |
|
220 { |
|
221 return true; |
|
222 } |
|
223 |
|
224 bool |
|
225 TestLatencyChild::RecvSpam() |
|
226 { |
|
227 // no-op |
|
228 return true; |
|
229 } |
|
230 |
|
231 bool |
|
232 TestLatencyChild::AnswerSynchro() |
|
233 { |
|
234 return true; |
|
235 } |
|
236 |
|
237 bool |
|
238 TestLatencyChild::RecvCompressedSpam(const uint32_t& seqno) |
|
239 { |
|
240 if (seqno <= mLastSeqno) |
|
241 fail("compressed seqnos must monotonically increase"); |
|
242 |
|
243 mLastSeqno = seqno; |
|
244 ++mNumProcessedCompressedSpams; |
|
245 return true; |
|
246 } |
|
247 |
|
248 bool |
|
249 TestLatencyChild::AnswerSynchro2(uint32_t* lastSeqno, |
|
250 uint32_t* numMessagesDispatched) |
|
251 { |
|
252 *lastSeqno = mLastSeqno; |
|
253 *numMessagesDispatched = mNumProcessedCompressedSpams; |
|
254 return true; |
|
255 } |
|
256 |
|
257 } // namespace _ipdltest |
|
258 } // namespace mozilla |