void MockCheckedActualCall::checkExpectations() { if (state_ != CALL_IN_PROGRESS) { unfulfilledExpectations_.resetExpectations(); return; } if (! unfulfilledExpectations_.hasUnfulfilledExpectations()) FAIL("Actual call is in progress. Checking expectations. But no unfulfilled expectations. Cannot happen.") // LCOV_EXCL_LINE fulfilledExpectation_ = unfulfilledExpectations_.removeOneFulfilledExpectationWithIgnoredParameters(); if (fulfilledExpectation_) { callHasSucceeded(); unfulfilledExpectations_.resetExpectations(); return; } if (unfulfilledExpectations_.hasUnfulfilledExpectationsBecauseOfMissingParameters()) { MockExpectedParameterDidntHappenFailure failure(getTest(), getName(), allExpectations_); failTest(failure); } else { MockExpectedObjectDidntHappenFailure failure(getTest(), getName(), allExpectations_); failTest(failure); } }
virtual void test() { item_array& arr = getTest().m_Data ; for ( size_t nPass = 0; nPass < s_nPassPerThread; ) { size_t nIdx = m_rndGen( size_t(0), s_nDataSize - 1 ) ; Item & item = arr.at(nIdx) ; if ( item.m_access.tryLock() ) { if ( item.m_pszBlock ) { m_Alloc.deallocate( item.m_pszBlock, 1 ) ; item.m_pszBlock = NULL ; } else { size_t nSize ; item.m_pszBlock = m_Alloc.allocate( nSize = m_rndGen(s_nMinBlockSize, s_nMaxBlockSize ), NULL ) ; if ( nSize < 32 ) memset( item.m_pszBlock, 0, nSize ) ; else { memset( item.m_pszBlock, 0, 16 ) ; memset( ((char *) item.m_pszBlock) + nSize * sizeof(*item.m_pszBlock) - 16, 0, 16 ) ; } } item.m_access.unlock() ; ++nPass ; } } }
virtual void test() { MAP& rMap = m_Map ; m_nInsertSuccess = m_nInsertFailed = 0 ; key_array const& arr = getTest().m_arrValues ; if ( m_nThreadNo & 1 ) { for ( size_t nPass = 0; nPass < c_nThreadPassCount; ++nPass ) { for ( key_array::const_iterator it = arr.begin(), itEnd = arr.end(); it != itEnd; ++it ) { if ( rMap.insert( *it, *it * 8 ) ) ++m_nInsertSuccess ; else ++m_nInsertFailed ; } } } else { for ( size_t nPass = 0; nPass < c_nThreadPassCount; ++nPass ) { for ( key_array::const_reverse_iterator it = arr.rbegin(), itEnd = arr.rend(); it != itEnd; ++it ) { if ( rMap.insert( *it, *it * 8 ) ) ++m_nInsertSuccess ; else ++m_nInsertFailed ; } } } }
bool TestManager::editTest(const QString &catName, const QString &testName, const quint32 numVis, const bool vis) { if(!tests->editTest(catName, testName, numVis, vis)) return false; Test test = getTest(catName, testName); test.setNumVis(numVis); if(vis) test.setVis(); else test.setNoVis(); QString testFileName = tests->getFileNameTest(catName, testName); QFile file(testsDir + "/" + testFileName); if(!file.open(QIODevice::WriteOnly)) { qDebug() << "Can not open file " << (testsDir + "/" + testFileName) << " for writing. Error: " << file.errorString(); return false; } QDataStream out(&file); out << quint32(magicNumber) << quint16(out.version()); out << test; return true; }
virtual void test() { Set& rSet = m_Set ; m_nInsertSuccess = m_nInsertFailed = 0 ; const std::vector<std::string>& arrString = *getTest().m_parrString ; size_t nArrSize = arrString.size() ; if ( m_nThreadNo & 1 ) { for ( size_t nPass = 0; nPass < c_nThreadPassCount; ++nPass ) { for ( size_t nItem = 0; nItem < c_nMapSize; ++nItem ) { if ( rSet.insert( keyval_type(arrString[nItem % nArrSize], nItem * 8) ) ) ++m_nInsertSuccess ; else ++m_nInsertFailed ; } } } else { for ( size_t nPass = 0; nPass < c_nThreadPassCount; ++nPass ) { for ( size_t nItem = c_nMapSize; nItem > 0; --nItem ) { if ( rSet.insert( keyval_type( arrString[nItem % nArrSize], nItem * 8) ) ) ++m_nInsertSuccess ; else ++m_nInsertFailed ; } } } }
virtual void test() { m_nPopEmpty = 0; m_nPopped = 0; m_nBadWriter = 0; const size_t nTotalWriters = s_nWriterThreadCount; Value v; m_fTime = m_Timer.duration(); while ( true ) { if ( m_Queue.pop( v ) ) { ++m_nPopped; if ( /*v.nWriterNo >= 0 &&*/ v.nWriterNo < nTotalWriters ) m_WriterData[ v.nWriterNo ].push_back( v.nNo ); else ++m_nBadWriter; } else ++m_nPopEmpty; if ( m_Queue.empty() ) { if ( getTest().m_nWriterDone.load() >= nTotalWriters ) { if ( m_Queue.empty() ) break; } } } m_fTime = m_Timer.duration() - m_fTime; }
void initPoppedData() { const size_t nWriterCount = s_nWriterThreadCount; const size_t nWriterPushCount = getTest().m_nThreadPushCount; m_WriterData.resize( nWriterCount ); for ( size_t i = 0; i < nWriterCount; ++i ) m_WriterData[i].reserve( nWriterPushCount ); }
status_t BnMcuService::onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { ALOGI("BnMcuService::onTransact, code[%d]", code); switch (code) { case GET_TEST: { CHECK_INTERFACE(IMcuService, data, reply); int result = getTest(); reply->writeInt32(result); return NO_ERROR; } break; case obtain_info: { CHECK_INTERFACE(IMcuService, data, reply); int domain = data.readInt32(); int cmd = data.readInt32(); Parcel out; bool res = obtainInfo(domain, cmd, out); reply->appendFrom(&out, 0, out.dataSize()); reply->writeInt32(res?1:0); out.freeData(); return NO_ERROR; } break; case send_info: { CHECK_INTERFACE(IMcuService, data, reply); int domain = data.readInt32(); int cmd = data.readInt32(); Parcel in; if(data.dataAvail() >0) { in.appendFrom(&data, data.dataPosition(), data.dataSize()-data.dataPosition()); in.setDataPosition(0); } bool res = sendInfo(domain, cmd, in); reply->writeInt32(res?1:0); in.freeData(); return NO_ERROR; } break; case regist_data_changed_listener: { CHECK_INTERFACE(IMcuService, data, reply); int domain = data.readInt32(); sp<IDataChangedListener> client = interface_cast<IDataChangedListener>(data.readStrongBinder()); bool res = registDataChanagedListener(domain, client); reply->writeInt32((res?1:0)); return NO_ERROR; } break; case unregist_data_changed_listener: { CHECK_INTERFACE(IMcuService, data, reply); int domain = data.readInt32(); sp<IDataChangedListener> client = interface_cast<IDataChangedListener>(data.readStrongBinder()); bool res = unregistDataChanagedListener(domain, client); reply->writeInt32((res?1:0)); return NO_ERROR; } break; default: return BBinder::onTransact(code, data, reply, flags); } }
virtual void test() { size_t nPushCount = getTest().m_nThreadPushCount; Value v; for (size_t i = 0; i < nPushCount; i++) while (! m_Queue.pop( v ) ) ; }
virtual void test() { size_t nPushCount = getTest().m_nThreadPushCount; Value v; for (v.nNo = 0; v.nNo < nPushCount; ++v.nNo) while (! m_Queue.push( v )) ; }
JNIEXPORT jstring JNICALL Java_com_gohon_material_jnisample_Library_getString(JNIEnv *env, jobject instance) { // TODO jstring *jstr =(*env)->NewStringUTF(env, "users"); return getTest(env); }
virtual void test() { size_t nPushCount = getTest().m_nThreadPushCount; Value v; v.nWriterNo = m_nThreadNo; v.nNo = 0; m_nPushFailed = 0; m_fTime = m_Timer.duration(); while ( v.nNo < nPushCount ) { if ( m_Queue.push( v )) ++v.nNo; else ++m_nPushFailed; } m_fTime = m_Timer.duration() - m_fTime; getTest().m_nWriterDone.fetch_add( 1 ); }
virtual void test() { m_nPushError = 0; for ( array_type::const_iterator it = m_arr.begin(); it != m_arr.end(); ++it ) { if ( !m_Queue.push( SimpleValue( *it ) )) ++m_nPushError; } getTest().end_pusher(); }
bool MeasurementFunctorNVPM::callOnInit() { DP_ASSERT( dynamic_cast<TestRender*>( getTest() ) ); if ( !m_nvPerfMon.get() ) { m_nvPerfMon.reset( new NVPerfMon( m_counterFilters ) ); } DP_ASSERT( m_nvPerfMon.get() ); return( m_nvPerfMon->init() && MeasurementFunctor::callOnInit() ); }
virtual void test() { size_t nPushCount = getTest().m_nThreadPushCount; Cacheline v; for (v.nNo = 0; v.nNo < nPushCount; ++v.nNo) { m_Bag.add( v ); #if _DEBUG // Just so writer and reader have approximate "computation" CPPUNIT_MSG( "Added " << v.nNo ); #endif } }
MockActualCall& MockCheckedActualCall::withParameterOfType(const SimpleString& type, const SimpleString& name, const void* value) { MockNamedValue actualParameter(name); actualParameter.setObjectPointer(type, value); if (actualParameter.getComparator() == NULL) { MockNoWayToCompareCustomTypeFailure failure(getTest(), type); failTest(failure); return *this; } checkInputParameter(actualParameter); return *this; }
void MockCheckedActualCall::checkOutputParameter(const MockNamedValue& outputParameter) { unfulfilledExpectations_.onlyKeepUnfulfilledExpectationsWithOutputParameter(outputParameter); if (unfulfilledExpectations_.isEmpty()) { MockUnexpectedOutputParameterFailure failure(getTest(), getName(), outputParameter, allExpectations_); failTest(failure); return; } unfulfilledExpectations_.outputParameterWasPassed(outputParameter.getName()); finalizeCallWhenFulfilled(); }
MockFunctionCall& MockActualFunctionCall::withParameterOfType(const SimpleString& type, const SimpleString& name, void* value) { if (getComparatorForType(type) == NULL) { MockNoWayToCompareCustomTypeFailure failure(getTest(), type); failTest(failure); return *this; } MockNamedValue actualParameter(name); actualParameter.setObjectPointer(type, value); actualParameter.setComparator(getComparatorForType(type)); checkActualParameter(actualParameter); return *this; }
void MockActualFunctionCall::checkActualParameter(const MockNamedValue& actualParameter) { unfulfilledExpectations_.onlyKeepUnfulfilledExpectationsWithParameter(actualParameter); if (unfulfilledExpectations_.isEmpty()) { MockUnexpectedParameterFailure failure(getTest(), getName(), actualParameter, allExpectations_); failTest(failure); return; } unfulfilledExpectations_.parameterWasPassed(actualParameter.getName()); finnalizeCallWhenFulfilled(); }
virtual void test() { m_nPopSuccess = 0; m_nPopFailed = 0; SimpleValue val; while ( getTest().pushing() || !m_Queue.empty() ) { if ( m_Queue.pop( val )) ++m_nPopSuccess; else ++m_nPopFailed; } }
bool MeasurementFunctorNVPM::callOnRun( unsigned int i ) { DP_ASSERT( m_nvPerfMon.get() ); bool ok = true; while ( ok && !m_nvPerfMon->finishedExperiment() ) { m_nvPerfMon->beginPass(); ok = MeasurementFunctor::callOnRun( i ); static_cast<TestRender*>(getTest())->getBackend()->finish(); m_nvPerfMon->endPass(); } return( ok ); }
virtual void test() { Map& rMap = m_Map ; m_nDeleteSuccess = m_nDeleteFailed = 0 ; std::vector<size_t>& arrData = getTest().m_arrData ; if ( m_nThreadNo & 1 ) { for ( size_t k = 0; k < c_nInsThreadCount; ++k ) { for ( size_t i = 0; i < arrData.size(); ++i ) { if ( arrData[i] & 1 ) { if ( rMap.erase_with( arrData[i], key_less() )) ++m_nDeleteSuccess ; else ++m_nDeleteFailed ; } } if ( getTest().m_nInsThreadCount.load( CDS_ATOMIC::memory_order_acquire ) == 0 ) break; } } else { for ( size_t k = 0; k < c_nInsThreadCount; ++k ) { for ( size_t i = arrData.size() - 1; i > 0; --i ) { if ( arrData[i] & 1 ) { if ( rMap.erase_with( arrData[i], key_less() )) ++m_nDeleteSuccess ; else ++m_nDeleteFailed ; } } if ( getTest().m_nInsThreadCount.load( CDS_ATOMIC::memory_order_acquire ) == 0 ) break; } } }
bool MeasurementFunctorGoldImage::saveImages() { bool foundFile = true; bool success = true; const std::string& name = getCurTestName(); unsigned int nShots = dp::util::checked_cast<unsigned int>(m_screenshots.size()); for(unsigned int i = 0; i < nShots; i++) { std::string goldImageName(m_filenamePrefix + name + "_" + getTest()->getDescriptionOnRunInit(i) + m_filenameSuffix + util::to_string(".png")); if( m_gold ) { std::string filename( m_goldDir + "\\" + goldImageName ); dp::util::imageToFile( retrieveScreenshot(i), filename ); std::cerr << "Saved gold image: " << goldImageName + "\n"; } else { util::SmartImage gold = util::imageFromFile(m_goldDir + "\\" + goldImageName); if( !gold ) { if(foundFile) { std::cerr << "Could not find the following gold images\n"; foundFile = false; } std::cerr << goldImageName << "\n"; continue; } if( *retrieveScreenshot(i) != *gold ) { std::cerr << "Gold image comparison failed for " << goldImageName << "\n"; success = false; } std::string filename( m_imageDir + "\\" + goldImageName ); dp::util::imageToFile(retrieveScreenshot(i), filename); } } m_screenshots.clear(); return foundFile && success; }
MockFunctionCall& MockActualFunctionCall::onObject(void* objectPtr) { unfulfilledExpectations_.onlyKeepUnfulfilledExpectationsOnObject(objectPtr); if (unfulfilledExpectations_.isEmpty()) { MockUnexpectedObjectFailure failure(getTest(), getName(), objectPtr, allExpectations_); failTest(failure); return *this; } unfulfilledExpectations_.wasPassedToObject(); finnalizeCallWhenFulfilled(); return *this; }
virtual void test() { Map& rMap = m_Map ; m_nInsertSuccess = m_nInsertFailed = 0 ; std::vector<size_t>& arrData = getTest().m_arrData ; for ( size_t i = 0; i < arrData.size(); ++i ) { if ( rMap.insert( key_type( arrData[i], m_nThreadNo ))) ++m_nInsertSuccess ; else ++m_nInsertFailed ; } ensure_func f ; for ( size_t i = arrData.size() - 1; i > 0; --i ) { if ( arrData[i] & 1 ) { rMap.ensure( key_type( arrData[i], m_nThreadNo ), f ) ; } } getTest().m_nInsThreadCount.fetch_sub( 1, CDS_ATOMIC::memory_order_acquire ) ; }
DPTCORE_API void MeasurementFunctorNVPM::OutputPlotDataCSV() { Test * test = getTest(); DP_ASSERT( test ); std::string fileName = m_resultsDir + "//" + m_resultsFilenamePrefix + getCurTestName() + m_resultsFilenameSuffix + "_run.csv"; std::ofstream of( fileName.c_str() ); if ( of.fail() ) { std::cerr << "Warning: Could not open file <" << fileName << "> !!\n"; } else { of << "# Generated by dp::testfw::core::MeasurementFunctorNVPM for test <" << test->getDescriptionOnInit() << ">\n\n"; of << "CounterName"; unsigned int nResults = checked_cast<unsigned int>(m_counterResults.size()); for ( unsigned int i=0 ; i<nResults ; i++ ) { of << ";" << test->getDescriptionOnRunInit( i ); } of << std::endl; const vector<NVPMCounterID> & counterIDs = m_nvPerfMon->getCounterIDs(); const NVPerfMon::CounterIDToSpecMap & counterToSpecMap = m_nvPerfMon->getCounterIDToSpecMap(); for ( size_t i=0 ; i<counterIDs.size() ; i++ ) { NVPerfMon::CounterIDToSpecMap::const_iterator it = counterToSpecMap.find( counterIDs[i] ); DP_ASSERT( it != counterToSpecMap.end() ); of << it->second.name; if ( it->second.percentage ) { of << " (%)"; for ( unsigned int j=0 ; j<nResults ; j++ ) { of << ";" << m_counterResults[j][i].percent; } } else { for ( unsigned int j=0 ; j<nResults ; j++ ) { of << ";" << m_counterResults[j][i].count; } } of << std::endl; } } }
virtual void test() { size_t nPushCount = getTest().m_nThreadPushCount; Cacheline v; for (size_t i = 0; i < nPushCount; i++) { while (! m_Bag.tryRemoveAny( v ) ) ; #ifdef _DEBUG CPPUNIT_MSG( "Removed " << v.nNo ); #endif } #ifdef _DEBUG CPPUNIT_MSG( "Consumer finished." ); #endif }
MockActualCall& MockCheckedActualCall::onObject(const void* objectPtr) { callIsInProgress(); unfulfilledExpectations_.onlyKeepExpectationsOnObject(objectPtr); if (unfulfilledExpectations_.isEmpty()) { MockUnexpectedObjectFailure failure(getTest(), getName(), objectPtr, allExpectations_); failTest(failure); return *this; } unfulfilledExpectations_.wasPassedToObject(); finalizeCallWhenFulfilled(); return *this; }
virtual void test() { ValueVector& arr = getTest().m_Arr ; //size_t nSize = arr.size() ; MAP& rMap = m_Map ; for ( size_t nPass = 0; nPass < c_nPassCount; ++nPass ) { if ( m_nThreadNo & 1 ) { ValueVector::const_iterator itEnd = arr.end() ; for ( ValueVector::const_iterator it = arr.begin(); it != itEnd; ++it ) { bool bFound = rMap.find( *(it->pKey) ) ; if ( it->bExists ) { if ( bFound ) ++m_KeyExists.nSuccess ; else ++m_KeyExists.nFailed ; } else { if ( bFound ) ++m_KeyNotExists.nFailed ; else ++m_KeyNotExists.nSuccess ; } } } else { ValueVector::const_reverse_iterator itEnd = arr.rend() ; for ( ValueVector::const_reverse_iterator it = arr.rbegin(); it != itEnd; ++it ) { bool bFound = rMap.find( *(it->pKey) ) ; if ( it->bExists ) { if ( bFound ) ++m_KeyExists.nSuccess ; else ++m_KeyExists.nFailed ; } else { if ( bFound ) ++m_KeyNotExists.nFailed ; else ++m_KeyNotExists.nSuccess ; } } } } }
MockFunctionCall& MockActualFunctionCall::withName(const SimpleString& name) { setName(name); setState(CALL_IN_PROGESS); unfulfilledExpectations_.onlyKeepUnfulfilledExpectationsRelatedTo(name); if (unfulfilledExpectations_.isEmpty()) { MockUnexpectedCallHappenedFailure failure(getTest(), name, allExpectations_); failTest(failure); return *this; } unfulfilledExpectations_.callWasMade(callOrder_); finnalizeCallWhenFulfilled(); return *this; }