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