diff --git a/CMakeLists.txt b/CMakeLists.txt index f395e78..cbce239 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,7 +155,7 @@ endif() # Import definitions of all libraries # -# add_subdirectory(lib) +add_subdirectory(lib) # # MMU firmware diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..09159f6 --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,3 @@ +if(NOT CMAKE_CROSSCOMPILING) + add_subdirectory(Catch2) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 792d600..269aea0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1 +1 @@ -# +add_subdirectory(unit) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 792d600..bc08872 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -1 +1,28 @@ -# +# first, let's create a symbolic target for all tests +add_custom_target(tests) + +# this had a reason on the Buddy FW, but on the AVR we cannot get close to having 16bit ints and +# pointers so the unit tests may be compiled 64bit afterall +set(CMAKE_C_FLAGS -m32) +set(CMAKE_CXX_FLAGS -m32) + +# include catch_discover_tests function from Catch2 +include(${Catch2_SOURCE_DIR}/contrib/Catch.cmake) + +add_library(catch_main ${CMAKE_CURRENT_SOURCE_DIR}/test_main.cpp) +target_link_libraries(catch_main Catch2::Catch2) + +# registers given target as a catch test +function(add_catch_test target) + target_link_libraries(${target} catch_main Catch2::Catch2) + catch_discover_tests(${target}) + add_dependencies(tests ${target}) +endfunction() + +add_executable(system_tests ${CMAKE_CURRENT_SOURCE_DIR}/system_test.cpp) +add_catch_test(system_tests) + +# now, include all the unit tests; they should add themselves using the add_catch_test function +add_subdirectory(hal) +add_subdirectory(logic) +add_subdirectory(modules) diff --git a/tests/unit/hal/CMakeLists.txt b/tests/unit/hal/CMakeLists.txt new file mode 100644 index 0000000..792d600 --- /dev/null +++ b/tests/unit/hal/CMakeLists.txt @@ -0,0 +1 @@ +# diff --git a/tests/unit/logic/CMakeLists.txt b/tests/unit/logic/CMakeLists.txt new file mode 100644 index 0000000..792d600 --- /dev/null +++ b/tests/unit/logic/CMakeLists.txt @@ -0,0 +1 @@ +# diff --git a/tests/unit/modules/CMakeLists.txt b/tests/unit/modules/CMakeLists.txt new file mode 100644 index 0000000..be359f4 --- /dev/null +++ b/tests/unit/modules/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(protocol) diff --git a/tests/unit/modules/protocol/CMakeLists.txt b/tests/unit/modules/protocol/CMakeLists.txt new file mode 100644 index 0000000..fbaaf53 --- /dev/null +++ b/tests/unit/modules/protocol/CMakeLists.txt @@ -0,0 +1,8 @@ +# define the test executable +add_executable(protocol_tests test_protocol.cpp) + +# define required search paths +target_include_directories(protocol_tests PUBLIC ${CMAKE_SOURCE_DIR}/src/modules) + +# tell build system about the test case +add_catch_test(protocol_tests) diff --git a/tests/unit/modules/protocol/test_protocol.cpp b/tests/unit/modules/protocol/test_protocol.cpp new file mode 100644 index 0000000..df686bd --- /dev/null +++ b/tests/unit/modules/protocol/test_protocol.cpp @@ -0,0 +1,8 @@ +#include "catch2/catch.hpp" +#include "protocol.h" + +using Catch::Matchers::Equals; + +TEST_CASE("protocol::1", "[protocol]") { + CHECK(true); +} diff --git a/tests/unit/system_test.cpp b/tests/unit/system_test.cpp new file mode 100644 index 0000000..a14875a --- /dev/null +++ b/tests/unit/system_test.cpp @@ -0,0 +1,6 @@ +#include "catch2/catch.hpp" + +TEST_CASE("type tests", "[system]") { + REQUIRE(sizeof(uint64_t) == 8); + REQUIRE(sizeof(char *) == 4); +} diff --git a/tests/unit/test_main.cpp b/tests/unit/test_main.cpp new file mode 100644 index 0000000..75a6112 --- /dev/null +++ b/tests/unit/test_main.cpp @@ -0,0 +1,3 @@ +#define CATCH_CONFIG_MAIN +//#define CATCH_CONFIG_ENABLE_BENCHMARKING +#include "catch2/catch.hpp"