Skip to content

Commit

Permalink
Fix nasa#285, Refactor OSAL to avoid inclusion of C files
Browse files Browse the repository at this point in the history
Use separate source files and CMake-based source selection
to configure OSAL features, rather than using the C preprocessor.

This commit covers the OSAL coverage test.  This had been using
inclusion of a C file to allow access to static functions/variables.
This updates all UT code to correspond with the FSW code changes.
All "static" helper functions become non-static so unit test can
invoke directly.  Prototype is in a private header, so
the functions are still not exposed in the API.
  • Loading branch information
jphickey committed May 4, 2020
1 parent 2edd5bd commit 636bd7c
Show file tree
Hide file tree
Showing 223 changed files with 6,525 additions and 4,711 deletions.
65 changes: 26 additions & 39 deletions src/unit-test-coverage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enable_testing()
# code coverage analysis. Because the actual underlying OS calls are stubbed out, there
# is no dependency on the actual underlying OS. Note that RTEMS is not included as the
# coverage test is not implemented at this time.
set(OSALCOVERAGE_TARGET_OSTYPE "vxworks;posix;shared" CACHE STRING "OSAL target(s) to build coverage tests for (default=all)")
set(OSALCOVERAGE_TARGET_OSTYPE "vxworks;shared" CACHE STRING "OSAL target(s) to build coverage tests for (default=all)")

# Check that coverage has been implemented for this OSTYPE
foreach(OSTYPE ${OSALCOVERAGE_TARGET_OSTYPE})
Expand All @@ -44,63 +44,50 @@ message(STATUS "Coverage Test Target OS: ${OSALCOVERAGE_TARGET_OSTYPE}")
# Utilize the shared UT assert library, along with the standard OSAL includes
include_directories(${UT_ASSERT_SOURCE_DIR}/inc)
include_directories(${OSAL_SOURCE_DIR}/src/os/inc)
include_directories(${OSAL_SOURCE_DIR}/src/os/shared)
include_directories(${OSAL_SOURCE_DIR}/src/os/shared/inc)
include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/inc)

# The OSALCOVERAGE_STUB_LIB_LIST is a list of stub libraries to link the
# test runner executables with. It will be appended at various points
# depending on what is under test.
set(OSALCOVERAGE_STUB_LIB_LIST)
add_subdirectory(ut-stubs)

# The "ut_osapi_stubs" library is the stubs for the OSAL public API
# this should be supplied by the parent build
list(APPEND OSALCOVERAGE_STUB_LIB_LIST ut_osapi_stubs)

# A generic function to add a coverage test case source file
# This combines the following into an executable
# - The test case setup (a C source file starting with "coveragetest" prefix)
# - The object code of the unit under test (special build with instrumentation)
# - Links to the stub libraries of everything else, plus UT assert
function (add_coverage_tests SETNAME)
foreach(MODNAME ${ARGN})
set (TESTCASE_SRCFILE)
foreach (SRCFILE
"${PROJECT_SOURCE_DIR}/portable/coveragetest-${MODNAME}.c"
"${CMAKE_CURRENT_SOURCE_DIR}/src/coveragetest-${MODNAME}.c"
function (add_coverage_testrunner TESTNAME FSW_SRCFILE TESTCASE_SRCFILE)
add_library(utobj_${TESTNAME} OBJECT
${FSW_SRCFILE}
)
if (EXISTS "${SRCFILE}")
set (TESTCASE_SRCFILE "${SRCFILE}")
endif (EXISTS "${SRCFILE}")
endforeach()

if (TESTCASE_SRCFILE)
set(TESTNAME "coverage-${SETNAME}-${MODNAME}")
# only the actual FSW src file gets the coverage instrumentation
target_compile_options(utobj_${TESTNAME} PRIVATE
${UT_COVERAGE_COMPILE_FLAGS}
)

if (DEFINED MODULE_LINK_MAP_${MODNAME})
set(LINKMOD ${MODULE_LINK_MAP_${MODNAME}})
else()
set(LINKMOD ${MODNAME})
endif()
# both the FSW src file and the adaptor file get compiled with override includes
target_include_directories(utobj_${TESTNAME} BEFORE PRIVATE
${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc
)

add_executable(${TESTNAME}-testrunner
# the testcase is compiled with no special flags or override includes
add_executable(${TESTNAME}-testrunner
${TESTCASE_SRCFILE}
$<TARGET_OBJECTS:ut_${SETNAME}_${LINKMOD}>)
$<TARGET_OBJECTS:utobj_${TESTNAME}>
)

target_link_libraries(${TESTNAME}-testrunner
target_link_libraries(${TESTNAME}-testrunner
${UT_COVERAGE_LINK_FLAGS}
${OSALCOVERAGE_STUB_LIB_LIST}
${ARGN}
ut_assert
)
add_test(${TESTNAME} ${TESTNAME}-testrunner)
)

foreach(TGT ${INSTALL_TARGET_LIST})
install(TARGETS ${TESTNAME}-testrunner DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR})
endforeach()
add_test(${TESTNAME} ${TESTNAME}-testrunner)

endif()
endforeach(MODNAME ${ARGN})
foreach(TGT ${INSTALL_TARGET_LIST})
install(TARGETS ${TESTNAME}-testrunner DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR})
endforeach()

endfunction(add_coverage_tests SETNAME)
endfunction()


foreach(SETNAME ${OSALCOVERAGE_TARGET_OSTYPE})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
*
* 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-portable-posix-files.h
* \ingroup adaptors
* \author joseph.p.hickey@nasa.gov
*
*/

#ifndef INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_FILES_H_
#define INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_FILES_H_

#include <common_types.h>

unsigned int UT_PortablePosixFileTest_GetSelfEUID(void);
unsigned int UT_PortablePosixFileTest_GetSelfEGID(void);

#endif /* INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_FILES_H_ */

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
*
* 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-portable-posix-io.h
* \ingroup adaptors
* \author joseph.p.hickey@nasa.gov
*
*/

#ifndef INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_IO_H_
#define INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_IO_H_



/**
* \file ut-osfileapi.h
* \ingroup adaptors
* \author joseph.p.hickey@nasa.gov
*
*/

#ifndef _UT_PPOSFILEAPI_H_
#define _UT_PPOSFILEAPI_H_

#include <common_types.h>

/*****************************************************
*
* UT FUNCTION PROTOTYPES
*
* These are functions that need to be invoked by UT
* but are not exposed directly through the implementation API.
*
*****************************************************/
void UT_PortablePosixIOTest_Set_Selectable(uint32 local_id, bool is_selectable);

#endif /* _UT_OSFILEAPI_H_ */


#endif /* INCLUDE_UT_ADAPTOR_PORTABLE_POSIX_IO_H_ */

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
*
* 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-portable-posix-files.c
* \ingroup adaptors
* \author joseph.p.hickey@nasa.gov
*
*/


/* pull in the OSAL configuration */
#include "osconfig.h"
#include "ut-adaptor-portable-posix-files.h"

#include <os-impl-files.h>

unsigned int UT_PortablePosixFileTest_GetSelfEUID(void)
{
return OS_IMPL_SELF_EUID;
}

unsigned int UT_PortablePosixFileTest_GetSelfEGID(void)
{
return OS_IMPL_SELF_EGID;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
*
* 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-portable-posix-io.c
* \ingroup adaptors
* \author joseph.p.hickey@nasa.gov
*
*/

/* pull in the OSAL configuration */
#include "osconfig.h"
#include "ut-adaptor-portable-posix-io.h"

#include <os-impl-io.h>


void UT_PortablePosixIOTest_Set_Selectable(uint32 local_id, bool is_selectable)
{
OS_impl_filehandle_table[local_id].selectable = is_selectable;
}
111 changes: 0 additions & 111 deletions src/unit-test-coverage/portable/coveragetest-posixgettime.c

This file was deleted.

Loading

0 comments on commit 636bd7c

Please sign in to comment.