Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #413, Add coverage tests for pc-rtems #414

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ target_include_directories(psp-${CFE_PSP_TARGETNAME} INTERFACE
if (ENABLE_UNIT_TESTS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ut-stubs)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unit-test-coverage)
endif (ENABLE_UNIT_TESTS)
endif ()

4 changes: 1 addition & 3 deletions fsw/pc-rtems/src/cfe_psp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <rtems/rtems_dhcp_failsafe.h>
#include <bsp.h>

extern int rtems_fxp_attach(struct rtems_bsdnet_ifconfig *config, int attaching);

/*
** cFE includes
*/
Expand Down Expand Up @@ -145,7 +143,7 @@ void OS_Application_Startup(void)
{
if (CFE_PSP_Setup() != RTEMS_SUCCESSFUL)
{
CFE_PSP_Panic(CFE_PSP_ERROR);
CFE_PSP_Panic(CFE_PSP_ERROR); /* Unreachable currently - CFE_PSP_Setup always returns RTEMS_SUCCESSFUL */
}

/*
Expand Down
9 changes: 4 additions & 5 deletions unit-test-coverage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@

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)")
set(PSPCOVERAGE_TARGETS mcp750-vxworks pc-rtems 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})
endif ()
endforeach()

message(STATUS "PSP Coverage Test Targets: ${PSPCOVERAGE_TARGETS}")

Expand All @@ -35,5 +34,5 @@ add_subdirectory(modules)
# Build targets for each of the indicated PSPs
foreach(SETNAME ${PSPCOVERAGE_TARGETS})
add_subdirectory(${SETNAME})
endforeach(SETNAME ${PSPCOVERAGE_TARGETS})
endforeach()

6 changes: 3 additions & 3 deletions unit-test-coverage/mcp750-vxworks/adaptors/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# "Adaptors" help enable the unit test code to reach functions/objects that
# are otherwise not exposed.
# are otherwise not exposed.

# NOTE: These source files are compiled with OVERRIDES on the headers just like
# the FSW code is compiled. This is how it is able to include internal headers
Expand All @@ -21,7 +21,7 @@ target_include_directories(ut-adaptor-${CFE_PSP_TARGETNAME} PUBLIC
${PSPCOVERAGE_SOURCE_DIR}/shared/adaptors/inc
)

target_link_libraries(ut-adaptor-${CFE_PSP_TARGETNAME} PRIVATE
target_link_libraries(ut-adaptor-${CFE_PSP_TARGETNAME} PRIVATE
psp_module_api
ut_assert
ut_assert
)
2 changes: 1 addition & 1 deletion unit-test-coverage/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function(add_psp_covtest MODULE_NAME TESTCASE_SRC UT_SRCS)
install(TARGETS ${RUNNER_TARGET} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR})
endforeach()

endfunction(add_psp_covtest)
endfunction()


# a list of modules for which there is a coverage test implemented
Expand Down
50 changes: 50 additions & 0 deletions unit-test-coverage/pc-rtems/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
######################################################################
#
# CMake build recipe for pc-rtems PSP white-box coverage tests
#
######################################################################

include_directories(${CFEPSP_SOURCE_DIR}/fsw/pc-rtems/inc)
include_directories(${PSPCOVERAGE_SOURCE_DIR}/shared/inc)
skliper marked this conversation as resolved.
Show resolved Hide resolved

# Target names use a "ut" prefix to avoid confusion with 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)
skliper marked this conversation as resolved.
Show resolved Hide resolved

# The UT assert library defines OS_Application_Startup, so this redefines ours with a "UT_" prefix
target_compile_definitions(psp-${CFE_PSP_TARGETNAME}-impl PRIVATE
OS_Application_Startup=UT_OS_Application_Startup
)

foreach(TGT psp-${CFE_PSP_TARGETNAME}-impl psp-${CFE_PSP_TARGETNAME}-shared)
target_compile_options(${TGT} PRIVATE ${UT_COVERAGE_COMPILE_FLAGS})
target_include_directories(${TGT} BEFORE PRIVATE ${PSPCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc)
endforeach()
skliper marked this conversation as resolved.
Show resolved Hide resolved

add_executable(coverage-${CFE_PSP_TARGETNAME}-testrunner
src/coveragetest-cfe-psp-exception.c
src/coveragetest-cfe-psp-memory.c
src/coveragetest-cfe-psp-ssr.c
src/coveragetest-cfe-psp-start.c
src/coveragetest-cfe-psp-support.c
src/coveragetest-cfe-psp-watchdog.c
src/coveragetest-psp-pc-rtems.c
$<TARGET_OBJECTS:psp-${CFE_PSP_TARGETNAME}-shared>
skliper marked this conversation as resolved.
Show resolved Hide resolved
$<TARGET_OBJECTS:psp-${CFE_PSP_TARGETNAME}-impl>
)

target_link_libraries(coverage-${CFE_PSP_TARGETNAME}-testrunner PUBLIC
${UT_COVERAGE_LINK_FLAGS}
psp_module_api
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 ${TGT}/${UT_INSTALL_SUBDIR})
endforeach()
51 changes: 51 additions & 0 deletions unit-test-coverage/pc-rtems/src/coveragetest-cfe-psp-exception.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

#include "coveragetest-psp-pc-rtems.h"

#include "cfe_psp.h"
#include "PCS_stdlib.h"

extern int32 CFE_PSP_ExceptionGetSummary_Impl(void *, char *, uint32);
extern void CFE_PSP_SetupReservedMemoryMap(void);

uint32 UT_AttachExceptionsBuffer[1024];

void Test_CFE_PSP_AttachExceptions(void)
{
/* Need to call CFE_PSP_SetupReservedMemoryMap here for initialization of CFE_PSP_ReservedMemoryMap */
UT_SetDataBuffer(UT_KEY(PCS_malloc), UT_AttachExceptionsBuffer, sizeof(UT_AttachExceptionsBuffer), false);
CFE_PSP_SetupReservedMemoryMap();
UT_ResetState(UT_KEY(OS_printf)); /* Reset so calls to OS_printf in the setup above don't affect the actual test */

/* Nominal path */
CFE_PSP_AttachExceptions();
UtAssert_STUB_COUNT(OS_printf, 1);
}

void Test_CFE_PSP_ExceptionGetSummary_Impl(void)
{
/* Placeholder test to exercise function - amend tests if/when function is fully implemented */
UtAssert_INT32_EQ(CFE_PSP_ExceptionGetSummary_Impl(NULL, NULL, 4), CFE_PSP_ERROR_NOT_IMPLEMENTED);
}

void Test_CFE_PSP_SetDefaultExceptionEnvironment(void)
{
/* Placeholder test to exercise function - amend tests if/when function is fully implemented */
CFE_PSP_SetDefaultExceptionEnvironment();
}
143 changes: 143 additions & 0 deletions unit-test-coverage/pc-rtems/src/coveragetest-cfe-psp-memory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

#include "coveragetest-psp-pc-rtems.h"

#include "cfe_psp.h"
#include "PCS_stdlib.h"

extern int32 CFE_PSP_InitProcessorReservedMemory(uint32 ResetType);
extern void CFE_PSP_SetupReservedMemoryMap(void);

/* Blocks of 'heap' memory for emulated calls to malloc (via PCS_malloc) in the tests */
uint32 UT_MemoryMapBuffer[1024];
uint32 UT_TooSmallMemoryMapBuffer[1];

void Test_CFE_PSP_GetCDSSize(void)
{
uint32 SizeOfCDS;

/* Test NULL pointer guard */
UtAssert_INT32_EQ(CFE_PSP_GetCDSSize(NULL), OS_ERROR);

/* Nominal/success path */
UtAssert_INT32_EQ(CFE_PSP_GetCDSSize(&SizeOfCDS), OS_SUCCESS);
}

void Test_CFE_PSP_WriteToCDS(void)
{
uint32 CDSOffset = 8;
uint32 NumBytes = 8;

/* Test NULL pointer guard */
UtAssert_INT32_EQ(CFE_PSP_WriteToCDS(NULL, CDSOffset, NumBytes), OS_ERROR);
}

void Test_CFE_PSP_ReadFromCDS(void)
{
uint32 CDSOffset = 8;
uint32 NumBytes = 8;

/* Test NULL pointer guard */
UtAssert_INT32_EQ(CFE_PSP_ReadFromCDS(NULL, CDSOffset, NumBytes), OS_ERROR);
}

void Test_CFE_PSP_GetResetArea(void)
{
cpuaddr PtrToResetArea;
uint32 SizeOfResetArea;

/* Test both NULL pointer guards */
UtAssert_INT32_EQ(CFE_PSP_GetResetArea(NULL, &SizeOfResetArea), OS_ERROR);
UtAssert_INT32_EQ(CFE_PSP_GetResetArea(&PtrToResetArea, NULL), OS_ERROR);

/* Nominal/success path */
UtAssert_INT32_EQ(CFE_PSP_GetResetArea(&PtrToResetArea, &SizeOfResetArea), OS_SUCCESS);
}

void Test_CFE_PSP_GetUserReservedArea(void)
{
cpuaddr PtrToUserArea;
uint32 SizeOfUserArea;

/* Test both NULL pointer guards */
UtAssert_INT32_EQ(CFE_PSP_GetUserReservedArea(NULL, &SizeOfUserArea), OS_ERROR);
UtAssert_INT32_EQ(CFE_PSP_GetUserReservedArea(&PtrToUserArea, NULL), OS_ERROR);

/* Nominal/success path */
UtAssert_INT32_EQ(CFE_PSP_GetUserReservedArea(&PtrToUserArea, &SizeOfUserArea), OS_SUCCESS);
}

void Test_CFE_PSP_GetVolatileDiskMem(void)
{
cpuaddr PtrToVolDisk;
uint32 SizeOfVolDisk;

/* Test both NULL pointer guards */
UtAssert_INT32_EQ(CFE_PSP_GetVolatileDiskMem(NULL, &SizeOfVolDisk), OS_ERROR);
UtAssert_INT32_EQ(CFE_PSP_GetVolatileDiskMem(&PtrToVolDisk, NULL), OS_ERROR);

/* Nominal/success path */
UtAssert_INT32_EQ(CFE_PSP_GetVolatileDiskMem(&PtrToVolDisk, &SizeOfVolDisk), OS_SUCCESS);
}

void Test_CFE_PSP_SetupReservedMemoryMap(void)
{
/* Test NULL ReservedMemBlock.BlockPtr path and early abort due to failure of malloc with a too-small heap */
UT_SetDataBuffer(UT_KEY(PCS_malloc), UT_TooSmallMemoryMapBuffer, sizeof(UT_TooSmallMemoryMapBuffer), false);
CFE_PSP_SetupReservedMemoryMap();
UtAssert_STUB_COUNT(PCS_abort, 1);
UT_ResetState(UT_KEY(PCS_malloc)); /* Reset so cleared for next test */
UT_ResetState(UT_KEY(OS_printf)); /* Reset so cleared for next test */

/* Nominal/success path with sufficiently sized 'heap' for emulated call to malloc */
UT_SetDataBuffer(UT_KEY(PCS_malloc), UT_MemoryMapBuffer, sizeof(UT_MemoryMapBuffer), false);
CFE_PSP_SetupReservedMemoryMap();
UtAssert_STUB_COUNT(OS_printf, 3); /* 3 calls to OS_printf along nominal path in CFE_PSP_SetupReservedMemoryMap */
}

void Test_CFE_PSP_InitProcessorReservedMemory(void)
{
/* Always returns CFE_PSP_SUCCESS */
UtAssert_INT32_EQ(CFE_PSP_InitProcessorReservedMemory(CFE_PSP_RST_TYPE_POWERON), CFE_PSP_SUCCESS);
}

void Test_CFE_PSP_GetKernelTextSegmentInfo(void)
{
cpuaddr PtrToKernelSegment;
uint32 SizeOfKernelSegment;

/* Test both NULL pointer guards */
UtAssert_INT32_EQ(CFE_PSP_GetKernelTextSegmentInfo(NULL, &SizeOfKernelSegment), OS_ERROR);
UtAssert_INT32_EQ(CFE_PSP_GetKernelTextSegmentInfo(&PtrToKernelSegment, NULL), OS_ERROR);

/* Nominal/success path */
UtAssert_INT32_EQ(CFE_PSP_GetKernelTextSegmentInfo(&PtrToKernelSegment, &SizeOfKernelSegment), OS_SUCCESS);
}

void Test_CFE_PSP_GetCFETextSegmentInfo(void)
{
cpuaddr PtrToCFESegment;
uint32 SizeOfCFESegment;

/* Test NULL pointer guard */
UtAssert_INT32_EQ(CFE_PSP_GetCFETextSegmentInfo(&PtrToCFESegment, NULL), OS_ERROR);

/* Nominal/success path */
UtAssert_INT32_EQ(CFE_PSP_GetCFETextSegmentInfo(&PtrToCFESegment, &SizeOfCFESegment), OS_SUCCESS);
}
31 changes: 31 additions & 0 deletions unit-test-coverage/pc-rtems/src/coveragetest-cfe-psp-ssr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

#include "coveragetest-psp-pc-rtems.h"

#include "cfe_psp.h"

void Test_CFE_PSP_InitSSR(void)
{
uint32 bus = 1;
uint32 device = 1;
char DeviceName[] = "TestDevice";

/* Placeholder test to exercise function - amend tests if/when function is fully implemented */
UtAssert_INT32_EQ(CFE_PSP_InitSSR(bus, device, DeviceName), CFE_PSP_SUCCESS);
}
Loading