diff --git a/src/os/shared/inc/os-shared-file.h b/src/os/shared/inc/os-shared-file.h index fcadb2c40..909bf335c 100644 --- a/src/os/shared/inc/os-shared-file.h +++ b/src/os/shared/inc/os-shared-file.h @@ -183,4 +183,13 @@ int32 OS_FileRename_Impl(const char *old_path, const char *new_path); ------------------------------------------------------------------*/ int32 OS_FileChmod_Impl(const char *local_path, uint32 access); -#endif /* OS_SHARED_FILE_H */ + +/* + * Internal helper function + * + * Not called outside this unit, but need to be prototyped + * here for coverage test. + */ +int32 OS_FileIteratorClose(osal_id_t filedes, void *arg); + +#endif /* OS_SHARED_FILE_H */ diff --git a/src/os/shared/inc/os-shared-filesys.h b/src/os/shared/inc/os-shared-filesys.h index 717699f1f..b16a3765e 100644 --- a/src/os/shared/inc/os-shared-filesys.h +++ b/src/os/shared/inc/os-shared-filesys.h @@ -190,5 +190,6 @@ int32 OS_FileSysUnmountVolume_Impl(const OS_object_token_t *token); bool OS_FileSys_FindVirtMountPoint(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fsvolname, size_t blocksize, osal_blockcount_t numblocks, bool should_format); +bool OS_FileSysFilterFree(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); -#endif /* OS_SHARED_FILESYS_H */ +#endif /* OS_SHARED_FILESYS_H */ diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-dirs.c b/src/unit-test-coverage/portable/src/coveragetest-posix-dirs.c index 371e3b254..17d581fcd 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-posix-dirs.c +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-dirs.c @@ -32,7 +32,9 @@ #include #include #include +#include #include +#include void Test_OS_DirCreate_Impl(void) { @@ -40,10 +42,22 @@ void Test_OS_DirCreate_Impl(void) * Test Case For: * int32 OS_DirCreate_Impl(const char *local_path, uint32 access) */ + struct OCS_stat statbuf; + OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl, ("dir", 0), OS_SUCCESS); + /* With errno other than EEXIST it should return OS_ERROR */ + OCS_errno = OCS_EROFS; UT_SetDefaultReturnValue(UT_KEY(OCS_mkdir), -1); OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl, ("dir", 0), OS_ERROR); + + /* If the errno is EEXIST it should return success */ + OCS_errno = OCS_EEXIST; + memset(&statbuf, 0, sizeof(statbuf)); + statbuf.st_mode = OCS_S_IFDIR; + UT_SetDataBuffer(UT_KEY(OCS_stat), &statbuf, sizeof(statbuf), false); + UT_SetDefaultReturnValue(UT_KEY(OCS_mkdir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl, ("dir", 0), OS_SUCCESS); } void Test_OS_DirOpen_Impl(void) diff --git a/src/unit-test-coverage/shared/src/coveragetest-common.c b/src/unit-test-coverage/shared/src/coveragetest-common.c index a8c3d8706..f760641bd 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-common.c +++ b/src/unit-test-coverage/shared/src/coveragetest-common.c @@ -57,9 +57,9 @@ static int32 TimeBaseInitGlobal(void *UserObj, int32 StubRetcode, uint32 CallCou static int32 ObjectDeleteCountHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) { - uint32 *counter = (uint32 *)Context->ArgPtr[1]; + uint32 *counter = UT_Hook_GetArgValueByName(Context, "callback_arg", uint32 *); - if (CallCount == 0) + if (CallCount < 2) { *counter = 1; } @@ -77,6 +77,11 @@ static int32 SetShutdownFlagHook(void *UserObj, int32 StubRetcode, uint32 CallCo return StubRetcode; } +static int32 TestEventHandlerHook(OS_Event_t event, osal_id_t object_id, void *data) +{ + return UT_DEFAULT_IMPL(TestEventHandlerHook); +} + /* ********************************************************************************** ** PUBLIC API FUNCTIONS @@ -258,6 +263,37 @@ void Test_OS_IdleLoopAndShutdown(void) UtAssert_True(CallCount == 1, "OS_ApplicationShutdown_Impl() call count (%lu) == 1", (unsigned long)CallCount); } +void Test_OS_NotifyEvent(void) +{ + /* + * Test cases for: + * int32 OS_NotifyEvent(OS_Event_t event, osal_id_t object_id, void *data) + * int32 OS_RegisterEventHandler(OS_EventHandler_t handler) + */ + + OS_SharedGlobalVars.EventHandler = NULL; + + /* With no hook function registered OS_NotifyEvent() should return success */ + OSAPI_TEST_FUNCTION_RC(OS_NotifyEvent(OS_EVENT_RESERVED, OS_OBJECT_ID_UNDEFINED, NULL), OS_SUCCESS); + + /* Registering a NULL hook function should fail */ + OSAPI_TEST_FUNCTION_RC(OS_RegisterEventHandler(NULL), OS_INVALID_POINTER); + + /* Now Register the locally-defined hook function */ + OSAPI_TEST_FUNCTION_RC(OS_RegisterEventHandler(TestEventHandlerHook), OS_SUCCESS); + + /* Now this should invoke the test hook */ + OSAPI_TEST_FUNCTION_RC(OS_NotifyEvent(OS_EVENT_RESERVED, OS_OBJECT_ID_UNDEFINED, NULL), OS_SUCCESS); + UtAssert_STUB_COUNT(TestEventHandlerHook, 1); + + /* Should also return whatever the hook returned */ + UT_SetDefaultReturnValue(UT_KEY(TestEventHandlerHook), -12345); + OSAPI_TEST_FUNCTION_RC(OS_NotifyEvent(OS_EVENT_RESERVED, OS_OBJECT_ID_UNDEFINED, NULL), -12345); + UtAssert_STUB_COUNT(TestEventHandlerHook, 2); + + OS_SharedGlobalVars.EventHandler = NULL; +} + /* ------------------- End of test cases --------------------------------------*/ /* Osapi_Test_Setup @@ -288,4 +324,5 @@ void UtTest_Setup(void) ADD_TEST(OS_CleanUpObject); ADD_TEST(OS_IdleLoopAndShutdown); ADD_TEST(OS_ApplicationExit); + ADD_TEST(OS_NotifyEvent); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-file.c b/src/unit-test-coverage/shared/src/coveragetest-file.c index 4292c5497..e064ead1b 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-file.c +++ b/src/unit-test-coverage/shared/src/coveragetest-file.c @@ -386,6 +386,13 @@ void Test_OS_CloseAllFiles(void) actual = OS_CloseAllFiles(); UtAssert_True(actual == expected, "OS_CloseAllFiles() (%ld) == -222", (long)actual); + + /* This uses a helper function OS_FileIteratorClose() with the iterator, + * which needs to be called for coverage - it just invokes OS_close() */ + expected = OS_SUCCESS; + actual = OS_FileIteratorClose(UT_OBJID_1, NULL); + + UtAssert_True(actual == expected, "OS_FileIteratorClose() (%ld) == OS_SUCCESS", (long)actual); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 6d3c7191b..96854d2cf 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -451,9 +451,10 @@ void Test_OS_GetFsInfo(void) * Test Case For: * int32 OS_GetFsInfo(OS_FsInfo_t *filesys_info) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - os_fsinfo_t filesys_info; + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + os_fsinfo_t filesys_info; + OS_common_record_t rec; UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdIteratorGetNext), 1); UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdIteratorGetNext), 3, 0); @@ -469,15 +470,21 @@ void Test_OS_GetFsInfo(void) "filesys_info.MaxVolumes (%lu) == OS_MAX_FILE_SYSTEMS", (unsigned long)filesys_info.MaxVolumes); /* since there are no open files, the free fd count should match the max */ - UtAssert_True(filesys_info.FreeFds == 2, "filesys_info.FreeFds (%lu) == 2", - (unsigned long)filesys_info.FreeFds); + UtAssert_True(filesys_info.FreeFds == 2, "filesys_info.FreeFds (%lu) == 2", (unsigned long)filesys_info.FreeFds); UtAssert_True(filesys_info.FreeVolumes == 3, "filesys_info.FreeVolumes (%lu) == 3", - (unsigned long)filesys_info.FreeVolumes); + (unsigned long)filesys_info.FreeVolumes); expected = OS_INVALID_POINTER; actual = OS_GetFsInfo(NULL); UtAssert_True(actual == expected, "OS_GetFsInfo() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* This function uses a helper OS_FileSysFilterFree() that needs to be called for coverage. */ + /* It is just a wrapper around OS_ObjectIdDefined() for the record ID */ + memset(&rec, 0, sizeof(rec)); + UtAssert_True(OS_FileSysFilterFree(NULL, NULL, &rec), "OS_FileSysFilterFree() (unused record)"); + rec.active_id = UT_OBJID_1; + UtAssert_True(!OS_FileSysFilterFree(NULL, NULL, &rec), "!OS_FileSysFilterFree() (used record)"); } void Test_OS_TranslatePath(void) diff --git a/src/unit-test-coverage/shared/src/coveragetest-module.c b/src/unit-test-coverage/shared/src/coveragetest-module.c index 043ebeb36..2552626bb 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-module.c +++ b/src/unit-test-coverage/shared/src/coveragetest-module.c @@ -158,6 +158,44 @@ void Test_OS_SymbolLookup(void) UtAssert_True(actual == expected, "OS_SymbolLookup(UT_staticsym) (%ld) == OS_SUCCESS", (long)actual); } +void Test_OS_ModuleSymbolLookup(void) +{ + /* + * Test Case For: + * int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const char *symbol_name) + */ + int32 expected = OS_SUCCESS; + int32 actual = ~OS_SUCCESS; + cpuaddr testaddr = 0; + cpuaddr symaddr = 0; + + actual = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symaddr, "uttestsym0"); + UtAssert_True(actual == expected, "OS_ModuleSymbolLookup(name=%s) (%ld) == OS_SUCCESS", "uttestsym0", (long)actual); + + UT_ResetState(UT_KEY(OS_ModuleSymbolLookup_Impl)); + UT_SetDefaultReturnValue(UT_KEY(OS_ModuleSymbolLookup_Impl), OS_ERROR); + + /* this lookup should always fail */ + symaddr = 0; + testaddr = 0; + actual = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symaddr, "uttestsym1"); + expected = OS_ERROR; + UtAssert_True(actual == expected, "OS_ModuleSymbolLookup(name=%s) (%ld) == OS_ERROR", "uttestsym1", (long)actual); + UtAssert_True(symaddr == testaddr, "OS_ModuleSymbolLookup(address=%lx) == %lx", (unsigned long)symaddr, + (unsigned long)testaddr); + + actual = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, NULL, NULL); + expected = OS_INVALID_POINTER; + UtAssert_True(actual == expected, "OS_ModuleSymbolLookup(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + + /* + * Look up a symbol that is present in the static symbol table + */ + actual = OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symaddr, "UT_staticsym"); + expected = OS_SUCCESS; + UtAssert_True(actual == expected, "OS_ModuleSymbolLookup(UT_staticsym) (%ld) == OS_SUCCESS", (long)actual); +} + void Test_OS_StaticSymbolLookup(void) { /* @@ -190,7 +228,7 @@ void Test_OS_StaticSymbolLookup(void) UtAssert_True(actual == expected, "OS_ModuleLoad_Static(name=%s) (%ld) == OS_SUCCESS", "UT", (long)actual); expected = OS_ERROR; - actual = OS_SymbolLookup_Static(&addr, "UT_staticsym", "NoModuleMatch"); + actual = OS_SymbolLookup_Static(&addr, "UT_staticsym", "NoModuleMatch"); UtAssert_True(actual == expected, "OS_SymbolLookup_Static(name=%s, NoModuleMatch) (%ld) == OS_ERROR", "Test_Func1", (long)actual); UtAssert_True(addr == (cpuaddr)&Test_DummyFunc, "OS_SymbolLookup_Static(address=%lx) == %lx", (unsigned long)addr, @@ -221,6 +259,12 @@ void Test_OS_SymbolTableDump(void) expected = OS_ERROR; actual = OS_SymbolTableDump("test", OSAL_SIZE_C(555)); UtAssert_True(actual == expected, "OS_SymbolTableDump() (%ld) == OS_ERROR", (long)actual); + + UT_ResetState(UT_KEY(OS_TranslatePath)); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdTransactionInit), OS_ERROR); + expected = OS_ERROR; + actual = OS_SymbolTableDump("test", OSAL_SIZE_C(555)); + UtAssert_True(actual == expected, "OS_SymbolTableDump() (%ld) == OS_ERROR", (long)actual); } void Test_OS_ModuleGetInfo(void) @@ -274,6 +318,7 @@ void UtTest_Setup(void) ADD_TEST(OS_ModuleLoad); ADD_TEST(OS_ModuleUnload); ADD_TEST(OS_SymbolLookup); + ADD_TEST(OS_ModuleSymbolLookup); ADD_TEST(OS_ModuleGetInfo); ADD_TEST(OS_SymbolTableDump); ADD_TEST(OS_StaticSymbolLookup); diff --git a/src/unit-test-coverage/shared/src/coveragetest-mutex.c b/src/unit-test-coverage/shared/src/coveragetest-mutex.c index 4c68e64a3..e0c5dd418 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/shared/src/coveragetest-mutex.c @@ -85,12 +85,26 @@ void Test_OS_MutSemGive(void) * Test Case For: * int32 OS_MutSemGive ( uint32 sem_id ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + OS_mutex_internal_record_t *mutex; + int32 expected; + int32 actual; - actual = OS_MutSemGive(UT_OBJID_1); + expected = OS_SUCCESS; + + /* Set up for "last owner" matching the calling task (nominal) */ + mutex = &OS_mutex_table[1]; + mutex->last_owner = OS_TaskGetId(); + actual = OS_MutSemGive(UT_OBJID_1); UtAssert_True(actual == expected, "OS_MutSemGive() (%ld) == OS_SUCCESS", (long)actual); + + /* owner should be unset */ + UtAssert_True(!OS_ObjectIdDefined(mutex->last_owner), "Mutex owner unset"); + + /* Call again when not "owned". This still works (or at least it calls the OS impl) + * but should generate a debug message */ + actual = OS_MutSemGive(UT_OBJID_1); + UtAssert_True(actual == expected, "OS_MutSemGive(), not owned (%ld) == OS_SUCCESS", (long)actual); } void Test_OS_MutSemTake(void) @@ -99,11 +113,24 @@ void Test_OS_MutSemTake(void) * Test Case For: * int32 OS_MutSemTake ( uint32 sem_id ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + OS_mutex_internal_record_t *mutex; + int32 expected; + int32 actual; - actual = OS_MutSemTake(UT_OBJID_1); + expected = OS_SUCCESS; + /* Set up for "last owner" being undefined (nominal) */ + mutex = &OS_mutex_table[1]; + mutex->last_owner = OS_OBJECT_ID_UNDEFINED; + actual = OS_MutSemTake(UT_OBJID_1); + UtAssert_True(actual == expected, "OS_MutSemTake() (%ld) == OS_SUCCESS", (long)actual); + + /* owner should be set */ + UtAssert_True(OS_ObjectIdDefined(mutex->last_owner), "Mutex owner set"); + + /* Call again when not already "owned". This still works (or at least it calls the OS impl) + * but should generate a debug message */ + actual = OS_MutSemTake(UT_OBJID_1); UtAssert_True(actual == expected, "OS_MutSemTake() (%ld) == OS_SUCCESS", (long)actual); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-queue.c b/src/unit-test-coverage/shared/src/coveragetest-queue.c index ba4387118..397bc1068 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-queue.c +++ b/src/unit-test-coverage/shared/src/coveragetest-queue.c @@ -130,14 +130,20 @@ void Test_OS_QueuePut(void) int32 actual = ~OS_SUCCESS; const char Data[4] = "xyz"; - actual = OS_QueuePut(UT_OBJID_1, Data, sizeof(Data), 0); + OS_queue_table[1].max_depth = 10; + OS_queue_table[1].max_size = sizeof(Data); + actual = OS_QueuePut(UT_OBJID_1, Data, sizeof(Data), 0); UtAssert_True(actual == expected, "OS_QueuePut() (%ld) == OS_SUCCESS", (long)actual); /* test error cases */ expected = OS_INVALID_POINTER; actual = OS_QueuePut(UT_OBJID_1, NULL, sizeof(Data), 0); UtAssert_True(actual == expected, "OS_QueuePut() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_QUEUE_INVALID_SIZE; + actual = OS_QueuePut(UT_OBJID_1, Data, 1 + sizeof(Data), 0); + UtAssert_True(actual == expected, "OS_QueuePut() (%ld) == OS_QUEUE_INVALID_SIZE", (long)actual); } void Test_OS_QueueGetIdByName(void) diff --git a/src/unit-test-coverage/shared/src/coveragetest-time.c b/src/unit-test-coverage/shared/src/coveragetest-time.c index 445714f32..5a61fd999 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-time.c +++ b/src/unit-test-coverage/shared/src/coveragetest-time.c @@ -154,6 +154,14 @@ void Test_OS_TimerCreate(void) actual = OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback); UtAssert_True(actual == expected, "OS_TimerCreate() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); UT_ClearForceFail(UT_KEY(OCS_memchr)); + + /* This function creates its own timebase. If OS_DoTimerAdd() fails this timebase needs to be deleted */ + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + expected = OS_ERROR; + actual = OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback); + UtAssert_True(actual == expected, "OS_TimerCreate() (%ld) == OS_ERROR", (long)actual); + UT_ResetState(UT_KEY(OS_ObjectIdGetById)); + UtAssert_STUB_COUNT(OS_TimeBaseDelete, 1); } void Test_OS_TimerSet(void) @@ -195,35 +203,56 @@ void Test_OS_TimerDelete(void) * Test Case For: * int32 OS_TimerDelete(uint32 timer_id) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_TimerDelete(UT_OBJID_1); - osal_id_t timebase_id; + int32 expected; + int32 actual; + osal_id_t timebase_id; + osal_id_t timer_objid_1, timer_objid_2; + OS_timebase_internal_record_t *timebase; + OS_object_token_t timebase_token; + uint32 accuracy; + + expected = OS_SUCCESS; + + /* The ObjIds in the ring need to match what will be in the token */ + /* Get a "timebase" from the stub so the objid will validate */ + OS_TimeBaseCreate(&timebase_id, "ut", NULL); + OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id, &timebase_token); + timebase = OS_OBJECT_TABLE_GET(OS_timebase_table, timebase_token); + OS_TimerAdd(&timer_objid_1, "UT1", timebase_id, UT_TimerArgCallback, NULL); + OS_TimerAdd(&timer_objid_2, "UT2", timebase_id, UT_TimerArgCallback, NULL); + + /* Sanity check: After adding the two timers the "first_cb" should be pointing at timer 2 */ + UtAssert_True(OS_ObjectIdEqual(timebase->first_cb, timer_objid_2), "First CB at timer 2"); + actual = OS_TimerDelete(timer_objid_2); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); - OS_timecb_table[1].timebase_token.obj_type = OS_OBJECT_TYPE_OS_TIMEBASE; - OS_timecb_table[1].timebase_token.obj_id = UT_OBJID_1; - OS_timecb_table[1].timebase_token.obj_idx = UT_INDEX_0; - OS_timecb_table[2].timebase_token = OS_timecb_table[1].timebase_token; - OS_timecb_table[2].next_cb = UT_OBJID_1; - OS_timecb_table[1].next_cb = UT_OBJID_1; - OS_timebase_table[0].first_cb = UT_OBJID_2; - actual = OS_TimerDelete(UT_OBJID_2); + /* After deleting timer 2 the "first_cb" should be pointing at timer 1 */ + UtAssert_True(OS_ObjectIdEqual(timebase->first_cb, timer_objid_1), "First CB at timer 1"); + + /* Re-add timer 2 again */ + OS_TimerAdd(&timer_objid_2, "UT2", timebase_id, UT_TimerArgCallback, NULL); + + /* Sanity check: the "first_cb" should be pointing at timer 2 again */ + UtAssert_True(OS_ObjectIdEqual(timebase->first_cb, timer_objid_2), "First CB at timer 2"); + + /* delete timer 1 */ + actual = OS_TimerDelete(timer_objid_1); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); - OS_timebase_table[0].first_cb = UT_OBJID_1; - actual = OS_TimerDelete(UT_OBJID_1); + /* The "first_cb" should be still pointing at timer 2 */ + UtAssert_True(OS_ObjectIdEqual(timebase->first_cb, timer_objid_2), "First CB at timer 2"); + + actual = OS_TimerDelete(timer_objid_2); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); + /* The "first_cb" should be undefined */ + UtAssert_True(!OS_ObjectIdDefined(timebase->first_cb), "First CB at OS_OBJECT_ID_UNDEFINED"); + /* verify deletion of the dedicated timebase objects * these are implicitly created as part of timer creation for API compatibility */ - OS_TimeBaseCreate(&timebase_id, "ut", NULL); - OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_TIMECB, UT_INDEX_1); - OS_timecb_table[1].flags = TIMECB_FLAG_DEDICATED_TIMEBASE; - OS_timecb_table[1].timebase_token.obj_type = OS_OBJECT_TYPE_OS_TIMEBASE; - OS_timecb_table[1].timebase_token.obj_id = timebase_id; - OS_timecb_table[1].timebase_token.obj_idx = OS_ObjectIdToInteger(timebase_id) & OS_OBJECT_INDEX_MASK; - actual = OS_TimerDelete(UT_OBJID_1); + OS_TimerCreate(&timer_objid_1, "UT1", &accuracy, UT_TimerCallback); + actual = OS_TimerDelete(timer_objid_1); UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(UT_GetStubCount(UT_KEY(OS_TimeBaseDelete)) == 1, "OS_TimerDelete() invoked OS_TimeBaseDelete()"); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c b/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c index e97635900..946d462d9 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c @@ -62,7 +62,7 @@ void Test_OS_Unlock_Global_Impl(void) UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semGive)) == 1, "semTake() called"); UT_SetDefaultReturnValue(UT_KEY(OCS_semGive), -1); - OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK); /* for coverage of error path */ + OS_Unlock_Global_Impl(OS_OBJECT_TYPE_OS_TASK); /* for coverage of error path */ } void Test_OS_API_Impl_Init(void) @@ -78,6 +78,22 @@ void Test_OS_API_Impl_Init(void) OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TableMutex_Init(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); } +void Test_OS_WaitForStateChange_Impl(void) +{ + /* + * Test Case For: + * void OS_WaitForStateChange_Impl(osal_objtype_t idtype, uint32 attempts) + */ + + /* + * This has no return value/error results - just needs to be called for coverage. + * Call it once with a low number and once with a high number of attempts - + * which should cause it to hit its limit for wait time. + */ + OS_WaitForStateChange_Impl(OS_OBJECT_TYPE_OS_TASK, 1); + OS_WaitForStateChange_Impl(OS_OBJECT_TYPE_OS_TASK, 1000); +} + /* ------------------- End of test cases --------------------------------------*/ /* Osapi_Test_Setup @@ -108,4 +124,5 @@ void UtTest_Setup(void) ADD_TEST(OS_Lock_Global_Impl); ADD_TEST(OS_Unlock_Global_Impl); ADD_TEST(OS_API_Impl_Init); + ADD_TEST(OS_WaitForStateChange_Impl); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c index 7f27a328d..524c9d28e 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c @@ -132,6 +132,18 @@ void Test_OS_TaskDelete_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_TaskDelete_Impl(&token), OS_ERROR); } +void Test_OS_TaskDetach_Impl(void) +{ + /* + * Test Case For: + * int32 OS_TaskDetach_Impl(const OS_object_token_t *token) + */ + OS_object_token_t token; + + /* no-op on VxWorks - always returns sucess */ + OSAPI_TEST_FUNCTION_RC(OS_TaskDetach_Impl(&token), OS_SUCCESS); +} + void Test_OS_TaskExit_Impl(void) { /* @@ -280,6 +292,7 @@ void UtTest_Setup(void) ADD_TEST(OS_VxWorksEntry); ADD_TEST(OS_TaskMatch_Impl); ADD_TEST(OS_TaskDelete_Impl); + ADD_TEST(OS_TaskDetach_Impl); ADD_TEST(OS_TaskExit_Impl); ADD_TEST(OS_TaskDelay_Impl); ADD_TEST(OS_TaskSetPriority_Impl); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c index 2690966e4..2e7f2862c 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c @@ -110,9 +110,15 @@ void Test_OS_TimeBaseCreate_Impl(void) * This should be done first as it will assign the "external_sync" * and therefore cause future calls to skip this block. */ - memset(&id, 0x01, sizeof(id)); + id = OS_ObjectIdFromInteger(OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT); + + OS_global_timebase_table[0].active_id = id; + UT_TimeBaseTest_Setup(UT_INDEX_0, OCS_SIGRTMIN, false); + + id = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(id) + 1); + OS_global_timebase_table[1].active_id = id; - UT_TimeBaseTest_Setup(UT_INDEX_1, OCS_SIGRTMIN, false); + UT_TimeBaseTest_Setup(UT_INDEX_1, 1 + OCS_SIGRTMIN, false); UT_SetDefaultReturnValue(UT_KEY(OCS_sigismember), true); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(&token), OS_TIMER_ERR_UNAVAILABLE); UT_ResetState(UT_KEY(OCS_sigismember)); @@ -158,6 +164,11 @@ void Test_OS_TimeBaseCreate_Impl(void) UT_SetDefaultReturnValue(UT_KEY(OCS_timer_create), -1); UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED); UtAssert_True(UT_TimeBaseTest_CheckTimeBaseErrorState(UT_INDEX_0), "timer registration failure state"); + + UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED); + UtAssert_True(!UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0), "timer registration bad ID"); } void Test_OS_VxWorks_SigWait(void) diff --git a/src/ut-stubs/osapi-utstub-binsem.c b/src/ut-stubs/osapi-utstub-binsem.c index e85d4559e..3b7fd4da3 100644 --- a/src/ut-stubs/osapi-utstub-binsem.c +++ b/src/ut-stubs/osapi-utstub-binsem.c @@ -131,7 +131,7 @@ int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initia if (status == OS_SUCCESS) { - *sem_id = UT_AllocStubObjId(UT_OBJTYPE_BINSEM); + *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_BINSEM); } else { @@ -196,7 +196,7 @@ int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_BinSemGetInfo), bin_prop, sizeof(*bin_prop)) < sizeof(*bin_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &bin_prop->creator); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &bin_prop->creator); strncpy(bin_prop->name, "Name", OS_MAX_API_NAME - 1); bin_prop->name[OS_MAX_API_NAME - 1] = '\0'; } @@ -234,7 +234,7 @@ int32 OS_BinSemDelete(osal_id_t sem_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_BINSEM, sem_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_BINSEM, sem_id); } return status; @@ -288,7 +288,7 @@ int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_BinSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_BINSEM, sem_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_BINSEM, sem_id); } return status; diff --git a/src/ut-stubs/osapi-utstub-countsem.c b/src/ut-stubs/osapi-utstub-countsem.c index f4c4d3934..602af87f8 100644 --- a/src/ut-stubs/osapi-utstub-countsem.c +++ b/src/ut-stubs/osapi-utstub-countsem.c @@ -55,7 +55,7 @@ int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_init if (status == OS_SUCCESS) { - *sem_id = UT_AllocStubObjId(UT_OBJTYPE_COUNTSEM); + *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_COUNTSEM); } else { @@ -95,7 +95,7 @@ int32 OS_CountSemDelete(osal_id_t sem_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_COUNTSEM, sem_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_COUNTSEM, sem_id); } return status; @@ -167,7 +167,7 @@ int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_CountSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_COUNTSEM, sem_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_COUNTSEM, sem_id); } return status; @@ -201,7 +201,7 @@ int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_CountSemGetInfo), count_prop, sizeof(*count_prop)) < sizeof(*count_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &count_prop->creator); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &count_prop->creator); strncpy(count_prop->name, "Name", OS_MAX_API_NAME - 1); count_prop->name[OS_MAX_API_NAME - 1] = '\0'; } diff --git a/src/ut-stubs/osapi-utstub-dir.c b/src/ut-stubs/osapi-utstub-dir.c index 7f53306e8..43ad38760 100644 --- a/src/ut-stubs/osapi-utstub-dir.c +++ b/src/ut-stubs/osapi-utstub-dir.c @@ -86,7 +86,7 @@ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path) if (Status == OS_SUCCESS) { - *dir_id = UT_AllocStubObjId(UT_OBJTYPE_DIR); + *dir_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_DIR); } else { @@ -111,7 +111,7 @@ int32 OS_DirectoryClose(osal_id_t dir_id) if (Status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_DIR, dir_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_DIR, dir_id); } return Status; diff --git a/src/ut-stubs/osapi-utstub-file.c b/src/ut-stubs/osapi-utstub-file.c index 6efd2913f..29a73f4c6 100644 --- a/src/ut-stubs/osapi-utstub-file.c +++ b/src/ut-stubs/osapi-utstub-file.c @@ -126,7 +126,7 @@ int32 OS_creat(const char *path, int32 access) if (status == OS_SUCCESS) { - objid = UT_AllocStubObjId(UT_OBJTYPE_FILESTREAM); + objid = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); status = OS_ObjectIdToInteger(objid); } @@ -150,7 +150,7 @@ int32 OS_open(const char *path, int32 access, uint32 mode) if (status == OS_SUCCESS) { - objid = UT_AllocStubObjId(UT_OBJTYPE_FILESTREAM); + objid = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); status = OS_ObjectIdToInteger(objid); } @@ -175,7 +175,7 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc status = UT_DEFAULT_IMPL(OS_OpenCreate); if (status == OS_SUCCESS) { - *filedes = UT_AllocStubObjId(UT_OBJTYPE_FILESTREAM); + *filedes = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); } else { @@ -200,7 +200,7 @@ int32 OS_close(osal_id_t filedes) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_FILESTREAM, filedes); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_STREAM, filedes); } return status; @@ -430,7 +430,7 @@ int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop) { memset(fd_prop, 0, sizeof(*fd_prop)); fd_prop->IsValid = true; - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &fd_prop->User); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &fd_prop->User); } } diff --git a/src/ut-stubs/osapi-utstub-filesys.c b/src/ut-stubs/osapi-utstub-filesys.c index b696751e5..43c9003c7 100644 --- a/src/ut-stubs/osapi-utstub-filesys.c +++ b/src/ut-stubs/osapi-utstub-filesys.c @@ -54,7 +54,7 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const if (status == OS_SUCCESS) { - *filesys_id = UT_AllocStubObjId(UT_OBJTYPE_FILESYS); + *filesys_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_FILESYS); } else { @@ -206,7 +206,8 @@ int32 OS_FileSysStatVolume(const char *name, OS_statvfs_t *statbuf) status = UT_DEFAULT_IMPL(OS_FileSysStatVolume); - if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_FileSysStatVolume), statbuf, sizeof(*statbuf)) < sizeof(*statbuf)) + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_FileSysStatVolume), statbuf, sizeof(*statbuf)) < sizeof(*statbuf)) { memset(statbuf, 0, sizeof(*statbuf)); } diff --git a/src/ut-stubs/osapi-utstub-idmap.c b/src/ut-stubs/osapi-utstub-idmap.c index 4b2bd3992..54078c925 100644 --- a/src/ut-stubs/osapi-utstub-idmap.c +++ b/src/ut-stubs/osapi-utstub-idmap.c @@ -43,7 +43,7 @@ /* * UT Helper function to create a fake object lock token */ -static void UT_TokenCompose(uint32 lock_mode, uint32 indx, UT_ObjType_t objtype, OS_object_token_t *token) +static void UT_TokenCompose(uint32 lock_mode, uint32 indx, osal_objtype_t objtype, OS_object_token_t *token) { token->lock_mode = lock_mode; token->obj_type = objtype; @@ -72,7 +72,7 @@ uint32 OS_GetMaxForObjectType(osal_objtype_t idtype) { int32 max; - if (idtype > UT_OBJTYPE_NONE && idtype < UT_OBJTYPE_MAX) + if (idtype > OS_OBJECT_TYPE_UNDEFINED && idtype < OS_OBJECT_TYPE_USER) { max = OSAL_MAX_VALID_PER_TYPE; } @@ -93,7 +93,7 @@ uint32 OS_GetBaseForObjectType(osal_objtype_t idtype) { int32 base; - if (idtype > UT_OBJTYPE_NONE && idtype < UT_OBJTYPE_MAX) + if (idtype > OS_OBJECT_TYPE_UNDEFINED && idtype < OS_OBJECT_TYPE_USER) { base = OSAL_MAX_VALID_PER_TYPE * (idtype - 1); } @@ -112,9 +112,9 @@ uint32 OS_GetBaseForObjectType(osal_objtype_t idtype) *****************************************************************************/ int32 OS_ObjectIdToArrayIndex(osal_objtype_t idtype, osal_id_t id, osal_index_t *ArrayIndex) { - int32 Status; - UT_ObjType_t checktype; - uint32 tempserial; + int32 Status; + osal_objtype_t checktype; + uint32 tempserial; Status = UT_DEFAULT_IMPL(OS_ObjectIdToArrayIndex); @@ -457,9 +457,9 @@ int32 OS_ConvertToArrayIndex(osal_id_t object_id, osal_index_t *ArrayIndex) if (return_code == OS_SUCCESS) { - UT_ObjType_t ObjType; + osal_objtype_t ObjType; UT_ObjIdDecompose(object_id, &tempserial, &ObjType); - if (ObjType != UT_OBJTYPE_NONE && ObjType < UT_OBJTYPE_MAX) + if (ObjType != OS_OBJECT_TYPE_UNDEFINED && ObjType < OS_OBJECT_TYPE_USER) { tempserial %= UT_MAXOBJS[ObjType]; } @@ -603,7 +603,7 @@ void OS_ObjectIdIteratorDestroy(OS_object_iter_t *iter) UT_DEFAULT_IMPL(OS_ObjectIdIteratorDestroy); } -int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, int32 (*func)(osal_id_t, void*)) +int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, int32 (*func)(osal_id_t, void *)) { int32 Status; @@ -623,53 +623,13 @@ osal_objtype_t OS_IdentifyObject(osal_id_t object_id) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_IdentifyObject), object_id); - UT_ObjType_t ObjType; - uint32 checkindx; - int32 DefaultType; + osal_objtype_t ObjType; + uint32 checkindx; + int32 DefaultType; UT_ObjIdDecompose(object_id, &checkindx, &ObjType); - switch (ObjType) - { - case UT_OBJTYPE_TASK: - DefaultType = OS_OBJECT_TYPE_OS_TASK; - break; - case UT_OBJTYPE_QUEUE: - DefaultType = OS_OBJECT_TYPE_OS_QUEUE; - break; - case UT_OBJTYPE_COUNTSEM: - DefaultType = OS_OBJECT_TYPE_OS_COUNTSEM; - break; - case UT_OBJTYPE_BINSEM: - DefaultType = OS_OBJECT_TYPE_OS_BINSEM; - break; - case UT_OBJTYPE_MUTEX: - DefaultType = OS_OBJECT_TYPE_OS_MUTEX; - break; - case UT_OBJTYPE_TIMECB: - DefaultType = OS_OBJECT_TYPE_OS_TIMECB; - break; - case UT_OBJTYPE_MODULE: - DefaultType = OS_OBJECT_TYPE_OS_MODULE; - break; - case UT_OBJTYPE_FILESTREAM: - DefaultType = OS_OBJECT_TYPE_OS_STREAM; - break; - case UT_OBJTYPE_TIMEBASE: - DefaultType = OS_OBJECT_TYPE_OS_TIMEBASE; - break; - case UT_OBJTYPE_DIR: - DefaultType = OS_OBJECT_TYPE_OS_DIR; - break; - case UT_OBJTYPE_FILESYS: - DefaultType = OS_OBJECT_TYPE_OS_FILESYS; - break; - default: - DefaultType = OS_OBJECT_TYPE_UNDEFINED; - break; - } - - DefaultType = UT_DEFAULT_IMPL_RC(OS_IdentifyObject, DefaultType); + DefaultType = UT_DEFAULT_IMPL_RC(OS_IdentifyObject, ObjType); return DefaultType; } diff --git a/src/ut-stubs/osapi-utstub-module.c b/src/ut-stubs/osapi-utstub-module.c index 793369360..e62c85d2b 100644 --- a/src/ut-stubs/osapi-utstub-module.c +++ b/src/ut-stubs/osapi-utstub-module.c @@ -94,7 +94,7 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f if (status == OS_SUCCESS) { - *module_id = UT_AllocStubObjId(UT_OBJTYPE_MODULE); + *module_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_MODULE); } else { @@ -134,7 +134,7 @@ int32 OS_ModuleUnload(osal_id_t module_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_MODULE, module_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_MODULE, module_id); } return status; diff --git a/src/ut-stubs/osapi-utstub-mutex.c b/src/ut-stubs/osapi-utstub-mutex.c index baf060e93..fea9de66a 100644 --- a/src/ut-stubs/osapi-utstub-mutex.c +++ b/src/ut-stubs/osapi-utstub-mutex.c @@ -70,7 +70,7 @@ int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options) if (status == OS_SUCCESS) { - *sem_id = UT_AllocStubObjId(UT_OBJTYPE_MUTEX); + *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_MUTEX); } else { @@ -110,7 +110,7 @@ int32 OS_MutSemDelete(osal_id_t sem_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_MUTEX, sem_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_MUTEX, sem_id); } return status; @@ -195,7 +195,7 @@ int32 OS_MutSemGetIdByName(osal_id_t *sem_id, const char *sem_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_MutSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_MUTEX, sem_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_MUTEX, sem_id); } return status; @@ -231,7 +231,7 @@ int32 OS_MutSemGetInfo(osal_id_t sem_id, OS_mut_sem_prop_t *mut_prop) { strncpy(mut_prop->name, "Name", OS_MAX_API_NAME - 1); mut_prop->name[OS_MAX_API_NAME - 1] = '\0'; - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &mut_prop->creator); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &mut_prop->creator); } return status; diff --git a/src/ut-stubs/osapi-utstub-queue.c b/src/ut-stubs/osapi-utstub-queue.c index 77ed039ac..1888f10df 100644 --- a/src/ut-stubs/osapi-utstub-queue.c +++ b/src/ut-stubs/osapi-utstub-queue.c @@ -78,7 +78,7 @@ int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcoun if (status == OS_SUCCESS) { - *queue_id = UT_AllocStubObjId(UT_OBJTYPE_QUEUE); + *queue_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_QUEUE); } else { @@ -121,7 +121,7 @@ int32 OS_QueueDelete(osal_id_t queue_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_QUEUE, queue_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_QUEUE, queue_id); } return status; @@ -235,7 +235,7 @@ int32 OS_QueueGetIdByName(osal_id_t *queue_id, const char *queue_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_QueueGetIdByName), queue_id, sizeof(*queue_id)) < sizeof(*queue_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_QUEUE, queue_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_QUEUE, queue_id); } return status; @@ -269,7 +269,7 @@ int32 OS_QueueGetInfo(osal_id_t queue_id, OS_queue_prop_t *queue_prop) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_QueueGetInfo), queue_prop, sizeof(*queue_prop)) < sizeof(*queue_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &queue_prop->creator); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &queue_prop->creator); strncpy(queue_prop->name, "Name", OS_MAX_API_NAME - 1); queue_prop->name[OS_MAX_API_NAME - 1] = '\0'; } diff --git a/src/ut-stubs/osapi-utstub-sockets.c b/src/ut-stubs/osapi-utstub-sockets.c index 3eb783d15..bd95e9598 100644 --- a/src/ut-stubs/osapi-utstub-sockets.c +++ b/src/ut-stubs/osapi-utstub-sockets.c @@ -52,7 +52,7 @@ int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_ if (status == OS_SUCCESS) { - *sock_id = UT_AllocStubObjId(UT_OBJTYPE_SOCKET); + *sock_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); } return status; @@ -209,7 +209,7 @@ int32 OS_SocketGetIdByName(osal_id_t *sock_id, const char *sock_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_SocketGetIdByName), sock_id, sizeof(*sock_id)) < sizeof(*sock_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_SOCKET, sock_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_STREAM, sock_id); } return status; @@ -236,7 +236,7 @@ int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop) CopySize = UT_Stub_CopyToLocal(UT_KEY(OS_SocketGetInfo), sock_prop, sizeof(*sock_prop)); if (CopySize < sizeof(*sock_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &sock_prop->creator); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &sock_prop->creator); strncpy(sock_prop->name, "ut", sizeof(sock_prop->name)); } } diff --git a/src/ut-stubs/osapi-utstub-task.c b/src/ut-stubs/osapi-utstub-task.c index f29990f8b..9d6db317b 100644 --- a/src/ut-stubs/osapi-utstub-task.c +++ b/src/ut-stubs/osapi-utstub-task.c @@ -70,7 +70,7 @@ int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry f if (status == OS_SUCCESS) { - *task_id = UT_AllocStubObjId(UT_OBJTYPE_TASK); + *task_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TASK); } else { @@ -106,7 +106,7 @@ int32 OS_TaskDelete(osal_id_t task_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_TASK, task_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TASK, task_id); } return status; @@ -224,7 +224,7 @@ osal_id_t OS_TaskGetId(void) int32 status; status = UT_DEFAULT_IMPL_RC(OS_TaskGetId, 1); - UT_ObjIdCompose(status, UT_OBJTYPE_TASK, &TaskId); + UT_ObjIdCompose(status, OS_OBJECT_TYPE_OS_TASK, &TaskId); return TaskId; } @@ -246,7 +246,7 @@ int32 OS_TaskGetIdByName(osal_id_t *task_id, const char *task_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TaskGetIdByName), task_id, sizeof(*task_id)) < sizeof(*task_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, task_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, task_id); } return status; @@ -281,7 +281,7 @@ int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TaskGetInfo), task_prop, sizeof(*task_prop)) < sizeof(*task_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &task_prop->creator); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &task_prop->creator); task_prop->stack_size = OSAL_SIZE_C(100); task_prop->priority = OSAL_PRIORITY_C(150); strncpy(task_prop->name, "UnitTest", OS_MAX_API_NAME - 1); @@ -316,7 +316,7 @@ int32 OS_TaskFindIdBySystemData(osal_id_t *task_id, const void *sysdata, size_t if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TaskFindIdBySystemData), task_id, sizeof(*task_id)) < sizeof(*task_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, task_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, task_id); } return status; diff --git a/src/ut-stubs/osapi-utstub-time.c b/src/ut-stubs/osapi-utstub-time.c index 585463c67..e8478332a 100644 --- a/src/ut-stubs/osapi-utstub-time.c +++ b/src/ut-stubs/osapi-utstub-time.c @@ -57,7 +57,7 @@ int32 OS_TimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_t timebas if (status == OS_SUCCESS) { - *timer_id = UT_AllocStubObjId(UT_OBJTYPE_TIMECB); + *timer_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMECB); } else { @@ -86,7 +86,7 @@ int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *clock_ if (status == OS_SUCCESS) { - *timer_id = UT_AllocStubObjId(UT_OBJTYPE_TIMECB); + *timer_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMECB); } else { @@ -139,7 +139,7 @@ int32 OS_TimerDelete(osal_id_t timer_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_TIMECB, timer_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TIMECB, timer_id); } return status; @@ -162,7 +162,7 @@ int32 OS_TimerGetIdByName(osal_id_t *timer_id, const char *timer_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TimerGetIdByName), timer_id, sizeof(*timer_id)) < sizeof(*timer_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TIMECB, timer_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TIMECB, timer_id); } return status; @@ -200,7 +200,7 @@ int32 OS_TimerGetInfo(osal_id_t timer_id, OS_timer_prop_t *timer_prop) UT_Stub_CopyToLocal(UT_KEY(OS_TimerGetInfo), timer_prop, sizeof(*timer_prop)) < sizeof(*timer_prop)) { memset(timer_prop, 0, sizeof(*timer_prop)); - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &timer_prop->creator); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &timer_prop->creator); } return status; diff --git a/src/ut-stubs/osapi-utstub-timebase.c b/src/ut-stubs/osapi-utstub-timebase.c index 16b490479..c654eefb2 100644 --- a/src/ut-stubs/osapi-utstub-timebase.c +++ b/src/ut-stubs/osapi-utstub-timebase.c @@ -54,7 +54,7 @@ int32 OS_TimeBaseCreate(osal_id_t *timebase_id, const char *timebase_name, OS_Ti if (status == OS_SUCCESS) { - *timebase_id = UT_AllocStubObjId(UT_OBJTYPE_TIMEBASE); + *timebase_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMEBASE); } else { @@ -97,7 +97,7 @@ int32 OS_TimeBaseDelete(osal_id_t timebase_id) if (status == OS_SUCCESS) { - UT_DeleteStubObjId(UT_OBJTYPE_TIMEBASE, timebase_id); + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id); } return status; @@ -120,7 +120,7 @@ int32 OS_TimeBaseGetIdByName(osal_id_t *timebase_id, const char *timebase_name) if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TimeBaseGetIdByName), timebase_id, sizeof(*timebase_id)) < sizeof(*timebase_id)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TIMEBASE, timebase_id); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id); } return status; @@ -143,7 +143,7 @@ int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_pro if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_TimeBaseGetInfo), timebase_prop, sizeof(*timebase_prop)) < sizeof(*timebase_prop)) { - UT_ObjIdCompose(1, UT_OBJTYPE_TASK, &timebase_prop->creator); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &timebase_prop->creator); strncpy(timebase_prop->name, "Name", OS_MAX_API_NAME - 1); timebase_prop->name[OS_MAX_API_NAME - 1] = '\0'; } diff --git a/src/ut-stubs/utstub-helpers.c b/src/ut-stubs/utstub-helpers.c index 22abd573e..21f2a335a 100644 --- a/src/ut-stubs/utstub-helpers.c +++ b/src/ut-stubs/utstub-helpers.c @@ -36,19 +36,19 @@ #include "osapi-idmap.h" -const uint32 UT_MAXOBJS[UT_OBJTYPE_MAX] = {[UT_OBJTYPE_TASK] = OS_MAX_TASKS, - [UT_OBJTYPE_QUEUE] = OS_MAX_QUEUES, - [UT_OBJTYPE_COUNTSEM] = OS_MAX_COUNT_SEMAPHORES, - [UT_OBJTYPE_BINSEM] = OS_MAX_BIN_SEMAPHORES, - [UT_OBJTYPE_MUTEX] = OS_MAX_MUTEXES, - [UT_OBJTYPE_TIMECB] = OS_MAX_TIMERS, - [UT_OBJTYPE_MODULE] = OS_MAX_MODULES, - [UT_OBJTYPE_FILESTREAM] = OS_MAX_NUM_OPEN_FILES, - [UT_OBJTYPE_TIMEBASE] = OS_MAX_TIMEBASES, - [UT_OBJTYPE_FILESYS] = OS_MAX_FILE_SYSTEMS, - [UT_OBJTYPE_DIR] = OS_MAX_NUM_OPEN_DIRS}; - -static UT_ObjTypeState_t UT_ObjState[UT_OBJTYPE_MAX]; +const uint32 UT_MAXOBJS[OS_OBJECT_TYPE_USER] = {[OS_OBJECT_TYPE_OS_TASK] = OS_MAX_TASKS, + [OS_OBJECT_TYPE_OS_QUEUE] = OS_MAX_QUEUES, + [OS_OBJECT_TYPE_OS_COUNTSEM] = OS_MAX_COUNT_SEMAPHORES, + [OS_OBJECT_TYPE_OS_BINSEM] = OS_MAX_BIN_SEMAPHORES, + [OS_OBJECT_TYPE_OS_MUTEX] = OS_MAX_MUTEXES, + [OS_OBJECT_TYPE_OS_TIMECB] = OS_MAX_TIMERS, + [OS_OBJECT_TYPE_OS_MODULE] = OS_MAX_MODULES, + [OS_OBJECT_TYPE_OS_STREAM] = OS_MAX_NUM_OPEN_FILES, + [OS_OBJECT_TYPE_OS_TIMEBASE] = OS_MAX_TIMEBASES, + [OS_OBJECT_TYPE_OS_FILESYS] = OS_MAX_FILE_SYSTEMS, + [OS_OBJECT_TYPE_OS_DIR] = OS_MAX_NUM_OPEN_DIRS}; + +static UT_ObjTypeState_t UT_ObjState[OS_OBJECT_TYPE_USER]; /** * Initialization function @@ -64,7 +64,7 @@ void UT_ClearAllStubObjects(void) /* * Helper function - "allocate" a fake object ID of the given type */ -osal_id_t UT_AllocStubObjId(UT_ObjType_t ObjType) +osal_id_t UT_AllocStubObjId(osal_objtype_t ObjType) { UT_ObjTypeState_t *StatePtr; uint8 ObjMask; @@ -73,7 +73,7 @@ osal_id_t UT_AllocStubObjId(UT_ObjType_t ObjType) UT_Stub_CallOnce(UT_ClearAllStubObjects); - if (ObjType == UT_OBJTYPE_NONE || ObjType >= UT_OBJTYPE_MAX) + if (ObjType == OS_OBJECT_TYPE_UNDEFINED || ObjType >= OS_OBJECT_TYPE_USER) { /* Code is broken, abort the test * (This signifies an error in the stub code itself hence the abort) @@ -115,11 +115,11 @@ osal_id_t UT_AllocStubObjId(UT_ObjType_t ObjType) /* * Helper function - "deallocate" a fake object ID of the given type */ -void UT_DeleteStubObjId(UT_ObjType_t ObjType, osal_id_t ObjId) +void UT_DeleteStubObjId(osal_objtype_t ObjType, osal_id_t ObjId) { UT_ObjTypeState_t *StatePtr; uint8 ObjMask; - UT_ObjType_t checktype; + osal_objtype_t checktype; uint32 checkidx; bool ObjWasValid; @@ -171,14 +171,14 @@ void UT_DeleteStubObjId(UT_ObjType_t ObjType, osal_id_t ObjId) } } -void UT_ObjIdCompose(uint32 indx, UT_ObjType_t objtype, osal_id_t *id) +void UT_ObjIdCompose(uint32 indx, osal_objtype_t objtype, osal_id_t *id) { /* note - the OS_ObjectIdFromInteger() is an inline function, * and therefore this uses the real thing and not a stub */ *id = OS_ObjectIdFromInteger((unsigned long)indx | ((0x4000UL | objtype) << 16)); } -void UT_ObjIdDecompose(osal_id_t id, uint32 *indx, UT_ObjType_t *objtype) +void UT_ObjIdDecompose(osal_id_t id, uint32 *indx, osal_objtype_t *objtype) { unsigned long idv = OS_ObjectIdToInteger(id); *indx = idv & 0xFFFFUL; @@ -198,7 +198,7 @@ void UT_CheckForOpenSockets(void) UT_ObjTypeState_t *StatePtr; uint32 i; - StatePtr = &UT_ObjState[UT_OBJTYPE_QUEUE]; + StatePtr = &UT_ObjState[OS_OBJECT_TYPE_OS_QUEUE]; for (i = 0; i <= StatePtr->LastIssueNumber; ++i) { if ((StatePtr->ValidBits[i >> 3] & (1 << (i & 0x07))) != 0) diff --git a/src/ut-stubs/utstub-helpers.h b/src/ut-stubs/utstub-helpers.h index bb7775e9c..ce3ab4a86 100644 --- a/src/ut-stubs/utstub-helpers.h +++ b/src/ut-stubs/utstub-helpers.h @@ -46,29 +46,12 @@ #include "common_types.h" #include "osapi-error.h" #include "osapi-constants.h" +#include "osapi-idmap.h" #include "utstubs.h" #include "utbsp.h" #include "utassert.h" #include "uttools.h" -typedef enum -{ - UT_OBJTYPE_NONE = 0, - UT_OBJTYPE_TASK, - UT_OBJTYPE_QUEUE, - UT_OBJTYPE_COUNTSEM, - UT_OBJTYPE_BINSEM, - UT_OBJTYPE_MUTEX, - UT_OBJTYPE_TIMECB, - UT_OBJTYPE_MODULE, - UT_OBJTYPE_FILESTREAM, - UT_OBJTYPE_SOCKET, - UT_OBJTYPE_TIMEBASE, - UT_OBJTYPE_DIR, - UT_OBJTYPE_FILESYS, - UT_OBJTYPE_MAX -} UT_ObjType_t; - /* * A constant to use in stubs where no other value is applicable */ @@ -100,12 +83,12 @@ extern const uint32 UT_MAXOBJS[]; /* * Helper function - "allocate" a fake object ID of the given type */ -osal_id_t UT_AllocStubObjId(UT_ObjType_t ObjType); +osal_id_t UT_AllocStubObjId(osal_objtype_t ObjType); /* * Helper function - "deallocate" a fake object ID of the given type */ -void UT_DeleteStubObjId(UT_ObjType_t ObjType, osal_id_t ObjId); +void UT_DeleteStubObjId(osal_objtype_t ObjType, osal_id_t ObjId); /* * Helper function - Report any queue objects found open @@ -123,7 +106,7 @@ void UT_ClearAllStubObjects(void); * Compose/Decompose a unit test object ID from an index and type. * This is the UT-specific version not related to the OSAL runtime version. */ -void UT_ObjIdCompose(uint32 indx, UT_ObjType_t objtype, osal_id_t *id); -void UT_ObjIdDecompose(osal_id_t id, uint32 *indx, UT_ObjType_t *objtype); +void UT_ObjIdCompose(uint32 indx, osal_objtype_t objtype, osal_id_t *id); +void UT_ObjIdDecompose(osal_id_t id, uint32 *indx, osal_objtype_t *objtype); #endif