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 Thread test utilities 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuThreadUtil.hpp" 25fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deClock.h" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMemory.h" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing de::SharedPtr; 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace ThreadUtil 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 373c827367444ee418f129b2c238299f49d3264554Jarkko PoyryEvent::Event (void) 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_result (RESULT_NOT_READY) 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_waiterCount (0) 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_waiters (0, 0) 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 443c827367444ee418f129b2c238299f49d3264554Jarkko PoyryEvent::~Event (void) 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Event::setResult (Result result) 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_lock.lock(); 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_result == RESULT_NOT_READY); 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_result = result; 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_lock.unlock(); 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < m_waiterCount; i++) 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_waiters.increment(); 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 593c827367444ee418f129b2c238299f49d3264554Jarkko PoyryEvent::Result Event::waitReady (void) 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_lock.lock(); 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_result == RESULT_NOT_READY) 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_waiterCount++; 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_lock.unlock(); 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_result; 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_lock.unlock(); 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_waiters.decrement(); 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_result; 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 783c827367444ee418f129b2c238299f49d3264554Jarkko PoyryObject::Object (const char* type, SharedPtr<Event> e) 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_type (type) 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_modify (e) 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 843c827367444ee418f129b2c238299f49d3264554Jarkko PoyryObject::~Object (void) 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Object::read (SharedPtr<Event> event, std::vector<SharedPtr<Event> >& deps) 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Make call depend on last modifying call 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deps.push_back(m_modify); 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Add read dependency 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_reads.push_back(event); 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Object::modify (SharedPtr<Event> event, std::vector<SharedPtr<Event> >& deps) 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Make call depend on all reads 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int readNdx = 0; readNdx < (int)m_reads.size(); readNdx++) 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deps.push_back(m_reads[readNdx]); 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deps.push_back(m_modify); 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Update last modifying call 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_modify = event; 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear read dependencies of last "version" of this object 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_reads.clear(); 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1133c827367444ee418f129b2c238299f49d3264554Jarkko PoyryOperation::Operation (const char* name) 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_name (name) 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_event (new Event) 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1193c827367444ee418f129b2c238299f49d3264554Jarkko PoyryOperation::~Operation (void) 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Operation::execute (Thread& thread) 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool success = true; 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Wait for dependencies and check that they succeeded 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int depNdx = 0; depNdx < (int)m_deps.size(); depNdx++) 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_deps[depNdx]->waitReady() != Event::RESULT_OK) 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry success = false; 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Try execute operation 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (success) 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry exec(thread); 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (...) 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Got exception event failed 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_event->setResult(Event::RESULT_FAILED); 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_event->setResult(Event::RESULT_OK); 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Some dependencies failed 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_event->setResult(Event::RESULT_FAILED); 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Release resources 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_deps.clear(); 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_event = SharedPtr<Event>(); 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst MessageBuilder::EndToken Message::End = MessageBuilder::EndToken(); 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MessageBuilder::operator<< (const EndToken&) 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_thread.pushMessage(m_stream.str()); 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 16624ceed3e1acf66512ee25ee75002198b6672879dJarkko PöyryThread::Thread (deUint32 seed) 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_random (seed) 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_status (THREADSTATUS_NOT_STARTED) 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1723c827367444ee418f129b2c238299f49d3264554Jarkko PoyryThread::~Thread (void) 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int operationNdx = 0; operationNdx < (int)m_operations.size(); operationNdx++) 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_operations[operationNdx]; 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_operations.clear(); 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1803c827367444ee418f129b2c238299f49d3264554Jarkko PoyrydeUint8* Thread::getDummyData (size_t size) 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_dummyData.size() < size) 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_dummyData.resize(size); 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return &(m_dummyData[0]); 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Thread::addOperation (Operation* operation) 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_operations.push_back(operation); 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Thread::run (void) 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_status = THREADSTATUS_RUNNING; 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool initOk = false; 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Reserve at least two messages for each operation 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_messages.reserve(m_operations.size()*2); 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry init(); 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry initOk = true; 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int operationNdx = 0; operationNdx < (int)m_operations.size(); operationNdx++) 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_operations[operationNdx]->execute(*this); 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_status = THREADSTATUS_READY; 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const tcu::NotSupportedError& e) 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry newMessage() << "tcu::NotSupportedError '" << e.what() << "'" << Message::End; 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_status = (initOk ? THREADSTATUS_NOT_SUPPORTED : THREADSTATUS_INIT_FAILED); 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const tcu::Exception& e) 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry newMessage() << "tcu::Exception '" << e.what() << "'" << Message::End; 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_status = (initOk ? THREADSTATUS_FAILED : THREADSTATUS_INIT_FAILED); 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const std::exception& error) 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry newMessage() << "std::exception '" << error.what() << "'" << Message::End; 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_status = (initOk ? THREADSTATUS_FAILED : THREADSTATUS_INIT_FAILED); 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (...) 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry newMessage() << "Unkown exception" << Message::End; 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_status = (initOk ? THREADSTATUS_FAILED : THREADSTATUS_INIT_FAILED); 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Thread::exec (void) 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry start(); 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Thread::pushMessage (const std::string& str) 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 245fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi de::ScopedLock lock(m_messageLock); 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_messages.push_back(Message(deGetMicroseconds(), str.c_str())); 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 249fd41d5db179bcd04819c656c3100324a787a456fMika Isojärviint Thread::getMessageCount (void) const 250fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi{ 251fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi de::ScopedLock lock(m_messageLock); 252fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi return (int)(m_messages.size()); 253fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi} 254fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi 255fd41d5db179bcd04819c656c3100324a787a456fMika IsojärviMessage Thread::getMessage (int index) const 256fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi{ 257fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi de::ScopedLock lock(m_messageLock); 258fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi return m_messages[index]; 259fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi} 260fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi 261fd41d5db179bcd04819c656c3100324a787a456fMika Isojärvi 2623c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDataBlock::DataBlock (SharedPtr<Event> event) 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : Object("DataBlock", event) 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DataBlock::setData (size_t size, const void* data) 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_data = std::vector<deUint8>(size); 27024ceed3e1acf66512ee25ee75002198b6672879dJarkko Pöyry deMemcpy(&(m_data[0]), data, size); 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2733c827367444ee418f129b2c238299f49d3264554Jarkko PoyryCompareData::CompareData (SharedPtr<DataBlock> a, SharedPtr<DataBlock> b) 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : Operation ("CompareData") 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_a (a) 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_b (b) 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readObject(SharedPtr<Object>(a)); 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readObject(SharedPtr<Object>(b)); 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid CompareData::exec (Thread& thread) 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool result = true; 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_a->getSize() == m_b->getSize()); 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry thread.newMessage() << "Begin -- CompareData" << Message::End; 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int byteNdx = 0; byteNdx < (int)m_a->getSize(); byteNdx++) 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_a->getData()[byteNdx] != m_b->getData()[byteNdx]) 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry result = false; 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry thread.newMessage() << "CompareData failed at offset :" << byteNdx << Message::End; 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (result) 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry thread.newMessage() << "CompareData passed" << Message::End; 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_FAIL("Data comparision failed"); 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry thread.newMessage() << "End -- CompareData" << Message::End; 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // ThreadUtil 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu 309