Skip to content

Commit cf3b645

Browse files
committed
Fix #982, Add test for object id inline functions
1 parent 706f0de commit cf3b645

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/unit-test-coverage/shared/src/coveragetest-idmap.c

+78
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131

3232
#include "OCS_string.h"
3333

34+
#define maxRecords \
35+
(OS_MAX_TASKS + OS_MAX_QUEUES + OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + \
36+
OS_MAX_NUM_OPEN_FILES + OS_MAX_NUM_OPEN_DIRS + OS_MAX_TIMEBASES + OS_MAX_TIMERS + OS_MAX_MODULES + \
37+
OS_MAX_FILE_SYSTEMS + OS_MAX_CONSOLES)
38+
3439
typedef struct
3540
{
3641
uint32 TaskCount;
@@ -1065,6 +1070,78 @@ void Test_OS_ObjectIdIterator(void)
10651070
UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 2);
10661071
}
10671072

1073+
void Test_OS_ObjectIDInteger(void)
1074+
{
1075+
/*
1076+
* Test Case For:
1077+
* OS_ObjectIdToInteger, OS_ObjectIdFromInteger, OS_ObjectIdEqual, OS_ObjectIdDefined
1078+
*/
1079+
int32 actual;
1080+
OS_object_token_t token;
1081+
osal_id_t typesI[maxRecords];
1082+
osal_id_t typesJ[maxRecords];
1083+
uint32 intID;
1084+
int32 recordscount = 0;
1085+
uint32 maxType = 0;
1086+
uint32 typeReturn = 0;
1087+
osal_objtype_t idtype;
1088+
char str[maxRecords];
1089+
1090+
for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype)
1091+
{
1092+
typeReturn = OS_GetMaxForObjectType(idtype);
1093+
maxType += typeReturn;
1094+
}
1095+
1096+
if (maxType == maxRecords)
1097+
{
1098+
for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype)
1099+
{
1100+
actual = OS_SUCCESS;
1101+
do
1102+
{
1103+
snprintf(str, sizeof(str), "%d", recordscount);
1104+
1105+
actual = OS_ObjectIdAllocateNew(idtype, str, &token);
1106+
1107+
if (actual == OS_SUCCESS)
1108+
{
1109+
typesI[recordscount] = token.obj_id;
1110+
intID = OS_ObjectIdToInteger(typesI[recordscount]);
1111+
typesJ[recordscount] = OS_ObjectIdFromInteger(intID);
1112+
1113+
recordscount++;
1114+
}
1115+
1116+
} while (actual == OS_SUCCESS);
1117+
}
1118+
1119+
for (int i = 0; i < recordscount; i++)
1120+
{
1121+
UtAssert_True(OS_ObjectIdDefined(typesI[i]), "%lu Is defined", OS_ObjectIdToInteger(typesI[i]));
1122+
1123+
for (int j = 0; j < recordscount; j++)
1124+
{
1125+
if (i == j)
1126+
{
1127+
UtAssert_True(OS_ObjectIdEqual(typesI[i], typesJ[j]), "%lu equals %lu",
1128+
OS_ObjectIdToInteger(typesI[i]), OS_ObjectIdToInteger(typesJ[j]));
1129+
}
1130+
else
1131+
{
1132+
UtAssert_True(!OS_ObjectIdEqual(typesI[i], typesJ[j]), "%lu does not equal %lu",
1133+
OS_ObjectIdToInteger(typesI[i]), OS_ObjectIdToInteger(typesJ[j]));
1134+
}
1135+
}
1136+
}
1137+
}
1138+
else
1139+
{
1140+
UtAssert_Failed("Max records calculated by unit test does not match flight software. Confirm calculation in "
1141+
"test is correct");
1142+
}
1143+
}
1144+
10681145
/* Osapi_Test_Setup
10691146
*
10701147
* Purpose:
@@ -1115,4 +1192,5 @@ void UtTest_Setup(void)
11151192
ADD_TEST(OS_GetBaseForObjectType);
11161193
ADD_TEST(OS_GetResourceName);
11171194
ADD_TEST(OS_ObjectIdIterator);
1195+
ADD_TEST(OS_ObjectIDInteger);
11181196
}

0 commit comments

Comments
 (0)