void TestProcess::start (const char* name, const char* params, const char* workingDir, const char* caseList)
{
	DBG_PRINT(("TestProcess::start(%s, %s, %s, ...)", name, params, workingDir));

	JNIEnv* env			= getCurrentThreadEnv();
	jstring	nameStr		= 0;
	jstring	paramsStr	= 0;
	jstring caseListStr	= 0;

	DE_UNREF(workingDir);

	// Remove old log file if such exists.
	if (deFileExists(LOG_FILE_NAME))
	{
		if (!deDeleteFile(LOG_FILE_NAME) || deFileExists(LOG_FILE_NAME))
			throw xs::TestProcessException(std::string("Failed to remove '") + LOG_FILE_NAME + "'");
	}

	try
	{
		nameStr = env->NewStringUTF(name);
		JNI_CHECK(nameStr);

		paramsStr = env->NewStringUTF(params);
		JNI_CHECK(paramsStr);

		caseListStr = env->NewStringUTF(caseList);
		JNI_CHECK(caseListStr);

		jboolean res = env->CallBooleanMethod(m_remote, m_start, nameStr, paramsStr, caseListStr);
		checkJniException(env, __FILE__, __LINE__);

		if (res == JNI_FALSE)
			throw xs::TestProcessException("Failed to launch activity");

		m_launchTime		= deGetMicroseconds();
		m_lastQueryTime		= m_launchTime;
		m_lastRunningStatus	= true;
	}
	catch (...)
	{
		if (nameStr)
			env->DeleteLocalRef(nameStr);
		if (paramsStr)
			env->DeleteLocalRef(paramsStr);
		if (caseListStr)
			env->DeleteLocalRef(caseListStr);
		throw;
	}

	env->DeleteLocalRef(nameStr);
	env->DeleteLocalRef(paramsStr);
	env->DeleteLocalRef(caseListStr);
}
void PosixTestProcess::start (const char* name, const char* params, const char* workingDir, const char* caseList)
{
	bool hasCaseList = strlen(caseList) > 0;

	XS_CHECK(!m_process);

	de::FilePath logFilePath = de::FilePath::join(workingDir, "TestResults.qpa");
	m_logFileName = logFilePath.getPath();

	// Remove old file if such exists.
	if (deFileExists(m_logFileName.c_str()))
	{
		if (!deDeleteFile(m_logFileName.c_str()) || deFileExists(m_logFileName.c_str()))
			throw TestProcessException(string("Failed to remove '") + m_logFileName + "'");
	}

	// Construct command line.
	string cmdLine = de::FilePath(name).isAbsolutePath() ? name : de::FilePath::join(workingDir, name).normalize().getPath();
	cmdLine += string(" --deqp-log-filename=") + logFilePath.getBaseName();

	if (hasCaseList)
		cmdLine += " --deqp-stdin-caselist";

	if (strlen(params) > 0)
		cmdLine += string(" ") + params;

	DE_ASSERT(!m_process);
	m_process = new de::Process();

	try
	{
		m_process->start(cmdLine.c_str(), strlen(workingDir) > 0 ? workingDir : DE_NULL);
	}
	catch (const de::ProcessError& e)
	{
		delete m_process;
		m_process = DE_NULL;
		throw TestProcessException(e.what());
	}

	m_processStartTime = deGetMicroseconds();

	// Create stdout & stderr readers.
	if (m_process->getStdOut())
		m_stdOutReader.start(m_process->getStdOut());

	if (m_process->getStdErr())
		m_stdErrReader.start(m_process->getStdErr());

	// Start case list writer.
	if (hasCaseList)
	{
		deFile* dst = m_process->getStdIn();
		if (dst)
			m_caseListWriter.start(caseList, dst);
		else
		{
			cleanup();
			throw TestProcessException("Failed to write case list");
		}
	}
}