Build and upload tool (arduino-build.sh): - Compile, upload, and monitor via arduino-cli - Device discovery with USB ID identification (--devices) - Persistent reconnecting serial monitor (--watch) - Split compile/upload workflow (--verify, --upload-only) - First-time setup wizard (--setup) - Comprehensive --help with troubleshooting and RedBoard specs Testable application architecture: - Hardware abstraction layer (lib/hal/) decouples logic from Arduino API - Google Mock HAL for unit tests (exact call verification) - Simulated HAL for system tests (GPIO state, virtual clock, I2C devices) - Example I2C temperature sensor simulator (TMP102) - Host-side test suite via CMake + Google Test (21 tests) Example sketch: - blink/ -- LED blink with button-controlled speed, wired through HAL
71 lines
2.3 KiB
CMake
71 lines
2.3 KiB
CMake
cmake_minimum_required(VERSION 3.14)
|
|
project(sparkfun_tests LANGUAGES CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Google Test (fetched automatically)
|
|
# --------------------------------------------------------------------------
|
|
include(FetchContent)
|
|
FetchContent_Declare(
|
|
googletest
|
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
|
GIT_TAG v1.14.0
|
|
)
|
|
# Prevent gtest from overriding compiler/linker options on Windows
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
FetchContent_MakeAvailable(googletest)
|
|
|
|
enable_testing()
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Include paths -- same headers used by Arduino, but compiled on host
|
|
# --------------------------------------------------------------------------
|
|
set(LIB_DIR ${CMAKE_SOURCE_DIR}/../lib)
|
|
|
|
include_directories(
|
|
${LIB_DIR}/hal # hal.h
|
|
${LIB_DIR}/app # blink_app.h
|
|
${CMAKE_SOURCE_DIR}/mocks # mock_hal.h, sim_hal.h
|
|
)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Unit tests (Google Mock)
|
|
# --------------------------------------------------------------------------
|
|
add_executable(test_blink_unit
|
|
test_blink_unit.cpp
|
|
)
|
|
target_link_libraries(test_blink_unit
|
|
GTest::gtest_main
|
|
GTest::gmock
|
|
)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# System tests (SimHal)
|
|
# --------------------------------------------------------------------------
|
|
add_executable(test_blink_system
|
|
test_blink_system.cpp
|
|
)
|
|
target_link_libraries(test_blink_system
|
|
GTest::gtest_main
|
|
)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# I2C example tests
|
|
# --------------------------------------------------------------------------
|
|
add_executable(test_i2c_example
|
|
test_i2c_example.cpp
|
|
)
|
|
target_link_libraries(test_i2c_example
|
|
GTest::gtest_main
|
|
)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Register with CTest
|
|
# --------------------------------------------------------------------------
|
|
include(GoogleTest)
|
|
gtest_discover_tests(test_blink_unit)
|
|
gtest_discover_tests(test_blink_system)
|
|
gtest_discover_tests(test_i2c_example)
|