-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #168, add PSP coverage test example
Implement a basic example of PSP coverage test.
- Loading branch information
Showing
88 changed files
with
3,883 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*~ | ||
*.o | ||
*.gcov | ||
*.gcda | ||
*.gcno | ||
*.exe | ||
*_log.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
###################################################################### | ||
# | ||
# CMAKE build recipe for PSP white-box coverage tests | ||
# | ||
###################################################################### | ||
|
||
# The following cache variables are recognized: | ||
# PSPCOVERAGE_TARGETS -> the intended PSP module(s) that run on the actual target | ||
# | ||
# Like OSAL coverage testing, the actual underlying OS calls are stubbed out, there | ||
# is no dependency on the actual underlying OS. All coverage tests can be built on | ||
# all platforms regardless of the actual PSP in use for flight software. | ||
|
||
project(PSPCOVERAGE C) | ||
|
||
# Currently only mcp750-vxworks is implemented a demonstration of how this works. | ||
set(PSPCOVERAGE_TARGETS "mcp750-vxworks" CACHE STRING "PSP target(s) to build coverage tests for (default=all)") | ||
|
||
# Check that coverage has been implemented for this PSPTYPE | ||
foreach(PSPTYPE ${PSPCOVERAGE_TARGETS}) | ||
if (NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${PSPTYPE}) | ||
message(FATAL_ERROR "No coverage tests implemented for ${PSPTYPE}") | ||
endif (NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${PSPTYPE}) | ||
endforeach(PSPTYPE ${PSPCOVERAGE_TARGETS}) | ||
|
||
message(STATUS "PSP Coverage Test Targets: ${PSPCOVERAGE_TARGETS}") | ||
|
||
# Utilize the shared UT assert library, along with the standard OSAL includes | ||
include_directories(${UT_ASSERT_SOURCE_DIR}/inc) | ||
include_directories(${PSPCOVERAGE_SOURCE_DIR}/ut-stubs/inc) | ||
|
||
add_subdirectory(ut-stubs) | ||
|
||
# Build targets for each of the indicated PSPs | ||
foreach(SETNAME ${PSPCOVERAGE_TARGETS}) | ||
add_subdirectory(${SETNAME}) | ||
endforeach(SETNAME ${PSPCOVERAGE_TARGETS}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
###################################################################### | ||
# | ||
# CMAKE build recipe for mcp750-vxworks PSP white-box coverage tests | ||
# | ||
###################################################################### | ||
|
||
include_directories("${CFEPSP_SOURCE_DIR}/fsw/mcp750-vxworks/inc") | ||
include_directories("${PSPCOVERAGE_SOURCE_DIR}/shared/inc") | ||
|
||
# The target names will be the PSP name with a "ut" prefix | ||
# this is to distinguish these test targets from the FSW targets. | ||
set(CFE_PSP_TARGETNAME "ut-${SETNAME}") | ||
add_subdirectory("${CFEPSP_SOURCE_DIR}/fsw/${SETNAME}" "${CFE_PSP_TARGETNAME}-impl") | ||
add_subdirectory("${CFEPSP_SOURCE_DIR}/fsw/shared" "${CFE_PSP_TARGETNAME}-shared") | ||
add_subdirectory(adaptors) | ||
|
||
# as UT assert defines OS_Application_Startup and OS_Application_Run, we need | ||
# to change the ones in this module to a different name. | ||
target_compile_definitions(psp-${CFE_PSP_TARGETNAME}-impl PRIVATE | ||
OS_Application_Startup=UT_OS_Application_Startup | ||
OS_Application_Run=UT_OS_Application_Run | ||
) | ||
|
||
# only the actual FSW src file gets the coverage instrumentation | ||
target_compile_options(psp-${CFE_PSP_TARGETNAME}-impl PRIVATE | ||
${UT_COVERAGE_COMPILE_FLAGS} | ||
) | ||
target_compile_options(psp-${CFE_PSP_TARGETNAME}-shared PRIVATE | ||
${UT_COVERAGE_COMPILE_FLAGS} | ||
) | ||
|
||
# both the FSW src file and the adaptor file get compiled with override includes | ||
target_include_directories(psp-${CFE_PSP_TARGETNAME}-impl BEFORE PRIVATE | ||
${PSPCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc | ||
) | ||
target_include_directories(psp-${CFE_PSP_TARGETNAME}-shared BEFORE PRIVATE | ||
${PSPCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc | ||
) | ||
|
||
add_executable(coverage-${CFE_PSP_TARGETNAME}-testrunner | ||
src/coveragetest-psp-mcp750-vxworks.c | ||
src/coveragetest-cfe-psp-start.c | ||
src/coveragetest-cfe-psp-support.c | ||
${PSPCOVERAGE_SOURCE_DIR}/shared/src/coveragetest-cfe-psp-exceptionstorage.c | ||
$<TARGET_OBJECTS:psp-${CFE_PSP_TARGETNAME}-shared> | ||
$<TARGET_OBJECTS:psp-${CFE_PSP_TARGETNAME}-impl> | ||
) | ||
|
||
target_link_libraries(coverage-${CFE_PSP_TARGETNAME}-testrunner | ||
${UT_COVERAGE_LINK_FLAGS} | ||
ut-adaptor-${CFE_PSP_TARGETNAME} | ||
ut_psp_cfe_stubs | ||
ut_psp_libc_stubs | ||
ut_osapi_stubs | ||
ut_assert | ||
) | ||
|
||
add_test(coverage-${CFE_PSP_TARGETNAME} coverage-${CFE_PSP_TARGETNAME}-testrunner) | ||
|
||
foreach(TGT ${INSTALL_TARGET_LIST}) | ||
install(TARGETS coverage-${CFE_PSP_TARGETNAME}-testrunner DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR}) | ||
endforeach() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# | ||
# Copyright (c) 2019, United States government as represented by the | ||
# administrator of the National Aeronautics Space Administration. | ||
# All rights reserved. This software was created at NASA Goddard | ||
# Space Flight Center pursuant to government contracts. | ||
# | ||
# This is governed by the NASA Open Source Agreement and may be used, | ||
# distributed and modified only according to the terms of that agreement. | ||
# | ||
|
||
|
||
# "Adaptors" help enable the unit test code to reach functions/objects that | ||
# are otherwise not exposed. | ||
|
||
# NOTE: These source files are compile with OVERRIDES on the headers just like | ||
# the FSW code is compiled. This is how it is able to include internal headers | ||
# which otherwise would fail. But that also means that adaptor code cannot call | ||
# any library functions, as this would also reach a stub, not the real function. | ||
|
||
add_library(ut-adaptor-${CFE_PSP_TARGETNAME} STATIC | ||
src/ut-adaptor-bootrec.c | ||
${PSPCOVERAGE_SOURCE_DIR}/shared/adaptors/src/ut-adaptor-exceptions.c | ||
) | ||
|
||
# the "override_inc" dir contains replacement versions of the C-library include files. | ||
target_include_directories(ut-adaptor-${CFE_PSP_TARGETNAME} BEFORE PRIVATE | ||
${PSPCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc | ||
) | ||
|
||
target_include_directories(ut-adaptor-${CFE_PSP_TARGETNAME} PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/inc | ||
${PSPCOVERAGE_SOURCE_DIR}/shared/adaptors/inc | ||
) |
32 changes: 32 additions & 0 deletions
32
unit-test-coverage/mcp750-vxworks/adaptors/inc/ut-adaptor-bootrec.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020, United States government as represented by the | ||
* administrator of the National Aeronautics Space Administration. | ||
* All rights reserved. This software was created at NASA Goddard | ||
* Space Flight Center pursuant to government contracts. | ||
* | ||
* This is governed by the NASA Open Source Agreement and may be used, | ||
* distributed and modified only according to the terms of that agreement. | ||
* | ||
*/ | ||
|
||
|
||
/** | ||
* \file ut-adaptor-bootrec.h | ||
* \ingroup adaptors | ||
* \author joseph.p.hickey@nasa.gov | ||
* | ||
*/ | ||
|
||
#ifndef INCLUDE_UT_ADAPTOR_BOOTREC_H_ | ||
#define INCLUDE_UT_ADAPTOR_BOOTREC_H_ | ||
|
||
#include <common_types.h> | ||
|
||
void UT_Setup_ReservedMem_BootRec(void); | ||
uint32 UT_Get_ReservedMem_BootType(void); | ||
void UT_Set_ReservedMem_BootType(uint32 reset_type); | ||
|
||
|
||
#endif /* INCLUDE_UT_ADAPTOR_BOOTREC_H_ */ | ||
|
47 changes: 47 additions & 0 deletions
47
unit-test-coverage/mcp750-vxworks/adaptors/src/ut-adaptor-bootrec.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020, United States government as represented by the | ||
* administrator of the National Aeronautics Space Administration. | ||
* All rights reserved. This software was created at NASA Goddard | ||
* Space Flight Center pursuant to government contracts. | ||
* | ||
* This is governed by the NASA Open Source Agreement and may be used, | ||
* distributed and modified only according to the terms of that agreement. | ||
* | ||
*/ | ||
|
||
|
||
/** | ||
* \file ut-adaptor-bootrec.c | ||
* \ingroup adaptors | ||
* \author joseph.p.hickey@nasa.gov | ||
* | ||
*/ | ||
|
||
#include "ut-adaptor-bootrec.h" | ||
#include <cfe_psp_config.h> | ||
#include <cfe_psp_memory.h> | ||
|
||
|
||
static CFE_PSP_ReservedMemoryBootRecord_t UT_BOOTREC; | ||
|
||
static const CFE_PSP_ReservedMemoryBootRecord_t UT_DEFAULT_BOOTREC = { 0 }; | ||
|
||
|
||
void UT_Setup_ReservedMem_BootRec(void) | ||
{ | ||
UT_BOOTREC = UT_DEFAULT_BOOTREC; | ||
CFE_PSP_ReservedMemoryMap.BootPtr = &UT_BOOTREC; | ||
} | ||
|
||
uint32 UT_Get_ReservedMem_BootType(void) | ||
{ | ||
return UT_BOOTREC.bsp_reset_type; | ||
} | ||
|
||
void UT_Set_ReservedMem_BootType(uint32 reset_type) | ||
{ | ||
UT_BOOTREC.bsp_reset_type = reset_type; | ||
} | ||
|
||
|
150 changes: 150 additions & 0 deletions
150
unit-test-coverage/mcp750-vxworks/src/coveragetest-cfe-psp-start.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020, United States government as represented by the | ||
* administrator of the National Aeronautics Space Administration. | ||
* All rights reserved. This software was created at NASA Goddard | ||
* Space Flight Center pursuant to government contracts. | ||
* | ||
* This is governed by the NASA Open Source Agreement and may be used, | ||
* distributed and modified only according to the terms of that agreement. | ||
* | ||
*/ | ||
|
||
|
||
/** | ||
* \file coveragetest-binsem.c | ||
* \ingroup vxworks | ||
* \author joseph.p.hickey@nasa.gov | ||
* | ||
*/ | ||
|
||
|
||
#include "coveragetest-psp-mcp750-vxworks.h" | ||
#include "ut-adaptor-bootrec.h" | ||
|
||
#include <cfe_psp.h> | ||
|
||
#include <PCS_sysLib.h> | ||
#include <PCS_mcpx750.h> | ||
#include <PCS_stdlib.h> | ||
#include <PCS_cfe_configdata.h> | ||
|
||
extern void UT_OS_Application_Startup(void); | ||
extern void UT_OS_Application_Run(void); | ||
|
||
uint32 UT_ReservedMemBuffer[256]; | ||
|
||
typedef struct | ||
{ | ||
uint32 StartType; | ||
uint32 StartSubtype; | ||
} PSP_UT_StartType_t; | ||
|
||
/* | ||
* A hook function that can check/verify the reset sub type | ||
*/ | ||
static int32 Test_Hook_ResetSubType(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) | ||
{ | ||
PSP_UT_StartType_t *UserBuffer = UserObj; | ||
UserBuffer->StartType = UT_Hook_GetArgValueByName(Context, "StartType", uint32); | ||
UserBuffer->StartSubtype = UT_Hook_GetArgValueByName(Context, "StartSubtype", uint32); | ||
return StubRetcode; | ||
} | ||
|
||
void Test_OS_Application_Startup(void) | ||
{ | ||
/* | ||
* Test Case For: | ||
* void OS_Application_Startup(void) | ||
* | ||
* NOTE: The UT assert library itself defines OS_Application_Startup | ||
* To avoid conflict with the UT assert, the unit under test is renamed | ||
* to "UT_OS_Application_Startup" using a preprocessor definition | ||
*/ | ||
PSP_UT_StartType_t StartType; | ||
|
||
/* Install a hook function to grab the start type parameters from the system main call */ | ||
UT_SetHookFunction(UT_KEY(PCS_SystemMain), Test_Hook_ResetSubType, &StartType); | ||
UT_Setup_ReservedMem_BootRec(); | ||
|
||
/* nominal */ | ||
UT_SetDataBuffer(UT_KEY(PCS_sysMemTop), UT_ReservedMemBuffer, sizeof(UT_ReservedMemBuffer), false); | ||
UT_OS_Application_Startup(); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(OS_printf)), 4); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(PCS_SystemMain)), 1); | ||
UtAssert_INT32_EQ(StartType.StartType, CFE_PSP_RST_TYPE_POWERON); | ||
UtAssert_INT32_EQ(StartType.StartSubtype, CFE_PSP_RST_SUBTYPE_UNDEFINED_RESET); | ||
|
||
/* failure of OS_API_Init */ | ||
UT_SetForceFail(UT_KEY(OS_API_Init), OS_ERROR); | ||
UT_OS_Application_Startup(); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(PCS_exit)), 1); | ||
UT_ClearForceFail(UT_KEY(OS_API_Init)); | ||
|
||
/* failure of OS_FileSysAddFixedMap - an extra OS_printf */ | ||
UT_SetForceFail(UT_KEY(OS_FileSysAddFixedMap), OS_ERROR); | ||
UT_OS_Application_Startup(); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(OS_printf)), 9); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(PCS_SystemMain)), 2); | ||
UT_ClearForceFail(UT_KEY(OS_FileSysAddFixedMap)); | ||
|
||
/* coverage for each of the reset types */ | ||
*PCS_SYS_REG_BLRR = PCS_SYS_REG_BLRR_PWRON; | ||
UT_OS_Application_Startup(); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(PCS_SystemMain)), 3); | ||
UtAssert_INT32_EQ(StartType.StartType, CFE_PSP_RST_TYPE_POWERON); | ||
UtAssert_INT32_EQ(StartType.StartSubtype, CFE_PSP_RST_SUBTYPE_POWER_CYCLE); | ||
|
||
*PCS_SYS_REG_BLRR = PCS_SYS_REG_BLRR_PBRST; | ||
UT_OS_Application_Startup(); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(PCS_SystemMain)), 4); | ||
UtAssert_INT32_EQ(StartType.StartType, CFE_PSP_RST_TYPE_POWERON); | ||
UtAssert_INT32_EQ(StartType.StartSubtype, CFE_PSP_RST_SUBTYPE_PUSH_BUTTON); | ||
|
||
*PCS_SYS_REG_BLRR = PCS_SYS_REG_BLRR_FBTN; | ||
UT_OS_Application_Startup(); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(PCS_SystemMain)), 5); | ||
UtAssert_INT32_EQ(StartType.StartType, CFE_PSP_RST_SUBTYPE_PUSH_BUTTON); | ||
UtAssert_INT32_EQ(StartType.StartSubtype, 3); | ||
|
||
*PCS_SYS_REG_BLRR = PCS_SYS_REG_BLRR_WDT2; | ||
UT_OS_Application_Startup(); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(PCS_SystemMain)), 6); | ||
UtAssert_INT32_EQ(StartType.StartType, CFE_PSP_RST_TYPE_PROCESSOR); | ||
UtAssert_INT32_EQ(StartType.StartSubtype, CFE_PSP_RST_SUBTYPE_HW_WATCHDOG); | ||
|
||
*PCS_SYS_REG_BLRR = PCS_SYS_REG_BLRR_SWSRST; | ||
UT_OS_Application_Startup(); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(PCS_SystemMain)), 7); | ||
UtAssert_INT32_EQ(StartType.StartType, CFE_PSP_RST_TYPE_PROCESSOR); | ||
UtAssert_INT32_EQ(StartType.StartSubtype, CFE_PSP_RST_SUBTYPE_RESET_COMMAND); | ||
|
||
*PCS_SYS_REG_BLRR = PCS_SYS_REG_BLRR_SWHRST; | ||
UT_Set_ReservedMem_BootType(CFE_PSP_RST_TYPE_POWERON); | ||
UT_OS_Application_Startup(); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(PCS_SystemMain)), 8); | ||
UtAssert_INT32_EQ(StartType.StartType, CFE_PSP_RST_TYPE_POWERON); | ||
UtAssert_INT32_EQ(StartType.StartSubtype, CFE_PSP_RST_SUBTYPE_RESET_COMMAND); | ||
|
||
UT_Set_ReservedMem_BootType(CFE_PSP_RST_TYPE_PROCESSOR); | ||
UT_OS_Application_Startup(); | ||
UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(PCS_SystemMain)), 9); | ||
UtAssert_INT32_EQ(StartType.StartType, CFE_PSP_RST_TYPE_PROCESSOR); | ||
UtAssert_INT32_EQ(StartType.StartSubtype, CFE_PSP_RST_SUBTYPE_RESET_COMMAND); | ||
|
||
} | ||
|
||
void Test_OS_Application_Run(void) | ||
{ | ||
/* | ||
* Test Case For: | ||
* void OS_Application_Run(void) | ||
* | ||
* NOTE: The UT assert library itself defines OS_Application_Run | ||
* To avoid conflict with the UT assert, the unit under test is renamed | ||
* to "UT_OS_Application_Run" using a preprocessor definition | ||
*/ | ||
|
||
/* The function currently contains an infinite loop so cannot be tested now */ | ||
} | ||
|
Oops, something went wrong.