Skip to content

CI Add unit test workflow #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 9, 2025
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
58 changes: 58 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Unit Tests

on:
pull_request:
paths:
- ".github/workflows/unit-tests.yml"
- 'extras/test/**'
- 'src/**'

push:
paths:
- ".github/workflows/unit-tests.yml"
- 'extras/test/**'
- 'src/**'

jobs:
test:
name: Run unit tests
runs-on: ubuntu-latest

env:
COVERAGE_DATA_PATH: extras/coverage-data/coverage.info

steps:
- name: Checkout
uses: actions/checkout@v4

- uses: arduino/cpp-test-action@main
with:
runtime-paths: |
- extras/test/build/bin/TEST_TARGET_UUID
- extras/test/build/bin/TEST_TARGET_DISC_DEVICE
- extras/test/build/bin/TEST_TARGET_ADVERTISING_DATA
coverage-exclude-paths: |
- '*/extras/test/*'
- '/usr/*'
coverage-data-path: ${{ env.COVERAGE_DATA_PATH }}

# A token is used to avoid intermittent spurious job failures caused by rate limiting.
- name: Set up Codecov upload token
run: |
if [[ "${{ github.repository }}" == "arduino-libraries/ArduinoBLE" ]]; then
# In order to avoid uploads of data from forks, only use the token for runs in the parent repo.
# Token is intentionally exposed.
# See: https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
CODECOV_TOKEN="8118de48-b2af-48b4-a66a-26026847bfc5"
else
# codecov/codecov-action does unauthenticated upload if empty string is passed via the `token` input.
CODECOV_TOKEN=""
fi
echo "CODECOV_TOKEN=$CODECOV_TOKEN" >> "$GITHUB_ENV"

- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v3
with:
file: "${{ env.COVERAGE_DATA_PATH }}"
fail_ci_if_error: true
token: ${{ env.CODECOV_TOKEN }}
18 changes: 17 additions & 1 deletion extras/test/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
build
build
### CMake ###
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

### CMake Patch ###
# External projects
*-prefix/
20 changes: 18 additions & 2 deletions extras/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
##########################################################################

set(CMAKE_VERBOSE_MAKEFILE ON)
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.5)

##########################################################################

project(testArduinoBLE)

Include(FetchContent)

FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
)

FetchContent_MakeAvailable(Catch2)

##########################################################################

set(CMAKE_CXX_STANDARD 11)
Expand Down Expand Up @@ -35,6 +45,9 @@ set(DUT_SRCS
../../src/utility/HCI.cpp
../../src/utility/GATT.cpp
../../src/utility/L2CAPSignaling.cpp
../../src/utility/keyDistribution.cpp
../../src/utility/bitDescriptions.cpp
../../src/utility/btct.cpp
../../src/local/BLELocalAttribute.cpp
../../src/local/BLELocalCharacteristic.cpp
../../src/local/BLELocalDescriptor.cpp
Expand Down Expand Up @@ -102,7 +115,6 @@ include_directories(../../src)
include_directories(../../src/local)
include_directories(../../src/remote)
include_directories(../../src/utility)
include_directories(external/catch/v2.12.1/include)

target_include_directories(TEST_TARGET_DISC_DEVICE PUBLIC include/test_discovered_device)
target_include_directories(TEST_TARGET_ADVERTISING_DATA PUBLIC include/test_advertising_data)
Expand All @@ -124,3 +136,7 @@ add_custom_command(TARGET TEST_TARGET_DISC_DEVICE POST_BUILD
add_custom_command(TARGET TEST_TARGET_ADVERTISING_DATA POST_BUILD
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_ADVERTISING_DATA
)

target_link_libraries( TEST_TARGET_UUID Catch2WithMain )
target_link_libraries( TEST_TARGET_DISC_DEVICE Catch2WithMain )
target_link_libraries( TEST_TARGET_ADVERTISING_DATA Catch2WithMain )
Loading
Loading