TestCase::IterateResult MakeCurrentPerfCase::iterate (void)
{
	if (m_samples.size() == 0)
		logTestInfo();

	{
		EGLDisplay	display		= m_eglTestCtx.getDisplay().getEGLDisplay();
		deUint64	beginTimeUs	= deGetMicroseconds();

		for (int iteration = 0; iteration < m_spec.iterationCount; iteration++)
		{
			EGLContext	context = m_contexts[m_rnd.getUint32() % m_contexts.size()];
			EGLSurface	surface	= m_surfaces[m_rnd.getUint32() % m_surfaces.size()];

			TCU_CHECK_EGL_CALL(eglMakeCurrent(display, surface, surface, context));

			if (m_spec.release)
				TCU_CHECK_EGL_CALL(eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
		}

		m_samples.push_back(deGetMicroseconds() - beginTimeUs);
	}

	if ((int)m_samples.size() == m_spec.sampleCount)
	{
		logResults();
		return STOP;
	}
	else
		return CONTINUE;
}
Exemple #2
0
static void timerThread (void* arg)
{
	deTimerThread*	thread			= (deTimerThread*)arg;
	int				numCallbacks	= 0;
	deBool			destroy			= DE_TRUE;
	deInt64			lastCallback	= (deInt64)deGetMicroseconds();

	for (;;)
	{
		int sleepTime = 0;

		deMutex_lock(thread->lock);

		if (thread->state == TIMERSTATE_SINGLE && numCallbacks > 0)
		{
			destroy = DE_FALSE; /* Will be destroyed by deTimer_disable(). */
			thread->state = TIMERSTATE_DISABLED;
			break;
		}
		else if (thread->state == TIMERSTATE_DISABLED)
			break;

		deMutex_unlock(thread->lock);

		sleepTime = thread->interval - (int)(((deInt64)deGetMicroseconds()-lastCallback)/1000);
		if (sleepTime > 0)
			deSleep(sleepTime);

		lastCallback = (deInt64)deGetMicroseconds();
		thread->callback(thread->callbackArg);
		numCallbacks += 1;
	}

	/* State lock is held when loop is exited. */
	deMutex_unlock(thread->lock);

	if (destroy)
	{
		/* Destroy thread except thread->thread. */
		deMutex_destroy(thread->lock);
		deFree(thread);
	}
}
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);
}
tcu::TestNode::IterateResult TextureUploadAndDrawCase::iterate (void)
{
	if (m_testCtx.getTestResult() == QP_TEST_RESULT_NOT_SUPPORTED)
		return STOP;

	if (m_lastIterationRender && (m_calibrator.getState() == gls::TheilSenCalibrator::STATE_MEASURE))
	{
		deUint64 curTime = deGetMicroseconds();
		m_calibrator.recordIteration(curTime - m_renderStart);
	}

	gls::TheilSenCalibrator::State state = m_calibrator.getState();

	if (state == gls::TheilSenCalibrator::STATE_MEASURE)
	{
		// Render
		int	numCalls = m_calibrator.getCallCount();

		m_renderStart			= deGetMicroseconds();
		m_lastIterationRender	= true;

		for (int i = 0; i < numCalls; i++)
			render();

		return CONTINUE;
	}
	else if (state == gls::TheilSenCalibrator::STATE_RECOMPUTE_PARAMS)
	{
		m_calibrator.recomputeParameters();
		m_lastIterationRender = false;
		return CONTINUE;
	}
	else
	{
		DE_ASSERT(state == gls::TheilSenCalibrator::STATE_FINISHED);
		GLU_EXPECT_NO_ERROR(m_context.getRenderContext().getFunctions().getError(), "finish");
		logResults();
		return STOP;
	}
}
bool TestProcess::isRunning (void)
{
	deUint64 curTime = deGetMicroseconds();

	// On Android process launch is asynchronous so we don't want to poll for process until after some time.
	if (curTime-m_launchTime < PROCESS_START_TIMEOUT ||
		curTime-m_lastQueryTime < PROCESS_QUERY_INTERVAL)
		return m_lastRunningStatus;

	JNIEnv*		env		= getCurrentThreadEnv();
	jboolean	res		= env->CallBooleanMethod(m_remote, m_isRunning);
	checkJniException(env, __FILE__, __LINE__);

	DBG_PRINT(("TestProcess::isRunning(): %s", res == JNI_TRUE ? "true" : "false"));
	m_lastQueryTime		= curTime;
	m_lastRunningStatus	= res == JNI_TRUE;

	return m_lastRunningStatus;
}
int PosixTestProcess::readTestLog (deUint8* dst, int numBytes)
{
	if (!m_logReader.isRunning())
	{
		if (deGetMicroseconds() - m_processStartTime > LOG_FILE_TIMEOUT*1000)
		{
			// Timeout, kill process.
			terminate();
			return 0; // \todo [2013-08-13 pyry] Throw exception?
		}

		if (!deFileExists(m_logFileName.c_str()))
			return 0;

		// Start reader.
		m_logReader.start(m_logFileName.c_str());
	}

	DE_ASSERT(m_logReader.isRunning());
	return m_logReader.read(dst, numBytes);
}
int TestProcess::readTestLog (deUint8* dst, int numBytes)
{
	if (!m_logReader.isRunning())
	{
		if (deGetMicroseconds() - m_launchTime > xs::LOG_FILE_TIMEOUT*1000)
		{
			// Timeout, kill process.
			terminate();
			DBG_PRINT(("TestProcess:readTestLog(): Log file timeout occurred!"));
			return 0; // \todo [2013-08-13 pyry] Throw exception?
		}

		if (!deFileExists(LOG_FILE_NAME))
			return 0;

		// Start reader.
		m_logReader.start(LOG_FILE_NAME);
	}

	DE_ASSERT(m_logReader.isRunning());
	return m_logReader.read(dst, numBytes);
}
bool TestCaseWrapper::initTestCase (TestCase* testCase)
{
	// Initialize test case.
	TestLog&	log		= m_testCtx.getLog();
	bool		success	= false;

	// Record test start time.
	m_testStartTime = deGetMicroseconds();

	try
	{
		testCase->init();
		success = true;
	}
	catch (const std::bad_alloc&)
	{
		DE_ASSERT(!success);
		m_testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR, "Failed to allocate memory in test case init");
		m_testCtx.setTerminateAfter(true);
	}
	catch (const tcu::TestException& e)
	{
		DE_ASSERT(!success);
		m_testCtx.setTestResult(e.getTestResult(), e.getMessage());
		m_testCtx.setTerminateAfter(e.isFatal());
		log << e;
	}
	catch (const tcu::Exception& e)
	{
		DE_ASSERT(!success);
		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, e.getMessage());
		log << e;
	}

	DE_ASSERT(success || m_testCtx.getTestResult() != QP_TEST_RESULT_LAST);

	return success;
}
bool TestCaseWrapper::deinitTestCase (TestCase* testCase)
{
	bool deinitOk = false;

	// De-init case.
	try
	{
		testCase->deinit();
		deinitOk = true;
	}
	catch (const tcu::Exception& e)
	{
		m_testCtx.getLog() << e
						   << TestLog::Message << "Error in test case deinit, test program will terminate." << TestLog::EndMessage;
	}

	{
		const deInt64 duration = deGetMicroseconds()-m_testStartTime;
		m_testStartTime = 0;
		m_testCtx.getLog() << TestLog::Integer("TestDuration", "Test case duration in microseconds", "us", QP_KEY_TAG_TIME, duration);
	}

	return deinitOk;
}
tcu::TestStatus RandomOrderExecutor::executeInner(TestCase *testCase, const std::string &casePath)
{
    TestLog &log = m_testCtx.getLog();
    const deUint64 testStartTime = deGetMicroseconds();

    m_testCtx.setTestResult(QP_TEST_RESULT_LAST, "");

    // Initialize, will return immediately if fails
    try
    {
        m_caseExecutor->init(testCase, casePath);
    }
    catch (const std::bad_alloc &)
    {
        m_testCtx.setTerminateAfter(true);
        return TestStatus(QP_TEST_RESULT_RESOURCE_ERROR,
                          "Failed to allocate memory in test case init");
    }
    catch (const TestException &e)
    {
        DE_ASSERT(e.getTestResult() != QP_TEST_RESULT_LAST);
        m_testCtx.setTerminateAfter(e.isFatal());
        log << e;
        return TestStatus(e.getTestResult(), e.getMessage());
    }
    catch (const Exception &e)
    {
        log << e;
        return TestStatus(QP_TEST_RESULT_FAIL, e.getMessage());
    }

    // Execute
    for (;;)
    {
        TestCase::IterateResult iterateResult = TestCase::STOP;

        m_testCtx.touchWatchdog();

        try
        {
            iterateResult = m_caseExecutor->iterate(testCase);
        }
        catch (const std::bad_alloc &)
        {
            m_testCtx.setTestResult(QP_TEST_RESULT_RESOURCE_ERROR,
                                    "Failed to allocate memory during test "
                                    "execution");
        }
        catch (const TestException &e)
        {
            log << e;
            m_testCtx.setTestResult(e.getTestResult(), e.getMessage());
            m_testCtx.setTerminateAfter(e.isFatal());
        }
        catch (const Exception &e)
        {
            log << e;
            m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, e.getMessage());
        }

        if (iterateResult == TestCase::STOP)
            break;
    }

    DE_ASSERT(m_testCtx.getTestResult() != QP_TEST_RESULT_LAST);

    if (m_testCtx.getTestResult() == QP_TEST_RESULT_RESOURCE_ERROR)
        m_testCtx.setTerminateAfter(true);

    // De-initialize
    try
    {
        m_caseExecutor->deinit(testCase);
    }
    catch (const tcu::Exception &e)
    {
        log << e << TestLog::Message << "Error in test case deinit, test program "
                                        "will terminate."
            << TestLog::EndMessage;
        m_testCtx.setTerminateAfter(true);
    }

    if (m_testCtx.getWatchDog())
        qpWatchDog_reset(m_testCtx.getWatchDog());

    {
        const TestStatus result =
            TestStatus(m_testCtx.getTestResult(), m_testCtx.getTestResultDesc());
        m_testCtx.setTestResult(QP_TEST_RESULT_LAST, "");
        return result;
    }
}
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");
		}
	}
}
Exemple #12
0
void Thread::pushMessage (const std::string& str)
{
	de::ScopedLock lock(m_messageLock);
	m_messages.push_back(Message(deGetMicroseconds(), str.c_str()));
}