Skip to content

Commit

Permalink
[filter] test unit library compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisCarouge committed Oct 13, 2024
1 parent d45fb3a commit 948952d
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/clang_tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ jobs:
egress-policy: audit
- name: Checkout
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: 'Install Ninja'
run: sudo apt install ninja-build
- name: 'Configure'
env:
CXX: 'clang++-18'
CC: 'clang-18'
run: cmake -S . -B 'build' -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
run: cmake -S . -B 'build' -G 'Ninja' -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
- name: Verify
run: |
cat build/compile_commands.json
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ jobs:
uses: github/codeql-action/init@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # v3.26.11
with:
languages: ${{ matrix.language }}
- name: 'Install Ninja'
run: sudo apt install ninja-build
- name: 'Configure'
env:
CXX: 'g++-14'
CC: 'gcc-14'
run: cmake -S . -B 'build'
run: cmake -S . -B 'build' -G 'Ninja'
- name: 'Build'
run: cmake --build 'build' --verbose --parallel 4
- name: Perform CodeQL Analysis
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy_test_coverage_coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ jobs:
- name: Checkout
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: 'Install'
run: sudo apt install lcov
run: sudo apt install lcov ninja-build
- name: 'Configure'
env:
CXX: 'g++-14'
CXXFLAGS: '-O0 -g --coverage -fno-inline -fno-exceptions'
CC: 'gcc-14'
CCFLAGS: '-O0 -g --coverage -fno-inline -fno-exceptions'
run: cmake -S . -B 'build'
run: cmake -S . -B 'build' -G 'Ninja'
- name: 'Build'
run: cmake --build 'build' --verbose --parallel 4
- name: 'Coverage: Base'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/memory_valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:
- name: Checkout
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: 'Install'
run: sudo apt install valgrind
run: sudo apt install valgrind ninja-build
- name: Build
env:
CXX: 'g++-14'
CC: 'gcc-14'
COMMAND: 'valgrind --error-exitcode=1 --leak-check=full --track-origins=yes'
run: cmake -S . -B 'build'
run: cmake -S . -B 'build' -G 'Ninja'
- name: 'Build'
run: cmake --build 'build' --verbose --parallel 4
- name: 'Test'
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
fail-fast: false
matrix:
include:
- { os: 'ubuntu-24.04', cxx: 'clang++-18', cc: 'clang-18', generator: 'Unix Makefiles', packages: 'clang-18' }
- { os: 'ubuntu-24.04', cxx: 'g++-14', cc: 'gcc-14', generator: 'Unix Makefiles', packages: 'g++-14' }
- { os: 'ubuntu-24.04', cxx: 'clang++-18', cc: 'clang-18', generator: 'Ninja', packages: 'clang-18' }
- { os: 'ubuntu-24.04', cxx: 'g++-14', cc: 'gcc-14', generator: 'Ninja', packages: 'g++-14' }
- { os: 'windows-latest', cxx: 'cl', cc: 'cl', generator: 'Ninja', config: 'Debug' }
- { os: 'windows-latest', cxx: 'cl', cc: 'cl', generator: 'Ninja', config: 'Release' }
name: '${{ matrix.os }} / ${{ matrix.cxx }} / ${{ matrix.generator }} / ${{ matrix.config }}'
Expand All @@ -32,6 +32,9 @@ jobs:
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: 'Install: MSVC'
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
- name: 'Install Ninja'
if: ${{ matrix.os == 'ubuntu-24.04' }}
run: sudo apt install ninja-build
- name: 'Configure'
env:
CXX: '${{ matrix.cxx }}'
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/sanitizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ jobs:
egress-policy: audit
- name: 'Checkout'
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: 'Install Ninja'
run: sudo apt install ninja-build
- name: 'Configure'
env:
CXX: 'g++-14'
CC: 'gcc-14'
run: cmake -S . -B 'build'
run: cmake -S . -B 'build' -G 'Ninja'
- name: 'Build'
run: cmake --build 'build' --verbose --parallel 4
- name: 'Test'
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ project(
VERSION "0.4.0")

set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
Expand Down
6 changes: 0 additions & 6 deletions support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
kalman_options
INTERFACE "-D_FORTIFY_SOURCE=3"
"-D_GLIBCXX_ASSERTIONS"
"-fcf-protection=full"
"-fno-check-new"
"-fno-common"
"-fPIE"
"-fstack-clash-protection"
"-fstack-protector-strong"
"-fstrict-aliasing"
"-ftrivial-auto-var-init=pattern"
"-pedantic"
"-Wall"
"-Wcast-align"
Expand All @@ -75,14 +72,11 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
kalman_options
INTERFACE "-D_FORTIFY_SOURCE=3"
"-D_GLIBCXX_ASSERTIONS"
"-fcf-protection=full"
"-fno-check-new"
"-fno-common"
"-fPIE"
"-fstack-clash-protection"
"-fstack-protector-strong"
"-fstrict-aliasing"
"-ftrivial-auto-var-init=pattern"
"-pedantic"
"-Wall"
"-Wcast-align"
Expand Down
24 changes: 23 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org> ]]

include(FetchContent)

FetchContent_Declare(
fmt
GIT_REPOSITORY "https://github.com/fmtlib/fmt"
FIND_PACKAGE_ARGS NAMES fmt)
FetchContent_MakeAvailable(fmt)

FetchContent_Declare(
gsl-lite
GIT_REPOSITORY "https://github.com/gsl-lite/gsl-lite"
FIND_PACKAGE_ARGS NAMES gsl-lite)
FetchContent_MakeAvailable(gsl-lite)

set(MP_UNITS_BUILD_CXX_MODULES ON)
FetchContent_Declare(
mp-units
GIT_REPOSITORY "https://github.com/mpusz/mp-units"
SOURCE_SUBDIR "src" FIND_PACKAGE_ARGS NAMES mp-units)
FetchContent_MakeAvailable(mp-units)

foreach(
TEST
"kalman_constructor_default_float_1x1x1.cpp"
Expand All @@ -44,7 +65,8 @@ foreach(
"kalman_format_arguments.cpp"
"kalman_format_float_1x1x1.cpp"
"kalman_format.cpp"
"kalman_println.cpp")
"kalman_println.cpp"
"units_kf_1x1x0.cpp")
get_filename_component(NAME ${TEST} NAME_WE)
add_executable(kalman_test_${NAME}_driver ${TEST})
target_link_libraries(kalman_test_${NAME}_driver PRIVATE kalman kalman_main
Expand Down
40 changes: 40 additions & 0 deletions test/units_kf_1x1x0.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "fcarouge/kalman.hpp"

#include <cassert>
#include <cmath>
import mp_units;

namespace fcarouge::test {
namespace {
//! @test Verifies compatibility with
[[maybe_unused]] auto sample{[] {
kalman filter{state{60.}, output<double>, estimate_uncertainty{225.},
output_uncertainty{25.}};

assert(60 == filter.x() &&
"Since our system's dynamic model is constant, i.e. the building "
"doesn't change its height: 60 meters.");
assert(225 == filter.p() &&
"The extrapolated estimate uncertainty (variance) also doesn't "
"change: 225");

filter.update(48.54);

filter.update(47.11);
filter.update(55.01);
filter.update(55.15);
filter.update(49.89);
filter.update(40.85);
filter.update(46.72);
filter.update(50.05);
filter.update(51.27);
filter.update(49.95);

assert(std::abs(1 - filter.x() / 49.57) < 0.001 &&
"After 10 measurement and update iterations, the building estimated "
"height is: 49.57m.");

return 0;
}()};
} // namespace
} // namespace fcarouge::test

0 comments on commit 948952d

Please sign in to comment.