Skip to content
This repository has been archived by the owner on Dec 6, 2018. It is now read-only.

Unity integration #142

Merged
merged 6 commits into from
Sep 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
[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/forGGe/Unity.git
# Base repo
# url = https://github.com/ThrowTheSwitch/Unity.git
4 changes: 1 addition & 3 deletions dev/bus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ add_subdirectory(thread)
add_subdirectory(containers)
add_subdirectory(cmsis)
add_subdirectory(stm32-spl)

add_subdirectory(unity)
2 changes: 1 addition & 1 deletion lib/allocators/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions lib/debug/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
17 changes: 17 additions & 0 deletions lib/unity/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
add_library(unity
unity_stubs.cpp
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=unity_putc # Uses bypass platform driver internally to print output.
-DUNITY_OUTPUT_FLUSH= # Bypass driver is fully synchronius in theCore.
)

target_link_libraries(unity PRIVATE ${PLATFORM_NAME})
1 change: 1 addition & 0 deletions lib/unity/Unity
Submodule Unity added at a8e799
9 changes: 9 additions & 0 deletions lib/unity/unity_stubs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! \file
//! \brief Stubs implementation for Unity functions.

#include <platform/console.hpp>

extern "C" void unity_putc(char c)
{
ecl::bypass_putc(c);
}
14 changes: 14 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
15 changes: 15 additions & 0 deletions tests/cases/unity_demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions tests/cases/unity_demo/host/app_defs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Enable console.
set(CONFIG_USE_CONSOLE 1)

# Enable OS support, required to enable sleep_for() call
set(CONFIG_OS host)
8 changes: 8 additions & 0 deletions tests/cases/unity_demo/host/app_defs.hpp
Original file line number Diff line number Diff line change
@@ -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_
29 changes: 29 additions & 0 deletions tests/cases/unity_demo/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <unity.h>
#include <unity_fixture.h>

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);
}
2 changes: 2 additions & 0 deletions tests/cases/unity_demo/stm32f4disc_nonos/app_defs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Console enabled by the target
include(${TARGET_DIR}/target_defs.cmake)
8 changes: 8 additions & 0 deletions tests/cases/unity_demo/stm32f4disc_nonos/app_defs.hpp
Original file line number Diff line number Diff line change
@@ -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_