Skip to content

Commit

Permalink
Fix nasa#538, Build failure in UT stubs with multiple CPUs
Browse files Browse the repository at this point in the history
Fix issue regarding inclusion of cfe_platform_cfg.h when
multiple CPUs are in use.  Also fix for duplicate name
collision where different configs exist within the same
arch.
  • Loading branch information
jphickey committed Mar 4, 2020
1 parent f1be048 commit 29a37f5
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 43 deletions.
23 changes: 14 additions & 9 deletions fsw/cfe-core/unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,47 @@ add_library(ut_${CFE_CORE_TARGET}_support STATIC
# UT version of the real module (compiled with coverage flags)
foreach(MODULE ${CFE_CORE_MODULES})

# The "UT_TARGET_NAME" is a concatenation of the configuration name with the current module
# This avoids target name duplication in case more than one configuration is used
# (All targets should be based on this name)
set(UT_TARGET_NAME "${CFE_CORE_TARGET}_${MODULE}")

set(CFE_MODULE_FILES)
aux_source_directory(${cfe-core_MISSION_DIR}/src/${MODULE} CFE_MODULE_FILES)

# Compile the unit(s) under test as an object library
# this allows easy configuration of special flags and include paths
# in particular this should use the UT_C_FLAGS for coverage instrumentation
add_library(ut_cfe_${MODULE}_object OBJECT
add_library(ut_${UT_TARGET_NAME}_object OBJECT
${CFE_MODULE_FILES})

# Apply the UT_C_FLAGS to the units under test
# This should enable coverage analysis on platforms that support this
set_target_properties(ut_cfe_${MODULE}_object PROPERTIES
set_target_properties(ut_${UT_TARGET_NAME}_object PROPERTIES
COMPILE_FLAGS "${UT_C_FLAGS}")

# For this object target only, the "override" includes should be injected
# into the include path BEFORE any other include path. This is so the
# override will take precedence over any system-provided version.
target_include_directories(ut_cfe_${MODULE}_object BEFORE PRIVATE
target_include_directories(ut_${UT_TARGET_NAME}_object BEFORE PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/modules/inc/overrides)

add_executable(${CFE_CORE_TARGET}_${MODULE}_UT
add_executable(${UT_TARGET_NAME}_UT
${MODULE}_UT.c
$<TARGET_OBJECTS:ut_cfe_${MODULE}_object>)
$<TARGET_OBJECTS:ut_${UT_TARGET_NAME}_object>)

target_link_libraries(${CFE_CORE_TARGET}_${MODULE}_UT
target_link_libraries(${UT_TARGET_NAME}_UT
ut_${CFE_CORE_TARGET}_support
ut_cfe-core_stubs
ut_assert)

# Also add the C FLAGS to the link command
# This should enable coverage analysis on platforms that support this
set_target_properties(${CFE_CORE_TARGET}_${MODULE}_UT PROPERTIES
set_target_properties(${UT_TARGET_NAME}_UT PROPERTIES
LINK_FLAGS "${UT_C_FLAGS}")

add_test(${CFE_CORE_TARGET}_${MODULE}_UT ${CFE_CORE_TARGET}_${MODULE}_UT)
install(TARGETS ${CFE_CORE_TARGET}_${MODULE}_UT DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR})
add_test(${UT_TARGET_NAME}_UT ${UT_TARGET_NAME}_UT)
install(TARGETS ${UT_TARGET_NAME}_UT DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR})
endforeach(MODULE ${CFE_CORE_MODULES})

# Generate the FS test input files
Expand Down
121 changes: 91 additions & 30 deletions fsw/cfe-core/ut-stubs/ut_es_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,30 @@
*/
#include <string.h>
#include "cfe.h"
#include "cfe_platform_cfg.h"
#include "utstubs.h"
#include "utassert.h"

/*
* Unit-test stub definitions/limits
*
* Note these limits only apply to the ES _stubs_ and not
* the normal implementation. It should not be necessary
* to configure these on a deployment basis.
*/

/*
* Maximum block size for ES pool requests
*
* This is only for pool block requests where the test
* case does _not_ register its own buffer, and therefore
* gets serviced from the default (static) pool buffer.
*
* This fixed value should be enough for most simple test
* cases. If a test case requires a larger block, it should
* register its own simulated pool using UT_SetDataBuffer,
* rather than changing this value.
*/
#define CFE_UT_ES_POOL_STATIC_BLOCK_SIZE 4096

/*
** Functions
Expand Down Expand Up @@ -351,10 +373,8 @@ int32 CFE_ES_GetPoolBuf(uint32 **BufPtr,
static union
{
uint32 Start;
long long int Align1;
long double Align2;
void *Align3;
uint8 Bytes[CFE_PLATFORM_ES_MAX_BLOCK_SIZE];
CFE_ES_PoolAlign_t Align;
uint8 Bytes[CFE_UT_ES_POOL_STATIC_BLOCK_SIZE];
} Buffer;
uint32 PoolSize;
uint32 Position;
Expand All @@ -366,35 +386,66 @@ int32 CFE_ES_GetPoolBuf(uint32 **BufPtr,
if (status > 0)
{
Size = status;
if (Size > CFE_PLATFORM_ES_MAX_BLOCK_SIZE)
if (Size < sizeof(CFE_ES_PoolAlign_t))
{
status = 0xffffffff;
Size = sizeof(CFE_ES_PoolAlign_t) - 1;
}
else
{
UT_GetDataBuffer(UT_KEY(CFE_ES_GetPoolBuf), (void**)&PoolPtr, &PoolSize, &Position);
--Size;
Size |= Size >> 1;
Size |= Size >> 2;
Size |= Size >> 4;
Size |= Size >> 8;
Size |= Size >> 16;
++Size;
if (Size > CFE_PLATFORM_ES_MAX_BLOCK_SIZE)
{
Size = CFE_PLATFORM_ES_MAX_BLOCK_SIZE;
}
memset(&Buffer, 0x55, Size);
}

/* find next higher power of 2 */
Size |= Size >> 1;
Size |= Size >> 2;
Size |= Size >> 4;
Size |= Size >> 8;
Size |= Size >> 16;
++Size;

UT_GetDataBuffer(UT_KEY(CFE_ES_GetPoolBuf), (void **)&PoolPtr, &PoolSize, &Position);
if (PoolSize == 0)
{
/*
* This means the test case did not register a buffer.
* Use the static buffer to fulfill the request.
*/
PoolPtr = Buffer.Bytes;
PoolSize = sizeof(Buffer);
}

if ((Position + Size) < PoolSize)
{
PoolPtr += Position;
*BufPtr = (uint32 *)PoolPtr;
status = Size;
if (BufPtr == NULL || (Position + Size) > PoolSize)
{
*BufPtr = &Buffer.Start;
}
else
memset(PoolPtr, 0x55, Size);

/*
* Unfortunately the UT assert stub library is missing
* the ability to set the buffer position, the only way
* to do it is by calling CopyFromLocal to advance the position.
*/
while (Size > sizeof(Buffer))
{
*BufPtr = (uint32 *)(PoolPtr + Position);
UT_Stub_CopyFromLocal(UT_KEY(CFE_ES_GetPoolBuf), Buffer.Bytes, Size);
UT_Stub_CopyFromLocal(UT_KEY(CFE_ES_GetPoolBuf), &Buffer,
sizeof(Buffer));
Size -= sizeof(Buffer);
}
UT_Stub_CopyFromLocal(UT_KEY(CFE_ES_GetPoolBuf), &Buffer, Size);
}
else
{
/*
* This a a bug in the test case.
*
* The buffer is insufficient, so the test case must
* use UT_SetDataBuffer() to register a pool buffer that is
* sufficient for the code under test.
*/
UtAssert_Failed("Pool buffer empty in %s: need at least %lu bytes",
__func__, (unsigned long)(Position + Size));
status = -1;
}
}

Expand Down Expand Up @@ -708,15 +759,20 @@ void CFE_ES_ExitApp(uint32 ExitStatus)
int32 CFE_ES_CopyToCDS(CFE_ES_CDSHandle_t Handle, void *DataToCopy)
{
int32 status;
uint32 CdsBufferSize;

UT_Stub_RegisterContext(UT_KEY(CFE_ES_CopyToCDS), (void*)Handle);
UT_Stub_RegisterContext(UT_KEY(CFE_ES_CopyToCDS), DataToCopy);
status = UT_DEFAULT_IMPL(CFE_ES_CopyToCDS);

if (status >= 0)
{
UT_Stub_CopyFromLocal(UT_KEY(CFE_ES_CopyToCDS), DataToCopy,
CFE_PLATFORM_ES_CDS_MAX_BLOCK_SIZE);
/* query the size of the supplied data buffer, if any */
UT_GetDataBuffer(UT_KEY(CFE_ES_CopyToCDS), NULL, &CdsBufferSize, NULL);
if (CdsBufferSize > 0)
{
UT_Stub_CopyFromLocal(UT_KEY(CFE_ES_CopyToCDS), DataToCopy, CdsBufferSize);
}
}

return status;
Expand Down Expand Up @@ -745,15 +801,20 @@ int32 CFE_ES_CopyToCDS(CFE_ES_CDSHandle_t Handle, void *DataToCopy)
int32 CFE_ES_RestoreFromCDS(void *RestoreToMemory, CFE_ES_CDSHandle_t Handle)
{
int32 status;
uint32 CdsBufferSize;

UT_Stub_RegisterContext(UT_KEY(CFE_ES_RestoreFromCDS), RestoreToMemory);
UT_Stub_RegisterContext(UT_KEY(CFE_ES_RestoreFromCDS), (void*)Handle);
status = UT_DEFAULT_IMPL(CFE_ES_RestoreFromCDS);

if (status >= 0)
{
UT_Stub_CopyToLocal(UT_KEY(CFE_ES_RestoreFromCDS), RestoreToMemory,
CFE_PLATFORM_ES_CDS_MAX_BLOCK_SIZE);
/* query the size of the supplied data buffer, if any */
UT_GetDataBuffer(UT_KEY(CFE_ES_RestoreFromCDS), NULL, &CdsBufferSize, NULL);
if (CdsBufferSize > 0)
{
UT_Stub_CopyToLocal(UT_KEY(CFE_ES_RestoreFromCDS), RestoreToMemory, CdsBufferSize);
}
}

return status;
Expand Down
1 change: 0 additions & 1 deletion fsw/cfe-core/ut-stubs/ut_evs_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
*/
#include <string.h>
#include "cfe.h"
#include "cfe_platform_cfg.h"
#include "utstubs.h"

/*
Expand Down
1 change: 0 additions & 1 deletion fsw/cfe-core/ut-stubs/ut_fs_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
*/
#include <string.h>
#include "cfe.h"
#include "cfe_platform_cfg.h"
#include "utstubs.h"


Expand Down
1 change: 0 additions & 1 deletion fsw/cfe-core/ut-stubs/ut_sb_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
*/
#include <string.h>
#include "cfe.h"
#include "cfe_platform_cfg.h"
#include "utstubs.h"

/*
Expand Down
1 change: 0 additions & 1 deletion fsw/cfe-core/ut-stubs/ut_tbl_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
#include <string.h>
#include "cfe.h"
#include "cfe_platform_cfg.h"
#include "utstubs.h"

/*
Expand Down

0 comments on commit 29a37f5

Please sign in to comment.