diff --git a/src/os/shared/inc/os-shared-idmap.h b/src/os/shared/inc/os-shared-idmap.h index 0e86a4cda..4eab9e44e 100644 --- a/src/os/shared/inc/os-shared-idmap.h +++ b/src/os/shared/inc/os-shared-idmap.h @@ -44,6 +44,23 @@ struct OS_common_record uint16 refcount; }; +typedef enum +{ + OS_TASK_BASE = 0, + OS_QUEUE_BASE = OS_TASK_BASE + OS_MAX_TASKS, + OS_BINSEM_BASE = OS_QUEUE_BASE + OS_MAX_QUEUES, + OS_COUNTSEM_BASE = OS_BINSEM_BASE + OS_MAX_BIN_SEMAPHORES, + OS_MUTEX_BASE = OS_COUNTSEM_BASE + OS_MAX_COUNT_SEMAPHORES, + OS_STREAM_BASE = OS_MUTEX_BASE + OS_MAX_MUTEXES, + OS_DIR_BASE = OS_STREAM_BASE + OS_MAX_NUM_OPEN_FILES, + OS_TIMEBASE_BASE = OS_DIR_BASE + OS_MAX_NUM_OPEN_DIRS, + OS_TIMECB_BASE = OS_TIMEBASE_BASE + OS_MAX_TIMEBASES, + OS_MODULE_BASE = OS_TIMECB_BASE + OS_MAX_TIMERS, + OS_FILESYS_BASE = OS_MODULE_BASE + OS_MAX_MODULES, + OS_CONSOLE_BASE = OS_FILESYS_BASE + OS_MAX_FILE_SYSTEMS, + OS_MAX_TOTAL_RECORDS = OS_CONSOLE_BASE + OS_MAX_CONSOLES +} OS_ObjectIndex_t; + /* * Type of locking that should occur when checking IDs. */ diff --git a/src/os/shared/src/osapi-idmap.c b/src/os/shared/src/osapi-idmap.c index ab3a71883..cd05f5f0c 100644 --- a/src/os/shared/src/osapi-idmap.c +++ b/src/os/shared/src/osapi-idmap.c @@ -63,23 +63,6 @@ #define OS_LOCK_KEY_FIXED_VALUE 0x4D000000 #define OS_LOCK_KEY_INVALID ((osal_key_t) {0}) -typedef enum -{ - OS_TASK_BASE = 0, - OS_QUEUE_BASE = OS_TASK_BASE + OS_MAX_TASKS, - OS_BINSEM_BASE = OS_QUEUE_BASE + OS_MAX_QUEUES, - OS_COUNTSEM_BASE = OS_BINSEM_BASE + OS_MAX_BIN_SEMAPHORES, - OS_MUTEX_BASE = OS_COUNTSEM_BASE + OS_MAX_COUNT_SEMAPHORES, - OS_STREAM_BASE = OS_MUTEX_BASE + OS_MAX_MUTEXES, - OS_DIR_BASE = OS_STREAM_BASE + OS_MAX_NUM_OPEN_FILES, - OS_TIMEBASE_BASE = OS_DIR_BASE + OS_MAX_NUM_OPEN_DIRS, - OS_TIMECB_BASE = OS_TIMEBASE_BASE + OS_MAX_TIMEBASES, - OS_MODULE_BASE = OS_TIMECB_BASE + OS_MAX_TIMERS, - OS_FILESYS_BASE = OS_MODULE_BASE + OS_MAX_MODULES, - OS_CONSOLE_BASE = OS_FILESYS_BASE + OS_MAX_FILE_SYSTEMS, - OS_MAX_TOTAL_RECORDS = OS_CONSOLE_BASE + OS_MAX_CONSOLES -} OS_ObjectIndex_t; - /* * A structure containing the user-specified * details of a "foreach" iteration request diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index 70b6e7329..d341ec553 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -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; @@ -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[OS_MAX_TOTAL_RECORDS]; + osal_id_t typesJ[OS_MAX_TOTAL_RECORDS]; + uint32 intID; + int32 recordscount = 0; + osal_objtype_t idtype; + char str[OS_MAX_TOTAL_RECORDS]; + + for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype) + { + actual = OS_SUCCESS; + do + { + snprintf(str, sizeof(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]), "%lu Is defined", OS_ObjectIdToInteger(typesI[i])); + + for (int j = 0; j < recordscount; j++) + { + if (i == j) + { + UtAssert_True(OS_ObjectIdEqual(typesI[i], typesJ[j]), "%lu equals %lu", OS_ObjectIdToInteger(typesI[i]), + OS_ObjectIdToInteger(typesJ[j])); + } + else + { + UtAssert_True(!OS_ObjectIdEqual(typesI[i], typesJ[j]), "%lu does not equal %lu", + OS_ObjectIdToInteger(typesI[i]), OS_ObjectIdToInteger(typesJ[j])); + } + } + } +} + +void Test_OS_ObjectIDUndefined(void) +{ + osal_id_t id; + uint32 intID; + + UtAssert_True(!OS_ObjectIdDefined(OS_OBJECT_ID_UNDEFINED), "%lu Is undefined", + OS_ObjectIdToInteger(OS_OBJECT_ID_UNDEFINED)); + + intID = OS_ObjectIdToInteger(OS_OBJECT_ID_UNDEFINED); + id = OS_ObjectIdFromInteger(intID); + + UtAssert_True(!OS_ObjectIdDefined(id), "%lu Is undefined", OS_ObjectIdToInteger(id)); +} + /* Osapi_Test_Setup * * Purpose: @@ -1115,4 +1190,6 @@ void UtTest_Setup(void) ADD_TEST(OS_GetBaseForObjectType); ADD_TEST(OS_GetResourceName); ADD_TEST(OS_ObjectIdIterator); + ADD_TEST(OS_ObjectIDInteger); + ADD_TEST(OS_ObjectIDUndefined); }