void setup_test() { bool ok; psoObjectDefinition def = { PSO_QUEUE, 0, 0, PSO_DEF_USER_DEFINED, 0, '\0' }; char * data = "My Data"; pQueue = initQueueTest( &context ); psonTxStatusInit( &status, SET_OFFSET(context.pBaseAddress, context.pTransaction), &context ); psonTreeNodeInit( &queueNode, SET_OFFSET(context.pBaseAddress, pQueue ), PSO_QUEUE, SET_OFFSET(context.pBaseAddress, &status), PSON_NULL_OFFSET, &context ); ok = psonQueueInit( pQueue, 0, 1, &queueNode, &def, &context ); assert( ok ); ok = psonQueueInsert( pQueue, data, 8, PSON_QUEUE_FIRST, &context ); assert( ok ); ok = psonQueueGetFirst( pQueue, &pItem, 20, &context ); assert( ok ); ok = psonQueueRelease( pQueue, pItem, &context ); assert( ok ); }
/* * change object position and update references * XXX this one is never used! */ static void heap_move(struct dn_heap *h, uint64_t new_key, void *object) { int temp, i, max = h->elements-1; struct dn_heap_entry *p, buf; if (h->ofs <= 0) panic("cannot move items on this heap"); p = h->p; /* shortcut */ i = *((int *)((char *)object + h->ofs)); if (DN_KEY_LT(new_key, p[i].key) ) { /* must move up */ p[i].key = new_key; for (; i>0 && DN_KEY_LT(new_key, p[(temp = HEAP_FATHER(i))].key); i = temp ) { /* bubble up */ HEAP_SWAP(p[i], p[temp], buf); SET_OFFSET(h, i); } } else { /* must move down */ p[i].key = new_key; while ( (temp = HEAP_LEFT(i)) <= max ) { /* found left child */ if (temp != max && DN_KEY_LT(p[temp+1].key, p[temp].key)) temp++; /* select child with min key */ if (DN_KEY_LT(>p[temp].key, new_key)) { /* go down */ HEAP_SWAP(p[i], p[temp], buf); SET_OFFSET(h, i); } else break; i = temp; } }
void test_pass( void ** state ) { #if defined(PSO_UNIT_TESTS) psonBlockGroupInit( pGroup, SET_OFFSET(context.pBaseAddress, ptr), 10, PSON_IDENT_QUEUE, &context ); assert_true( pGroup->node.nextOffset == PSON_NULL_OFFSET ); assert_true( pGroup->node.previousOffset == PSON_NULL_OFFSET ); assert_true( pGroup->numBlocks == 10 ); assert_true( pGroup->maxFreeBytes >= 9*PSON_BLOCK_SIZE && pGroup->maxFreeBytes < 10*PSON_BLOCK_SIZE ); assert_true( pGroup->freeList.initialized == PSON_LIST_SIGNATURE ); assert_false( pGroup->isDeletable ); assert_true( pGroup->bitmap.baseAddressOffset == SET_OFFSET(context.pBaseAddress, ptr) ); psonBlockGroupFini( pGroup, &context ); /* A zero offset this time */ pGroup = (psonBlockGroup*) ptr; psonBlockGroupInit( pGroup, SET_OFFSET(context.pBaseAddress, ptr), 10, PSON_IDENT_QUEUE, &context ); assert_true( pGroup->isDeletable ); psonBlockGroupFini( pGroup, &context ); #endif return; }
int heap_insert(struct dn_heap *h, uint64_t key1, void *p) { int son = h->elements; //log("%s key %llu p %p\n", __FUNCTION__, key1, p); if (p == NULL) { /* data already there, set starting point */ son = key1; } else { /* insert new element at the end, possibly resize */ son = h->elements; if (son == h->size) /* need resize... */ // XXX expand by 16 or so if (heap_resize(h, h->elements+16) ) return 1; /* failure... */ h->p[son].object = p; h->p[son].key = key1; h->elements++; } /* make sure that son >= father along the path */ while (son > 0) { int father = HEAP_FATHER(son); struct dn_heap_entry tmp; if (DN_KEY_LT( h->p[father].key, h->p[son].key ) ) break; /* found right position */ /* son smaller than father, swap and repeat */ HEAP_SWAP(h->p[son], h->p[father], tmp); SET_OFFSET(h, son); son = father; } SET_OFFSET(h, son); return 0; }
int main() { psonHashMap * pHashMap; psonSessionContext context; bool ok; psonTxStatus status; psoObjectDefinition def = { PSO_HASH_MAP, 0, 0, 0 }; psonKeyDefinition keyDef; psonDataDefinition fields; pHashMap = initHashMapTest( expectedToPass, &context ); psonTxStatusInit( &status, SET_OFFSET( context.pTransaction ) ); ok = psonHashMapInit( pHashMap, 0, 1, 0, &status, 4, "Map1", SET_OFFSET(pHashMap), &def, &keyDef, &fields, &context ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &context.errorHandler, ; );
void setup_test() { bool ok; char * ptr; psoObjectDefinition def = { PSO_HASH_MAP, 0, 0, PSO_DEF_USER_DEFINED, 0, '\0' }; psoKeyDefinition keyDef = { PSO_DEF_USER_DEFINED, 0, '\0' }; pHashMap = initHashMapTest( &context ); psonTxStatusInit( &status, SET_OFFSET(context.pBaseAddress, context.pTransaction), &context ); psonTreeNodeInit( &mapNode, SET_OFFSET(context.pBaseAddress, pHashMap ), PSO_HASH_MAP, SET_OFFSET(context.pBaseAddress, &status), PSON_NULL_OFFSET, &context ); ok = psonHashMapInit( pHashMap, 0, 1, 0, &mapNode, &def, &keyDef, &context ); assert( ok ); ok = psonHashMapInsert( pHashMap, (const void *) key, 6, (const void *) data, 7, &context ); assert( ok ); }
int main() { psonQueue * pQueue; psonSessionContext context; bool ok; psonTxStatus status; psoObjectDefinition def = { PSO_QUEUE, 0, 0, 0 }; psonDataDefinition fields; pQueue = initQueueTest( expectedToPass, &context ); psonTxStatusInit( &status, SET_OFFSET( context.pTransaction ) ); ok = psonQueueInit( pQueue, 0, 1, &status, 6, "Queue1", SET_OFFSET(pQueue), &def, &fields, &context ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &context.errorHandler, ; );
int main() { #if defined(USE_DBC) psonHashMap * pHashMap; psonSessionContext context; int errcode; psonTxStatus status; psoObjectDefinition def = { PSO_HASH_MAP, 0, 0, 0 }; psonKeyDefinition keyDef; psonDataDefinition fields; pHashMap = initHashMapTest( expectedToPass, &context ); psonTxStatusInit( &status, SET_OFFSET( context.pTransaction ) ); errcode = psonHashMapInit( NULL, /* NULL hashmap */ 0, 1, 0, &status, 4, "Map1", SET_OFFSET(pHashMap), &def, &keyDef, &fields, &context ); ERROR_EXIT( expectedToPass, &context.errorHandler, ; );
void setup_test() { bool ok; psoObjectDefinition mapDef = { PSO_FAST_MAP, 0, 0, PSO_DEF_USER_DEFINED, 0, '\0' }; psoKeyDefinition key = { PSO_DEF_USER_DEFINED, 0, '\0' }; pFolder = initFolderTest( &context ); psonTxStatusInit( &status, SET_OFFSET(context.pBaseAddress, context.pTransaction), &context ); psonTreeNodeInit( &node, SET_OFFSET(context.pBaseAddress, pFolder), PSO_FOLDER, SET_OFFSET(context.pBaseAddress, &status), PSON_NULL_OFFSET, &context ); ok = psonFolderInit( pFolder, 0, 1, 0, &node, &context ); assert( ok ); ok = psonFolderInsertMap( pFolder, "test2", 5, &mapDef, &key, 1, 0, &context ); assert( ok ); ok = psonFolderEditObject( pFolder, "test2", 5, PSO_FAST_MAP, &folderItem, &context ); assert( ok ); }
int main() { psonFastMap * pHashMap; psonSessionContext context; bool ok; int errcode; psonTxStatus status; char * key1 = "my key1"; char * key2 = "my key2"; char * data1 = "my data1"; char * data2 = "my data2"; psonFastMapItem item; psoObjectDefinition def = { PSO_FAST_MAP, 0, 0, 0 }; psonKeyDefinition keyDef; psonDataDefinition fields; pHashMap = initHashMapTest( expectedToPass, &context ); psonTxStatusInit( &status, SET_OFFSET( context.pTransaction ) ); ok = psonFastMapInit( pHashMap, 0, 1, 0, &status, 4, "Map1", SET_OFFSET(pHashMap), &def, &keyDef, &fields, &context ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &context.errorHandler, ; );
int main() { #if defined(USE_DBC) psonQueue * pQueue; psonSessionContext context; psonTxStatus status; psoObjectDefinition def = { PSO_QUEUE, 0, 0, 0 }; psonDataDefinition fields; pQueue = initQueueTest( expectedToPass, &context ); psonTxStatusInit( &status, SET_OFFSET( context.pTransaction ) ); psonQueueInit( pQueue, PSON_NULL_OFFSET, 1, &status, 6, "Queue1", SET_OFFSET(pQueue), &def, &fields, &context ); ERROR_EXIT( expectedToPass, NULL, ; );
void test_pass( void ** state ) { #if defined(PSO_UNIT_TESTS) psonQueueCommitAdd( pQueue, SET_OFFSET(context.pBaseAddress, pItem ), &context ); #endif return; }
void test_null_queue( void ** state ) { #if defined(PSO_UNIT_TESTS) expect_assert_failure( psonQueueCommitAdd( NULL, SET_OFFSET(context.pBaseAddress, pItem ), &context ) ); #endif return; }
void psonTreeNodeDump( psonTreeNode * pNode, int indent, psonSessionContext * pContext ) { DO_INDENT( pContext, indent ); fprintf( pContext->tracefp, "psonTreeNode (%p) offset = "PSO_PTRDIFF_T_FORMAT"\n", pNode, SET_OFFSET(pContext->pBaseAddress, pNode) ); if ( pNode == NULL ) return; DO_INDENT( pContext, indent + 2 ); fprintf( pContext->tracefp, "offset of the object: "PSO_PTRDIFF_T_FORMAT"\n", pNode->offset ); if ( pNode->apiType < PSO_FOLDER || pNode->apiType >= PSO_LAST_OBJECT_TYPE ) { DO_INDENT( pContext, indent + 2 ); fprintf( pContext->tracefp, "object api type: unknown (value: %d)\n", pNode->apiType ); } else { DO_INDENT( pContext, indent + 2 ); fprintf( pContext->tracefp, "object api type: %s\n", apiTypes[pNode->apiType-1] ); } DO_INDENT( pContext, indent + 2 ); fprintf( pContext->tracefp, "tx counter: %d\n", pNode->txCounter ); DO_INDENT( pContext, indent + 2 ); fprintf( pContext->tracefp, "offset of the tx status object: "PSO_PTRDIFF_T_FORMAT"\n", pNode->txStatusOffset ); DO_INDENT( pContext, indent + 2 ); fprintf( pContext->tracefp, "offset of the parent object: "PSO_PTRDIFF_T_FORMAT"\n", pNode->myParentOffset ); DO_INDENT( pContext, indent ); fprintf( pContext->tracefp, "psonTreeNode END\n" ); }
bool psonSetInit( psonSet * pSet, ptrdiff_t parentOffset, size_t numberOfBlocks, psonTreeNode * pSetNode, uint32_t origNameLength, char * origName, ptrdiff_t hashItemOffset, psoObjectDefinition * pDefinition, psonDataDefinition * pDataDefinition, psonSessionContext * pContext ) { psoErrors errcode; PSO_PRE_CONDITION( pSet != NULL ); PSO_PRE_CONDITION( pContext != NULL ); PSO_PRE_CONDITION( pSetNode != NULL ); PSO_PRE_CONDITION( origName != NULL ); PSO_PRE_CONDITION( pDefinition != NULL ); PSO_PRE_CONDITION( pDataDefinition != NULL ); PSO_PRE_CONDITION( hashItemOffset != PSON_NULL_OFFSET ); PSO_PRE_CONDITION( parentOffset != PSON_NULL_OFFSET ); PSO_PRE_CONDITION( numberOfBlocks > 0 ); PSO_PRE_CONDITION( origNameLength > 0 ); PSO_TRACE_ENTER_NUCLEUS( pContext ); errcode = psonMemObjectInit( &pSet->memObject, PSON_IDENT_QUEUE, &pSet->blockGroup, numberOfBlocks, pContext ); if ( errcode != PSO_OK ) { psocSetError( &pContext->errorHandler, g_psoErrorHandle, errcode ); PSO_TRACE_EXIT_NUCLEUS( pContext, false ); return false; } pSet->nodeOffset = SET_OFFSET(pContext->pBaseAddress, pSetNode ); psonLinkedListInit( &pSet->listOfElements, pContext ); pSet->dataDefOffset = SET_OFFSET(pContext->pBaseAddress, pDataDefinition); PSO_TRACE_EXIT_NUCLEUS( pContext, true ); return true; }
/* * Remove the top element, or object. */ int fr_heap_extract(fr_heap_t *hp, void *data) { int child, parent; int max; if (!hp || (hp->num_elements == 0)) return 0; max = hp->num_elements - 1; /* * Extract element. Default is the first one. */ if (!data) { parent = 0; } else { /* extract from the middle */ if (!hp->offset) return 0; parent = *((int *)(((uint8_t *)data) + hp->offset)); /* * Out of bounds. */ if (parent < 0 || parent >= hp->num_elements) return 0; } RESET_OFFSET(hp, parent); child = HEAP_LEFT(parent); while (child <= max) { /* * Maybe take the right child. */ if ((child != max) && (hp->cmp(hp->p[child + 1], hp->p[child]) < 0)) { child = child + 1; } hp->p[parent] = hp->p[child]; SET_OFFSET(hp, parent); parent = child; child = HEAP_LEFT(child); } hp->num_elements--; /* * We didn't end up at the last element in the heap. * This element has to be re-inserted. */ if (parent != max) { /* * Fill hole with last entry and bubble up, * reusing the insert code */ hp->p[parent] = hp->p[max]; return fr_heap_bubble(hp, parent); } return 1; }
void setup_test() { bool ok; psoObjectDefinition def = { PSO_HASH_MAP, 0, 0, PSO_DEF_USER_DEFINED, 0, '\0' }; psoKeyDefinition keyDef = { PSO_DEF_USER_DEFINED, 0, '\0' }; pHashMap = initHashMapTest( &context ); psonTxStatusInit( &status, SET_OFFSET(context.pBaseAddress, context.pTransaction), &context ); psonTreeNodeInit( &mapNode, SET_OFFSET(context.pBaseAddress, pHashMap ), PSO_HASH_MAP, SET_OFFSET(context.pBaseAddress, &status ), PSON_NULL_OFFSET, &context ); ok = psonHashMapInit( pHashMap, 0, 1, 0, &mapNode, &def, &keyDef, &context ); assert( ok ); ok = psonHashMapInsert( pHashMap, (const void *) key, 6, (const void *) data, 7, &context ); assert( ok ); /* * We use get to get to the hash item in order to commit it * (we need to commit the insertion before deleting it) */ ok = psonHashMapGet( pHashMap, (const void *) key, 6, &pItem, 20, &context ); assert( ok ); psonHashMapCommitAdd( pHashMap, SET_OFFSET(context.pBaseAddress, pItem), &context ); ok = psonHashMapRelease( pHashMap, pItem, &context ); assert( ok ); }
void test_pass( void ** state ) { #if defined(PSO_UNIT_TESTS) psonHashMapCommitRemove( pHashMap, SET_OFFSET(context.pBaseAddress, pItem ), &context ); #endif return; }
void test_null_context( void ** state ) { #if defined(PSO_UNIT_TESTS) expect_assert_failure( psonHashMapCommitRemove( pHashMap, SET_OFFSET(context.pBaseAddress, pItem ), NULL ) ); #endif return; }
void setup_test() { bool ok; psoObjectDefinition def = { PSO_FOLDER, 0, 0 }; pFolder = initFolderTest( &context ); psonTxStatusInit( &status, SET_OFFSET(context.pBaseAddress, context.pTransaction), &context ); psonTreeNodeInit( &node, SET_OFFSET(context.pBaseAddress, pFolder), PSO_FOLDER, SET_OFFSET(context.pBaseAddress, &status), PSON_NULL_OFFSET, &context ); ok = psonFolderInit( pFolder, 0, 1, 0, &node, &context ); assert( ok ); ok = psonFolderInsertFolder( pFolder, "test2", 5, &context ); assert( ok ); }
void test_invalid_type( void ** state ) { #if defined(PSO_UNIT_TESTS) expect_assert_failure( psonBlockGroupInit( pGroup, SET_OFFSET(context.pBaseAddress, ptr), 10, (psonMemObjIdent)(PSON_IDENT_LAST+200), &context ) ); #endif return; }
void test_null_group( void ** state ) { #if defined(PSO_UNIT_TESTS) expect_assert_failure( psonBlockGroupInit( NULL, SET_OFFSET(context.pBaseAddress, ptr), 10, PSON_IDENT_QUEUE, &context ) ); #endif return; }
void psonLinkedListReset( psonLinkedList* pList ) { PSO_PRE_CONDITION( pList != NULL ); /* Test to see if the list is initialized */ PSO_INV_CONDITION( pList->initialized == PSON_LIST_SIGNATURE ); pList->currentSize = 0; /* Make the list circular by pointing it back to itself. */ pList->head.previousOffset = pList->head.nextOffset = SET_OFFSET( &pList->head ); }
void psonLinkedListInit( psonLinkedList* pList ) { PSO_PRE_CONDITION( pList != NULL ); psonLinkNodeInit( &pList->head ); pList->currentSize = 0; /* Make the list circular by pointing it back to itself. */ pList->head.previousOffset = pList->head.nextOffset = SET_OFFSET( &pList->head ); pList->initialized = PSON_LIST_SIGNATURE; }
int main() { psonFolder* pFolder; psonSessionContext context; bool ok; psonTxStatus status; pFolder = initFolderTest( expectedToPass, &context ); psonTxStatusInit( &status, SET_OFFSET( context.pTransaction ) ); ok = psonFolderInit( pFolder, 0, 1, 0, &status, 5, "Test1", 1234, &context ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &context.errorHandler, ; );
int main() { #if defined(USE_DBC) psonFastMap * pHashMap; psonSessionContext context; bool ok; psonTxStatus txStatus; char * key = "my key"; char * data = "my data"; psoObjStatus status; psoObjectDefinition def = { PSO_FAST_MAP, 0, 0, 0 }; psonKeyDefinition keyDef; psonDataDefinition fields; pHashMap = initHashMapTest( expectedToPass, &context ); psonTxStatusInit( &txStatus, SET_OFFSET( context.pTransaction ) ); ok = psonFastMapInit( pHashMap, 0, 1, 0, &txStatus, 4, "Map1", SET_OFFSET(pHashMap), &def, &keyDef, &fields, &context ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &context.errorHandler, ; );
int main() { #if defined(USE_DBC) psonFolder* pFolder; psonSessionContext context; psonTxStatus status; pFolder = initFolderTest( expectedToPass, &context ); psonTxStatusInit( &status, SET_OFFSET( context.pTransaction ) ); psonFolderInit( pFolder, 0, 1, 0, &status, 0, "Test1", 1234, &context ); ERROR_EXIT( expectedToPass, NULL, ; );
void setup_test() { bool ok; char * key = "my key"; char * data = "my data"; psoObjectDefinition def = { PSO_FAST_MAP, 0, 0, PSO_DEF_USER_DEFINED, 0, '\0' }; psoKeyDefinition keyDef = { PSO_DEF_USER_DEFINED, 0, '\0' }; pHashMap = initHashMapTest( &context ); assert( pHashMap ); psonTxStatusInit( &status, SET_OFFSET(context.pBaseAddress, context.pTransaction ), &context ); psonTreeNodeInit( &mapNode, SET_OFFSET(context.pBaseAddress, pHashMap ), PSO_FAST_MAP, SET_OFFSET(context.pBaseAddress, &status ), PSON_NULL_OFFSET, &context ); ok = psonFastMapInit( pHashMap, 0, 1, 0, &mapNode, SET_OFFSET(context.pBaseAddress, pHashMap), &def, &keyDef, &context ); assert( ok ); ok = psonFastMapInsert( pHashMap, (const void *) key, 6, (const void *) data, 7, &context ); assert( ok ); ok = psonFastMapGet( pHashMap, (const void *) key, 6, &pItem, 20, &context ); assert( ok ); assert( status.usageCounter == 1 ); }
void setup_test() { bool ok; psoObjectDefinition def = { PSO_QUEUE, 0, 0, PSO_DEF_USER_DEFINED, 0, '\0' }; char * data = "My Data"; pQueue = initQueueTest( &context ); psonTxStatusInit( &status, SET_OFFSET(context.pBaseAddress, context.pTransaction), &context ); psonTreeNodeInit( &queueNode, SET_OFFSET(context.pBaseAddress, pQueue ), PSO_QUEUE, SET_OFFSET(context.pBaseAddress, &status), PSON_NULL_OFFSET, &context ); ok = psonQueueInit( pQueue, 0, 1, &queueNode, &def, &context ); assert( ok ); ok = psonQueueInsert( pQueue, data, 8, PSON_QUEUE_FIRST, &context ); assert( ok ); ok = psonQueueInsert( pQueue, data, 6, PSON_QUEUE_LAST, &context ); assert( ok ); ok = psonQueueGetFirst( pQueue, &pQueueItem, 100, &context ); assert( ok ); /* Must commit the insert before we attempt to remove */ psonQueueCommitAdd( pQueue, SET_OFFSET(context.pBaseAddress, pQueueItem), &context ); }
static int fr_heap_bubble(fr_heap_t *hp, int child) { /* * Bubble up the element. */ while (child > 0) { int parent = HEAP_PARENT(child); /* * Parent is smaller than the child. We're done. */ if (hp->cmp(hp->p[parent], hp->p[child]) < 0) break; /* * Child is smaller than the parent, repeat. */ HEAP_SWAP(hp->p[child], hp->p[parent]); SET_OFFSET(hp, child); child = parent; } SET_OFFSET(hp, child); return 1; }