From 45b95bf64a8dd633d5bdbde262cbe863368ce4bb Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 4 Feb 2010 21:40:42 -0600 Subject: [PATCH] No bug: Test RPC round-trip times and warn before sleep()ing. no r=, test only --- ipc/ipdl/test/cxx/PTestLatency.ipdl | 9 +++++-- ipc/ipdl/test/cxx/TestLatency.cpp | 37 +++++++++++++++++++++++++--- ipc/ipdl/test/cxx/TestLatency.h | 11 +++++++-- ipc/ipdl/test/cxx/TestSyncWakeup.cpp | 2 ++ 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/ipc/ipdl/test/cxx/PTestLatency.ipdl b/ipc/ipdl/test/cxx/PTestLatency.ipdl index 65cc4c4e2324..644951a4b24e 100644 --- a/ipc/ipdl/test/cxx/PTestLatency.ipdl +++ b/ipc/ipdl/test/cxx/PTestLatency.ipdl @@ -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__; }; diff --git a/ipc/ipdl/test/cxx/TestLatency.cpp b/ipc/ipdl/test/cxx/TestLatency.cpp index 6d7a5c25b427..e93b69ad12da 100644 --- a/ipc/ipdl/test/cxx/TestLatency.cpp +++ b/ipc/ipdl/test/cxx/TestLatency.cpp @@ -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"); @@ -76,7 +81,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()); @@ -97,18 +102,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 @@ -137,6 +161,11 @@ TestLatencyChild::RecvPing5() return true; } +bool +TestLatencyChild::AnswerRpc() +{ + return true; +} } // namespace _ipdltest } // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestLatency.h b/ipc/ipdl/test/cxx/TestLatency.h index 9cbc52c895a7..85727338b856 100644 --- a/ipc/ipdl/test/cxx/TestLatency.h +++ b/ipc/ipdl/test/cxx/TestLatency.h @@ -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) diff --git a/ipc/ipdl/test/cxx/TestSyncWakeup.cpp b/ipc/ipdl/test/cxx/TestSyncWakeup.cpp index 977342cfd84e..cce0ca34fae9 100644 --- a/ipc/ipdl/test/cxx/TestSyncWakeup.cpp +++ b/ipc/ipdl/test/cxx/TestSyncWakeup.cpp @@ -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;