This commit is contained in:
Chris Jones 2010-03-11 01:35:32 -06:00
Родитель 36162b5b9d
Коммит eb4b1d88db
3 изменённых файлов: 155 добавлений и 4 удалений

Просмотреть файл

@ -5,11 +5,18 @@ rpc protocol PTestRPCRaces {
both:
rpc Race() returns (bool hasReply);
rpc StackFrame() returns ();
rpc StackFrame3() returns ();
parent:
sync StartRace();
rpc Parent();
sync GetAnsweredParent() returns (bool answeredParent);
child:
Start();
Wakeup();
Wakeup3();
rpc Child();
__delete__();
state START:
@ -37,9 +44,26 @@ state RACE2:
call Race goto DUMMY2_1;
answer Race goto DUMMY2_2;
state DUMMY2_1:
answer Race goto DYING;
answer Race goto TEST3;
state DUMMY2_2:
call Race goto DYING;
call Race goto TEST3;
// Third test: resolve race using custom policy
state TEST3:
call StackFrame3 goto MORESTACK3;
state MORESTACK3:
answer StackFrame3 goto STARTRACE3;
state STARTRACE3:
send Wakeup3 goto RACE3;
state RACE3:
call Child goto DUMMY3_1;
answer Parent goto DUMMY3_2;
state DUMMY3_1:
answer Parent goto CHECK;
state DUMMY3_2:
call Child goto CHECK;
state CHECK:
recv GetAnsweredParent goto DYING;
state DYING:
send __delete__;

Просмотреть файл

@ -2,6 +2,7 @@
#include "IPDLUnitTests.h" // fail etc.
using mozilla::ipc::RPCChannel;
template<>
struct RunnableMethodTraits<mozilla::_ipdltest::TestRPCRacesParent>
@ -14,6 +15,14 @@ struct RunnableMethodTraits<mozilla::_ipdltest::TestRPCRacesParent>
namespace mozilla {
namespace _ipdltest {
RPCChannel::RacyRPCPolicy
MediateRace(const RPCChannel::Message& parent,
const RPCChannel::Message& child)
{
return (PTestRPCRaces::Msg_Child__ID == parent.type()) ?
RPCChannel::RRPParentWins : RPCChannel::RRPChildWins;
}
//-----------------------------------------------------------------------------
// parent
void
@ -70,7 +79,9 @@ TestRPCRacesParent::Test2()
puts(" passed");
Close();
MessageLoop::current()->PostTask(
FROM_HERE,
NewRunnableMethod(this, &TestRPCRacesParent::Test3));
}
bool
@ -89,6 +100,45 @@ TestRPCRacesParent::AnswerStackFrame()
return true;
}
void
TestRPCRacesParent::Test3()
{
puts("Test 3");
if (!CallStackFrame3())
fail("can't set up a stack frame");
puts(" passed");
Close();
}
bool
TestRPCRacesParent::AnswerStackFrame3()
{
if (!SendWakeup3())
fail("can't wake up the child");
if (!CallChild())
fail("can't set up race condition");
return true;
}
bool
TestRPCRacesParent::AnswerParent()
{
mAnsweredParent = true;
return true;
}
bool
TestRPCRacesParent::RecvGetAnsweredParent(bool* answeredParent)
{
*answeredParent = mAnsweredParent;
return true;
}
//-----------------------------------------------------------------------------
// child
bool
@ -144,5 +194,37 @@ TestRPCRacesChild::RecvWakeup()
return true;
}
bool
TestRPCRacesChild::AnswerStackFrame3()
{
if (!CallStackFrame3())
fail("can't set up stack frame");
return true;
}
bool
TestRPCRacesChild::RecvWakeup3()
{
if (!CallParent())
fail("can't set up race condition");
return true;
}
bool
TestRPCRacesChild::AnswerChild()
{
bool parentAnsweredParent;
// the parent is supposed to win the race, which means its
// message, Child(), is supposed to be processed before the
// child's message, Parent()
if (!SendGetAnsweredParent(&parentAnsweredParent))
fail("sending GetAnsweredParent");
if (parentAnsweredParent)
fail("parent was supposed to win the race!");
return true;
}
} // namespace _ipdltest
} // namespace mozilla

Просмотреть файл

@ -9,12 +9,17 @@
namespace mozilla {
namespace _ipdltest {
mozilla::ipc::RPCChannel::RacyRPCPolicy
MediateRace(const mozilla::ipc::RPCChannel::Message& parent,
const mozilla::ipc::RPCChannel::Message& child);
class TestRPCRacesParent :
public PTestRPCRacesParent
{
public:
TestRPCRacesParent() : mHasReply(false), mChildHasReply(false)
TestRPCRacesParent() : mHasReply(false),
mChildHasReply(false),
mAnsweredParent(false)
{ }
virtual ~TestRPCRacesParent() { }
@ -33,6 +38,25 @@ protected:
virtual bool
AnswerStackFrame();
NS_OVERRIDE
virtual bool
AnswerStackFrame3();
NS_OVERRIDE
virtual bool
AnswerParent();
NS_OVERRIDE
virtual bool
RecvGetAnsweredParent(bool* answeredParent);
NS_OVERRIDE
virtual mozilla::ipc::RPCChannel::RacyRPCPolicy
MediateRPCRace(const Message& parent, const Message& child)
{
return MediateRace(parent, child);
}
NS_OVERRIDE
virtual void ActorDestroy(ActorDestroyReason why)
{
@ -48,9 +72,11 @@ private:
void OnRaceTime();
void Test2();
void Test3();
bool mHasReply;
bool mChildHasReply;
bool mAnsweredParent;
};
@ -74,10 +100,29 @@ protected:
virtual bool
AnswerStackFrame();
NS_OVERRIDE
virtual bool
AnswerStackFrame3();
NS_OVERRIDE
virtual bool
RecvWakeup();
NS_OVERRIDE
virtual bool
RecvWakeup3();
NS_OVERRIDE
virtual bool
AnswerChild();
NS_OVERRIDE
virtual mozilla::ipc::RPCChannel::RacyRPCPolicy
MediateRPCRace(const Message& parent, const Message& child)
{
return MediateRace(parent, child);
}
NS_OVERRIDE
virtual void ActorDestroy(ActorDestroyReason why)
{