Skip to content

Commit

Permalink
Partial nasa#791, Add unit test branch coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Jul 21, 2021
1 parent cb95655 commit 002ff71
Show file tree
Hide file tree
Showing 29 changed files with 969 additions and 995 deletions.
62 changes: 28 additions & 34 deletions src/unit-test-coverage/shared/src/coveragetest-binsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include "OCS_string.h"

#define UT_ERR_UNIQUE 0xDEADBEEF

/*
**********************************************************************************
** PUBLIC API FUNCTIONS
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions src/unit-test-coverage/shared/src/coveragetest-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
54 changes: 25 additions & 29 deletions src/unit-test-coverage/shared/src/coveragetest-countsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include "OCS_string.h"

#define UT_ERR_UNIQUE 0xDEADBEEF

/*
**********************************************************************************
** PUBLIC API FUNCTIONS
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
Loading

0 comments on commit 002ff71

Please sign in to comment.