diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 58a7d722..0d61656c 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -10,7 +10,7 @@ on: jobs: unit-test: name: Build and run unit test - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout repository @@ -19,9 +19,29 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y libboost-all-dev libfmt-dev + sudo apt-get install -y libboost-all-dev libfmt-dev lcov - name: Run unit test run: | cd extras/test/unit ./test.sh + + - name: Measure test coverage + run: | + cd extras/test/unit + ./coverage.sh + + - name: Upload coverage report as artifact + uses: actions/upload-artifact@v4 + with: + name: coverage_report + path: extras/test/unit/lcov.report + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_branch: gh-pages + publish_dir: extras/test/unit/lcov.report + destination_dir: coverage + keep_files: true diff --git a/extras/cppcheck/check_file.sh b/extras/cppcheck/check_file.sh index a560cd33..45c32744 100755 --- a/extras/cppcheck/check_file.sh +++ b/extras/cppcheck/check_file.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [[ $@ -lt 1 ]]; then +if [[ $# -lt 1 ]]; then echo "Usage: $0 " exit 1 fi diff --git a/extras/test/unit/.gitignore b/extras/test/unit/.gitignore index 567609b1..b9f0c3b0 100644 --- a/extras/test/unit/.gitignore +++ b/extras/test/unit/.gitignore @@ -1 +1,2 @@ build/ +lcov* diff --git a/extras/test/unit/CMakeLists.txt b/extras/test/unit/CMakeLists.txt index 300b8869..a3943e84 100644 --- a/extras/test/unit/CMakeLists.txt +++ b/extras/test/unit/CMakeLists.txt @@ -18,11 +18,13 @@ add_executable(${PROJECT_NAME} ${TEST_SOURCES}) target_include_directories(${PROJECT_NAME} PUBLIC include) # link RadioLib -target_link_libraries(${PROJECT_NAME} RadioLib fmt) +target_link_libraries(${PROJECT_NAME} RadioLib fmt gcov) # set target properties and options set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20) -target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra) +set(BUILD_FLAGS -Wall -Wextra -fprofile-arcs -ftest-coverage -O0) +target_compile_options(${PROJECT_NAME} PRIVATE ${BUILD_FLAGS}) +target_compile_options(RadioLib PRIVATE ${BUILD_FLAGS}) # set RadioLib debug #target_compile_definitions(RadioLib PUBLIC RADIOLIB_DEBUG_BASIC RADIOLIB_DEBUG_SPI RADIOLIB_DEBUG_PROTOCOL) diff --git a/extras/test/unit/coverage.sh b/extras/test/unit/coverage.sh new file mode 100755 index 00000000..c2c3c9dd --- /dev/null +++ b/extras/test/unit/coverage.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e +filename="lcov" +rm -rf $filename.* +lcov --capture --directory build --output-file "${filename}.info" + +# filter out boost and C++ standard library +lcov --remove "${filename}.info" "/usr/*/boost/*" "/usr/include/c++/*" --output-file "${filename}.info" + +# generate HTML +genhtml "${filename}.info" --output-directory "${filename}.report" diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 297a91e4..47511aba 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -118,6 +118,10 @@ //#define RADIOLIB_CLOCK_DRIFT_MS (0) #endif +#if !defined(RADIOLIB_LINE_FEED) + #define RADIOLIB_LINE_FEED "\r\n" +#endif + #if ARDUINO >= 100 // Arduino build #include "Arduino.h" @@ -471,9 +475,9 @@ #if RADIOLIB_DEBUG #if defined(RADIOLIB_BUILD_ARDUINO) #define RADIOLIB_DEBUG_PRINT(...) rlb_printf(__VA_ARGS__) - #define RADIOLIB_DEBUG_PRINTLN(M, ...) rlb_printf(M "\n", ##__VA_ARGS__) + #define RADIOLIB_DEBUG_PRINTLN(M, ...) rlb_printf(M "" RADIOLIB_LINE_FEED, ##__VA_ARGS__) #define RADIOLIB_DEBUG_PRINT_LVL(LEVEL, M, ...) rlb_printf(LEVEL "" M, ##__VA_ARGS__) - #define RADIOLIB_DEBUG_PRINTLN_LVL(LEVEL, M, ...) rlb_printf(LEVEL "" M "\n", ##__VA_ARGS__) + #define RADIOLIB_DEBUG_PRINTLN_LVL(LEVEL, M, ...) rlb_printf(LEVEL "" M "" RADIOLIB_LINE_FEED, ##__VA_ARGS__) // some platforms do not support printf("%f"), so it has to be done this way #define RADIOLIB_DEBUG_PRINT_FLOAT(LEVEL, VAL, DECIMALS) RADIOLIB_DEBUG_PRINT(LEVEL); RADIOLIB_DEBUG_PORT.print(VAL, DECIMALS) @@ -483,8 +487,8 @@ #define RADIOLIB_DEBUG_PRINT_LVL(LEVEL, M, ...) fprintf(RADIOLIB_DEBUG_PORT, LEVEL "" M, ##__VA_ARGS__) #endif #if !defined(RADIOLIB_DEBUG_PRINTLN) - #define RADIOLIB_DEBUG_PRINTLN(M, ...) fprintf(RADIOLIB_DEBUG_PORT, M "\n", ##__VA_ARGS__) - #define RADIOLIB_DEBUG_PRINTLN_LVL(LEVEL, M, ...) fprintf(RADIOLIB_DEBUG_PORT, LEVEL "" M "\n", ##__VA_ARGS__) + #define RADIOLIB_DEBUG_PRINTLN(M, ...) fprintf(RADIOLIB_DEBUG_PORT, M "" RADIOLIB_LINE_FEED, ##__VA_ARGS__) + #define RADIOLIB_DEBUG_PRINTLN_LVL(LEVEL, M, ...) fprintf(RADIOLIB_DEBUG_PORT, LEVEL "" M "" RADIOLIB_LINE_FEED, ##__VA_ARGS__) #endif #define RADIOLIB_DEBUG_PRINT_FLOAT(LEVEL, VAL, DECIMALS) RADIOLIB_DEBUG_PRINT(LEVEL "%.3f", VAL) #endif @@ -545,13 +549,13 @@ #define RADIOLIB_VALUE_TO_STRING(x) #x #define RADIOLIB_VALUE(x) RADIOLIB_VALUE_TO_STRING(x) -#define RADIOLIB_INFO "\nRadioLib Info\nVersion: \"" \ +#define RADIOLIB_INFO "\r\nRadioLib Info\nVersion: \"" \ RADIOLIB_VALUE(RADIOLIB_VERSION_MAJOR) "." \ RADIOLIB_VALUE(RADIOLIB_VERSION_MINOR) "." \ RADIOLIB_VALUE(RADIOLIB_VERSION_PATCH) "." \ - RADIOLIB_VALUE(RADIOLIB_VERSION_EXTRA) "\"\n" \ - "Platform: " RADIOLIB_VALUE(RADIOLIB_PLATFORM) "\n" \ - "Compiled: " RADIOLIB_VALUE(__DATE__) " " RADIOLIB_VALUE(__TIME__) + RADIOLIB_VALUE(RADIOLIB_VERSION_EXTRA) "\"\r\n" \ + "Platform: " RADIOLIB_VALUE(RADIOLIB_PLATFORM) "\r\n" \ + RADIOLIB_VALUE(__DATE__) " " RADIOLIB_VALUE(__TIME__) /*! \brief A simple assert macro, will return on error. diff --git a/src/RadioLib.h b/src/RadioLib.h index adc6854a..3c362e11 100644 --- a/src/RadioLib.h +++ b/src/RadioLib.h @@ -37,6 +37,7 @@ - PhysicalLayer - FSK and LoRa radio modules \see https://github.com/jgromes/RadioLib + \see https://jgromes.github.io/RadioLib/coverage/src/index.html \copyright Copyright (c) 2019 Jan Gromes */ diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index b66a9d22..cb09bfad 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -765,9 +765,9 @@ int16_t Si443x::updateClockRecovery() { uint16_t rxOsr_fixed = (uint16_t)rxOsr; // print that whole mess - RADIOLIB_DEBUG_BASIC_PRINTLN("%X\n%X\n%X", bypass, decRate, manch); + RADIOLIB_DEBUG_BASIC_PRINTLN("%X %X %X", bypass, decRate, manch); RADIOLIB_DEBUG_BASIC_PRINT_FLOAT((double)rxOsr, 2); - RADIOLIB_DEBUG_BASIC_PRINTLN("\t%d\t%X\n%lu\t%lX\n%d\t%X", rxOsr_fixed, rxOsr_fixed, (long unsigned int)ncoOff, (long unsigned int)ncoOff, crGain, crGain); + RADIOLIB_DEBUG_BASIC_PRINTLN("\t%d\t%X" RADIOLIB_LINE_FEED "%lu\t%lX" RADIOLIB_LINE_FEED "%d\t%X", rxOsr_fixed, rxOsr_fixed, (long unsigned int)ncoOff, (long unsigned int)ncoOff, crGain, crGain); // update oversampling ratio int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((rxOsr_fixed & 0x0700) >> 3), 7, 5); diff --git a/src/protocols/Morse/Morse.cpp b/src/protocols/Morse/Morse.cpp index c261773b..fbacc824 100644 --- a/src/protocols/Morse/Morse.cpp +++ b/src/protocols/Morse/Morse.cpp @@ -86,7 +86,7 @@ int MorseClient::read(uint8_t* symbol, uint8_t* len, float low, float high) { if((pauseLen >= low*(float)letterSpace) && (pauseLen <= high*(float)letterSpace)) { return(RADIOLIB_MORSE_CHAR_COMPLETE); } else if(pauseLen > wordSpace) { - RADIOLIB_DEBUG_PROTOCOL_PRINTLN("\n"); + RADIOLIB_DEBUG_PROTOCOL_PRINTLN(RADIOLIB_LINE_FEED ""); return(RADIOLIB_MORSE_WORD_COMPLETE); } @@ -164,7 +164,7 @@ size_t MorseClient::write(uint8_t b) { // letter space standby(); mod->waitForMicroseconds(mod->hal->micros(), letterSpace*1000 - dotLength*1000); - RADIOLIB_DEBUG_PROTOCOL_PRINT_NOTAG("\n"); + RADIOLIB_DEBUG_PROTOCOL_PRINT_NOTAG(RADIOLIB_LINE_FEED); return(1); }