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 7, 2021
1 parent 706f0de commit 373741e
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/unit-test-coverage/shared/src/coveragetest-idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,76 @@ void Test_OS_ObjectIdIterator(void)
UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 2);
}

#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)

void Test_OS_ObjectIDInteger(void)
{
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 +1185,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 373741e

Please sign in to comment.