From 3ec2c2e2c4c86a03f7e45a24acae00a1829269ce Mon Sep 17 00:00:00 2001 From: Alex Campbell Date: Fri, 14 May 2021 09:47:35 -0400 Subject: [PATCH] Fix #982, Add test for object id inline functions --- src/os/shared/inc/os-shared-idmap.h | 17 +++++ src/os/shared/src/osapi-idmap.c | 17 ----- .../shared/src/coveragetest-idmap.c | 72 +++++++++++++++++++ 3 files changed, 89 insertions(+), 17 deletions(-) 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..83b09e5f8 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); } +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_API_NAME]; + + for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype) + { + actual = OS_SUCCESS; + while (actual == OS_SUCCESS && recordscount < OS_MAX_TOTAL_RECORDS) + { + snprintf(str, sizeof(str), "%d", (int)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++; + } + } + } + + UtAssert_True(recordscount < OS_MAX_TOTAL_RECORDS, "All Id types checked"); + + 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 +1185,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); }