Skip to content

Commit

Permalink
Fix nasa#982, Add test for object id inline functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzaben committed May 10, 2021
1 parent 706f0de commit dbd78d3
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/unit-test-coverage/shared/src/coveragetest-idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@

#include "OCS_string.h"

#define maxRecords \
(OS_MAX_TASKS + OS_MAX_QUEUES + OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + \
OS_MAX_NUM_OPEN_FILES + OS_MAX_NUM_OPEN_DIRS + OS_MAX_TIMEBASES + OS_MAX_TIMERS + OS_MAX_MODULES + \
OS_MAX_FILE_SYSTEMS + OS_MAX_CONSOLES)

typedef struct
{
uint32 TaskCount;
Expand Down Expand Up @@ -1065,6 +1070,76 @@ void Test_OS_ObjectIdIterator(void)
UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 2);
}

void Test_OS_ObjectIDInteger(void)
{
/*
* Test Case For:
* OS_ObjectIdToInteger, OS_ObjectIdFromInteger, OS_ObjectIdEqual, OS_ObjectIdDefined
*/
int32 actual;
OS_object_token_t token;
osal_id_t typesI[maxRecords];
osal_id_t typesJ[maxRecords];
uint32 intID;
int32 recordscount = 0;
uint32 maxType = 0;
uint32 typeReturn = 0;
osal_objtype_t idtype;
char str[maxRecords];

for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype)
{
typeReturn = OS_GetMaxForObjectType(idtype);
maxType += typeReturn;
}

if (maxType == maxRecords)
{
for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype)
{
actual = OS_SUCCESS;
do
{
sprintf(str, "%d", recordscount);
actual = OS_ObjectIdAllocateNew(idtype, str, &token);

if (actual == OS_SUCCESS)
{
typesI[recordscount] = token.obj_id;
intID = OS_ObjectIdToInteger(typesI[recordscount]);
typesJ[recordscount] = OS_ObjectIdFromInteger(intID);

recordscount++;
}

} while (actual == OS_SUCCESS);
}

for (int i = 0; i < recordscount; i++)
{
UtAssert_True(OS_ObjectIdDefined(typesI[i]), "%d Is defined", typesI[i]);

for (int j = 0; j < recordscount; j++)
{
if (i == j)
{
UtAssert_True(OS_ObjectIdEqual(typesI[i], typesJ[j]), "%d equals %d", typesI[i], typesJ[j]);
}
else
{
UtAssert_True(!OS_ObjectIdEqual(typesI[i], typesJ[j]), "%d does not equal %d", typesI[i],
typesJ[j]);
}
}
}
}
else
{
UtAssert_Failed("Max records calculated by unit test does not match flight software. Confirm calculation in "
"test is correct");
}
}

/* Osapi_Test_Setup
*
* Purpose:
Expand Down Expand Up @@ -1115,4 +1190,5 @@ void UtTest_Setup(void)
ADD_TEST(OS_GetBaseForObjectType);
ADD_TEST(OS_GetResourceName);
ADD_TEST(OS_ObjectIdIterator);
ADD_TEST(OS_ObjectIDInteger);
}

0 comments on commit dbd78d3

Please sign in to comment.