ipc/ipdl/test/cxx/TestLatency.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial