2009-10-06 11:02:26 -07:00
|
|
|
//
|
|
|
|
// Autogenerated from Python template. Hands off.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "IPDLUnitTests.h"
|
|
|
|
|
2009-12-04 16:15:44 -08:00
|
|
|
#include <stdlib.h>
|
2009-10-06 11:02:26 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/string_util.h"
|
|
|
|
|
|
|
|
#include "IPDLUnitTestSubprocess.h"
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//===== TEMPLATED =====
|
|
|
|
${INCLUDES}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
using mozilla::_ipdltest::IPDLUnitTestSubprocess;
|
|
|
|
|
2009-12-17 16:12:01 -08:00
|
|
|
void* mozilla::_ipdltest::gParentActor;
|
|
|
|
IPDLUnitTestSubprocess* mozilla::_ipdltest::gSubprocess;
|
|
|
|
|
|
|
|
void* mozilla::_ipdltest::gChildActor;
|
|
|
|
|
2009-10-06 11:02:26 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// data/functions accessed by both parent and child processes
|
|
|
|
|
|
|
|
namespace {
|
2009-12-06 22:03:49 -08:00
|
|
|
char* gIPDLUnitTestName = NULL;
|
2009-10-06 11:02:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace _ipdltest {
|
|
|
|
|
|
|
|
const char* const
|
|
|
|
IPDLUnitTestName()
|
|
|
|
{
|
|
|
|
if (!gIPDLUnitTestName) {
|
2009-11-05 16:24:27 -08:00
|
|
|
#if defined(OS_WIN)
|
2009-10-06 11:02:26 -07:00
|
|
|
std::vector<std::wstring> args =
|
|
|
|
CommandLine::ForCurrentProcess()->GetLooseValues();
|
2009-11-05 16:24:27 -08:00
|
|
|
gIPDLUnitTestName = strdup(WideToUTF8(args[0]).c_str());
|
|
|
|
#elif defined(OS_POSIX)
|
|
|
|
std::vector<std::string> argv =
|
|
|
|
CommandLine::ForCurrentProcess()->argv();
|
|
|
|
gIPDLUnitTestName = strdup(argv[1].c_str());
|
2009-10-13 21:08:24 -07:00
|
|
|
#else
|
2009-11-05 16:24:27 -08:00
|
|
|
# error Sorry
|
2009-10-13 21:08:24 -07:00
|
|
|
#endif
|
2009-10-06 11:02:26 -07:00
|
|
|
}
|
|
|
|
return gIPDLUnitTestName;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace _ipdltest
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
enum IPDLUnitTestType {
|
|
|
|
NoneTest = 0,
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//===== TEMPLATED =====
|
|
|
|
${ENUM_VALUES}
|
|
|
|
|
|
|
|
LastTest = ${LAST_ENUM}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
IPDLUnitTestType
|
|
|
|
IPDLUnitTestFromString(const char* const aString)
|
|
|
|
{
|
|
|
|
if (!aString)
|
|
|
|
return static_cast<IPDLUnitTestType>(0);
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//===== TEMPLATED =====
|
|
|
|
${STRING_TO_ENUMS}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
else
|
|
|
|
return static_cast<IPDLUnitTestType>(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* const
|
|
|
|
IPDLUnitTestToString(IPDLUnitTestType aTest)
|
|
|
|
{
|
|
|
|
switch (aTest) {
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//===== TEMPLATED =====
|
|
|
|
${ENUM_TO_STRINGS}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IPDLUnitTestType
|
|
|
|
IPDLUnitTest()
|
|
|
|
{
|
|
|
|
return IPDLUnitTestFromString(mozilla::_ipdltest::IPDLUnitTestName());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace <anon>
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// parent process only
|
|
|
|
|
2009-12-17 16:12:01 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace _ipdltest {
|
|
|
|
|
|
|
|
void
|
|
|
|
IPDLUnitTestMain(void* aData)
|
|
|
|
{
|
|
|
|
char* testString = reinterpret_cast<char*>(aData);
|
|
|
|
IPDLUnitTestType test = IPDLUnitTestFromString(testString);
|
|
|
|
if (!test) {
|
|
|
|
// use this instead of |fail()| because we don't know what the test is
|
2010-03-12 16:23:50 -08:00
|
|
|
fprintf(stderr, MOZ_IPDL_TESTFAIL_LABEL "| %s | unknown unit test %s\n",
|
2009-12-17 16:12:01 -08:00
|
|
|
"<--->", testString);
|
|
|
|
NS_RUNTIMEABORT("can't continue");
|
|
|
|
}
|
|
|
|
gIPDLUnitTestName = testString;
|
|
|
|
|
2010-03-12 16:23:50 -08:00
|
|
|
printf(MOZ_IPDL_TESTINFO_LABEL "| running test | %s\n", gIPDLUnitTestName);
|
|
|
|
|
2009-12-17 16:12:01 -08:00
|
|
|
std::vector<std::string> testCaseArgs;
|
|
|
|
testCaseArgs.push_back(testString);
|
|
|
|
|
|
|
|
gSubprocess = new IPDLUnitTestSubprocess();
|
|
|
|
if (!gSubprocess->SyncLaunch(testCaseArgs))
|
|
|
|
fail("problem launching subprocess");
|
|
|
|
|
|
|
|
IPC::Channel* transport = gSubprocess->GetChannel();
|
|
|
|
if (!transport)
|
|
|
|
fail("no transport");
|
|
|
|
|
|
|
|
base::ProcessHandle child = gSubprocess->GetChildProcessHandle();
|
|
|
|
|
|
|
|
switch (test) {
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//===== TEMPLATED =====
|
|
|
|
${PARENT_MAIN_CASES}
|
|
|
|
//-----------------------------------------------------------------------------
|
2009-12-04 16:15:44 -08:00
|
|
|
|
2009-12-17 16:12:01 -08:00
|
|
|
default:
|
|
|
|
fail("not reached");
|
|
|
|
return; // unreached
|
|
|
|
}
|
|
|
|
}
|
2009-12-04 16:15:44 -08:00
|
|
|
|
|
|
|
void
|
2009-12-06 22:03:49 -08:00
|
|
|
DeleteParentActor()
|
2009-12-04 16:15:44 -08:00
|
|
|
{
|
|
|
|
if (!gParentActor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (IPDLUnitTest()) {
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//===== TEMPLATED =====
|
|
|
|
${PARENT_DELETE_CASES}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
default: mozilla::_ipdltest::fail("???");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-06 22:03:49 -08:00
|
|
|
void
|
|
|
|
QuitXPCOM()
|
|
|
|
{
|
|
|
|
DeleteParentActor();
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
|
|
|
nsCOMPtr<nsIAppShell> appShell (do_GetService(kAppShellCID));
|
|
|
|
appShell->Exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DeleteSubprocess(MessageLoop* uiLoop)
|
|
|
|
{
|
2009-12-06 22:04:00 -08:00
|
|
|
// pong to QuitXPCOM
|
2009-12-06 22:03:49 -08:00
|
|
|
delete gSubprocess;
|
|
|
|
uiLoop->PostTask(FROM_HERE, NewRunnableFunction(QuitXPCOM));
|
|
|
|
}
|
|
|
|
|
2009-12-06 22:04:00 -08:00
|
|
|
void
|
|
|
|
DeferredParentShutdown()
|
|
|
|
{
|
|
|
|
// ping to DeleteSubprocess
|
|
|
|
XRE_GetIOMessageLoop()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
NewRunnableFunction(DeleteSubprocess, MessageLoop::current()));
|
|
|
|
}
|
|
|
|
|
2009-12-06 22:03:49 -08:00
|
|
|
void
|
|
|
|
QuitParent()
|
|
|
|
{
|
2009-12-06 22:04:00 -08:00
|
|
|
// defer "real" shutdown to avoid *Channel::Close() racing with the
|
|
|
|
// deletion of the subprocess
|
|
|
|
MessageLoop::current()->PostTask(
|
|
|
|
FROM_HERE, NewRunnableFunction(DeferredParentShutdown));
|
2009-12-06 22:03:49 -08:00
|
|
|
}
|
|
|
|
|
2009-10-06 11:02:26 -07:00
|
|
|
} // namespace _ipdltest
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// child process only
|
|
|
|
|
2009-12-17 16:12:01 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace _ipdltest {
|
2009-12-04 16:15:44 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
DeleteChildActor()
|
|
|
|
{
|
|
|
|
if (!gChildActor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (IPDLUnitTest()) {
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//===== TEMPLATED =====
|
|
|
|
${CHILD_DELETE_CASES}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
default: mozilla::_ipdltest::fail("???");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-06 11:02:26 -07:00
|
|
|
void
|
2009-10-27 14:52:37 -07:00
|
|
|
IPDLUnitTestChildInit(IPC::Channel* transport,
|
|
|
|
base::ProcessHandle parent,
|
|
|
|
MessageLoop* worker)
|
2009-10-06 11:02:26 -07:00
|
|
|
{
|
2009-12-04 16:15:44 -08:00
|
|
|
if (atexit(DeleteChildActor))
|
|
|
|
fail("can't install atexit() handler");
|
|
|
|
|
2009-10-06 11:02:26 -07:00
|
|
|
switch (IPDLUnitTest()) {
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//===== TEMPLATED =====
|
|
|
|
${CHILD_INIT_CASES}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
default:
|
|
|
|
fail("not reached");
|
|
|
|
return; // unreached
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace _ipdltest
|
|
|
|
} // namespace mozilla
|