diff --git a/CMakeLists.txt b/CMakeLists.txt index 28ce58a06..e0852e5dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,263 +1,276 @@ -cmake_minimum_required(VERSION 2.6.4) -project(OSAL C) - -enable_testing() - -# Generic function for consistent definition of a unit testing target -# This is defined here in the top-level OSAL CMakeLists so it can be used -# in both the "tests" and "unit-tests" subdirectories. -# These binaries are linked with the "ut_osal" and "ut_assert" libraries -function(add_osal_ut_exe TGTNAME) - - add_executable(${TGTNAME} ${ARGN}) - # Need to force the OS_VolumeTable as undefined to be sure the linker pulls it in - # This is workaround specific to UT builds that run the *REAL* OSAL (in other words, - # the unit test for OSAL itself). - # It is not an issue for UT builds that use OSAL stubs or no OSAL at all. - set_target_properties(${TGTNAME} PROPERTIES COMPILE_DEFINITIONS "_UNIT_TEST_") - set_target_properties(${TGTNAME} PROPERTIES COMPILE_FLAGS "${UT_C_FLAGS}") - set_target_properties(${TGTNAME} PROPERTIES LINK_FLAGS "${UT_C_FLAGS} -u OS_VolumeTable -u OS_Application_Startup") - target_link_libraries(${TGTNAME} ut_assert osal) - add_test(${TGTNAME} ${TGTNAME}) - foreach(TGT ${INSTALL_TARGET_LIST}) - install(TARGETS ${TGTNAME} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR}) - endforeach() - -endfunction(add_osal_ut_exe) - +###################################################################### +# +# CMAKE build recipe for Operating System Abstraction Layer (OSAL) +# +###################################################################### +# +# This defines the following static library target(s): +# +# osal : The main library containing the OSAL binary code +# This is based off the OSAL_SYSTEM_OSTYPE selection +# +# osal_bsp : The board support library containing the system- +# specific entry point function (e.g. main) and the +# file system volume table for the target board. +# This is based off the OSAL_SYSTEM_BSPTYPE selection +# +# ut_assert : The unit test support library. This implements +# an application entry point (OS_Application_Startup) +# that contains a unit test subsystem. This uses +# the OSAL BSP to provide system-specific entry point. +# Linking with this library also links with osal_bsp, +# but not necessarily the osal library itself. +# +# Additionally the following target is defined if ENABLE_UNIT_TESTS +# is set TRUE: # -# Assembly of the FLAGS used for compiler invocation: -# -# This currently consists of four sets of flags, depending on scope: -# -# OSAL_COMMON_COMPILE_DEFS ==> Generic Compile Flags, applies to all BSPs, both C and C++ -# OSAL_C_FLAGS ==> Compile Flags specific to C code -# OSAL_CXX_FLAGS ==> Compile Flags specific to C++ code -# BSP_COMPILE_FLAGS ==> Flags specific to the BSP in use for both C and C++ +# ut_osapi_stubs : Stub library correlating to the OSAL public API +# This is for unit testing OSAL-based applications +# It operates in conjunction with the ut_assert library. # -# The osal_assemble_compiler_flags() function will set the relevant variables -# for the OSAL build based on the selected OSTYPE and BSPTYPE +# This also exports the following variables: # -function(osal_assemble_compiler_flags OSTYPE BSPTYPE) - - # Reset the local variables to initial state - set(OSAL_COMMON_COMPILE_DEFS) - set(OSAL_C_FLAGS) - set(OSAL_CXX_FLAGS) - set(BSP_COMPILE_FLAGS) - set(UT_C_FLAGS) - set(OSAL_LINK_LIBS) - - # Include the OS-specific compiler options - # NOTE: OSTYPE may be passed as FALSE to skip OS-specific flags - if (OSTYPE) - include(${OSAL_SOURCE_DIR}/src/os/${OSTYPE}/build_options.cmake OPTIONAL) - endif() - - # Include the BSP/PSP-specific compiler options - # NOTE: BSPTYPE may be passed as FALSE to skip BSP-specific flags - if (BSPTYPE) - include(${OSAL_SOURCE_DIR}/src/bsp/${BSPTYPE}/make/build_options.cmake OPTIONAL) - endif() - - # Set up the final set of C flags for the build. This is the sum of what the toolchain needs, - # what the BSP/PSP has added and anything else that the user has asked for. - set(CMAKE_C_FLAGS - "${CMAKE_C_FLAGS_INIT} ${OSAL_COMMON_COMPILE_DEFS} ${BSP_COMPILE_FLAGS} ${OSAL_USER_C_FLAGS} ${OSAL_C_FLAGS}" - PARENT_SCOPE) - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS_INIT} ${OSAL_COMMON_COMPILE_DEFS} ${BSP_COMPILE_FLAGS} ${OSAL_USER_CXX_FLAGS} ${OSAL_CXX_FLAGS}" - PARENT_SCOPE) - - # Additionally export other relevant information to the caller - set(BSP_UT_C_FLAGS ${UT_C_FLAGS} PARENT_SCOPE) - set(OSAL_LINK_LIBS ${OSAL_LINK_LIBS} PARENT_SCOPE) - if (INSTALL_SUBDIR) - set(INSTALL_SUBDIR ${INSTALL_SUBDIR} PARENT_SCOPE) - endif (INSTALL_SUBDIR) - -endfunction(osal_assemble_compiler_flags OSTYPE BSPTYPE) - -# Cache any user-specified C flags so they will be retained in future builds -# These can be specified either through cmake command line (e.g. -DUSER_C_FLAGS=-Werror) or -# through an environment variable (e.g. OSAL_USER_C_FLAGS=-Werror cmake ...) -set(OSAL_USER_C_FLAGS "$ENV{OSAL_USER_C_FLAGS}" CACHE STRING "User-specified C flags for OSAL build") -set(OSAL_USER_CXX_FLAGS "$ENV{OSAL_USER_CXX_FLAGS}" CACHE STRING "User-specified C++ flags for OSAL build") - -# OSAL_SYSTEM_OSTYPE indicates which of the OS packages to include -# This is required and must be defined -if (OSAL_SYSTEM_OSTYPE AND - IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/os/${OSTYPE}") - set(OSAL_SELECTED_OSTYPE ${OSAL_SYSTEM_OSTYPE}) -else() +# OSAL_BSP_STAGING_INSTALL_DIR : the location of the staging directory +# for the selected OSAL BSP. This can be used in +# post-build rules or "install()" commands to stage +# binary or data files for execution. +# +# UT_COVERAGE_COMPILE_FLAGS : Compiler flags that must be used to +# instrument code for coverage testing +# UT_COVERAGE_LINK_FLAGS : Linker flags that must be used to +# instrument code for coverage testing +# +# The ENABLE_UNIT_TESTS option also builds a set of test applications from +# that demonstrate the usage and validate the runtime behavior of various +# OSAL resources. +# +###################################################################### +cmake_minimum_required(VERSION 2.8.12) +project(OSAL C) + +# OSAL_SYSTEM_OSTYPE and OSAL_SYSTEM_BSPTYPE indicate which of the OS packages +# to build. These are required and must be defined. Confirm that this exists +# and error out now if it does not. +if (NOT DEFINED OSAL_SYSTEM_OSTYPE OR + NOT IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/os/${OSAL_SYSTEM_OSTYPE}") # It is an error if the indicated OSTYPE does not correspond to a subdirectory # If this is not caught here then a more obfuscated error will occur later. + message("Error: \"${OSAL_SYSTEM_OSTYPE}\" is not a valid OS type") message(FATAL_ERROR "OSAL_SYSTEM_OSTYPE must be set to the appropriate OS") endif () +if (NOT DEFINED OSAL_SYSTEM_BSPTYPE OR + NOT IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/bsp/${OSAL_SYSTEM_BSPTYPE}") + # It is an error if the indicated BSPTYPE does not correspond to a subdirectory + # If this is not caught here then a more obfuscated error will occur later. + message("Error: \"${OSAL_SYSTEM_BSPTYPE}\" is not a valid BSP type") + message(FATAL_ERROR "OSAL_SYSTEM_BSPTYPE must be set to the appropriate BSP") +endif () + +message(STATUS "OSAL Selection: ${OSAL_SYSTEM_OSTYPE}") +message(STATUS "BSP Selection: ${OSAL_SYSTEM_BSPTYPE}") + +# The initial set of directories that define the OSAL API +# This is used to initialize the interface include directory property of external targets +set(OSAL_API_INCLUDE_DIRECTORIES + "${OSAL_SOURCE_DIR}/src/os/inc" + "${CMAKE_BINARY_DIR}/inc" + ${OSAL_INCLUDEDIR} +) +include_directories(${OSAL_API_INCLUDE_DIRECTORIES}) -message(STATUS "OSAL Selection: ${OSAL_SELECTED_OSTYPE}") - - -# OSAL_SYSTEM_BSPTYPE indicates which of the BSP packages to include -# It is optional to build this library (e.g. cFE includes its own PSP) -# If used, this should also define the installation location for binaries, -# which depends on the bsp volume table -# This may also set more "-D" options to the compiler command in order to -# build code properly for this OS -# This should not be included if CFE_SYSTEM_PSPNAME is given, since the PSP -# replaces the OSAL BSP -set(OSAL_SELECTED_BSPTYPE FALSE) -if (OSAL_SYSTEM_BSPTYPE AND NOT CFE_SYSTEM_PSPNAME) - if (IS_DIRECTORY ${OSAL_SOURCE_DIR}/src/bsp/${OSAL_SYSTEM_BSPTYPE}) - set(OSAL_SELECTED_BSPTYPE ${OSAL_SYSTEM_BSPTYPE}) - message(STATUS "OSAL BSP Selection: ${OSAL_SELECTED_BSPTYPE}") - else() - message(FATAL_ERROR "Error: ${OSAL_SYSTEM_BSPTYPE} is not a valid BSP") - endif() -endif (OSAL_SYSTEM_BSPTYPE AND NOT CFE_SYSTEM_PSPNAME) - -# Set up the final set of C flags for the build. This is the sum of what the toolchain needs, -# what the BSP/PSP has added and anything else that the user has asked for. -osal_assemble_compiler_flags(${OSAL_SELECTED_OSTYPE} ${OSAL_SELECTED_BSPTYPE}) - -# At a mimimum, also compile with -Wall to show extra warnings. Only do this if nothing -# added it already (prevents adding this twice in case the User/BSP/PSP already specified it) -if (NOT CMAKE_C_FLAGS MATCHES "-Wall") - set(CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}") -endif(NOT CMAKE_C_FLAGS MATCHES "-Wall") - -message(STATUS "OSAL Compile Definitions: ${CMAKE_C_FLAGS}") -message(STATUS "OSAL Link Libraries: ${OSAL_LINK_LIBS}") - -# Use the OSAL shared include directory -include_directories(src/os/inc) -include_directories(src/os/shared) - -# Use the UT assert include directory -# Although this is only used for unit tests, putting this out here -# rather than in the "if(ENABLE_UNIT_TESTS)" section keeps things consistent -# between the UT and non-UT builds -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ut_assert/inc) - -# Include any user-specified header file directory -if (OSAL_INCLUDEDIR) - include_directories(${OSAL_INCLUDEDIR}) -endif (OSAL_INCLUDEDIR) - -# Use all source files under the specific OS and BSP directories -# Use the shared code directory if the OS layer requires it -aux_source_directory(src/os/shared OSALFILES) -aux_source_directory(src/os/${OSAL_SELECTED_OSTYPE} OSALFILES) -if (OSAL_SELECTED_BSPTYPE) - aux_source_directory(src/bsp/${OSAL_SELECTED_BSPTYPE}/src BSPFILES) -endif (OSAL_SELECTED_BSPTYPE) - -add_library(osal STATIC ${OSALFILES} ${BSPFILES}) -target_link_libraries(osal ${OSAL_LINK_LIBS}) - -# Determine if this build is standalone or part of a larger build -# If this is part of a larger build, certain key values will be exported to the parent -# Do this now, before adding the unit test logic into the mix -get_directory_property(BUILD_PARENT PARENT_DIRECTORY) -if (BUILD_PARENT) - # Important - all code in the entire build should be built using - # at least the same C_FLAGS as OSAL used, so push this to parent scope - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} PARENT_SCOPE) - set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE) - set(INSTALL_SUBDIR ${INSTALL_SUBDIR} PARENT_SCOPE) -endif (BUILD_PARENT) +# In case the OSAL_USER_C_FLAGS was specified, use them +add_definitions(${OSAL_USER_C_FLAGS}) # -# UNIT TEST SUPPORT LIBRARIES -# the basic library targets are now always created regardless of "ENABLE_UNIT_TESTS", -# but flagged using "EXCLUDE_FROM_ALL" so they won't be built unless actually used. +# Build UT assert - +# the basic ut_assert library target is always defined regardless of "ENABLE_UNIT_TESTS", +# but flagged using "EXCLUDE_FROM_ALL" so they won't be built unless actually used. This +# is because the library is usable with functional tests, not just unit (coverage) tests. +# This is done early, so that other targets may reference UT_ASSERT_SOURCE_DIR if needed +add_subdirectory(ut_assert) + + +# +# Step 1: +# Build the BSP layer # +# The BSP library is a separate target from OSAL and can be used +# independently of the OSAL library and/or in combination with +# UT assert and the OSAL stub library for unit testing. +# +# The Implementation-Specific BSP subdirectory should define +# an OBJECT target named "osal_${OSAL_SYSTEM_BSPTYPE}_impl" +add_subdirectory(src/bsp/${OSAL_SYSTEM_BSPTYPE} ${OSAL_SYSTEM_BSPTYPE}_impl) +target_include_directories(osal_${OSAL_SYSTEM_BSPTYPE}_impl PRIVATE + ${OSAL_SOURCE_DIR}/src/bsp/shared +) + +# Propagate the BSP-specific compile definitions and include directories +# Apply these to the directory-scope COMPILE_DEFINITIONS and INCLUDE_DIRECTORIES +# Note this needs to append to the directory property, not overwrite it. +get_directory_property(OSAL_BASE_COMPILE_DEFINITIONS COMPILE_DEFINITIONS) +get_target_property(OSAL_BSP_COMPILE_DEFINITIONS osal_${OSAL_SYSTEM_BSPTYPE}_impl INTERFACE_COMPILE_DEFINITIONS) +set(OSAL_COMPILE_DEFINITIONS) +if (OSAL_BASE_COMPILE_DEFINITIONS) + list(APPEND OSAL_COMPILE_DEFINITIONS ${OSAL_BASE_COMPILE_DEFINITIONS}) +endif (OSAL_BASE_COMPILE_DEFINITIONS) +if (OSAL_BSP_COMPILE_DEFINITIONS) + list(APPEND OSAL_COMPILE_DEFINITIONS ${OSAL_BSP_COMPILE_DEFINITIONS}) +endif (OSAL_BSP_COMPILE_DEFINITIONS) +set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${OSAL_COMPILE_DEFINITIONS}") +message(STATUS "OSAL Compile Definitions: ${OSAL_COMPILE_DEFINITIONS}") + +# The include directories is simpler, as the include_directories() function +# appends to the directory property +get_target_property(OSAL_BSP_INCLUDE_DIRECTORIES osal_${OSAL_SYSTEM_BSPTYPE}_impl INTERFACE_INCLUDE_DIRECTORIES) +if (OSAL_BSP_INCLUDE_DIRECTORIES) + include_directories(${OSAL_BSP_INCLUDE_DIRECTORIES}) +endif (OSAL_BSP_INCLUDE_DIRECTORIES) + + +# Define the external "osal_bsp" static library target +add_library(osal_bsp STATIC + src/bsp/shared/osapi-bsp.c + src/bsp/shared/bsp_default_app_run.c + src/bsp/shared/bsp_default_app_startup.c + src/bsp/shared/bsp_default_symtab.c + $ +) + +target_include_directories(osal_bsp INTERFACE + ${OSAL_API_INCLUDE_DIRECTORIES} +) -# NOTE: The "ut_assert" and "ut_bsp" libraries are usable by ANY and ALL subsystem(s) that need -# to do unit testing of any kind. These provide the basic startup procedure, test message output -# abstractions, and all the "assert" calls to perform unit testing. They specifically do NOT -# include any stub functions, as the configuration of stubs vs. real implementations are specific -# to the unit being tested. - -# The "utassert" library is the core GSFC-provided unit test library -# It is only the generic framework and does _not_ include any of the specific stub/hook functions -# It is built as static library so it may be linked with either a "real" implementation or a stub -# library (see next targets) or some combination of those as the test cases dictate. -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/ut_assert/src UT_ASSERT_FILES) -add_library(ut_assert STATIC EXCLUDE_FROM_ALL ${UT_ASSERT_FILES}) - -# in order to run the unit test, we need a BSP. -# The "ut_bsp" library is a simple startup BSP that can be used for unit testing -# This removes the need to use the "real" CFE PSP and also provides the necessary -# UT output functions that UT assert may rely upon to report test messages -if (NOT DEFINED UT_OSAL_BSPTYPE) - if (DEFINED OSAL_SYSTEM_BSPTYPE) - set(UT_OSAL_BSPTYPE ${OSAL_SYSTEM_BSPTYPE}) - elseif(DEFINED CFE_SYSTEM_PSPNAME) - # assume an OSAL bsp with the same name exists - set(UT_OSAL_BSPTYPE ${CFE_SYSTEM_PSPNAME}) - endif (DEFINED OSAL_SYSTEM_BSPTYPE) -endif (NOT DEFINED UT_OSAL_BSPTYPE) - -# Recompute the compiler flags for UT builds, as this may be using a different BSP -osal_assemble_compiler_flags(${OSAL_SELECTED_OSTYPE} ${UT_OSAL_BSPTYPE}) - -if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/bsp/${UT_OSAL_BSPTYPE}/ut-src) - aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/bsp/${UT_OSAL_BSPTYPE}/ut-src UT_BSPFILES) - add_library(ut_bsp STATIC EXCLUDE_FROM_ALL ${UT_BSPFILES}) - set_target_properties(ut_bsp PROPERTIES COMPILE_DEFINITIONS "_UNIT_TEST_") - target_link_libraries(ut_assert ut_bsp) -endif() +# +# Step 2: +# Build the OSAL layer +# +# The implementation-specific OSAL subdirectory should define +# an OBJECT target named "osal_${OSAL_SYSTEM_OSTYPE}_impl" +add_subdirectory(src/os/${OSAL_SYSTEM_OSTYPE} ${OSAL_SYSTEM_OSTYPE}_impl) + +# The "shared" directory contains internal components which +# are referenced in implementation OSAL modules, but should _NOT_ +# be referenced outside the OSAL code +target_include_directories(osal_${OSAL_SYSTEM_OSTYPE}_impl PRIVATE + ${OSAL_SOURCE_DIR}/src/os/shared + ${OSAL_SOURCE_DIR}/src/bsp/shared +) + +# Define the external "osal" static library target +# This is a combination of the generic parts with the low level +# system-specific parts +add_library(osal STATIC + src/os/shared/osapi-binsem.c + src/os/shared/osapi-clock.c + src/os/shared/osapi-common.c + src/os/shared/osapi-countsem.c + src/os/shared/osapi-dir.c + src/os/shared/osapi-errors.c + src/os/shared/osapi-file.c + src/os/shared/osapi-filesys.c + src/os/shared/osapi-fpu.c + src/os/shared/osapi-heap.c + src/os/shared/osapi-idmap.c + src/os/shared/osapi-interrupts.c + src/os/shared/osapi-module.c + src/os/shared/osapi-mutex.c + src/os/shared/osapi-network.c + src/os/shared/osapi-printf.c + src/os/shared/osapi-queue.c + src/os/shared/osapi-select.c + src/os/shared/osapi-sockets.c + src/os/shared/osapi-task.c + src/os/shared/osapi-timebase.c + src/os/shared/osapi-time.c + $ +) + +target_include_directories(osal INTERFACE + ${OSAL_API_INCLUDE_DIRECTORIES} +) + +# Link the OSAL with the BSP +target_link_libraries(osal osal_bsp) + +# propagate the BSP-specific compile flags to OSAL external library target, if defined +if (OSAL_BSP_COMPILE_DEFINITIONS) + target_compile_definitions(osal INTERFACE + ${OSAL_BSP_COMPILE_DEFINITIONS} + ) +endif(OSAL_BSP_COMPILE_DEFINITIONS) + +# propagate the BSP-specific include directories OSAL all external library target, if defined +if (OSAL_BSP_INCLUDE_DIRECTORIES) + target_include_directories(osal INTERFACE + ${OSAL_BSP_INCLUDE_DIRECTORIES} + ) +endif(OSAL_BSP_INCLUDE_DIRECTORIES) + + + +# The "build_options.cmake" file within each component may +# fine-tune the library for this particular build. This is included +# AFTER The basic targets are defined, so it may set properties +# on the defined targets and/or use target-specific commands. +include("${OSAL_SOURCE_DIR}/src/bsp/${OSAL_SYSTEM_BSPTYPE}/build_options.cmake" OPTIONAL) +include("${OSAL_SOURCE_DIR}/src/os/${OSAL_SYSTEM_OSTYPE}/build_options.cmake" OPTIONAL) +# +# UNIT TEST SUPPORT +# if (ENABLE_UNIT_TESTS) - if (NOT TARGET ut_bsp) - # This was originally a warning, but it produces some really weird behavior of - # subsequent builds if "ENABLE_UNIT_TESTS" is true but the associated OSAL libraries - # and targets are not available. More prudent to make this a fatal error, and the - # user can re-run with "ENABLE_UNIT_TESTS" set false if that is what they want. - message(FATAL_ERROR "No BSP available for unit tests. Tests cannot be built.") - endif() - - # The "ut_osapi_stubs" library contains "stub" functions of the OSAL API calls, used for - # testing application code built on top of OSAL. - set(UT_OSAPI_STUB_SRCFILES - src/ut-stubs/utstub-helpers.c - src/ut-stubs/osapi-utstub-binsem.c - src/ut-stubs/osapi-utstub-clock.c - src/ut-stubs/osapi-utstub-common.c - src/ut-stubs/osapi-utstub-countsem.c - src/ut-stubs/osapi-utstub-dir.c - src/ut-stubs/osapi-utstub-errors.c - src/ut-stubs/osapi-utstub-file.c - src/ut-stubs/osapi-utstub-filesys.c - src/ut-stubs/osapi-utstub-fpu.c - src/ut-stubs/osapi-utstub-heap.c - src/ut-stubs/osapi-utstub-idmap.c - src/ut-stubs/osapi-utstub-interrupts.c - src/ut-stubs/osapi-utstub-module.c - src/ut-stubs/osapi-utstub-mutex.c - src/ut-stubs/osapi-utstub-network.c - src/ut-stubs/osapi-utstub-printf.c - src/ut-stubs/osapi-utstub-queue.c - src/ut-stubs/osapi-utstub-select.c - src/ut-stubs/osapi-utstub-sockets.c - src/ut-stubs/osapi-utstub-task.c - src/ut-stubs/osapi-utstub-time.c - src/ut-stubs/osapi-utstub-timebase.c) - - add_library(ut_osapi_stubs STATIC ${UT_OSAPI_STUB_SRCFILES}) - - add_subdirectory(src/tests tests) - add_subdirectory(src/unit-tests unit-tests) - - if (BUILD_PARENT) - # Append _UNIT_TEST_ definition to the project-wide unit test CFLAGS - # This allows the UT implementations to add extra UT hooks/debug where needed - # For compatibility this also needs to expand the include path to include UT assert headers - # (this assumes a gcc style compiler) - set(UT_C_FLAGS "-D_UNIT_TEST_ -I${CMAKE_CURRENT_SOURCE_DIR}/ut_assert/inc ${BSP_UT_C_FLAGS}" PARENT_SCOPE) - endif (BUILD_PARENT) + enable_testing() + + # Generic function for consistent definition of a unit testing target + # This is defined here in the top-level OSAL CMakeLists so it can be used + # in both the "tests" and "unit-tests" subdirectories. + function(add_osal_ut_exe TGTNAME) + + add_executable(${TGTNAME} ${ARGN}) + target_link_libraries(${TGTNAME} ut_assert osal) + add_test(${TGTNAME} ${TGTNAME}) + foreach(TGT ${INSTALL_TARGET_LIST}) + install(TARGETS ${TGTNAME} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR}) + endforeach() + + endfunction(add_osal_ut_exe) + + # The "ut_osapi_stubs" library contains "stub" functions of the OSAL API calls, used for + # testing other application code built on top of OSAL. + add_subdirectory(src/ut-stubs ut-stubs) + + # The "unit-test-coverage" is a white-box line coverage test. + # It re-compiles each source unit for coverage analysis and links + # with stub dependencies and a test sequence designed to execute + # every line of source code within OSAL. + add_subdirectory(src/unit-test-coverage unit-test-coverage) + + # The "tests" and "unit-tests" subdirectories implement examples and verification tests + # of the OSAL library. Note that these are both black box tests that link with the full + # OSAL (not a stub/coverage test). + add_subdirectory(src/tests tests) + add_subdirectory(src/unit-tests unit-tests) endif (ENABLE_UNIT_TESTS) +# If this build is being performed as a subdirectory within a larger project, +# then export the important data regarding compile flags/dirs to that parent +# This is conditional to avoid warnings in a standalone build. +get_directory_property(HAS_PARENT PARENT_DIRECTORY) +if (HAS_PARENT) + # export the "OSAL_BSP_STAGING_INSTALL_DIR" to the parent build, so this can be + # used in "install" commands as necessary for the files needed at runtime + set(OSAL_BSP_STAGING_INSTALL_DIR "${OSAL_BSP_STAGING_INSTALL_DIR}" PARENT_SCOPE) + + # Export the UT coverage compiler/linker flags to the parent build. + # These flags are based on the target system type and should be used + # when building code intended for coverage analysis. + set(UT_COVERAGE_COMPILE_FLAGS "${UT_COVERAGE_COMPILE_FLAGS}" PARENT_SCOPE) + set(UT_COVERAGE_LINK_FLAGS "${UT_COVERAGE_LINK_FLAGS}" PARENT_SCOPE) +endif(HAS_PARENT) + + + + diff --git a/src/bsp/mcp750-vxworks/CMakeLists.txt b/src/bsp/mcp750-vxworks/CMakeLists.txt new file mode 100644 index 000000000..954cbefd4 --- /dev/null +++ b/src/bsp/mcp750-vxworks/CMakeLists.txt @@ -0,0 +1,26 @@ +###################################################################### +# +# CMAKE build recipe for MCP750 Board Support Package (BSP) +# +###################################################################### + +add_library(osal_mcp750-vxworks_impl OBJECT + src/bsp_start.c + src/bsp_voltab.c + src/bsp_console.c +) + +target_include_directories(osal_mcp750-vxworks_impl PUBLIC + $ENV{WIND_BASE}/target/h + $ENV{WIND_BASE}/target/h/wrn/coreip + $ENV{WIND_BASE}/target/config/mcp750 +) + +# NOTE: the __PPC__ and MCP750 macros are referenced in some system headers. +# therefore all code compiled for this platform should always define these symbols. +target_compile_definitions(osal_mcp750-vxworks_impl PUBLIC + "__PPC__" + "MCP750" +) + + diff --git a/src/bsp/mcp750-vxworks/build_options.cmake b/src/bsp/mcp750-vxworks/build_options.cmake new file mode 100644 index 000000000..73cc0d050 --- /dev/null +++ b/src/bsp/mcp750-vxworks/build_options.cmake @@ -0,0 +1,8 @@ +########################################################################## +# +# Build options for "mcp750-vxworks" BSP +# +########################################################################## + +# This indicates where to stage target binaries created during the build +set(OSAL_BSP_STAGING_INSTALL_DIR "CF:0") diff --git a/src/bsp/mcp750-vxworks/make/compiler-opts.mak b/src/bsp/mcp750-vxworks/make/compiler-opts.mak deleted file mode 100644 index 643e6852a..000000000 --- a/src/bsp/mcp750-vxworks/make/compiler-opts.mak +++ /dev/null @@ -1,97 +0,0 @@ -############################################################################### -## compiler-opts.mak - compiler definitions and options for building the OSAL and apps -## -## Target: PPC COTS boards with vxWorks 6.x -## -## Modifications: -## -############################################################################### -## -## Warning Level Configuration -## -## WARNINGS=-Wall -ansi -pedantic -Wstrict-prototypes -WARNINGS = -Wall -std=c99 - -## -## A fix for Windows systems on vxWorks 6.4 -## When generating dependancies, the Windows GCC cannot seem to deal -## with the Windows style path separators in the WIND_BASE macro. -## -FIXED_WIND_BASE = $(subst \,/,$(WIND_BASE)) - -## -## vxWorks system includes -## -VXINCDIR = $(FIXED_WIND_BASE)/target/h \ -$(FIXED_WIND_BASE)/target/h/wrn/coreip \ -$(FIXED_WIND_BASE)/target/h/drv \ -$(FIXED_WIND_BASE)/target/src/config \ -$(FIXED_WIND_BASE)/target/src/drv \ -$(FIXED_WIND_BASE)/target/config/comps/src \ -$(FIXED_WIND_BASE)/target/config/comps/src/dosfs2 \ - -SYSINCS = $(VXINCDIR:%=-I%) - -## -## Target Defines for the OS, Hardware Arch, etc.. -## -TARGET_DEFS = -D_VXWORKS_OS_ -D_PPC_ -D__PPC__ $(CFE_SB_NET) -D$(OS) -DGENPPC -D_EMBED_ \ - -DTOOL_FAMILY=gnu -DTOOL=gnu -D_WRS_KERNEL -DCPU=PPC604 - -## -## Endian Defines -## -ENDIAN_DEFS=-D_EB -DENDIAN=_EB -DSOFTWARE_BIG_BIT_ORDER - -## -## Compiler Architecture Switches -## removed -fvolatile - not needed for vxworks 6.x -## -ARCH_OPTS = -mcpu=750 -mstrict-align -fno-builtin -mlongcall - - -## -## Extra Cflags for Assembly listings, etc. -## -LIST_OPTS = -Wa,-a=$*.lis - -## -## gcc options for dependancy generation -## -COPTS_D = $(ENDIAN_DEFS) $(TARGET_DEFS) $(ARCH_OPTS) $(SYSINCS) $(WARNINGS) - -## -## General gcc options that apply to compiling and dependency generation. -## -COPTS=$(LIST_OPTS) $(COPTS_D) - -## -## Extra defines and switches for assembly code -## -ASOPTS = $(APP_ASOPTS) -P -xassembler-with-cpp - -##--------------------------------------------------------- -## Application file extention type -## This is the defined application extention. -## Known extentions: Mac OS X: .bundle, Linux: .so, RTEMS: -## .s3r, vxWorks: .o etc.. -##--------------------------------------------------------- -APP_EXT = elf - -#################################################### -## Host Development System and Toolchain defintions -## -## Host OS utils -## -RM=rm -f -CP=cp - -## -## Compiler tools -## -COMPILER = ccppc -ASSEMBLER = ccppc -LINKER = ldppc -AR = arppc -NM = nmppc -OBJCPY = objcopyppc diff --git a/src/bsp/mcp750-vxworks/make/link-rules.mak b/src/bsp/mcp750-vxworks/make/link-rules.mak deleted file mode 100644 index 08b45aa88..000000000 --- a/src/bsp/mcp750-vxworks/make/link-rules.mak +++ /dev/null @@ -1,35 +0,0 @@ -############################################################################### -# File: link-rules.mak -# -# Purpose: -# Makefile for linking code and producing the OSAL Core executable image. -# -# History: -# -############################################################################### -## -## Executable target. This is target specific -## - -## -## Linker flags that are needed -## -LDFLAGS = - -## -## Libraries to link in -## -LIBS = - -## -## OSAL Core Link Rule -## -$(EXE_TARGET): $(CORE_OBJS) - $(COMPILER) $(DEBUG_FLAGS) -r -nostdlib -o $(EXE_TARGET) $(CORE_OBJS) - -## -## Application Link Rule -## -$(APPTARGET).$(APP_EXT): $(OBJS) - $(LINKER) -r $(OBJS) $(CORE_OBJS) -o $@ - diff --git a/src/bsp/mcp750-vxworks/src/bsp_console.c b/src/bsp/mcp750-vxworks/src/bsp_console.c new file mode 100644 index 000000000..710b1a007 --- /dev/null +++ b/src/bsp/mcp750-vxworks/src/bsp_console.c @@ -0,0 +1,52 @@ +/****************************************************************************** +** File: bsp_console.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** OSAL BSP debug console abstraction +** +******************************************************************************/ + +#include +#include +#include + +#include "mcp750_bsp_internal.h" +#include "bsp-impl.h" + +/**************************************************************************************** + BSP CONSOLE IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*---------------------------------------------------------------- + OS_BSP_ConsoleOutput_Impl + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen) +{ + while (DataLen > 0) + { + putchar(*Str); + ++Str; + --DataLen; + } +} + +/*---------------------------------------------------------------- + OS_BSP_ConsoleSetMode_Impl() definition + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits) +{ + /* ignored; not implemented */ +} + + diff --git a/src/bsp/mcp750-vxworks/src/bsp_start.c b/src/bsp/mcp750-vxworks/src/bsp_start.c index 177825684..6c47c4eaf 100644 --- a/src/bsp/mcp750-vxworks/src/bsp_start.c +++ b/src/bsp/mcp750-vxworks/src/bsp_start.c @@ -1,15 +1,15 @@ /****************************************************************************** ** File: bsp_start.c ** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. ** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. ** ** Purpose: -** +** ** OSAL main entry point. ** ** History: @@ -19,23 +19,10 @@ /* ** Include Files */ -#include #include -#include -#include "vxWorks.h" -#include "sysLib.h" -#include "taskLib.h" - -/* -** OSAL includes -*/ -#include "common_types.h" -#include "osapi.h" +#include -/* -** External Declarations -*/ -void OS_Application_Startup(void); +#include "mcp750_bsp_internal.h" /****************************************************************************** ** Function: OS_BSPMain() @@ -47,30 +34,32 @@ void OS_Application_Startup(void); ** (none) ** ** Return: -** (none) +** integer return code, with zero indicating normal exit, nonzero +** indicating an off-nominal condition */ -void OS_BSPMain( void ) +int OS_BSPMain(void) { - int TicksPerSecond; - - /* - ** Delay for one second. - */ - TicksPerSecond = sysClkRateGet(); - (void) taskDelay( TicksPerSecond ); + /* + * Initially clear the global object (this contains return code) + */ + memset(&OS_BSP_Global, 0, sizeof(OS_BSP_Global)); - OS_printf("Starting Up OSAPI App.\n"); - - /* - ** Call OSAL entry point. - */ - OS_Application_Startup(); + /* + * Call application specific entry point. + * This should set up all user tasks and resources, then return + */ + OS_Application_Startup(); - /* - ** Exit the main thread. - ** in VxWorks we can delete all of the OS tasks if we want. - */ + /* + * OS_Application_Run() implements the background task. + * The user application may provide this, or a default implementation + * is used which just calls OS_IdleLoop(). + */ + OS_Application_Run(); + /* + * Return to shell with the current status code + */ + return OS_BSP_Global.AppStatus; } - diff --git a/src/bsp/mcp750-vxworks/src/mcp750_bsp_internal.h b/src/bsp/mcp750-vxworks/src/mcp750_bsp_internal.h new file mode 100644 index 000000000..7b6d84363 --- /dev/null +++ b/src/bsp/mcp750-vxworks/src/mcp750_bsp_internal.h @@ -0,0 +1,27 @@ +/****************************************************************************** +** File: mcp750_bsp_internal.h +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Header file for internal data to the MCP750 BSP +** +******************************************************************************/ + +#ifndef _MCP750_BSP_INTERNAL_H_ +#define _MCP750_BSP_INTERNAL_H_ + +/* +** OSAL includes +*/ +#include "osapi.h" +#include "bsp-impl.h" + +#endif /* _MCP750_BSP_INTERNAL_H_ */ diff --git a/src/bsp/mcp750-vxworks/ut-src/bsp_ut.c b/src/bsp/mcp750-vxworks/ut-src/bsp_ut.c deleted file mode 100644 index 1b1890418..000000000 --- a/src/bsp/mcp750-vxworks/ut-src/bsp_ut.c +++ /dev/null @@ -1,222 +0,0 @@ -/****************************************************************************** -** File: bsp_ut.c -** -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** Purpose: -** BSP unit test implementation functions. -** -** History: -** Created on: Feb 10, 2015 -** -******************************************************************************/ - -/* - * NOTE - This entire source file is only relevant for unit testing. - * It should not be included in a "normal" BSP build. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "osapi.h" -#include "utbsp.h" -#include "uttest.h" - -/* -** Local Variables -*/ -uint32 TestVerbosity = (2 << UTASSERT_CASETYPE_PASS) - 1; - -/* - * Long jump buffer to implement ABORT - * - * (a fatal testing error that should - * stop execution and return to console) - */ -static jmp_buf AbortBuf; - -void UT_BSP_StartTestSegment(uint32 SegmentNumber, const char *SegmentName) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u %s", (unsigned int)SegmentNumber, SegmentName); - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, ReportBuffer); -} - -void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) -{ - const char *Prefix; - - if ((TestVerbosity >> MessageType) & 1) - { - switch(MessageType) - { - case UTASSERT_CASETYPE_ABORT: - Prefix = "ABORT"; - break; - case UTASSERT_CASETYPE_FAILURE: - Prefix = "FAIL"; - break; - case UTASSERT_CASETYPE_MIR: - Prefix = "MIR"; - break; - case UTASSERT_CASETYPE_TSF: - Prefix = "TSF"; - break; - case UTASSERT_CASETYPE_TTF: - Prefix = "TTF"; - break; - case UTASSERT_CASETYPE_NA: - Prefix = "N/A"; - break; - case UTASSERT_CASETYPE_BEGIN: - printf("\n"); /* add a bit of extra whitespace between tests */ - Prefix = "BEGIN"; - break; - case UTASSERT_CASETYPE_END: - Prefix = "END"; - break; - case UTASSERT_CASETYPE_PASS: - Prefix = "PASS"; - break; - case UTASSERT_CASETYPE_INFO: - Prefix = "INFO"; - break; - case UTASSERT_CASETYPE_DEBUG: - Prefix = "DEBUG"; - break; - default: - Prefix = "OTHER"; - break; - } - - printf("[%5s] %s\n",Prefix,OutputMessage); - } - - /* - * If any ABORT (major failure) message is thrown, - * then use longjmp() to go back to the main routine and exit. - */ - if (MessageType == UTASSERT_CASETYPE_ABORT) - { - longjmp(AbortBuf, -1); - } -} - -void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 TestSeq, uint8 MessageType, const char *SubsysName, const char *ShortDesc) -{ - uint32 FileLen; - const char *BasePtr; - char ReportBuffer[128]; - - FileLen = strlen(File); - BasePtr = File + FileLen; - while (FileLen > 0) - { - --BasePtr; - --FileLen; - if (*BasePtr == '/' || *BasePtr == '\\') - { - ++BasePtr; - break; - } - } - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u.%03u %s:%u - %s", - (unsigned int)SegmentNum, (unsigned int)TestSeq, - BasePtr, (unsigned int)LineNum, ShortDesc); - - UT_BSP_DoText(MessageType, ReportBuffer); -} - -void UT_BSP_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCounter_t *TestCounters) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), - "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-4u N/A::%-4u\n", - (unsigned int)TestCounters->TestSegmentCount, - SegmentName, - (unsigned int)TestCounters->TotalTestCases, - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_PASS], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_MIR], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_TSF], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_NA]); - - - UT_BSP_DoText(UTASSERT_CASETYPE_END, ReportBuffer); -} - -void UT_BSP_Setup(void) -{ - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "VxWorks UNIT TEST"); -} - - -void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters) -{ - /* - * Only output a "summary" if there is more than one test Segment. - * Otherwise it is a duplicate of the report already given. - */ - if (TestCounters->TestSegmentCount > 1) - { - UT_BSP_DoTestSegmentReport("SUMMARY", TestCounters); - } - - printf("COMPLETE: %u tests Segment(s) executed\n\n", (unsigned int)TestCounters->TestSegmentCount); -} - -/****************************************************************************** -** Function: RunTest() -** -** Purpose: -** BSP Unit Test Application entry point. -** -** Arguments: -** (none) -** -** Return: -** 0 on successful test, or nonzero if any errors occurred. -*/ - -int RunTest(void) -{ - int RetVal; - - RetVal = setjmp(AbortBuf); - - if (RetVal == 0) - { - /* - ** Call application specific entry point. - */ - OS_Application_Startup(); - - /* - ** The OS_Application_Run function is part of UT Assert library - */ - OS_Application_Run(); - - RetVal = (UtAssert_GetCounters()->CaseCount[UTASSERT_CASETYPE_FAILURE] + - UtAssert_GetCounters()->CaseCount[UTASSERT_CASETYPE_TSF]); - } - - return RetVal; -} - diff --git a/src/bsp/mcp750-vxworks/ut-src/bsp_ut_voltab.c b/src/bsp/mcp750-vxworks/ut-src/bsp_ut_voltab.c deleted file mode 100644 index 0cc20947c..000000000 --- a/src/bsp/mcp750-vxworks/ut-src/bsp_ut_voltab.c +++ /dev/null @@ -1,67 +0,0 @@ -/* -** File : bsp_voltab.c -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** Author : Nicholas Yanchik / GSFC Code 582 -** -** BSP Volume table for file systems -*/ - -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ -#include "common_types.h" -#include "osapi.h" - - -/* -** volume table. -*/ -OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES] = -{ - -/* Dev Name Phys Dev Vol Type Volatile? Free? IsMounted? Volname MountPt BlockSz */ - -/* RAM Disk */ -{"/ramdev0", " ", RAM_DISK, true, true, false, " ", " ", 0 }, - -/* non-volatile Disk -- Auto-Mapped to an existing CF disk */ -{"/eedev0", "CF:0", FS_BASED, false, false, true, "CF", "/cf", 512 }, - -/* -** Spare RAM disks to be used for SSR and other RAM disks -*/ -{"/ramdev1", " ", RAM_DISK, true, true, false, " ", " ", 0 }, -{"/ramdev2", " ", RAM_DISK, true, true, false, " ", " ", 0 }, -{"/ramdev3", " ", RAM_DISK, true, true, false, " ", " ", 0 }, -{"/ramdev4", " ", RAM_DISK, true, true, false, " ", " ", 0 }, -{"/ramdev5", " ", RAM_DISK, true, true, false, " ", " ", 0 }, - - -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 } -}; - -/* - * An example of a static symbol loader table - * Only used if OS_STATIC_LOADER is enabled in osconfig.h - */ -OS_static_symbol_record_t OS_STATIC_SYMBOL_TABLE[] = -{ - { "OS_Application_Startup", OS_Application_Startup }, - { NULL, NULL } -}; - - diff --git a/src/bsp/pc-linux/CMakeLists.txt b/src/bsp/pc-linux/CMakeLists.txt new file mode 100644 index 000000000..783c96800 --- /dev/null +++ b/src/bsp/pc-linux/CMakeLists.txt @@ -0,0 +1,29 @@ +###################################################################### +# +# CMAKE build recipe for PC-LINUX Board Support Package (BSP) +# +###################################################################### + +# NOTE: Although this is traditionally called "pc-linux", it is generic +# enough to be applied to non-PC systems running embedded Linux, such +# as Raspberry Pi, BeagleBoard, Zync, or custom hardware. + +add_library(osal_pc-linux_impl OBJECT + src/bsp_start.c + src/bsp_voltab.c + src/bsp_console.c +) + +# OSAL needs conformance to at least POSIX.1c (aka POSIX 1995) - this includes all the +# real-time support and threading extensions. +# +# When compiling against glibc, using "_XOPEN_SOURCE=600" enables the X/Open 6 standard. +# XPG6 includes all necessary XPG5, POSIX.1c features as well as SUSv2/UNIX98 extensions. +# This OSAL implementation uses clock_nanosleep(), mq_timedreceive(), and +# mq_timedsend() which are enhancements added in the XPG6 standard. +# +# See http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html +# for a more detailed description of the feature test macros and available values +target_compile_definitions(osal_pc-linux_impl PUBLIC + _XOPEN_SOURCE=600 +) diff --git a/src/bsp/pc-linux/build_options.cmake b/src/bsp/pc-linux/build_options.cmake new file mode 100644 index 000000000..c0a7a5c07 --- /dev/null +++ b/src/bsp/pc-linux/build_options.cmake @@ -0,0 +1,28 @@ +########################################################################## +# +# Build options for "pc-linux" BSP +# +########################################################################## + + + +# Linux system libraries required for the final link of applications using OSAL +target_link_libraries(osal_bsp + pthread dl rt +) + +# C flags that should be used when (re-) compiling code for unit testing. +# Note: --coverage is just a shortcut for "-ftest-coverage" and "-fprofile-arcs" +# This also does not work well when cross compiling since paths to the _compile_ dir +# are baked into the executables, so they will not be there when copied to the target +# Note - although GCC understands the same flags for compile and link here, this may +# not be true on all platforms so the compile and link flags are specified separately. +if (NOT CMAKE_CROSSCOMPILING) + set(UT_COVERAGE_COMPILE_FLAGS -pg --coverage) + set(UT_COVERAGE_LINK_FLAGS -pg --coverage) +endif() + +# This indicates where to stage target binaries created during the build +# It should reflect the _real_ location of the persistent storage path used by +# the BSP which is intended to be used for runtime modules or files. +set(OSAL_BSP_STAGING_INSTALL_DIR "eeprom1") diff --git a/src/bsp/pc-linux/make/build_options.cmake b/src/bsp/pc-linux/make/build_options.cmake deleted file mode 100644 index 59eb9f72d..000000000 --- a/src/bsp/pc-linux/make/build_options.cmake +++ /dev/null @@ -1,14 +0,0 @@ -# This indicates where to install target binaries created during the build -set(INSTALL_SUBDIR "eeprom1") - -# Some upper-level code may be gated on _LINUX_OS_ being defined -set(OSAL_C_FLAGS "${OSAL_C_FLAGS} -D_LINUX_OS_") - -# C flags that should be used when (re-) compiling code for unit testing. -# Note: --coverage is just a shortcut for "-ftest-coverage" and "-fprofile-arcs" -# This also does not work well when cross compiling since paths to the _compile_ dir -# are baked into the executables, so they will not be there when copied to the target -if (NOT CMAKE_CROSSCOMPILING) - set(UT_C_FLAGS "-pg --coverage") -endif() - diff --git a/src/bsp/pc-linux/src/bsp_console.c b/src/bsp/pc-linux/src/bsp_console.c new file mode 100644 index 000000000..61c1d620d --- /dev/null +++ b/src/bsp/pc-linux/src/bsp_console.c @@ -0,0 +1,114 @@ +/****************************************************************************** +** File: bsp_console.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** OSAL BSP debug console abstraction +** +******************************************************************************/ + +#include +#include +#include +#include + +#include "pclinux_bsp_internal.h" +#include "bsp-impl.h" + +/*---------------------------------------------------------------- + OS_BSP_ExecTput() + + Helper function: Use the system "tput" utility to set the given + console capability. + + This uses a fork/exec to invoke the external command which outputs + the control sequence directly to the controlling terminal. + + It is assumed that this will only be used during debug/testing. + Otherwise it would be preferable to cache the control strings to + avoid repetitive fork/exec operations. + ------------------------------------------------------------------*/ +static void OS_BSP_ExecTput(const char *cap, const char *param) +{ + pid_t cpid; + int status; + + cpid = fork(); + if (cpid < 0) + { + return; + } + if (cpid == 0) + { + execlp("tput", "tput", cap, param, NULL); + exit(EXIT_FAILURE); + } + waitpid(cpid, &status, 0); +} + +/**************************************************************************************** + BSP CONSOLE IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*---------------------------------------------------------------- + OS_BSP_ConsoleOutput_Impl + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen) +{ + ssize_t WriteLen; + + while(DataLen > 0) + { + /* writes the raw data directly to STDOUT_FILENO (unbuffered) */ + WriteLen = write(STDOUT_FILENO, Str, DataLen); + if (WriteLen <= 0) + { + /* no recourse if this fails, just stop. */ + break; + } + Str += WriteLen; + DataLen -= WriteLen; + } +} + +/*---------------------------------------------------------------- + OS_BSP_ConsoleSetMode_Impl() definition + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits) +{ + char param[32]; + + if (OS_BSP_PcLinuxGlobal.EnableTermControl) + { + if (ModeBits == OS_BSP_CONSOLEMODE_NORMAL) + { + OS_BSP_ExecTput("sgr0", NULL); + } + else + { + if ((ModeBits & OS_BSP_CONSOLEMODE_HIGHLIGHT) == 0) + { + /* no highlight (standout) text */ + OS_BSP_ExecTput("rmso", NULL); + } + else + { + /* set highlight (standout) text */ + OS_BSP_ExecTput("smso", NULL); + } + + snprintf(param, sizeof(param), "%d", OS_BSP_CONSOLEMODE_TO_ANSICOLOR(ModeBits)); + OS_BSP_ExecTput("setaf", param); + } + } +} diff --git a/src/bsp/pc-linux/src/bsp_start.c b/src/bsp/pc-linux/src/bsp_start.c index 9836e6e98..50d080fcb 100644 --- a/src/bsp/pc-linux/src/bsp_start.c +++ b/src/bsp/pc-linux/src/bsp_start.c @@ -2,42 +2,136 @@ ** File: bsp_start.c ** ** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. ** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. ** ** ** Purpose: ** OSAL BSP main entry point. ** ** History: -** 2005/07/26 A. Cudmore | Initial version for linux +** 2005/07/26 A. Cudmore | Initial version for linux ** ******************************************************************************/ -/* -** OSAL includes -*/ -#include "osapi.h" +#include +#include +#include +#include +#include +#include -/* -** Types and prototypes for this module -*/ +#include "pclinux_bsp_internal.h" -/* -** External Declarations -*/ -void OS_Application_Startup(void); - -/* -** Global variables -*/ +OS_BSP_PcLinuxGlobalData_t OS_BSP_PcLinuxGlobal; + +/* --------------------------------------------------------- + OS_BSP_Initialize() + + Helper function to auto-create any missing FS_BASED mount + points listed in OS_VolumeTable. If these do not actually + exist then app code may fail. + --------------------------------------------------------- */ +void OS_BSP_Initialize(void) +{ + mode_t mode; + uint32 i; + struct stat statbuf; + FILE *fp; + char buffer[32]; + + /* + ** Create local directories for "disk" mount points + ** See bsp_voltab for the values + ** + ** NOTE - the voltab table is poorly designed here; values of "0" are valid + ** and will translate into an entry that is actually used. In particular the + ** "free" flag has to be actually initialized to TRUE to say its NOT valid. + ** So in the case of an entry that has been zeroed out (i.e. bss section) it + ** will be treated as a valid entry. + ** + ** Checking that the DeviceName starts with a leading slash '/' is a workaround + ** for this, and may be the only way to detect an entry that is uninitialized. + */ + mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO; + for (i = 0; i < NUM_TABLE_ENTRIES; ++i) + { + if (OS_VolumeTable[i].VolumeType == FS_BASED && + OS_VolumeTable[i].PhysDevName[0] != 0 && + OS_VolumeTable[i].DeviceName[0] == '/') + + { + if (stat(OS_VolumeTable[i].PhysDevName, &statbuf) < 0) + { + BSP_DEBUG("Creating mount point: %s\n", OS_VolumeTable[i].PhysDevName); + mkdir(OS_VolumeTable[i].PhysDevName, mode); + } + } + } + + /* + * If not running as root, check /proc/sys/fs/mqueue/msg_max + * + * This special file represents the max depth of a POSIX message queue for an unprivileged user. + * + * In order to facilitate running in simulation mode without any need for root access -- + * this will allow the OSAL to successfully create message queues by truncating anything larger than this size. + * + * No need to check _LINUX_OS_ here; if the file fails to open, i.e. if not on Linux and the file does not exist, + * then leave well enough alone and don't do anything. + */ + if (geteuid() != 0) + { + fp = fopen("/proc/sys/fs/mqueue/msg_max","r"); + if (fp) + { + if (fgets(buffer,sizeof(buffer),fp) != NULL) + { + OS_BSP_Global.MaxQueueDepth = strtoul(buffer, NULL, 10); + BSP_DEBUG("Maximum user msg queue depth = %u\n", (unsigned int)OS_BSP_Global.MaxQueueDepth); + } + fclose(fp); + } + } +} + +/* --------------------------------------------------------- + OS_BSP_GetReturnStatus() + + Helper function to convert an OSAL status code into + a code suitable for returning to the OS. + --------------------------------------------------------- */ +int OS_BSP_GetReturnStatus(void) +{ + int retcode; + + switch (OS_BSP_Global.AppStatus) + { + case OS_SUCCESS: + /* translate OS_SUCCESS to the system EXIT_SUCCESS value (usually 0) */ + retcode = EXIT_SUCCESS; + break; + + case OS_ERROR: + /* translate OS_ERROR to the system EXIT_FAILURE value (usually 1) */ + retcode = EXIT_FAILURE; + break; + + default: + /* any other value will be passed through (implementation-defined) */ + /* Range is limited to 0-127, however */ + retcode = OS_BSP_Global.AppStatus & 0x7F; + break; + } + + return retcode; +} - /****************************************************************************** ** Function: main() ** @@ -53,23 +147,56 @@ void OS_Application_Startup(void); int main(int argc, char *argv[]) { - /* - ** OS_API_Init is called by OS_Application_Startup - ** Also note that OS_API_Init now also takes care of signal masking - */ - - /* - ** Call application specific entry point. - */ - OS_Application_Startup(); - - /* - ** OS_IdleLoop() will wait forever and return if - ** someone calls OS_ApplicationShutdown(true) - */ - OS_IdleLoop(); - - /* Should typically never get here */ - return(EXIT_SUCCESS); -} + /* + * Initially clear the global objects + */ + memset(&OS_BSP_Global, 0, sizeof(OS_BSP_Global)); + memset(&OS_BSP_PcLinuxGlobal, 0, sizeof(OS_BSP_PcLinuxGlobal)); + /* + * Save the argc/argv arguments for future use. + * In particular the UT-specific logic uses this + * to control verbosity. + * + * Note that the first argument (0) is the command name. The + * first "real" argument is at position 1. + * + * The first arg is ignored to be more consistent with other platforms + * where this is not passed in. + */ + if (argc > 1) + { + OS_BSP_Global.ArgC = argc - 1; + OS_BSP_Global.ArgV = &argv[1]; + } + + /* + * Only attempt terminal control if the stdout is a TTY + * and the TERM environment variable is set + */ + if (getenv("TERM") != NULL) + { + OS_BSP_PcLinuxGlobal.EnableTermControl = isatty(STDOUT_FILENO); + } + + /* + * Auto-Create any missing FS_BASED mount points specified in OS_VolumeTable + */ + OS_BSP_Initialize(); + + /* + * Call application specific entry point. + * This should set up all user tasks and resources, then return + */ + OS_Application_Startup(); + + /* + * OS_Application_Run() implements the background task. + * The user application may provide this, or a default implementation + * is used which just calls OS_IdleLoop(). + */ + OS_Application_Run(); + + /* Should typically never get here */ + return OS_BSP_GetReturnStatus(); +} diff --git a/src/bsp/pc-linux/src/bsp_voltab.c b/src/bsp/pc-linux/src/bsp_voltab.c index 7f3019dd5..ca881b265 100644 --- a/src/bsp/pc-linux/src/bsp_voltab.c +++ b/src/bsp/pc-linux/src/bsp_voltab.c @@ -17,9 +17,8 @@ /**************************************************************************************** INCLUDE FILES ****************************************************************************************/ -#include "common_types.h" -#include "osapi.h" +#include "pclinux_bsp_internal.h" /* ** volume table. @@ -48,5 +47,3 @@ OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES] = {"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 } }; - - diff --git a/src/bsp/pc-linux/src/pclinux_bsp_internal.h b/src/bsp/pc-linux/src/pclinux_bsp_internal.h new file mode 100644 index 000000000..460df5c98 --- /dev/null +++ b/src/bsp/pc-linux/src/pclinux_bsp_internal.h @@ -0,0 +1,37 @@ +/****************************************************************************** +** File: pclinux_bsp_internal.h +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Header file for internal data to the PC-LINUX BSP +** +******************************************************************************/ + +#ifndef _PCLINUX_BSP_INTERNAL_H_ +#define _PCLINUX_BSP_INTERNAL_H_ + +#include "osapi.h" +#include "bsp-impl.h" + +/* +** BSP types +*/ +typedef struct +{ + bool EnableTermControl; /**< Will be set "true" when invoked from a TTY device, false otherwise */ +} OS_BSP_PcLinuxGlobalData_t; + +/* + * Global Data object + */ +extern OS_BSP_PcLinuxGlobalData_t OS_BSP_PcLinuxGlobal; + +#endif /* _PCLINUX_BSP_INTERNAL_H_ */ diff --git a/src/bsp/pc-linux/ut-src/bsp_ut.c b/src/bsp/pc-linux/ut-src/bsp_ut.c deleted file mode 100644 index a9cb1449f..000000000 --- a/src/bsp/pc-linux/ut-src/bsp_ut.c +++ /dev/null @@ -1,362 +0,0 @@ -/****************************************************************************** -** File: bsp_ut.c -** -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** Purpose: -** BSP unit test implementation functions. -** -** History: -** Created on: Feb 10, 2015 -** -******************************************************************************/ - -/* - * NOTE - This entire source file is only relevant for unit testing. - * It should not be included in a "normal" BSP build. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "osapi.h" -#include "utbsp.h" -#include "uttest.h" - -static const char BSP_TERMCODE_HIGHLIGHT[] = "\x1b[31m"; -static const char BSP_TERMCODE_NORMAL[] = "\x1b[0m"; -static const char BSP_TERMCODE_NONE[] = ""; - -/* -** External Declarations -*/ -extern OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES]; - -/* -** Local Variables -*/ -static int32 NumUserOptions = 0; -static char **FirstUserOption = NULL; -static uint32 CurrVerbosity = (2 << UTASSERT_CASETYPE_PASS) - 1; -static bool EnableTermCodes = false; - -/* - * UT_BSP_GetTotalOptions: See details in prototype - */ -int32 UT_BSP_GetTotalOptions(void) -{ - return NumUserOptions; -} - -/* - * UT_BSP_GetOptionString: See details in prototype - */ -const char * UT_BSP_GetOptionString(int32 OptionNum) -{ - if (OptionNum >= NumUserOptions) - { - return NULL; - } - - return FirstUserOption[OptionNum]; -} - - - -void UT_BSP_ParseCommandLine(int argc, char *argv[]) -{ - uint8 UserShift; - int opt; - - UserShift = UTASSERT_CASETYPE_NONE; - while ((opt = getopt(argc, argv, "v:qd")) != -1) - { - switch (opt) { - case 'd': - UserShift = UTASSERT_CASETYPE_DEBUG; - break; - case 'q': - UserShift = UTASSERT_CASETYPE_FAILURE; - break; - case 'v': - UserShift = atoi(optarg); - break; - default: /* '?' */ - fprintf(stderr, "Usage: %s [-v verbosity] [-d] [-q]\n", - argv[0]); - exit(EXIT_FAILURE); - } - if (UserShift > 0 && UserShift < UTASSERT_CASETYPE_MAX) - { - CurrVerbosity = (2 << UserShift) - 1; - } - } - - if (optind < argc) - { - NumUserOptions = argc - optind; - FirstUserOption = &argv[optind]; - } -} - -void UT_BSP_Setup(void) -{ - int mode; - uint32 i; - struct stat statbuf; - - /* - * Enable terminal codes only if stdout is actually terminal. - * This should prevent log files from having escape codes, for - * when output is redirected to a file. - */ - EnableTermCodes = isatty(STDOUT_FILENO); - - - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "PC-LINUX UNIT TEST"); - - /* - ** Create local directories for "disk" mount points - ** See bsp_voltab for the values - ** - ** NOTE - the voltab table is poorly designed here; values of "0" are valid - ** and will translate into an entry that is actually used. In particular the - ** "free" flag has to be actually initialized to TRUE to say its NOT valid. - ** So in the case of an entry that has been zeroed out (i.e. bss section) it - ** will be treated as a valid entry. - ** - ** Checking that the DeviceName starts with a leading slash '/' is a workaround - ** for this, and may be the only way to detect an entry that is uninitialized. - */ - mode = S_IFDIR |S_IRWXU | S_IRWXG | S_IRWXO; - for (i=0; i < NUM_TABLE_ENTRIES; ++i) - { - if (OS_VolumeTable[i].VolumeType == FS_BASED && - OS_VolumeTable[i].PhysDevName[0] != 0 && - OS_VolumeTable[i].DeviceName[0] == '/') - - { - if (stat(OS_VolumeTable[i].PhysDevName, &statbuf) < 0) - { - printf("Creating mount point directory: %s\n", - OS_VolumeTable[i].PhysDevName); - mkdir(OS_VolumeTable[i].PhysDevName, mode); - } - } - } -} - -void UT_BSP_StartTestSegment(uint32 SegmentNumber, const char *SegmentName) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u %s", (unsigned int)SegmentNumber, SegmentName); - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, ReportBuffer); -} - -void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) -{ - const char *Prefix; - const char *ControlCodeStart = NULL; - const char *ControlCodeEnd = NULL; - - if ((CurrVerbosity >> MessageType) & 1) - { - switch(MessageType) - { - case UTASSERT_CASETYPE_ABORT: - Prefix = "ABORT"; - break; - case UTASSERT_CASETYPE_FAILURE: - ControlCodeStart = BSP_TERMCODE_HIGHLIGHT; - Prefix = "FAIL"; - break; - case UTASSERT_CASETYPE_MIR: - Prefix = "MIR"; - break; - case UTASSERT_CASETYPE_TSF: - Prefix = "TSF"; - break; - case UTASSERT_CASETYPE_TTF: - Prefix = "TTF"; - break; - case UTASSERT_CASETYPE_NA: - Prefix = "N/A"; - break; - case UTASSERT_CASETYPE_BEGIN: - printf("\n"); /* add a bit of extra whitespace between tests */ - Prefix = "BEGIN"; - break; - case UTASSERT_CASETYPE_END: - Prefix = "END"; - break; - case UTASSERT_CASETYPE_PASS: - Prefix = "PASS"; - break; - case UTASSERT_CASETYPE_INFO: - Prefix = "INFO"; - break; - case UTASSERT_CASETYPE_DEBUG: - Prefix = "DEBUG"; - break; - default: - Prefix = "OTHER"; - break; - } - - if (!EnableTermCodes || ControlCodeStart == NULL) - { - ControlCodeStart = BSP_TERMCODE_NONE; - ControlCodeEnd = BSP_TERMCODE_NONE; - } - else if (ControlCodeEnd == NULL) - { - ControlCodeEnd = BSP_TERMCODE_NORMAL; - } - printf("[%s%5s%s] %s\n",ControlCodeStart,Prefix,ControlCodeEnd,OutputMessage); - } - - /* - * If any ABORT (major failure) message is thrown, - * then actually call abort() to stop the test and dump a core - */ - if (MessageType == UTASSERT_CASETYPE_ABORT) - { - abort(); - } -} - -void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 TestSeq, uint8 MessageType, const char *SubsysName, const char *ShortDesc) -{ - uint32 FileLen; - const char *BasePtr; - char ReportBuffer[128]; - - FileLen = strlen(File); - BasePtr = File + FileLen; - while (FileLen > 0) - { - --BasePtr; - --FileLen; - if (*BasePtr == '/' || *BasePtr == '\\') - { - ++BasePtr; - break; - } - } - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u.%03u %s:%u - %s", - (unsigned int)SegmentNum, (unsigned int)TestSeq, - BasePtr, (unsigned int)LineNum, ShortDesc); - - UT_BSP_DoText(MessageType, ReportBuffer); -} - -void UT_BSP_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCounter_t *TestCounters) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), - "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-4u N/A::%-4u\n", - (unsigned int)TestCounters->TestSegmentCount, - SegmentName, - (unsigned int)TestCounters->TotalTestCases, - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_PASS], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_MIR], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_TSF], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_NA]); - - - UT_BSP_DoText(UTASSERT_CASETYPE_END, ReportBuffer); -} - -void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters) -{ - int status = 0; - - /* - * Only output a "summary" if there is more than one test Segment. - * Otherwise it is a duplicate of the report already given. - */ - if (TestCounters->TestSegmentCount > 1) - { - UT_BSP_DoTestSegmentReport("SUMMARY", TestCounters); - } - - printf("COMPLETE: %u tests Segment(s) executed\n\n", (unsigned int)TestCounters->TestSegmentCount); - - /* - * The Linux UT BSP allows at least a 7 bit status code to be returned to the OS (i.e. the exit status - * of the process). This is useful to report pass/fail. Because we have multiple bits, we can make - * descriptive exit status codes to indicate what went wrong. Anything nonzero represents failure. - * - * Consider Failures as well as "TSF" (setup failures) to be grounds for returning nonzero (bad) status. - * Also the lack of ANY test cases should produce a bad status. - * - * "MIR" results should not produce a bad status -- these may have worked fine, we do not know. - * - * Likewise "N/A" tests are simply not applicable, so we just ignore them. - */ - - if (TestCounters->TotalTestCases == 0) - { - status |= 0x01; - } - - if (TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE] > 0) - { - status |= 0x02; - } - - if (TestCounters->CaseCount[UTASSERT_CASETYPE_TSF] > 0) - { - status |= 0x04; - } - - exit(status); -} - -/****************************************************************************** -** Function: main() -** -** Purpose: -** BSP Unit Test Application entry point. -** -** Arguments: -** (none) -** -** Return: -** (none) -*/ - -int main(int argc, char *argv[]) -{ - UT_BSP_ParseCommandLine(argc, argv); - - /* - ** Call application specific entry point. - */ - OS_Application_Startup(); - - /* - ** The OS_Application_Run function is part of UT Assert library - */ - OS_Application_Run(); - - /* Should typically never get here */ - return(EXIT_SUCCESS); -} - diff --git a/src/bsp/pc-linux/ut-src/bsp_ut_voltab.c b/src/bsp/pc-linux/ut-src/bsp_ut_voltab.c deleted file mode 100644 index a1256a461..000000000 --- a/src/bsp/pc-linux/ut-src/bsp_ut_voltab.c +++ /dev/null @@ -1,65 +0,0 @@ -/* -** File : bsp_voltab.c -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** Author : Nicholas Yanchik / GSFC Code 582 -** -** BSP Volume table for file systems -*/ - -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ -#include "common_types.h" -#include "osapi.h" - - -/* -** volume table. -*/ -OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES] = -{ -/* Dev Name Phys Dev Vol Type Volatile? Free? IsMounted? Volname MountPt BlockSz */ -{"/ramdev0", "./ram0", FS_BASED, true, true, false, " ", " ", 0 }, -{"/ramdev1", "./ram1", FS_BASED, true, true, false, " ", " ", 0 }, -{"/ramdev2", "./ram2", FS_BASED, true, true, false, " ", " ", 0 }, -{"/ramdev3", "./ram3", FS_BASED, true, true, false, " ", " ", 0 }, -{"/ramdev4", "./ram4", FS_BASED, true, true, false, " ", " ", 0 }, -{"/ramdev5", "./ram5", FS_BASED, true, true, false, " ", " ", 0 }, - -/* -** The following entry is a "pre-mounted" path to a non-volatile device -*/ -{"/eedev0", "./eeprom1", FS_BASED, false, false, true, "CF", "/cf", 512 }, - -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 } -}; - - -/* - * An example of a static symbol loader table - * Only used if OS_STATIC_LOADER is enabled in osconfig.h - */ -#ifdef OS_STATIC_LOADER -OS_static_symbol_record_t OS_STATIC_SYMBOL_TABLE[] = -{ - { "OS_Application_Startup", OS_Application_Startup }, - { NULL, NULL } -}; -#endif - - - diff --git a/src/bsp/pc-rtems/CMakeLists.txt b/src/bsp/pc-rtems/CMakeLists.txt new file mode 100644 index 000000000..7d003a861 --- /dev/null +++ b/src/bsp/pc-rtems/CMakeLists.txt @@ -0,0 +1,11 @@ +###################################################################### +# +# CMAKE build recipe for PC-RTEMS Board Support Package (BSP) +# +###################################################################### + +add_library(osal_pc-rtems_impl OBJECT + src/bsp_start.c + src/bsp_voltab.c + src/bsp_console.c +) diff --git a/src/bsp/pc-rtems/build_options.cmake b/src/bsp/pc-rtems/build_options.cmake new file mode 100644 index 000000000..1690376ff --- /dev/null +++ b/src/bsp/pc-rtems/build_options.cmake @@ -0,0 +1,15 @@ +########################################################################## +# +# Build options for "pc-rtems" BSP +# +########################################################################## + +# Link the RTEMS BSP with the "rtemscpu" system library +target_link_libraries(osal_bsp + rtemscpu +) + +# This indicates where to stage target binaries created during the build +# It should reflect the _real_ location of the persistent storage path used by +# the BSP which is intended to be used for runtime modules or files. +set(OSAL_BSP_STAGING_INSTALL_DIR "eeprom") diff --git a/src/bsp/pc-rtems/make/build_options.cmake b/src/bsp/pc-rtems/make/build_options.cmake deleted file mode 100644 index 730390f97..000000000 --- a/src/bsp/pc-rtems/make/build_options.cmake +++ /dev/null @@ -1,3 +0,0 @@ -# This indicates where to install target binaries created during the build -set(INSTALL_SUBDIR "cf") - diff --git a/src/bsp/pc-rtems/src/bsp_console.c b/src/bsp/pc-rtems/src/bsp_console.c new file mode 100644 index 000000000..cc90cbba8 --- /dev/null +++ b/src/bsp/pc-rtems/src/bsp_console.c @@ -0,0 +1,49 @@ +/****************************************************************************** +** File: bsp_console.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** OSAL BSP debug console abstraction +** +******************************************************************************/ + +#include +#include +#include +#include + +#include "pcrtems_bsp_internal.h" +#include "bsp-impl.h" + +/**************************************************************************************** + BSP CONSOLE IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*---------------------------------------------------------------- + OS_BSP_ConsoleOutput_Impl + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen) +{ + /* writes the raw data directly to STDOUT_FILENO (unbuffered) */ + write(STDOUT_FILENO, Str, DataLen); +} + +/*---------------------------------------------------------------- + OS_BSP_ConsoleSetMode_Impl() definition + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits) +{ + /* no-op on RTEMS */ +} + + diff --git a/src/bsp/pc-rtems/src/bsp_start.c b/src/bsp/pc-rtems/src/bsp_start.c index 9f143505e..bcce3f6e2 100644 --- a/src/bsp/pc-rtems/src/bsp_start.c +++ b/src/bsp/pc-rtems/src/bsp_start.c @@ -2,12 +2,12 @@ ** File: bsp_start.c ** ** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. ** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. ** ** ** Purpose: @@ -22,42 +22,30 @@ */ #include #include +#include #include +#include +#include #include #include #include #include #include +#include #include #include #include #include #include +#include -/* -** External Declarations -*/ -void OS_Application_Startup(void); - -extern rtems_status_code rtems_ide_part_table_initialize (const char* ); - -/* -** cFE includes -*/ -#include "common_types.h" -#include "osapi.h" - -#ifdef _UNIT_TEST_ -#include "utbsp.h" -#include "uttest.h" -#endif - -#define RTEMS_NUMBER_OF_RAMDISKS 1 - +#include "pcrtems_bsp_internal.h" /* -** Global variables +** External Declarations */ +extern rtems_status_code rtems_ide_part_table_initialize(const char *); +extern int rtems_rtl_shell_command (int argc, char* argv[]); /* * The RAM Disk configuration. @@ -66,7 +54,7 @@ rtems_ramdisk_config rtems_ramdisk_configuration[RTEMS_NUMBER_OF_RAMDISKS]; /* * The number of RAM Disk configurations. -*/ + */ size_t rtems_ramdisk_configuration_size = RTEMS_NUMBER_OF_RAMDISKS; /* @@ -82,126 +70,307 @@ rtems_driver_address_table rtems_ramdisk_io_ops = .control_entry = rtems_blkdev_generic_ioctl }; -rtems_id RtemsTimerId; - /* - * The RTEMS shell needs a function to check the validity of a login username/password - * This is just a stub that always passes. + * Additional shell commands for the RTL functionality */ -bool BSP_Login_Check(const char *user, const char *passphrase) -{ - return true; -} +rtems_shell_cmd_t rtems_shell_RTL_Command = { + .name = "rtl", + .usage = "rtl COMMAND...", + .topic = "misc", + .command = rtems_rtl_shell_command +}; +rtems_shell_cmd_t rtems_shell_dlopen_Command = { + .name = "dlopen", + .usage = "dlopen COMMAND...", + .topic = "misc", + .command = shell_dlopen +}; +rtems_shell_cmd_t rtems_shell_dlsym_Command = { + .name = "dlsym", + .usage = "dlsym COMMAND...", + .topic = "misc", + .command = shell_dlsym +}; /* -** 1 HZ Timer "ISR" +** Global variables */ -int timer_count = 0; +OS_BSP_PcRtemsGlobalData_t OS_BSP_PcRtemsGlobal; -void BSP_Setup(void) +void OS_BSP_Setup(void) { - int status; - -#ifdef _UNIT_TEST_ - UT_BSP_Setup("PC-RTEMS UNIT TEST"); -#endif - - OS_printf( "\n\n*** RTEMS Info ***\n" ); - OS_printf("%s", _Copyright_Notice ); - OS_printf("%s\n\n", _RTEMS_version ); - OS_printf(" Stack size=%d\n", (int)Configuration.stack_space_size ); - OS_printf(" Workspace size=%d\n", (int) Configuration.work_space_size ); - OS_printf("\n"); - OS_printf( "*** End RTEMS info ***\n\n" ); - - /* - ** Create the RTEMS Root file system - */ - status = rtems_create_root_fs(); - if (status != RTEMS_SUCCESSFUL) - { - OS_printf("Creating Root file system failed: %s\n",rtems_status_text(status)); - } - - /* - ** create the directory mountpoints - */ - status = mkdir("/ram", S_IFDIR |S_IRWXU | S_IRWXG | S_IRWXO); /* For ramdisk mountpoint */ - if (status != RTEMS_SUCCESSFUL) - { - OS_printf("mkdir failed: %s\n", strerror (errno)); - } - - status = mkdir("/cf", S_IFDIR |S_IRWXU | S_IRWXG | S_IRWXO); /* For EEPROM mountpoint */ - if (status != RTEMS_SUCCESSFUL) - { - OS_printf("mkdir failed: %s\n", strerror (errno)); - return; - } - - /* - * Register the IDE partition table. + int status; + unsigned int i; + struct stat statbuf; + const char * cfpart; + const char * cmdlinestr; + const char * cmdp; + char * cmdi, *cmdo; + + cmdlinestr = bsp_cmdline(); + + printf("\n\n*** RTEMS Info ***\n"); + printf("%s", _Copyright_Notice); + printf("%s\n\n", _RTEMS_version); + printf(" Stack size=%d\n", (int)Configuration.stack_space_size); + printf(" Workspace size=%d\n", (int)Configuration.work_space_size); + if (cmdlinestr != NULL) + { + printf(" Bootloader Command Line: %s\n", cmdlinestr); + } + + printf("\n"); + printf("*** End RTEMS info ***\n\n"); + + /* + * Parse command line string (passed in from bootloader) + * + * Known arguments are handled here, and unknown args are + * saved for the UT application. + * + * Batch mode is intended for non-interative execution. + * + * It does two things: + * - do not start the shell task + * - when tests are complete, shutdown the executive + * + * The BSP should be configured with these options to + * make this most useful: + * USE_COM1_AS_CONSOLE=1 + * BSP_PRESS_KEY_FOR_RESET=0 + * BSP_RESET_BOARD_AT_EXIT=1 + * + * This way all the test output will be sent to COM1 + * and then immediately resets the CPU when done. + * + * When running under QEMU the "-no-reboot" flag is + * also useful to shutdown QEMU rather than resetting. + */ + if (cmdlinestr != NULL) + { + cmdp = cmdlinestr; + cmdo = NULL; + cmdi = NULL; + + while (1) + { + if (isgraph((int)*cmdp)) + { + if (cmdo == NULL) + { + cmdo = OS_BSP_PcRtemsGlobal.UserArgBuffer; + } + else + { + ++cmdo; + } + if (cmdi == NULL) + { + cmdi = cmdo; + } + *cmdo = *cmdp; + } + else if (cmdi != NULL) + { + ++cmdo; + *cmdo = 0; + if (strcmp(cmdi, "--batch-mode") == 0) + { + OS_BSP_PcRtemsGlobal.BatchMode = true; + } + else if (OS_BSP_Global.ArgC < RTEMS_MAX_USER_OPTIONS) + { + /* save other args for app */ + OS_BSP_Global.ArgV[OS_BSP_Global.ArgC] = cmdi; + ++OS_BSP_Global.ArgC; + } + cmdi = NULL; + } + + if (*cmdp == 0) + { + break; + } + + ++cmdp; + } + } + + /* + ** Create the RTEMS Root file system */ - status = rtems_ide_part_table_initialize ("/dev/hda"); - if (status != RTEMS_SUCCESSFUL) - { - OS_printf ("error: ide partition table not found: %s / %s\n", - rtems_status_text (status),strerror(errno)); - } - - status = mount("/dev/hda1", "/cf", - RTEMS_FILESYSTEM_TYPE_DOSFS, - RTEMS_FILESYSTEM_READ_WRITE, - NULL); - if (status < 0) - { - OS_printf ("mount failed: %s\n", strerror (errno)); - } + status = rtems_create_root_fs(); + if (status != RTEMS_SUCCESSFUL) + { + printf("Creating Root file system failed: %s\n", rtems_status_text(status)); + } + + /* + * Register the IDE partition table. + */ + status = rtems_ide_part_table_initialize("/dev/hda"); + if (status != RTEMS_SUCCESSFUL) + { + /* note this is not necessarily an error, it just means there + * will be no persistent storage in this instance. The IMFS + * is still available. */ + BSP_DEBUG("warning: /dev/hda partition table not found: %s / %s\n", rtems_status_text(status), strerror(errno)); + BSP_DEBUG("Persistent storage will NOT be mounted\n"); + cfpart = NULL; + } + else + { + cfpart = "/dev/hda1"; + } + + /* + ** Create local directories for "disk" mount points + ** See bsp_voltab for the values + ** + ** NOTE - the voltab table is poorly designed here; values of "0" are valid + ** and will translate into an entry that is actually used. In particular the + ** "free" flag has to be actually initialized to TRUE to say its NOT valid. + ** So in the case of an entry that has been zeroed out (i.e. bss section) it + ** will be treated as a valid entry. + ** + ** Checking that the DeviceName starts with a leading slash '/' is a workaround + ** for this, and may be the only way to detect an entry that is uninitialized. + */ + for (i = 0; i < NUM_TABLE_ENTRIES; ++i) + { + if (OS_VolumeTable[i].VolumeType == FS_BASED && OS_VolumeTable[i].PhysDevName[0] != 0 && + OS_VolumeTable[i].DeviceName[0] == '/') + + { + if (stat(OS_VolumeTable[i].PhysDevName, &statbuf) < 0) + { + status = mkdir(OS_VolumeTable[i].PhysDevName, + S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO); /* For ramdisk mountpoint */ + if (status < 0) + { + printf("mkdir failed: %s\n", strerror(errno)); + } + } + if (cfpart != NULL && strcmp(OS_VolumeTable[i].MountPoint, "/cf") == 0) + { + status = mount(cfpart, OS_VolumeTable[i].PhysDevName, RTEMS_FILESYSTEM_TYPE_DOSFS, + RTEMS_FILESYSTEM_READ_WRITE, NULL); + if (status < 0) + { + printf("mount failed: %s\n", strerror(errno)); + } + } + } + } + + /* + * Start the shell now, before any application starts. + * This way, if there is an issue with the application startup, + * the shell can still be used to debug the system. + * + * The shell is _NOT_ started if the "--batch-mode" switch is + * given (this means to run completely autonomous) + */ + if (!OS_BSP_PcRtemsGlobal.BatchMode) + { + status = rtems_shell_init("SHLL", RTEMS_MINIMUM_STACK_SIZE * 4, RTEMS_SHELL_PRIORITY, "/dev/console", false, + false, NULL); + if (status < 0) + { + printf("shell init failed: %d / %s\n", status, strerror(errno)); + } + + /* give a small delay to let the shell start, + avoids having the login prompt show up mid-test, + and gives a little time for pending output to actually + be sent to the console in case of a slow port */ + rtems_task_wake_after(50); + } + + printf("\n\n"); +} + +/* --------------------------------------------------------- + OS_BSP_GetReturnStatus() + Helper function to convert an OSAL status code into + a code suitable for returning to the OS. + --------------------------------------------------------- */ +rtems_status_code OS_BSP_GetReturnStatus(void) +{ + rtems_status_code retcode; + const char * StatusStr; + + switch (OS_BSP_Global.AppStatus) + { + case OS_SUCCESS: + /* translate OS_SUCCESS to the system RTEMS_SUCCESSFUL value */ + StatusStr = "SUCCESS"; + retcode = RTEMS_SUCCESSFUL; + break; + + default: + /* translate anything else to a generic non-success code, + * this basically just means the main task exited */ + StatusStr = "ERROR"; + retcode = RTEMS_TASK_EXITTED; + break; + } + + printf("\nApplication exit status: %s (%d)\n\n", StatusStr, (int)OS_BSP_Global.AppStatus); + rtems_task_wake_after(100); + + return retcode; } /* -** A simple entry point to start from the loader -*/ -rtems_task Init( - rtems_task_argument ignored -) + ** A simple entry point to start from the loader + */ +rtems_task Init(rtems_task_argument ignored) { - BSP_Setup(); - - if (rtems_shell_init("SHLL", RTEMS_MINIMUM_STACK_SIZE * 4, 100, "/dev/console", false, false, BSP_Login_Check) < 0) - { - OS_printf ("shell init failed: %s\n", strerror (errno)); - } - - /* - ** Call application specific entry point. - ** This is supposed to call OS_API_Init() - */ - OS_Application_Startup(); - -#ifdef _UNIT_TEST_ - - /* - ** In unit test mode, call the UtTest_Run function (part of UT Assert library) - */ - UtTest_Run(); - UT_BSP_EndTest(UtAssert_GetCounters()); - -#else - - /* - ** OS_IdleLoop() will wait forever and return if - ** someone calls OS_ApplicationShutdown(true) - */ - OS_IdleLoop(); - -#endif - + /* + * Initially clear the global object + */ + memset(&OS_BSP_Global, 0, sizeof(OS_BSP_Global)); + memset(&OS_BSP_PcRtemsGlobal, 0, sizeof(OS_BSP_PcRtemsGlobal)); + + /* + * Perform BSP setup - + * Initialize the root file system, create mount points, etc. + */ + OS_BSP_Setup(); + + /* + * Call application specific entry point. + * This should set up all user tasks and resources, then return + */ + OS_Application_Startup(); + + /* + * OS_Application_Run() implements the background task. + * The user application may provide this, or a default implementation + * is used which just calls OS_IdleLoop(). + */ + OS_Application_Run(); + + /* + * Not calling exit() under RTEMS, this simply shuts down the executive, + * forcing the user to reboot the system. + * + * Calling suspend causes execution to get stuck here, but the RTEMS + * shell thread will still be active so the user can poke around, read results, + * then use a shell command to reboot when ready. + */ + while (!OS_BSP_PcRtemsGlobal.BatchMode) + { + printf("\n\nInit thread idle.\nPress for shell or reset machine...\n\n"); + rtems_task_suspend(rtems_task_self()); + } + + rtems_shutdown_executive(OS_BSP_GetReturnStatus()); } - /* configuration information */ /* @@ -211,43 +380,46 @@ rtems_task Init( #define CONFIGURE_INIT #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_FLOATING_POINT | RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(TASK_INTLEVEL)) #define CONFIGURE_INIT_TASK_STACK_SIZE (20*1024) -#define CONFIGURE_INIT_TASK_PRIORITY 120 +#define CONFIGURE_INIT_TASK_PRIORITY 10 /* - * Note that these resources are shared with RTEMS itself (e.g. the shell) - * so they should be allocated slightly higher than the limits in osconfig.h + * Note that these resources are shared with RTEMS itself (e.g. the init task, the shell) + * so they should be allocated slightly higher than the user limits in osconfig.h + * + * Many RTEMS services use tasks internally, including the idle task, BSWP, ATA driver, + * low level console I/O, the shell, TCP/IP network stack, and DHCP (if enabled). + * Many of these also use semaphores for synchronization. + * + * Budgeting for additional: + * 8 internal tasks + * 2 internal timers + * 4 internal queues + * 16 internal semaphores + * */ -#define CONFIGURE_MAXIMUM_TASKS (OS_MAX_TASKS + 4) +#define CONFIGURE_MAXIMUM_TASKS (OS_MAX_TASKS + 8) #define CONFIGURE_MAXIMUM_TIMERS (OS_MAX_TIMERS + 2) -#define CONFIGURE_MAXIMUM_SEMAPHORES (OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + 4) +#define CONFIGURE_MAXIMUM_SEMAPHORES (OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + 16) #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES (OS_MAX_QUEUES + 4) - - -#define CONFIGURE_EXECUTIVE_RAM_SIZE (1024*1024) +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) +#define CONFIGURE_MAXIMUM_DRIVERS 10 +#define CONFIGURE_MAXIMUM_POSIX_KEYS 4 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER - #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM -#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 100 - #define CONFIGURE_FILESYSTEM_RFS #define CONFIGURE_FILESYSTEM_IMFS #define CONFIGURE_FILESYSTEM_DOSFS #define CONFIGURE_FILESYSTEM_DEVFS - #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK - -#define CONFIGURE_MICROSECONDS_PER_TICK 10000 - -#define CONFIGURE_MAXIMUM_DRIVERS 10 - #define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER -#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY 9 -#define CONFIGURE_MAXIMUM_POSIX_KEYS 4 +#define CONFIGURE_EXECUTIVE_RAM_SIZE (8*1024*1024) +#define CONFIGURE_MICROSECONDS_PER_TICK 10000 +#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY 9 #include @@ -255,6 +427,10 @@ rtems_task Init( #define CONFIGURE_SHELL_COMMANDS_ALL #define CONFIGURE_SHELL_MOUNT_MSDOS -#include +#define CONFIGURE_SHELL_USER_COMMANDS \ + &rtems_shell_RTL_Command, \ + &rtems_shell_dlopen_Command, \ + &rtems_shell_dlsym_Command +#include diff --git a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h new file mode 100644 index 000000000..de2ae50f7 --- /dev/null +++ b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h @@ -0,0 +1,59 @@ +/****************************************************************************** +** File: pcrtems_bsp_internal.h +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Header file for internal data to the PC-RTEMS BSP +** +******************************************************************************/ + +#ifndef _PCRTEMS_BSP_INTERNAL_H_ +#define _PCRTEMS_BSP_INTERNAL_H_ + +/* +** OSAL includes +*/ +#include "osapi.h" +#include "bsp-impl.h" + +/* + * BSP compile-time tuning + */ +#define RTEMS_MAX_USER_OPTIONS 4 +#define RTEMS_NUMBER_OF_RAMDISKS 1 +#define RTEMS_MAX_CMDLINE 256 + +/* + * For debugging, it is helpful to keep the shell + * priority relatively high. But this may cause the + * shell activity to preempt the actual realtime tasks. + */ +#ifdef NDEBUG +#define RTEMS_SHELL_PRIORITY 100 +#else +#define RTEMS_SHELL_PRIORITY 5 +#endif + +/* +** BSP types +*/ +typedef struct +{ + char UserArgBuffer[RTEMS_MAX_CMDLINE]; + bool BatchMode; +} OS_BSP_PcRtemsGlobalData_t; + +/* + * Global Data object + */ +extern OS_BSP_PcRtemsGlobalData_t OS_BSP_PcRtemsGlobal; + +#endif /* _PCRTEMS_BSP_INTERNAL_H_ */ diff --git a/src/bsp/pc-rtems/ut-src/bsp_ut.c b/src/bsp/pc-rtems/ut-src/bsp_ut.c deleted file mode 100644 index 26d82cba2..000000000 --- a/src/bsp/pc-rtems/ut-src/bsp_ut.c +++ /dev/null @@ -1,530 +0,0 @@ -/****************************************************************************** -** File: bsp_ut.c -** -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** Purpose: -** BSP unit test implementation functions. -** -** History: -** Created on: Feb 10, 2015 -** -******************************************************************************/ - -/* - * NOTE - This entire source file is only relevant for unit testing. - * It should not be included in a "normal" BSP build. - */ - -#define _USING_RTEMS_INCLUDES_ - -/* -** Include Files -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "osapi.h" -#include "utbsp.h" -#include "uttest.h" - -/* -** External Declarations -*/ -extern OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES]; - -void OS_Application_Startup(void); - -#define RTEMS_NUMBER_OF_RAMDISKS 1 -#define RTEMS_UT_MAX_USER_OPTIONS 4 -#define RTEMS_UT_MAX_CMDLINE 256 - -/* -** Global variables -*/ - -/* - * The RAM Disk configuration. - */ -rtems_ramdisk_config rtems_ramdisk_configuration[RTEMS_NUMBER_OF_RAMDISKS]; - -/* - * The number of RAM Disk configurations. -*/ -size_t rtems_ramdisk_configuration_size = RTEMS_NUMBER_OF_RAMDISKS; - -/* -** RAM Disk IO op table. -*/ -rtems_driver_address_table rtems_ramdisk_io_ops = -{ - .initialization_entry = ramdisk_initialize, - .open_entry = rtems_blkdev_generic_open, - .close_entry = rtems_blkdev_generic_close, - .read_entry = rtems_blkdev_generic_read, - .write_entry = rtems_blkdev_generic_write, - .control_entry = rtems_blkdev_generic_ioctl -}; - -/* - * Under RTEMS there is no notion of command-line arguments like in pc-linux, - * so it is not as easy to change this value at runtime. For now the default - * will show all messages except debug. - * - * It may be possible to set this value using the shell... - */ -static bool BatchMode = false; -static int32 UserArgc = 0; -static char UserArgBuffer[RTEMS_UT_MAX_CMDLINE]; -static char *UserArgv[RTEMS_UT_MAX_USER_OPTIONS] = { NULL }; -static uint32 CurrVerbosity = (2 << UTASSERT_CASETYPE_PASS) - 1; - -/* - * UT_BSP_GetTotalOptions: See details in prototype - */ -int32 UT_BSP_GetTotalOptions(void) -{ - return UserArgc; -} - -/* - * UT_BSP_GetOptionString: See details in prototype - */ -const char * UT_BSP_GetOptionString(int32 OptionNum) -{ - if (OptionNum >= UserArgc) - { - return NULL; - } - - return UserArgv[OptionNum]; -} - - -void UT_BSP_Setup(void) -{ - int status; - int i; - struct stat statbuf; - const char *cmdlinestr; - const char *cmdp; - char *cmdi, *cmdo; - - cmdlinestr = bsp_cmdline(); - printf( "\n\n*** RTEMS Info ***\n" ); - printf("%s", _Copyright_Notice ); - printf("%s\n\n", _RTEMS_version ); - printf(" Stack size=%d\n", (int)Configuration.stack_space_size ); - printf(" Workspace size=%d\n", (int) Configuration.work_space_size ); - if (cmdlinestr != NULL) - { - printf(" Bootloader Command Line: %s\n", cmdlinestr); - } - printf("\n"); - printf( "*** End RTEMS info ***\n\n" ); - - /* - * Parse command line string (passed in from bootloader) - * - * Known arguments are handled here, and unknown args are - * saved for the UT application. - * - * Batch mode is intended for non-interative execution. - * - * It does two things: - * - do not start the shell task - * - when tests are complete, shutdown the executive - * - * The BSP should be configured with these options to - * make this most useful: - * USE_COM1_AS_CONSOLE=1 - * BSP_PRESS_KEY_FOR_RESET=0 - * BSP_RESET_BOARD_AT_EXIT=1 - * - * This way all the test output will be sent to COM1 - * and then immediately resets the CPU when done. - * - * When running under QEMU the "-no-reboot" flag is - * also useful to shutdown QEMU rather than resetting. - */ - if (cmdlinestr != NULL) - { - cmdp = cmdlinestr; - cmdo = NULL; - cmdi = NULL; - while (1) - { - if (isgraph((int)*cmdp)) - { - if (cmdo == NULL) - { - cmdo = UserArgBuffer; - } - else - { - ++cmdo; - } - if (cmdi == NULL) - { - cmdi = cmdo; - } - *cmdo = *cmdp; - } - else if (cmdi != NULL) - { - ++cmdo; - *cmdo = 0; - if (strcmp(cmdi,"--batch-mode") == 0) - { - BatchMode = true; - } - else if (UserArgc < RTEMS_UT_MAX_USER_OPTIONS) - { - /* save other args for app */ - UserArgv[UserArgc] = cmdi; - ++UserArgc; - } - cmdi = NULL; - } - - if (*cmdp == 0) - { - break; - } - - ++cmdp; - } - } - - /* - ** Create the RTEMS Root file system - */ - status = rtems_create_root_fs(); - if (status != RTEMS_SUCCESSFUL) - { - printf("Creating Root file system failed: %s\n",rtems_status_text(status)); - } - - /* - ** create the directory mountpoints - */ - - /* - ** Create local directories for "disk" mount points - ** See bsp_voltab for the values - ** - ** NOTE - the voltab table is poorly designed here; values of "0" are valid - ** and will translate into an entry that is actually used. In particular the - ** "free" flag has to be actually initialized to TRUE to say its NOT valid. - ** So in the case of an entry that has been zeroed out (i.e. bss section) it - ** will be treated as a valid entry. - ** - ** Checking that the DeviceName starts with a leading slash '/' is a workaround - ** for this, and may be the only way to detect an entry that is uninitialized. - */ - for (i=0; i < NUM_TABLE_ENTRIES; ++i) - { - if (OS_VolumeTable[i].VolumeType == FS_BASED && - OS_VolumeTable[i].PhysDevName[0] != 0 && - OS_VolumeTable[i].DeviceName[0] == '/') - - { - if (stat(OS_VolumeTable[i].PhysDevName, &statbuf) < 0) - { - printf("Creating mount point directory: %s\n", - OS_VolumeTable[i].PhysDevName); - status = mkdir(OS_VolumeTable[i].PhysDevName, S_IFDIR |S_IRWXU | S_IRWXG | S_IRWXO); /* For ramdisk mountpoint */ - if (status != RTEMS_SUCCESSFUL) - { - printf("mkdir failed: %s\n", strerror (errno)); - } - } - } - } - - if (!BatchMode) - { - status = rtems_shell_init("SHLL", RTEMS_MINIMUM_STACK_SIZE * 4, 100, "/dev/console", false, false, NULL); - if (status < 0) - { - printf ("shell init failed: %s\n", strerror (errno)); - } - - } - - printf("\n\n"); - - /* give a small delay to let the shell start, - avoids having the login prompt show up mid-test, - and gives a little time for pending output to actually - be sent to the console in case of a slow port */ - rtems_task_wake_after(50); - - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "PC-RTEMS UNIT TEST"); -} - - -void UT_BSP_StartTestSegment(uint32 SegmentNumber, const char *SegmentName) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u %s", (unsigned int)SegmentNumber, SegmentName); - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, ReportBuffer); -} - -void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) -{ - const char *Prefix; - - if ((CurrVerbosity >> MessageType) & 1) - { - switch(MessageType) - { - case UTASSERT_CASETYPE_ABORT: - Prefix = "ABORT"; - break; - case UTASSERT_CASETYPE_FAILURE: - Prefix = "FAIL"; - break; - case UTASSERT_CASETYPE_MIR: - Prefix = "MIR"; - break; - case UTASSERT_CASETYPE_TSF: - Prefix = "TSF"; - break; - case UTASSERT_CASETYPE_TTF: - Prefix = "TTF"; - break; - case UTASSERT_CASETYPE_NA: - Prefix = "N/A"; - break; - case UTASSERT_CASETYPE_BEGIN: - printf("\n"); /* add a bit of extra whitespace between tests */ - Prefix = "BEGIN"; - break; - case UTASSERT_CASETYPE_END: - Prefix = "END"; - break; - case UTASSERT_CASETYPE_PASS: - Prefix = "PASS"; - break; - case UTASSERT_CASETYPE_INFO: - Prefix = "INFO"; - break; - case UTASSERT_CASETYPE_DEBUG: - Prefix = "DEBUG"; - break; - default: - Prefix = "OTHER"; - break; - } - printf("[%5s] %s\n",Prefix,OutputMessage); - } - - /* - * If any ABORT (major failure) message is thrown, - * then actually call abort() to stop the test and dump a core - */ - if (MessageType == UTASSERT_CASETYPE_ABORT) - { - abort(); - } -} - -void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 TestSeq, uint8 MessageType, const char *SubsysName, const char *ShortDesc) -{ - uint32 FileLen; - const char *BasePtr; - char ReportBuffer[128]; - - FileLen = strlen(File); - BasePtr = File + FileLen; - while (FileLen > 0) - { - --BasePtr; - --FileLen; - if (*BasePtr == '/' || *BasePtr == '\\') - { - ++BasePtr; - break; - } - } - - snprintf(ReportBuffer,sizeof(ReportBuffer), "%02u.%03u %s:%u - %s", - (unsigned int)SegmentNum, (unsigned int)TestSeq, - BasePtr, (unsigned int)LineNum, ShortDesc); - - UT_BSP_DoText(MessageType, ReportBuffer); -} - -void UT_BSP_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCounter_t *TestCounters) -{ - char ReportBuffer[128]; - - snprintf(ReportBuffer,sizeof(ReportBuffer), - "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-4u N/A::%-4u\n", - (unsigned int)TestCounters->TestSegmentCount, - SegmentName, - (unsigned int)TestCounters->TotalTestCases, - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_PASS], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_MIR], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_TSF], - (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_NA]); - - - UT_BSP_DoText(UTASSERT_CASETYPE_END, ReportBuffer); -} - -void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters) -{ - const char *Overall; - - /* - * Only output a "summary" if there is more than one test Segment. - * Otherwise it is a duplicate of the report already given. - */ - if (TestCounters->TestSegmentCount > 1) - { - UT_BSP_DoTestSegmentReport("SUMMARY", TestCounters); - } - - printf("COMPLETE: %u test segment(s) executed\n", (unsigned int)TestCounters->TestSegmentCount); - - /* - * Since this test is probably not running directly on the - * host but rather on a separate target or emulator, we cannot - * rely on a return code / exit status to identify pass/fail - * as is done on the Linux UT. - * - * This outputs a simplified "RESULT: " line as the - * final output line. A test script can grep for this line. - */ - if (TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE] > 0 || - TestCounters->CaseCount[UTASSERT_CASETYPE_ABORT] > 0) - { - Overall = "FAILURE"; - } - else if (TestCounters->CaseCount[UTASSERT_CASETYPE_TSF] > 0 || - TestCounters->CaseCount[UTASSERT_CASETYPE_TTF] > 0) - { - Overall = "TSF/TTF"; - } - else if (TestCounters->CaseCount[UTASSERT_CASETYPE_PASS] > 0) - { - Overall = "SUCCESS"; - } - else - { - /* no tests failed, but no tests passed either... */ - Overall = "UNKNOWN"; - } - - printf("RESULT: %s\n", Overall); - - /* - * Not calling exit() under RTEMS, this simply shuts down the executive, - * forcing the user to reboot the system. - * - * Calling suspend causes execution to get stuck here, but the RTEMS - * shell thread will still be active so the user can poke around, read results, - * then use a shell command to reboot when ready. - */ - while (!BatchMode) - { - printf("\n\nTesting thread now idle.\nPress for shell or reset machine...\n\n"); - rtems_task_suspend(rtems_task_self()); - } -} - - -/* -** A simple entry point to start from the loader -*/ -rtems_task Init( - rtems_task_argument ignored -) -{ - /* - ** Call application specific entry point. - ** This is supposed to call OS_API_Init() - */ - OS_Application_Startup(); - - /* - ** The OS_Application_Run function is part of UT Assert library - */ - OS_Application_Run(); - - rtems_shutdown_executive(UtAssert_GetFailCount() != 0); -} - - -/* configuration information */ - -/* -** RTEMS OS Configuration defintions -*/ -#define TASK_INTLEVEL 0 -#define CONFIGURE_INIT -#define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_FLOATING_POINT | RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(TASK_INTLEVEL)) -#define CONFIGURE_INIT_TASK_STACK_SIZE (20*1024) -#define CONFIGURE_INIT_TASK_PRIORITY 120 - -/* - * Note that these resources are shared with RTEMS itself (e.g. the shell) - * so they should be allocated slightly higher than the limits in osconfig.h - */ -#define CONFIGURE_MAXIMUM_TASKS (OS_MAX_TASKS + 4) -#define CONFIGURE_MAXIMUM_TIMERS (OS_MAX_TIMERS + 2) -#define CONFIGURE_MAXIMUM_SEMAPHORES (OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + 2) -#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES (OS_MAX_QUEUES + 2) - - -#define CONFIGURE_EXECUTIVE_RAM_SIZE (1024*1024) - -#define CONFIGURE_RTEMS_INIT_TASKS_TABLE -#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER -#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER - -#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM -#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) - -#define CONFIGURE_FILESYSTEM_RFS -#define CONFIGURE_FILESYSTEM_IMFS -#define CONFIGURE_FILESYSTEM_DEVFS - -#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK - -#define CONFIGURE_MICROSECONDS_PER_TICK 10000 -#define CONFIGURE_MAXIMUM_DRIVERS 10 -#define CONFIGURE_MAXIMUM_POSIX_KEYS 4 - -#include - -#define CONFIGURE_SHELL_COMMANDS_INIT -#define CONFIGURE_SHELL_COMMANDS_ALL - -#include - - diff --git a/src/bsp/pc-rtems/ut-src/bsp_ut_voltab.c b/src/bsp/pc-rtems/ut-src/bsp_ut_voltab.c deleted file mode 100644 index 9c9a67ad4..000000000 --- a/src/bsp/pc-rtems/ut-src/bsp_ut_voltab.c +++ /dev/null @@ -1,61 +0,0 @@ -/* -** File : bsp_voltab.c -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Copyright (c) 2004-2006, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. -** -** -** BSP Volume table for file systems -*/ - -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ -#include "common_types.h" -#include "osapi.h" - -/* -** volume table. This table has the OS_ name, since it belongs to the OSAL, not the CFE_PSP -*/ -OS_VolumeInfo_t OS_VolumeTable [NUM_TABLE_ENTRIES] = -{ -/* Dev Name Phys Dev Vol Type Volatile? Free? IsMounted? Volname MountPt BlockSz */ - -/* Two virtual RAM disks for testing purposes - file system tests use these */ -{ "/ramdev0", "/ram0", FS_BASED, true, true, false, " ", "/drive0", 512 }, -{ "/ramdev1", "/ram1", FS_BASED, true, true, false, " ", "/drive1", 512 }, - -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, - -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, - -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 }, -{"unused", "unused", FS_BASED, true, true, false, " ", " ", 0 } - -}; - -/* - * An example of a static symbol loader table - * Only used if OS_STATIC_LOADER is enabled in osconfig.h - */ -#ifdef OS_STATIC_LOADER -OS_static_symbol_record_t OS_STATIC_SYMBOL_TABLE[] = -{ - { "OS_Application_Startup", OS_Application_Startup }, - { NULL, NULL } -}; -#endif - - diff --git a/src/bsp/shared/bsp-impl.h b/src/bsp/shared/bsp-impl.h new file mode 100644 index 000000000..f2d0d9f37 --- /dev/null +++ b/src/bsp/shared/bsp-impl.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2018, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Glenn + * Research 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 bsp-impl.h + * \author joseph.p.hickey@nasa.gov + * + * Purpose: Contains functions prototype definitions and variables declarations + * for the OSAL BSP layer + * + * This is used to provide an abstract notion of certain platform-specific features: + * + * - Startup arguments/options. These are optional strings containing any + * passed-in parameters from a bootloader/shell/etc. Not all platforms + * support this notion, but this provides a consistent access method for + * those platforms that do pass startup options. + * + * - Exit code. This is the "status" passed back to the operating system + * if/when the application terminates. This is a numeric value with + * platform-defined meaning. + * + * - Low-level console output. Provide direct, synchronous access to the + * BSP-provided console or debug terminal device. + */ + +#ifndef _osapi_bsp_impl_ +#define _osapi_bsp_impl_ + +#include "osapi.h" + +/* + * A set of simplified console control options + * + * These constants are used with the OS_BSP_ConsoleSetMode_Impl() API + * to allow debug console text to be output with additional attributes + * on platforms that support it. + * + * This is NOT intended as a full terminal control abstraction, + * just enough to draw visual attention to certain messages on + * platforms that support it. + */ +#define OS_BSP_CONSOLEMODE_NORMAL 0x0 /**< Default output mode - clears any previously-set attributes */ +#define OS_BSP_CONSOLEMODE_RED 0x1 /**< Red text, if terminal supports color */ +#define OS_BSP_CONSOLEMODE_GREEN 0x2 /**< Green text, if terminal supports color */ +#define OS_BSP_CONSOLEMODE_BLUE 0x4 /**< Blue text, if terminal supports color */ +#define OS_BSP_CONSOLEMODE_HIGHLIGHT 0x8 /**< Highlighted/Emphasis text, if terminal supports it */ + +#define OS_BSP_CONSOLEMODE_TO_ANSICOLOR(x) ((x) & 0x07) + +/* + * Macro for BSP debug messages, similar to OS_DEBUG in OSAL code. + * + * This is also controlled by the OS_DEBUG_PRINTF compile-time option, + * except it does not reference the OSAL global variables like OS_DEBUG does. + * + * (This global is likely not initialized at the time the BSP code executes, + * and are also generally not accessible from BSP code) + */ +#if defined(OS_DEBUG_PRINTF) +#define BSP_DEBUG(...) \ + do \ + { \ + printf("%s():", __func__); \ + printf(__VA_ARGS__); \ + } while (0) +#else +/* Debug printfs are not compiled in at all */ +#define BSP_DEBUG(...) +#endif + +/* +** Common/Abstract BSP state data +*/ +typedef struct +{ + uint32 ArgC; /* number of boot/startup parameters in ArgV */ + char **ArgV; /* strings for boot/startup parameters */ + int32 AppStatus; /* value which can be returned to the OS (0=nominal) */ + uint32 MaxQueueDepth; /* Queue depth limit supported by BSP (0=no limit) */ +} OS_BSP_GlobalData_t; + +/* + * Common/Abstracted BSP state data + */ +extern OS_BSP_GlobalData_t OS_BSP_Global; + +/* + * Volume Table declaration (supplied by BSP; typically defined in bsp_voltab.c) + */ +extern OS_VolumeInfo_t OS_VolumeTable[NUM_TABLE_ENTRIES]; + +/********************************************************************/ +/* INTERNAL BSP IMPLEMENTATION FUNCTIONS */ +/********************************************************************/ + +/*---------------------------------------------------------------- + Function: OS_BSP_ConsoleOutput_Impl + + Purpose: Low level raw console data output. Writes a sequence of + characters directly to the BSP debug terminal or console device. + + The string is not required to be null terminated, and + any control characters will be passed through. Any + non-printable ASCII codes will have platform-defined + interpretation. + + Note: This should write the string as-is without buffering. + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen); + +/*---------------------------------------------------------------- + Function: OS_BSP_ConsoleSetMode_Impl + + Purpose: Set the console output mode, if supported by the BSP. + + Causes any future text written to the debug console to + be colored/highlighted accordingly. Intended for use + with test applications where certain messages may need + visual distinction (e.g. failures). + + See the OS_BSP_CONSOLEMODE constants for possible values. + Values may be bitwise OR'ed together. + + This call is ignored if the BSP does not support console + control codes. + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits); + +/********************* + END bsp-impl.h + *********************/ +#endif /* _osapi_bsp_impl_ */ diff --git a/src/bsp/shared/bsp_default_app_run.c b/src/bsp/shared/bsp_default_app_run.c new file mode 100644 index 000000000..0dd067eef --- /dev/null +++ b/src/bsp/shared/bsp_default_app_run.c @@ -0,0 +1,32 @@ +/****************************************************************************** +** File: bsp_app_run.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2015, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Application run default implementation. +** +** NOTE: This is isolated in a separate compilation unit, so that a user +** application may directly provide an OS_Application_Run() implementation +** which will override this default. +** +******************************************************************************/ + +#include "osapi.h" +#include "bsp-impl.h" + +/* + * The default implementation of OS_Application_Run() + * just calls the OS_IdleLoop() provided by OSAL. + */ +void OS_Application_Run(void) +{ + OS_IdleLoop(); +} diff --git a/src/bsp/shared/bsp_default_app_startup.c b/src/bsp/shared/bsp_default_app_startup.c new file mode 100644 index 000000000..e6174ec0a --- /dev/null +++ b/src/bsp/shared/bsp_default_app_startup.c @@ -0,0 +1,41 @@ +/****************************************************************************** +** File: bsp_app_startup.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2015, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Application startup default implementation. +** +** NOTE: This is isolated in a separate compilation unit, so that a user +** application may directly provide an OS_Application_Startup() implementation +** which will override this default. +** +******************************************************************************/ + +#include +#include "osapi.h" + +#include "bsp-impl.h" + +/* + * The default implementation of OS_Application_Startup() + * just calls the OS_API_Init() provided by OSAL. + */ +void OS_Application_Startup(void) +{ + int32 Status; + + Status = OS_API_Init(); + if (Status != OS_SUCCESS) + { + BSP_DEBUG("Error: OS_API_Init() failed with status=%d\n", (int)Status); + OS_ApplicationExit(Status); + } +} diff --git a/src/bsp/shared/bsp_default_symtab.c b/src/bsp/shared/bsp_default_symtab.c new file mode 100644 index 000000000..a8a9f1e2a --- /dev/null +++ b/src/bsp/shared/bsp_default_symtab.c @@ -0,0 +1,31 @@ +/****************************************************************************** +** File: bsp_symtab.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2015, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Application static symbol table default implementation. +** +** NOTE: This is isolated in a separate compilation unit, so that a user +** application may directly provide an OS_STATIC_SYMBOL_TABLE definition +** which will override this default. +** +******************************************************************************/ + +#include "osapi.h" +#include "bsp-impl.h" + + +OS_static_symbol_record_t OS_STATIC_SYMBOL_TABLE[] = +{ + { "OS_Application_Startup", OS_Application_Startup }, + { "OS_Application_Run", OS_Application_Run }, + { NULL, NULL } +}; diff --git a/src/bsp/shared/osapi-bsp.c b/src/bsp/shared/osapi-bsp.c new file mode 100644 index 000000000..9e9bf5178 --- /dev/null +++ b/src/bsp/shared/osapi-bsp.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2018, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Glenn + * Research 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 osapi-common.c + * \author joseph.p.hickey@nasa.gov + * + * Purpose: + * This file contains some of the OS APIs abstraction layer code + * that is shared/common across all OS-specific implementations. + * + * Instantiates the global object tables and the overall OSAL + * init/teardown logic such as OS_API_Init() and OS_ApplicationExit(). + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ +#include +#include +#include + +/* + * User defined include files + */ +#include "common_types.h" +#include "bsp-impl.h" + +/* + * BSP Global Data Object + */ +OS_BSP_GlobalData_t OS_BSP_Global; + +/* + ********************************************************************************* + * PUBLIC API (application-callable functions) + ********************************************************************************* + */ + +/*---------------------------------------------------------------- + OS_BSP_GetArgC + See full description in header + ------------------------------------------------------------------*/ +uint32 OS_BSP_GetArgC(void) +{ + return OS_BSP_Global.ArgC; +} + +/*---------------------------------------------------------------- + OS_BSP_GetArgV + See full description in header + ------------------------------------------------------------------*/ +char * const * OS_BSP_GetArgV(void) +{ + return OS_BSP_Global.ArgV; +} + +/*---------------------------------------------------------------- + OS_BSP_SetExitCode + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_SetExitCode(int32 code) +{ + OS_BSP_Global.AppStatus = code; +} + diff --git a/src/os/inc/osapi-os-core.h b/src/os/inc/osapi-os-core.h index 2378ed5f3..728508424 100644 --- a/src/os/inc/osapi-os-core.h +++ b/src/os/inc/osapi-os-core.h @@ -1527,4 +1527,59 @@ void OS_printf_disable(void); void OS_printf_enable(void); /**@}*/ + +/**************************************************************************************** + BSP LOW-LEVEL IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*---------------------------------------------------------------- + Function: OS_BSP_GetArgC + + Purpose: Obtain the number of boot arguments passed from the bootloader + or shell if supported by the platform + + Returns: The number of boot arguments, or 0 if no arguments were passed + or not supported by the BSP. + ------------------------------------------------------------------*/ +uint32 OS_BSP_GetArgC(void); + +/*---------------------------------------------------------------- + Function: OS_BSP_GetArgV + + Purpose: Obtain an array of boot argument strings passed from the bootloader + or shell if supported by the platform + + Returns: Pointer to char* array containing the argument strings, or NULL if + no arguments are available or not supported by the BSP. + + The array is sized according to OS_BSP_GetArgC() + ------------------------------------------------------------------*/ +char * const * OS_BSP_GetArgV(void); + +/*---------------------------------------------------------------- + Function: OS_BSP_SetExitCode + + Purpose: Sets the status to be returned to the shell or bootloader + if supported by the platform. The value is an integer with + platform and application-defined meaning, but BSP's should + attempt to provide consistent meaning for the following values + + OS_SUCCESS: normal status (default) + OS_ERROR: any abnormal status + + Other more specific status values may be passed, with + implementation-defined behavior. Depending on the system + capabilities, the BSP implementation may either pass the + value through as-is, translate it to defined value, or + ignore it. + + Note this does NOT cause the application to exit, it only + sets the state that will be returned if/when the application + exits itself at a future time. + + ------------------------------------------------------------------*/ +void OS_BSP_SetExitCode(int32 code); + + + #endif diff --git a/src/os/posix/CMakeLists.txt b/src/os/posix/CMakeLists.txt new file mode 100644 index 000000000..b628aefe0 --- /dev/null +++ b/src/os/posix/CMakeLists.txt @@ -0,0 +1,19 @@ +###################################################################### +# +# CMAKE build recipe for POSIX OSAL implementation +# +###################################################################### + +# This CMake script generates targets specific to the POSIX implementation +# It defines an OBJECT target named "osal_posix_impl" + +add_library(osal_posix_impl OBJECT + osapi.c + osfileapi.c + osfilesys.c + osloader.c + osnetwork.c + osselect.c + ostimer.c +) + diff --git a/src/os/posix/build_options.cmake b/src/os/posix/build_options.cmake index da1278c2c..c1f609301 100644 --- a/src/os/posix/build_options.cmake +++ b/src/os/posix/build_options.cmake @@ -1,30 +1,9 @@ +########################################################################## # -# For POSIX systems based on glibc (i.e. Linux) certain features must be enabled -# Glibc headers support multiple standards and multiple versions of the standards, -# so the definitions of these macros determine which standard we will use +# Build options for "posix" implementation layer # -# OSAL needs conformance to at least POSIX.1c (aka POSIX 1995) - this includes all the -# real-time support and threading extensions. -# -# When compiling against glibc, using "_XOPEN_SOURCE=600" enables the X/Open 6 standard. -# XPG6 includes all necessary XPG5, POSIX.1c features as well as SUSv2/UNIX98 extensions. -# This OSAL implementation uses clock_nanosleep(), mq_timedreceive(), and -# mq_timedsend() which are enhancements added in the XPG6 standard. (The previous OSAL -# POSIX implementation needed only XPG5). It may be possible to conditionally compile -# these calls in case of a C library that does not have XPG6. -# -# Note that this definition assumes glibc -- in case of compiling OSAL for some platform -# that supports POSIX but does not use glibc (e.g. uclibc) this definition shouldn't -# harm anything, but it may need to be tweaked. -# -# See http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html -# for a more detailed description of the feature test macros and available values -# -set(OSAL_COMMON_COMPILE_DEFS "${OSAL_COMMON_COMPILE_DEFS} -D_XOPEN_SOURCE=600") - -# OSAL_LINK_LIBS determines which system-level libraries must be included in the -# link command in order to produce the final binary. These libs will be used for -# ALL targets that utilize the POSIX OS layer. Additional target-specific libraries -# may also be specified in the BSP or the cross-compile toolchain. -set (OSAL_LINK_LIBS ${OSAL_LINK_LIBS} pthread dl rt) +########################################################################## +# this file is a placeholder for POSIX-specific compile tuning +# currently no extra flags/definitions needed + diff --git a/src/os/posix/osapi.c b/src/os/posix/osapi.c index 9f6a30092..6ad957968 100644 --- a/src/os/posix/osapi.c +++ b/src/os/posix/osapi.c @@ -25,6 +25,7 @@ ***************************************************************************************/ #include "os-posix.h" +#include "bsp-impl.h" #include /* @@ -177,7 +178,7 @@ static void OS_NoopSigHandler (int signal) } /* end OS_NoopSigHandler */ - + /*---------------------------------------------------------------- * * Function: OS_Lock_Global_Impl @@ -221,7 +222,7 @@ int32 OS_Lock_Global_Impl(uint32 idtype) return OS_SUCCESS; } /* end OS_Lock_Global_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_Unlock_Global_Impl @@ -367,7 +368,7 @@ int32 OS_API_Impl_Init(uint32 idtype) return(return_code); } /* end OS_API_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_IdleLoop_Impl @@ -389,7 +390,7 @@ void OS_IdleLoop_Impl() sigsuspend(&POSIX_GlobalVars.NormalSigMask); } /* end OS_IdleLoop_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_ApplicationShutdown_Impl @@ -726,7 +727,7 @@ int32 OS_Posix_TaskAPI_Impl_Init(void) return OS_SUCCESS; } /* end OS_Posix_TaskAPI_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_Posix_InternalTaskCreate_Impl @@ -851,7 +852,7 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t return OS_SUCCESS; } /* end OS_Posix_InternalTaskCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskCreate_Impl @@ -878,7 +879,7 @@ int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) return return_code; } /* end OS_TaskCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskMatch_Impl @@ -897,7 +898,7 @@ int32 OS_TaskMatch_Impl(uint32 task_id) return OS_SUCCESS; } /* end OS_TaskMatch_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskDelete_Impl @@ -919,7 +920,7 @@ int32 OS_TaskDelete_Impl (uint32 task_id) } /* end OS_TaskDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskExit_Impl @@ -934,7 +935,7 @@ void OS_TaskExit_Impl() } /* end OS_TaskExit_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskDelay_Impl @@ -974,7 +975,7 @@ int32 OS_TaskDelay_Impl(uint32 millisecond) } } /* end OS_TaskDelay_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskSetPriority_Impl @@ -1008,7 +1009,7 @@ int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) return OS_SUCCESS; } /* end OS_TaskSetPriority_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskRegister_Impl @@ -1039,7 +1040,7 @@ int32 OS_TaskRegister_Impl(uint32 global_task_id) return return_code; } /* end OS_TaskRegister_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskGetId_Impl @@ -1057,7 +1058,7 @@ uint32 OS_TaskGetId_Impl (void) return(self_record.value); } /* end OS_TaskGetId_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TaskGetInfo_Impl @@ -1108,50 +1109,28 @@ int32 OS_Posix_QueueAPI_Impl_Init(void) { memset(OS_impl_queue_table, 0, sizeof(OS_impl_queue_table)); - /* - * Initialize this to zero to indicate no limit - * (would have expected osconfig.h to specify an upper limit, but it does not) - */ - POSIX_GlobalVars.TruncateQueueDepth = 0; - /* * Automatic truncation is dependent on the OSAL_DEBUG_PERMISSIVE_MODE compile-time define - so * creating a too-large message queue on a target without OSAL_DEBUG_PERMISSIVE_MODE will fail * with an OS error as intended. */ #ifdef OSAL_DEBUG_PERMISSIVE_MODE - { - FILE *fp; - char buffer[32]; - - /* - * If running on Linux, /proc/sys/fs/mqueue/msg_max represents the max depth of a posix message queue for a user. - * - * In order to facilitate running in simulation mode without any need for root access -- - * this will allow the OSAL to successfully create message queues by truncating anything larger than this size. - * - * No need to check _LINUX_OS_ here; if the file fails to open, i.e. if not on Linux and the file does not exist, - * then leave well enough alone and don't do anything. - */ - - fp = fopen("/proc/sys/fs/mqueue/msg_max","r"); - if (fp) - { - if (fgets(buffer,sizeof(buffer),fp) != NULL) - { - POSIX_GlobalVars.TruncateQueueDepth = strtoul(buffer, NULL, 10); - OS_DEBUG("Maximum user msg queue depth = %u\n", (unsigned int)POSIX_GlobalVars.TruncateQueueDepth); - } - fclose(fp); - } - } + /* + * Use the BSP-provided limit + */ + POSIX_GlobalVars.TruncateQueueDepth = OS_BSP_Global.MaxQueueDepth; +#else + /* + * Initialize this to zero to indicate no limit + */ + POSIX_GlobalVars.TruncateQueueDepth = 0; #endif return OS_SUCCESS; } /* end OS_Posix_QueueAPI_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_QueueCreate_Impl @@ -1231,7 +1210,7 @@ int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) return return_code; } /* end OS_QueueCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_QueueDelete_Impl @@ -1258,7 +1237,7 @@ int32 OS_QueueDelete_Impl (uint32 queue_id) return return_code; } /* end OS_QueueDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_QueueGet_Impl @@ -1358,7 +1337,7 @@ int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_c return return_code; } /* end OS_QueueGet_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_QueuePut_Impl @@ -1432,7 +1411,7 @@ int32 OS_Posix_BinSemAPI_Impl_Init(void) return OS_SUCCESS; } /* end OS_Posix_BinSemAPI_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemCreate_Impl @@ -1556,7 +1535,7 @@ int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 initial_value, uint32 options) } /* end OS_BinSemCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemDelete_Impl @@ -1597,7 +1576,7 @@ int32 OS_BinSemDelete_Impl (uint32 sem_id) } /* end OS_BinSemDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemGive_Impl @@ -1640,7 +1619,7 @@ int32 OS_BinSemGive_Impl ( uint32 sem_id ) return OS_SUCCESS; } /* end OS_BinSemGive_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemFlush_Impl @@ -1744,7 +1723,7 @@ static int32 OS_GenericBinSemTake_Impl (OS_impl_binsem_internal_record_t *sem, c return return_code; } /* end OS_GenericBinSemTake_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemTake_Impl @@ -1758,7 +1737,7 @@ int32 OS_BinSemTake_Impl ( uint32 sem_id ) return (OS_GenericBinSemTake_Impl (&OS_impl_bin_sem_table[sem_id], NULL)); } /* end OS_BinSemTake_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemTimedWait_Impl @@ -1779,7 +1758,7 @@ int32 OS_BinSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) return (OS_GenericBinSemTake_Impl (&OS_impl_bin_sem_table[sem_id], &ts)); } /* end OS_BinSemTimedWait_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemGetInfo_Impl @@ -1819,7 +1798,7 @@ int32 OS_Posix_CountSemAPI_Impl_Init(void) return OS_SUCCESS; } /* end OS_Posix_CountSemAPI_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemCreate_Impl @@ -1844,7 +1823,7 @@ int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 op } /* end OS_CountSemCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemDelete_Impl @@ -1864,7 +1843,7 @@ int32 OS_CountSemDelete_Impl (uint32 sem_id) } /* end OS_CountSemDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemGive_Impl @@ -1884,7 +1863,7 @@ int32 OS_CountSemGive_Impl ( uint32 sem_id ) } /* end OS_CountSemGive_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemTake_Impl @@ -1903,7 +1882,7 @@ int32 OS_CountSemTake_Impl ( uint32 sem_id ) return OS_SUCCESS; } /* end OS_CountSemTake_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemTimedWait_Impl @@ -1939,7 +1918,7 @@ int32 OS_CountSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) return result; } /* end OS_CountSemTimedWait_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemGetInfo_Impl @@ -1966,7 +1945,7 @@ int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop) MUTEX API ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_Posix_MutexAPI_Impl_Init @@ -1980,7 +1959,7 @@ int32 OS_Posix_MutexAPI_Impl_Init(void) return OS_SUCCESS; } /* end OS_Posix_MutexAPI_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemCreate_Impl @@ -2042,7 +2021,7 @@ int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) return OS_SUCCESS; } /* end OS_MutSemCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemDelete_Impl @@ -2066,7 +2045,7 @@ int32 OS_MutSemDelete_Impl (uint32 sem_id) } /* end OS_MutSemDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemGive_Impl @@ -2091,7 +2070,7 @@ int32 OS_MutSemGive_Impl ( uint32 sem_id ) return OS_SUCCESS; } /* end OS_MutSemGive_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemTake_Impl @@ -2116,7 +2095,7 @@ int32 OS_MutSemTake_Impl ( uint32 sem_id ) return OS_SUCCESS; } /* end OS_MutSemTake_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemGetInfo_Impl @@ -2137,7 +2116,7 @@ int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) INT API ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_IntAttachHandler_Impl @@ -2151,7 +2130,7 @@ int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry Interru return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntAttachHandler_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntUnlock_Impl @@ -2165,7 +2144,7 @@ int32 OS_IntUnlock_Impl (int32 IntLevel) return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntUnlock_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntLock_Impl @@ -2178,7 +2157,7 @@ int32 OS_IntLock_Impl ( void ) { return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntLock_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntEnable_Impl @@ -2192,7 +2171,7 @@ int32 OS_IntEnable_Impl(int32 Level) return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntEnable_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntDisable_Impl @@ -2206,7 +2185,7 @@ int32 OS_IntDisable_Impl(int32 Level) return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntDisable_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntSetMask_Impl @@ -2220,7 +2199,7 @@ int32 OS_IntSetMask_Impl ( uint32 MaskSetting ) return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntSetMask_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_IntGetMask_Impl @@ -2321,7 +2300,7 @@ static int OS_PriorityRemap(uint32 InputPri) return OutputPri; } /* end OS_PriorityRemap */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcAttachHandler_Impl @@ -2338,7 +2317,7 @@ int32 OS_FPUExcAttachHandler_Impl(uint32 ExceptionNumber, osal_task_entry Except */ return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_FPUExcAttachHandler_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcEnable_Impl @@ -2354,7 +2333,7 @@ int32 OS_FPUExcEnable_Impl(int32 ExceptionNumber) */ return(OS_SUCCESS); } /* end OS_FPUExcEnable_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcDisable_Impl @@ -2371,7 +2350,7 @@ int32 OS_FPUExcDisable_Impl(int32 ExceptionNumber) return(OS_SUCCESS); } /* end OS_FPUExcDisable_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcSetMask_Impl @@ -2388,7 +2367,7 @@ int32 OS_FPUExcSetMask_Impl(uint32 mask) return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_FPUExcSetMask_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcGetMask_Impl @@ -2412,7 +2391,7 @@ int32 OS_FPUExcGetMask_Impl(uint32 *mask) /* use the portable version of OS_ConsoleWrite_Impl() */ #include "../portable/os-impl-console-directwrite.c" - + /*---------------------------------------------------------------- * * Function: OS_ConsoleWakeup_Impl @@ -2459,7 +2438,7 @@ static void* OS_ConsoleTask_Entry(void* arg) } return NULL; } /* end OS_ConsoleTask_Entry */ - + /*---------------------------------------------------------------- * * Function: OS_ConsoleCreate_Impl diff --git a/src/os/rtems/CMakeLists.txt b/src/os/rtems/CMakeLists.txt new file mode 100644 index 000000000..32ef42a9c --- /dev/null +++ b/src/os/rtems/CMakeLists.txt @@ -0,0 +1,17 @@ +###################################################################### +# +# CMAKE build recipe for RTEMS OSAL implementation +# +###################################################################### + +# This CMake script generates targets specific to the RTEMS implementation +# It defines an OBJECT target named "osal_rtems_impl" +add_library(osal_rtems_impl OBJECT + osapi.c + osfileapi.c + osfilesys.c + osloader.c + osnetwork.c + osselect.c + ostimer.c +) diff --git a/src/os/rtems/build_options.cmake b/src/os/rtems/build_options.cmake index af291eb18..83768a639 100644 --- a/src/os/rtems/build_options.cmake +++ b/src/os/rtems/build_options.cmake @@ -1,10 +1,9 @@ +########################################################################## +# +# Build options for "rtems" implementation layer +# +########################################################################## -# Some upper-level code may be gated on _RTEMS_OS_ being defined -set(OSAL_COMMON_COMPILE_DEFS "${OSAL_COMMON_COMPILE_DEFS} -D_RTEMS_OS_") - -# OSAL_LINK_LIBS determines which system-level libraries must be included in the -# link command in order to produce the final binary. These libs will be used for -# ALL targets that utilize the RTEMS OS layer. Additional target-specific libraries -# may also be specified in the BSP or the cross-compile toolchain. -SET(OSAL_LINK_LIBS rtemscpu) - +# this file is a placeholder for RTEMS-specific compile tuning +# currently no extra flags/definitions needed + diff --git a/src/os/vxworks/CMakeLists.txt b/src/os/vxworks/CMakeLists.txt new file mode 100644 index 000000000..578be6c60 --- /dev/null +++ b/src/os/vxworks/CMakeLists.txt @@ -0,0 +1,17 @@ +###################################################################### +# +# CMAKE build recipe for VxWorks OSAL implementation +# +###################################################################### + +# This CMake script generates targets specific to the VxWorks implementation +# It defines an OBJECT target named "osal_vxworks_impl" +add_library(osal_vxworks_impl OBJECT + osapi.c + osfileapi.c + osfilesys.c + osloader.c + osnetwork.c + osselect.c + ostimer.c +) \ No newline at end of file diff --git a/src/os/vxworks/build_options.cmake b/src/os/vxworks/build_options.cmake index bdcc46dae..4009d0cee 100644 --- a/src/os/vxworks/build_options.cmake +++ b/src/os/vxworks/build_options.cmake @@ -1,2 +1,9 @@ -# Set the OSAL_USE_SHARED flag to indicate this uses the shared OSAL base layer -set(OSAL_USE_SHARED TRUE) +########################################################################## +# +# Build options for "vxworks" implementation layer +# +########################################################################## + +# this file is a placeholder for VxWorks-specific compile tuning +# currently no extra flags/definitions needed + diff --git a/src/unit-test-coverage/CMakeLists.txt b/src/unit-test-coverage/CMakeLists.txt index 6579e877e..329d050bf 100644 --- a/src/unit-test-coverage/CMakeLists.txt +++ b/src/unit-test-coverage/CMakeLists.txt @@ -5,15 +5,15 @@ # To run coverage tests this must be built separately. There are several reasons # for having it this way: # - Not all targets have coverage testing implemented (yet). Only VxWorks right now. -# - It may use an entirely different toolchain than the actual target build. +# - It may use an entirely different toolchain than the actual target build. # (coverage tests run with the "real" calls stubbed out, so they can be executed # on any platform/os - case in point, the VxWorks coveraged paths can be analyzed -# by running the code on Linux using the specially-crafted inputs) -# - By definition this MUST completely rebuild OSAL to add the requisite "coverage" +# by running the code on Linux using the specially-crafted inputs) +# - By definition this MUST completely rebuild OSAL to add the requisite "coverage" # options so that the binaries include the extra instrumentation. # -# NO ARTEFACTS FROM THIS BUILD SHOULD EVER INTERMINGLE WITH THE REAL TARGET BUILD -# +# NO ARTEFACTS FROM THIS BUILD SHOULD EVER INTERMINGLE WITH THE REAL TARGET BUILD +# cmake_minimum_required(VERSION 2.6.4) project(OSALCOVERAGE C) @@ -21,36 +21,16 @@ project(OSALCOVERAGE C) # Ask to generate a "make test" target enable_testing() -add_definitions(-Wall -Werror) -add_definitions(-D_UNIT_TEST_) - -# Assume that this script lives in a subdirectory called /src/unit-test-coverage -# Get a reference to the top-level OSAL source tree and store it in OSAL_SOURCE_DIR -get_filename_component(OSAL_SOURCE_DIR "${CMAKE_SOURCE_DIR}/../.." ABSOLUTE) - - -# Cache any user-specified C flags so they will be retained in future builds -# These can be specified either through cmake command line (e.g. -DUSER_C_FLAGS=-Werror) or -# through an environment variable (e.g. OSALCOVERAGE_USER_C_FLAGS=-Werror cmake ...) -set(OSALCOVERAGE_USER_C_FLAGS "$ENV{OSALCOVERAGE_USER_C_FLAGS}" CACHE STRING "User-specified C flags for OSAL coverage test build") - # The following logic is borrowed from the real OSAL build # One difference here is that the UT BSP/framework and target OSTYPE need not "match" # The following cache variables are recognized: # OSALCOVERAGE_TARGET_OSTYPE -> the intended OSAL that runs on the actual target -# OSALCOVERAGE_HOST_BSPTYPE -> the platform/bsp that will execute the coverage tests -# -# The currently supported setup is to use the "pc-linux" BSP to execute the "vxworks6" +# +# The currently supported setup is to use the configured BSP to execute all available # code coverage analysis. Because the actual underlying OS calls are stubbed out, there -# is no dependency on the actual underlying OS. -set(OSALCOVERAGE_TARGET_OSTYPE "vxworks;shared" CACHE STRING "OSAL target(s) to build coverage tests for") -set(OSALCOVERAGE_HOST_BSPTYPE "pc-linux" CACHE STRING "OSAL unit test BSP to execute coverage tests") - -# OSALCOVERAGE_SYSTEM_OSTYPE indicates which of the BSP packages to include -# This is required and must be defined -if (NOT OSALCOVERAGE_TARGET_OSTYPE) - message(FATAL_ERROR "OSALCOVERAGE_TARGET_OSTYPE must be set to the appropriate OS") -endif (NOT OSALCOVERAGE_TARGET_OSTYPE) +# 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)") # Check that coverage has been implemented for this OSTYPE foreach(OSTYPE ${OSALCOVERAGE_TARGET_OSTYPE}) @@ -59,60 +39,12 @@ foreach(OSTYPE ${OSALCOVERAGE_TARGET_OSTYPE}) endif (NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${OSTYPE}) endforeach(OSTYPE ${OSALCOVERAGE_TARGET_OSTYPE}) -# Do NOT Include the OS-specific compiler options (those are for normal builds) -#include(src/os/${OSALCOVERAGE_TARGET_OSTYPE}/build_options.cmake OPTIONAL) message(STATUS "Coverage Test Target OS: ${OSALCOVERAGE_TARGET_OSTYPE}") -# OSALCOVERAGE_SYSTEM_BSPTYPE indicates which of the BSP packages to use to execute the tests -if (NOT OSALCOVERAGE_HOST_BSPTYPE) - message(FATAL_ERROR "OSALCOVERAGE_HOST_BSPTYPE must be set to the appropriate BSP") -endif (NOT OSALCOVERAGE_HOST_BSPTYPE) - -if (NOT IS_DIRECTORY ${OSAL_SOURCE_DIR}/src/bsp/${OSALCOVERAGE_HOST_BSPTYPE}) - message(FATAL_ERROR "${OSALCOVERAGE_HOST_BSPTYPE} is not a valid host BSP") -endif (NOT IS_DIRECTORY ${OSAL_SOURCE_DIR}/src/bsp/${OSALCOVERAGE_HOST_BSPTYPE}) - -# Include the BSP-specific (host) compiler options -include(${OSAL_SOURCE_DIR}/src/bsp/${OSALCOVERAGE_HOST_BSPTYPE}/make/build_options.cmake OPTIONAL) -message(STATUS "Coverage Test Host BSP: ${OSALCOVERAGE_HOST_BSPTYPE}") - -set(CMAKE_C_FLAGS "${OSALCOVERAGE_C_FLAGS} ${OSAL_C_FLAGS}") -message(STATUS "Coverage Test CFLAGS: ${CMAKE_C_FLAGS}") - # Utilize the shared UT assert library, along with the standard OSAL includes -include_directories(${OSAL_SOURCE_DIR}/ut_assert/inc) +include_directories(${UT_ASSERT_SOURCE_DIR}/inc) include_directories(${OSAL_SOURCE_DIR}/src/os/inc) - -# The "osconfig.h" file for coverage test should ideally be the same one that -# is used for the normal build. The path to this file can be supplied as OSAL_INCLUDEDIR -# If not supplied, the file from the UT BSP can be used, but coverage results might be -# less accurate. -if (DEFINED OSAL_INCLUDEDIR) - include_directories(${OSAL_INCLUDEDIR}) -else (DEFINED OSAL_INCLUDEDIR) - message(STATUS "No OSAL_INCLUDEDIR specified, using default config from UT BSP") - include_directories(${OSAL_SOURCE_DIR}/src/bsp/${OSALCOVERAGE_HOST_BSPTYPE}/config) -endif (DEFINED OSAL_INCLUDEDIR) - -# These include paths are not public APIs but are needed -# to get to some internal headers for private APIs include_directories(${OSAL_SOURCE_DIR}/src/os/shared) -include_directories(${OSAL_SOURCE_DIR}/src/os/portable) -include_directories(${CMAKE_SOURCE_DIR}/ut-stubs/inc) - -# The "ut_bsp" library is a simple startup BSP that can be used for unit testing -# This removes the need to use the "real" CFE PSP and also provides the necessary -# UT output functions that UT assert may rely upon to report test messages -# This is the OSAL BSP but with the _UNIT_TEST_ macro defined so it may have UT-specific features -aux_source_directory(${OSAL_SOURCE_DIR}/src/bsp/${OSALCOVERAGE_HOST_BSPTYPE}/ut-src BSPFILES) -add_library(ut_bsp STATIC ${BSPFILES}) - -# The "utassert" library is the core GSFC-provided unit test library -# It is only the generic framework and does _not_ include any of the specific stub/hook functions -# It is built as static library so it may be linked with either a "real" implementation or a stub -# library (see next targets) or some combination of those as the test cases dictate. -aux_source_directory(${OSAL_SOURCE_DIR}/ut_assert/src UT_ASSERT_FILES) -add_library(ut_assert STATIC ${UT_ASSERT_FILES}) # 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 @@ -120,12 +52,8 @@ add_library(ut_assert STATIC ${UT_ASSERT_FILES}) set(OSALCOVERAGE_STUB_LIB_LIST) add_subdirectory(ut-stubs) -# Build the stub libraries for OSAL itself. -# These are potentially needed by many tests, to handle calls -# from the module under test into OTHER parts of OSAL -aux_source_directory(${OSAL_SOURCE_DIR}/src/ut-stubs UT_OSAPI_STUB_FILES) -add_library(ut_osapi_stubs STATIC ${UT_OSAPI_STUB_FILES}) - +# 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 @@ -136,7 +64,7 @@ list(APPEND OSALCOVERAGE_STUB_LIB_LIST ut_osapi_stubs) function (add_coverage_tests SETNAME) foreach(MODNAME ${ARGN}) set (TESTCASE_SRCFILE) - foreach (SRCFILE + foreach (SRCFILE "${PROJECT_SOURCE_DIR}/portable/coveragetest-${MODNAME}.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/coveragetest-${MODNAME}.c" ) @@ -144,27 +72,34 @@ function (add_coverage_tests SETNAME) set (TESTCASE_SRCFILE "${SRCFILE}") endif (EXISTS "${SRCFILE}") endforeach() - + if (TESTCASE_SRCFILE) - set(TESTNAME "${SETNAME}-${MODNAME}") - message (STATUS "Found test case for ${TESTNAME} in ${TESTCASE_SRCFILE}") - + set(TESTNAME "coverage-${SETNAME}-${MODNAME}") + if (DEFINED MODULE_LINK_MAP_${MODNAME}) set(LINKMOD ${MODULE_LINK_MAP_${MODNAME}}) else() set(LINKMOD ${MODNAME}) endif() - - add_executable(${TESTNAME}-testrunner + + add_executable(${TESTNAME}-testrunner ${TESTCASE_SRCFILE} $) - - set_target_properties(${TESTNAME}-testrunner PROPERTIES LINK_FLAGS "${UT_C_FLAGS}") - target_link_libraries(${TESTNAME}-testrunner ${OSALCOVERAGE_STUB_LIB_LIST} ut_bsp ut_assert) + + target_link_libraries(${TESTNAME}-testrunner + ${UT_COVERAGE_LINK_FLAGS} + ${OSALCOVERAGE_STUB_LIB_LIST} + ut_assert + ) add_test(${TESTNAME} ${TESTNAME}-testrunner) + + foreach(TGT ${INSTALL_TARGET_LIST}) + install(TARGETS ${TESTNAME}-testrunner DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR}) + endforeach() + endif() endforeach(MODNAME ${ARGN}) - + endfunction(add_coverage_tests SETNAME) diff --git a/src/unit-test-coverage/posix/modules/CMakeLists.txt b/src/unit-test-coverage/posix/modules/CMakeLists.txt index c48a887bf..98fdcb0d3 100644 --- a/src/unit-test-coverage/posix/modules/CMakeLists.txt +++ b/src/unit-test-coverage/posix/modules/CMakeLists.txt @@ -17,19 +17,25 @@ # - Each sub-module is compiled to a separate "OBJECT" library # this simplifies the testrunner linking by allow only one specific # object file to be linked into each test -# - Each sub-module is wrapped to divert C library calls to the -# stub (OCS) counterpart -# - UT_C_FLAGS are enabled to include any code coverage instrumentation +# - Each sub-module is wrapped to divert C library calls to the +# stub (OCS) counterpart +# - UT_COVERAGE_COMPILE_FLAGS are enabled to include any code coverage instrumentation # the "overrides" dir contains empty versions of the C-library include files. include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/inc) include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc) +include_directories(${OSAL_SOURCE_DIR}/src/bsp/shared) +include_directories(${OSAL_SOURCE_DIR}/src/os/shared) foreach(MODULE ${MODULE_LIST}) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/ut-${MODULE}.c) - add_library(ut_${SETNAME}_${MODULE} OBJECT src/ut-${MODULE}.c) - set_target_properties(ut_${SETNAME}_${MODULE} PROPERTIES COMPILE_FLAGS "${UT_C_FLAGS}") + add_library(ut_${SETNAME}_${MODULE} OBJECT + src/ut-${MODULE}.c + ) + target_compile_options(ut_${SETNAME}_${MODULE} PRIVATE + ${UT_COVERAGE_COMPILE_FLAGS} + ) endif () endforeach() - - + + diff --git a/src/unit-test-coverage/posix/ut-stubs/src/osapi-impl-posix-stubs.c b/src/unit-test-coverage/posix/ut-stubs/src/osapi-impl-posix-stubs.c index d519a8894..f1dc87f7c 100644 --- a/src/unit-test-coverage/posix/ut-stubs/src/osapi-impl-posix-stubs.c +++ b/src/unit-test-coverage/posix/ut-stubs/src/osapi-impl-posix-stubs.c @@ -1,7 +1,6 @@ #include #include #include "utstubs.h" -#include "os-posix.h" UT_DEFAULT_STUB(OS_Posix_TimeBaseAPI_Impl_Init, (void)) UT_DEFAULT_STUB(OS_Posix_ModuleAPI_Impl_Init, (void)) diff --git a/src/unit-test-coverage/shared/modules/CMakeLists.txt b/src/unit-test-coverage/shared/modules/CMakeLists.txt index 0b35829ef..4cd649bbd 100644 --- a/src/unit-test-coverage/shared/modules/CMakeLists.txt +++ b/src/unit-test-coverage/shared/modules/CMakeLists.txt @@ -19,7 +19,7 @@ # object file to be linked into each test # - Each sub-module is wrapped to divert C library calls to the # stub (OCS) counterpart -# - UT_C_FLAGS are enabled to include any code coverage instrumentation +# - UT_COVERAGE_COMPILE_FLAGS are enabled to include any code coverage instrumentation # the "override_inc" dir contains replacement versions of the C-library include files. include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/inc) @@ -27,8 +27,12 @@ include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc) foreach(MODULE ${MODULE_LIST}) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/ut-osapi-${MODULE}.c) - add_library(ut_${SETNAME}_${MODULE} OBJECT src/ut-osapi-${MODULE}.c) - set_target_properties(ut_${SETNAME}_${MODULE} PROPERTIES COMPILE_FLAGS "${UT_C_FLAGS}") + add_library(ut_${SETNAME}_${MODULE} OBJECT + src/ut-osapi-${MODULE}.c + ) + target_compile_options(ut_${SETNAME}_${MODULE} PRIVATE + ${UT_COVERAGE_COMPILE_FLAGS} + ) endif () endforeach() diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 005fa4999..e30b38c7b 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -134,9 +134,9 @@ void Test_OS_rmfs(void) /* check error paths */ UT_SetForceFail(UT_KEY(OS_ObjectIdGetByName), OS_ERR_NAME_NOT_FOUND); - expected = OS_FS_ERROR; + expected = OS_ERR_NAME_NOT_FOUND; actual = OS_rmfs("/ramdev4"); - UtAssert_True(actual == expected, "OS_rmfs() (%ld) == OS_FS_ERROR", (long)actual); + UtAssert_True(actual == expected, "OS_rmfs() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); UT_ClearForceFail(UT_KEY(OS_ObjectIdGetByName)); expected = OS_FS_ERR_INVALID_POINTER; @@ -194,11 +194,9 @@ void Test_OS_mount(void) int32 expected; int32 actual; - /* supposed to be OS_ERR_INCORRECT_OBJ_STATE, but - * actually OS_FS_ERROR for compatibility */ - expected = OS_FS_ERROR; + expected = OS_ERR_NAME_NOT_FOUND; actual = OS_mount("/ramdev5","/ram5"); - UtAssert_True(actual == expected, "OS_mount() (%ld) == OS_FS_ERROR", (long)actual); + UtAssert_True(actual == expected, "OS_mount() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); /* mount on a fixed disk historically returns OS_SUCCESS and is a no-op. * This is for backward compatibility (it should probably an error to do this) */ @@ -236,11 +234,9 @@ void Test_OS_unmount(void) int32 expected; int32 actual; - /* supposed to be OS_ERR_INCORRECT_OBJ_STATE, but - * actually OS_FS_ERROR for compatibility */ - expected = OS_FS_ERROR; + expected = OS_ERR_NAME_NOT_FOUND; actual = OS_unmount("/ram0"); - UtAssert_True(actual == expected, "OS_mount() (%ld) == OS_FS_ERROR", (long)actual); + UtAssert_True(actual == expected, "OS_mount() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); /* unmount on a fixed disk historically returns OS_SUCCESS and is a no-op. * This is for backward compatibility (it should probably an error to do this) */ @@ -408,13 +404,13 @@ void Test_OS_FS_GetPhysDriveName(void) OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; expected = OS_SUCCESS; actual = OS_FS_GetPhysDriveName(NameBuf,"none"); - UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_FS_ERROR", (long)actual); + UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_SUCCESS", (long)actual); /* Test Fail due to no matching VolTab entry */ UT_SetForceFail(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); - expected = OS_FS_ERROR; + expected = OS_ERR_NAME_NOT_FOUND; actual = OS_FS_GetPhysDriveName(NameBuf,"none"); - UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_FS_ERROR", (long)actual); + UtAssert_True(actual == expected, "OS_FS_GetPhysDriveName() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); } diff --git a/src/unit-test-coverage/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/ut-stubs/CMakeLists.txt index 2a09002f9..aae7fbe9b 100644 --- a/src/unit-test-coverage/ut-stubs/CMakeLists.txt +++ b/src/unit-test-coverage/ut-stubs/CMakeLists.txt @@ -17,8 +17,6 @@ # any coverage test referencing on the shared/ng OSAL layer. # -include_directories(${OSAL_SOURCE_DIR}/src/ut-stubs) - # The "ut_libc_stubs" target provides stub versions of C library calls. # They are prefixed with "OCS_" and target code must be recompiled to # call the OCS_ version of the syscall instead of the regular syscall. @@ -72,6 +70,11 @@ add_library(ut_libc_stubs STATIC EXCLUDE_FROM_ALL src/vxworks-taskVarLib-stubs.c src/vxworks-xbdBlkDev-stubs.c) +target_include_directories(ut_libc_stubs PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/inc +) + + # The "ut_osapi_impl_stubs" provides stub functions for internal # OSAL calls used by or implemented by the shared layer. These # are not public API calls. This is only compiled if used. @@ -84,5 +87,9 @@ add_library(ut_osapi_impl_stubs STATIC EXCLUDE_FROM_ALL src/osapi-select-impl-stubs.c src/osapi-timer-impl-stubs.c) -list(APPEND OSALCOVERAGE_STUB_LIB_LIST ut_osapi_impl_stubs ut_libc_stubs) +list(APPEND OSALCOVERAGE_STUB_LIB_LIST + ut_osapi_impl_stubs + ut_libc_stubs +) set(OSALCOVERAGE_STUB_LIB_LIST ${OSALCOVERAGE_STUB_LIB_LIST} PARENT_SCOPE) + diff --git a/src/unit-test-coverage/vxworks/CMakeLists.txt b/src/unit-test-coverage/vxworks/CMakeLists.txt index 52b75996b..7a1041de5 100644 --- a/src/unit-test-coverage/vxworks/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/CMakeLists.txt @@ -2,9 +2,6 @@ set(MODULE_LIST osapi osfileapi osfilesys osloader osnetwork osselect ostimer posixio posixfile posixgettime printf) -# This always uses OSAL_OPAQUE_OBJECT_IDS and OSAL_ABSTRACT_FILESYS_TYPES -add_definitions(-DOSAL_OPAQUE_OBJECT_IDS -DOSAL_ABSTRACT_FILESYS_TYPES) - # This unit test is allowed to directly include any internal file in # the respective set under test. include_directories(${OSAL_SOURCE_DIR}/src/os/${SETNAME}) diff --git a/src/unit-test-coverage/vxworks/modules/CMakeLists.txt b/src/unit-test-coverage/vxworks/modules/CMakeLists.txt index 4ef5b121c..8611d9800 100644 --- a/src/unit-test-coverage/vxworks/modules/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/modules/CMakeLists.txt @@ -19,7 +19,7 @@ # object file to be linked into each test # - Each sub-module is wrapped to divert C library calls to the # stub (OCS) counterpart -# - UT_C_FLAGS are enabled to include any code coverage instrumentation +# - UT_COVERAGE_COMPILE_FLAGS are enabled to include any code coverage instrumentation # the "override_inc" dir contains replacement versions of the C-library include files. include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/inc) @@ -27,8 +27,12 @@ include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc) foreach(MODULE ${MODULE_LIST}) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/ut-${MODULE}.c) - add_library(ut_${SETNAME}_${MODULE} OBJECT src/ut-${MODULE}.c) - set_target_properties(ut_${SETNAME}_${MODULE} PROPERTIES COMPILE_FLAGS "${UT_C_FLAGS}") + add_library(ut_${SETNAME}_${MODULE} OBJECT + src/ut-${MODULE}.c + ) + target_compile_options(ut_${SETNAME}_${MODULE} PRIVATE + ${UT_COVERAGE_COMPILE_FLAGS} + ) endif () endforeach() diff --git a/src/unit-tests/CMakeLists.txt b/src/unit-tests/CMakeLists.txt index 26770023a..6cd0f641d 100644 --- a/src/unit-tests/CMakeLists.txt +++ b/src/unit-tests/CMakeLists.txt @@ -1,5 +1,5 @@ # CMake snippet for OSAL unit tests -# +# # NOTE: # This set of unit tests only includes platform support where # one of OSP_ARINC653, _LINUX_OS_ or _VXWORKS_OS_ are defined. @@ -11,19 +11,9 @@ # not necessary and other OS's like RTEMS should work. # -# For VxWorks and RTEMS targets there are still a few slight -# variances that need to be accounted for, mainly in the file -# names and/or directory structures that the test case uses. -set(UT_COMPILEDEFS_vxworks "_VXWORKS_OS_") -set(UT_COMPILEDEFS_rtems "_RTEMS_OS_") -set(UT_COMPILEDEFS_posix "_POSIX_OS_") -if (DEFINED UT_COMPILEDEFS_${OSAL_SYSTEM_OSTYPE}) - add_definitions(-D${UT_COMPILEDEFS_${OSAL_SYSTEM_OSTYPE}}) -endif() - enable_testing() -include_directories(${OSAL_SOURCE_DIR}/ut_assert/inc) +include_directories(${UTASSERT_SOURCE_DIR}/inc) include_directories(inc) add_subdirectory(oscore-test) @@ -32,4 +22,4 @@ add_subdirectory(osfilesys-test) add_subdirectory(osfile-test) add_subdirectory(osnetwork-test) add_subdirectory(ostimer-test) - + diff --git a/src/ut-stubs/CMakeLists.txt b/src/ut-stubs/CMakeLists.txt new file mode 100644 index 000000000..0482c6580 --- /dev/null +++ b/src/ut-stubs/CMakeLists.txt @@ -0,0 +1,53 @@ +###################################################################### +# +# CMAKE recipe for the OSAL stub library +# +###################################################################### + +# +# This works in conjunction with the UT Assert library to +# provide "stub" versions of all calls in the OSAL public API. +# + +# NOTE: There is no separate public include directory for the stubs. +# By definition, the stubs must implement the same public API that the +# normal OSAL library implements. Therefore, only the standard OSAL +# header files are used. +add_library(ut_osapi_stubs STATIC + utstub-helpers.c + osapi-utstub-binsem.c + osapi-utstub-clock.c + osapi-utstub-common.c + osapi-utstub-countsem.c + osapi-utstub-dir.c + osapi-utstub-errors.c + osapi-utstub-file.c + osapi-utstub-filesys.c + osapi-utstub-fpu.c + osapi-utstub-heap.c + osapi-utstub-idmap.c + osapi-utstub-interrupts.c + osapi-utstub-module.c + osapi-utstub-mutex.c + osapi-utstub-network.c + osapi-utstub-printf.c + osapi-utstub-queue.c + osapi-utstub-select.c + osapi-utstub-sockets.c + osapi-utstub-task.c + osapi-utstub-time.c + osapi-utstub-timebase.c +) + +# Some of the internal API definitions in stubs are based on +# types/definitions in the os-impl.h internal header file. +target_include_directories(ut_osapi_stubs PRIVATE + ${OSAL_SOURCE_DIR}/src/os/shared +) + +# These stubs must always link to UT Assert. +# This also implicitly adds the path to the UT Assert header files. +target_link_libraries(ut_osapi_stubs ut_assert) + + + diff --git a/ut_assert/CMakeLists.txt b/ut_assert/CMakeLists.txt new file mode 100644 index 000000000..21c94b3d2 --- /dev/null +++ b/ut_assert/CMakeLists.txt @@ -0,0 +1,45 @@ +###################################################################### +# +# CMAKE recipe for the UT assert library +# +###################################################################### + +# +# The "ut_assert" library is the core GSFC-provided unit test library +# +project(UT_ASSERT C) + +# The "ut_assert" library is usable by ANY and ALL subsystem(s) that need +# to do unit testing of any kind. This library implements an OSAL application +# that contains APIs to aid in unit testing. It provides the OS_Application_Startup +# and OS_Application_Run functions that a normal standalone OSAL application would. + +# It uses the same OSAL BSP as a normal application would use to provide the basic +# startup procedure and text message output abstractions. + +# NOTE: This library does NOT include any stub functions here, as the configuration +# of stubs vs. real implementations are specific to the unit being tested. All +# stub functions are compiled as separate libraries. + +add_library(ut_assert STATIC EXCLUDE_FROM_ALL + src/utassert.c + src/utbsp.c + src/utlist.c + src/utstubs.c + src/uttest.c + src/uttools.c +) + +target_include_directories(ut_assert PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_include_directories(ut_assert PRIVATE + "${OSAL_SOURCE_DIR}/src/bsp/shared" +) +target_compile_definitions(ut_assert PUBLIC + "_UNIT_TEST_" +) +target_link_libraries(ut_assert osal_bsp) + + + diff --git a/ut_assert/inc/utbsp.h b/ut_assert/inc/utbsp.h index 95ab9bde5..c52291fc6 100644 --- a/ut_assert/inc/utbsp.h +++ b/ut_assert/inc/utbsp.h @@ -30,7 +30,6 @@ * and the way pass/fail determinations are made. */ - #ifndef _UTBSP_H_ #define _UTBSP_H_ @@ -41,20 +40,6 @@ * Functions implemented by the UT-specific BSP **************************************************************/ -/** - * Gets the number of additional user-supplied options - * - * For instance, this would be command line parameters on platforms that have a command line. - */ -int32 UT_BSP_GetTotalOptions(void); - -/** - * Gets the text string associated with a specific user-supplied option - * - * For instance, this would be command line parameters on platforms that have a command line. - */ -const char * UT_BSP_GetOptionString(int32 OptionNum); - /* * Note - functions here are not typically directly called by UT code, they * are used by the framework to implement the common functions. @@ -94,7 +79,6 @@ void UT_BSP_StartTestSegment(uint32 SegmentNumber, const char *SegmentName); */ void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage); - /** * The BSP single test case reporting function. * @@ -111,7 +95,8 @@ void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage); * \param SegmentNum Sequence among the overall/global test Segments * \param TestDescr Sequence within the current test Segment */ -void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 SegmentSeq, uint8 MessageType, const char *SubsysName, const char *ShortDesc); +void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 SegmentSeq, uint8 MessageType, + const char *SubsysName, const char *ShortDesc); /** * The BSP overall test reporting function. @@ -137,5 +122,4 @@ void UT_BSP_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCoun */ void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters); - #endif /* _UTBSP_H_ */ diff --git a/ut_assert/src/utbsp.c b/ut_assert/src/utbsp.c new file mode 100644 index 000000000..1744af8c2 --- /dev/null +++ b/ut_assert/src/utbsp.c @@ -0,0 +1,248 @@ +/****************************************************************************** +** File: utbsp.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2015, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Unit test BSP interface functions. +** +******************************************************************************/ + +#include +#include +#include +#include + +#include "utbsp.h" +#include "uttest.h" + +#include "bsp-impl.h" + +/* +** Local Variables +*/ +typedef struct +{ + uint32 CurrVerbosity; +} BSP_UT_GlobalData_t; + +BSP_UT_GlobalData_t BSP_UT_Global; + +void UT_BSP_Setup(void) +{ + uint8 UserShift; + uint32 ArgC; + char *const *ArgV; + + memset(&BSP_UT_Global, 0, sizeof(BSP_UT_Global)); + + UserShift = UTASSERT_CASETYPE_NONE; + ArgC = OS_BSP_GetArgC(); + if (ArgC > 0) + { + ArgV = OS_BSP_GetArgV(); + while (ArgC > 0) + { + --ArgC; + + if (strcmp(ArgV[0], "-d") == 0) + { + UserShift = UTASSERT_CASETYPE_DEBUG; + } + if (strcmp(ArgV[0], "-q") == 0) + { + UserShift = UTASSERT_CASETYPE_FAILURE; + } + if (strcmp(ArgV[0], "-v") == 0 && ArgC > 0) + { + --ArgC; + UserShift = strtoul(ArgV[1], NULL, 0); + ++ArgV; + } + + ++ArgV; + } + } + + if (UserShift == UTASSERT_CASETYPE_NONE || UserShift >= UTASSERT_CASETYPE_MAX) + { + UserShift = UTASSERT_CASETYPE_PASS; + } + + BSP_UT_Global.CurrVerbosity = (2 << UserShift) - 1; + + UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "UNIT TEST"); +} + +void UT_BSP_StartTestSegment(uint32 SegmentNumber, const char *SegmentName) +{ + char ReportBuffer[128]; + + snprintf(ReportBuffer, sizeof(ReportBuffer), "%02u %s", (unsigned int)SegmentNumber, SegmentName); + UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, ReportBuffer); +} + +void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage) +{ + const char *Prefix; + char Buffer[16]; + uint32 TermModeBits = OS_BSP_CONSOLEMODE_NORMAL; + uint32 MsgEnabled = BSP_UT_Global.CurrVerbosity >> MessageType; + + if (MsgEnabled & 1) + { + switch (MessageType) + { + case UTASSERT_CASETYPE_ABORT: + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_RED; + Prefix = "ABORT"; + break; + case UTASSERT_CASETYPE_FAILURE: + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_RED; + Prefix = "FAIL"; + break; + case UTASSERT_CASETYPE_MIR: + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_RED | OS_BSP_CONSOLEMODE_GREEN; + Prefix = "MIR"; + break; + case UTASSERT_CASETYPE_TSF: + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_RED | OS_BSP_CONSOLEMODE_BLUE; + Prefix = "TSF"; + break; + case UTASSERT_CASETYPE_TTF: + Prefix = "TTF"; + break; + case UTASSERT_CASETYPE_NA: + Prefix = "N/A"; + break; + case UTASSERT_CASETYPE_BEGIN: + OS_BSP_ConsoleOutput_Impl("\n", 1); /* add a bit of extra whitespace between tests */ + Prefix = "BEGIN"; + break; + case UTASSERT_CASETYPE_END: + Prefix = "END"; + break; + case UTASSERT_CASETYPE_PASS: + TermModeBits = OS_BSP_CONSOLEMODE_HIGHLIGHT | OS_BSP_CONSOLEMODE_GREEN; + Prefix = "PASS"; + break; + case UTASSERT_CASETYPE_INFO: + Prefix = "INFO"; + break; + case UTASSERT_CASETYPE_DEBUG: + Prefix = "DEBUG"; + break; + default: + Prefix = "OTHER"; + break; + } + + if (MsgEnabled <= 1) + { + TermModeBits = OS_BSP_CONSOLEMODE_NORMAL; + } + + snprintf(Buffer, sizeof(Buffer), "[%5s]", Prefix); + + if (TermModeBits != OS_BSP_CONSOLEMODE_NORMAL) + { + OS_BSP_ConsoleSetMode_Impl(TermModeBits); + } + + OS_BSP_ConsoleOutput_Impl(Buffer, strlen(Buffer)); + + if (TermModeBits != OS_BSP_CONSOLEMODE_NORMAL) + { + OS_BSP_ConsoleSetMode_Impl(OS_BSP_CONSOLEMODE_NORMAL); + } + + OS_BSP_ConsoleOutput_Impl(" ", 1); + OS_BSP_ConsoleOutput_Impl(OutputMessage, strlen(OutputMessage)); + OS_BSP_ConsoleOutput_Impl("\n", 1); + } + + /* + * If any ABORT (major failure) message is thrown, + * then actually call abort() to stop the test and dump a core + */ + if (MessageType == UTASSERT_CASETYPE_ABORT) + { + abort(); + } +} + +void UT_BSP_DoReport(const char *File, uint32 LineNum, uint32 SegmentNum, uint32 TestSeq, uint8 MessageType, + const char *SubsysName, const char *ShortDesc) +{ + uint32 FileLen; + const char *BasePtr; + char ReportBuffer[128]; + + FileLen = strlen(File); + BasePtr = File + FileLen; + while (FileLen > 0) + { + --BasePtr; + --FileLen; + if (*BasePtr == '/' || *BasePtr == '\\') + { + ++BasePtr; + break; + } + } + + snprintf(ReportBuffer, sizeof(ReportBuffer), "%02u.%03u %s:%u - %s", (unsigned int)SegmentNum, + (unsigned int)TestSeq, BasePtr, (unsigned int)LineNum, ShortDesc); + + UT_BSP_DoText(MessageType, ReportBuffer); +} + +void UT_BSP_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCounter_t *TestCounters) +{ + char ReportBuffer[128]; + + snprintf(ReportBuffer, sizeof(ReportBuffer), + "%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-4u N/A::%-4u\n", + (unsigned int)TestCounters->TestSegmentCount, SegmentName, (unsigned int)TestCounters->TotalTestCases, + (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_PASS], + (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE], + (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_MIR], + (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_TSF], + (unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_NA]); + + UT_BSP_DoText(UTASSERT_CASETYPE_END, ReportBuffer); +} + +void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters) +{ + char Message[128]; + + /* + * Only output a "summary" if there is more than one test Segment. + * Otherwise it is a duplicate of the report already given. + */ + if (TestCounters->TestSegmentCount > 1) + { + UT_BSP_DoTestSegmentReport("SUMMARY", TestCounters); + } + + snprintf(Message, sizeof(Message), "COMPLETE: %u tests Segment(s) executed\n\n", + (unsigned int)TestCounters->TestSegmentCount); + OS_BSP_ConsoleOutput_Impl(Message, strlen(Message)); + + if (TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE] > 0) + { + OS_BSP_SetExitCode(OS_ERROR); + } + else + { + OS_BSP_SetExitCode(OS_SUCCESS); + } +}