13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ----------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Render target info.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuApp.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuPlatform.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestContext.hpp"
274e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos#include "tcuTestSessionExecutor.hpp"
284e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos#include "tcuTestHierarchyUtil.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuCommandLine.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
31bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "qpInfo.h"
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "qpDebugOut.h"
34bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
37bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita#include <iostream>
38bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
42bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raitausing std::string;
43bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita
44bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita/*--------------------------------------------------------------------*//*!
45bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita *  Writes all packages found stdout without any
46bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita *  separations. Recommended to be used with a single package
47bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita *  only. It's possible to use test selectors for limiting the export
48bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita *  to one package in a multipackage binary.
49bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita *//*--------------------------------------------------------------------*/
50c5cf5cb5dd01910d08bb5e600fea7179d89f9a68Pyry Haulosstatic void writeCaselistsToStdout (TestPackageRoot& root, TestContext& testCtx)
51bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita{
52c5cf5cb5dd01910d08bb5e600fea7179d89f9a68Pyry Haulos	DefaultHierarchyInflater			inflater		(testCtx);
53c5cf5cb5dd01910d08bb5e600fea7179d89f9a68Pyry Haulos	de::MovePtr<const CaseListFilter>	caseListFilter	(testCtx.getCommandLine().createCaseListFilter(testCtx.getArchive()));
54c5cf5cb5dd01910d08bb5e600fea7179d89f9a68Pyry Haulos	TestHierarchyIterator				iter			(root, inflater, *caseListFilter);
55bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita
56bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita	while (iter.getState() != TestHierarchyIterator::STATE_FINISHED)
57bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita	{
58bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita		iter.next();
59bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita
60bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita		while (iter.getNode()->getNodeType() != NODETYPE_PACKAGE)
61bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita		{
62bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita			if (iter.getState() == TestHierarchyIterator::STATE_ENTER_NODE)
63bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita				std::cout << (isTestNodeTypeExecutable(iter.getNode()->getNodeType()) ? "TEST" : "GROUP") << ": " << iter.getNodePath() << "\n";
64bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita			iter.next();
65bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita		}
66bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita
67bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita		DE_ASSERT(iter.getState() == TestHierarchyIterator::STATE_LEAVE_NODE &&
68bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita				  iter.getNode()->getNodeType() == NODETYPE_PACKAGE);
69bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita		iter.next();
70bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita	}
71bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita}
72bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*!
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Construct test application
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * If a fatal error occurs during initialization constructor will call
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * die() with debug information.
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param platform Reference to platform implementation.
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
813c827367444ee418f129b2c238299f49d3264554Jarkko PoyryApp::App (Platform& platform, Archive& archive, TestLog& log, const CommandLine& cmdLine)
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: m_platform		(platform)
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_watchDog		(DE_NULL)
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_crashHandler	(DE_NULL)
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_crashed			(false)
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_testCtx			(DE_NULL)
874e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	, m_testRoot		(DE_NULL)
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_testExecutor	(DE_NULL)
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	print("dEQP Core %s (0x%08x) starting..\n", qpGetReleaseName(), qpGetReleaseId());
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	print("  target implementation = '%s'\n", qpGetTargetName());
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
937c0f5bea1da74f70e549e9a735c9d702c9396084Lei Zhang	if (!deSetRoundingMode(DE_ROUNDINGMODE_TO_NEAREST_EVEN))
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		qpPrintf("WARNING: Failed to set floating-point rounding mode!\n");
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	try
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
984e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos		const RunMode	runMode	= cmdLine.getRunMode();
994e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Initialize watchdog
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (cmdLine.isWatchDogEnabled())
102963af9cc8940416f5205755d531046a41798cc5bNicolas Capens			TCU_CHECK_INTERNAL(m_watchDog = qpWatchDog_create(onWatchdogTimeout, this, WATCHDOG_TOTAL_TIME_LIMIT_SECS, WATCHDOG_INTERVAL_TIME_LIMIT_SECS));
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Initialize crash handler.
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (cmdLine.isCrashHandlingEnabled())
1064e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos			TCU_CHECK_INTERNAL(m_crashHandler = qpCrashHandler_create(onCrash, this));
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Create test context
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx = new TestContext(m_platform, archive, log, cmdLine, m_watchDog);
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1114e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos		// Create root from registry
1124e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos		m_testRoot = new TestPackageRoot(*m_testCtx, TestPackageRegistry::getSingleton());
1134e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos
1144e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos		// \note No executor is created if runmode is not EXECUTE
1154e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos		if (runMode == RUNMODE_EXECUTE)
1164e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos			m_testExecutor = new TestSessionExecutor(*m_testRoot, *m_testCtx);
117bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita		else if (runMode == RUNMODE_DUMP_STDOUT_CASELIST)
118c5cf5cb5dd01910d08bb5e600fea7179d89f9a68Pyry Haulos			writeCaselistsToStdout(*m_testRoot, *m_testCtx);
1194e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos		else if (runMode == RUNMODE_DUMP_XML_CASELIST)
120bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita			writeXmlCaselistsToFiles(*m_testRoot, *m_testCtx, cmdLine);
1214e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos		else if (runMode == RUNMODE_DUMP_TEXT_CASELIST)
122bb274a4ddafcac39d829208a049e1461d2aa151eKalle Raita			writeTxtCaselistsToFiles(*m_testRoot, *m_testCtx, cmdLine);
1234e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos		else
1244e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos			DE_ASSERT(false);
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	catch (const std::exception& e)
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1284e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos		cleanup();
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		die("Failed to initialize dEQP: %s", e.what());
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1333c827367444ee418f129b2c238299f49d3264554Jarkko PoyryApp::~App (void)
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1354e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	cleanup();
1364e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos}
1374e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos
1384e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulosvoid App::cleanup (void)
1394e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos{
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_testExecutor;
1414e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	delete m_testRoot;
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	delete m_testCtx;
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_crashHandler)
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		qpCrashHandler_destroy(m_crashHandler);
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_watchDog)
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		qpWatchDog_destroy(m_watchDog);
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*!
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Step forward test execution
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \return true if application should call iterate() again and false
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *         if test execution session is complete.
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool App::iterate (void)
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1584e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	if (!m_testExecutor)
1594e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	{
1604e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos		DE_ASSERT(m_testCtx->getCommandLine().getRunMode() != RUNMODE_EXECUTE);
1614e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos		return false;
1624e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	}
1634e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Poll platform events
1654e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	const bool platformOk = m_platform.processEvents();
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Iterate a step.
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool testExecOk = false;
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (platformOk)
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		try
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			testExecOk = m_testExecutor->iterate();
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		catch (const std::exception& e)
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			die("%s", e.what());
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!platformOk || !testExecOk)
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (!platformOk)
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			print("\nABORTED!\n");
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			print("\nDONE!\n");
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const RunMode runMode = m_testCtx->getCommandLine().getRunMode();
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (runMode == RUNMODE_EXECUTE)
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1914e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos			const TestRunStatus& result = m_testExecutor->getStatus();
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Report statistics.
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			print("\nTest run totals:\n");
19509307280328f7fe333960a53cddf8c2962af5536Jarkko Pöyry			print("  Passed:        %d/%d (%.1f%%)\n", result.numPassed,		result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numPassed			/ (float)result.numExecuted) : 0.0f));
19609307280328f7fe333960a53cddf8c2962af5536Jarkko Pöyry			print("  Failed:        %d/%d (%.1f%%)\n", result.numFailed,		result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numFailed			/ (float)result.numExecuted) : 0.0f));
19709307280328f7fe333960a53cddf8c2962af5536Jarkko Pöyry			print("  Not supported: %d/%d (%.1f%%)\n", result.numNotSupported,	result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numNotSupported	/ (float)result.numExecuted) : 0.0f));
19809307280328f7fe333960a53cddf8c2962af5536Jarkko Pöyry			print("  Warnings:      %d/%d (%.1f%%)\n", result.numWarnings,		result.numExecuted, (result.numExecuted > 0 ? (100.0f * (float)result.numWarnings		/ (float)result.numExecuted) : 0.0f));
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!result.isComplete)
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				print("Test run was ABORTED!\n");
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return platformOk && testExecOk;
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
207c5cf5cb5dd01910d08bb5e600fea7179d89f9a68Pyry Haulosconst TestRunStatus& App::getResult (void) const
208c5cf5cb5dd01910d08bb5e600fea7179d89f9a68Pyry Haulos{
209c5cf5cb5dd01910d08bb5e600fea7179d89f9a68Pyry Haulos	return m_testExecutor->getStatus();
210c5cf5cb5dd01910d08bb5e600fea7179d89f9a68Pyry Haulos}
211c5cf5cb5dd01910d08bb5e600fea7179d89f9a68Pyry Haulos
212fb2e496ff5f0c81f67052af9f30ad69f63458641Kalle Raitavoid App::onWatchdogTimeout (qpWatchDog* watchDog, void* userPtr, qpTimeoutReason reason)
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2144e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	DE_UNREF(watchDog);
215fb2e496ff5f0c81f67052af9f30ad69f63458641Kalle Raita	static_cast<App*>(userPtr)->onWatchdogTimeout(reason);
2164e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos}
2174e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos
2184e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulosvoid App::onCrash (qpCrashHandler* crashHandler, void* userPtr)
2194e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos{
2204e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	DE_UNREF(crashHandler);
2214e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	static_cast<App*>(userPtr)->onCrash();
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
224fb2e496ff5f0c81f67052af9f30ad69f63458641Kalle Raitavoid App::onWatchdogTimeout (qpTimeoutReason reason)
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_crashLock.tryLock() || m_crashed)
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return; // In crash handler already.
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_crashed = true;
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_testCtx->getLog().terminateCase(QP_TEST_RESULT_TIMEOUT);
232fb2e496ff5f0c81f67052af9f30ad69f63458641Kalle Raita	die("Watchdog timer timeout for %s", (reason == QP_TIMEOUT_REASON_INTERVAL_LIMIT ? "touch interval" : "total time"));
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void writeCrashToLog (void* userPtr, const char* infoString)
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2378d071f984dc0009c1ce3ba568ae24748bb88024eJarkko Pöyry	// \note THIS IS CALLED BY SIGNAL HANDLER! CALLING MALLOC/FREE IS NOT ALLOWED!
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog* log = static_cast<TestLog*>(userPtr);
2398d071f984dc0009c1ce3ba568ae24748bb88024eJarkko Pöyry	log->writeMessage(infoString);
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void writeCrashToConsole (void* userPtr, const char* infoString)
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2448d071f984dc0009c1ce3ba568ae24748bb88024eJarkko Pöyry	// \note THIS IS CALLED BY SIGNAL HANDLER! CALLING MALLOC/FREE IS NOT ALLOWED!
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_UNREF(userPtr);
2468d071f984dc0009c1ce3ba568ae24748bb88024eJarkko Pöyry	qpPrint(infoString);
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid App::onCrash (void)
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2518d071f984dc0009c1ce3ba568ae24748bb88024eJarkko Pöyry	// \note THIS IS CALLED BY SIGNAL HANDLER! CALLING MALLOC/FREE IS NOT ALLOWED!
2528d071f984dc0009c1ce3ba568ae24748bb88024eJarkko Pöyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!m_crashLock.tryLock() || m_crashed)
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return; // In crash handler already.
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	m_crashed = true;
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool isInCase = m_testExecutor ? m_testExecutor->isInTestCase() : false;
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (isInCase)
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		qpCrashHandler_writeCrashInfo(m_crashHandler, writeCrashToLog, &m_testCtx->getLog());
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx->getLog().terminateCase(QP_TEST_RESULT_CRASH);
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		qpCrashHandler_writeCrashInfo(m_crashHandler, writeCrashToConsole, DE_NULL);
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	die("Test program crashed");
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu
272