From af7f5673d1232e68123ad9372243d23bef376eeb Mon Sep 17 00:00:00 2001 From: Max Payne Date: Fri, 23 Sep 2016 23:57:09 +0300 Subject: [PATCH 1/6] Add Unity test framework to the source tree --- .gitmodules | 3 +++ lib/unity/Unity | 1 + 2 files changed, 4 insertions(+) create mode 160000 lib/unity/Unity diff --git a/.gitmodules b/.gitmodules index 5421df71..3a625d8e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "lib/stm32-spl/SPL"] path = lib/stm32-spl/SPL url = https://github.com/forGGe/spl-hub.git +[submodule "lib/unity/Unity"] + path = lib/unity/Unity + url = https://github.com/ThrowTheSwitch/Unity.git diff --git a/lib/unity/Unity b/lib/unity/Unity new file mode 160000 index 00000000..dce6d329 --- /dev/null +++ b/lib/unity/Unity @@ -0,0 +1 @@ +Subproject commit dce6d329ffa3a7317e52b2e0b7466886815f2297 From dc39be31984156ca5b587d9329c801aa84138296 Mon Sep 17 00:00:00 2001 From: Max Payne Date: Sun, 25 Sep 2016 20:45:42 +0300 Subject: [PATCH 2/6] Integrate Unity with buildsystem --- lib/CMakeLists.txt | 2 +- lib/unity/CMakeLists.txt | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 lib/unity/CMakeLists.txt diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 41589997..61779341 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -11,4 +11,4 @@ add_subdirectory(thread) add_subdirectory(containers) add_subdirectory(cmsis) add_subdirectory(stm32-spl) - +add_subdirectory(unity) diff --git a/lib/unity/CMakeLists.txt b/lib/unity/CMakeLists.txt new file mode 100644 index 00000000..a814e24e --- /dev/null +++ b/lib/unity/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(unity + Unity/src/unity.c + Unity/extras/fixture/src/unity_fixture.c) + +target_include_directories(unity PUBLIC Unity/src/ Unity/extras/fixture/src) + +target_compile_definitions(unity PUBLIC + -DUNITY_EXCLUDE_STDLIB_MALLOC # Prevent Unity from using standart library calls. + -DUNITY_EXCLUDE_FLOAT # Float can be heavy on embedded platforms. + -DUNITY_EXCLUDE_DOUBLE # Same. + -DUNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION # Do not use flush declaration. + -DUNITY_OUTPUT_CHAR=bypass_putc # Use bypass platform driver to print output. + -DUNITY_OUTPUT_FLUSH= # Bypass driver is fully synchronius in theCore. + ) + +target_link_libraries(unity PRIVATE ${PLATFORM_NAME}) From c8a504ed47692d6c8f5e6a5a849510f4024359d3 Mon Sep 17 00:00:00 2001 From: Max Payne Date: Sun, 25 Sep 2016 22:03:04 +0300 Subject: [PATCH 3/6] Add Unity demo test case --- tests/CMakeLists.txt | 14 +++++++++ tests/cases/unity_demo/CMakeLists.txt | 15 ++++++++++ tests/cases/unity_demo/host/app_defs.cmake | 5 ++++ tests/cases/unity_demo/host/app_defs.hpp | 8 +++++ tests/cases/unity_demo/main.cpp | 29 +++++++++++++++++++ .../stm32f4disc_nonos/app_defs.cmake | 2 ++ .../unity_demo/stm32f4disc_nonos/app_defs.hpp | 8 +++++ 7 files changed, 81 insertions(+) create mode 100644 tests/cases/unity_demo/CMakeLists.txt create mode 100644 tests/cases/unity_demo/host/app_defs.cmake create mode 100644 tests/cases/unity_demo/host/app_defs.hpp create mode 100644 tests/cases/unity_demo/main.cpp create mode 100644 tests/cases/unity_demo/stm32f4disc_nonos/app_defs.cmake create mode 100644 tests/cases/unity_demo/stm32f4disc_nonos/app_defs.hpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f8b95008..ef1e9e24 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -103,3 +103,17 @@ add_functional_test(hello_world TARGET_NAME stm32f4discovery_simple CONFIG_NAME stm32f4disc_nonos ) + +#------------------------------------------------------------------------------ +# Unity test framework demo. + +add_functional_test(unity_demo + TARGET_NAME host + CONFIG_NAME host) + +add_functional_test(unity_demo + TOOLCHAIN_NAME arm-cm3-gnu.cmake + MCU_NAME stm32f407 + TARGET_NAME stm32f4discovery_simple + CONFIG_NAME stm32f4disc_nonos + ) diff --git a/tests/cases/unity_demo/CMakeLists.txt b/tests/cases/unity_demo/CMakeLists.txt new file mode 100644 index 00000000..4a96ecfa --- /dev/null +++ b/tests/cases/unity_demo/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.4) + +# Hello World basic case +project(unity_demo) + +include(${APP_CFG}/app_defs.cmake) + +add_executable(unity_demo main.cpp) +target_include_directories(unity_demo PUBLIC + ${TARGET_DIR} + ${CMAKE_CURRENT_LIST_DIR}/${APP_CFG}) + +target_link_libraries(unity_demo the_core unity) + +add_subdirectory(${CORE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/core) diff --git a/tests/cases/unity_demo/host/app_defs.cmake b/tests/cases/unity_demo/host/app_defs.cmake new file mode 100644 index 00000000..1de81b2a --- /dev/null +++ b/tests/cases/unity_demo/host/app_defs.cmake @@ -0,0 +1,5 @@ +# Enable console. +set(CONFIG_USE_CONSOLE 1) + +# Enable OS support, required to enable sleep_for() call +set(CONFIG_OS host) diff --git a/tests/cases/unity_demo/host/app_defs.hpp b/tests/cases/unity_demo/host/app_defs.hpp new file mode 100644 index 00000000..3e433deb --- /dev/null +++ b/tests/cases/unity_demo/host/app_defs.hpp @@ -0,0 +1,8 @@ +//! \file +//! \brief Unity demo test running on host platform. +//! \details Just a stub for now. +#ifndef TEST_UNITY_DEMO_HOST_APP_DEFS_HPP_ +#define TEST_UNITY_DEMO_HOST_APP_DEFS_HPP_ + + +#endif // TEST_UNITY_DEMO_HOST_APP_DEFS_HPP_ diff --git a/tests/cases/unity_demo/main.cpp b/tests/cases/unity_demo/main.cpp new file mode 100644 index 00000000..1e25ba36 --- /dev/null +++ b/tests/cases/unity_demo/main.cpp @@ -0,0 +1,29 @@ +#include +#include + +extern "C" +void board_init() +{ +} + + +TEST_GROUP(demo_group); + +TEST_SETUP(demo_group) { } + +TEST_TEAR_DOWN(demo_group) { } + +TEST(demo_group, test1) +{ + TEST_ASSERT_TRUE(0 == 1); +} + +TEST_GROUP_RUNNER(demo_group) +{ + RUN_TEST_CASE(demo_group, test1); +} + +int main() +{ + RUN_TEST_GROUP(demo_group); +} diff --git a/tests/cases/unity_demo/stm32f4disc_nonos/app_defs.cmake b/tests/cases/unity_demo/stm32f4disc_nonos/app_defs.cmake new file mode 100644 index 00000000..00cbb5d6 --- /dev/null +++ b/tests/cases/unity_demo/stm32f4disc_nonos/app_defs.cmake @@ -0,0 +1,2 @@ +# Console enabled by the target +include(${TARGET_DIR}/target_defs.cmake) diff --git a/tests/cases/unity_demo/stm32f4disc_nonos/app_defs.hpp b/tests/cases/unity_demo/stm32f4disc_nonos/app_defs.hpp new file mode 100644 index 00000000..a1b6549e --- /dev/null +++ b/tests/cases/unity_demo/stm32f4disc_nonos/app_defs.hpp @@ -0,0 +1,8 @@ +//! \file +//! \brief Application definitions for stm32f4 discovery Unity demo test (no OS) + +#ifndef TEST_UNITY_DEMO_STM32_DICS_NONOS_APP_DEFS_HPP_ +#define TEST_UNITY_DEMO_STM32_DICS_NONOS_APP_DEFS_HPP_ + + +#endif // TEST_UNITY_DEMO_STM32_DICS_NONOS_APP_DEFS_HPP_ From 81cf74768a83687d0174e8076f166f5781ae8d6c Mon Sep 17 00:00:00 2001 From: Max Payne Date: Sun, 25 Sep 2016 22:04:14 +0300 Subject: [PATCH 4/6] Specify Unity fork as dependency for theCore Minor fix is required to run Unity code from C++ sources --- .gitmodules | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 3a625d8e..f99d83bd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,4 +9,6 @@ url = https://github.com/forGGe/spl-hub.git [submodule "lib/unity/Unity"] path = lib/unity/Unity - url = https://github.com/ThrowTheSwitch/Unity.git + url = https://github.com/forGGe/Unity.git + # Base repo + # url = https://github.com/ThrowTheSwitch/Unity.git From df0550d27a6d1c80ec5d6e05d6ea914b16b8477b Mon Sep 17 00:00:00 2001 From: Max Payne Date: Sun, 25 Sep 2016 22:28:17 +0300 Subject: [PATCH 5/6] Implement stubs for Unity console interaction Fix for platforms with inlined `bypass_putc` routine --- lib/unity/CMakeLists.txt | 3 ++- lib/unity/Unity | 2 +- lib/unity/unity_stubs.cpp | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 lib/unity/unity_stubs.cpp diff --git a/lib/unity/CMakeLists.txt b/lib/unity/CMakeLists.txt index a814e24e..f2ecfa7d 100644 --- a/lib/unity/CMakeLists.txt +++ b/lib/unity/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(unity + unity_stubs.cpp Unity/src/unity.c Unity/extras/fixture/src/unity_fixture.c) @@ -9,7 +10,7 @@ target_compile_definitions(unity PUBLIC -DUNITY_EXCLUDE_FLOAT # Float can be heavy on embedded platforms. -DUNITY_EXCLUDE_DOUBLE # Same. -DUNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION # Do not use flush declaration. - -DUNITY_OUTPUT_CHAR=bypass_putc # Use bypass platform driver to print output. + -DUNITY_OUTPUT_CHAR=unity_putc # Uses bypass platform driver internally to print output. -DUNITY_OUTPUT_FLUSH= # Bypass driver is fully synchronius in theCore. ) diff --git a/lib/unity/Unity b/lib/unity/Unity index dce6d329..a8e799b0 160000 --- a/lib/unity/Unity +++ b/lib/unity/Unity @@ -1 +1 @@ -Subproject commit dce6d329ffa3a7317e52b2e0b7466886815f2297 +Subproject commit a8e799b0666f6335b664a8ff26d71236491e8759 diff --git a/lib/unity/unity_stubs.cpp b/lib/unity/unity_stubs.cpp new file mode 100644 index 00000000..1afa7115 --- /dev/null +++ b/lib/unity/unity_stubs.cpp @@ -0,0 +1,9 @@ +//! \file +//! \brief Stubs implementation for Unity functions. + +#include + +extern "C" void unity_putc(char c) +{ + ecl::bypass_putc(c); +} From 95ea4d2be8bf77ea4a73ddb647b509893422bca2 Mon Sep 17 00:00:00 2001 From: Max Payne Date: Sun, 25 Sep 2016 22:29:29 +0300 Subject: [PATCH 6/6] Bunch of style fixes for link dependencies --- dev/bus/CMakeLists.txt | 4 +--- lib/allocators/CMakeLists.txt | 2 +- lib/cpp/CMakeLists.txt | 3 +-- lib/debug/CMakeLists.txt | 6 ++---- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/dev/bus/CMakeLists.txt b/dev/bus/CMakeLists.txt index fb460a5b..2d4378d9 100644 --- a/dev/bus/CMakeLists.txt +++ b/dev/bus/CMakeLists.txt @@ -1,8 +1,6 @@ add_library(bus INTERFACE) target_include_directories(bus INTERFACE export) -target_link_libraries(bus INTERFACE dbg) -target_link_libraries(bus INTERFACE platform_common) -target_link_libraries(bus INTERFACE thread) +target_link_libraries(bus INTERFACE dbg platform_common thread) add_unit_host_test(NAME bus SOURCES tests/bus_unit.cpp diff --git a/lib/allocators/CMakeLists.txt b/lib/allocators/CMakeLists.txt index 012c8808..5a488548 100644 --- a/lib/allocators/CMakeLists.txt +++ b/lib/allocators/CMakeLists.txt @@ -1,7 +1,7 @@ add_library(allocators STATIC alloc.cpp) target_include_directories(allocators PUBLIC export) # Requires assert -target_link_libraries(allocators dbg) +target_link_libraries(allocators dbg types) # Static analysis add_cppcheck(allocators UNUSED_FUNCTIONS STYLE POSSIBLE_ERROR FORCE) # Unit tests diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt index 26033ea3..d03e42a1 100644 --- a/lib/cpp/CMakeLists.txt +++ b/lib/cpp/CMakeLists.txt @@ -14,8 +14,7 @@ else() endif() add_cppcheck(libcpp UNUSED_FUNCTIONS STYLE POSSIBLE_ERROR FORCE) -target_link_libraries(libcpp PUBLIC types) -target_link_libraries(libcpp PUBLIC bus) +target_link_libraries(libcpp PUBLIC types bus) add_unit_host_test(NAME istream_test SOURCES tests/istream_unit.cpp INC_DIRS export) diff --git a/lib/debug/CMakeLists.txt b/lib/debug/CMakeLists.txt index 8f4bd36b..ccb83bb2 100644 --- a/lib/debug/CMakeLists.txt +++ b/lib/debug/CMakeLists.txt @@ -1,5 +1,3 @@ add_library(dbg assert.cpp) -target_include_directories(dbg PUBLIC export) -target_link_libraries(dbg PRIVATE libcpp) -target_link_libraries(dbg PRIVATE ${PLATFORM_NAME}) -target_link_libraries(dbg INTERFACE types) +target_include_directories(dbg PUBLIC export types) +target_link_libraries(dbg PRIVATE libcpp ${PLATFORM_NAME})