From 0451106cccbb6e9e8c5240bd2a5fedaec1b793bd Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Thu, 18 Nov 2021 19:15:20 -0800 Subject: [PATCH] Add sanitizers --- .github/workflows/sanitizers.yml | 45 +++++++++++++++++++ sysid-application/build.gradle | 24 ++++++++++ .../native/cpp/analysis/FilteringUtils.cpp | 19 ++++++-- 3 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/sanitizers.yml diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml new file mode 100644 index 00000000..5d00421c --- /dev/null +++ b/.github/workflows/sanitizers.yml @@ -0,0 +1,45 @@ +name: Sanitizers + +on: [pull_request, push] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - name: asan + build-env: "" + build-options: "-Pasan" + - name: tsan + build-env: "TSAN_OPTIONS=second_deadlock_stack=1" + build-options: "-Ptsan" + - name: ubsan + build-env: "" + build-options: "-Pubsan" + name: "${{ matrix.name }}" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - uses: actions/setup-java@v1 + with: + java-version: 11 + architecture: x64 + + - name: Install Toolchain + run: ./gradlew installRoborioToolchain + + - name: Run sanitizers on unit tests + run: ${{ matrix.build-env }} ./gradlew runSysidTestReleaseGoogleTestExe ${{ matrix.build-options }} + - name: Run sanitizers on analysis integration tests + run: ${{ matrix.build-env }} ./gradlew runAnalysisIntegrationTests -PwithIntegration ${{ matrix.build-options }} + + - name: Run sanitizers on generation integration tests + run: ${{ matrix.build-env }} ./gradlew runGenerationIntegrationTests -PwithIntegration ${{ matrix.build-options }} diff --git a/sysid-application/build.gradle b/sysid-application/build.gradle index 2bc2d157..96dffb73 100644 --- a/sysid-application/build.gradle +++ b/sysid-application/build.gradle @@ -213,5 +213,29 @@ model { } } +if (project.hasProperty("asan")) { + nativeUtils.platformConfigs.named("linuxx86-64").configure { + it.cppCompiler.args.add('-g3') + it.cppCompiler.args.add('-fsanitize=address') + it.linker.args.add('-fsanitize=address') + } +} + +if (project.hasProperty("tsan")) { + nativeUtils.platformConfigs.named("linuxx86-64").configure { + it.cppCompiler.args.add('-g3') + it.cppCompiler.args.add('-fsanitize=thread') + it.linker.args.add('-fsanitize=thread') + } +} + +if (project.hasProperty("ubsan")) { + nativeUtils.platformConfigs.named("linuxx86-64").configure { + it.cppCompiler.args.add('-g3') + it.cppCompiler.args.add('-fsanitize=undefined') + it.linker.args.add('-fsanitize=undefined') + } +} + // Configure publishing. apply from: "config/publish.gradle" diff --git a/sysid-application/src/main/native/cpp/analysis/FilteringUtils.cpp b/sysid-application/src/main/native/cpp/analysis/FilteringUtils.cpp index b70474a8..6c66ef8b 100644 --- a/sysid-application/src/main/native/cpp/analysis/FilteringUtils.cpp +++ b/sysid-application/src/main/native/cpp/analysis/FilteringUtils.cpp @@ -129,16 +129,27 @@ sysid::TrimStepVoltageData(std::vector* data, (settings->motionThreshold * datum.dt.value()); }); + units::second_t positionDelay; + if (motionBegins != data->end()) { + positionDelay = motionBegins->timestamp - firstTimestamp; + } else { + positionDelay = 0_s; + } + auto maxAccel = std::max_element( data->begin(), data->end(), [](const auto& a, const auto& b) { return std::abs(a.acceleration) < std::abs(b.acceleration); }); - units::second_t positionDelay = motionBegins->timestamp - firstTimestamp; - units::second_t velocityDelay = maxAccel->timestamp - firstTimestamp; + units::second_t velocityDelay; + if (maxAccel != data->end()) { + velocityDelay = maxAccel->timestamp - firstTimestamp; - // Trim data before max acceleration - data->erase(data->begin(), maxAccel); + // Trim data before max acceleration + data->erase(data->begin(), maxAccel); + } else { + velocityDelay = 0_s; + } minStepTime = std::min(data->at(0).timestamp - firstTimestamp, minStepTime);