2013-07-02 20:37:33 -07:00
|
|
|
#include "TestUrgency.h"
|
|
|
|
|
|
|
|
#include "IPDLUnitTests.h" // fail etc.
|
2013-11-21 16:51:26 -08:00
|
|
|
#if defined(OS_POSIX)
|
2013-07-02 20:37:33 -07:00
|
|
|
#include <unistd.h>
|
2013-11-21 16:51:26 -08:00
|
|
|
#else
|
2013-09-27 18:42:08 -07:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2013-07-02 20:37:33 -07:00
|
|
|
|
2013-08-26 21:56:57 -07:00
|
|
|
template<>
|
|
|
|
struct RunnableMethodTraits<mozilla::_ipdltest::TestUrgencyParent>
|
|
|
|
{
|
|
|
|
static void RetainCallee(mozilla::_ipdltest::TestUrgencyParent* obj) { }
|
|
|
|
static void ReleaseCallee(mozilla::_ipdltest::TestUrgencyParent* obj) { }
|
|
|
|
};
|
|
|
|
|
2013-07-02 20:37:33 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace _ipdltest {
|
|
|
|
|
2013-09-27 18:42:08 -07:00
|
|
|
#if defined(OS_POSIX)
|
|
|
|
static void Sleep(int ms)
|
|
|
|
{
|
|
|
|
sleep(ms / 1000);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-02 20:37:33 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// parent
|
|
|
|
|
|
|
|
TestUrgencyParent::TestUrgencyParent()
|
|
|
|
: inreply_(false)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(TestUrgencyParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
TestUrgencyParent::~TestUrgencyParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(TestUrgencyParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TestUrgencyParent::Main()
|
|
|
|
{
|
|
|
|
if (!SendStart())
|
|
|
|
fail("sending Start");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TestUrgencyParent::RecvTest1(uint32_t *value)
|
|
|
|
{
|
2014-10-07 21:32:45 -07:00
|
|
|
if (!SendReply1(value))
|
2013-07-02 20:37:33 -07:00
|
|
|
fail("sending Reply1");
|
|
|
|
if (*value != 99)
|
|
|
|
fail("bad value");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TestUrgencyParent::RecvTest2()
|
|
|
|
{
|
|
|
|
uint32_t value;
|
|
|
|
inreply_ = true;
|
2014-10-07 21:32:45 -07:00
|
|
|
if (!SendReply2(&value))
|
2013-07-02 20:37:33 -07:00
|
|
|
fail("sending Reply2");
|
|
|
|
inreply_ = false;
|
|
|
|
if (value != 500)
|
|
|
|
fail("bad value");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TestUrgencyParent::RecvTest3(uint32_t *value)
|
|
|
|
{
|
|
|
|
if (inreply_)
|
|
|
|
fail("nested non-urgent on top of urgent rpc");
|
|
|
|
*value = 1000;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-26 21:56:57 -07:00
|
|
|
bool
|
|
|
|
TestUrgencyParent::RecvFinalTest_Begin()
|
|
|
|
{
|
2014-08-20 12:49:11 -07:00
|
|
|
return true;
|
2013-08-26 21:56:57 -07:00
|
|
|
}
|
|
|
|
|
2013-07-02 20:37:33 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// child
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kFirstTestBegin = 1,
|
|
|
|
kFirstTestGotReply,
|
|
|
|
kSecondTestBegin,
|
|
|
|
kSecondTestGotReply,
|
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
|
|
|
TestUrgencyChild::RecvStart()
|
|
|
|
{
|
|
|
|
uint32_t result;
|
|
|
|
|
|
|
|
// Send a synchronous message, expect to get an urgent message while
|
|
|
|
// blocked.
|
|
|
|
test_ = kFirstTestBegin;
|
|
|
|
if (!SendTest1(&result))
|
|
|
|
fail("calling SendTest1");
|
|
|
|
if (result != 99)
|
|
|
|
fail("bad result in RecvStart");
|
|
|
|
if (test_ != kFirstTestGotReply)
|
|
|
|
fail("never received urgent message");
|
|
|
|
|
|
|
|
// Initiate the next test by sending an asynchronous message, then becoming
|
|
|
|
// blocked. This tests that the urgent message is still delivered properly,
|
|
|
|
// and that the parent does not try to service the sync
|
|
|
|
test_ = kSecondTestBegin;
|
|
|
|
if (!SendTest2())
|
|
|
|
fail("calling SendTest2");
|
|
|
|
if (!SendTest3(&result))
|
|
|
|
fail("calling SendTest3");
|
|
|
|
if (test_ != kSecondTestGotReply)
|
|
|
|
fail("never received urgent message #2");
|
|
|
|
if (result != 1000)
|
|
|
|
fail("wrong value from test3");
|
|
|
|
|
2014-08-20 12:49:11 -07:00
|
|
|
if (!SendFinalTest_Begin())
|
|
|
|
fail("Final test should have succeeded");
|
2013-08-26 21:56:57 -07:00
|
|
|
|
2013-07-02 20:37:33 -07:00
|
|
|
Close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-10-07 21:32:45 -07:00
|
|
|
TestUrgencyChild::RecvReply1(uint32_t *reply)
|
2013-07-02 20:37:33 -07:00
|
|
|
{
|
|
|
|
if (test_ != kFirstTestBegin)
|
2014-10-07 21:32:45 -07:00
|
|
|
fail("wrong test # in RecvReply1");
|
2013-07-02 20:37:33 -07:00
|
|
|
|
|
|
|
*reply = 99;
|
|
|
|
test_ = kFirstTestGotReply;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-10-07 21:32:45 -07:00
|
|
|
TestUrgencyChild::RecvReply2(uint32_t *reply)
|
2013-07-02 20:37:33 -07:00
|
|
|
{
|
|
|
|
if (test_ != kSecondTestBegin)
|
2014-10-07 21:32:45 -07:00
|
|
|
fail("wrong test # in RecvReply2");
|
2013-07-02 20:37:33 -07:00
|
|
|
|
|
|
|
// sleep for 5 seconds so the parent process tries to deliver more messages.
|
2013-09-27 18:42:08 -07:00
|
|
|
Sleep(5000);
|
2013-07-02 20:37:33 -07:00
|
|
|
|
|
|
|
*reply = 500;
|
|
|
|
test_ = kSecondTestGotReply;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TestUrgencyChild::TestUrgencyChild()
|
|
|
|
: test_(0)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(TestUrgencyChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
TestUrgencyChild::~TestUrgencyChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(TestUrgencyChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace _ipdltest
|
|
|
|
} // namespace mozilla
|