diff --git a/fsw/cfe-core/unit-test/CMakeLists.txt b/fsw/cfe-core/unit-test/CMakeLists.txt index afe6c42e1..712a79293 100644 --- a/fsw/cfe-core/unit-test/CMakeLists.txt +++ b/fsw/cfe-core/unit-test/CMakeLists.txt @@ -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_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 diff --git a/fsw/cfe-core/ut-stubs/ut_es_stubs.c b/fsw/cfe-core/ut-stubs/ut_es_stubs.c index 1930cb908..9a77c3d5b 100644 --- a/fsw/cfe-core/ut-stubs/ut_es_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_es_stubs.c @@ -34,8 +34,30 @@ */ #include #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 @@ -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; @@ -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; } } @@ -708,6 +759,7 @@ 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); @@ -715,8 +767,12 @@ int32 CFE_ES_CopyToCDS(CFE_ES_CDSHandle_t Handle, void *DataToCopy) 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; @@ -745,6 +801,7 @@ 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); @@ -752,8 +809,12 @@ int32 CFE_ES_RestoreFromCDS(void *RestoreToMemory, CFE_ES_CDSHandle_t Handle) 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; diff --git a/fsw/cfe-core/ut-stubs/ut_evs_stubs.c b/fsw/cfe-core/ut-stubs/ut_evs_stubs.c index 2d1432f85..306712dcf 100644 --- a/fsw/cfe-core/ut-stubs/ut_evs_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_evs_stubs.c @@ -34,7 +34,6 @@ */ #include #include "cfe.h" -#include "cfe_platform_cfg.h" #include "utstubs.h" /* diff --git a/fsw/cfe-core/ut-stubs/ut_fs_stubs.c b/fsw/cfe-core/ut-stubs/ut_fs_stubs.c index b341b4586..6c7df8335 100644 --- a/fsw/cfe-core/ut-stubs/ut_fs_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_fs_stubs.c @@ -34,7 +34,6 @@ */ #include #include "cfe.h" -#include "cfe_platform_cfg.h" #include "utstubs.h" diff --git a/fsw/cfe-core/ut-stubs/ut_sb_stubs.c b/fsw/cfe-core/ut-stubs/ut_sb_stubs.c index a68ae547a..b410d1b88 100644 --- a/fsw/cfe-core/ut-stubs/ut_sb_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_sb_stubs.c @@ -34,7 +34,6 @@ */ #include #include "cfe.h" -#include "cfe_platform_cfg.h" #include "utstubs.h" /* diff --git a/fsw/cfe-core/ut-stubs/ut_tbl_stubs.c b/fsw/cfe-core/ut-stubs/ut_tbl_stubs.c index fc57a0501..a939df970 100644 --- a/fsw/cfe-core/ut-stubs/ut_tbl_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_tbl_stubs.c @@ -23,7 +23,6 @@ */ #include #include "cfe.h" -#include "cfe_platform_cfg.h" #include "utstubs.h" /*