UniqueRandomIterator<T>::UniqueRandomIterator (deUint32 numItems, deUint32 numValues, int seed) { de::Random rnd(seed); DE_ASSERT(numItems <= numValues); if (numItems == numValues) { // Fast way to populate the index sequence m_indices = std::vector<deUint32>(numItems); for (deUint32 itemNdx = 0; itemNdx < numItems; itemNdx++) m_indices[itemNdx] = itemNdx; } else { std::set<deUint32> uniqueIndices; // Populate set with "numItems" unique values between 0 and numValues - 1 while (uniqueIndices.size() < numItems) uniqueIndices.insert(rnd.getUint32() % numValues); // Copy set into index sequence m_indices = std::vector<deUint32>(uniqueIndices.begin(), uniqueIndices.end()); } // Scramble the indices rnd.shuffle(m_indices.begin(), m_indices.end()); reset(); }
void ContainerFormatParser::getData (deUint8* dst, int numBytes, int offset) { DE_ASSERT(de::inBounds(offset, 0, m_elementLen) && numBytes > 0 && de::inRange(numBytes+offset, 0, m_elementLen)); for (int ndx = 0; ndx < numBytes; ndx++) dst[ndx] = m_buf.peekBack(offset+ndx); }
void RingBuffer<T>::resize (int newSize) { DE_ASSERT(newSize >= m_numElements); T* buf = new T[newSize]; try { // Copy old elements. for (int ndx = 0; ndx < m_numElements; ndx++) buf[ndx] = m_buffer[(m_back + ndx) % m_size]; // Reset pointers. m_front = m_numElements; m_back = 0; m_size = newSize; DE_SWAP(T*, buf, m_buffer); delete[] buf; } catch (...) { delete[] buf; throw; } }
std::ostream& operator<< (std::ostream& str, const TypeAccessFormat& format) { const VarType* curType = &format.type; for (TypeComponentVector::const_iterator iter = format.path.begin(); iter != format.path.end(); iter++) { switch (iter->type) { case VarTypeComponent::ARRAY_ELEMENT: curType = &curType->getElementType(); // Update current type. // Fall-through. case VarTypeComponent::MATRIX_COLUMN: case VarTypeComponent::VECTOR_COMPONENT: str << "[" << iter->index << "]"; break; case VarTypeComponent::STRUCT_MEMBER: { const StructMember& member = curType->getStructPtr()->getMember(iter->index); str << "." << member.getName(); curType = &member.getType(); break; } default: DE_ASSERT(false); } } return str; }
int wrap (Sampler::WrapMode mode, int c, int size) { switch (mode) { // \note CL and GL modes are handled identically here, as verification process accounts for // accuracy differences caused by different methods (wrapping vs. denormalizing first). case tcu::Sampler::CLAMP_TO_BORDER: return deClamp32(c, -1, size); case tcu::Sampler::CLAMP_TO_EDGE: return deClamp32(c, 0, size-1); case tcu::Sampler::REPEAT_GL: case tcu::Sampler::REPEAT_CL: return imod(c, size); case tcu::Sampler::MIRRORED_REPEAT_GL: case tcu::Sampler::MIRRORED_REPEAT_CL: return (size - 1) - mirror(imod(c, 2*size) - size); default: DE_ASSERT(DE_FALSE); return 0; } }
static void handle_dlm_load_cfm(hic_dlm_load_cfm_t *cfm) { hic_message_context_t msg_ref; hic_dlm_load_req_t *req; DE_ASSERT(dlm_state.ops); if(cfm->remaining_size == 0) { /* done */ WiFiEngine_AllowPowerSave(dlm_state.ps_ctrl); return; } create_dlm_req_and_update_state( &msg_ref, &req, cfm->address, cfm->remaining_size); DE_TRACE_INT4(TR_INITIALIZE, "DLM_REQ a:%x s:%u rs:%u c:%x\n", req->address, req->page.size, req->remaining_size, req->checksum); send_and_free(&msg_ref,req); }
static deBool qpTestLog_writeKeyValuePair (qpTestLog* log, const char* elementName, const char* name, const char* description, const char* unit, qpKeyValueTag tag, const char* text) { const char* tagString = QP_LOOKUP_STRING(s_qpTagMap, tag); qpXmlAttribute attribs[8]; int numAttribs = 0; DE_ASSERT(log && elementName && text); deMutex_lock(log->lock); /* Fill in attributes. */ if (name) attribs[numAttribs++] = qpSetStringAttrib("Name", name); if (description) attribs[numAttribs++] = qpSetStringAttrib("Description", description); if (tagString) attribs[numAttribs++] = qpSetStringAttrib("Tag", tagString); if (unit) attribs[numAttribs++] = qpSetStringAttrib("Unit", unit); if (!qpXmlWriter_startElement(log->writer, elementName, numAttribs, attribs) || !qpXmlWriter_writeString(log->writer, text) || !qpXmlWriter_endElement(log->writer, elementName)) { qpPrintf("qpTestLog_writeKeyValuePair(): Writing XML failed\n"); deMutex_unlock(log->lock); return DE_FALSE; } deMutex_unlock(log->lock); return DE_TRUE; }
/** Reads read buffer's depth data (assuming it's of 32-bit FP resolution) * and verifies its correctness. * * @param texture_size Texture size * @param n_layer Index of the layer to verify. * * @return true if the retrieved data was found correct, false otherwise. **/ bool TextureCubeMapArrayColorDepthAttachmentsTest::verifyDepth32FData(const _texture_size& texture_size, glw::GLuint n_layer) { /* Allocate buffer for the data we will retrieve from the implementation */ glw::GLfloat expected_value = (glw::GLfloat)n_layer / 256.0f; const glw::Functions& gl = m_context.getRenderContext().getFunctions(); bool result = false; const glw::GLuint result_data_size = texture_size.m_size * texture_size.m_size; glw::GLfloat* result_data = new glw::GLfloat[result_data_size]; DE_ASSERT(result_data != NULL); /* Read the data */ gl.readPixels(0, /* x */ 0, /* y */ texture_size.m_size, texture_size.m_size, m_depth_format, m_depth_type, result_data); GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels() call failed"); /* Verify image, expected value is layer index */ result = verifyImage<glw::GLfloat, 1>(texture_size.m_size, texture_size.m_size, &expected_value, result_data); /* Release the buffer */ if (result_data != NULL) { delete[] result_data; result_data = NULL; } return result; }
explicit Message (MessageType type_) : type(type_) { DE_ASSERT(type_ == MESSAGE_RESUME || type_ == MESSAGE_PAUSE || type_ == MESSAGE_FINISH); }
rr::BlendFunc mapGLBlendFunc (deUint32 func) { switch (func) { case GL_ZERO: return rr::BLENDFUNC_ZERO; case GL_ONE: return rr::BLENDFUNC_ONE; case GL_SRC_COLOR: return rr::BLENDFUNC_SRC_COLOR; case GL_ONE_MINUS_SRC_COLOR: return rr::BLENDFUNC_ONE_MINUS_SRC_COLOR; case GL_DST_COLOR: return rr::BLENDFUNC_DST_COLOR; case GL_ONE_MINUS_DST_COLOR: return rr::BLENDFUNC_ONE_MINUS_DST_COLOR; case GL_SRC_ALPHA: return rr::BLENDFUNC_SRC_ALPHA; case GL_ONE_MINUS_SRC_ALPHA: return rr::BLENDFUNC_ONE_MINUS_SRC_ALPHA; case GL_DST_ALPHA: return rr::BLENDFUNC_DST_ALPHA; case GL_ONE_MINUS_DST_ALPHA: return rr::BLENDFUNC_ONE_MINUS_DST_ALPHA; case GL_CONSTANT_COLOR: return rr::BLENDFUNC_CONSTANT_COLOR; case GL_ONE_MINUS_CONSTANT_COLOR: return rr::BLENDFUNC_ONE_MINUS_CONSTANT_COLOR; case GL_CONSTANT_ALPHA: return rr::BLENDFUNC_CONSTANT_ALPHA; case GL_ONE_MINUS_CONSTANT_ALPHA: return rr::BLENDFUNC_ONE_MINUS_CONSTANT_ALPHA; case GL_SRC_ALPHA_SATURATE: return rr::BLENDFUNC_SRC_ALPHA_SATURATE; case GL_SRC1_COLOR: return rr::BLENDFUNC_SRC1_COLOR; case GL_ONE_MINUS_SRC1_COLOR: return rr::BLENDFUNC_ONE_MINUS_SRC1_COLOR; case GL_SRC1_ALPHA: return rr::BLENDFUNC_SRC1_ALPHA; case GL_ONE_MINUS_SRC1_ALPHA: return rr::BLENDFUNC_ONE_MINUS_SRC1_ALPHA; default: DE_ASSERT(false); return rr::BLENDFUNC_LAST; } }
int core_dump_append(void *ctx, void *data, size_t len) { struct dump_s *s = (struct dump_s*)ctx; if(s==NULL) { return -1; } if( s->cache ) { /* Coredump cache must be larger then each packet */ DE_ASSERT(len < DE_COREDUMP_CACHE_SIZE); if(s->cache_off + len >= DE_COREDUMP_CACHE_SIZE) { s->written += de_fwrite(s->file, s->cache, s->cache_off); s->cache_off = 0; } DE_MEMCPY(s->cache + s->cache_off, data, len); s->cache_off += len; } else { s->written += de_fwrite(s->file, (char*)data, len); } DE_TRACE_INT2(TR_NOISE, "wrote %d file at %d\n", len, s->written); return len; }
static void stripLeadingPath (char* fileName, const char* pathPrefix) { int pathLen = strlen(pathPrefix); int fileNameLen = strlen(fileName); DE_ASSERT(beginsWithPath(fileName, pathPrefix)); /* Strip trailing / */ while (pathLen > 0 && pathPrefix[pathLen-1] == '/') pathLen -= 1; DE_ASSERT(pathLen > 0); DE_ASSERT(fileName[pathLen] == '/'); memmove(&fileName[0], &fileName[0]+pathLen+1, fileNameLen-pathLen); }
void deProcess_cleanupHandles (deProcess* process) { DE_ASSERT(!deProcess_isRunning(process)); if (process->standardErr) deFile_destroy(process->standardErr); if (process->standardOut) deFile_destroy(process->standardOut); if (process->standardIn) deFile_destroy(process->standardIn); if (process->procInfo.hProcess) CloseHandle(process->procInfo.hProcess); if (process->procInfo.hThread) CloseHandle(process->procInfo.hThread); process->standardErr = DE_NULL; process->standardOut = DE_NULL; process->standardIn = DE_NULL; process->procInfo.hProcess = DE_NULL; process->procInfo.hThread = DE_NULL; }
/*--------------------------------------------------------------------*//*! * \brief Start thread. * * Starts thread that will execute the virtual run() method. * * The function will fail if the thread is currently running or has finished * but no join() has been called. *//*--------------------------------------------------------------------*/ void Thread::start (void) { DE_ASSERT(!m_thread); m_thread = deThread_create(threadFunc, this, &m_attribs); if (!m_thread) throw std::bad_alloc(); }
IterateResult NumLayersTest::build (FboBuilder& builder) { TextureLayered* texCfg = DE_NULL; const GLenum target = GL_COLOR_ATTACHMENT0; switch (m_params.textureKind) { case GL_TEXTURE_3D: texCfg = &builder.makeConfig<Texture3D>(); break; case GL_TEXTURE_2D_ARRAY: texCfg = &builder.makeConfig<Texture2DArray>(); break; default: DE_ASSERT(!"Impossible case"); } texCfg->internalFormat = getDefaultFormat(target, GL_TEXTURE); texCfg->width = 64; texCfg->height = 64; texCfg->numLayers = m_params.numLayers; const GLuint tex = builder.glCreateTexture(*texCfg); TextureLayerAttachment* att = &builder.makeConfig<TextureLayerAttachment>(); att->layer = m_params.attachmentLayer; att->imageName = tex; builder.glAttach(target, att); return STOP; }
void ContainerFormatParser::parseContainerValue (std::string& dst, int& offset) const { DE_ASSERT(offset < m_elementLen); bool isString = getChar(offset) == '"' || getChar(offset) == '\''; int quotChar = isString ? getChar(offset) : 0; if (isString) offset += 1; dst.clear(); for (;;) { int curChar = offset < m_elementLen ? getChar(offset) : 0; bool isEnd = curChar == 0 || curChar == (int)END_OF_BUFFER || (isString ? (curChar == quotChar) : (curChar == ' ' || curChar == '\n' || curChar == '\r')); if (isEnd) break; else { // \todo [2012-06-09 pyry] Escapes. dst.push_back((char)curChar); } offset += 1; } if (isString && getChar(offset) == quotChar) offset += 1; }
void deTimer_destroy (deTimer* timer) { DE_ASSERT(timer); timer_delete(timer->timer); deFree(timer); }
void deMutex_destroy (deMutex mutex) { pthread_mutex_t* pMutex = (pthread_mutex_t*)mutex; DE_ASSERT(pMutex); pthread_mutex_destroy(pMutex); deFree(pMutex); }
static deTimerThread* deTimerThread_create (deTimerCallback callback, void* arg, int interval, TimerState state) { deTimerThread* thread = (deTimerThread*)deCalloc(sizeof(deTimerThread)); DE_ASSERT(state == TIMERSTATE_INTERVAL || state == TIMERSTATE_SINGLE); if (!thread) return DE_NULL; thread->callback = callback; thread->callbackArg = arg; thread->interval = interval; thread->lock = deMutex_create(DE_NULL); thread->state = state; thread->thread = deThread_create(timerThread, thread, DE_NULL); if (!thread->thread) { deMutex_destroy(thread->lock); deFree(thread); return DE_NULL; } return thread; }
DE_BEGIN_EXTERN_C JNIEXPORT void JNICALL Java_com_drawelements_deqp_execserver_ExecService_onCreateNative (JNIEnv* env, jobject obj) { tcu::Android::ExecService* service = DE_NULL; JavaVM* vm = DE_NULL; try { DE_ASSERT(!getExecService(env, obj)); env->GetJavaVM(&vm); TCU_CHECK_INTERNAL(vm); service = new tcu::Android::ExecService(vm, obj); service->start(); setExecService(env, obj, service); } catch (const std::exception& e) { logException(e); delete service; tcu::die("ExecService.onCreateNative() failed"); } }
static void inStreamCopy (void* arg) { deThreadInStream* threadStream = (deThreadInStream*)arg; deUint8* buffer = malloc(sizeof(deUint8) * threadStream->bufferSize); for(;;) { deInt32 read = 0; deInt32 written = 0; deStreamResult readResult = DE_STREAMRESULT_ERROR; readResult = deInStream_read(threadStream->input, buffer, threadStream->bufferSize, &read); DE_ASSERT(readResult != DE_STREAMRESULT_ERROR); while (written < read) { deInt32 wrote = 0; /* \todo [mika] Handle errors */ deOutStream_write(&(threadStream->producerStream), buffer, read - written, &wrote); written += wrote; } if (readResult == DE_STREAMRESULT_END_OF_STREAM) { break; } } deOutStream_flush(&(threadStream->producerStream)); deRingbuffer_stop(threadStream->ringbuffer); free(buffer); }
inline void RingBuffer<T>::pushFront (const T& elem) { DE_ASSERT(getNumFree() > 0); m_buffer[m_front] = elem; m_front = (m_front + 1) % m_size; m_numElements += 1; }
void deSemaphore_destroy (deSemaphore semaphore) { sem_t* sem = (sem_t*)semaphore; DE_ASSERT(sem); sem_destroy(sem); deFree(sem); }
static void writeCaseListNode (std::ostream& str, const TestNode* node, const TestSet& testSet) { DE_ASSERT(testSet.hasNode(node)); TestNodeType nodeType = node->getNodeType(); if (nodeType != TESTNODETYPE_ROOT) str << node->getName(); if (nodeType == TESTNODETYPE_ROOT || nodeType == TESTNODETYPE_GROUP) { const TestGroup* group = static_cast<const TestGroup*>(node); bool isFirst = true; str << "{"; for (int ndx = 0; ndx < group->getNumChildren(); ndx++) { const TestNode* child = group->getChild(ndx); if (testSet.hasNode(child)) { if (!isFirst) str << ","; writeCaseListNode(str, child, testSet); isFirst = false; } } str << "}"; } }
void deSemaphore_decrement (deSemaphore semaphore) { sem_t* sem = (sem_t*)semaphore; int ret = sem_wait(sem); DE_ASSERT(ret == 0); DE_UNREF(ret); }
void VarTokenizer::advance (void) { DE_ASSERT(m_token != TOKEN_END); m_tokenStart += m_tokenLen; m_token = TOKEN_LAST; m_tokenLen = 1; if (m_str[m_tokenStart] == '[') m_token = TOKEN_LEFT_BRACKET; else if (m_str[m_tokenStart] == ']') m_token = TOKEN_RIGHT_BRACKET; else if (m_str[m_tokenStart] == 0) m_token = TOKEN_END; else if (m_str[m_tokenStart] == '.') m_token = TOKEN_PERIOD; else if (isNum(m_str[m_tokenStart])) { m_token = TOKEN_NUMBER; while (isNum(m_str[m_tokenStart+m_tokenLen])) m_tokenLen += 1; } else if (isIdentifierChar(m_str[m_tokenStart])) { m_token = TOKEN_IDENTIFIER; while (isIdentifierChar(m_str[m_tokenStart+m_tokenLen])) m_tokenLen += 1; } else TCU_FAIL("Unexpected character"); }
void ContainerFormatParser::advance (void) { if (m_element != CONTAINERELEMENT_INCOMPLETE) { m_buf.popBack(m_elementLen); m_element = CONTAINERELEMENT_INCOMPLETE; m_elementLen = 0; m_attribute.clear(); m_value.clear(); } for (;;) { int curChar = getChar(m_elementLen); if (curChar != (int)END_OF_BUFFER) m_elementLen += 1; if (curChar == END_OF_STRING) { if (m_elementLen == 1) m_element = CONTAINERELEMENT_END_OF_STRING; else if (m_state == STATE_CONTAINER_LINE) parseContainerLine(); else m_element = CONTAINERELEMENT_TEST_LOG_DATA; break; } else if (curChar == (int)END_OF_BUFFER) { if (m_elementLen > 0 && m_state == STATE_DATA) m_element = CONTAINERELEMENT_TEST_LOG_DATA; break; } else if (curChar == '\r' || curChar == '\n') { // Check for \r\n int nextChar = getChar(m_elementLen); if (curChar == '\n' || (nextChar != (int)END_OF_BUFFER && nextChar != '\n')) { if (m_state == STATE_CONTAINER_LINE) parseContainerLine(); else m_element = CONTAINERELEMENT_TEST_LOG_DATA; m_state = STATE_AT_LINE_START; break; } // else handle following end or \n in next iteration. } else if (m_state == STATE_AT_LINE_START) { DE_ASSERT(m_elementLen == 1); m_state = (curChar == '#') ? STATE_CONTAINER_LINE : STATE_DATA; } } }
void deSemaphore_decrement (deSemaphore semaphore) { sem_t* sem = ((NamedSemaphore*)semaphore)->semaphore; int res = sem_wait(sem); DE_ASSERT(res == 0); DE_UNREF(res); }
deBool qpTestLog_endSampleList (qpTestLog* log) { DE_ASSERT(log); deMutex_lock(log->lock); if (!qpXmlWriter_endElement(log->writer, "SampleList")) { qpPrintf("qpTestLog_endSampleList(): Writing XML failed\n"); deMutex_unlock(log->lock); return DE_FALSE; } DE_ASSERT(ContainerStack_pop(&log->containerStack) == CONTAINERTYPE_SAMPLELIST); deMutex_unlock(log->lock); return DE_TRUE; }
deBool qpTestLog_startSampleInfo (qpTestLog* log) { DE_ASSERT(log); deMutex_lock(log->lock); if (!qpXmlWriter_startElement(log->writer, "SampleInfo", 0, DE_NULL)) { qpPrintf("qpTestLog_startSampleInfo(): Writing XML failed\n"); deMutex_unlock(log->lock); return DE_FALSE; } DE_ASSERT(ContainerStack_push(&log->containerStack, CONTAINERTYPE_SAMPLEINFO)); deMutex_unlock(log->lock); return DE_TRUE; }