From 002ff71fc0b5794cd23acc31568e8d6faa102f42 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Wed, 14 Apr 2021 14:07:01 +0000 Subject: [PATCH] Partial #791, Add unit test branch coverage --- .../shared/src/coveragetest-binsem.c | 62 ++-- .../shared/src/coveragetest-common.c | 24 ++ .../shared/src/coveragetest-countsem.c | 54 ++-- .../shared/src/coveragetest-dir.c | 52 ++-- .../shared/src/coveragetest-errors.c | 9 +- .../shared/src/coveragetest-file.c | 172 +++++------ .../shared/src/coveragetest-filesys.c | 201 +++++++------ .../shared/src/coveragetest-idmap.c | 80 +++-- .../shared/src/coveragetest-module.c | 104 +++---- .../shared/src/coveragetest-mutex.c | 73 ++--- .../shared/src/coveragetest-network.c | 27 +- .../shared/src/coveragetest-printf.c | 27 +- .../shared/src/coveragetest-queue.c | 107 +++---- .../shared/src/coveragetest-select.c | 51 ++-- .../shared/src/coveragetest-sockets.c | 284 +++++++----------- .../shared/src/coveragetest-task.c | 156 +++++----- .../shared/src/coveragetest-time.c | 219 ++++++-------- .../shared/src/coveragetest-timebase.c | 153 +++++----- .../src/osapi-shared-error-impl-table-stubs.c | 3 +- .../vxworks/adaptors/inc/ut-adaptor-console.h | 2 +- .../vxworks/adaptors/src/ut-adaptor-console.c | 4 +- .../vxworks/src/coveragetest-common.c | 3 + .../vxworks/src/coveragetest-console.c | 16 +- .../vxworks/src/coveragetest-filesys.c | 10 + .../vxworks/src/coveragetest-network.c | 5 + .../vxworks/src/coveragetest-shell.c | 22 +- .../vxworks/src/coveragetest-symtab.c | 6 +- .../vxworks/src/coveragetest-tasks.c | 20 ++ .../vxworks/src/coveragetest-timebase.c | 18 ++ 29 files changed, 969 insertions(+), 995 deletions(-) diff --git a/src/unit-test-coverage/shared/src/coveragetest-binsem.c b/src/unit-test-coverage/shared/src/coveragetest-binsem.c index 143bd75bf..e56b8731e 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-binsem.c @@ -29,6 +29,8 @@ #include "OCS_string.h" +#define UT_ERR_UNIQUE 0xDEADBEEF + /* ********************************************************************************** ** PUBLIC API FUNCTIONS @@ -41,10 +43,7 @@ void Test_OS_BinSemAPI_Init(void) * Test Case For: * int32 OS_BinSemAPI_Init(void) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_BinSemAPI_Init(); - - UtAssert_True(actual == expected, "OS_BinSemAPI_Init() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_BinSemAPI_Init(), OS_SUCCESS); } void Test_OS_BinSemCreate(void) @@ -54,17 +53,18 @@ void Test_OS_BinSemCreate(void) * int32 OS_BinSemCreate (uint32 *sem_id, const char *sem_name, * uint32 sem_initial_value, uint32 options) */ - int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual = OS_BinSemCreate(&objid, "UT", 0, 0); - UtAssert_True(actual == expected, "OS_BinSemCreate() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(&objid, "UT", 0, 0), OS_SUCCESS); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(NULL, "UT", 0, 0), OS_INVALID_POINTER); OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(&objid, NULL, 0, 0), OS_INVALID_POINTER); - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(&objid, "UT", 0, 0), OS_ERR_NAME_TOO_LONG); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(&objid, "UT", 0, 0), UT_ERR_UNIQUE); } void Test_OS_BinSemDelete(void) @@ -73,12 +73,10 @@ void Test_OS_BinSemDelete(void) * Test Case For: * int32 OS_BinSemDelete (uint32 sem_id) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - - actual = OS_BinSemDelete(UT_OBJID_1); + OSAPI_TEST_FUNCTION_RC(OS_BinSemDelete(UT_OBJID_1), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_BinSemDelete() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemDelete(UT_OBJID_1), UT_ERR_UNIQUE); } void Test_OS_BinSemGive(void) @@ -87,12 +85,10 @@ void Test_OS_BinSemGive(void) * Test Case For: * int32 OS_BinSemGive ( uint32 sem_id ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + OSAPI_TEST_FUNCTION_RC(OS_BinSemGive(UT_OBJID_1), OS_SUCCESS); - actual = OS_BinSemGive(UT_OBJID_1); - - UtAssert_True(actual == expected, "OS_BinSemGive() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGive(UT_OBJID_1), UT_ERR_UNIQUE); } void Test_OS_BinSemTake(void) @@ -101,12 +97,10 @@ void Test_OS_BinSemTake(void) * Test Case For: * int32 OS_BinSemTake ( uint32 sem_id ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - - actual = OS_BinSemTake(UT_OBJID_1); + OSAPI_TEST_FUNCTION_RC(OS_BinSemTake(UT_OBJID_1), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_BinSemTake() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemTake(UT_OBJID_1), UT_ERR_UNIQUE); } void Test_OS_BinSemFlush(void) @@ -115,12 +109,10 @@ void Test_OS_BinSemFlush(void) * Test Case For: * int32 OS_BinSemFlush (uint32 sem_id) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - - actual = OS_BinSemFlush(UT_OBJID_1); + OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush(UT_OBJID_1), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_BinSemFlush() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush(UT_OBJID_1), UT_ERR_UNIQUE); } void Test_OS_BinSemTimedWait(void) @@ -129,12 +121,10 @@ void Test_OS_BinSemTimedWait(void) * Test Case For: * int32 OS_BinSemTimedWait ( uint32 sem_id, uint32 msecs ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait(UT_OBJID_1, 1), OS_SUCCESS); - actual = OS_BinSemTimedWait(UT_OBJID_1, 1); - - UtAssert_True(actual == expected, "OS_BinSemTimedWait() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait(UT_OBJID_1, 1), UT_ERR_UNIQUE); } void Test_OS_BinSemGetIdByName(void) @@ -157,7 +147,8 @@ void Test_OS_BinSemGetIdByName(void) actual = OS_BinSemGetIdByName(&objid, "NF"); UtAssert_True(actual == expected, "OS_BinSemGetIdByName() (%ld) == %ld", (long)actual, (long)expected); - OSAPI_TEST_FUNCTION_RC(OS_BinSemGetIdByName(NULL, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGetIdByName(NULL, "UT"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGetIdByName(&objid, NULL), OS_INVALID_POINTER); } void Test_OS_BinSemGetInfo(void) @@ -179,6 +170,9 @@ void Test_OS_BinSemGetInfo(void) UtAssert_True(strcmp(prop.name, "ABC") == 0, "prop.name (%s) == ABC", prop.name); OSAPI_TEST_FUNCTION_RC(OS_BinSemGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGetInfo(UT_OBJID_1, &prop), UT_ERR_UNIQUE); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-common.c b/src/unit-test-coverage/shared/src/coveragetest-common.c index e2f35695f..b05699a00 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-common.c +++ b/src/unit-test-coverage/shared/src/coveragetest-common.c @@ -71,6 +71,17 @@ static int32 ObjectDeleteCountHook(void *UserObj, int32 StubRetcode, uint32 Call return StubRetcode; } +/* Always returns 1 so TryCount will be exceeded */ +static int32 ObjectDeleteFailHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) +{ + + uint32 *counter = UT_Hook_GetArgValueByName(Context, "callback_arg", uint32 *); + + *counter = 1; + + return StubRetcode; +} + static int32 SetShutdownFlagHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) { OS_ApplicationShutdown(true); @@ -99,6 +110,13 @@ void Test_OS_API_Init(void) OSAPI_TEST_FUNCTION_RC(OS_API_Init(), OS_ERROR); UtAssert_UINT32_EQ(OS_SharedGlobalVars.GlobalState, OS_SHUTDOWN_MAGIC_NUMBER); + /* TicksPerSec == 0 branch */ + Test_MicroSecPerTick = 1; + Test_TicksPerSecond = 0; + OS_SharedGlobalVars.GlobalState = 0; + OSAPI_TEST_FUNCTION_RC(OS_API_Init(), OS_ERROR); + UtAssert_UINT32_EQ(OS_SharedGlobalVars.GlobalState, OS_SHUTDOWN_MAGIC_NUMBER); + Test_MicroSecPerTick = 1000; Test_TicksPerSecond = 1000; OS_SharedGlobalVars.GlobalState = 0; @@ -259,6 +277,10 @@ void Test_OS_DeleteAllObjects(void) * there is nothing to assert/verify for postconditions here */ OS_DeleteAllObjects(); + + /* Exceed TryCount */ + UT_SetHookFunction(UT_KEY(OS_ForEachObject), ObjectDeleteFailHook, NULL); + OS_DeleteAllObjects(); } void Test_OS_IdleLoopAndShutdown(void) @@ -278,6 +300,8 @@ void Test_OS_IdleLoopAndShutdown(void) CallCount = UT_GetStubCount(UT_KEY(OS_ApplicationShutdown_Impl)); UtAssert_True(CallCount == 1, "OS_ApplicationShutdown_Impl() call count (%lu) == 1", (unsigned long)CallCount); + + OS_ApplicationShutdown(false); } void Test_OS_NotifyEvent(void) diff --git a/src/unit-test-coverage/shared/src/coveragetest-countsem.c b/src/unit-test-coverage/shared/src/coveragetest-countsem.c index 40f8cfc7e..d8dd30fb6 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-countsem.c @@ -29,6 +29,8 @@ #include "OCS_string.h" +#define UT_ERR_UNIQUE 0xDEADBEEF + /* ********************************************************************************** ** PUBLIC API FUNCTIONS @@ -41,10 +43,7 @@ void Test_OS_CountSemAPI_Init(void) * Test Case For: * int32 OS_CountSemAPI_Init(void) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_CountSemAPI_Init(); - - UtAssert_True(actual == expected, "OS_CountSemAPI_Init() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_CountSemAPI_Init(), OS_SUCCESS); } void Test_OS_CountSemCreate(void) @@ -54,17 +53,18 @@ void Test_OS_CountSemCreate(void) * int32 OS_CountSemCreate (uint32 *sem_id, const char *sem_name, * uint32 sem_initial_value, uint32 options) */ - int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual = OS_CountSemCreate(&objid, "UT", 0, 0); - UtAssert_True(actual == expected, "OS_CountSemCreate() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(&objid, "UT", 0, 0), OS_SUCCESS); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(NULL, "UT", 0, 0), OS_INVALID_POINTER); OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(&objid, NULL, 0, 0), OS_INVALID_POINTER); - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(&objid, "UT", 0, 0), OS_ERR_NAME_TOO_LONG); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(&objid, "UT", 0, 0), UT_ERR_UNIQUE); } void Test_OS_CountSemDelete(void) @@ -73,12 +73,10 @@ void Test_OS_CountSemDelete(void) * Test Case For: * int32 OS_CountSemDelete (uint32 sem_id) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - - actual = OS_CountSemDelete(UT_OBJID_1); + OSAPI_TEST_FUNCTION_RC(OS_CountSemDelete(UT_OBJID_1), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_CountSemDelete() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_CountSemDelete(UT_OBJID_1), UT_ERR_UNIQUE); } void Test_OS_CountSemGive(void) @@ -87,12 +85,10 @@ void Test_OS_CountSemGive(void) * Test Case For: * int32 OS_CountSemGive ( uint32 sem_id ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + OSAPI_TEST_FUNCTION_RC(OS_CountSemGive(UT_OBJID_1), OS_SUCCESS); - actual = OS_CountSemGive(UT_OBJID_1); - - UtAssert_True(actual == expected, "OS_CountSemGive() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_CountSemGive(UT_OBJID_1), UT_ERR_UNIQUE); } void Test_OS_CountSemTake(void) @@ -101,12 +97,10 @@ void Test_OS_CountSemTake(void) * Test Case For: * int32 OS_CountSemTake ( uint32 sem_id ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - - actual = OS_CountSemTake(UT_OBJID_1); + OSAPI_TEST_FUNCTION_RC(OS_CountSemTake(UT_OBJID_1), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_CountSemTake() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_CountSemTake(UT_OBJID_1), UT_ERR_UNIQUE); } void Test_OS_CountSemTimedWait(void) @@ -115,12 +109,10 @@ void Test_OS_CountSemTimedWait(void) * Test Case For: * int32 OS_CountSemTimedWait ( uint32 sem_id, uint32 msecs ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait(UT_OBJID_1, 1), OS_SUCCESS); - actual = OS_CountSemTimedWait(UT_OBJID_1, 1); - - UtAssert_True(actual == expected, "OS_CountSemTimedWait() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait(UT_OBJID_1, 1), UT_ERR_UNIQUE); } void Test_OS_CountSemGetIdByName(void) @@ -143,7 +135,8 @@ void Test_OS_CountSemGetIdByName(void) actual = OS_CountSemGetIdByName(&objid, "NF"); UtAssert_True(actual == expected, "OS_CountSemGetIdByName() (%ld) == %ld", (long)actual, (long)expected); - OSAPI_TEST_FUNCTION_RC(OS_CountSemGetIdByName(NULL, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_CountSemGetIdByName(NULL, "UT"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_CountSemGetIdByName(&objid, NULL), OS_INVALID_POINTER); } void Test_OS_CountSemGetInfo(void) @@ -165,6 +158,9 @@ void Test_OS_CountSemGetInfo(void) UtAssert_True(strcmp(prop.name, "ABC") == 0, "prop.name (%s) == ABC", prop.name); OSAPI_TEST_FUNCTION_RC(OS_CountSemGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_CountSemGetInfo(UT_OBJID_1, &prop), UT_ERR_UNIQUE); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-dir.c b/src/unit-test-coverage/shared/src/coveragetest-dir.c index a6ea62bc1..71c2e41b9 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-dir.c +++ b/src/unit-test-coverage/shared/src/coveragetest-dir.c @@ -27,6 +27,8 @@ #include "os-shared-coveragetest.h" #include "os-shared-dir.h" +#define UT_ERR_UNIQUE 0xDEADBEEF + /* ********************************************************************************** ** PUBLIC API FUNCTIONS @@ -39,10 +41,7 @@ void Test_OS_DirAPI_Init(void) * Test Case For: * int32 OS_DirAPI_Init(void) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_DirAPI_Init(); - - UtAssert_True(actual == expected, "OS_DirAPI_Init() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_DirAPI_Init(), OS_SUCCESS); } void Test_OS_mkdir(void) @@ -51,10 +50,10 @@ void Test_OS_mkdir(void) * Test Case For: * int32 OS_mkdir (const char *path, uint32 access) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_mkdir("Dir", OS_READ_WRITE); + OSAPI_TEST_FUNCTION_RC(OS_mkdir("Dir", OS_READ_WRITE), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_mkdir() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_mkdir("Dir", OS_READ_WRITE), UT_ERR_UNIQUE); } void Test_OS_DirectoryOpen(void) @@ -63,13 +62,19 @@ void Test_OS_DirectoryOpen(void) * Test Case For: * int32 OS_DirectoryOpen(uint32 *dir_id, const char *path) */ - int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual = OS_DirectoryOpen(&objid, "Dir"); + uint32 unique1 = UT_ERR_UNIQUE + 1; - UtAssert_True(actual == expected, "OS_DirectoryOpen() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_DirectoryOpen(&objid, "Dir"), OS_SUCCESS); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); + /* Branch coverage for errors */ + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_DirectoryOpen(&objid, "Dir"), UT_ERR_UNIQUE); + + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), unique1); + OSAPI_TEST_FUNCTION_RC(OS_DirectoryOpen(&objid, "Dir"), unique1); + /* * Note that the second arg (path) is validated by a separate unit (OS_TranslatePath), * so it should not be passed NULL here @@ -83,10 +88,11 @@ void Test_OS_DirectoryClose(void) * Test Case For: * int32 OS_DirectoryClose(uint32 dir_id) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_DirectoryClose(UT_OBJID_1); + OSAPI_TEST_FUNCTION_RC(OS_DirectoryClose(UT_OBJID_1), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_DirectoryClose() (%ld) == OS_SUCCESS", (long)actual); + /* Branch coverage for errors */ + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_DirectoryClose(UT_OBJID_1), UT_ERR_UNIQUE); } void Test_OS_DirectoryRead(void) @@ -95,12 +101,13 @@ void Test_OS_DirectoryRead(void) * Test Case For: * int32 OS_DirectoryRead(uint32 dir_id, OS_DirEntry_t *dirent) */ - int32 expected = OS_SUCCESS; os_dirent_t dirent; - int32 actual = OS_DirectoryRead(UT_OBJID_1, &dirent); + OSAPI_TEST_FUNCTION_RC(OS_DirectoryRead(UT_OBJID_1, &dirent), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_DirectoryRead() (%ld) == OS_SUCCESS", (long)actual); + /* Branch coverage for errors */ + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_DirectoryRead(UT_OBJID_1, &dirent), UT_ERR_UNIQUE); OSAPI_TEST_FUNCTION_RC(OS_DirectoryRead(UT_OBJID_1, NULL), OS_INVALID_POINTER); } @@ -111,10 +118,11 @@ void Test_OS_DirectoryRewind(void) * Test Case For: * int32 OS_DirectoryRewind(uint32 dir_id) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_DirectoryRewind(UT_OBJID_1); + OSAPI_TEST_FUNCTION_RC(OS_DirectoryRewind(UT_OBJID_1), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_DirectoryRewind() (%ld) == OS_SUCCESS", (long)actual); + /* Branch coverage for errors */ + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_DirectoryRewind(UT_OBJID_1), UT_ERR_UNIQUE); } void Test_OS_rmdir(void) @@ -123,10 +131,10 @@ void Test_OS_rmdir(void) * Test Case For: * int32 OS_rmdir (const char *path) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_rmdir("Dir"); + OSAPI_TEST_FUNCTION_RC(OS_rmdir("Dir"), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_rmdir() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_rmdir("Dir"), UT_ERR_UNIQUE); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-errors.c b/src/unit-test-coverage/shared/src/coveragetest-errors.c index dcd70c3a8..d31252df4 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-errors.c +++ b/src/unit-test-coverage/shared/src/coveragetest-errors.c @@ -34,12 +34,15 @@ void Test_OS_GetErrorName(void) * int32 OS_GetErrorName(int32 error_num, os_err_name_t* err_name); */ os_err_name_t err_name; - int32 expected = OS_SUCCESS; - int32 actual = OS_GetErrorName(OS_ERROR, &err_name); - UtAssert_True(actual == expected, "OS_GetErrorName(%s) (%ld) == OS_SUCCESS", "OS_ERROR", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_GetErrorName(OS_ERROR, &err_name), OS_SUCCESS); UtAssert_True(strcmp(err_name, "OS_ERROR") == 0, "string(%s) == OS_ERROR", err_name); + OSAPI_TEST_FUNCTION_RC(OS_GetErrorName(-4444, &err_name), OS_SUCCESS); + UtAssert_True(strcmp(err_name, "UT_ERROR") == 0, "string(%s) == UT_ERROR", err_name); + + OSAPI_TEST_FUNCTION_RC(OS_GetErrorName(-4445, &err_name), OS_ERROR); + UtAssert_True(strcmp(err_name, "OS_UNKNOWN(-4445)") == 0, "string(%s) == OS_UNKNOWN(-4445)", err_name); OSAPI_TEST_FUNCTION_RC(OS_GetErrorName(-555555, &err_name), OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_GetErrorName(-555555, NULL), OS_INVALID_POINTER); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-file.c b/src/unit-test-coverage/shared/src/coveragetest-file.c index 91f26cfa1..b1303f432 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-file.c +++ b/src/unit-test-coverage/shared/src/coveragetest-file.c @@ -30,6 +30,8 @@ #include "OCS_string.h" +#define UT_ERR_UNIQUE 0xDEADBEEF + /* ********************************************************************************** ** PUBLIC API FUNCTIONS @@ -42,10 +44,7 @@ void Test_OS_FileAPI_Init(void) * Test Case For: * int32 OS_FileAPI_Init(void) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_FileAPI_Init(); - - UtAssert_True(actual == expected, "OS_FileAPI_Init() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_FileAPI_Init(), OS_SUCCESS); } void Test_OS_OpenCreate(void) @@ -77,6 +76,9 @@ void Test_OS_OpenCreate(void) actual = OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, 9999); UtAssert_True(actual == expected, "OS_OpenCreate() (%ld) == OS_ERROR (bad flags)", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, OS_READ_WRITE), UT_ERR_UNIQUE); + /* Test failure to convert path */ UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR); expected = OS_ERROR; @@ -91,10 +93,10 @@ void Test_OS_close(void) * Test Case For: * int32 OS_close (uint32 filedes) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_close(UT_OBJID_1); + OSAPI_TEST_FUNCTION_RC(OS_close(UT_OBJID_1), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_close() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_close(UT_OBJID_1), UT_ERR_UNIQUE); } void Test_OS_TimedRead(void) @@ -113,8 +115,12 @@ void Test_OS_TimedRead(void) UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); UtAssert_True(memcmp(Buf, SrcBuf, actual) == 0, "buffer content match"); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_TimedRead(UT_OBJID_1, Buf, sizeof(Buf), 10), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_TimedRead(UT_OBJID_1, NULL, sizeof(Buf), 10), OS_INVALID_POINTER); - OSAPI_TEST_FUNCTION_RC(OS_TimedRead(UT_OBJID_1, Buf, 0, 10), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_TimedRead(UT_OBJID_1, Buf, OSAL_SIZE_C(0), 10), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_TimedRead(UT_OBJID_1, Buf, OSAL_SIZE_C(UINT32_MAX), 10), OS_ERR_INVALID_SIZE); } void Test_OS_TimedWrite(void) @@ -134,8 +140,12 @@ void Test_OS_TimedWrite(void) UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); UtAssert_True(memcmp(Buf, DstBuf, actual) == 0, "buffer content match"); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_TimedWrite(UT_OBJID_1, Buf, sizeof(Buf), 10), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_TimedWrite(UT_OBJID_1, NULL, sizeof(Buf), 10), OS_INVALID_POINTER); - OSAPI_TEST_FUNCTION_RC(OS_TimedWrite(UT_OBJID_1, Buf, 0, 10), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_TimedWrite(UT_OBJID_1, Buf, OSAL_SIZE_C(0), 10), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_TimedWrite(UT_OBJID_1, Buf, OSAL_SIZE_C(UINT32_MAX), 10), OS_ERR_INVALID_SIZE); } void Test_OS_read(void) @@ -179,10 +189,10 @@ void Test_OS_chmod(void) * Test Case For: * int32 OS_chmod (const char *path, uint32 access_mode) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_chmod("/cf/file", 0); + OSAPI_TEST_FUNCTION_RC(OS_chmod("/cf/file", 0), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_chmod() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_chmod("/cf/file", 0), UT_ERR_UNIQUE); } void Test_OS_stat(void) @@ -191,15 +201,14 @@ void Test_OS_stat(void) * Test Case For: * int32 OS_stat (const char *path, OS_FileStat_t *filestats) */ - int32 expected = OS_SUCCESS; os_fstat_t statbuf; - int32 actual = OS_stat("/cf/file", &statbuf); - UtAssert_True(actual == expected, "OS_stat() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_stat("/cf/file", &statbuf), OS_SUCCESS); - expected = OS_INVALID_POINTER; - actual = OS_stat("/cf/file", NULL); - UtAssert_True(actual == expected, "OS_stat() (%ld) == OS_INVALID_POINTER", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_stat("/cf/file", &statbuf), UT_ERR_UNIQUE); + + OSAPI_TEST_FUNCTION_RC(OS_stat("/cf/file", NULL), OS_INVALID_POINTER); } void Test_OS_lseek(void) @@ -208,10 +217,10 @@ void Test_OS_lseek(void) * Test Case For: * int32 OS_lseek (uint32 filedes, int32 offset, uint32 whence) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_lseek(UT_OBJID_1, 0, 0); + OSAPI_TEST_FUNCTION_RC(OS_lseek(UT_OBJID_1, 0, 0), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_lseek() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_lseek(UT_OBJID_1, 0, 0), UT_ERR_UNIQUE); } void Test_OS_remove(void) @@ -220,10 +229,10 @@ void Test_OS_remove(void) * Test Case For: * int32 OS_remove (const char *path) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_remove("/cf/file"); + OSAPI_TEST_FUNCTION_RC(OS_remove("/cf/file"), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_remove() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_remove("/cf/file"), UT_ERR_UNIQUE); } void Test_OS_rename(void) @@ -232,16 +241,17 @@ void Test_OS_rename(void) * Test Case For: * int32 OS_rename (const char *old, const char *new) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - - OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 1); + OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 3); strncpy(OS_stream_table[1].stream_name, "/cf/file1", sizeof(OS_stream_table[1].stream_name)); - actual = OS_rename("/cf/file1", "/cf/file2"); - - UtAssert_True(actual == expected, "OS_rename() (%ld) == OS_SUCCESS", (long)actual); + OS_stream_table[2].socket_domain = OS_SocketDomain_INET; + OSAPI_TEST_FUNCTION_RC(OS_rename("/cf/file1", "/cf/file2"), OS_SUCCESS); UtAssert_True(strcmp(OS_stream_table[1].stream_name, "/cf/file2") == 0, "OS_stream_table[1].stream_name (%s) == /cf/file2", OS_stream_table[1].stream_name); + + UT_SetDeferredRetcode(UT_KEY(OS_TranslatePath), 2, UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_rename("/cf/file1", "/cf/file2"), UT_ERR_UNIQUE); + UT_SetDeferredRetcode(UT_KEY(OS_TranslatePath), 1, UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_rename("/cf/file1", "/cf/file2"), UT_ERR_UNIQUE); } void Test_OS_cp(void) @@ -250,38 +260,26 @@ void Test_OS_cp(void) * Test Case For: * int32 OS_cp (const char *src, const char *dest) */ - int32 expected = OS_INVALID_POINTER; - int32 actual = OS_cp(NULL, NULL); - char ReadBuf[] = "cpcpcpcp"; - char WriteBuf[sizeof(ReadBuf)] = ""; + char ReadBuf[] = "cpcpcpcp"; + char WriteBuf[sizeof(ReadBuf)] = ""; - UtAssert_True(actual == expected, "OS_cp() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_cp(NULL, "/cf/file2"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_cp("/cf/file1", NULL), OS_INVALID_POINTER); /* setup to make internal copy loop execute at least once */ - expected = OS_SUCCESS; UT_SetDataBuffer(UT_KEY(OS_GenericRead_Impl), ReadBuf, sizeof(ReadBuf), false); UT_SetDataBuffer(UT_KEY(OS_GenericWrite_Impl), WriteBuf, sizeof(WriteBuf), false); - actual = OS_cp("/cf/file1", "/cf/file2"); + OSAPI_TEST_FUNCTION_RC(OS_cp("/cf/file1", "/cf/file2"), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_cp() (%ld) == OS_SUCCESS", (long)actual); - - UT_SetDefaultReturnValue(UT_KEY(OS_GenericRead_Impl), -444); - expected = -444; - actual = OS_cp("/cf/file1", "/cf/file2"); - UtAssert_True(actual == expected, "OS_cp() (%ld) == -444", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OS_GenericRead_Impl)); + UT_SetDeferredRetcode(UT_KEY(OS_GenericRead_Impl), 1, -444); + OSAPI_TEST_FUNCTION_RC(OS_cp("/cf/file1", "/cf/file2"), -444); UT_SetDataBuffer(UT_KEY(OS_GenericRead_Impl), ReadBuf, sizeof(ReadBuf), false); UT_SetDefaultReturnValue(UT_KEY(OS_GenericWrite_Impl), -555); - expected = -555; - actual = OS_cp("/cf/file1", "/cf/file2"); - UtAssert_True(actual == expected, "OS_cp() (%ld) == -555", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_cp("/cf/file1", "/cf/file2"), -555); - UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_INVALID_POINTER); - expected = OS_INVALID_POINTER; - actual = OS_cp("/cf/file1", "/cf/file2"); - UtAssert_True(actual == expected, "OS_cp() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OS_TranslatePath)); + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), -666); + OSAPI_TEST_FUNCTION_RC(OS_cp("/cf/file1", "/cf/file2"), -666); } void Test_OS_mv(void) @@ -290,16 +288,16 @@ void Test_OS_mv(void) * Test Case For: * int32 OS_mv (const char *src, const char *dest) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_mv("/cf/file1", "/cf/file2"); - - UtAssert_True(actual == expected, "OS_mv() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_mv("/cf/file1", "/cf/file2"), OS_SUCCESS); /* In the default case, the implementation tries to rename first. * Force rename to fail so it does a full copy and remove */ UT_SetDefaultReturnValue(UT_KEY(OS_FileRename_Impl), OS_ERROR); - actual = OS_mv("/cf/file1", "/cf/file2"); - UtAssert_True(actual == expected, "OS_mv() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_mv("/cf/file1", "/cf/file2"), OS_SUCCESS); + + /* Fail the OS_cp/OS_OpenCreate */ + UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_mv("/cf/file1", "/cf/file2"), UT_ERR_UNIQUE); } void Test_OS_FDGetInfo(void) @@ -308,20 +306,16 @@ void Test_OS_FDGetInfo(void) * Test Case For: * int32 OS_FDGetInfo (uint32 filedes, OS_file_prop_t *fd_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; OS_file_prop_t file_prop; OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, "ABC", UT_OBJID_OTHER); - - actual = OS_FDGetInfo(UT_OBJID_1, &file_prop); - - UtAssert_True(actual == expected, "OS_FDGetInfo() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_FDGetInfo(UT_OBJID_1, &file_prop), OS_SUCCESS); UtAssert_True(strcmp(file_prop.Path, "ABC") == 0, "file_prop.Path (%s) == ABC", file_prop.Path); - expected = OS_INVALID_POINTER; - actual = OS_FDGetInfo(UT_OBJID_1, NULL); - UtAssert_True(actual == expected, "OS_FDGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_FDGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_FDGetInfo(UT_OBJID_1, &file_prop), UT_ERR_UNIQUE); } void Test_OS_FileOpenCheck(void) @@ -330,21 +324,14 @@ void Test_OS_FileOpenCheck(void) * Test Case For: * int32 OS_FileOpenCheck(const char *Filename) */ - int32 expected = OS_ERROR; - int32 actual = OS_FileOpenCheck("/cf/file"); - - UtAssert_True(actual == expected, "OS_FileOpenCheck() (%ld) == OS_ERROR", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_FileOpenCheck("/cf/file"), OS_ERROR); - OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 1); - UT_SetDefaultReturnValue(UT_KEY(OCS_strcmp), 0); - expected = OS_SUCCESS; - actual = OS_FileOpenCheck("/cf/file"); - - UtAssert_True(actual == expected, "OS_FileOpenCheck() (%ld) == OS_SUCCESS", (long)actual); + OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 3); + strncpy(OS_stream_table[3].stream_name, "/cf/file", sizeof(OS_stream_table[1].stream_name)); + OS_stream_table[2].socket_domain = OS_SocketDomain_INET; + OSAPI_TEST_FUNCTION_RC(OS_FileOpenCheck("/cf/file"), OS_SUCCESS); - expected = OS_INVALID_POINTER; - actual = OS_FileOpenCheck(NULL); - UtAssert_True(actual == expected, "OS_FDGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_FileOpenCheck(NULL), OS_INVALID_POINTER); } void Test_OS_CloseFileByName(void) @@ -353,21 +340,18 @@ void Test_OS_CloseFileByName(void) * Test Case For: * int32 OS_CloseFileByName(const char *Filename) */ - int32 expected = OS_FS_ERR_PATH_INVALID; - int32 actual = OS_CloseFileByName("/cf/file"); - - UtAssert_True(actual == expected, "OS_CloseFileByName() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_CloseFileByName("/cf/file"), OS_FS_ERR_PATH_INVALID); /* setup for success */ - OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 1); - expected = OS_SUCCESS; - UT_SetDefaultReturnValue(UT_KEY(OCS_strcmp), 0); - actual = OS_CloseFileByName("/cf/file"); - UtAssert_True(actual == expected, "OS_CloseFileByName() (%ld) == OS_SUCCESS", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_CloseFileByName(NULL); - UtAssert_True(actual == expected, "OS_CloseFileByName() (%ld) == OS_INVALID_POINTER", (long)actual); + OS_UT_SetupIterator(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, 5); + OS_stream_table[2].socket_domain = OS_SocketDomain_INET; + strncpy(OS_stream_table[3].stream_name, "/cf/file", sizeof(OS_stream_table[3].stream_name)); + strncpy(OS_stream_table[4].stream_name, "/cf/file", sizeof(OS_stream_table[4].stream_name)); + strncpy(OS_stream_table[5].stream_name, "/cf/file", sizeof(OS_stream_table[5].stream_name)); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdIteratorProcessEntry), 3, UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_CloseFileByName("/cf/file"), UT_ERR_UNIQUE); + + OSAPI_TEST_FUNCTION_RC(OS_CloseFileByName(NULL), OS_INVALID_POINTER); } void Test_OS_CloseAllFiles(void) diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 9e0fb6376..84e2f74f6 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -29,6 +29,8 @@ #include "OCS_string.h" +#define UT_ERR_UNIQUE 0xDEADBEEF + /* ********************************************************************************** ** PUBLIC API FUNCTIONS @@ -58,6 +60,7 @@ void Test_OS_FileSysAddFixedMap(void) OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_SUCCESS); OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", NULL), OS_INVALID_POINTER); OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, NULL, "/virt"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(NULL, "/phys", "/virt"), OS_INVALID_POINTER); UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_FS_ERR_PATH_TOO_LONG); @@ -70,6 +73,13 @@ void Test_OS_FileSysAddFixedMap(void) UT_ResetState(UT_KEY(OCS_memchr)); UT_ResetState(UT_KEY(OCS_strrchr)); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdAllocateNew), 1, UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), UT_ERR_UNIQUE); + UT_SetDeferredRetcode(UT_KEY(OS_FileSysStartVolume_Impl), 1, UT_ERR_UNIQUE + 1); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), UT_ERR_UNIQUE + 1); + UT_SetDeferredRetcode(UT_KEY(OS_FileSysMountVolume_Impl), 1, UT_ERR_UNIQUE + 2); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), UT_ERR_UNIQUE + 2); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_SUCCESS); OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_SUCCESS); } @@ -81,46 +91,53 @@ void Test_OS_mkfs(void) * int32 OS_mkfs (char *address, const char *devname, const char * volname, * uint32 blocksize, uint32 numblocks) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - char TestBuffer[128]; - actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_SUCCESS", (long)actual); + /* Success case for existing entry */ + OSAPI_TEST_FUNCTION_RC(OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), OS_SUCCESS); /* * Test an entry NOT found in the OS_VolumeTable */ - actual = OS_mkfs(TestBuffer, "/rd1", "vol1", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_mkfs(TestBuffer, "/rd1", "vol1", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), OS_SUCCESS); - expected = OS_INVALID_POINTER; - actual = OS_mkfs(NULL, NULL, NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_INVALID_POINTER", (long)actual); + /* NULL addr with RAM volume to cover branches */ + OSAPI_TEST_FUNCTION_RC(OS_mkfs(NULL, "/rd1", "RAM1", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), OS_SUCCESS); - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); + OSAPI_TEST_FUNCTION_RC(OS_mkfs(TestBuffer, NULL, "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_mkfs(TestBuffer, "/ramdev0", NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), + OS_INVALID_POINTER); - /* set up for failure due to empty strings */ - expected = OS_FS_ERR_PATH_INVALID; - actual = OS_mkfs(TestBuffer, "", "", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); + /* First string check error */ + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), + OS_FS_ERR_PATH_TOO_LONG); + + /* Second string check error */ + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 2, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), + OS_FS_ERR_PATH_TOO_LONG); + + /* failure due to empty strings */ + OSAPI_TEST_FUNCTION_RC(OS_mkfs(TestBuffer, "", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), + OS_FS_ERR_PATH_INVALID); + OSAPI_TEST_FUNCTION_RC(OS_mkfs(TestBuffer, "/ramdev0", "", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), + OS_FS_ERR_PATH_INVALID); /* set up for failure due to formatting */ UT_SetDefaultReturnValue(UT_KEY(OS_FileSysFormatVolume_Impl), OS_FS_ERR_DRIVE_NOT_CREATED); - expected = OS_FS_ERR_DRIVE_NOT_CREATED; - actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_DRIVE_NOT_CREATED (format failure)", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), + OS_FS_ERR_DRIVE_NOT_CREATED); + + /* Start failure */ + UT_SetDefaultReturnValue(UT_KEY(OS_FileSysStartVolume_Impl), OS_ERR_INCORRECT_OBJ_STATE); + OSAPI_TEST_FUNCTION_RC(OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), + OS_FS_ERR_DEVICE_NOT_FREE); /* set up for failure due to no free slots */ UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERR_NO_FREE_IDS); - expected = OS_FS_ERR_DEVICE_NOT_FREE; - actual = OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_mkfs() (%ld) == OS_FS_ERR_DEVICE_NOT_FREE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_mkfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), + OS_FS_ERR_DEVICE_NOT_FREE); } void Test_OS_rmfs(void) @@ -159,32 +176,26 @@ void Test_OS_initfs(void) * int32 OS_initfs (char *address,const char *devname, const char *volname, * uint32 blocksize, uint32 numblocks) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - char TestBuffer[128]; - actual = OS_initfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_initfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_initfs(NULL, "/hda2", "vol2", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), OS_SUCCESS); - actual = OS_initfs(NULL, "/hda2", "vol2", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_SUCCESS", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_initfs(NULL, NULL, NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_initfs(NULL, NULL, NULL, OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), OS_INVALID_POINTER); - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_initfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_initfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), + OS_FS_ERR_PATH_TOO_LONG); /* set up for failure */ - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERR_NO_FREE_IDS); - expected = OS_FS_ERR_DEVICE_NOT_FREE; - actual = OS_initfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)); - UtAssert_True(actual == expected, "OS_initfs() (%ld) == OS_FS_ERR_DEVICE_NOT_FREE", (long)actual); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdAllocateNew), 1, OS_ERR_NO_FREE_IDS); + OSAPI_TEST_FUNCTION_RC(OS_initfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), + OS_FS_ERR_DEVICE_NOT_FREE); + + /* Start failure */ + UT_SetDefaultReturnValue(UT_KEY(OS_FileSysStartVolume_Impl), OS_ERR_INCORRECT_OBJ_STATE); + OSAPI_TEST_FUNCTION_RC(OS_initfs(TestBuffer, "/ramdev0", "vol", OSAL_SIZE_C(0), OSAL_BLOCKCOUNT_C(0)), + OS_FS_ERR_DEVICE_NOT_FREE); } void Test_OS_mount(void) @@ -193,34 +204,30 @@ void Test_OS_mount(void) * Test Case For: * int32 OS_mount (const char *devname, const char* mountpoint) */ - int32 expected; - int32 actual; - - expected = OS_ERR_NAME_NOT_FOUND; - actual = OS_mount("/ramdev5", "/ram5"); - UtAssert_True(actual == expected, "OS_mount() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_mount("/ramdev5", "/ram5"), OS_ERR_NAME_NOT_FOUND); /* Test unknown/unset system mountpoint */ OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY; OS_filesys_table[1].system_mountpt[0] = 0; - expected = OS_ERR_NAME_NOT_FOUND; /* should be OS_FS_ERR_PATH_INVALID, but compat return overwrites */ - actual = OS_mount("/ramdev5", "/ram5"); - UtAssert_True(actual == expected, "OS_mount(no mountpt) (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); + /* should be OS_FS_ERR_PATH_INVALID, but compat return overwrites */ + OSAPI_TEST_FUNCTION_RC(OS_mount("/ramdev5", "/ram5"), OS_ERR_NAME_NOT_FOUND); /* set up so record is in the right state for mounting */ - expected = OS_SUCCESS; snprintf(OS_filesys_table[1].system_mountpt, sizeof(OS_filesys_table[1].system_mountpt), "/ut"); - actual = OS_mount("/ramdev5", "/ram5"); - UtAssert_True(actual == expected, "OS_mount(nominal) (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_mount("/ramdev5", "/ram5"), OS_SUCCESS); - expected = OS_INVALID_POINTER; - actual = OS_mount(NULL, NULL); - UtAssert_True(actual == expected, "OS_mount() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_mount(NULL, "/ram5"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_mount("/ramdev5", NULL), OS_INVALID_POINTER); - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_mount("/ramdev0", "/ram0"); - UtAssert_True(actual == expected, "OS_mount() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); + /* Path too long errors */ + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_mount("/ramdev0", "/ram0"), OS_FS_ERR_PATH_TOO_LONG); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 2, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_mount("/ramdev0", "/ram0"), OS_FS_ERR_PATH_TOO_LONG); + + /* Fail OS_ObjectIdGetByName */ + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetByName), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_mount("/ramdev5", "/ram5"), OS_ERR_NAME_NOT_FOUND); } void Test_OS_unmount(void) @@ -229,28 +236,20 @@ void Test_OS_unmount(void) * Test Case For: * int32 OS_unmount (const char *mountpoint) */ - int32 expected; - int32 actual; - - expected = OS_ERR_NAME_NOT_FOUND; - actual = OS_unmount("/ram0"); - UtAssert_True(actual == expected, "OS_mount() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_unmount("/ram0"), OS_ERR_NAME_NOT_FOUND); /* set up so record is in the right state for mounting */ OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; - expected = OS_SUCCESS; - actual = OS_unmount("/ram0"); - UtAssert_True(actual == expected, "OS_unmount(nominal) (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_unmount("/ram0"), OS_SUCCESS); - expected = OS_INVALID_POINTER; - actual = OS_unmount(NULL); - UtAssert_True(actual == expected, "OS_unmount() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_unmount(NULL), OS_INVALID_POINTER); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetBySearch), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_unmount("/ram0"), OS_ERR_NAME_NOT_FOUND); UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_unmount("/ram0"); - UtAssert_True(actual == expected, "OS_unmount() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_unmount("/ram0"), OS_FS_ERR_PATH_TOO_LONG); } void Test_OS_FileSysStatVolume(void) @@ -349,33 +348,23 @@ void Test_OS_FS_GetPhysDriveName(void) * Test Case For: * int32 OS_FS_GetPhysDriveName(char * PhysDriveName, const char * MountPoint) */ - int32 expected = OS_INVALID_POINTER; - int32 actual = OS_FS_GetPhysDriveName(NULL, NULL); - char NameBuf[OS_FS_PHYS_NAME_LEN]; + char NameBuf[OS_FS_PHYS_NAME_LEN]; - UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_FS_GetPhysDriveName(NULL, "none"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_FS_GetPhysDriveName(NameBuf, NULL), OS_INVALID_POINTER); - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_FS_GetPhysDriveName(NameBuf, "none"); - UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_FS_GetPhysDriveName(NameBuf, "none"), OS_FS_ERR_PATH_TOO_LONG); - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_FS_GetPhysDriveName(NameBuf, "none"); - UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_FS_GetPhysDriveName(NameBuf, "none"), OS_ERR_INCORRECT_OBJ_STATE); OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; - expected = OS_SUCCESS; - actual = OS_FS_GetPhysDriveName(NameBuf, "none"); - UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_FS_GetPhysDriveName(NameBuf, "none"), OS_SUCCESS); /* Test Fail due to no matching VolTab entry */ UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); - expected = OS_ERR_NAME_NOT_FOUND; - actual = OS_FS_GetPhysDriveName(NameBuf, "none"); - UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_FS_GetPhysDriveName(NameBuf, "none"), OS_ERR_NAME_NOT_FOUND); } void Test_OS_GetFsInfo(void) @@ -500,7 +489,8 @@ void Test_OS_FileSys_FindVirtMountPoint(void) */ bool result; OS_common_record_t refobj; - const char refstr[] = "/ut"; + const char refstr[] = "/ut"; + const char refstr1[] = "/ut/"; OS_object_token_t token; memset(&token, 0, sizeof(token)); @@ -516,6 +506,16 @@ void Test_OS_FileSys_FindVirtMountPoint(void) OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; + /* Branch coverage for mismatches */ + result = OS_FileSys_FindVirtMountPoint((void *)refstr, &token, &refobj); + UtAssert_True(!result, "OS_FileSys_FindVirtMountPoint(%s) (mountpt=%s) == false", refstr, + OS_filesys_table[1].virtual_mountpt); + + memset(OS_filesys_table[1].virtual_mountpt, 'a', sizeof(OS_filesys_table[1].virtual_mountpt)); + result = OS_FileSys_FindVirtMountPoint((void *)refstr, &token, &refobj); + UtAssert_True(!result, "OS_FileSys_FindVirtMountPoint(%s) (mountpt=%s) == false", refstr, + OS_filesys_table[1].virtual_mountpt); + /* Verify cases where one is a substring of the other - * these should also return false */ strncpy(OS_filesys_table[1].virtual_mountpt, "/ut11", sizeof(OS_filesys_table[1].virtual_mountpt)); @@ -531,6 +531,11 @@ void Test_OS_FileSys_FindVirtMountPoint(void) strncpy(OS_filesys_table[1].virtual_mountpt, "/ut", sizeof(OS_filesys_table[1].virtual_mountpt)); result = OS_FileSys_FindVirtMountPoint((void *)refstr, &token, &refobj); UtAssert_True(result, "OS_FileSys_FindVirtMountPoint(%s) (nominal) == true", refstr); + + /* Passing case with reference ending in "/" */ + strncpy(OS_filesys_table[1].virtual_mountpt, "/ut", sizeof(OS_filesys_table[1].virtual_mountpt)); + result = OS_FileSys_FindVirtMountPoint((void *)refstr1, &token, &refobj); + UtAssert_True(result, "OS_FileSys_FindVirtMountPoint(%s) (nominal) == true", refstr); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index e37cf9362..9659a3d17 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -45,6 +45,15 @@ static bool TestAlwaysMatch(void *ref, const OS_object_token_t *token, const OS_ return true; } +/* OS_TaskGetId_Impl handler to provide a valid id */ +void UT_Handler_OS_TaskGetId_Impl(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t objid; + + OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TASK, 1, &objid); + UT_Stub_SetReturnValue(FuncKey, objid); +} + static void ObjTypeCounter(osal_id_t object_id, void *arg) { Test_OS_ObjTypeCount_t *count = arg; @@ -94,7 +103,7 @@ void Test_OS_LockUnlockGlobal(void) memset(&token, 0, sizeof(token)); token.obj_type = OS_OBJECT_TYPE_OS_COUNTSEM; - token.lock_mode = OS_LOCK_MODE_GLOBAL; + token.lock_mode = OS_LOCK_MODE_NONE; /* * As these have no return codes, these tests @@ -103,6 +112,16 @@ void Test_OS_LockUnlockGlobal(void) OS_Lock_Global(&token); OS_Unlock_Global(&token); + token.lock_mode = OS_LOCK_MODE_GLOBAL; + OS_Lock_Global(&token); + OS_Unlock_Global(&token); + + /* Register handler to provide valid self_task_id for branch coverage*/ + UT_SetHandlerFunction(UT_KEY(OS_TaskGetId_Impl), UT_Handler_OS_TaskGetId_Impl, NULL); + OS_Lock_Global(&token); + OS_Unlock_Global(&token); + UT_ResetState(UT_KEY(OS_TaskGetId_Impl)); + token.obj_type = OS_OBJECT_TYPE_UNDEFINED; OS_Lock_Global(&token); @@ -183,6 +202,19 @@ void Test_OS_ObjectIdConvertToken(void) /* Global should not be released */ UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 1); + /* object in use, not OS_OBJECT_ID_RESERVED */ + token.lock_mode = OS_LOCK_MODE_GLOBAL; + record->active_id = OS_OBJECT_ID_RESERVED; + OSAPI_TEST_FUNCTION_RC(OS_ObjectIdConvertToken(&token), OS_ERR_OBJECT_IN_USE); + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 1); + UtAssert_STUB_COUNT(OS_WaitForStateChange_Impl, 4); + UT_ResetState(UT_KEY(OS_WaitForStateChange_Impl)); + record->active_id = objid; + + /* Failure branch for exclusive lock where active id was overwritten (non-reserved expected_id) */ + token.lock_mode = OS_LOCK_MODE_EXCLUSIVE; + OSAPI_TEST_FUNCTION_RC(OS_ObjectIdConvertToken(&token), OS_ERR_INVALID_ID); + /* * Use mode OS_LOCK_MODE_NONE with matching ID * This should return success. @@ -491,6 +523,11 @@ void Test_OS_ObjectIdGetById(void) /* set "true" for the remainder of tests */ OS_SharedGlobalVars.GlobalState = OS_INIT_MAGIC_NUMBER; + /* OS_ObjectIdToArrayIndex failure branch */ + OSAPI_TEST_FUNCTION_RC( + OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, OS_OBJECT_ID_UNDEFINED, &token1), + OS_ERR_INVALID_ID); + OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TASK, 1000, &refobjid); OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TASK, refobjid, &local_idx); rptr = &OS_global_task_table[local_idx]; @@ -813,6 +850,10 @@ void Test_OS_ObjectIdTransaction(void) OS_ObjectIdTransactionCancel(&token); UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 1); + /* Call again to cover OS_LOCK_MODE_NONE branch */ + OS_ObjectIdTransactionCancel(&token); + UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 1); + /* other cases for normal operating mode */ OS_SharedGlobalVars.GlobalState = OS_INIT_MAGIC_NUMBER; OSAPI_TEST_FUNCTION_RC(OS_ObjectIdTransactionInit(OS_LOCK_MODE_GLOBAL, OS_OBJECT_TYPE_OS_COUNTSEM, &token), @@ -1025,8 +1066,6 @@ void Test_OS_GetResourceName(void) OS_object_token_t token; OS_common_record_t *rptr; char NameBuffer[OS_MAX_API_NAME]; - int32 expected; - int32 actual; /* * Set up for the OS_GetResourceName function to return success @@ -1039,22 +1078,22 @@ void Test_OS_GetResourceName(void) rptr->name_entry = "UTTask"; rptr->active_id = token.obj_id; - expected = OS_SUCCESS; - actual = OS_GetResourceName(token.obj_id, NameBuffer, sizeof(NameBuffer)); - UtAssert_True(actual == expected, "OS_GetResourceName() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_GetResourceName(token.obj_id, NameBuffer, sizeof(NameBuffer)), OS_SUCCESS); UtAssert_True(strcmp(NameBuffer, "UTTask") == 0, "NameBuffer (%s) == UTTask", NameBuffer); - expected = OS_ERR_NAME_TOO_LONG; - actual = OS_GetResourceName(token.obj_id, NameBuffer, OSAL_SIZE_C(2)); - UtAssert_True(actual == expected, "OS_GetResourceName() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_GetResourceName(token.obj_id, NameBuffer, OSAL_SIZE_C(2)), OS_ERR_NAME_TOO_LONG); - expected = OS_INVALID_POINTER; - actual = OS_GetResourceName(token.obj_id, NULL, sizeof(NameBuffer)); - UtAssert_True(actual == expected, "OS_GetResourceName() (%ld) == OS_INVALID_POINTER", (long)actual); + /* Null entry */ + rptr->name_entry = NULL; + OSAPI_TEST_FUNCTION_RC(OS_GetResourceName(token.obj_id, NameBuffer, sizeof(NameBuffer)), OS_SUCCESS); - expected = OS_ERR_INVALID_SIZE; - actual = OS_GetResourceName(token.obj_id, NameBuffer, OSAL_SIZE_C(0)); - UtAssert_True(actual == expected, "OS_GetResourceName() (%ld) == OS_ERR_INVALID_SIZE", (long)actual); + /* Invalid token */ + memset(&token, 0, sizeof(token)); + OSAPI_TEST_FUNCTION_RC(OS_GetResourceName(token.obj_id, NameBuffer, sizeof(NameBuffer)), OS_ERR_INVALID_ID); + + OSAPI_TEST_FUNCTION_RC(OS_GetResourceName(token.obj_id, NULL, sizeof(NameBuffer)), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_GetResourceName(token.obj_id, NameBuffer, OSAL_SIZE_C(0)), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_GetResourceName(token.obj_id, NameBuffer, OSAL_SIZE_C(UINT32_MAX)), OS_ERR_INVALID_SIZE); } void Test_OS_ObjectIdIterator(void) @@ -1069,9 +1108,16 @@ void Test_OS_ObjectIdIterator(void) uint32 testarg; OSAPI_TEST_FUNCTION_RC(OS_ObjectIdIteratorInit(NULL, NULL, OS_OBJECT_TYPE_UNDEFINED, &iter), OS_ERR_INVALID_ID); - OSAPI_TEST_FUNCTION_RC(OS_ObjectIdIterateActive(OS_OBJECT_TYPE_OS_TASK, &iter), OS_SUCCESS); + + OSAPI_TEST_FUNCTION_RC(OS_ObjectIdIteratorInit(NULL, NULL, OS_OBJECT_TYPE_OS_TASK, &iter), OS_SUCCESS); UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 1); + /* Cover NULL match function case */ + UtAssert_True(OS_ObjectIdIteratorGetNext(&iter), "OS_ObjectIdIteratorGetNext() with null match function"); + + OSAPI_TEST_FUNCTION_RC(OS_ObjectIdIterateActive(OS_OBJECT_TYPE_OS_TASK, &iter), OS_SUCCESS); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 2); + memset(&rec, 0, sizeof(rec)); UtAssert_True(!OS_ObjectFilterActive(NULL, NULL, &rec), "OS_ObjectFilterActive() empty record"); @@ -1083,7 +1129,7 @@ void Test_OS_ObjectIdIterator(void) iter.arg = &testarg; OS_ObjectIdIteratorProcessEntry(&iter, TestIterator); UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 1); - UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 2); + UtAssert_STUB_COUNT(OS_Lock_Global_Impl, 3); /* OS_ObjectIdIteratorDestroy is just a passthrough to OS_ObjectIdTransactionCancel, * but need to call for coverage */ diff --git a/src/unit-test-coverage/shared/src/coveragetest-module.c b/src/unit-test-coverage/shared/src/coveragetest-module.c index e1e3d8a1d..195ea4e1b 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-module.c +++ b/src/unit-test-coverage/shared/src/coveragetest-module.c @@ -31,6 +31,8 @@ #include "OCS_string.h" +#define UT_ERR_UNIQUE 0xDEADBEEF + /* A dummy function for the static symbol lookup test. Not called */ void Test_DummyFunc(void) {} @@ -40,7 +42,8 @@ void Test_DummyFunc(void) {} * Note - the symbol name is intentionally not the actual function name here. * This way, the test case knows that the answer actually came from the static table */ -OS_static_symbol_record_t OS_UT_STATIC_SYMBOL_TABLE[] = {{"UT_staticsym", &Test_DummyFunc, "UTS"}, {NULL}}; +OS_static_symbol_record_t OS_UT_STATIC_SYMBOL_TABLE[] = { + {"UT_staticsym", &Test_DummyFunc, "UTS"}, {"UT_nullmod", NULL, NULL}, {NULL}}; /* ********************************************************************************** @@ -66,44 +69,37 @@ void Test_OS_ModuleLoad(void) * Test Case For: * int32 OS_ModuleLoad ( uint32 *module_id, const char *module_name, const char *filename ) */ - int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual = OS_ModuleLoad(&objid, "UT", "File", OS_MODULE_FLAG_GLOBAL_SYMBOLS); - UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_SUCCESS", (long)actual); - actual = UT_GetStubCount(UT_KEY(OS_ModuleLoad_Impl)); - UtAssert_True(actual == 1, "OS_ModuleLoad_Impl() called (%ld) == 1", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad(&objid, "UT", "File", OS_MODULE_FLAG_GLOBAL_SYMBOLS), OS_SUCCESS); + UtAssert_STUB_COUNT(OS_ModuleLoad_Impl, 1); + UT_ResetState(UT_KEY(OS_ModuleLoad_Impl)); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); /* for a static module, it should also return a valid objid, but should NOT invoke OS_ModuleLoad_Impl */ - actual = OS_ModuleLoad(&objid, "UTS", "File2", OS_MODULE_FLAG_GLOBAL_SYMBOLS); - UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_SUCCESS", (long)actual); - actual = UT_GetStubCount(UT_KEY(OS_ModuleLoad_Impl)); - UtAssert_True(actual == 1, "OS_ModuleLoad_Impl() called (%ld) == 1", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad(&objid, "UTS", "File2", OS_MODULE_FLAG_GLOBAL_SYMBOLS), OS_SUCCESS); + UtAssert_STUB_COUNT(OS_ModuleLoad_Impl, 0); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); /* a dynamic module with local symbols */ - actual = OS_ModuleLoad(&objid, "UT", "File3", OS_MODULE_FLAG_LOCAL_SYMBOLS); - UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_SUCCESS", (long)actual); - actual = UT_GetStubCount(UT_KEY(OS_ModuleLoad_Impl)); - UtAssert_True(actual == 2, "OS_ModuleLoad_Impl() called (%ld) == 2", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad(&objid, "UT", "File3", OS_MODULE_FLAG_LOCAL_SYMBOLS), OS_SUCCESS); + UtAssert_STUB_COUNT(OS_ModuleLoad_Impl, 1); + UT_ResetState(UT_KEY(OS_ModuleLoad_Impl)); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); /* error cases */ - actual = OS_ModuleLoad(NULL, NULL, NULL, OS_MODULE_FLAG_GLOBAL_SYMBOLS); - expected = OS_INVALID_POINTER; - UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad(NULL, "UT", "File", OS_MODULE_FLAG_GLOBAL_SYMBOLS), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad(&objid, NULL, "File", OS_MODULE_FLAG_GLOBAL_SYMBOLS), OS_INVALID_POINTER); UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - actual = OS_ModuleLoad(&objid, "UTS", "File2", OS_MODULE_FLAG_GLOBAL_SYMBOLS); - expected = OS_ERR_NAME_TOO_LONG; - UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad(&objid, "UTS", "File2", OS_MODULE_FLAG_GLOBAL_SYMBOLS), OS_ERR_NAME_TOO_LONG); UT_ResetState(UT_KEY(OCS_memchr)); UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR); - actual = OS_ModuleLoad(&objid, "UT", "FileBad", OS_MODULE_FLAG_GLOBAL_SYMBOLS); - expected = OS_ERROR; - UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_ERROR", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad(&objid, "UT", "FileBad", OS_MODULE_FLAG_GLOBAL_SYMBOLS), OS_ERROR); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad(&objid, "UT", "FileBad", OS_MODULE_FLAG_GLOBAL_SYMBOLS), UT_ERR_UNIQUE); } void Test_OS_ModuleUnload(void) @@ -112,19 +108,27 @@ void Test_OS_ModuleUnload(void) * Test Case For: * int32 OS_ModuleUnload ( uint32 module_id ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + osal_id_t objid; + + /* Clear module table */ + memset(OS_module_table, 0, sizeof(OS_module_table)); + + /* Set up one dynamic and one static entry */ + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad(&objid, "UT", "File", OS_MODULE_FLAG_GLOBAL_SYMBOLS), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad(&objid, "UTS", "File2", OS_MODULE_FLAG_GLOBAL_SYMBOLS), OS_SUCCESS); - actual = OS_ModuleUnload(UT_OBJID_1); + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload(UT_OBJID_1), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload(UT_OBJID_2), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_ModuleDelete() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload(OS_OBJECT_ID_UNDEFINED), OS_ERROR); } void Test_OS_SymbolLookup(void) { /* * Test Case For: - * int32 OS_ModuleUnload ( uint32 module_id ) + * int32 OS_SymbolLookup(cpuaddr *SymbolAddress, const char *SymbolName) */ int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; @@ -146,9 +150,8 @@ void Test_OS_SymbolLookup(void) UtAssert_True(symaddr == testaddr, "OS_SymbolLookup(address=%lx) == %lx", (unsigned long)symaddr, (unsigned long)testaddr); - actual = OS_SymbolLookup(NULL, NULL); - expected = OS_INVALID_POINTER; - UtAssert_True(actual == expected, "OS_SymbolLookup(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup(NULL, "uttestsym0"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup(&symaddr, NULL), OS_INVALID_POINTER); /* * Look up a symbol that is present in the static symbol table @@ -164,36 +167,30 @@ 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); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symaddr, "uttestsym0"), OS_SUCCESS); - UT_ResetState(UT_KEY(OS_ModuleSymbolLookup_Impl)); + /* Fail implementation layer */ 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); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symaddr, "uttestsym1"), OS_ERROR); 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); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, NULL, "ut"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symaddr, NULL), OS_INVALID_POINTER); /* * 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); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symaddr, "UT_staticsym"), OS_SUCCESS); + + /* Fail OS_ObjectIdGetById */ + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symaddr, "uttestsym0"), OS_ERR_INVALID_ID); } void Test_OS_StaticSymbolLookup(void) @@ -273,22 +270,19 @@ void Test_OS_ModuleGetInfo(void) * Test Case For: * int32 OS_ModuleInfo ( uint32 module_id, OS_module_prop_t *module_prop ) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; OS_module_prop_t module_prop; OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_MODULE, UT_INDEX_1, "ABC", UT_OBJID_OTHER); strncpy(OS_module_table[1].file_name, "DEF", sizeof(OS_module_table[1].file_name)); - actual = OS_ModuleInfo(UT_OBJID_1, &module_prop); - - UtAssert_True(actual == expected, "OS_ModuleGetInfo() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_ModuleInfo(UT_OBJID_1, &module_prop), OS_SUCCESS); UtAssert_True(strcmp(module_prop.filename, "DEF") == 0, "module_prop.filename (%s) == DEF", module_prop.filename); UtAssert_True(strcmp(module_prop.name, "ABC") == 0, "module_prop.name (%s) == ABC", module_prop.name); - actual = OS_ModuleInfo(UT_OBJID_1, NULL); - expected = OS_INVALID_POINTER; - UtAssert_True(actual == expected, "OS_ModuleGetInfo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_ModuleInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleInfo(OS_OBJECT_ID_UNDEFINED, &module_prop), OS_ERROR); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-mutex.c b/src/unit-test-coverage/shared/src/coveragetest-mutex.c index 42f04489a..d66265ee4 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/shared/src/coveragetest-mutex.c @@ -41,10 +41,7 @@ void Test_OS_MutexAPI_Init(void) * Test Case For: * int32 OS_MutSemAPI_Init(void) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_MutexAPI_Init(); - - UtAssert_True(actual == expected, "OS_MutexAPI_Init() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_MutexAPI_Init(), OS_SUCCESS); } void Test_OS_MutSemCreate(void) @@ -53,15 +50,17 @@ void Test_OS_MutSemCreate(void) * Test Case For: * int32 OS_MutSemCreate (uint32 *sem_id, const char *sem_name, uint32 options) */ - int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual = OS_MutSemCreate(&objid, "UT", 0); - UtAssert_True(actual == expected, "OS_MutSemCreate() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(&objid, "UT", 0), OS_SUCCESS); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(NULL, "UT", 0), OS_INVALID_POINTER); OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(&objid, NULL, 0), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(&objid, "UT", 0), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(&objid, "UT", 0), OS_ERR_NAME_TOO_LONG); } @@ -72,12 +71,11 @@ void Test_OS_MutSemDelete(void) * Test Case For: * int32 OS_MutSemDelete (uint32 sem_id) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - actual = OS_MutSemDelete(UT_OBJID_1); + OSAPI_TEST_FUNCTION_RC(OS_MutSemDelete(UT_OBJID_1), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_MutSemDelete() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_MutSemDelete(UT_OBJID_1), OS_ERROR); } void Test_OS_MutSemGive(void) @@ -87,25 +85,21 @@ void Test_OS_MutSemGive(void) * int32 OS_MutSemGive ( uint32 sem_id ) */ OS_mutex_internal_record_t *mutex; - int32 expected; - int32 actual; - - 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); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGive(UT_OBJID_1), OS_SUCCESS); /* 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); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGive(UT_OBJID_1), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGive(UT_OBJID_1), OS_ERROR); } void Test_OS_MutSemTake(void) @@ -115,24 +109,23 @@ void Test_OS_MutSemTake(void) * int32 OS_MutSemTake ( uint32 sem_id ) */ OS_mutex_internal_record_t *mutex; - int32 expected; - int32 actual; - - 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); + OSAPI_TEST_FUNCTION_RC(OS_MutSemTake(UT_OBJID_1), OS_SUCCESS); /* 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); + /* Call again when not already "owned". This still works (or at least it calls the OS impl) */ + OSAPI_TEST_FUNCTION_RC(OS_MutSemTake(UT_OBJID_1), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OS_MutSemTake_Impl), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_MutSemTake(UT_OBJID_1), OS_ERROR); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_MutSemTake(UT_OBJID_1), OS_ERR_INVALID_ID); } void Test_OS_MutSemGetIdByName(void) @@ -141,21 +134,17 @@ void Test_OS_MutSemGetIdByName(void) * Test Case For: * int32 OS_MutSemGetIdByName (uint32 *sem_id, const char *sem_name) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; osal_id_t objid; UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); - actual = OS_MutSemGetIdByName(&objid, "UT"); - UtAssert_True(actual == expected, "OS_MutSemGetIdByName() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGetIdByName(&objid, "UT"), OS_SUCCESS); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); - expected = OS_ERR_NAME_NOT_FOUND; - actual = OS_MutSemGetIdByName(&objid, "NF"); - UtAssert_True(actual == expected, "OS_MutSemGetIdByName() (%ld) == %ld", (long)actual, (long)expected); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGetIdByName(&objid, "NF"), OS_ERR_NAME_NOT_FOUND); - OSAPI_TEST_FUNCTION_RC(OS_MutSemGetIdByName(NULL, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGetIdByName(NULL, "UT"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGetIdByName(&objid, NULL), OS_INVALID_POINTER); } void Test_OS_MutSemGetInfo(void) @@ -164,19 +153,19 @@ void Test_OS_MutSemGetInfo(void) * Test Case For: * int32 OS_MutSemGetInfo (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; OS_mut_sem_prop_t prop; OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_MUTEX, UT_INDEX_1, "ABC", UT_OBJID_OTHER); - actual = OS_MutSemGetInfo(UT_OBJID_1, &prop); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGetInfo(UT_OBJID_1, &prop), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_MutSemGetInfo() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(prop.creator, ==, UT_OBJID_OTHER); UtAssert_True(strcmp(prop.name, "ABC") == 0, "prop.name (%s) == ABC", prop.name); OSAPI_TEST_FUNCTION_RC(OS_MutSemGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGetInfo(UT_OBJID_1, &prop), OS_ERR_INVALID_ID); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-network.c b/src/unit-test-coverage/shared/src/coveragetest-network.c index a9876236b..5d9b11a1f 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-network.c +++ b/src/unit-test-coverage/shared/src/coveragetest-network.c @@ -33,10 +33,7 @@ void Test_OS_NetworkAPI_Init(void) * Test Case For: * int32 OS_NetworkAPI_Init(void) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_NetworkAPI_Init(); - - UtAssert_True(actual == expected, "OS_NetworkAPI_Init() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_NetworkAPI_Init(), OS_SUCCESS); } void Test_OS_NetworkGetHostName(void) @@ -45,20 +42,16 @@ void Test_OS_NetworkGetHostName(void) * Test Case For: * int32 OS_NetworkGetHostName(char *host_name, uint32 name_len) */ - char Buffer[32]; - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + char Buffer[32]; - actual = OS_NetworkGetHostName(Buffer, sizeof(Buffer)); - UtAssert_True(actual == expected, "OS_NetworkGetHostName() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetHostName(Buffer, sizeof(Buffer)), OS_SUCCESS); UT_SetDefaultReturnValue(UT_KEY(OS_NetworkGetHostName_Impl), -4444); - expected = -4444; - actual = OS_NetworkGetHostName(Buffer, sizeof(Buffer)); - UtAssert_True(actual == expected, "OS_NetworkGetHostName(impl error) (%ld) == -4444", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetHostName(Buffer, sizeof(Buffer)), -4444); OSAPI_TEST_FUNCTION_RC(OS_NetworkGetHostName(NULL, sizeof(Buffer)), OS_INVALID_POINTER); OSAPI_TEST_FUNCTION_RC(OS_NetworkGetHostName(Buffer, 0), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetHostName(Buffer, UINT32_MAX), OS_ERR_INVALID_SIZE); } void Test_OS_NetworkGetID(void) @@ -67,17 +60,11 @@ void Test_OS_NetworkGetID(void) * Test Case For: * int32 OS_NetworkGetID(void) */ - int32 expected; - int32 actual; - expected = 42; - actual = OS_NetworkGetID(); - UtAssert_True(actual == expected, "OS_NetworkGetID(nominal) (%ld) == 42", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetID(), 42); UT_SetDefaultReturnValue(UT_KEY(OS_NetworkGetID_Impl), -5555); - expected = -1; - actual = OS_NetworkGetID(); - UtAssert_True(actual == expected, "OS_NetworkGetID(error) (%ld) == -1", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetID(), -1); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-printf.c b/src/unit-test-coverage/shared/src/coveragetest-printf.c index 562a59a9d..5278c91f4 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-printf.c +++ b/src/unit-test-coverage/shared/src/coveragetest-printf.c @@ -38,7 +38,6 @@ void Test_OS_ConsoleAPI_Init(void) * Test Case For: * int32 OS_ConsoleAPI_Init(void) */ - uint32 CallCount = 0; OS_object_token_t token; /* make a custom token to force use of array index 0 */ @@ -51,9 +50,13 @@ void Test_OS_ConsoleAPI_Init(void) /* call for coverage */ OS_ConsoleAPI_Init(); + UtAssert_STUB_COUNT(OS_ConsoleCreate_Impl, 1); + UT_ResetState(UT_KEY(OS_ConsoleCreate_Impl)); - CallCount = UT_GetStubCount(UT_KEY(OS_ConsoleCreate_Impl)); - UtAssert_True(CallCount == 1, "OS_ConsoleCreate_Impl() call count (%lu) == 1", (unsigned long)CallCount); + /* Fail OS_ObjectIdAllocateNew */ + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERROR); + OS_ConsoleAPI_Init(); + UtAssert_STUB_COUNT(OS_ConsoleCreate_Impl, 0); } void Test_OS_printf(void) @@ -100,13 +103,18 @@ void Test_OS_printf(void) /* print a long string that does not fit in the 16-char buffer */ OS_printf_enable(); OS_printf("UnitTest4BufferLengthExceeded"); - UtAssert_True(OS_console_table[0].OverflowEvents == 1, "OverflowEvents (%lu) == 1", - (unsigned long)OS_console_table[0].OverflowEvents); + UtAssert_UINT32_EQ(OS_console_table[0].OverflowEvents, 1); /* test writing with a non-empty console name */ strncpy(OS_console_table[0].device_name, "ut", sizeof(OS_console_table[0].device_name) - 1); OS_printf("UnitTest5"); + /* Cover branch for console name overflowing buffer*/ + OS_console_table[0].WritePos = 0; + OS_console_table[0].ReadPos = 1; + OS_printf("UnitTest5.5"); + UtAssert_UINT32_EQ(OS_console_table[0].OverflowEvents, 3); + /* * For coverage, exercise different paths depending on the return value */ @@ -115,6 +123,15 @@ void Test_OS_printf(void) UT_SetDefaultReturnValue(UT_KEY(OCS_vsnprintf), OS_BUFFER_SIZE + 10); OS_printf("UnitTest7"); + + /* Null case */ + OS_printf(NULL); + + /* OS_ObjectIdGetById failure */ + UT_ResetState(UT_KEY(OS_ConsoleWakeup_Impl)); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OS_printf("a"); + UtAssert_STUB_COUNT(OS_ConsoleWakeup_Impl, 0); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-queue.c b/src/unit-test-coverage/shared/src/coveragetest-queue.c index e7bbabbe6..873d768a9 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-queue.c +++ b/src/unit-test-coverage/shared/src/coveragetest-queue.c @@ -41,10 +41,7 @@ void Test_OS_QueueAPI_Init(void) * Test Case For: * int32 OS_QueueAPI_Init(void) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_QueueAPI_Init(); - - UtAssert_True(actual == expected, "OS_QueueAPI_Init() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueAPI_Init(), OS_SUCCESS); } void Test_OS_QueueCreate(void) @@ -54,30 +51,27 @@ void Test_OS_QueueCreate(void) * int32 OS_QueueCreate (uint32 *queue_id, const char *queue_name, uint32 queue_depth, uint32 data_size, uint32 * flags) */ - int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual = OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(4), 0); - UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(4), 0), OS_SUCCESS); /* test error cases */ - expected = OS_INVALID_POINTER; - actual = OS_QueueCreate(NULL, "UT", OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(4), 0); - UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate(NULL, "UT", OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(4), 0), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate(&objid, NULL, OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(4), 0), OS_INVALID_POINTER); - expected = OS_ERR_INVALID_SIZE; - actual = OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(0), 0); - UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_ERR_INVALID_SIZE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(0), 0), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(UINT32_MAX), 0), + OS_ERR_INVALID_SIZE); UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_ERR_NAME_TOO_LONG; - actual = OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(0), OSAL_SIZE_C(4), 0); - UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(0), OSAL_SIZE_C(4), 0), OS_ERR_NAME_TOO_LONG); UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); - expected = OS_QUEUE_INVALID_SIZE; - actual = OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(1 + OS_QUEUE_MAX_DEPTH), OSAL_SIZE_C(4), 0); - UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_QUEUE_INVALID_SIZE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(1 + OS_QUEUE_MAX_DEPTH), OSAL_SIZE_C(4), 0), + OS_QUEUE_INVALID_SIZE); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate(&objid, "UT", OSAL_BLOCKCOUNT_C(4), OSAL_SIZE_C(4), 0), OS_ERROR); } void Test_OS_QueueDelete(void) @@ -86,12 +80,11 @@ void Test_OS_QueueDelete(void) * Test Case For: * int32 OS_QueueDelete (uint32 queue_id) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - actual = OS_QueueDelete(UT_OBJID_1); + OSAPI_TEST_FUNCTION_RC(OS_QueueDelete(UT_OBJID_1), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_QueueDelete() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueDelete(UT_OBJID_1), OS_ERROR); } void Test_OS_QueueGet(void) @@ -100,26 +93,23 @@ void Test_OS_QueueGet(void) * Test Case For: * int32 OS_QueueGet (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; size_t actual_size; char Buf[4]; - actual = OS_QueueGet(UT_OBJID_1, Buf, sizeof(Buf), &actual_size, 0); - - UtAssert_True(actual == expected, "OS_QueueGet() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet(UT_OBJID_1, Buf, sizeof(Buf), &actual_size, 0), OS_SUCCESS); /* test error cases */ - expected = OS_INVALID_POINTER; - actual = OS_QueueGet(UT_OBJID_1, NULL, sizeof(Buf), &actual_size, 0); - UtAssert_True(actual == expected, "OS_QueueGet() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet(UT_OBJID_1, NULL, sizeof(Buf), &actual_size, 0), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet(UT_OBJID_1, Buf, sizeof(Buf), NULL, 0), OS_INVALID_POINTER); OS_queue_table[1].max_size = sizeof(Buf) + 10; - expected = OS_QUEUE_INVALID_SIZE; - actual = OS_QueueGet(UT_OBJID_1, Buf, sizeof(Buf), &actual_size, 0); - UtAssert_True(actual == expected, "OS_QueueGet() (%ld) == OS_QUEUE_INVALID_SIZE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet(UT_OBJID_1, Buf, sizeof(Buf), &actual_size, 0), OS_QUEUE_INVALID_SIZE); - OSAPI_TEST_FUNCTION_RC(OS_QueueGet(UT_OBJID_1, Buf, 0, &actual_size, 0), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet(UT_OBJID_1, Buf, OSAL_SIZE_C(0), &actual_size, 0), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet(UT_OBJID_1, Buf, OSAL_SIZE_C(UINT32_MAX), &actual_size, 0), OS_ERR_INVALID_SIZE); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet(UT_OBJID_1, Buf, sizeof(Buf), &actual_size, 0), OS_ERROR); } void Test_OS_QueuePut(void) @@ -128,26 +118,22 @@ void Test_OS_QueuePut(void) * Test Case For: * int32 OS_QueuePut (uint32 queue_id, const void *data, uint32 size, uint32 flags) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - const char Data[4] = "xyz"; + const char Data[4] = "xyz"; 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); + OSAPI_TEST_FUNCTION_RC(OS_QueuePut(UT_OBJID_1, Data, sizeof(Data), 0), OS_SUCCESS); /* 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); + OSAPI_TEST_FUNCTION_RC(OS_QueuePut(UT_OBJID_1, NULL, sizeof(Data), 0), OS_INVALID_POINTER); - 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); + OSAPI_TEST_FUNCTION_RC(OS_QueuePut(UT_OBJID_1, Data, 1 + sizeof(Data), 0), OS_QUEUE_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_QueuePut(UT_OBJID_1, Data, OSAL_SIZE_C(0), 0), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_QueuePut(UT_OBJID_1, Data, OSAL_SIZE_C(UINT32_MAX), 0), OS_ERR_INVALID_SIZE); - OSAPI_TEST_FUNCTION_RC(OS_QueuePut(UT_OBJID_1, Data, 0, 0), OS_ERR_INVALID_SIZE); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueuePut(UT_OBJID_1, Data, sizeof(Data), 0), OS_ERROR); } void Test_OS_QueueGetIdByName(void) @@ -156,22 +142,16 @@ void Test_OS_QueueGetIdByName(void) * Test Case For: * int32 OS_QueueGetIdByName (uint32 *queue_id, const char *queue_name) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; osal_id_t objid; UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); - actual = OS_QueueGetIdByName(&objid, "UT"); - UtAssert_True(actual == expected, "OS_QueueGetIdByName() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueGetIdByName(&objid, "UT"), OS_SUCCESS); UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); - expected = OS_ERR_NAME_NOT_FOUND; - actual = OS_QueueGetIdByName(&objid, "NF"); - UtAssert_True(actual == expected, "OS_QueueGetIdByName() (%ld) == %ld", (long)actual, (long)expected); + OSAPI_TEST_FUNCTION_RC(OS_QueueGetIdByName(&objid, "NF"), OS_ERR_NAME_NOT_FOUND); - expected = OS_INVALID_POINTER; - actual = OS_QueueGetIdByName(NULL, "NF"); - UtAssert_True(actual == expected, "OS_QueueGetIdByName() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueGetIdByName(NULL, "NF"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_QueueGetIdByName(&objid, NULL), OS_INVALID_POINTER); } void Test_OS_QueueGetInfo(void) @@ -180,8 +160,6 @@ void Test_OS_QueueGetInfo(void) * Test Case For: * int32 OS_QueueGetInfo (uint32 queue_id, OS_queue_prop_t *queue_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; OS_queue_prop_t queue_prop; osal_id_t id; @@ -189,15 +167,14 @@ void Test_OS_QueueGetInfo(void) OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_QUEUE, UT_INDEX_1, "ABC", UT_OBJID_OTHER); - actual = OS_QueueGetInfo(UT_OBJID_1, &queue_prop); - - UtAssert_True(actual == expected, "OS_QueueGetInfo() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueGetInfo(UT_OBJID_1, &queue_prop), OS_SUCCESS); UtAssert_MemCmp(&queue_prop.creator, &id, sizeof(osal_id_t), "queue_prop.creator == UT_OBJID_OTHER"); UtAssert_True(strcmp(queue_prop.name, "ABC") == 0, "queue_prop.name (%s) == ABC", queue_prop.name); - expected = OS_INVALID_POINTER; - actual = OS_QueueGetInfo(UT_OBJID_1, NULL); - UtAssert_True(actual == expected, "OS_QueueGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_QueueGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueGetInfo(UT_OBJID_1, &queue_prop), OS_ERROR); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-select.c b/src/unit-test-coverage/shared/src/coveragetest-select.c index 7f43131e4..0d8389aff 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-select.c +++ b/src/unit-test-coverage/shared/src/coveragetest-select.c @@ -41,14 +41,14 @@ void Test_OS_SelectSingle(void) * Test Case For: * int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs); */ - int32 expected = OS_SUCCESS; uint32 StateFlags = 0; - int32 actual = OS_SelectSingle(UT_OBJID_1, &StateFlags, 0); - /* Verify Outputs */ - UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle(UT_OBJID_1, &StateFlags, 0), OS_SUCCESS); OSAPI_TEST_FUNCTION_RC(OS_SelectSingle(UT_OBJID_1, NULL, 0), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle(UT_OBJID_1, &StateFlags, 0), OS_ERROR); } void Test_OS_SelectMultiple(void) @@ -59,15 +59,10 @@ void Test_OS_SelectMultiple(void) */ OS_FdSet ReadSet; OS_FdSet WriteSet; - int32 expected = OS_SUCCESS; - int32 actual; OS_SelectFdZero(&ReadSet); OS_SelectFdZero(&WriteSet); - actual = OS_SelectMultiple(&ReadSet, &WriteSet, 0); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "OS_SelectMultiple() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SelectMultiple(&ReadSet, &WriteSet, 0), OS_SUCCESS); } void Test_OS_SelectFdAddClearOps(void) @@ -79,41 +74,37 @@ void Test_OS_SelectFdAddClearOps(void) * int32 OS_SelectFdClear(OS_FdSet *Set, uint32 objid); * bool OS_SelectFdIsSet(OS_FdSet *Set, uint32 objid); */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - uint32 CallCount = 0; OS_FdSet UtSet; - actual = OS_SelectFdZero(&UtSet); + /* Error cases */ + OSAPI_TEST_FUNCTION_RC(OS_SelectFdZero(NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SelectFdAdd(NULL, UT_OBJID_1), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SelectFdClear(NULL, UT_OBJID_1), OS_INVALID_POINTER); + UtAssert_True(!OS_SelectFdIsSet(NULL, UT_OBJID_1), "!OS_SelectFdIsSet(NULL, UT_OBJID_1)"); + + OSAPI_TEST_FUNCTION_RC(OS_SelectFdZero(&UtSet), OS_SUCCESS); /* Verify Outputs */ - UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); - CallCount = UT_GetStubCount(UT_KEY(OCS_memset)); - UtAssert_True(CallCount == 1, "memset() call count (%lu) == 1", (unsigned long)CallCount); + UtAssert_STUB_COUNT(OCS_memset, 1); UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_1), "OS_SelectFdIsSet(1) == false"); UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_2), "OS_SelectFdIsSet(2) == false"); - expected = OS_SUCCESS; - actual = OS_SelectFdAdd(&UtSet, UT_OBJID_1); - UtAssert_True(actual == expected, "OS_SelectFdAdd() (%ld) == %ld", (long)actual, (long)expected); + OSAPI_TEST_FUNCTION_RC(OS_SelectFdAdd(&UtSet, UT_OBJID_1), OS_SUCCESS); + UtAssert_True(OS_SelectFdIsSet(&UtSet, UT_OBJID_1), "OS_SelectFdIsSet(1) == true"); UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_2), "OS_SelectFdIsSet(2) == false"); - actual = OS_SelectFdAdd(&UtSet, UT_OBJID_2); - UtAssert_True(actual == expected, "OS_SelectFdAdd() (%ld) == %ld", (long)actual, (long)expected); + OSAPI_TEST_FUNCTION_RC(OS_SelectFdAdd(&UtSet, UT_OBJID_2), OS_SUCCESS); + UtAssert_True(OS_SelectFdIsSet(&UtSet, UT_OBJID_1), "OS_SelectFdIsSet(1) == true"); UtAssert_True(OS_SelectFdIsSet(&UtSet, UT_OBJID_2), "OS_SelectFdIsSet(2) == true"); - actual = OS_SelectFdClear(&UtSet, UT_OBJID_2); - UtAssert_True(actual == expected, "OS_SelectFdClear() (%ld) == %ld", (long)actual, (long)expected); + OSAPI_TEST_FUNCTION_RC(OS_SelectFdClear(&UtSet, UT_OBJID_2), OS_SUCCESS); UtAssert_True(OS_SelectFdIsSet(&UtSet, UT_OBJID_1), "OS_SelectFdIsSet(1) == true"); UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_2), "OS_SelectFdIsSet(2) == false"); - expected = -42; - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdToArrayIndex), expected); - actual = OS_SelectFdAdd(&UtSet, UT_OBJID_2); - UtAssert_True(actual == expected, "OS_SelectFdAdd() (%ld) == %ld", (long)actual, (long)expected); - actual = OS_SelectFdClear(&UtSet, UT_OBJID_1); - UtAssert_True(actual == expected, "OS_SelectFdClear() (%ld) == %ld", (long)actual, (long)expected); + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdToArrayIndex), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SelectFdAdd(&UtSet, UT_OBJID_2), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SelectFdClear(&UtSet, UT_OBJID_1), OS_ERROR); UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_1), "OS_SelectFdIsSet(1) == false"); UtAssert_True(!OS_SelectFdIsSet(&UtSet, UT_OBJID_2), "OS_SelectFdIsSet(2) == false"); diff --git a/src/unit-test-coverage/shared/src/coveragetest-sockets.c b/src/unit-test-coverage/shared/src/coveragetest-sockets.c index de6694a02..82f447067 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-sockets.c +++ b/src/unit-test-coverage/shared/src/coveragetest-sockets.c @@ -68,13 +68,16 @@ void Test_OS_CreateSocketName(void) token.obj_id = UT_OBJID_1; token.obj_type = OS_OBJECT_TYPE_OS_STREAM; + /* Hit off-nominal branches, nominal covered by use of helper in code */ UT_SetDefaultReturnValue(UT_KEY(OS_SocketAddrToString_Impl), OS_ERROR); OS_CreateSocketName(&token, &testaddr, "ut"); + UT_SetDefaultReturnValue(UT_KEY(OS_SocketAddrGetPort_Impl), OS_ERROR); + OS_CreateSocketName(&token, &testaddr, "ut"); /* * The function should have called snprintf() to create the name */ - UtAssert_True(UT_GetStubCount(UT_KEY(OCS_snprintf)) == 2, "OS_CreateSocketName() invoked snprintf()"); + UtAssert_STUB_COUNT(OCS_snprintf, 3); UtAssert_True(OS_stream_table[0].stream_name[0] != 'x', "OS_CreateSocketName() set stream name"); } @@ -89,16 +92,15 @@ void Test_OS_SocketOpen(void) * Test Case For: * int32 OS_SocketOpen(uint32 *sock_id, OS_SocketDomain_t Domain, OS_SocketType_t Type) */ - int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual = OS_SocketOpen(&objid, OS_SocketDomain_INET, OS_SocketType_STREAM); - UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketOpen(&objid, OS_SocketDomain_INET, OS_SocketType_STREAM), OS_SUCCESS); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - expected = OS_INVALID_POINTER; - actual = OS_SocketOpen(NULL, OS_SocketDomain_INVALID, OS_SocketType_INVALID); - UtAssert_True(actual == expected, "OS_SocketOpen(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketOpen(NULL, OS_SocketDomain_INVALID, OS_SocketType_INVALID), OS_INVALID_POINTER); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SocketOpen(&objid, OS_SocketDomain_INET, OS_SocketType_STREAM), OS_ERROR); } /***************************************************************************** @@ -112,37 +114,34 @@ void Test_OS_SocketBind(void) * Test Case For: * int32 OS_SocketBind(uint32 sock_id, const OS_SockAddr_t *Addr) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; OS_SockAddr_t Addr; OS_stream_table[1].socket_domain = OS_SocketDomain_INET; memset(&Addr, 0, sizeof(Addr)); - actual = OS_SocketBind(UT_OBJID_1, &Addr); - UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); + /* Fail implementation */ + UT_SetDeferredRetcode(UT_KEY(OS_SocketBind_Impl), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SocketBind(UT_OBJID_1, &Addr), OS_ERROR); - expected = OS_INVALID_POINTER; - actual = OS_SocketBind(UT_OBJID_1, NULL); - UtAssert_True(actual == expected, "OS_SocketBind(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketBind(UT_OBJID_1, &Addr), OS_SUCCESS); + + OSAPI_TEST_FUNCTION_RC(OS_SocketBind(UT_OBJID_1, NULL), OS_INVALID_POINTER); /* * Should fail if not a socket domain */ OS_stream_table[1].socket_domain = OS_SocketDomain_INVALID; - expected = OS_ERR_INCORRECT_OBJ_TYPE; - actual = OS_SocketBind(UT_OBJID_1, &Addr); - UtAssert_True(actual == expected, "OS_SocketBind() non-socket (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketBind(UT_OBJID_1, &Addr), OS_ERR_INCORRECT_OBJ_TYPE); /* * Should fail if already bound */ OS_stream_table[1].socket_domain = OS_SocketDomain_INET; OS_stream_table[1].stream_state = OS_STREAM_STATE_BOUND; - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_SocketBind(UT_OBJID_1, &Addr); - UtAssert_True(actual == expected, "OS_SocketBind() already bound (%ld) == OS_ERR_INCORRECT_OBJ_STATE", - (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketBind(UT_OBJID_1, &Addr), OS_ERR_INCORRECT_OBJ_STATE); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SocketBind(UT_OBJID_1, &Addr), OS_ERROR); } /***************************************************************************** @@ -156,8 +155,6 @@ void Test_OS_SocketAccept(void) * Test Case For: * int32 OS_SocketAccept(uint32 sock_id, uint32 *connsock_id, OS_SockAddr_t *Addr, int32 timeout) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; osal_index_t local_id; osal_id_t connsock_id; OS_SockAddr_t Addr; @@ -169,40 +166,37 @@ void Test_OS_SocketAccept(void) OS_stream_table[local_id].stream_state = OS_STREAM_STATE_BOUND; OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_STREAM, local_id); memset(&Addr, 0, sizeof(Addr)); - actual = OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0); - UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0), OS_SUCCESS); - expected = OS_INVALID_POINTER; - actual = OS_SocketAccept(UT_OBJID_1, NULL, NULL, 0); - UtAssert_True(actual == expected, "OS_SocketAccept(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept(UT_OBJID_1, NULL, &Addr, 0), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept(UT_OBJID_1, &connsock_id, NULL, 0), OS_INVALID_POINTER); /* * Should fail if not a stream socket */ OS_stream_table[1].socket_type = OS_SocketType_INVALID; - expected = OS_ERR_INCORRECT_OBJ_TYPE; - actual = OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0); - UtAssert_True(actual == expected, "OS_SocketAccept() non-stream (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0), OS_ERR_INCORRECT_OBJ_TYPE); /* * Should fail if already connected */ OS_stream_table[1].socket_type = OS_SocketType_STREAM; OS_stream_table[1].stream_state = OS_STREAM_STATE_BOUND | OS_STREAM_STATE_CONNECTED; - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0); - UtAssert_True(actual == expected, "OS_SocketAccept() already bound (%ld) == OS_ERR_INCORRECT_OBJ_STATE", - (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0), OS_ERR_INCORRECT_OBJ_STATE); /* * Underlying implementation failure test */ OS_stream_table[1].stream_state = OS_STREAM_STATE_BOUND; - expected = -1234; UT_SetDefaultReturnValue(UT_KEY(OS_SocketAccept_Impl), -1234); - actual = OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0); - UtAssert_True(actual == expected, "OS_SocketAccept() underlying failure (%ld) == -1234", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0), -1234); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0), OS_ERROR); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept(UT_OBJID_1, &connsock_id, &Addr, 0), OS_ERR_INVALID_ID); } /***************************************************************************** @@ -216,8 +210,6 @@ void Test_OS_SocketConnect(void) * Test Case For: * int32 OS_SocketConnect(uint32 sock_id, const OS_SockAddr_t *Addr, int32 Timeout) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; OS_SockAddr_t Addr; osal_index_t idbuf; @@ -228,33 +220,33 @@ void Test_OS_SocketConnect(void) OS_stream_table[idbuf].socket_type = OS_SocketType_STREAM; OS_stream_table[idbuf].stream_state = 0; - actual = OS_SocketConnect(UT_OBJID_1, &Addr, 0); + /* Fail implementation */ + UT_SetDeferredRetcode(UT_KEY(OS_SocketConnect_Impl), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect(UT_OBJID_1, &Addr, 0), OS_ERROR); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect(UT_OBJID_1, &Addr, 0), OS_SUCCESS); - expected = OS_INVALID_POINTER; - actual = OS_SocketConnect(UT_OBJID_1, NULL, 0); - UtAssert_True(actual == expected, "OS_SocketConnect(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect(UT_OBJID_1, NULL, 0), OS_INVALID_POINTER); /* * Should fail if not a stream socket */ OS_stream_table[1].socket_domain = OS_SocketDomain_INVALID; - OS_stream_table[1].socket_type = OS_SocketType_INVALID; - expected = OS_ERR_INCORRECT_OBJ_TYPE; - actual = OS_SocketConnect(UT_OBJID_1, &Addr, 0); - UtAssert_True(actual == expected, "OS_SocketConnect() non-stream (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect(UT_OBJID_1, &Addr, 0), OS_ERR_INCORRECT_OBJ_TYPE); /* * Should fail if already connected */ OS_stream_table[1].socket_domain = OS_SocketDomain_INET; - OS_stream_table[1].socket_type = OS_SocketType_STREAM; OS_stream_table[1].stream_state = OS_STREAM_STATE_CONNECTED; - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_SocketConnect(UT_OBJID_1, &Addr, 0); - UtAssert_True(actual == expected, "OS_SocketConnect() already connected (%ld) == OS_ERR_INCORRECT_OBJ_STATE", - (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect(UT_OBJID_1, &Addr, 0), OS_ERR_INCORRECT_OBJ_STATE); + + /* Only stream type will fail if connected */ + OS_stream_table[1].socket_type = OS_SocketType_DATAGRAM; + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect(UT_OBJID_1, &Addr, 0), OS_SUCCESS); + + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect(UT_OBJID_1, &Addr, 0), OS_ERR_INVALID_ID); } /***************************************************************************** @@ -268,8 +260,6 @@ void Test_OS_SocketShutdown(void) * Test Case For: * int32 OS_SocketShutdown(osal_id_t sock_id, OS_SocketShutdownMode_t Mode) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; osal_index_t idbuf; idbuf = UT_INDEX_1; @@ -280,65 +270,57 @@ void Test_OS_SocketShutdown(void) OS_STREAM_STATE_CONNECTED | OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; /* nominal */ - actual = OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READ); - UtAssert_True(actual == expected, "OS_SocketShutdown() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READ), OS_SUCCESS); UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_READABLE) == 0, "Stream bits cleared"); UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_WRITABLE) != 0, "Stream bits unchanged"); OS_stream_table[idbuf].stream_state = OS_STREAM_STATE_CONNECTED | OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; - actual = OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_WRITE); - UtAssert_True(actual == expected, "OS_SocketShutdown() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_WRITE), OS_SUCCESS); UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_READABLE) != 0, "Stream bits unchanged"); UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_WRITABLE) == 0, "Stream bits cleared"); OS_stream_table[idbuf].stream_state = OS_STREAM_STATE_CONNECTED | OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; - actual = OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READWRITE); - UtAssert_True(actual == expected, "OS_SocketShutdown() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READWRITE), OS_SUCCESS); UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_READABLE) == 0, "Stream bits cleared"); - UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_WRITABLE) == 0, "Stream bits unchanged"); + UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_WRITABLE) == 0, "Stream bits cleared"); /* Invalid Argument */ - expected = OS_ERR_INVALID_ARGUMENT; OS_stream_table[idbuf].stream_state = OS_STREAM_STATE_CONNECTED | OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; - actual = OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_NONE); - UtAssert_True(actual == expected, "OS_SocketShutdown() (%ld) == OS_ERR_INVALID_ARGUMENT", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_NONE), OS_ERR_INVALID_ARGUMENT); UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_READABLE) != 0, "Stream bits unchanged"); UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_WRITABLE) != 0, "Stream bits unchanged"); /* Implementation failure */ - expected = -1234; - UT_SetDefaultReturnValue(UT_KEY(OS_SocketShutdown_Impl), expected); - actual = OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READWRITE); - UtAssert_True(actual == expected, "OS_SocketShutdown() impl failure (%ld) == %ld", (long)actual, (long)expected); + UT_SetDeferredRetcode(UT_KEY(OS_SocketShutdown_Impl), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READWRITE), OS_ERROR); UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_READABLE) != 0, "Stream bits unchanged"); UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_WRITABLE) != 0, "Stream bits unchanged"); - UT_ResetState(UT_KEY(OS_SocketShutdown_Impl)); /* Invalid ID */ - expected = OS_ERR_INVALID_ID; - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), expected); - actual = OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READWRITE); - UtAssert_True(actual == expected, "OS_SocketShutdown() invalid ID (%ld) == OS_ERR_INVALID_ID", (long)actual); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READWRITE), OS_ERR_INVALID_ID); UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_READABLE) != 0, "Stream bits unchanged"); UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_WRITABLE) != 0, "Stream bits unchanged"); - UT_ResetState(UT_KEY(OS_ObjectIdGetById)); /* Unconnected socket */ - expected = OS_ERR_INCORRECT_OBJ_STATE; OS_stream_table[idbuf].stream_state = 0; - actual = OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READWRITE); - UtAssert_True(actual == expected, "OS_SocketShutdown() unconnected (%ld) == OS_ERR_INCORRECT_OBJ_STATE", - (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READWRITE), + OS_ERR_INCORRECT_OBJ_STATE); + + /* Unconnected datagram should clear bits */ + OS_stream_table[idbuf].socket_type = OS_SocketType_DATAGRAM; + OS_stream_table[idbuf].stream_state = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; + OSAPI_TEST_FUNCTION_RC(OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READWRITE), OS_SUCCESS); + UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_READABLE) == 0, "Stream bits cleared"); + UtAssert_True((OS_stream_table[idbuf].stream_state & OS_STREAM_STATE_WRITABLE) == 0, "Stream bits cleared"); /* Invalid socket type */ - expected = OS_ERR_INCORRECT_OBJ_TYPE; OS_stream_table[idbuf].socket_domain = OS_SocketDomain_INVALID; - actual = OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READWRITE); - UtAssert_True(actual == expected, "OS_SocketShutdown() unconnected (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", - (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketShutdown(UT_OBJID_1, OS_SocketShutdownMode_SHUT_READWRITE), + OS_ERR_INCORRECT_OBJ_TYPE); } /***************************************************************************** @@ -353,8 +335,6 @@ void Test_OS_SocketRecvFrom(void) * OS_SocketRecvFrom(uint32 sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) */ char Buf; - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; OS_SockAddr_t Addr; osal_index_t idbuf; @@ -363,36 +343,31 @@ void Test_OS_SocketRecvFrom(void) OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_STREAM, idbuf); OS_stream_table[idbuf].socket_type = OS_SocketType_DATAGRAM; OS_stream_table[idbuf].stream_state = OS_STREAM_STATE_BOUND; - actual = OS_SocketRecvFrom(UT_OBJID_1, &Buf, 1, &Addr, 0); - actual = OS_SocketRecvFrom(UT_OBJID_1, &Buf, sizeof(Buf), &Addr, 0); - UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom(UT_OBJID_1, &Buf, 1, &Addr, 0), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom(UT_OBJID_1, &Buf, sizeof(Buf), &Addr, 0), OS_SUCCESS); - expected = OS_INVALID_POINTER; - actual = OS_SocketRecvFrom(UT_OBJID_1, NULL, OSAL_SIZE_C(0), NULL, 0); - UtAssert_True(actual == expected, "OS_SocketRecvFrom(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom(UT_OBJID_1, NULL, OSAL_SIZE_C(0), NULL, 0), OS_INVALID_POINTER); /* * Should fail if not a datagram socket */ OS_stream_table[1].socket_type = OS_SocketType_INVALID; - expected = OS_ERR_INCORRECT_OBJ_TYPE; - actual = OS_SocketRecvFrom(UT_OBJID_1, &Buf, sizeof(Buf), &Addr, 0); - UtAssert_True(actual == expected, "OS_SocketRecvFrom() non-datagram (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", - (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom(UT_OBJID_1, &Buf, sizeof(Buf), &Addr, 0), OS_ERR_INCORRECT_OBJ_TYPE); /* * Should fail if not bound */ OS_stream_table[1].socket_type = OS_SocketType_DATAGRAM; OS_stream_table[1].stream_state = 0; - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_SocketRecvFrom(UT_OBJID_1, &Buf, sizeof(Buf), &Addr, 0); - UtAssert_True(actual == expected, "OS_SocketRecvFrom() non-bound (%ld) == OS_ERR_INCORRECT_OBJ_STATE", - (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom(UT_OBJID_1, &Buf, sizeof(Buf), &Addr, 0), OS_ERR_INCORRECT_OBJ_STATE); /* Fail w/OS_ERR_INVALID_SIZE */ - OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom(UT_OBJID_1, &Buf, 0, &Addr, 0), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom(UT_OBJID_1, &Buf, OSAL_SIZE_C(0), &Addr, 0), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom(UT_OBJID_1, &Buf, OSAL_SIZE_C(UINT32_MAX), &Addr, 0), OS_ERR_INVALID_SIZE); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom(UT_OBJID_1, &Buf, sizeof(Buf), &Addr, 0), OS_ERR_INVALID_ID); } /***************************************************************************** @@ -406,9 +381,7 @@ void Test_OS_SocketSendTo(void) * Test Case For: * int32 OS_SocketSendTo(uint32 sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr) */ - char Buf = 'A'; - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + char Buf = 'A'; OS_SockAddr_t Addr; osal_index_t idbuf; @@ -417,30 +390,23 @@ void Test_OS_SocketSendTo(void) OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_STREAM, idbuf); OS_stream_table[idbuf].socket_type = OS_SocketType_DATAGRAM; OS_stream_table[idbuf].stream_state = OS_STREAM_STATE_BOUND; - actual = OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), &Addr); - - UtAssert_True(actual == expected, "OS_SocketSendTo() (%ld) == OS_SUCCESS", (long)actual); - expected = OS_INVALID_POINTER; - actual = OS_SocketSendTo(UT_OBJID_1, NULL, sizeof(Buf), &Addr); - UtAssert_True(actual == expected, "OS_SocketSendTo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), &Addr), OS_SUCCESS); - expected = OS_INVALID_POINTER; - actual = OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), NULL); - UtAssert_True(actual == expected, "OS_SocketSendTo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketSendTo(UT_OBJID_1, NULL, sizeof(Buf), &Addr), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), NULL), OS_INVALID_POINTER); - expected = OS_ERR_INVALID_SIZE; - actual = OS_SocketSendTo(UT_OBJID_1, &Buf, OSAL_SIZE_C(0), &Addr); - UtAssert_True(actual == expected, "OS_SocketSendTo(0) (%ld) == OS_ERR_INVALID_SIZE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketSendTo(UT_OBJID_1, &Buf, OSAL_SIZE_C(0), &Addr), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_SocketSendTo(UT_OBJID_1, &Buf, OSAL_SIZE_C(UINT32_MAX), &Addr), OS_ERR_INVALID_SIZE); /* * Should fail if not a datagram socket */ OS_stream_table[1].socket_type = OS_SocketType_INVALID; - expected = OS_ERR_INCORRECT_OBJ_TYPE; - actual = OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), &Addr); - UtAssert_True(actual == expected, "OS_SocketSendTo() non-datagram (%ld) == OS_ERR_INCORRECT_OBJ_TYPE", - (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), &Addr), OS_ERR_INCORRECT_OBJ_TYPE); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_SocketSendTo(UT_OBJID_1, &Buf, sizeof(Buf), &Addr), OS_ERR_INVALID_ID); } /***************************************************************************** @@ -454,23 +420,16 @@ void Test_OS_SocketGetIdByName(void) * Test Case For: * int32 OS_SocketGetIdByName (uint32 *sock_id, const char *sock_name) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; osal_id_t objid; - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); - actual = OS_SocketGetIdByName(&objid, "UT"); - UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdFindByName), 1, OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SocketGetIdByName(&objid, "UT"), OS_SUCCESS); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); - expected = OS_ERR_NAME_NOT_FOUND; - actual = OS_SocketGetIdByName(&objid, "NF"); - UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == %ld", (long)actual, (long)expected); + OSAPI_TEST_FUNCTION_RC(OS_SocketGetIdByName(&objid, "NF"), OS_ERR_NAME_NOT_FOUND); - expected = OS_INVALID_POINTER; - actual = OS_SocketGetIdByName(NULL, NULL); - UtAssert_True(actual == expected, "Test_OS_SocketGetIdByName(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketGetIdByName(NULL, "UT"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SocketGetIdByName(&objid, NULL), OS_INVALID_POINTER); } /***************************************************************************** @@ -484,20 +443,18 @@ void Test_OS_SocketGetInfo(void) * Test Case For: * int32 OS_SocketGetInfo (uint32 sock_id, OS_socket_prop_t *sock_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; OS_socket_prop_t prop; OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, "ABC", UT_OBJID_OTHER); - actual = OS_SocketGetInfo(UT_OBJID_1, &prop); - UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketGetInfo(UT_OBJID_1, &prop), OS_SUCCESS); OSAPI_TEST_OBJID(prop.creator, ==, UT_OBJID_OTHER); UtAssert_True(strcmp(prop.name, "ABC") == 0, "prop.name (%s) == ABC", prop.name); - expected = OS_INVALID_POINTER; - actual = OS_SocketGetInfo(UT_OBJID_1, NULL); - UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_SocketGetInfo(UT_OBJID_1, &prop), OS_ERR_INVALID_ID); } void Test_OS_SocketAddr(void) @@ -512,42 +469,27 @@ void Test_OS_SocketAddr(void) OS_SockAddr_t Addr; char Buffer[32]; uint16 PortNum; - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; /* First verify nominal case for each function */ - actual = OS_SocketAddrInit(&Addr, OS_SocketDomain_INVALID); - UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); - - actual = OS_SocketAddrToString(Buffer, sizeof(Buffer), &Addr); - UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); - - actual = OS_SocketAddrFromString(&Addr, Buffer); - UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); - - actual = OS_SocketAddrSetPort(&Addr, 1234); - UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); - - actual = OS_SocketAddrGetPort(&PortNum, &Addr); - UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrInit(&Addr, OS_SocketDomain_INVALID), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrToString(Buffer, sizeof(Buffer), &Addr), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrFromString(&Addr, Buffer), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrSetPort(&Addr, 1234), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrGetPort(&PortNum, &Addr), OS_SUCCESS); /* Verify invalid pointer checking in each function */ - expected = OS_INVALID_POINTER; - - actual = OS_SocketAddrInit(NULL, OS_SocketDomain_INVALID); - UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual); - - actual = OS_SocketAddrToString(NULL, OSAL_SIZE_C(0), NULL); - UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); - - actual = OS_SocketAddrFromString(NULL, NULL); - UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_INVALID_POINTER", (long)actual); - - actual = OS_SocketAddrSetPort(NULL, 1234); - UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_INVALID_POINTER", (long)actual); - - actual = OS_SocketAddrGetPort(NULL, NULL); - UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrInit(NULL, OS_SocketDomain_INVALID), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrToString(Buffer, 1, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrToString(NULL, 1, &Addr), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrFromString(&Addr, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrFromString(NULL, Buffer), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrSetPort(NULL, 1234), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrGetPort(&PortNum, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrGetPort(NULL, &Addr), OS_INVALID_POINTER); + + /* Invalid sizes */ + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrToString(Buffer, OSAL_SIZE_C(0), &Addr), OS_ERR_INVALID_SIZE); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrToString(Buffer, OSAL_SIZE_C(UINT32_MAX), &Addr), OS_ERR_INVALID_SIZE); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-task.c b/src/unit-test-coverage/shared/src/coveragetest-task.c index 7c288ca8e..4668594df 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-task.c +++ b/src/unit-test-coverage/shared/src/coveragetest-task.c @@ -53,31 +53,27 @@ void Test_OS_TaskEntryPoint(void) * the internal "prepare" call will return INVALID_ID, * which in turn will invoke OS_TaskExit() */ - uint32 CallCount = 0; - UT_TestHook_Count = 0; UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERROR); OS_TaskEntryPoint(UT_OBJID_1); UtAssert_True(UT_TestHook_Count == 0, "UT_TestHook_Count (%lu) == 0", (unsigned long)UT_TestHook_Count); - CallCount = UT_GetStubCount(UT_KEY(OS_TaskMatch_Impl)); - UtAssert_True(CallCount == 0, "OS_TaskMatch_Impl() count (%lu) == 0", (unsigned long)CallCount); - - CallCount = UT_GetStubCount(UT_KEY(OS_TaskRegister_Impl)); - UtAssert_True(CallCount == 0, "OS_TaskRegister_Impl() count (%lu) == 0", (unsigned long)CallCount); + UtAssert_STUB_COUNT(OS_TaskMatch_Impl, 0); + UtAssert_STUB_COUNT(OS_TaskRegister_Impl, 0); OS_global_task_table[1].active_id = UT_OBJID_1; OS_task_table[1].entry_function_pointer = UT_TestHook; OS_TaskEntryPoint(UT_OBJID_1); UtAssert_True(UT_TestHook_Count == 1, "UT_TestHook_Count (%lu) == 1", (unsigned long)UT_TestHook_Count); - CallCount = UT_GetStubCount(UT_KEY(OS_TaskMatch_Impl)); - UtAssert_True(CallCount == 1, "OS_TaskMatch_Impl() count (%lu) == 1", (unsigned long)CallCount); + UtAssert_STUB_COUNT(OS_TaskMatch_Impl, 1); + UtAssert_STUB_COUNT(OS_TaskRegister_Impl, 1); - CallCount = UT_GetStubCount(UT_KEY(OS_TaskRegister_Impl)); - UtAssert_True(CallCount == 1, "OS_TaskRegister_Impl() count (%lu) == 1", (unsigned long)CallCount); - - OS_global_task_table[1].active_id = OS_OBJECT_ID_UNDEFINED; OS_task_table[1].entry_function_pointer = NULL; + UT_TestHook_Count = 0; + OS_TaskEntryPoint(UT_OBJID_1); + UtAssert_True(UT_TestHook_Count == 0, "UT_TestHook_Count (%lu) == 0", (unsigned long)UT_TestHook_Count); + + OS_global_task_table[1].active_id = OS_OBJECT_ID_UNDEFINED; } void Test_OS_TaskAPI_Init(void) @@ -86,10 +82,7 @@ void Test_OS_TaskAPI_Init(void) * Test Case For: * int32 OS_TaskAPI_Init(void) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_TaskAPI_Init(); - - UtAssert_True(actual == expected, "OS_TaskAPI_Init() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TaskAPI_Init(), OS_SUCCESS); } /* @@ -105,32 +98,38 @@ void Test_OS_TaskCreate(void) * int32 OS_TaskCreate (uint32 *task_id, const char *task_name, osal_task_entry function_pointer, * uint32 *stack_pointer, uint32 stack_size, uint32 priority, uint32 flags) */ - int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual; - - actual = - OS_TaskCreate(&objid, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(128), OSAL_PRIORITY_C(0), 0); - UtAssert_True(actual == expected, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC( + OS_TaskCreate(&objid, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(128), OSAL_PRIORITY_C(0), 0), + OS_SUCCESS); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); OSAPI_TEST_FUNCTION_RC( - OS_TaskCreate(NULL, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(0), OSAL_PRIORITY_C(0), 0), + OS_TaskCreate(NULL, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(128), OSAL_PRIORITY_C(0), 0), OS_INVALID_POINTER); OSAPI_TEST_FUNCTION_RC( - OS_TaskCreate(&objid, NULL, UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(0), OSAL_PRIORITY_C(0), 0), + OS_TaskCreate(&objid, NULL, UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(128), OSAL_PRIORITY_C(0), 0), OS_INVALID_POINTER); OSAPI_TEST_FUNCTION_RC( - OS_TaskCreate(&objid, "UT", NULL, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(0), OSAL_PRIORITY_C(0), 0), + OS_TaskCreate(&objid, "UT", NULL, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(128), OSAL_PRIORITY_C(0), 0), OS_INVALID_POINTER); OSAPI_TEST_FUNCTION_RC( OS_TaskCreate(&objid, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(0), OSAL_PRIORITY_C(0), 0), OS_ERR_INVALID_SIZE); - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate(&objid, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(UINT32_MAX), + OSAL_PRIORITY_C(0), 0), + OS_ERR_INVALID_SIZE); + + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); OSAPI_TEST_FUNCTION_RC( OS_TaskCreate(&objid, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(128), OSAL_PRIORITY_C(0), 0), OS_ERR_NAME_TOO_LONG); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdAllocateNew), 1, OS_ERR_NO_FREE_IDS); + OSAPI_TEST_FUNCTION_RC( + OS_TaskCreate(&objid, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(128), OSAL_PRIORITY_C(0), 0), + OS_ERR_NO_FREE_IDS); } void Test_OS_TaskDelete(void) @@ -139,21 +138,23 @@ void Test_OS_TaskDelete(void) * Test Case For: * int32 OS_TaskDelete (uint32 task_id) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - UT_TestHook_Count = 0; OS_task_table[1].delete_hook_pointer = UT_TestHook; - actual = OS_TaskDelete(UT_OBJID_1); - - UtAssert_True(actual == expected, "OS_TaskDelete() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TaskDelete(UT_OBJID_1), OS_SUCCESS); UtAssert_True(UT_TestHook_Count == 1, "UT_TestHook_Count (%lu) == 1", (unsigned long)UT_TestHook_Count); + UT_TestHook_Count = 0; - UT_SetDefaultReturnValue(UT_KEY(OS_TaskDelete_Impl), OS_ERROR); + UT_SetDeferredRetcode(UT_KEY(OS_TaskDelete_Impl), 1, OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_TaskDelete(UT_OBJID_1), OS_ERROR); - UtAssert_True(UT_TestHook_Count == 1, "UT_TestHook_Count (%lu) == 1", (unsigned long)UT_TestHook_Count); + UtAssert_True(UT_TestHook_Count == 0, "UT_TestHook_Count (%lu) == 0", (unsigned long)UT_TestHook_Count); + /* Null case */ OS_task_table[1].delete_hook_pointer = NULL; + OSAPI_TEST_FUNCTION_RC(OS_TaskDelete(UT_OBJID_1), OS_SUCCESS); + UtAssert_True(UT_TestHook_Count == 0, "UT_TestHook_Count (%lu) == 0", (unsigned long)UT_TestHook_Count); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TaskDelete(UT_OBJID_1), OS_ERR_INVALID_ID); } void Test_OS_TaskExit(void) @@ -167,6 +168,11 @@ void Test_OS_TaskExit(void) /* TaskExit should have called OS_ObjectIdFinalizeDelete to clear the active_id */ UtAssert_STUB_COUNT(OS_ObjectIdFinalizeDelete, 1); + UT_ResetState(UT_KEY(OS_ObjectIdFinalizeDelete)); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OS_TaskExit(); + UtAssert_STUB_COUNT(OS_ObjectIdFinalizeDelete, 0); } void Test_OS_TaskDelay(void) { @@ -174,10 +180,7 @@ void Test_OS_TaskDelay(void) * Test Case For: * int32 OS_TaskDelay(uint32 millisecond) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_TaskDelay(1); - - UtAssert_True(actual == expected, "OS_TaskDelay() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TaskDelay(1), OS_SUCCESS); } void Test_OS_TaskSetPriority(void) { @@ -185,10 +188,13 @@ void Test_OS_TaskSetPriority(void) * Test Case For: * int32 OS_TaskSetPriority (uint32 task_id, uint32 new_priority) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_TaskSetPriority(UT_OBJID_1, OSAL_PRIORITY_C(1)); + OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority(UT_OBJID_1, OSAL_PRIORITY_C(1)), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_TaskSetPriority() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority(UT_OBJID_1, OSAL_PRIORITY_C(1)), OS_ERR_INVALID_ID); + + UT_SetDeferredRetcode(UT_KEY(OS_TaskSetPriority_Impl), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority(UT_OBJID_1, OSAL_PRIORITY_C(1)), OS_ERROR); } void Test_OS_TaskGetId(void) { @@ -211,21 +217,16 @@ void Test_OS_TaskGetIdByName(void) * Test Case For: * int32 OS_TaskGetIdByName (uint32 *task_id, const char *task_name) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - osal_id_t objid = OS_OBJECT_ID_UNDEFINED; + osal_id_t objid = OS_OBJECT_ID_UNDEFINED; - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); - actual = OS_TaskGetIdByName(&objid, "UT"); - UtAssert_True(actual == expected, "OS_TaskGetIdByName() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdFindByName), 1, OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetIdByName(&objid, "UT"), OS_SUCCESS); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); - expected = OS_ERR_NAME_NOT_FOUND; - actual = OS_TaskGetIdByName(&objid, "NF"); - UtAssert_True(actual == expected, "OS_TaskGetIdByName() (%ld) == %ld", (long)actual, (long)expected); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetIdByName(&objid, "NF"), OS_ERR_NAME_NOT_FOUND); - OSAPI_TEST_FUNCTION_RC(OS_TaskGetIdByName(NULL, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetIdByName(&objid, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetIdByName(NULL, "UT"), OS_INVALID_POINTER); } void Test_OS_TaskGetInfo(void) @@ -234,27 +235,32 @@ void Test_OS_TaskGetInfo(void) * Test Case For: * int32 OS_TaskGetInfo (uint32 task_id, OS_task_prop_t *task_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; OS_task_prop_t task_prop; OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_TASK, UT_INDEX_1, "ABC", UT_OBJID_OTHER); OS_task_table[1].stack_size = OSAL_SIZE_C(222); OS_task_table[1].priority = OSAL_PRIORITY_C(133); - actual = OS_TaskGetInfo(UT_OBJID_1, &task_prop); - - UtAssert_True(actual == expected, "OS_TaskGetInfo() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo(UT_OBJID_1, &task_prop), OS_SUCCESS); OSAPI_TEST_OBJID(task_prop.creator, ==, UT_OBJID_OTHER); UtAssert_True(strcmp(task_prop.name, "ABC") == 0, "task_prop.name (%s) == ABC", task_prop.name); UtAssert_True(task_prop.stack_size == 222, "task_prop.stack_size (%lu) == 222", (unsigned long)task_prop.stack_size); UtAssert_True(task_prop.priority == 133, "task_prop.priority (%lu) == 133", (unsigned long)task_prop.priority); + /* Null name entry path */ + task_prop.name[0] = 0; + OS_global_task_table[1].name_entry = NULL; + OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo(UT_OBJID_1, &task_prop), OS_SUCCESS); + UtAssert_True(strlen(task_prop.name) == 0, "task_prop.name empty"); + OS_task_table[1].stack_size = OSAL_SIZE_C(0); OS_task_table[1].priority = OSAL_PRIORITY_C(0); OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo(UT_OBJID_1, &task_prop), OS_ERR_INVALID_ID); } void Test_OS_TaskInstallDeleteHandler(void) @@ -263,17 +269,16 @@ void Test_OS_TaskInstallDeleteHandler(void) * Test Case For: * int32 OS_TaskInstallDeleteHandler(osal_task_entry function_pointer) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1); - actual = OS_TaskInstallDeleteHandler(UT_TestHook); - UtAssert_True(actual == expected, "OS_TaskInstallDeleteHandler() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TaskInstallDeleteHandler(UT_TestHook), OS_SUCCESS); UtAssert_True(OS_task_table[1].delete_hook_pointer == UT_TestHook, "OS_task_table[1].delete_hook_pointer (%lx) == %lx", (unsigned long)OS_task_table[1].delete_hook_pointer, (unsigned long)UT_TestHook); OS_task_table[1].delete_hook_pointer = NULL; + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TaskInstallDeleteHandler(UT_TestHook), OS_ERR_INVALID_ID); } void Test_OS_TaskFindIdBySystemData(void) @@ -282,9 +287,6 @@ void Test_OS_TaskFindIdBySystemData(void) * Test Case For: * int32 OS_TaskFindIdBySystemData(uint32 *task_id, const void *sysdata, size_t sysdata_size) */ - - int32 expected; - int32 actual; osal_id_t task_id; /* @@ -299,26 +301,18 @@ void Test_OS_TaskFindIdBySystemData(void) memset(&test_sysdata, 'x', sizeof(test_sysdata)); - expected = OS_SUCCESS; - actual = OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)); - UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)), OS_SUCCESS); /* Test parameter validation branches */ - expected = OS_INVALID_POINTER; - actual = OS_TaskFindIdBySystemData(NULL, &test_sysdata, sizeof(test_sysdata)); - UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TaskFindIdBySystemData(NULL, &test_sysdata, sizeof(test_sysdata)), OS_INVALID_POINTER); - UT_SetDefaultReturnValue(UT_KEY(OS_TaskValidateSystemData_Impl), expected); - actual = OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)); - UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_INVALID_POINTER", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OS_TaskValidateSystemData_Impl)); + UT_SetDeferredRetcode(UT_KEY(OS_TaskValidateSystemData_Impl), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)), OS_ERROR); /* Test search failure */ - expected = OS_ERR_NAME_NOT_FOUND; - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), expected); - actual = OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)); - UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch)); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetBySearch), 1, OS_ERR_NAME_NOT_FOUND); + OSAPI_TEST_FUNCTION_RC(OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)), + OS_ERR_NAME_NOT_FOUND); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-time.c b/src/unit-test-coverage/shared/src/coveragetest-time.c index baf4c4a0d..00aa2d030 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-time.c +++ b/src/unit-test-coverage/shared/src/coveragetest-time.c @@ -55,10 +55,7 @@ void Test_OS_TimerCbAPI_Init(void) * Test Case For: * int32 OS_TimerCbAPI_Init(void) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_TimerCbAPI_Init(); - - UtAssert_True(actual == expected, "OS_TimerCbAPI_Init() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimerCbAPI_Init(), OS_SUCCESS); } void Test_OS_TimerAdd(void) @@ -68,46 +65,35 @@ void Test_OS_TimerAdd(void) * int32 OS_TimerAdd(uint32 *timer_id, const char *timer_name, uint32 timebase_ref_id, OS_ArgCallback_t * callback_ptr, void *callback_arg) */ - int32 expected = OS_SUCCESS; - osal_id_t objid = OS_OBJECT_ID_UNDEFINED; - char arg = 'a'; - - int32 actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); + osal_id_t objid = OS_OBJECT_ID_UNDEFINED; + char arg = 'a'; - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg), OS_SUCCESS); /* test error cases */ - expected = OS_INVALID_POINTER; - actual = OS_TimerAdd(NULL, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_INVALID_POINTER", (long)actual); - - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_ERR_NAME_TOO_LONG; - actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); + OSAPI_TEST_FUNCTION_RC(OS_TimerAdd(NULL, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TimerAdd(&objid, NULL, UT_OBJID_1, UT_TimerArgCallback, &arg), OS_INVALID_POINTER); + + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg), OS_ERR_NAME_TOO_LONG); + + OSAPI_TEST_FUNCTION_RC(OS_TimerAdd(&objid, "UT", UT_OBJID_1, NULL, &arg), OS_INVALID_POINTER); + + UT_SetDeferredRetcode(UT_KEY(OS_TaskGetId_Impl), 1, 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + OSAPI_TEST_FUNCTION_RC(OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg), + OS_ERR_INCORRECT_OBJ_STATE); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg), OS_ERR_INVALID_ID); - expected = OS_INVALID_POINTER; - actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, NULL, &arg); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); - - UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); - - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); - expected = OS_ERROR; - actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERROR", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdGetById)); - - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERROR); - expected = OS_ERROR; - actual = OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERROR", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew)); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdAllocateNew), 1, OS_ERR_NO_FREE_IDS); + OSAPI_TEST_FUNCTION_RC(OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg), OS_ERR_NO_FREE_IDS); + + /* Callback ring paths (still success) */ + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 2, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg), OS_SUCCESS); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 3, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimerAdd(&objid, "UT", UT_OBJID_1, UT_TimerArgCallback, &arg), OS_SUCCESS); } void Test_OS_TimerCreate(void) @@ -116,51 +102,34 @@ void Test_OS_TimerCreate(void) * Test Case For: * int32 OS_TimerCreate(uint32 *timer_id, const char *timer_name, uint32 *accuracy, OS_TimerCallback_t callback_ptr) */ - int32 expected = OS_SUCCESS; - osal_id_t objid = OS_OBJECT_ID_UNDEFINED; + osal_id_t objid = OS_OBJECT_ID_UNDEFINED; osal_index_t local_id; uint32 accuracy = 0xFFFFFFFF; - int32 actual = OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback); - - UtAssert_True(actual == expected, "OS_TimerCreate() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback), OS_SUCCESS); OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TIMECB, objid, &local_id); - UtAssert_True(OS_timecb_table[local_id].callback_ptr != NULL, "OS_timecb_table[%lu].callback_ptr (%lx) != NULL", (unsigned long)local_id, (unsigned long)OS_timecb_table[local_id].callback_ptr); - UT_TimerCount = 0; OS_timecb_table[local_id].callback_ptr(objid, OS_timecb_table[local_id].callback_arg); - UtAssert_True(UT_TimerCount == 1, "UT_TimerCount (%lu) == 1", (unsigned long)UT_TimerCount); /* additional cases to exercise error paths */ - expected = OS_INVALID_POINTER; - actual = OS_TimerCreate(&objid, NULL, NULL, NULL); - UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_TimerCreate(&objid, "UT", &accuracy, NULL); - UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); - - UT_SetDefaultReturnValue(UT_KEY(OS_TimeBaseCreate), 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_ClearDefaultReturnValue(UT_KEY(OS_TimeBaseCreate)); - - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_ERR_NAME_TOO_LONG; - actual = OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback); - UtAssert_True(actual == expected, "OS_TimerCreate() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimerCreate(NULL, "UT", &accuracy, UT_TimerCallback), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TimerCreate(&objid, NULL, &accuracy, UT_TimerCallback), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TimerCreate(&objid, "UT", NULL, UT_TimerCallback), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TimerCreate(&objid, "UT", &accuracy, NULL), OS_INVALID_POINTER); + + UT_SetDeferredRetcode(UT_KEY(OS_TimeBaseCreate), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback), OS_ERROR); + + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback), OS_ERR_NAME_TOO_LONG); UT_ClearDefaultReturnValue(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)); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimerCreate(&objid, "UT", &accuracy, UT_TimerCallback), OS_ERR_INVALID_ID); UtAssert_STUB_COUNT(OS_TimeBaseDelete, 1); } @@ -170,31 +139,30 @@ void Test_OS_TimerSet(void) * Test Case For: * int32 OS_TimerSet(uint32 timer_id, uint32 start_time, uint32 interval_time) */ - int32 expected = OS_TIMER_ERR_INVALID_ARGS; - int32 actual = OS_TimerSet(UT_OBJID_1, 0, 0); - UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimerSet(UT_OBJID_1, 0, 0), OS_TIMER_ERR_INVALID_ARGS); - expected = OS_SUCCESS; - actual = OS_TimerSet(UT_OBJID_1, 0, 1); - UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimerSet(UT_OBJID_1, 0, 1), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TimerSet(UT_OBJID_1, 1, 0), OS_SUCCESS); OS_timecb_table[2].timebase_token.obj_type = OS_OBJECT_TYPE_OS_TIMEBASE; OS_timecb_table[2].timebase_token.obj_id = UT_OBJID_2; OS_timecb_table[2].timebase_token.obj_idx = UT_INDEX_0; OS_timecb_table[2].flags = TIMECB_FLAG_DEDICATED_TIMEBASE; - actual = OS_TimerSet(UT_OBJID_2, 0, 1); - UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_SUCCESS", (long)actual); + + OSAPI_TEST_FUNCTION_RC(OS_TimerSet(UT_OBJID_2, 0, 1), OS_SUCCESS); memset(OS_timecb_table, 0, sizeof(OS_timecb_table)); - expected = OS_TIMER_ERR_INVALID_ARGS; - actual = OS_TimerSet(UT_OBJID_2, UINT32_MAX, UINT32_MAX); - UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); + /* Call again without dedicated timebase */ + OSAPI_TEST_FUNCTION_RC(OS_TimerSet(UT_OBJID_2, 0, 1), OS_SUCCESS); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimerSet(UT_OBJID_2, 0, 1), OS_ERR_INVALID_ID); - UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_TimerSet(UT_OBJID_2, 0, 1); - UtAssert_True(actual == expected, "OS_TimerSet() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); + OSAPI_TEST_FUNCTION_RC(OS_TimerSet(UT_OBJID_2, UINT32_MAX, 1), OS_TIMER_ERR_INVALID_ARGS); + OSAPI_TEST_FUNCTION_RC(OS_TimerSet(UT_OBJID_2, 1, UINT32_MAX), OS_TIMER_ERR_INVALID_ARGS); + + UT_SetDeferredRetcode(UT_KEY(OS_TaskGetId_Impl), 1, 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + OSAPI_TEST_FUNCTION_RC(OS_TimerSet(UT_OBJID_2, 0, 1), OS_ERR_INCORRECT_OBJ_STATE); } void Test_OS_TimerDelete(void) @@ -203,29 +171,27 @@ void Test_OS_TimerDelete(void) * Test Case For: * int32 OS_TimerDelete(uint32 timer_id) */ - int32 expected; - int32 actual; osal_id_t timebase_id; - osal_id_t timer_objid_1, timer_objid_2; + osal_id_t timer_objid_1; + osal_id_t 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); + + /* Add and confirm timebase and cb references */ OS_TimerAdd(&timer_objid_1, "UT1", timebase_id, UT_TimerArgCallback, NULL); - OS_TimerAdd(&timer_objid_2, "UT2", timebase_id, UT_TimerArgCallback, NULL); + UtAssert_True(OS_ObjectIdEqual(timebase->first_cb, timer_objid_1), "1st timer add - First CB at timer 1"); - /* 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"); + OS_TimerAdd(&timer_objid_2, "UT2", timebase_id, UT_TimerArgCallback, NULL); + UtAssert_True(OS_ObjectIdEqual(timebase->first_cb, timer_objid_2), "2nd timer add - First CB at timer 2"); - actual = OS_TimerDelete(timer_objid_2); - UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimerDelete(timer_objid_2), OS_SUCCESS); /* 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"); @@ -237,14 +203,12 @@ void Test_OS_TimerDelete(void) 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); + OSAPI_TEST_FUNCTION_RC(OS_TimerDelete(timer_objid_1), OS_SUCCESS); /* 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); + OSAPI_TEST_FUNCTION_RC(OS_TimerDelete(timer_objid_2), OS_SUCCESS); /* The "first_cb" should be undefined */ UtAssert_True(!OS_ObjectIdDefined(timebase->first_cb), "First CB at OS_OBJECT_ID_UNDEFINED"); @@ -252,18 +216,23 @@ void Test_OS_TimerDelete(void) /* verify deletion of the dedicated timebase objects * these are implicitly created as part of timer creation for API compatibility */ 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()"); + OSAPI_TEST_FUNCTION_RC(OS_TimerDelete(timer_objid_1), OS_SUCCESS); + UtAssert_STUB_COUNT(OS_TimeBaseDelete, 1); + + /* Cover OS_ObjectIdGetById failure cases for callback ring which can't occur nominally */ + OS_TimerAdd(&timer_objid_1, "UT1", timebase_id, UT_TimerArgCallback, NULL); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 2, OS_ERR_INVALID_ID); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimerDelete(UT_OBJID_1), OS_SUCCESS); memset(OS_timecb_table, 0, sizeof(OS_timecb_table)); memset(OS_timebase_table, 0, sizeof(OS_timebase_table)); - UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_TimerDelete(UT_OBJID_2); - UtAssert_True(actual == expected, "OS_TimerDelete() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); + UT_SetDeferredRetcode(UT_KEY(OS_TaskGetId_Impl), 1, 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + OSAPI_TEST_FUNCTION_RC(OS_TimerDelete(UT_OBJID_2), OS_ERR_INCORRECT_OBJ_STATE); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimerDelete(UT_OBJID_2), OS_ERR_INVALID_ID); } void Test_OS_TimerGetIdByName(void) @@ -272,21 +241,17 @@ void Test_OS_TimerGetIdByName(void) * Test Case For: * int32 OS_TimerGetIdByName (uint32 *timer_id, const char *timer_name) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; osal_id_t objid; - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); - actual = OS_TimerGetIdByName(&objid, "UT"); - UtAssert_True(actual == expected, "OS_TimerGetIdByName() (%ld) == OS_SUCCESS", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdFindByName), 1, OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TimerGetIdByName(&objid, "UT"), OS_SUCCESS); OSAPI_TEST_FUNCTION_RC(OS_TimerGetIdByName(&objid, "NF"), OS_ERR_NAME_NOT_FOUND); OSAPI_TEST_FUNCTION_RC(OS_TimerGetIdByName(NULL, "NF"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TimerGetIdByName(&objid, NULL), OS_INVALID_POINTER); - UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + UT_SetDeferredRetcode(UT_KEY(OS_TaskGetId_Impl), 1, 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); OSAPI_TEST_FUNCTION_RC(OS_TimerGetIdByName(&objid, "NF"), OS_ERR_INCORRECT_OBJ_STATE); - UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); } void Test_OS_TimerGetInfo(void) @@ -295,8 +260,6 @@ void Test_OS_TimerGetInfo(void) * Test Case For: * int32 OS_TimerGetInfo (uint32 timer_id, OS_timer_prop_t *timer_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; OS_timer_prop_t timer_prop; OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_TIMECB, UT_INDEX_1, "ABC", UT_OBJID_OTHER); @@ -307,23 +270,19 @@ void Test_OS_TimerGetInfo(void) OS_timecb_table[1].timebase_token.obj_idx = UT_INDEX_0; OS_timebase_table[0].accuracy_usec = 3333; - actual = OS_TimerGetInfo(UT_OBJID_1, &timer_prop); - - UtAssert_True(actual == expected, "OS_TimerGetInfo() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimerGetInfo(UT_OBJID_1, &timer_prop), OS_SUCCESS); UtAssert_True(strcmp(timer_prop.name, "ABC") == 0, "timer_prop.name (%s) == ABC", timer_prop.name); UtAssert_True(timer_prop.interval_time == 2222, "timer_prop.interval_time (%lu) == 2222", (unsigned long)timer_prop.interval_time); UtAssert_True(timer_prop.accuracy == 3333, "timer_prop.accuracy (%lu) == 3333", (unsigned long)timer_prop.accuracy); - expected = OS_INVALID_POINTER; - actual = OS_TimerGetInfo(UT_OBJID_1, NULL); - UtAssert_True(actual == expected, "OS_TimerGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimerGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDeferredRetcode(UT_KEY(OS_TaskGetId_Impl), 1, 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + OSAPI_TEST_FUNCTION_RC(OS_TimerGetInfo(UT_OBJID_1, &timer_prop), OS_ERR_INCORRECT_OBJ_STATE); - UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_TimerGetInfo(UT_OBJID_1, &timer_prop); - UtAssert_True(actual == expected, "OS_TimerGetInfo() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl)); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimerGetInfo(UT_OBJID_1, &timer_prop), OS_ERR_INVALID_ID); } /* Osapi_Test_Setup diff --git a/src/unit-test-coverage/shared/src/coveragetest-timebase.c b/src/unit-test-coverage/shared/src/coveragetest-timebase.c index b2b28a6bd..6563f8ed8 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/shared/src/coveragetest-timebase.c @@ -72,10 +72,7 @@ void Test_OS_TimeBaseAPI_Init(void) * Test Case For: * int32 OS_TimeBaseAPI_Init(void) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_TimeBaseAPI_Init(); - - UtAssert_True(actual == expected, "OS_TimeBaseAPI_Init() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseAPI_Init(), OS_SUCCESS); } void Test_OS_TimeBaseCreate(void) @@ -84,31 +81,24 @@ void Test_OS_TimeBaseCreate(void) * Test Case For: * int32 OS_TimeBaseCreate(uint32 *timer_id, const char *timebase_name, OS_TimerSync_t external_sync) */ - int32 expected = OS_SUCCESS; osal_id_t objid; - int32 actual; - actual = OS_TimeBaseCreate(&objid, "UT1", UT_TimerSync); - UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate(&objid, "UT1", UT_TimerSync), OS_SUCCESS); - actual = OS_TimeBaseCreate(&objid, "UT2", NULL); - UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate(&objid, "UT2", NULL), OS_SUCCESS); /* test error paths */ - expected = OS_INVALID_POINTER; - actual = OS_TimeBaseCreate(NULL, NULL, NULL); - UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_INVALID_POINTER", (long)actual); - - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_ERR_NAME_TOO_LONG; - actual = OS_TimeBaseCreate(&objid, "UT", UT_TimerSync); - UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual); - UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr)); - - UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_TimeBaseCreate(&objid, "UT", UT_TimerSync); - UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate(NULL, "UT1", UT_TimerSync), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate(&objid, NULL, UT_TimerSync), OS_INVALID_POINTER); + + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate(&objid, "UT", UT_TimerSync), OS_ERR_NAME_TOO_LONG); + + UT_SetDeferredRetcode(UT_KEY(OS_TaskGetId_Impl), 1, 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate(&objid, "UT", UT_TimerSync), OS_ERR_INCORRECT_OBJ_STATE); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdAllocateNew), 1, OS_ERR_NO_FREE_IDS); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate(&objid, "UT1", UT_TimerSync), OS_ERR_NO_FREE_IDS); } void Test_OS_TimeBaseSet(void) @@ -117,21 +107,21 @@ void Test_OS_TimeBaseSet(void) * Test Case For: * int32 OS_TimeBaseSet(uint32 timer_id, uint32 start_time, uint32 interval_time) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_TimeBaseSet(UT_OBJID_1, 1000, 1000); - - UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet(UT_OBJID_1, 1000, 1000), OS_SUCCESS); /* test error paths: overflow on input */ - expected = OS_TIMER_ERR_INVALID_ARGS; - actual = OS_TimeBaseSet(UT_OBJID_1, UINT32_MAX, UINT32_MAX); - UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet(UT_OBJID_1, UINT32_MAX, 1000), OS_TIMER_ERR_INVALID_ARGS); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet(UT_OBJID_1, 1000, UINT32_MAX), OS_TIMER_ERR_INVALID_ARGS); /* test error paths */ - UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_TimeBaseSet(UT_OBJID_1, 1000, 1000); - UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + UT_SetDeferredRetcode(UT_KEY(OS_TaskGetId_Impl), 1, 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet(UT_OBJID_1, 1000, 1000), OS_ERR_INCORRECT_OBJ_STATE); + + UT_SetDeferredRetcode(UT_KEY(OS_TimeBaseSet_Impl), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet(UT_OBJID_1, 1000, 1000), OS_ERROR); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet(UT_OBJID_1, 1000, 1000), OS_ERR_INVALID_ID); } void Test_OS_TimeBaseDelete(void) @@ -140,16 +130,14 @@ void Test_OS_TimeBaseDelete(void) * Test Case For: * int32 OS_TimeBaseDelete(uint32 timer_id) */ - int32 expected = OS_SUCCESS; - int32 actual = OS_TimeBaseDelete(UT_OBJID_1); - - UtAssert_True(actual == expected, "OS_TimeBaseDelete() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseDelete(UT_OBJID_1), OS_SUCCESS); /* test error paths */ - UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_TimeBaseDelete(UT_OBJID_1); - UtAssert_True(actual == expected, "OS_TimeBaseDelete() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + UT_SetDeferredRetcode(UT_KEY(OS_TaskGetId_Impl), 1, 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseDelete(UT_OBJID_1), OS_ERR_INCORRECT_OBJ_STATE); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseDelete(UT_OBJID_1), OS_ERR_INVALID_ID); } void Test_OS_TimeBaseGetIdByName(void) @@ -158,31 +146,23 @@ void Test_OS_TimeBaseGetIdByName(void) * Test Case For: * int32 OS_TimeBaseGetIdByName (uint32 *timer_id, const char *timebase_name) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; osal_id_t objid; - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); - actual = OS_TimeBaseGetIdByName(&objid, "UT"); - UtAssert_True(actual == expected, "OS_TimeBaseGetIdByName() (%ld) == OS_SUCCESS", (long)actual); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdFindByName), 1, OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetIdByName(&objid, "UT"), OS_SUCCESS); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - UT_ClearDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName)); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetIdByName(&objid, "NF"), OS_ERR_NAME_NOT_FOUND); - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), -1); + UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, -1); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetIdByName(&objid, "TL"), OS_ERR_NAME_TOO_LONG); - UT_ResetState(UT_KEY(OCS_memchr)); /* test error paths */ - expected = OS_INVALID_POINTER; - actual = OS_TimeBaseGetIdByName(NULL, NULL); - UtAssert_True(actual == expected, "OS_TimeBaseGetIdByName() (%ld) == OS_INVALID_POINTER", (long)actual); - - UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_TimeBaseGetIdByName(&objid, "NF"); - UtAssert_True(actual == expected, "OS_TimeBaseGetIdByName() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetIdByName(NULL, "UT"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetIdByName(&objid, NULL), OS_INVALID_POINTER); + + UT_SetDeferredRetcode(UT_KEY(OS_TaskGetId_Impl), 1, 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetIdByName(&objid, "NF"), OS_ERR_INCORRECT_OBJ_STATE); } void Test_OS_TimeBaseGetInfo(void) @@ -191,8 +171,6 @@ void Test_OS_TimeBaseGetInfo(void) * Test Case For: * int32 OS_TimeBaseGetInfo (uint32 timebase_id, OS_timebase_prop_t *timebase_prop) */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; OS_timebase_prop_t timebase_prop; OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_TIMEBASE, UT_INDEX_1, "ABC", UT_OBJID_OTHER); @@ -201,9 +179,7 @@ void Test_OS_TimeBaseGetInfo(void) OS_timebase_table[1].freerun_time = 3333; OS_timebase_table[1].accuracy_usec = 4444; - actual = OS_TimeBaseGetInfo(UT_OBJID_1, &timebase_prop); - - UtAssert_True(actual == expected, "OS_TimeBaseGetInfo() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetInfo(UT_OBJID_1, &timebase_prop), OS_SUCCESS); OSAPI_TEST_OBJID(timebase_prop.creator, ==, UT_OBJID_OTHER); UtAssert_True(strcmp(timebase_prop.name, "ABC") == 0, "timebase_prop.name (%s) == ABC", timebase_prop.name); @@ -215,14 +191,13 @@ void Test_OS_TimeBaseGetInfo(void) (unsigned long)timebase_prop.accuracy); /* test error paths */ - expected = OS_INVALID_POINTER; - actual = OS_TimeBaseGetInfo(UT_OBJID_1, NULL); - UtAssert_True(actual == expected, "OS_TimeBaseGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); - - UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_TimeBaseGetInfo(UT_OBJID_1, &timebase_prop); - UtAssert_True(actual == expected, "OS_TimeBaseGetInfo() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); + + UT_SetDeferredRetcode(UT_KEY(OS_TaskGetId_Impl), 1, 1 | (OS_OBJECT_TYPE_OS_TIMEBASE << OS_OBJECT_TYPE_SHIFT)); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetInfo(UT_OBJID_1, &timebase_prop), OS_ERR_INCORRECT_OBJ_STATE); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetInfo(UT_OBJID_1, &timebase_prop), OS_ERR_INVALID_ID); } void Test_OS_TimeBaseGetFreeRun(void) @@ -231,15 +206,14 @@ void Test_OS_TimeBaseGetFreeRun(void) * Test Case For: * int32 OS_TimeBaseGetFreeRun (uint32 timebase_id, uint32 *freerun_val) */ - int32 expected = OS_SUCCESS; - uint32 freerun = 0xFFFFFFFF; - int32 actual = OS_TimeBaseGetFreeRun(UT_OBJID_1, &freerun); + uint32 freerun = 0xFFFFFFFF; + + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetFreeRun(UT_OBJID_1, &freerun), OS_SUCCESS); - UtAssert_True(actual == expected, "OS_TimeBaseGetFreeRun() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetFreeRun(UT_OBJID_1, NULL), OS_INVALID_POINTER); - expected = OS_INVALID_POINTER; - actual = OS_TimeBaseGetFreeRun(UT_OBJID_1, NULL); - UtAssert_True(actual == expected, "OS_TimeBaseGetFreeRun() (%ld) == OS_INVALID_POINTER", (long)actual); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERR_INVALID_ID); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseGetFreeRun(UT_OBJID_1, &freerun), OS_ERR_INVALID_ID); } void Test_OS_TimeBase_CallbackThread(void) @@ -250,6 +224,7 @@ void Test_OS_TimeBase_CallbackThread(void) */ OS_common_record_t *recptr; OS_object_token_t timecb_token; + OS_object_token_t timecb_token2; recptr = &OS_global_timebase_table[2]; memset(recptr, 0, sizeof(*recptr)); @@ -271,6 +246,7 @@ void Test_OS_TimeBase_CallbackThread(void) UtAssert_True(TimerSyncCount == 11, "TimerSyncCount (%lu) == 11", (unsigned long)TimerSyncCount); + /* No spin path, first timebase->first_cb token get will error */ UT_ResetState(UT_KEY(OS_TimeBaseLock_Impl)); TimerSyncCount = 0; TimerSyncRetVal = 1000; @@ -282,7 +258,24 @@ void Test_OS_TimeBase_CallbackThread(void) /* Check that the TimeCB function was called */ UtAssert_True(TimeCB > 0, "TimeCB (%lu) > 0", (unsigned long)TimeCB); - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + /* Error on call to get timebase token */ + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERROR); + OS_TimeBase_CallbackThread(UT_OBJID_2); + + /* Other paths for cb logic */ + OS_ObjectIdGetById(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TIMECB, UT_OBJID_2, &timecb_token2); + OS_timecb_table[1].next_cb = timecb_token2.obj_id; + OS_timecb_table[2].next_cb = timecb_token.obj_id; + UT_ResetState(UT_KEY(OS_TimeBaseLock_Impl)); + recptr->active_id = UT_OBJID_2; + OS_UT_SetupTestTargetIndex(OS_OBJECT_TYPE_OS_TIMEBASE, UT_INDEX_2); + UT_SetHookFunction(UT_KEY(OS_TimeBaseLock_Impl), ClearObjectsHook, recptr); + OS_timecb_table[1].interval_time = 1; + OS_timecb_table[1].callback_ptr = NULL; + + /* OS_UT_SetupTestTargetIndex sets the first OS_ObjectIdGetById return, so this sets the second and fourth */ + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OS_ERROR); + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 2, OS_ERROR); OS_TimeBase_CallbackThread(UT_OBJID_2); } diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-shared-error-impl-table-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-shared-error-impl-table-stubs.c index 3e75fc378..b52c51ac7 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-shared-error-impl-table-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-shared-error-impl-table-stubs.c @@ -34,4 +34,5 @@ #include "os-shared-errors.h" -const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = {{-4444, "UT_ERROR"}, {0, NULL}}; +/* Nonzero/NULL entry required for full branch coverage */ +const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = {{-4444, "UT_ERROR"}, {-4445, NULL}, {0, NULL}}; diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h index 83a1b47b1..400667821 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h @@ -37,6 +37,6 @@ extern size_t const UT_Ref_OS_impl_console_table_SIZE; /** * Invokes the console helper task entry point */ -extern void UT_ConsoleTest_TaskEntry(int arg); +extern int UT_ConsoleTest_TaskEntry(int arg); #endif /* UT_ADAPTOR_CONSOLE_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c index 8909b537b..806093688 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c @@ -35,7 +35,7 @@ void *const UT_Ref_OS_impl_console_table = OS_impl_console_table; size_t const UT_Ref_OS_impl_console_table_SIZE = sizeof(OS_impl_console_table); -void UT_ConsoleTest_TaskEntry(int arg) +int UT_ConsoleTest_TaskEntry(int arg) { - OS_VxWorks_ConsoleTask_Entry(arg); + return OS_VxWorks_ConsoleTask_Entry(arg); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-common.c b/src/unit-test-coverage/vxworks/src/coveragetest-common.c index 41b4eda18..01c353439 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-common.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-common.c @@ -103,6 +103,9 @@ void Test_OS_VxWorks_GenericSemTake(void) OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemTake(SemID, 0), OS_SEM_TIMEOUT); OCS_errno = OCS_S_objLib_OBJ_ID_ERROR; OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemTake(SemID, 0), OS_SEM_FAILURE); + OCS_errno = OCS_S_objLib_OBJ_UNAVAILABLE; + OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemTake(SemID, 0), OS_SEM_TIMEOUT); + OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemTake(SemID, 1), OS_SEM_FAILURE); } /* end OS_VxWorks_GenericSemTake */ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-console.c b/src/unit-test-coverage/vxworks/src/coveragetest-console.c index 0746f74fc..1c7a4a033 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-console.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-console.c @@ -28,6 +28,7 @@ #include "os-vxworks-coveragetest.h" #include "ut-adaptor-console.h" #include "os-shared-printf.h" +#include "os-shared-common.h" #include "OCS_unistd.h" #include "OCS_semLib.h" @@ -78,11 +79,19 @@ void Test_OS_ConsoleCreate_Impl(void) token.obj_idx = OS_MAX_CONSOLES + 1; OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_ERR_NOT_IMPLEMENTED); +} - /* Also call the actual console task, to get coverage on it. - * This task has an infinite loop, which only exits if semTake fails */ +void Test_OS_VxWorks_ConsoleTask_Entry(void) +{ + /* This task has an infinite loop, which only exits if semTake fails */ UT_SetDeferredRetcode(UT_KEY(OCS_semTake), 2, OCS_ERROR); - UT_ConsoleTest_TaskEntry(0); + OSAPI_TEST_FUNCTION_RC(UT_ConsoleTest_TaskEntry(0), OCS_OK); + + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(UT_ConsoleTest_TaskEntry(0), OCS_OK); + + OS_SharedGlobalVars.GlobalState = OS_SHUTDOWN_MAGIC_NUMBER; + OSAPI_TEST_FUNCTION_RC(UT_ConsoleTest_TaskEntry(0), OCS_OK); } /* ------------------- End of test cases --------------------------------------*/ @@ -118,4 +127,5 @@ void UtTest_Setup(void) { ADD_TEST(OS_ConsoleCreate_Impl); ADD_TEST(OS_ConsoleWakeup_Impl); + ADD_TEST(OS_VxWorks_ConsoleTask_Entry); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c b/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c index 4e852f2a2..64c7b3eb6 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c @@ -99,6 +99,16 @@ void Test_OS_FileSysStopVolume_Impl(void) token = UT_TOKEN_1; OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(&token), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_xbdBlkDevDelete)) == 1, "xbdBlkDevDelete() called"); + + /* Test alternative branches */ + UT_ResetState(UT_KEY(OCS_xbdBlkDevDelete)); + UT_FileSysTest_SetupFileSysEntry(1, NULL, OCS_NULLDEV, 4); + OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(&token), OS_SUCCESS); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_xbdBlkDevDelete)) == 0, "xbdBlkDevDelete() not called"); + + UT_FileSysTest_SetupFileSysEntry(1, NULL, 1, 0); + OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(&token), OS_SUCCESS); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_xbdBlkDevDelete)) == 0, "xbdBlkDevDelete() not called"); } void Test_OS_FileSysFormatVolume_Impl(void) diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-network.c b/src/unit-test-coverage/vxworks/src/coveragetest-network.c index 908ca50db..52933fa97 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-network.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-network.c @@ -66,8 +66,13 @@ void Test_OS_NetworkGetID_Impl(void) UT_SetDefaultReturnValue(UT_KEY(OCS_hostGetByName), 1234); OSAPI_TEST_FUNCTION_RC(OS_NetworkGetID_Impl(&IdBuf), OS_SUCCESS); UtAssert_True(IdBuf == 1234, "IdBuf (%ld) == 1234", (long)IdBuf); + UT_SetDefaultReturnValue(UT_KEY(OCS_hostGetByName), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_NetworkGetID_Impl(&IdBuf), OS_ERROR); + + UT_SetDefaultReturnValue(UT_KEY(OCS_gethostname), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetID_Impl(&IdBuf), OS_ERROR); + } /* end OS_NetworkGetID_Impl */ /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-shell.c b/src/unit-test-coverage/vxworks/src/coveragetest-shell.c index 29f2bcb4b..4c6d3b1ff 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-shell.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-shell.c @@ -37,8 +37,6 @@ void Test_OS_ShellOutputToFile_Impl(void) * Test Case For: * int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) */ - int32 expected = OS_SUCCESS; - int32 actual; OS_object_token_t token = UT_TOKEN_0; /* @@ -47,17 +45,21 @@ void Test_OS_ShellOutputToFile_Impl(void) * must be set to avoid getting into an endless loop. */ UT_SetDeferredRetcode(UT_KEY(OCS_taskNameToId), 2, -1); - - actual = OS_ShellOutputToFile_Impl(&token, "TestCmd"); - - UtAssert_True(actual == expected, "OS_ShellOutputToFile_Impl() (%ld) == OS_SUCCESS", (long)actual); + OSAPI_TEST_FUNCTION_RC(OS_ShellOutputToFile_Impl(&token, "TestCmd"), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_shellGenericInit)) == 1, "shellGenericInit() called"); /* failure to open the output file */ - UT_SetDefaultReturnValue(UT_KEY(OS_OpenCreate), OS_ERROR); - expected = OS_ERROR; - actual = OS_ShellOutputToFile_Impl(&token, "TestCmd"); - UtAssert_True(actual == expected, "OS_ShellOutputToFile_Impl() (%ld) == OS_ERROR", (long)actual); + UT_SetDeferredRetcode(UT_KEY(OS_OpenCreate), 1, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ShellOutputToFile_Impl(&token, "TestCmd"), OS_ERROR); + + /* Shell failure */ + UT_SetDefaultReturnValue(UT_KEY(OCS_shellGenericInit), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ShellOutputToFile_Impl(&token, "TestCmd"), OS_ERROR); + + /* ID failure */ + UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); + UT_SetDefaultReturnValue(UT_KEY(OCS_taskNameToId), -1); + OSAPI_TEST_FUNCTION_RC(OS_ShellOutputToFile_Impl(&token, "TestCmd"), OS_SUCCESS); } /* ------------------- End of test cases --------------------------------------*/ diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c index b080a3dd4..9d2e84397 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c @@ -41,7 +41,8 @@ void Test_OS_GlobalSymbolLookup_Impl(void) cpuaddr SymAddr; OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(&SymAddr, "symname"), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(NULL, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(NULL, "symname"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(&SymAddr, NULL), OS_INVALID_POINTER); UT_SetDefaultReturnValue(UT_KEY(OCS_symFind), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(&SymAddr, "symname"), OS_ERROR); } @@ -55,7 +56,8 @@ void Test_OS_ModuleSymbolLookup_Impl(void) OS_object_token_t token = UT_TOKEN_0; OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(&token, &SymAddr, "symname"), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(&token, NULL, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(&token, NULL, "symname"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(&token, &SymAddr, NULL), OS_INVALID_POINTER); UT_SetDefaultReturnValue(UT_KEY(OCS_symFind), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl(&token, &SymAddr, "symname"), OS_ERROR); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c index 8f7604dbf..8bbfecb78 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c @@ -65,6 +65,7 @@ void Test_OS_TaskCreate_Impl(void) * int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) */ OS_object_token_t token = UT_TOKEN_0; + char userstack[500]; UT_SetDataBuffer(UT_KEY(OCS_malloc), TestHeap, sizeof(TestHeap), false); UT_SetDataBuffer(UT_KEY(OCS_free), TestHeap, sizeof(TestHeap), false); @@ -98,6 +99,12 @@ void Test_OS_TaskCreate_Impl(void) UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 3, "taskInit() called"); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskActivate)) == 3, "taskActivate() called"); + /* create again with nonzero userstackbase */ + OS_task_table[0].stack_pointer = userstack; + OS_task_table[0].stack_size = sizeof(userstack); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, OS_FP_ENABLED), OS_SUCCESS); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 3, "malloc() not called"); + /* other failure modes */ UT_SetDefaultReturnValue(UT_KEY(OCS_taskInit), -1); OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(&token, 0), OS_ERROR); @@ -208,6 +215,19 @@ void Test_OS_TaskGetId_Impl(void) UT_SetDataBuffer(UT_KEY(OCS_taskTcb), &TaskTcb, sizeof(TaskTcb), false); id2 = OS_TaskGetId_Impl(); UtAssert_MemCmp(&id1, &id2, sizeof(osal_id_t), "OS_TaskGetId_Impl()"); + + /* bad lrec */ + TaskTcb = (OCS_WIND_TCB *)(&OS_global_task_table[0] + OS_MAX_TASKS); + UT_SetDataBuffer(UT_KEY(OCS_taskTcb), &TaskTcb, sizeof(TaskTcb), false); + id1 = OS_OBJECT_ID_UNDEFINED; + id2 = OS_TaskGetId_Impl(); + UtAssert_MemCmp(&id1, &id2, sizeof(osal_id_t), "OS_TaskGetId_Impl() - invalid lrec"); + + /* NULL lrec */ + UT_SetDefaultReturnValue(UT_KEY(OCS_taskTcb), -1); + id1 = OS_OBJECT_ID_UNDEFINED; + id2 = OS_TaskGetId_Impl(); + UtAssert_MemCmp(&id1, &id2, sizeof(osal_id_t), "OS_TaskGetId_Impl() - invalid lrec"); } void Test_OS_TaskGetInfo_Impl(void) diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c index 74576b883..5005224f9 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c @@ -192,6 +192,10 @@ void Test_OS_VxWorks_SigWait(void) osal_id_t id; OS_object_token_t token = UT_TOKEN_0; + /* OS_ObjectIdGetById error case */ + UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdGetById), 1, OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(OS_OBJECT_ID_UNDEFINED), 0); + memset(&id, 0x02, sizeof(id)); OS_global_timebase_table[0].active_id = id; OS_timebase_table[0].nominal_start_time = 8888; @@ -215,6 +219,13 @@ void Test_OS_VxWorks_SigWait(void) UT_SetDataBuffer(UT_KEY(OCS_sigwait), &signo, sizeof(signo), false); OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(OS_OBJECT_ID_UNDEFINED), 2222222); + /* sigwait interrupt cases */ + UT_SetDeferredRetcode(UT_KEY(OCS_sigwait), 1, OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(OS_OBJECT_ID_UNDEFINED), 0); + signo++; + UT_SetDataBuffer(UT_KEY(OCS_sigwait), &signo, sizeof(signo), false); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(OS_OBJECT_ID_UNDEFINED), 0); + UT_TimeBaseTest_Setup(UT_INDEX_0, 0, false); OS_global_timebase_table[0].active_id = OS_OBJECT_ID_UNDEFINED; OS_timebase_table[0].nominal_interval_time = 0; @@ -235,6 +246,10 @@ void Test_OS_TimeBaseSet_Impl(void) UT_SetDefaultReturnValue(UT_KEY(OCS_timer_settime), -1); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_TIMER_ERR_INVALID_ARGS); + + /* reset_flag false and return_code != OS_SUCCESS branch */ + UT_TimeBaseTest_Setup(UT_INDEX_0, OCS_SIGRTMIN, false); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_TIMER_ERR_INVALID_ARGS); } void Test_OS_TimeBaseDelete_Impl(void) @@ -246,6 +261,9 @@ void Test_OS_TimeBaseDelete_Impl(void) UT_TimeBaseTest_Setup(UT_INDEX_0, OCS_SIGRTMIN, false); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseDelete_Impl(&token), OS_SUCCESS); + + /* Second call to cover assigned_signal == 0 */ + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseDelete_Impl(&token), OS_SUCCESS); } void Test_OS_TimeBaseGetInfo_Impl(void)