From 373741ecc63f641b956b88314060f4b9a3a0d449 Mon Sep 17 00:00:00 2001 From: Alex Campbell Date: Fri, 7 May 2021 11:12:20 -0400 Subject: [PATCH] Fix #982, Add test for object id inline functions --- .../shared/src/coveragetest-idmap.c | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index 70b6e7329..04fe6b02d 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -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: @@ -1115,4 +1185,5 @@ void UtTest_Setup(void) ADD_TEST(OS_GetBaseForObjectType); ADD_TEST(OS_GetResourceName); ADD_TEST(OS_ObjectIdIterator); + ADD_TEST(OS_ObjectIDInteger); }