Skip to content

Commit 3ec2c2e

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

File tree

3 files changed

+89
-17
lines changed

3 files changed

+89
-17
lines changed

src/os/shared/inc/os-shared-idmap.h

+17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ struct OS_common_record
4444
uint16 refcount;
4545
};
4646

47+
typedef enum
48+
{
49+
OS_TASK_BASE = 0,
50+
OS_QUEUE_BASE = OS_TASK_BASE + OS_MAX_TASKS,
51+
OS_BINSEM_BASE = OS_QUEUE_BASE + OS_MAX_QUEUES,
52+
OS_COUNTSEM_BASE = OS_BINSEM_BASE + OS_MAX_BIN_SEMAPHORES,
53+
OS_MUTEX_BASE = OS_COUNTSEM_BASE + OS_MAX_COUNT_SEMAPHORES,
54+
OS_STREAM_BASE = OS_MUTEX_BASE + OS_MAX_MUTEXES,
55+
OS_DIR_BASE = OS_STREAM_BASE + OS_MAX_NUM_OPEN_FILES,
56+
OS_TIMEBASE_BASE = OS_DIR_BASE + OS_MAX_NUM_OPEN_DIRS,
57+
OS_TIMECB_BASE = OS_TIMEBASE_BASE + OS_MAX_TIMEBASES,
58+
OS_MODULE_BASE = OS_TIMECB_BASE + OS_MAX_TIMERS,
59+
OS_FILESYS_BASE = OS_MODULE_BASE + OS_MAX_MODULES,
60+
OS_CONSOLE_BASE = OS_FILESYS_BASE + OS_MAX_FILE_SYSTEMS,
61+
OS_MAX_TOTAL_RECORDS = OS_CONSOLE_BASE + OS_MAX_CONSOLES
62+
} OS_ObjectIndex_t;
63+
4764
/*
4865
* Type of locking that should occur when checking IDs.
4966
*/

src/os/shared/src/osapi-idmap.c

-17
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@
6363
#define OS_LOCK_KEY_FIXED_VALUE 0x4D000000
6464
#define OS_LOCK_KEY_INVALID ((osal_key_t) {0})
6565

66-
typedef enum
67-
{
68-
OS_TASK_BASE = 0,
69-
OS_QUEUE_BASE = OS_TASK_BASE + OS_MAX_TASKS,
70-
OS_BINSEM_BASE = OS_QUEUE_BASE + OS_MAX_QUEUES,
71-
OS_COUNTSEM_BASE = OS_BINSEM_BASE + OS_MAX_BIN_SEMAPHORES,
72-
OS_MUTEX_BASE = OS_COUNTSEM_BASE + OS_MAX_COUNT_SEMAPHORES,
73-
OS_STREAM_BASE = OS_MUTEX_BASE + OS_MAX_MUTEXES,
74-
OS_DIR_BASE = OS_STREAM_BASE + OS_MAX_NUM_OPEN_FILES,
75-
OS_TIMEBASE_BASE = OS_DIR_BASE + OS_MAX_NUM_OPEN_DIRS,
76-
OS_TIMECB_BASE = OS_TIMEBASE_BASE + OS_MAX_TIMEBASES,
77-
OS_MODULE_BASE = OS_TIMECB_BASE + OS_MAX_TIMERS,
78-
OS_FILESYS_BASE = OS_MODULE_BASE + OS_MAX_MODULES,
79-
OS_CONSOLE_BASE = OS_FILESYS_BASE + OS_MAX_FILE_SYSTEMS,
80-
OS_MAX_TOTAL_RECORDS = OS_CONSOLE_BASE + OS_MAX_CONSOLES
81-
} OS_ObjectIndex_t;
82-
8366
/*
8467
* A structure containing the user-specified
8568
* details of a "foreach" iteration request

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

+72
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,76 @@ void Test_OS_ObjectIdIterator(void)
10651065
UtAssert_STUB_COUNT(OS_Unlock_Global_Impl, 2);
10661066
}
10671067

1068+
void Test_OS_ObjectIDInteger(void)
1069+
{
1070+
/*
1071+
* Test Case For:
1072+
* OS_ObjectIdToInteger, OS_ObjectIdFromInteger, OS_ObjectIdEqual, OS_ObjectIdDefined
1073+
*/
1074+
int32 actual;
1075+
OS_object_token_t token;
1076+
osal_id_t typesI[OS_MAX_TOTAL_RECORDS];
1077+
osal_id_t typesJ[OS_MAX_TOTAL_RECORDS];
1078+
uint32 intID;
1079+
int32 recordscount = 0;
1080+
osal_objtype_t idtype;
1081+
char str[OS_MAX_API_NAME];
1082+
1083+
for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype)
1084+
{
1085+
actual = OS_SUCCESS;
1086+
while (actual == OS_SUCCESS && recordscount < OS_MAX_TOTAL_RECORDS)
1087+
{
1088+
snprintf(str, sizeof(str), "%d", (int)recordscount);
1089+
actual = OS_ObjectIdAllocateNew(idtype, str, &token);
1090+
1091+
if (actual == OS_SUCCESS)
1092+
{
1093+
typesI[recordscount] = token.obj_id;
1094+
intID = OS_ObjectIdToInteger(typesI[recordscount]);
1095+
typesJ[recordscount] = OS_ObjectIdFromInteger(intID);
1096+
1097+
recordscount++;
1098+
}
1099+
}
1100+
}
1101+
1102+
UtAssert_True(recordscount < OS_MAX_TOTAL_RECORDS, "All Id types checked");
1103+
1104+
for (int i = 0; i < recordscount; i++)
1105+
{
1106+
UtAssert_True(OS_ObjectIdDefined(typesI[i]), "%lu Is defined", OS_ObjectIdToInteger(typesI[i]));
1107+
1108+
for (int j = 0; j < recordscount; j++)
1109+
{
1110+
if (i == j)
1111+
{
1112+
UtAssert_True(OS_ObjectIdEqual(typesI[i], typesJ[j]), "%lu equals %lu", OS_ObjectIdToInteger(typesI[i]),
1113+
OS_ObjectIdToInteger(typesJ[j]));
1114+
}
1115+
else
1116+
{
1117+
UtAssert_True(!OS_ObjectIdEqual(typesI[i], typesJ[j]), "%lu does not equal %lu",
1118+
OS_ObjectIdToInteger(typesI[i]), OS_ObjectIdToInteger(typesJ[j]));
1119+
}
1120+
}
1121+
}
1122+
}
1123+
1124+
void Test_OS_ObjectIDUndefined(void)
1125+
{
1126+
osal_id_t id;
1127+
uint32 intID;
1128+
1129+
UtAssert_True(!OS_ObjectIdDefined(OS_OBJECT_ID_UNDEFINED), "%lu Is undefined",
1130+
OS_ObjectIdToInteger(OS_OBJECT_ID_UNDEFINED));
1131+
1132+
intID = OS_ObjectIdToInteger(OS_OBJECT_ID_UNDEFINED);
1133+
id = OS_ObjectIdFromInteger(intID);
1134+
1135+
UtAssert_True(!OS_ObjectIdDefined(id), "%lu Is undefined", OS_ObjectIdToInteger(id));
1136+
}
1137+
10681138
/* Osapi_Test_Setup
10691139
*
10701140
* Purpose:
@@ -1115,4 +1185,6 @@ void UtTest_Setup(void)
11151185
ADD_TEST(OS_GetBaseForObjectType);
11161186
ADD_TEST(OS_GetResourceName);
11171187
ADD_TEST(OS_ObjectIdIterator);
1188+
ADD_TEST(OS_ObjectIDInteger);
1189+
ADD_TEST(OS_ObjectIDUndefined);
11181190
}

0 commit comments

Comments
 (0)