Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

Commit

Permalink
Add sanitizers
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Aug 21, 2023
1 parent b2cc84b commit 0451106
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
@@ -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 }}
24 changes: 24 additions & 0 deletions sysid-application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 15 additions & 4 deletions sysid-application/src/main/native/cpp/analysis/FilteringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,27 @@ sysid::TrimStepVoltageData(std::vector<PreparedData>* 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);

Expand Down

0 comments on commit 0451106

Please sign in to comment.