[修改] 增加freeRTOS
1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
@ -0,0 +1,69 @@
|
||||
cmake_minimum_required( VERSION 3.13 )
|
||||
set( BINARY_DIR ${CMAKE_BINARY_DIR} )
|
||||
|
||||
# Reset coverage counters.
|
||||
execute_process( COMMAND lcov --directory ${CMAKE_BINARY_DIR}
|
||||
--base-directory ${CMAKE_BINARY_DIR}
|
||||
--zerocounters )
|
||||
|
||||
# Create directory for results.
|
||||
execute_process( COMMAND mkdir -p ${CMAKE_BINARY_DIR}/coverage )
|
||||
|
||||
# Generate "baseline" coverage data with zero coverage for every instrumented
|
||||
# line. This is later combined with the coverage data from test run to ensure
|
||||
# that the percentage of total lines covered is correct even when not all source
|
||||
# code files were loaded during the test.
|
||||
execute_process( COMMAND lcov --directory ${CMAKE_BINARY_DIR}
|
||||
--base-directory ${CMAKE_BINARY_DIR}
|
||||
--initial
|
||||
--capture
|
||||
--rc lcov_branch_coverage=1
|
||||
--rc genhtml_branch_coverage=1
|
||||
--output-file=${CMAKE_BINARY_DIR}/base_coverage.info )
|
||||
|
||||
# Capture all the test binaries.
|
||||
file( GLOB files "${CMAKE_BINARY_DIR}/bin/tests/*" )
|
||||
|
||||
# Create an empty report file.
|
||||
set( REPORT_FILE ${CMAKE_BINARY_DIR}/utest_report.txt )
|
||||
file( WRITE ${REPORT_FILE} "" )
|
||||
|
||||
# Execute all test binaries and capture all the output in the report file.
|
||||
foreach( testname ${files} )
|
||||
get_filename_component( test ${testname} NAME_WLE )
|
||||
message( "Running ${testname}" )
|
||||
execute_process( COMMAND ${testname} OUTPUT_FILE ${CMAKE_BINARY_DIR}/${test}_out.txt )
|
||||
|
||||
# Append the test run output to the report file.
|
||||
file( READ ${CMAKE_BINARY_DIR}/${test}_out.txt CONTENTS )
|
||||
file( APPEND ${REPORT_FILE} "${CONTENTS}" )
|
||||
endforeach()
|
||||
|
||||
# Generate Junit style xml output.
|
||||
execute_process( COMMAND ruby
|
||||
${UNITY_DIR}/auto/parse_output.rb
|
||||
-xml ${REPORT_FILE}
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} )
|
||||
|
||||
# Capture coverage data after test run.
|
||||
execute_process( COMMAND lcov --capture
|
||||
--rc lcov_branch_coverage=1
|
||||
--rc genhtml_branch_coverage=1
|
||||
--base-directory ${CMAKE_BINARY_DIR}
|
||||
--directory ${CMAKE_BINARY_DIR}
|
||||
--output-file ${CMAKE_BINARY_DIR}/second_coverage.info )
|
||||
|
||||
# Combine baseline coverage data (zeros) with the coverage data from test run.
|
||||
execute_process( COMMAND lcov --base-directory ${CMAKE_BINARY_DIR}
|
||||
--directory ${CMAKE_BINARY_DIR}
|
||||
--add-tracefile ${CMAKE_BINARY_DIR}/base_coverage.info
|
||||
--add-tracefile ${CMAKE_BINARY_DIR}/second_coverage.info
|
||||
--output-file ${CMAKE_BINARY_DIR}/coverage.info
|
||||
--no-external
|
||||
--rc lcov_branch_coverage=1 )
|
||||
|
||||
# Generate HTML Report.
|
||||
execute_process( COMMAND genhtml --rc lcov_branch_coverage=1
|
||||
--branch-coverage
|
||||
--output-directory ${CMAKE_BINARY_DIR}/coverage
|
||||
${CMAKE_BINARY_DIR}/coverage.info )
|
||||
@ -0,0 +1,64 @@
|
||||
# Function to create the test executable.
|
||||
function( create_test_binary_target test_name
|
||||
test_src
|
||||
link_list
|
||||
dep_list
|
||||
include_list )
|
||||
include ( CTest )
|
||||
get_filename_component( test_src_absolute ${test_src} ABSOLUTE )
|
||||
|
||||
# Generate test runner file.
|
||||
add_custom_command( OUTPUT ${test_name}_runner.c
|
||||
COMMAND ruby ${UNITY_DIR}/auto/generate_test_runner.rb
|
||||
${MODULE_ROOT_DIR}/tools/unity/project.yml
|
||||
${test_src_absolute}
|
||||
${test_name}_runner.c
|
||||
DEPENDS ${test_src} )
|
||||
|
||||
add_executable( ${test_name} ${test_src} ${test_name}_runner.c )
|
||||
|
||||
set_target_properties( ${test_name} PROPERTIES
|
||||
COMPILE_FLAG "-O0 -ggdb"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/tests"
|
||||
INSTALL_RPATH_USE_LINK_PATH TRUE
|
||||
LINK_FLAGS "-Wl,-rpath,${CMAKE_BINARY_DIR}/lib \
|
||||
-Wl,-rpath,${CMAKE_CURRENT_BINARY_DIR}/lib" )
|
||||
|
||||
target_include_directories( ${test_name} PUBLIC ${mocks_dir} ${include_list} )
|
||||
|
||||
target_link_directories( ${test_name} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} )
|
||||
|
||||
# Link all libraries sent through parameters.
|
||||
foreach( link IN LISTS link_list )
|
||||
target_link_libraries( ${test_name} ${link} )
|
||||
endforeach()
|
||||
|
||||
# Add dependency to all the dep_list parameter.
|
||||
foreach( dependency IN LISTS dep_list )
|
||||
add_dependencies( ${test_name} ${dependency} )
|
||||
target_link_libraries( ${test_name} ${dependency} )
|
||||
endforeach()
|
||||
|
||||
target_link_libraries( ${test_name} -lgcov unity )
|
||||
target_link_directories( ${test_name} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/lib )
|
||||
|
||||
add_test( NAME ${test_name}
|
||||
COMMAND ${CMAKE_BINARY_DIR}/bin/tests/${test_name}
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} )
|
||||
endfunction()
|
||||
|
||||
# Function to create target for library under test.
|
||||
function( create_library_target target_name
|
||||
src_file
|
||||
include_list )
|
||||
add_library( ${target_name} STATIC ${src_file} )
|
||||
target_include_directories( ${target_name} PUBLIC ${include_list} )
|
||||
|
||||
set_target_properties( ${target_name} PROPERTIES
|
||||
COMPILE_FLAGS "-Wextra -Wpedantic \
|
||||
-fprofile-arcs -ftest-coverage -fprofile-generate \
|
||||
-Wno-unused-but-set-variable"
|
||||
LINK_FLAGS "-fprofile-arcs -ftest-coverage \
|
||||
-fprofile-generate "
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib )
|
||||
endfunction()
|
||||
@ -0,0 +1,12 @@
|
||||
:unity:
|
||||
:when_no_prototypes: :warn
|
||||
:enforce_strict_ordering: TRUE
|
||||
:treat_as:
|
||||
uint8: HEX8
|
||||
uint16: HEX16
|
||||
uint32: UINT32
|
||||
int8: INT8
|
||||
bool: UINT8
|
||||
:treat_externs: :exclude
|
||||
:weak: __attribute__((weak))
|
||||
:treat_externs: :include
|
||||
Reference in New Issue
Block a user