Bug 1320755 - Remove dependence of IPDL unit tests on state() method. r=dvander
The uses of state() in TestHangs and TestStackHooks only have two
states, depending on how many times the method has been called.
Two uses of state() have to be fixed in TestLatency. Each waits for 5
messages, then resets the state and sends replies.
MozReview-Commit-ID: 7Glj7wbl1ni
--- a/ipc/ipdl/test/cxx/TestHangs.cpp
+++ b/ipc/ipdl/test/cxx/TestHangs.cpp
@@ -7,17 +7,19 @@
using base::KillProcess;
namespace mozilla {
namespace _ipdltest {
//-----------------------------------------------------------------------------
// parent
-TestHangsParent::TestHangsParent() : mDetectedHang(false)
+TestHangsParent::TestHangsParent()
+ : mDetectedHang(false)
+ , mNumAnswerStackFrame(0)
{
MOZ_COUNT_CTOR(TestHangsParent);
}
TestHangsParent::~TestHangsParent()
{
MOZ_COUNT_DTOR(TestHangsParent);
}
@@ -42,17 +44,17 @@ TestHangsParent::Main()
// this tells the subprocess to send us Nonce()
if (!SendStart())
fail("sending Start");
// now we sleep here for a while awaiting the Nonce() message from
// the child. since we're not blocked on anything, the IO thread
// will enqueue an OnMaybeDequeueOne() task to process that
// message
- //
+ //
// NB: PR_Sleep is exactly what we want, only the current thread
// sleeping
PR_Sleep(5000);
// when we call into this, we'll pull the Nonce() message out of
// the mPending queue, but that doesn't matter ... the
// OnMaybeDequeueOne() event will remain
if (CallStackFrame() && mDetectedHang)
@@ -80,27 +82,34 @@ TestHangsParent::ShouldContinueFromReply
GetIPCChannel()->CloseWithTimeout();
return false;
}
mozilla::ipc::IPCResult
TestHangsParent::AnswerStackFrame()
{
- if (PTestHangs::HANG != state()) {
- if (CallStackFrame())
- fail("should have timed out!");
- }
- else {
+ ++mNumAnswerStackFrame;
+
+ // XXX This assertion will get deleted as part of bug 1316757.
+ MOZ_ASSERT((PTestHangs::HANG != state()) == (mNumAnswerStackFrame == 1));
+
+ if (mNumAnswerStackFrame == 1) {
+ if (CallStackFrame()) {
+ fail("should have timed out!");
+ }
+ } else if (mNumAnswerStackFrame == 2) {
// minimum possible, 2 ms. We want to detecting a hang to race
// with the reply coming in, as reliably as possible
SetReplyTimeoutMs(2);
if (CallHang())
fail("should have timed out!");
+ } else {
+ fail("unexpected state");
}
return IPC_OK();
}
void
TestHangsParent::CleanUp()
{
--- a/ipc/ipdl/test/cxx/TestHangs.h
+++ b/ipc/ipdl/test/cxx/TestHangs.h
@@ -32,24 +32,25 @@ protected:
return IPC_OK();
}
virtual mozilla::ipc::IPCResult AnswerStackFrame() override;
virtual void ActorDestroy(ActorDestroyReason why) override
{
if (AbnormalShutdown != why)
- fail("unexpected destruction!");
+ fail("unexpected destruction!");
passed("ok");
QuitParent();
}
void CleanUp();
bool mDetectedHang;
+ int32_t mNumAnswerStackFrame;
};
class TestHangsChild :
public PTestHangsChild
{
public:
TestHangsChild();
--- a/ipc/ipdl/test/cxx/TestLatency.cpp
+++ b/ipc/ipdl/test/cxx/TestLatency.cpp
@@ -14,17 +14,18 @@ namespace _ipdltest {
TestLatencyParent::TestLatencyParent() :
mStart(),
mPPTimeTotal(),
mPP5TimeTotal(),
mRpcTimeTotal(),
mPPTrialsToGo(NR_TRIALS),
mPP5TrialsToGo(NR_TRIALS),
- mNumChildProcessedCompressedSpams(0)
+ mNumChildProcessedCompressedSpams(0),
+ mWhichPong5(0)
{
MOZ_COUNT_CTOR(TestLatencyParent);
}
TestLatencyParent::~TestLatencyParent()
{
MOZ_COUNT_DTOR(TestLatencyParent);
}
@@ -84,18 +85,26 @@ TestLatencyParent::RecvPong()
else
Ping5Pong5Trial();
return IPC_OK();
}
mozilla::ipc::IPCResult
TestLatencyParent::RecvPong5()
{
- if (PTestLatency::PING5 != state())
+ ++mWhichPong5;
+
+ // XXX This assertion will be deleted as part of bug 1316757.
+ MOZ_ASSERT((PTestLatency::PING5 != state()) == (mWhichPong5 < 5));
+
+ if (mWhichPong5 < 5) {
return IPC_OK();
+ }
+
+ mWhichPong5 = 0;
TimeDuration thisTrial = (TimeStamp::Now() - mStart);
mPP5TimeTotal += thisTrial;
if (0 == (mPP5TrialsToGo % 1000))
printf(" PP5 trial %d: %g\n",
mPP5TrialsToGo, thisTrial.ToSecondsSigDigits());
@@ -178,16 +187,17 @@ TestLatencyParent::Exit()
}
//-----------------------------------------------------------------------------
// child
TestLatencyChild::TestLatencyChild()
: mLastSeqno(0)
, mNumProcessedCompressedSpams(0)
+ , mWhichPing5(0)
{
MOZ_COUNT_CTOR(TestLatencyChild);
}
TestLatencyChild::~TestLatencyChild()
{
MOZ_COUNT_DTOR(TestLatencyChild);
}
@@ -197,18 +207,26 @@ TestLatencyChild::RecvPing()
{
SendPong();
return IPC_OK();
}
mozilla::ipc::IPCResult
TestLatencyChild::RecvPing5()
{
- if (PTestLatency::PONG1 != state())
+ ++mWhichPing5;
+
+ // XXX This assertion will be deleted as part of bug 1316757.
+ MOZ_ASSERT((PTestLatency::PONG1 != state()) == (mWhichPing5 < 5));
+
+ if (mWhichPing5 < 5) {
return IPC_OK();
+ }
+
+ mWhichPing5 = 0;
if (!SendPong5() ||
!SendPong5() ||
!SendPong5() ||
!SendPong5() ||
!SendPong5())
fail("sending Pong5()");
--- a/ipc/ipdl/test/cxx/TestLatency.h
+++ b/ipc/ipdl/test/cxx/TestLatency.h
@@ -32,17 +32,17 @@ public:
protected:
virtual mozilla::ipc::IPCResult RecvPong() override;
virtual mozilla::ipc::IPCResult RecvPong5() override;
virtual void ActorDestroy(ActorDestroyReason why) override
{
if (NormalShutdown != why)
- fail("unexpected destruction!");
+ fail("unexpected destruction!");
passed("\n"
" average #ping-pong/sec: %g\n"
" average #ping5-pong5/sec: %g\n"
" average #RPC call-answer/sec: %g\n"
" average #spams/sec: %g\n"
" pct. spams compressed away: %g\n",
double(NR_TRIALS) / mPPTimeTotal.ToSecondsSigDigits(),
@@ -67,16 +67,17 @@ private:
TimeDuration mPPTimeTotal;
TimeDuration mPP5TimeTotal;
TimeDuration mRpcTimeTotal;
TimeDuration mSpamTimeTotal;
int mPPTrialsToGo;
int mPP5TrialsToGo;
uint32_t mNumChildProcessedCompressedSpams;
+ uint32_t mWhichPong5;
};
class TestLatencyChild :
public PTestLatencyChild
{
public:
TestLatencyChild();
@@ -96,16 +97,17 @@ protected:
{
if (NormalShutdown != why)
fail("unexpected destruction!");
QuitChild();
}
uint32_t mLastSeqno;
uint32_t mNumProcessedCompressedSpams;
+ uint32_t mWhichPing5;
};
} // namespace _ipdltest
} // namespace mozilla
#endif // ifndef mozilla__ipdltest_TestLatency_h
--- a/ipc/ipdl/test/cxx/TestStackHooks.cpp
+++ b/ipc/ipdl/test/cxx/TestStackHooks.cpp
@@ -50,17 +50,18 @@ TestStackHooksParent::AnswerStackFrame()
//-----------------------------------------------------------------------------
// child
TestStackHooksChild::TestStackHooksChild() :
mOnStack(false),
mEntered(0),
mExited(0),
- mIncallDepth(0)
+ mIncallDepth(0),
+ mNumAnswerStackFrame(0)
{
MOZ_COUNT_CTOR(TestStackHooksChild);
}
TestStackHooksChild::~TestStackHooksChild()
{
MOZ_COUNT_DTOR(TestStackHooksChild);
}
@@ -85,31 +86,35 @@ TestStackHooksChild::RecvStart()
MessageLoop::current()->PostTask(NewRunnableFunction(RunTestsFn));
return IPC_OK();
}
mozilla::ipc::IPCResult
TestStackHooksChild::AnswerStackFrame()
{
+ ++mNumAnswerStackFrame;
+
if (!mOnStack)
fail("missed stack notification");
if (1 != mIncallDepth)
fail("missed EnteredCall or ExitedCall hook");
- if (PTestStackHooks::TEST4_3 == state()) {
+ if (mNumAnswerStackFrame == 1) {
+ // XXX This assertion will be deleted as part of bug 1316757.
+ MOZ_ASSERT(PTestStackHooks::TEST4_3 == state());
if (!SendAsync())
fail("sending Async()");
- }
- else if (PTestStackHooks::TEST5_3 == state()) {
+ } else if (mNumAnswerStackFrame == 2) {
+ // XXX This assertion will be deleted as part of bug 1316757.
+ MOZ_ASSERT(PTestStackHooks::TEST5_3 == state());
if (!SendSync())
fail("sending Sync()");
- }
- else {
+ } else {
fail("unexpected state");
}
if (!mOnStack)
fail("bad stack exit notification");
return IPC_OK();
}
--- a/ipc/ipdl/test/cxx/TestStackHooks.h
+++ b/ipc/ipdl/test/cxx/TestStackHooks.h
@@ -17,17 +17,17 @@ public:
TestStackHooksParent();
virtual ~TestStackHooksParent();
static bool RunTestInProcesses() { return true; }
static bool RunTestInThreads() { return true; }
void Main();
-protected:
+protected:
virtual mozilla::ipc::IPCResult RecvAsync() override {
if (!mOnStack)
fail("not on C++ stack?!");
return IPC_OK();
}
virtual mozilla::ipc::IPCResult RecvSync() override {
if (!mOnStack)
@@ -41,17 +41,17 @@ protected:
return IPC_OK();
}
virtual mozilla::ipc::IPCResult AnswerStackFrame() override;
virtual void ActorDestroy(ActorDestroyReason why) override
{
if (NormalShutdown != why)
- fail("unexpected destruction!");
+ fail("unexpected destruction!");
passed("ok");
QuitParent();
}
virtual void EnteredCxxStack() override {
mOnStack = true;
}
virtual void ExitedCxxStack() override {
@@ -115,16 +115,17 @@ protected:
--mIncallDepth;
}
private:
bool mOnStack;
int mEntered;
int mExited;
int mIncallDepth;
+ int32_t mNumAnswerStackFrame;
};
} // namespace _ipdltest
} // namespace mozilla
#endif // ifndef mozilla__ipdltest_TestStackHooks_h