diff --git a/.gitea/workflows/unit-tests-host.yaml b/.gitea/workflows/unit-tests-host.yaml new file mode 100644 index 0000000..26357e5 --- /dev/null +++ b/.gitea/workflows/unit-tests-host.yaml @@ -0,0 +1,22 @@ +name: Run unit tests on host +on: + push: + +jobs: + Run-Unit-Tests: + runs-on: ubuntu-22.04-full + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Build and test + run: | + cmake software -B build + cmake --build build + ctest --test-dir build + - name: Upload test report + uses: actions/upload-artifact@v3 + with: + name: junit-xml + path: build/junit.xml + # Use always() to always run this step to publish test results when there are test failures + if: ${{ always() }} diff --git a/software/CMakeLists.txt b/software/CMakeLists.txt index 703612a..1e23f9b 100644 --- a/software/CMakeLists.txt +++ b/software/CMakeLists.txt @@ -1,12 +1,60 @@ -cmake_minimum_required(VERSION 3.14) +# SPDX-License-Identifier: MIT +# Copyright (c) 2024 Matthias Blankertz -project(tonberry-pico) +cmake_minimum_required(VERSION 3.29) +project(tonberry-pico LANGUAGES C) + +include(FetchContent) +FetchContent_Declare(unity + GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git + GIT_TAG v2.6.0 +) +FetchContent_MakeAvailable(unity) +include(CTest) +function(make_unity_test ) + set(options "") + set(oneValueArgs NAME TEST_SOURCE) + set(multiValueArgs SOURCES INCLUDES) + cmake_parse_arguments(PARSE_ARGV 0 MAKE_UNITY_TEST + "${options}" "${oneValueArgs}" "${multiValueArgs}" + ) + + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MAKE_UNITY_TEST_NAME}_runner.c + COMMAND ${unity_SOURCE_DIR}/auto/generate_test_runner.rb ${MAKE_UNITY_TEST_TEST_SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/${MAKE_UNITY_TEST_NAME}_runner.c + DEPENDS ${MAKE_UNITY_TEST_TEST_SOURCE} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + add_executable(${MAKE_UNITY_TEST_NAME} + ${MAKE_UNITY_TEST_TEST_SOURCE} + ${MAKE_UNITY_TEST_SOURCES} + ${CMAKE_CURRENT_BINARY_DIR}/${MAKE_UNITY_TEST_NAME}_runner.c + ) + target_link_libraries(${MAKE_UNITY_TEST_NAME} PUBLIC unity::framework) + target_include_directories(${MAKE_UNITY_TEST_NAME} + PRIVATE ${MAKE_UNITY_TEST_INCLUDES}) + + add_test(NAME ${MAKE_UNITY_TEST_NAME} + COMMAND sh -c "$ > ${PROJECT_BINARY_DIR}/reports/${MAKE_UNITY_TEST_NAME}.testresults" + ) + set_tests_properties(${MAKE_UNITY_TEST_NAME} PROPERTIES FIXTURES_REQUIRED Report) +endfunction() + +add_test(NAME clean-reports + COMMAND sh -c "rm -rf ${PROJECT_BINARY_DIR}/reports; mkdir ${PROJECT_BINARY_DIR}/reports" +) +add_test(NAME generate-xml-report + COMMAND ${unity_SOURCE_DIR}/auto/stylize_as_junit.rb -r ${PROJECT_BINARY_DIR}/reports/ -o junit.xml +) +set_tests_properties(clean-reports PROPERTIES FIXTURES_SETUP "Report") +set_tests_properties(generate-xml-report PROPERTIES FIXTURES_CLEANUP "Report") + +add_subdirectory(src/audiocore) add_custom_target(check-format find . -iname '*.[ch]' -exec clang-format -Werror --dry-run {} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src ) - add_custom_target(clang-format find . -iname '*.[ch]' -exec clang-format -i {} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src diff --git a/software/src/audiocore/CMakeLists.txt b/software/src/audiocore/CMakeLists.txt new file mode 100644 index 0000000..508a913 --- /dev/null +++ b/software/src/audiocore/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +# Copyright (c) 2024 Matthias Blankertz + +make_unity_test(NAME test_audiocore + TEST_SOURCE test/test_audiocore.c + SOURCES audiocore.c + INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../test/include" "${CMAKE_CURRENT_SOURCE_DIR}" +) diff --git a/software/src/audiocore/audiocore.h b/software/src/audiocore/audiocore.h index 6ff31f3..7079e53 100644 --- a/software/src/audiocore/audiocore.h +++ b/software/src/audiocore/audiocore.h @@ -5,6 +5,7 @@ #include +#include #include /* Access rules diff --git a/software/src/audiocore/test/test_audiocore.c b/software/src/audiocore/test/test_audiocore.c new file mode 100644 index 0000000..e80eafe --- /dev/null +++ b/software/src/audiocore/test/test_audiocore.c @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2024 Matthias Blankertz + +#include "audiocore.h" +#include "i2s.h" + +#include "unity.h" + +struct audiocore_shared_context shared_context; + +bool i2s_init(int out_pin, int sideset_base, int samplerate) {} + +void i2s_deinit(void) {} + +void multicore_fifo_push_blocking(unsigned val) {} + +unsigned multicore_fifo_pop_blocking(void) {} + +void test_something(void) { TEST_ASSERT_TRUE(1); } diff --git a/software/src/test/include/hardware/sync.h b/software/src/test/include/hardware/sync.h new file mode 100644 index 0000000..b8228c1 --- /dev/null +++ b/software/src/test/include/hardware/sync.h @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2024 Matthias Blankertz + +#pragma once + +struct spin_lock; +typedef struct spin_lock spin_lock_t; + +void multicore_fifo_push_blocking(unsigned val); +unsigned multicore_fifo_pop_blocking(void); diff --git a/software/src/test/include/py/mperrno.h b/software/src/test/include/py/mperrno.h new file mode 100644 index 0000000..60a4e6d --- /dev/null +++ b/software/src/test/include/py/mperrno.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +#define MP_EIO EIO