No bug: Test RPC round-trip times and warn before sleep()ing. no r=, test only

This commit is contained in:
Chris Jones 2010-02-04 21:40:42 -06:00
parent 0486f6f11e
commit 44e3e67b08
4 changed files with 51 additions and 8 deletions

View File

@ -3,12 +3,13 @@ namespace mozilla {
namespace _ipdltest {
protocol PTestLatency {
rpc protocol PTestLatency {
child:
__delete__();
Ping();
Ping5();
rpc Rpc();
parent:
Pong();
@ -31,7 +32,7 @@ state PONG:
// Trial 2: "overlapped" ping/pong latency
state PING5:
send Ping5 goto PING4;
send __delete__;
call Rpc goto RPC;
state PING4: send Ping5 goto PING3;
state PING3: send Ping5 goto PING2;
@ -43,6 +44,10 @@ state PONG2: recv Pong5 goto PONG3;
state PONG3: recv Pong5 goto PONG4;
state PONG4: recv Pong5 goto PONG5;
state PONG5: recv Pong5 goto PING5;
state RPC:
call Rpc goto RPC;
send __delete__;
};

View File

@ -16,6 +16,7 @@ TestLatencyParent::TestLatencyParent() :
mStart(),
mPPTimeTotal(),
mPP5TimeTotal(),
mRpcTimeTotal(),
mPPTrialsToGo(NR_TRIALS),
mPP5TrialsToGo(NR_TRIALS),
mPongsToGo(0)
@ -31,12 +32,16 @@ TestLatencyParent::~TestLatencyParent()
void
TestLatencyParent::Main()
{
if (TimeDuration::Resolution().ToSeconds() > kTimingResolutionCutoff) {
TimeDuration resolution = TimeDuration::Resolution();
if (resolution.ToSeconds() > kTimingResolutionCutoff) {
puts(" (skipping TestLatency, timing resolution is too poor)");
Close();
return;
}
printf(" timing resolution: %g seconds\n",
resolution.ToSecondsSigDigits());
if (mozilla::ipc::LoggingEnabled())
NS_RUNTIMEABORT("you really don't want to log all IPC messages during this test, trust me");
@ -78,7 +83,7 @@ TestLatencyParent::RecvPong()
TimeDuration thisTrial = (TimeStamp::Now() - mStart);
mPPTimeTotal += thisTrial;
if (0 == ((mPPTrialsToGo % 1000)))
if (0 == (mPPTrialsToGo % 1000))
printf(" PP trial %d: %g\n",
mPPTrialsToGo, thisTrial.ToSecondsSigDigits());
@ -99,18 +104,37 @@ TestLatencyParent::RecvPong5()
TimeDuration thisTrial = (TimeStamp::Now() - mStart);
mPP5TimeTotal += thisTrial;
if (0 == ((mPP5TrialsToGo % 1000)))
if (0 == (mPP5TrialsToGo % 1000))
printf(" PP5 trial %d: %g\n",
mPP5TrialsToGo, thisTrial.ToSecondsSigDigits());
if (0 < --mPP5TrialsToGo)
Ping5Pong5Trial();
else
Exit();
RpcTrials();
return true;
}
void
TestLatencyParent::RpcTrials()
{
for (int i = 0; i < NR_TRIALS; ++i) {
TimeStamp start = TimeStamp::Now();
if (!CallRpc())
fail("can't call Rpc()");
TimeDuration thisTrial = (TimeStamp::Now() - start);
if (0 == (i % 1000))
printf(" Rpc trial %d: %g\n", i, thisTrial.ToSecondsSigDigits());
mRpcTimeTotal += thisTrial;
}
Exit();
}
//-----------------------------------------------------------------------------
// child
@ -139,6 +163,11 @@ TestLatencyChild::RecvPing5()
return true;
}
bool
TestLatencyChild::AnswerRpc()
{
return true;
}
} // namespace _ipdltest
} // namespace mozilla

View File

@ -38,9 +38,12 @@ protected:
if (NormalShutdown != why)
fail("unexpected destruction!");
passed("average ping/pong latency: %g sec, average ping5/pong5 latency: %g sec",
passed("average ping/pong latency: %g sec, "
"average ping5/pong5 latency: %g sec, "
"average RPC call/answer: %g sec",
mPPTimeTotal.ToSecondsSigDigits() / (double) NR_TRIALS,
mPP5TimeTotal.ToSecondsSigDigits() / (double) NR_TRIALS);
mPP5TimeTotal.ToSecondsSigDigits() / (double) NR_TRIALS,
mRpcTimeTotal.ToSecondsSigDigits() / (double) NR_TRIALS);
QuitParent();
}
@ -48,11 +51,13 @@ protected:
private:
void PingPongTrial();
void Ping5Pong5Trial();
void RpcTrials();
void Exit();
TimeStamp mStart;
TimeDuration mPPTimeTotal;
TimeDuration mPP5TimeTotal;
TimeDuration mRpcTimeTotal;
int mPPTrialsToGo;
int mPP5TrialsToGo;
@ -74,6 +79,8 @@ protected:
virtual bool RecvPing();
NS_OVERRIDE
virtual bool RecvPing5();
NS_OVERRIDE
virtual bool AnswerRpc();
NS_OVERRIDE
virtual void ActorDestroy(ActorDestroyReason why)

View File

@ -50,6 +50,7 @@ TestSyncWakeupParent::RecvSync1()
// NB: can't use PR_Sleep (i.e. Sleep() on windows) because it's
// only spec'd to block the current thread, not the current
// process. We need the IO thread to sleep as well.
puts(" (sleeping for 5 seconds. sorry!)");
sleep(5);
#endif
@ -65,6 +66,7 @@ TestSyncWakeupParent::RecvSync2()
#if defined(OS_POSIX)
// see above
sleep(5);
puts(" (sleeping for 5 seconds. sorry!)");
#endif
return true;