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 18, 2020
1 parent 95f34d2 commit 744a9b4
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 @@ -3933,6 +3933,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 @@ -4299,8 +4300,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 @@ -4315,8 +4316,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 @@ -4329,8 +4330,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 @@ -4343,8 +4344,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 @@ -4357,8 +4358,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 @@ -4371,8 +4372,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 @@ -4391,8 +4392,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 @@ -4411,8 +4412,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 @@ -5798,8 +5799,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 @@ -5858,7 +5859,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 @@ -5868,22 +5869,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 @@ -5893,7 +5894,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 @@ -5923,7 +5924,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 @@ -5944,7 +5945,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 @@ -5955,7 +5956,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 @@ -5964,7 +5965,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 @@ -6083,7 +6084,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 @@ -6096,8 +6097,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 @@ -6106,8 +6106,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 @@ -6117,8 +6116,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 @@ -6130,8 +6128,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 @@ -6145,8 +6142,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 @@ -6157,8 +6153,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 @@ -6169,8 +6164,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 @@ -6193,7 +6187,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 @@ -6205,8 +6199,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 @@ -6218,8 +6211,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 @@ -6229,7 +6221,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 @@ -6245,15 +6237,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 @@ -6262,8 +6253,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 @@ -6288,7 +6278,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 @@ -6313,8 +6303,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 744a9b4

Please sign in to comment.