Skip to content

Commit

Permalink
Fix #982, Add test for object id inline functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzaben committed May 13, 2021
1 parent 706f0de commit 41281d0
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 17 deletions.
17 changes: 17 additions & 0 deletions src/os/shared/inc/os-shared-idmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
17 changes: 0 additions & 17 deletions src/os/shared/src/osapi-idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 77 additions & 0 deletions src/unit-test-coverage/shared/src/coveragetest-idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}

0 comments on commit 41281d0

Please sign in to comment.