Skip to content

Commit

Permalink
add miri to ci and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cospectrum committed Apr 27, 2024
1 parent 8ba7732 commit 600ccd9
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 30 deletions.
File renamed without changes.
23 changes: 23 additions & 0 deletions .github/workflows/safety.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,26 @@ jobs:
env:
LSAN_OPTIONS: "suppressions=lsan-suppressions.txt"
RUSTFLAGS: "-Z sanitizer=leak"
miri:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- run: |
echo "NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)" >> $GITHUB_ENV
- name: Install ${{ env.NIGHTLY }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.NIGHTLY }}
components: miri
- name: Install cargo-nextest
uses: baptiste0928/cargo-install@v1
with:
crate: cargo-nextest
locked: true
- name: cargo miri test
timeout-minutes: 120
run: cargo miri nextest run --no-default-features --features=image/default
env:
MIRIFLAGS: ""
17 changes: 11 additions & 6 deletions src/binary_descriptors/brief.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,11 @@ pub fn brief(

#[cfg(test)]
mod tests {
use super::*;
use crate::utils::gray_bench_image;
use rand::Rng;
use test::{black_box, Bencher};

use crate::utils::gray_bench_image;

use super::*;

#[test]
fn test_compute_hamming_distance() {
let d1 = BriefDescriptor {
Expand Down Expand Up @@ -326,8 +324,16 @@ mod tests {
let integral_image: ImageBuffer<Luma<u32>, Vec<u32>> = integral_image(&image);
assert_eq!(local_pixel_average(&integral_image, 3, 3, 2), 117);
}
}

#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
use crate::utils::gray_bench_image;
use rand::Rng;
use test::{black_box, Bencher};

#[cfg_attr(miri, ignore)]
#[bench]
#[ignore]
fn bench_brief_random_test_pairs_1000_keypoints(b: &mut Bencher) {
Expand All @@ -346,7 +352,6 @@ mod tests {
})
}

#[cfg_attr(miri, ignore)]
#[bench]
#[ignore]
fn bench_brief_fixed_test_pairs_1000_keypoints(b: &mut Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion src/binary_descriptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn match_binary_descriptors<'a, T: BinaryDescriptor>(
matches
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/distance_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/drawing/bezier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn draw_cubic_bezier_curve_mut<C>(
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use image::{GrayImage, Luma};
Expand Down
3 changes: 2 additions & 1 deletion src/drawing/conics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore = "slow [>1480s]")]
#[test]
fn test_draw_filled_ellipse() {
let ellipse = Ellipse {
Expand All @@ -378,7 +379,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/drawing/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn hysteresis(
out
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::canny;
Expand Down
2 changes: 1 addition & 1 deletion src/filter/median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl HistSet {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
3 changes: 0 additions & 3 deletions src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,6 @@ mod tests {
blur(image, stdev)
}

#[cfg_attr(miri, ignore)]
#[bench]
#[ignore] // Gives a baseline performance using code from another library
fn bench_baseline_gaussian_stdev_1(b: &mut Bencher) {
Expand All @@ -968,7 +967,6 @@ mod tests {
});
}

#[cfg_attr(miri, ignore)]
#[bench]
#[ignore] // Gives a baseline performance using code from another library
fn bench_baseline_gaussian_stdev_3(b: &mut Bencher) {
Expand All @@ -979,7 +977,6 @@ mod tests {
});
}

#[cfg_attr(miri, ignore)]
#[bench]
#[ignore] // Gives a baseline performance using code from another library
fn bench_baseline_gaussian_stdev_10(b: &mut Bencher) {
Expand Down
8 changes: 8 additions & 0 deletions src/geometric_transformations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ mod tests {
});
}

#[cfg_attr(miri, ignore = "Miri detected UB in nalgebra")]
#[test]
fn test_from_control_points_translate() {
let from = [(0f32, 0.0), (50.0, 50.0), (50.0, 0.0), (0.0, 50.0)];
Expand All @@ -1122,6 +1123,7 @@ mod tests {
assert_approx_eq!(out.1, 5.0, 1e-10);
}

#[cfg_attr(miri, ignore = "Miri detected UB in dependencies")]
#[test]
fn test_from_control_points() {
let from = [(0f32, 0.0), (50.0, 50.0), (50.0, 0.0), (0.0, 50.0)];
Expand All @@ -1136,6 +1138,7 @@ mod tests {
assert_approx_eq!(out.1, 20.0, 1e-10);
}

#[cfg_attr(miri, ignore = "Miri detected UB in nalgebra")]
#[test]
fn test_from_control_points_2() {
let from = [
Expand All @@ -1150,6 +1153,7 @@ mod tests {
assert!(p.is_some());
}

#[cfg_attr(miri, ignore = "Miri detected UB in nalgebra")]
#[test]
/// Test case from https://github.com/image-rs/imageproc/issues/412
fn test_from_control_points_nofreeze() {
Expand All @@ -1164,6 +1168,7 @@ mod tests {
Projection::from_control_points(from, to);
}

#[cfg_attr(miri, ignore = "Miri detected UB in nalgebra")]
#[test]
fn test_from_control_points_known_transform() {
let t = Projection::translate(10f32, 10f32);
Expand All @@ -1185,6 +1190,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore = "Miri detected UB in nalgebra")]
#[test]
fn test_from_control_points_colinear() {
let from = [(0f32, 0.0), (50.0, 50.0), (50.0, 0.0), (0.0, 50.0)];
Expand All @@ -1195,6 +1201,7 @@ mod tests {
assert!(p.is_none());
}

#[cfg_attr(miri, ignore = "Miri detected UB in nalgebra")]
#[test]
fn test_from_control_points_translation() {
let p = Projection::translate(10f32, 15f32);
Expand All @@ -1213,6 +1220,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore = "Miri detected UB in nalgebra")]
#[test]
fn test_from_control_points_underdetermined() {
let from = [
Expand Down
3 changes: 1 addition & 2 deletions src/gradients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ mod tests {
use super::*;
use crate::utils::gray_bench_image;
use image::{ImageBuffer, Luma};
use test::{black_box, Bencher};

#[rustfmt::skip::macros(gray_image)]
#[test]
Expand Down Expand Up @@ -365,7 +364,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/haar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/hog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/hough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ mod tests {
test_detect_line!(detect_line_neg10_120, -10.0, 120);
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/local_binary_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/morphology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/pixelops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
4 changes: 2 additions & 2 deletions src/region_labelling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ mod tests {

// One huge component with eight-way connectivity, loads of
// isolated components with four-way connectivity.
pub(in super::benches) fn chessboard(width: u32, height: u32) -> GrayImage {
pub(super) fn chessboard(width: u32, height: u32) -> GrayImage {
ImageBuffer::from_fn(width, height, |x, y| {
if (x + y) % 2 == 0 {
Luma([255u8])
Expand Down Expand Up @@ -304,7 +304,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::connected_components;
Expand Down
2 changes: 1 addition & 1 deletion src/seam_carving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub fn draw_vertical_seams(image: &GrayImage, seams: &[VerticalSeam]) -> Image<R
out
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/union_find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
Expand Down
2 changes: 2 additions & 0 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
//!
//! [caltech256 dataset]: https://authors.library.caltech.edu/7694/
#![cfg(not(miri))]

#[macro_use]
extern crate imageproc;

Expand Down

0 comments on commit 600ccd9

Please sign in to comment.