Skip to content

Commit

Permalink
Fix #832, update coverage test to use generated stubs
Browse files Browse the repository at this point in the history
Update the coverage-specific (shared layer internal) stubs to use
generated stubs.
  • Loading branch information
jphickey committed Apr 16, 2021
1 parent 19fdecf commit a76d7ac
Show file tree
Hide file tree
Showing 63 changed files with 4,298 additions and 713 deletions.
2 changes: 2 additions & 0 deletions src/unit-test-coverage/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ set(SHARED_COVERAGE_LINK_LIST
os-shared-coverage-support
ut-adaptor-shared
ut_osapi_impl_stubs
ut_osapi_init_stubs
ut_osapi_shared_stubs
ut_osapi_table_stubs
ut_osapi_stubs
ut_libc_stubs
)
Expand Down
195 changes: 154 additions & 41 deletions src/unit-test-coverage/ut-stubs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Stub libraries for coverage testing
# ----------------------------------------

# This provides suitable "stub" implementations of every
# This provides suitable "stub" implementations of every
# function call used internally by the various OSAL modules
# for which there is not a stub already defined.
#
Expand All @@ -13,27 +13,27 @@
# i.e. memset, strcmp, etc - these should be relevant for all
# supported operating systems as they are standard C
# - Stub versions of internal "shared" OSAL implementation functions
# i.e. everything declared in the internal API. These are needed by
# i.e. everything declared in the internal API. These are needed by
# any coverage test referencing on the shared/ng OSAL layer.
#

# 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.
# This is because in some circumstances for these calls the stub actually
# needs to invoke the real version or else weird things happen.
# This is because in some circumstances for these calls the stub actually
# needs to invoke the real version or else weird things happen.
# This library includes stubs from all supported operating systems. This
# is generally OK as we do not use any actual OS system headers
#
# These files are generally organized to match whatever header file
# These files are generally organized to match whatever header file
# defines the function. For instance, POSIX defines the "mqueue.h"
# header file which in turn provides mq_open, mq_close, etc. So
# the OCS_mq_open, OCS_mq_close declarations are in overrides/mqueue.h, and
# the OCS_mq_open, OCS_mq_close declarations are in overrides/mqueue.h, and
# the respective implementation is in posix-mqueue-stubs.c.
#
# This keeps things relatively organized, and by keeping the source files
# This keeps things relatively organized, and by keeping the source files
# relatively small and targeted like this the linker should only pull in
# the OCS functions that are actually used.
# the OCS functions that are actually used.
#
add_library(ut_libc_stubs STATIC EXCLUDE_FROM_ALL
src/arpa-inet-stubs.c
Expand Down Expand Up @@ -74,57 +74,170 @@ add_library(ut_libc_stubs STATIC EXCLUDE_FROM_ALL
src/vxworks-taskLib-stubs.c
src/vxworks-taskVarLib-stubs.c
src/vxworks-xbdBlkDev-stubs.c)
target_include_directories(ut_libc_stubs PUBLIC

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.

# About the generated UT stub sources
#
# The interface between "shared" (upper) and "impl" (lower) layers presents a few
# complexities for stubs, because the os/shared/inc headers define prototypes for
# functions that are both referenced from upper and implemented in lower level, as
# well as some functions that are referenced from lower and implemented in upper.
#
# it is important _NOT_ to mix these into the same stub units, even if they are
# declared in the same header file, or else link-time errors are likely to occur.
#
# However, this is eased to some degree because of the naming conventions. All
# functions that are intended to be implemented in the lower layer have an "_Impl"
# suffix on their name.
#
# The stubs are generated in three sets
# impl-stubs : for all "Impl" routines, normally implemented in lower layer. No handlers.
# init-stubs : for all "Init" routines, normally implemented in upper layer. No handlers.
# stubs : for everything else, normally implemented in upper layer. Has handlers.
#
set(OSAL_SHARED_IMPL_HEADERS
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-binsem.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-clock.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-common.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-console.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-countsem.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-dir.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-errors.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-file.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-filesys.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-globaldefs.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-heap.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-idmap.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-module.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-mutex.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-network.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-printf.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-queue.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-select.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-shell.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-sockets.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-task.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-timebase.h
${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-time.h
)

# The following target rule contains the specific commands required
# to auto-generate the stub implementations from the headers
add_custom_target(generate_osal_coverage_stubs
COMMAND ${UT_ASSERT_SOURCE_DIR}/scripts/generate_stubs.pl
--filter=/_Impl$/
--stub-suffix=impl-stubs
--hook-suffix=impl-hooks
${CMAKE_CURRENT_SOURCE_DIR}/src
${OSAL_SHARED_IMPL_HEADERS}
COMMAND ${UT_ASSERT_SOURCE_DIR}/scripts/generate_stubs.pl
--filter=/_Init$/
--stub-suffix=init-stubs
--hook-suffix=init-hooks
${CMAKE_CURRENT_SOURCE_DIR}/src
${OSAL_SHARED_IMPL_HEADERS}
COMMAND ${UT_ASSERT_SOURCE_DIR}/scripts/generate_stubs.pl
--filter=!/_Init$|_Impl$/
${CMAKE_CURRENT_SOURCE_DIR}/src
${OSAL_SHARED_IMPL_HEADERS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM
)

# The "ut_osapi_impl_stubs" provides stub functions for the
# implementation-specific function calls that are declared under os/shared/inc
# header directory. These are the functions that all end in an "_Impl" suffix,
# and are not public API calls. This is only compiled if used.
add_library(ut_osapi_impl_stubs STATIC EXCLUDE_FROM_ALL
src/osapi-binsem-impl-stubs.c
src/osapi-common-impl-stubs.c
src/osapi-console-impl-stubs.c
src/osapi-countsem-impl-stubs.c
src/osapi-error-impl-stubs.c
src/osapi-file-impl-stubs.c
src/osapi-filesys-impl-stubs.c
src/osapi-heap-impl-stubs.c
src/osapi-idmap-impl-stubs.c
src/osapi-loader-impl-stubs.c
src/osapi-mutex-impl-stubs.c
src/osapi-network-impl-stubs.c
src/osapi-queue-impl-stubs.c
src/osapi-select-impl-stubs.c
src/osapi-shared-common-stubs.c
src/osapi-shared-debug-stubs.c
src/osapi-shared-idmap-stubs.c
src/osapi-task-impl-stubs.c
src/osapi-timer-impl-stubs.c
src/portable-console-bsp-impl-stubs.c
src/os-shared-binsem-impl-stubs.c
src/os-shared-clock-impl-stubs.c
src/os-shared-common-impl-stubs.c
src/os-shared-console-impl-stubs.c
src/os-shared-countsem-impl-stubs.c
src/os-shared-dir-impl-stubs.c
src/os-shared-file-impl-hooks.c
src/os-shared-file-impl-stubs.c
src/os-shared-filesys-impl-hooks.c
src/os-shared-filesys-impl-stubs.c
src/os-shared-heap-impl-stubs.c
src/os-shared-idmap-impl-stubs.c
src/os-shared-module-impl-stubs.c
src/os-shared-mutex-impl-stubs.c
src/os-shared-network-impl-hooks.c
src/os-shared-network-impl-stubs.c
src/os-shared-printf-impl-stubs.c
src/os-shared-queue-impl-stubs.c
src/os-shared-select-impl-stubs.c
src/os-shared-shell-impl-stubs.c
src/os-shared-sockets-impl-stubs.c
src/os-shared-task-impl-stubs.c
src/os-shared-timebase-impl-stubs.c
)

# The "ut_osapi_shared_stubs" provides stub objects for shared
# objects used by the implementation layer. These
# are not public. This is only compiled if used.
# The "ut_osapi_init_stubs" provides stub functions for the
# initialization function calls that are declared under os/shared/inc
# header directory. These are the functions that all end in an "_Init" suffix,
# and are not public API calls. This is only compiled if used.
add_library(ut_osapi_init_stubs STATIC EXCLUDE_FROM_ALL
src/os-shared-binsem-init-stubs.c
src/os-shared-common-init-stubs.c
src/os-shared-console-init-stubs.c
src/os-shared-countsem-init-stubs.c
src/os-shared-dir-init-stubs.c
src/os-shared-file-init-stubs.c
src/os-shared-filesys-init-stubs.c
src/os-shared-module-init-stubs.c
src/os-shared-mutex-init-stubs.c
src/os-shared-network-init-stubs.c
src/os-shared-queue-init-stubs.c
src/os-shared-sockets-init-stubs.c
src/os-shared-task-init-stubs.c
src/os-shared-timebase-init-stubs.c
src/os-shared-time-init-stubs.c
)

# The "ut_osapi_shared_stubs" provides stub functions for the
# all other function calls that are declared under os/shared/inc
# header directory. These are the non-public functions that do
# NOT end in either _Init or _Impl suffix, and are normally
# implemented in the shared (upper) layer.
# Unlike the others, these stubs have default handler/hook functions.
add_library(ut_osapi_shared_stubs STATIC EXCLUDE_FROM_ALL
src/osapi-shared-common-stubs.c
src/osapi-shared-idmap-stubs.c
src/os-shared-common-stubs.c
src/os-shared-file-stubs.c
src/os-shared-filesys-stubs.c
src/os-shared-globaldefs-stubs.c
src/os-shared-idmap-hooks.c
src/os-shared-idmap-stubs.c
src/os-shared-module-stubs.c
src/os-shared-sockets-stubs.c
src/os-shared-task-stubs.c
src/os-shared-timebase-stubs.c
)


# The "ut_osapi_table_stubs" provides stub objects for shared
# table objects used by the implementation layer. These
# are not public. This is only compiled if used.
add_library(ut_osapi_table_stubs STATIC EXCLUDE_FROM_ALL
src/osapi-shared-binsem-table-stubs.c
src/osapi-shared-console-table-stubs.c
src/osapi-shared-common-stubs.c
src/osapi-shared-countsem-table-stubs.c
src/osapi-shared-error-impl-table-stubs.c
src/osapi-shared-dir-table-stubs.c
src/osapi-shared-filesys-table-stubs.c
src/osapi-shared-idmap-table-stubs.c
src/osapi-shared-module-table-stubs.c
src/osapi-shared-mutex-table-stubs.c
src/osapi-shared-queue-table-stubs.c
src/osapi-shared-stream-table-stubs.c
src/osapi-shared-task-table-stubs.c
src/osapi-shared-timebase-table-stubs.c
src/osapi-shared-timecb-table-stubs.c
src/osapi-shared-debug-stubs.c
)

add_library(ut_bsp_impl_stubs STATIC EXCLUDE_FROM_ALL
Expand Down
Loading

0 comments on commit a76d7ac

Please sign in to comment.