Skip to content

Commit

Permalink
Fix nasa#679, Alignment warnings in UT
Browse files Browse the repository at this point in the history
Resolve remaining alignment warnings in the unit test and stub code.
In es_UT.c test cases were passing a char* as a stack pointer (uint32*)
Memory pool code was also using uint8[] buffer as uint32.
Most casting becomes unnecessary when defined as the correct type.
  • Loading branch information
jphickey committed May 8, 2020
1 parent 7a608f0 commit 0037fc0
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 82 deletions.
101 changes: 45 additions & 56 deletions fsw/cfe-core/unit-test/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -4382,6 +4382,7 @@ void TestAPI(void)
uint32 Id;
uint32 TestObjId;
char AppName[32];
uint32 StackBuf[8];
char CounterName[11];
char CDSName[CFE_MISSION_ES_CDS_MAX_NAME_LENGTH + 2];
int i;
Expand Down Expand Up @@ -4748,8 +4749,8 @@ void TestAPI(void)
Return = CFE_ES_CreateChildTask(&TaskId,
"TaskName",
TestAPI,
(uint32*) AppName,
32,
StackBuf,
sizeof(StackBuf),
400,
0);
UT_Report(__FILE__, __LINE__,
Expand All @@ -4764,8 +4765,8 @@ void TestAPI(void)
Return = CFE_ES_CreateChildTask(&TaskId,
"TaskName",
TestAPI,
(uint32*) AppName,
32,
StackBuf,
sizeof(StackBuf),
400,
0);
UT_Report(__FILE__, __LINE__,
Expand All @@ -4778,8 +4779,8 @@ void TestAPI(void)
Return = CFE_ES_CreateChildTask(NULL,
"TaskName",
TestAPI,
(uint32*) AppName,
32,
StackBuf,
sizeof(StackBuf),
400,
0);
UT_Report(__FILE__, __LINE__,
Expand All @@ -4792,8 +4793,8 @@ void TestAPI(void)
Return = CFE_ES_CreateChildTask(&TaskId,
NULL,
TestAPI,
(uint32*) AppName,
32,
StackBuf,
sizeof(StackBuf),
400,
0);
UT_Report(__FILE__, __LINE__,
Expand All @@ -4806,8 +4807,8 @@ void TestAPI(void)
Return = CFE_ES_CreateChildTask(NULL,
NULL,
TestAPI,
(uint32*) AppName,
32,
StackBuf,
sizeof(StackBuf),
400,
0);
UT_Report(__FILE__, __LINE__,
Expand All @@ -4820,8 +4821,8 @@ void TestAPI(void)
Return = CFE_ES_CreateChildTask(&TaskId,
"TaskName",
NULL,
(uint32*) AppName,
32,
StackBuf,
sizeof(StackBuf),
2,
0);
UT_Report(__FILE__, __LINE__,
Expand All @@ -4840,8 +4841,8 @@ void TestAPI(void)
Return = CFE_ES_CreateChildTask(&TaskId,
"TaskName",
TestAPI,
(uint32*) AppName,
32,
StackBuf,
sizeof(StackBuf),
400,
0);
UT_Report(__FILE__, __LINE__,
Expand All @@ -4860,8 +4861,8 @@ void TestAPI(void)
Return = CFE_ES_CreateChildTask(&TaskId,
"TaskName",
TestAPI,
(uint32*) AppName,
32,
StackBuf,
sizeof(StackBuf),
400,
0);
UT_Report(__FILE__, __LINE__,
Expand Down Expand Up @@ -6247,8 +6248,8 @@ void TestESMempool(void)
{
CFE_ES_MemHandle_t HandlePtr;
uint8 Buffer[CFE_PLATFORM_ES_MAX_BLOCK_SIZE];
uint8 *address = NULL;
uint8 *address2 = NULL;
uint32 *address = NULL;
uint32 *address2 = NULL;
Pool_t *PoolPtr;
CFE_ES_MemPoolStats_t Stats;
uint32 BlockSizes[4];
Expand Down Expand Up @@ -6307,7 +6308,7 @@ void TestESMempool(void)
/* Test successfully getting the size of an existing pool buffer */
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBufInfo(HandlePtr, (uint32 *) address) > 0,
CFE_ES_GetPoolBufInfo(HandlePtr, address) > 0,
"CFE_ES_GetPoolBufInfo",
"Get pool buffer size; successful");

Expand All @@ -6317,22 +6318,22 @@ void TestESMempool(void)
ES_ResetUnitTest();
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_NO_MUTEX;
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBufInfo(HandlePtr, (uint32 *) address) > 0,
CFE_ES_GetPoolBufInfo(HandlePtr, address) > 0,
"CFE_ES_GetPoolBufInfo",
"Get pool buffer size; successful (no mutex)");
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_USE_MUTEX;

/* Test successfully returning a pool buffer to the memory pool */
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_PutPoolBuf(HandlePtr, (uint32 *) address) > 0,
CFE_ES_PutPoolBuf(HandlePtr, address) > 0,
"CFE_ES_PutPoolBuf",
"Return buffer to the memory pool; successful");

/* Test successfully allocating an additional pool buffer */
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBuf((uint32 **) &address, HandlePtr, 256) > 0,
CFE_ES_GetPoolBuf(&address, HandlePtr, 256) > 0,
"CFE_ES_GetPoolBuf",
"Allocate pool buffer [2]; successful");

Expand All @@ -6342,7 +6343,7 @@ void TestESMempool(void)
ES_ResetUnitTest();
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_NO_MUTEX;
UT_Report(__FILE__, __LINE__,
CFE_ES_PutPoolBuf(HandlePtr, (uint32 *) address) > 0,
CFE_ES_PutPoolBuf(HandlePtr, address) > 0,
"CFE_ES_PutPoolBuf",
"Return buffer to the second memory pool; successful");
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_USE_MUTEX;
Expand Down Expand Up @@ -6372,7 +6373,7 @@ void TestESMempool(void)
*/
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBuf((uint32 **) &address,
CFE_ES_GetPoolBuf(&address,
HandlePtr2,
256) == CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_GetPoolBuf",
Expand All @@ -6393,7 +6394,7 @@ void TestESMempool(void)
*/
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBuf((uint32 **) &address,
CFE_ES_GetPoolBuf(&address,
HandlePtr,
75000) == CFE_ES_ERR_MEM_BLOCK_SIZE,
"CFE_ES_GetPoolBuf",
Expand All @@ -6404,7 +6405,7 @@ void TestESMempool(void)
*/
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBufInfo(HandlePtr, (uint32 *) address) ==
CFE_ES_GetPoolBufInfo(HandlePtr, address) ==
CFE_ES_BUFFER_NOT_IN_POOL,
"CFE_ES_GetPoolBufInfo",
"Invalid memory pool handle");
Expand All @@ -6413,7 +6414,7 @@ void TestESMempool(void)
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_PutPoolBuf(HandlePtr,
(uint32 *) address) == CFE_ES_ERR_MEM_HANDLE,
address) == CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_PutPoolBuf",
"Invalid memory block");

Expand Down Expand Up @@ -6532,7 +6533,7 @@ void TestESMempool(void)
BdPtr->Allocated = 717;
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBufInfo(HandlePtr,
(uint32 *) address) ==
address) ==
CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_GetPoolBufInfo",
"Invalid memory pool handle; unallocated block");
Expand All @@ -6545,8 +6546,7 @@ void TestESMempool(void)
BdPtr = ((BD_t *)address) - 1;
BdPtr->Allocated = 717;
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBufInfo(HandlePtr,
(uint32 *) address) ==
CFE_ES_GetPoolBufInfo(HandlePtr, address) ==
CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_GetPoolBufInfo",
"Invalid memory pool handle; unallocated block (no mutex)");
Expand All @@ -6555,8 +6555,7 @@ void TestESMempool(void)
/* Test returning a pool buffer using an unallocated block */
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_PutPoolBuf(HandlePtr,
(uint32 *) address) == CFE_ES_ERR_MEM_HANDLE,
CFE_ES_PutPoolBuf(HandlePtr, address) == CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_PutPoolBuf",
"Deallocate an unallocated block");

Expand All @@ -6566,8 +6565,7 @@ void TestESMempool(void)
ES_ResetUnitTest();
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_NO_MUTEX;
UT_Report(__FILE__, __LINE__,
CFE_ES_PutPoolBuf(HandlePtr,
(uint32 *) address) == CFE_ES_ERR_MEM_HANDLE,
CFE_ES_PutPoolBuf(HandlePtr, address) == CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_PutPoolBuf",
"Deallocate an unallocated block (no mutex)");
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_USE_MUTEX;
Expand All @@ -6579,8 +6577,7 @@ void TestESMempool(void)
BdPtr->Allocated = 0xaaaa;
BdPtr->CheckBits = 717;
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBufInfo(HandlePtr,
(uint32 *) address) ==
CFE_ES_GetPoolBufInfo(HandlePtr, address) ==
CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_GetPoolBufInfo",
"Invalid memory pool handle; check bit pattern");
Expand All @@ -6594,8 +6591,7 @@ void TestESMempool(void)
BdPtr->Allocated = 0xaaaa;
BdPtr->CheckBits = 717;
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBufInfo(HandlePtr,
(uint32 *) address) ==
CFE_ES_GetPoolBufInfo(HandlePtr, address) ==
CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_GetPoolBufInfo",
"Invalid memory pool handle; check bit pattern (no mutex)");
Expand All @@ -6606,8 +6602,7 @@ void TestESMempool(void)
*/
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_PutPoolBuf(HandlePtr,
(uint32 *) address) ==
CFE_ES_PutPoolBuf(HandlePtr, address) ==
CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_PutPoolBuf",
"Invalid/corrupted memory descriptor");
Expand All @@ -6618,8 +6613,7 @@ void TestESMempool(void)
ES_ResetUnitTest();
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_NO_MUTEX;
UT_Report(__FILE__, __LINE__,
CFE_ES_PutPoolBuf(HandlePtr,
(uint32 *) address) ==
CFE_ES_PutPoolBuf(HandlePtr, address) ==
CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_PutPoolBuf",
"Invalid/corrupted memory descriptor (no mutex)");
Expand All @@ -6642,7 +6636,7 @@ void TestESMempool(void)
ES_ResetUnitTest();
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_NO_MUTEX;
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBuf((uint32 **) &address, HandlePtr, 256) > 0,
CFE_ES_GetPoolBuf(&address, HandlePtr, 256) > 0,
"CFE_ES_GetPoolBuf",
"Allocate pool buffer [4]; successful");
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_USE_MUTEX;
Expand All @@ -6654,8 +6648,7 @@ void TestESMempool(void)
BdPtr->CheckBits = 0x5a5a;
BdPtr->Size =CFE_PLATFORM_ES_MAX_BLOCK_SIZE +1;
UT_Report(__FILE__, __LINE__,
CFE_ES_PutPoolBuf(HandlePtr,
(uint32 *) address) == CFE_ES_ERR_MEM_HANDLE,
CFE_ES_PutPoolBuf(HandlePtr, address) == CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_PutPoolBuf",
"Pool buffer size exceeds maximum");

Expand All @@ -6667,8 +6660,7 @@ void TestESMempool(void)
BdPtr->CheckBits = 0x5a5a;
BdPtr->Size =CFE_PLATFORM_ES_MAX_BLOCK_SIZE +1;
UT_Report(__FILE__, __LINE__,
CFE_ES_PutPoolBuf(HandlePtr,
(uint32 *) address) == CFE_ES_ERR_MEM_HANDLE,
CFE_ES_PutPoolBuf(HandlePtr, address) == CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_PutPoolBuf",
"Pool buffer size exceeds maximum (no mutex)");
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_USE_MUTEX;
Expand All @@ -6678,7 +6670,7 @@ void TestESMempool(void)
*/
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBuf((uint32 **) &address2,
CFE_ES_GetPoolBuf(&address2,
HandlePtr,
99000) == CFE_ES_ERR_MEM_BLOCK_SIZE,
"CFE_ES_GetPoolBuf",
Expand All @@ -6694,15 +6686,14 @@ void TestESMempool(void)
/* Test returning a pool buffer using a null handle */
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_PutPoolBuf(0,
(uint32 *) address) == CFE_ES_ERR_MEM_HANDLE,
CFE_ES_PutPoolBuf(0, address) == CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_PutPoolBuf",
"NULL memory handle");

/* Test allocating a pool buffer using a null handle */
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBuf((uint32 **) &address,
CFE_ES_GetPoolBuf(&address,
0,
256) == CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_GetPoolBuf",
Expand All @@ -6711,8 +6702,7 @@ void TestESMempool(void)
/* Test getting the size of an existing pool buffer using a null handle */
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBufInfo(0,
(uint32 *) address) ==
CFE_ES_GetPoolBufInfo(0, address) ==
CFE_ES_ERR_MEM_HANDLE,
"CFE_ES_GetPoolBufInfo",
"NULL memory handle");
Expand All @@ -6737,7 +6727,7 @@ void TestESMempool(void)
ES_ResetUnitTest();
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_NO_MUTEX;
UT_Report(__FILE__, __LINE__,
CFE_ES_GetPoolBuf((uint32 **) &address2,
CFE_ES_GetPoolBuf(&address2,
HandlePtr,
32) == CFE_ES_ERR_MEM_BLOCK_SIZE,
"CFE_ES_GetPoolBuf",
Expand All @@ -6762,8 +6752,7 @@ void TestESMempool(void)
((Pool_t *) HandlePtr)->UseMutex = CFE_ES_NO_MUTEX;
for (i=0; i < 25; ++i)
{
if (CFE_ES_GetPoolBuf((uint32 **) &address,
HandlePtr,
if (CFE_ES_GetPoolBuf(&address, HandlePtr,
12) == CFE_ES_ERR_MEM_BLOCK_SIZE)
{
break;
Expand Down
Loading

0 comments on commit 0037fc0

Please sign in to comment.