13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _GLSSTATEQUERYUTIL_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _GLSSTATEQUERYUTIL_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL (ES) Module 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ----------------------------------------------- 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief State Query test utils. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuDefs.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gls 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace StateQueryUtil 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Rounds given float to the nearest integer (half up). 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Returns the nearest integer for a float argument. In the case that there 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * are two nearest integers at the equal distance (aka. the argument is of 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * form x.5), the integer with the higher value is chosen. (x.5 rounds to x+1) 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T> 453c827367444ee418f129b2c238299f49d3264554Jarkko PoyryT roundGLfloatToNearestIntegerHalfUp (float val) 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return (T)(deFloatFloor(val + 0.5f)); 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Rounds given float to the nearest integer (half down). 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Returns the nearest integer for a float argument. In the case that there 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * are two nearest integers at the equal distance (aka. the argument is of 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * form x.5), the integer with the higher value is chosen. (x.5 rounds to x) 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T> 583c827367444ee418f129b2c238299f49d3264554Jarkko PoyryT roundGLfloatToNearestIntegerHalfDown (float val) 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return (T)(deFloatCeil(val - 0.5f)); 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T> 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass StateQueryMemoryWriteGuard 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry StateQueryMemoryWriteGuard (void); 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry operator T& (void); 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry T* operator & (void); 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isUndefined (void) const; 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isMemoryContaminated (void) const; 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool verifyValidity (tcu::TestContext& testCtx) const; 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const T& get (void) const { return m_value; } 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GUARD_VALUE = 0xDEDEADCD 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry WRITE_GUARD_VALUE = 0xDE 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deInt32 m_preguard; 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry union 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry T m_value; 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8 m_isWrittenToGuard[sizeof(T)]; 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deInt32 m_postguard; // \note guards are not const qualified since the GL implementation might modify them 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T> 983c827367444ee418f129b2c238299f49d3264554Jarkko PoyryStateQueryMemoryWriteGuard<T>::StateQueryMemoryWriteGuard (void) 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_preguard ((deInt32)(GUARD_VALUE)) 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_postguard ((deInt32)(GUARD_VALUE)) 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (size_t i = 0; i < DE_LENGTH_OF_ARRAY(m_isWrittenToGuard); ++i) 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_isWrittenToGuard[i] = (deUint8)WRITE_GUARD_VALUE; 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T> 1073c827367444ee418f129b2c238299f49d3264554Jarkko PoyryStateQueryMemoryWriteGuard<T>::operator T& (void) 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_value; 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T> 1133c827367444ee418f129b2c238299f49d3264554Jarkko PoyryT* StateQueryMemoryWriteGuard<T>::operator & (void) 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return &m_value; 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T> 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool StateQueryMemoryWriteGuard<T>::isUndefined () const 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (size_t i = 0; i < DE_LENGTH_OF_ARRAY(m_isWrittenToGuard); ++i) 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_isWrittenToGuard[i] != (deUint8)WRITE_GUARD_VALUE) 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T> 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool StateQueryMemoryWriteGuard<T>::isMemoryContaminated () const 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return (m_preguard != (deInt32)(GUARD_VALUE)) || (m_postguard != (deInt32)(GUARD_VALUE)); 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename T> 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool StateQueryMemoryWriteGuard<T>::verifyValidity (tcu::TestContext& testCtx) const 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry using tcu::TestLog; 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_preguard != (deInt32)(GUARD_VALUE)) 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry testCtx.getLog() << TestLog::Message << "// ERROR: Pre-guard value was modified " << TestLog::EndMessage; 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (testCtx.getTestResult() == QP_TEST_RESULT_PASS || 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry testCtx.getTestResult() == QP_TEST_RESULT_LAST) 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Get* did an illegal memory write"); 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_postguard != (deInt32)(GUARD_VALUE)) 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry testCtx.getLog() << TestLog::Message << "// ERROR: Post-guard value was modified " << TestLog::EndMessage; 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (testCtx.getTestResult() == QP_TEST_RESULT_PASS || 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry testCtx.getTestResult() == QP_TEST_RESULT_LAST) 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Get* did an illegal memory write"); 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (isUndefined()) 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry testCtx.getLog() << TestLog::Message << "// ERROR: Get* did not return a value" << TestLog::EndMessage; 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (testCtx.getTestResult() == QP_TEST_RESULT_PASS || 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry testCtx.getTestResult() == QP_TEST_RESULT_LAST) 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Get* did not return a value"); 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename T> 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystd::ostream& operator<< (std::ostream& str, const StateQueryMemoryWriteGuard<T>& guard) 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return str << guard.get(); 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // StateQueryUtil 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gls 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _GLSSTATEQUERYUTIL_HPP 180