From 259fc990167cf5ce8df50a845f3760a826ecc305 Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Fri, 20 May 2022 11:19:15 +0200 Subject: [PATCH] Modustoolbox wrapper constructors fixes --- CMakeLists.txt | 56 ++++-- cmake/CompilerSettings.cmake | 33 ++++ cmake/TestMacros.cmake | 67 +++++++ cmake/UseGoogleTestInstallation.cmake | 42 +++++ devops/xfpbuild/sonar-project.properties | 2 +- src/framework/arduino/library.json | 2 +- src/framework/arduino/library.properties | 2 +- .../modustoolbox/wrapper/tle94112-mtb.cpp | 22 ++- src/framework/raspberrypi/setup.py | 2 +- test/unit/CMakeLists.txt | 167 ++++++++++++------ test/unit/test_tle94112-motor.cpp | 10 +- test/unit/test_tle94112.cpp | 2 +- 12 files changed, 322 insertions(+), 85 deletions(-) create mode 100644 cmake/CompilerSettings.cmake create mode 100644 cmake/TestMacros.cmake create mode 100644 cmake/UseGoogleTestInstallation.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a859e48f..835647d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,38 @@ cmake_minimum_required(VERSION 3.12.4) -# Arduino Library Template +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") + set(mhbcore multi-half-bridge-corelib) project(${mhbcore} CXX C) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) -set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON) -set(CMAKE_C_OUTPUT_EXTENSION_REPLACE ON) +# set(CMAKE_CXX_STANDARD 11) +# set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON) +# set(CMAKE_C_OUTPUT_EXTENSION_REPLACE ON) + +# # Coverage Flags +# set(CMAKE_CXX_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage") +# set(CMAKE_C_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage") + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib) -# Coverage Flags -set(CMAKE_CXX_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage") -set(CMAKE_C_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage") +message( STATUS "PROJECT_NAME : ${PROJECT_NAME}" ) +message( STATUS "CMAKE_BUILD_TYPE : ${CMAKE_BUILD_TYPE}" ) +message( STATUS "CMAKE_SYSTEM_NAME : ${CMAKE_SYSTEM_NAME}" ) +message( STATUS "CMAKE_SOURCE_DIR : ${CMAKE_SOURCE_DIR}" ) + +include( CompilerSettings ) # Search for include Files include_directories( @@ -39,10 +59,18 @@ add_library(${mhbcore} ${Sources} ${Headers}) # add_subdirectory(src/framework/raspberrypi) # endif() -# Enable Testing with CTest -enable_testing() +option(SETUP_PROJECT_TESTS "Enable and setup project tests." ON) + +if(SETUP_PROJECT_TESTS) + + # Add GoogleTest + option(USE_GLOBAL_GOOGLETEST_INSTALLATION "Use available global installation of googletest." ON) + include(UseGoogleTestInstallation) + + # Enable Testing with CTest + enable_testing() + + # Add Tests Folder + add_subdirectory(test/unit) -# Add GoogleTest -add_subdirectory(googletest) -# Add Tests Folder -add_subdirectory(test/unit) \ No newline at end of file +endif() \ No newline at end of file diff --git a/cmake/CompilerSettings.cmake b/cmake/CompilerSettings.cmake new file mode 100644 index 00000000..06a93234 --- /dev/null +++ b/cmake/CompilerSettings.cmake @@ -0,0 +1,33 @@ + +set(CMAKE_CXX_STANDARD 20) + + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON) +set(CMAKE_C_OUTPUT_EXTENSION_REPLACE ON) + + +set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +#set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${GNUCXX_LIB_PATH}) + + +message(STATUS "CMAKE_INSTALL_RPATH : ${CMAKE_INSTALL_RPATH}") + + +# settings per configuration +set(COMPILER_CXX_FLAGS "${COREDEV_BUILD_MODEL_FLAG} -pedantic -Wall -Wno-long-long -Wno-variadic-macros") +set(COMPILER_CXX_FLAGS_DEBUG "-g -O0 -fprofile-arcs -ftest-coverage") +set(COMPILER_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") + +set(CMAKE_CXX_FLAGS "${COMPILER_CXX_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS "${COMPILER_CXX_FLAGS_RELEASE}") + +set(CMAKE_CXX_FLAGS_DEBUG "${COMPILER_CXX_FLAGS_DEBUG}") +set(CMAKE_C_FLAGS_DEBUG "${COMPILER_CXX_FLAGS_DEBUG}") + +message(STATUS "CMAKE_C_FLAGS_DEBUG : ${CMAKE_C_FLAGS_DEBUG}") + +set(CMAKE_CXX_FLAGS_RELEASE "${COMPILER_CXX_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS_RELEASE "${COMPILER_CXX_FLAGS_RELEASE}") + diff --git a/cmake/TestMacros.cmake b/cmake/TestMacros.cmake new file mode 100644 index 00000000..8f74fdd9 --- /dev/null +++ b/cmake/TestMacros.cmake @@ -0,0 +1,67 @@ + +MACRO( createSimpleTests ) + +set( TestList "" ) +set( LibraryList "" ) +set( SourceList "" ) +set( LabelList "" ) +set( CurrentVar "" ) + +FOREACH( arg ${ARGN} ) + + IF( ${arg} STREQUAL "LIBRARIES" ) + set( CurrentVar "LibraryList" ) + ELSEIF( ${arg} STREQUAL "LABELS" ) + set( CurrentVar "LabelList" ) + ELSEIF( ${arg} STREQUAL "TESTS" ) + set( CurrentVar "TestList" ) + ELSEIF( ${arg} STREQUAL "SOURCES" ) + set( CurrentVar "SourceList" ) + ELSE( ${arg} STREQUAL "LIBRARIES" ) + set( ${CurrentVar} ${${CurrentVar}} ${arg} ) + ENDIF( ${arg} STREQUAL "LIBRARIES" ) + +ENDFOREACH( arg ${ARGN} ) + + +string( TOUPPER ${CMAKE_BUILD_TYPE} MY_LOCAL_BUILD_TYPE ) + + +IF( ${MY_LOCAL_BUILD_TYPE} STREQUAL "DEBUG" ) + + message( STATUS "#############################" ) + message( STATUS "ARGN = ${ARGN}" ) + message( STATUS "TestList = ${TestList}" ) + message( STATUS "LibraryList = ${LibraryList}" ) + message( STATUS "SourceList = ${SourceList}" ) + message( STATUS "LabelList = ${LabelList}" ) + message( STATUS "#############################" ) + +ENDIF( ${MY_LOCAL_BUILD_TYPE} STREQUAL "DEBUG" ) + + +FOREACH( TestName ${TestList} ) + + IF( ${MY_LOCAL_BUILD_TYPE} STREQUAL "DEBUG" ) + + message( STATUS "###" ) + message( STATUS "Testname = ${TestName}" ) + message( STATUS "###" ) + + ENDIF( ${MY_LOCAL_BUILD_TYPE} STREQUAL "DEBUG" ) + + + add_executable( ${TestName} ${TestName} ${SourceList} ) + target_link_libraries( ${TestName} PUBLIC ${LibraryList} ) + + + add_test( NAME ${TestName} + COMMAND ${TestName} ) + + set_tests_properties( ${TestName} + PROPERTIES + LABELS "${LabelList}") + +ENDFOREACH( TestName ${TestList} ) + +ENDMACRO( createSimpleTests ) diff --git a/cmake/UseGoogleTestInstallation.cmake b/cmake/UseGoogleTestInstallation.cmake new file mode 100644 index 00000000..be0ab4f1 --- /dev/null +++ b/cmake/UseGoogleTestInstallation.cmake @@ -0,0 +1,42 @@ + + +set( GOOGLETEST_LIBRARIES gmock gmock_main gtest gtest_main ) +set( GOOGLETEST_LINK_LIBRARIES ${GOOGLETEST_LIBRARIES} pthread ) + + +if( USE_GLOBAL_GOOGLETEST_INSTALLATION ) + + if( NOT GOOGLETEST_PATH ) + + set( GOOGLETEST_PATH "${CMAKE_SOURCE_DIR}/googletest" ) + message(STATUS "GOOGLETEST_PATH not set, setting it to ${GOOGLETEST_PATH} !") + + endif( NOT GOOGLETEST_PATH ) + + set( GOOGLETEST_INCLUDE_PATH "${GOOGLETEST_PATH}/googlemock/include" "${GOOGLETEST_PATH}/googletest/include" ) + set( GOOGLETEST_LIBRARY_PATH "${GOOGLETEST_PATH}/build/lib" ) + + include_directories( ${GOOGLETEST_INCLUDE_PATH} ) + link_directories( ${GOOGLETEST_LIBRARY_PATH} ) + + + foreach(LIBNAME ${GOOGLETEST_LIBRARIES}) + + add_library( ${LIBNAME} STATIC IMPORTED ) + + set_target_properties( ${LIBNAME} + PROPERTIES + IMPORTED_LOCATION "${GOOGLETEST_LIBRARY_PATH}/lib${LIBNAME}.a" + IMPORTED_LOCATION_RELEASE "${GOOGLETEST_LIBRARY_PATH}/lib${LIBNAME}.a" + IMPORTED_LOCATION_DEBUG "${GOOGLETEST_LIBRARY_PATH}/lib${LIBNAME}.a" + IMPORTED_CONFIGURATIONS "RELEASE;DEBUG" ) + + endforeach(LIBNAME ${GOOGLETEST_LIBRARIES}) + + +else( USE_GLOBAL_GOOGLETEST_INSTALLATION ) + + add_subdirectory( ${CMAKE_SOURCE_DIR}/googletest ) + +endif( USE_GLOBAL_GOOGLETEST_INSTALLATION ) + diff --git a/devops/xfpbuild/sonar-project.properties b/devops/xfpbuild/sonar-project.properties index b1471b23..00d7950c 100644 --- a/devops/xfpbuild/sonar-project.properties +++ b/devops/xfpbuild/sonar-project.properties @@ -6,7 +6,7 @@ sonar.projectKey=XFP_Build_multi-half-bridge sonar.projectName=XFP_Build_multi-half-bridge -sonar.projectVersion=5.0.0 +sonar.projectVersion=5.0.1 sonar.verbose=true sonar.sourceEncoding=UTF-8 diff --git a/src/framework/arduino/library.json b/src/framework/arduino/library.json index fbfe160c..bbb6c415 100644 --- a/src/framework/arduino/library.json +++ b/src/framework/arduino/library.json @@ -12,7 +12,7 @@ "url":"https://www.infineon.com/cms/en/product/power/motor-control-ics/brushed-dc-motor-driver-ics/multi-half-bridge-ics/", "maintainer": true }, - "version":"5.0.0", + "version":"5.0.1", "license":"MIT", "frameworks":"arduino", "platforms":[ diff --git a/src/framework/arduino/library.properties b/src/framework/arduino/library.properties index 0253514d..d33960b4 100644 --- a/src/framework/arduino/library.properties +++ b/src/framework/arduino/library.properties @@ -1,5 +1,5 @@ name=multi-half-bridge -version=5.0.0 +version=5.0.1 author=Infineon Technologies maintainer=Infineon Technologies sentence=Library of Infineon Multi Half-Bridge IC controllers family diff --git a/src/framework/modustoolbox/wrapper/tle94112-mtb.cpp b/src/framework/modustoolbox/wrapper/tle94112-mtb.cpp index c803a00c..a7de6263 100644 --- a/src/framework/modustoolbox/wrapper/tle94112-mtb.cpp +++ b/src/framework/modustoolbox/wrapper/tle94112-mtb.cpp @@ -21,12 +21,12 @@ * @param sckPin system clock pin for the SPIC */ Tle94112Mtb::Tle94112Mtb(cyhal_gpio_t csPin, cyhal_gpio_t misoPin, cyhal_gpio_t mosiPin, cyhal_gpio_t sckPin) -:Tle94112(new SPICMtb(SPICMtb::unusedPin, misoPin, mosiPin, sckPin), - new GPIOMtb(csPin, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, GPIOMtb::POSITIVE), - new GPIOMtb(TLE94112_PIN_EN, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, GPIOMtb::POSITIVE), - new TimerMtb()) +:Tle94112() { - + Tle94112::en = new GPIOMtb(TLE94112_PIN_EN, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, GPIOMtb::POSITIVE); + Tle94112::cs = new GPIOMtb(csPin, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, GPIOMtb::POSITIVE); + Tle94112::timer = new TimerMtb(); + Tle94112::sBus = new SPICMtb(SPICMtb::unusedPin, misoPin, mosiPin, sckPin); } /** @@ -37,8 +37,12 @@ Tle94112Mtb::Tle94112Mtb(cyhal_gpio_t csPin, cyhal_gpio_t misoPin, cyhal_gpio_t * */ Tle94112Mtb::Tle94112Mtb(void) +:Tle94112() { - Tle94112Mtb(TLE94112_PIN_CS1, KIT_SPI_MASTER_MISO, KIT_SPI_MASTER_MOSI, KIT_SPI_MASTER_SCLK); + Tle94112::en = new GPIOMtb(TLE94112_PIN_EN, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, GPIOMtb::POSITIVE ); + Tle94112::cs = new GPIOMtb(TLE94112_PIN_CS1, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, GPIOMtb::POSITIVE ); + Tle94112::timer = new TimerMtb(); + Tle94112::sBus = new SPICMtb(SPICMtb::unusedPin,KIT_SPI_MASTER_MISO,KIT_SPI_MASTER_MOSI,KIT_SPI_MASTER_SCLK); } /** @@ -50,6 +54,10 @@ Tle94112Mtb::Tle94112Mtb(void) * @param csPin chipselect pin for the wrapping GPIO */ Tle94112Mtb::Tle94112Mtb(cyhal_gpio_t csPin) +:Tle94112() { - Tle94112Mtb(csPin, KIT_SPI_MASTER_MISO, KIT_SPI_MASTER_MOSI, KIT_SPI_MASTER_SCLK); + Tle94112::en = new GPIOMtb(TLE94112_PIN_EN, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, GPIOMtb::POSITIVE ); + Tle94112::cs = new GPIOMtb(csPin, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, GPIOMtb::POSITIVE ); + Tle94112::timer = new TimerMtb(); + Tle94112::sBus = new SPICMtb(SPICMtb::unusedPin,KIT_SPI_MASTER_MISO,KIT_SPI_MASTER_MOSI,KIT_SPI_MASTER_SCLK); } diff --git a/src/framework/raspberrypi/setup.py b/src/framework/raspberrypi/setup.py index ee904c9a..795d312d 100644 --- a/src/framework/raspberrypi/setup.py +++ b/src/framework/raspberrypi/setup.py @@ -103,7 +103,7 @@ def build_extension(self, ext): # logic and declaration, and simpler if you include description/version in a file. setup( name="multi-half-bridge", - version="5.0.0", + version="5.0.1", author="Infineon Technologies", description="Python Library for Infineon's multi half-bridge IC drivers", long_description="Python library for Infineons multi half-bridge IC drivers", diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 54fc9247..26f7c56f 100755 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -1,55 +1,112 @@ -cmake_minimum_required(VERSION 3.12.4) - -set(prjtest unit-test) - -file(GLOB Sources CONFIGURE_DEPENDS "*.cpp") - -# GCOV Coverage Targets -set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON) -set(GCOV_FILES_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/${mhbcore}.dir/src) - -# Binary and Output Coverage Files -file(GLOB_RECURSE GCOV_GNNO_GCDA_FILES ${CMAKE_BINARY_DIR}/*.gc??) - -# Coverage Target -add_custom_target(gcov - COMMAND ${CMAKE_COMMAND} -E make_directory coverage - COMMAND ${CMAKE_MAKE_PROGRAM} test - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - ) - -# Coverage Command -add_custom_command(TARGET gcov - COMMAND ${CMAKE_COMMAND} -E echo "=================== GCOVR ====================" - COMMAND ${CMAKE_COMMAND} -E echo ${CMAKE_SOURCE_DIR} - COMMAND ${CMAKE_COMMAND} -E echo ${GCOV_FILES_DIR} - - COMMAND gcovr -r ${CMAKE_SOURCE_DIR} ${GCOV_FILES_DIR}/corelib -b -k --gcov-ignore-parse-errors --sonarqube -o ${CMAKE_BINARY_DIR}/coverage/coverage.xml - COMMAND ${CMAKE_COMMAND} -E echo "-- Coverage files have been output to ${CMAKE_BINARY_DIR}/coverage" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/coverage - ) - -# Coverage Clean -add_custom_target(gcov_clean - COMMAND ${CMAKE_COMMAND} -E remove -f ${GCOV_GNNO_GCDA_FILES} - COMMAND ${CMAKE_COMMAND} -E remove_directory coverage - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} -) - -add_dependencies(gcov ${prjtest}) - -# Executable -add_executable(${prjtest} ${Sources}) #${Headers}) - -# Required Libraries -target_link_libraries(${prjtest} PUBLIC - gtest_main - gmock_main - multi-half-bridge-corelib -) - -# Add Ctest -add_test( - NAME ${prjtest} - COMMAND ${prjtest} -) \ No newline at end of file +# cmake_minimum_required(VERSION 3.12.4) + +# set(prjtest unit-test) + +# file(GLOB Sources CONFIGURE_DEPENDS "*.cpp") + +# # GCOV Coverage Targets +# set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON) +# set(GCOV_FILES_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/${mhbcore}.dir/src) + +# # Binary and Output Coverage Files +# file(GLOB_RECURSE GCOV_GNNO_GCDA_FILES ${CMAKE_BINARY_DIR}/*.gc??) + +# # Coverage Target +# add_custom_target(gcovr +# COMMAND ${CMAKE_COMMAND} -E make_directory coverage +# COMMAND ${CMAKE_MAKE_PROGRAM} test +# WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +# ) + +# # Coverage Command +# add_custom_command(TARGET gcovr +# COMMAND ${CMAKE_COMMAND} -E echo "=================== GCOVR ====================" +# COMMAND ${CMAKE_COMMAND} -E echo ${CMAKE_SOURCE_DIR} +# COMMAND ${CMAKE_COMMAND} -E echo ${GCOV_FILES_DIR} + +# COMMAND gcovr -r ${CMAKE_SOURCE_DIR} ${GCOV_FILES_DIR}/corelib -b -k --gcov-ignore-parse-errors --sonarqube -o ${CMAKE_BINARY_DIR}/coverage/coverage.xml +# COMMAND ${CMAKE_COMMAND} -E echo "-- Coverage files have been output to ${CMAKE_BINARY_DIR}/coverage" +# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/coverage +# ) + +# # Coverage Clean +# add_custom_target(gcovr_clean +# COMMAND ${CMAKE_COMMAND} -E remove -f ${GCOV_GNNO_GCDA_FILES} +# COMMAND ${CMAKE_COMMAND} -E remove_directory coverage +# WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +# ) + +# add_dependencies(gcovr ${prjtest}) + +# include_directories(/usr/local/include) +# link_directories(/usr/local/lib /usr/lib64) + +# # Executable +# add_executable(${prjtest} ${Sources}) #${Headers}) + +# # Required Libraries +# target_include_directories(${prjtest} PUBLIC /usr/local/lib /usr/lib64) +# target_link_directories(${prjtest} PUBLIC /usr/local/include ${CMAKE_SOURCE_DIR}/build/lib) + +# target_link_libraries(${prjtest} PUBLIC +# ${GOOGLETEST_LIBRARIES} +# ${GOOGLETEST_LINK_LIBRARIES} +# stdc++ +# multi-half-bridge-corelib +# ) + +# # Add Ctest +# add_test( +# NAME ${prjtest} +# COMMAND ${prjtest} +# ) + +# set_tests_properties(${prjtest} +# PROPERTIES +# LABELS "coverage") + +include( TestMacros ) + +set( TEST_LIBRARIES ${GOOGLETEST_LINK_LIBRARIES} ${GOOGLETEST_LINK_LIBRARIES} multi-half-bridge-corelib ) +set( TEST_CPP_LIBRARIES ${TEST_LIBRARIES} stdc++ ) +set( TEST_C_LIBRARIES ${TEST_LIBRARIES} ) + + +include_directories( ${CMAKE_SOURCE_DIR}/src/pal /usr/local/include ) +link_directories( ${CMAKE_SOURCE_DIR}/build/lib /usr/local/lib ) + + +################################################################################################### + +set( GCOV_FILES_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/${mhbcore}.dir/src ) + +add_custom_target( gcovr + COMMAND ${CMAKE_COMMAND} -E remove_directory coverage + COMMAND ${CMAKE_COMMAND} -E make_directory coverage + COMMAND ${CMAKE_MAKE_PROGRAM} test + COMMAND ${CMAKE_COMMAND} -E echo "=================== GCOVR ====================" + COMMAND gcovr -r ${CMAKE_SOURCE_DIR} ${GCOV_FILES_DIR} -b -k --gcov-ignore-parse-errors --html --html-details + -o ${CMAKE_BINARY_DIR}/coverage/coverage.html --sonarqube ${CMAKE_BINARY_DIR}/coverage/coverage.xml + COMMAND ${CMAKE_COMMAND} -E echo "-- Coverage files have been output to ${CMAKE_BINARY_DIR}/coverage" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) + +################################################################################################### + +# unit tests : individual functions +include_directories( ${CMAKE_SOURCE_DIR}/test/unit ) + +################################################################################################### +set( UNIT_TEST_CPP_LABELS "CPP;unit;coverage" ) +set( UNIT_TEST_C_LABELS "C;unit;coverage" ) + +set( UNIT_TEST_CPP_LIBRARIES ${TEST_CPP_LIBRARIES} ) +set( UNIT_TEST_C_LIBRARIES ${TEST_C_LIBRARIES} ) + +set ( TestNames "" ) +set ( TestSources "" ) + +list(APPEND TestNames test_tle94112-motor.cpp test_tle94112.cpp) + +createSimpleTests( TESTS ${TestNames} LIBRARIES ${UNIT_TEST_CPP_LIBRARIES} LABELS ${UNIT_TEST_CPP_LABELS} SOURCES ${TestSources} ) + +add_dependencies(gcovr ${TestNames} ) \ No newline at end of file diff --git a/test/unit/test_tle94112-motor.cpp b/test/unit/test_tle94112-motor.cpp index 40b27ecd..05c9b9de 100755 --- a/test/unit/test_tle94112-motor.cpp +++ b/test/unit/test_tle94112-motor.cpp @@ -387,7 +387,7 @@ TEST_F(Tle94112Motor_Test, start_NoHighSideConenctorSuccess) /** * stop() tests */ -TEST_F(Tle94112Motor_Test, stop_NoHighSideConenctorSuccess) +TEST_F(Tle94112Motor_Test, stop_NoHighSideConnectorSuccess) { Tle94112 mhb(&sbus, &cs, &en, &timer); Tle94112Motor motor(mhb); @@ -397,13 +397,13 @@ TEST_F(Tle94112Motor_Test, stop_NoHighSideConenctorSuccess) motor.stop(127); } -TEST_F(Tle94112Motor_Test, stop_HighSideConenctorSuccess) +TEST_F(Tle94112Motor_Test, stop_HighSideConnectorSuccess) { Tle94112 mhb(&sbus, &cs, &en, &timer); Tle94112Motor motor(mhb); - /* No test, just pretty coverage */ - motor.initConnector(motor.HIGHSIDE, mhb.TLE_NOPWM, mhb.TLE_HB1, mhb.TLE_HB2, mhb.TLE_NOHB, mhb.TLE_NOHB); +// /* No test, just pretty coverage */ +// motor.initConnector(motor.HIGHSIDE, mhb.TLE_NOPWM, mhb.TLE_HB1, mhb.TLE_HB2, mhb.TLE_NOHB, mhb.TLE_NOHB); motor.begin(); motor.stop(127); } @@ -414,6 +414,7 @@ TEST_F(Tle94112Motor_Test, stop_NotmEnabled) Tle94112Motor motor(mhb); /* No test, just pretty coverage */ + motor.begin(); motor.stop(127); } @@ -461,6 +462,7 @@ TEST_F(Tle94112Motor_Test, rampSpeed_NotmEnabled) Tle94112Motor motor(mhb); /* No test, just pretty coverage */ + motor.begin(); motor.rampSpeed(127, 5000); } diff --git a/test/unit/test_tle94112.cpp b/test/unit/test_tle94112.cpp index 33197aa9..a2391c5a 100755 --- a/test/unit/test_tle94112.cpp +++ b/test/unit/test_tle94112.cpp @@ -159,7 +159,7 @@ TEST_F(Tle94112_Test, configHB_Success) Tle94112::HalfBridge hb = Tle94112::TLE_HB1; Tle94112::HBState hbState = Tle94112::TLE_LOW; Tle94112::PWMChannel pwmChan = Tle94112::TLE_PWM1; - uint8_t activeFW = 1; + // uint8_t activeFW = 1; /* No test, just pretty coverage */ mhb.configHB(hb, hbState, pwmChan);