13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Internal Test Module
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 Build information tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "ditBuildInfoTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace dit
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* getOsName (int os)
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (os)
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_OS_VANILLA:		return "DE_OS_VANILLA";
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_OS_WIN32:		return "DE_OS_WIN32";
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_OS_UNIX:		return "DE_OS_UNIX";
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_OS_WINCE:		return "DE_OS_WINCE";
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_OS_OSX:			return "DE_OS_OSX";
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_OS_ANDROID:		return "DE_OS_ANDROID";
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_OS_SYMBIAN:		return "DE_OS_SYMBIAN";
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_OS_IOS:			return "DE_OS_IOS";
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return DE_NULL;
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* getCompilerName (int compiler)
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (compiler)
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_COMPILER_VANILLA:	return "DE_COMPILER_VANILLA";
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_COMPILER_MSC:		return "DE_COMPILER_MSC";
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_COMPILER_GCC:		return "DE_COMPILER_GCC";
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_COMPILER_CLANG:		return "DE_COMPILER_CLANG";
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return DE_NULL;
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* getCpuName (int cpu)
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (cpu)
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_CPU_VANILLA:	return "DE_CPU_VANILLA";
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_CPU_ARM:		return "DE_CPU_ARM";
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_CPU_X86:		return "DE_CPU_X86";
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_CPU_X86_64:		return "DE_CPU_X86_64";
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_CPU_ARM_64:		return "DE_CPU_ARM_64";
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_CPU_MIPS:		return "DE_CPU_MIPS";
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_CPU_MIPS_64:	return "DE_CPU_MIPS_64";
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return DE_NULL;
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const char* getEndiannessName (int endianness)
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (endianness)
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_BIG_ENDIAN:		return "DE_BIG_ENDIAN";
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case DE_LITTLE_ENDIAN:	return "DE_LITTLE_ENDIAN";
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return DE_NULL;
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BuildInfoStringCase : public tcu::TestCase
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BuildInfoStringCase (tcu::TestContext& testCtx, const char* name, const char* valueName, const char* value)
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: tcu::TestCase	(testCtx, name, valueName)
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_valueName	(valueName)
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_value		(value)
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult iterate (void)
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << m_valueName << " = " << m_value << TestLog::EndMessage;
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string	m_valueName;
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string	m_value;
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BuildEnumCase : public tcu::TestCase
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	typedef const char* (*GetStringFunc) (int value);
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	BuildEnumCase (tcu::TestContext& testCtx, const char* name, const char* varName, int value, GetStringFunc getString)
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: tcu::TestCase	(testCtx, name, varName)
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_varName		(varName)
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_value		(value)
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, m_getString	(getString)
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult iterate (void)
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*	valueName	= m_getString(m_value);
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool	isOk		= valueName != DE_NULL;
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		std::string	logValue	= valueName ? std::string(valueName) : de::toString(m_value);
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog() << TestLog::Message << m_varName << " = " << logValue << TestLog::EndMessage;
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								isOk ? "Pass"				: "No enum name found");
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string		m_varName;
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	int				m_value;
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GetStringFunc	m_getString;
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass EndiannessConsistencyCase : public tcu::TestCase
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EndiannessConsistencyCase (tcu::TestContext& context, const char* name, const char* description)
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: tcu::TestCase(context, name, description)
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult iterate (void)
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint16	multiByte	= (deUint16)0x0102;
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#if DE_ENDIANNESS == DE_BIG_ENDIAN
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool		isOk		= *((const deUint8*)&multiByte) == (deUint8)0x01;
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#elif DE_ENDIANNESS == DE_LITTLE_ENDIAN
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const bool		isOk		= *((const deUint8*)&multiByte) == (deUint8)0x02;
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.getLog()
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< TestLog::Message
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< "Verifying DE_ENDIANNESS matches actual behavior"
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			<< TestLog::EndMessage;
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS	: QP_TEST_RESULT_FAIL,
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry								isOk ? "Pass"				: "Configured endianness inconsistent");
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1733c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBuildInfoTests::BuildInfoTests (tcu::TestContext& testCtx)
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: tcu::TestCaseGroup(testCtx, "build_info", "Build Info Tests")
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1783c827367444ee418f129b2c238299f49d3264554Jarkko PoyryBuildInfoTests::~BuildInfoTests (void)
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid BuildInfoTests::init (void)
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#if defined(DE_DEBUG)
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool isDebug = true;
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#else
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const bool isDebug = false;
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new BuildInfoStringCase		(m_testCtx, "date",						"__DATE__",			__DATE__));
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new BuildInfoStringCase		(m_testCtx, "time",						"__TIME__",			__TIME__));
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new BuildInfoStringCase		(m_testCtx, "de_debug",					"DE_DEBUG",			isDebug ? "1" : "not defined"));
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new BuildEnumCase				(m_testCtx, "de_os",					"DE_OS",			DE_OS,									getOsName));
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new BuildEnumCase				(m_testCtx, "de_cpu",					"DE_CPU",			DE_CPU,									getCpuName));
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new BuildEnumCase				(m_testCtx, "de_compiler",				"DE_COMPILER",		DE_COMPILER,							getCompilerName));
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new BuildInfoStringCase		(m_testCtx, "de_ptr_size",				"DE_PTR_SIZE",		de::toString(DE_PTR_SIZE).c_str()));
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new BuildEnumCase				(m_testCtx, "de_endianness",			"DE_ENDIANNESS",	DE_ENDIANNESS,							getEndiannessName));
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	addChild(new EndiannessConsistencyCase	(m_testCtx, "de_endianness_consitent", 	"DE_ENDIANNESS"));
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // dit
202