Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Miri to CI #573

Merged
merged 30 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4fef85c
mod hough::benches
cospectrum Apr 27, 2024
1da29c4
rename edges tests to benches
cospectrum Apr 27, 2024
358b44a
union_fin benches
cospectrum Apr 27, 2024
4be059e
haar benches
cospectrum Apr 27, 2024
309b9d2
mv drawing benches
cospectrum Apr 27, 2024
25981f8
rename seam_curving tests to benches
cospectrum Apr 27, 2024
81a289b
rename noise tests to benches
cospectrum Apr 27, 2024
a86bd37
mv stats benches
cospectrum Apr 27, 2024
edf70a7
mv hog benches
cospectrum Apr 27, 2024
aad19c4
mv median tests/benches
cospectrum Apr 27, 2024
6576669
mv pixelops benches/tests
cospectrum Apr 27, 2024
6e7554d
mv gradients benches/tests
cospectrum Apr 27, 2024
73fd2a1
rename tests to benches inside binary_descriptors mod.rs
cospectrum Apr 27, 2024
4333892
separate tests and benches in local_binary_patterns
cospectrum Apr 27, 2024
f8af828
add miri tag for corners
cospectrum Apr 27, 2024
6f5301c
separate tests and benches in distance_transform
cospectrum Apr 27, 2024
5283539
separate tests/benches in morphology
cospectrum Apr 27, 2024
5618aa8
separate tests/benches in region_labelling
cospectrum Apr 27, 2024
8ba7732
add miri ignore for benches
cospectrum Apr 27, 2024
600ccd9
add miri to ci and fix warnings
cospectrum Apr 27, 2024
5adef89
specify dependency (nalgebra)
cospectrum Apr 28, 2024
201d463
Merge branch 'master' into miri
cospectrum Apr 28, 2024
bf8493f
sep tests/benches in filter/mod and template_matching
cospectrum Apr 28, 2024
5721f4b
sep tests in drawing/rect
cospectrum Apr 28, 2024
84680cc
sep contrast tests/benches
cospectrum Apr 29, 2024
6e253c8
merge master
cospectrum Apr 29, 2024
f5e8924
sep tests/becnehs in integral_image
cospectrum Apr 29, 2024
8d9cd01
sep tests/becnehs in corners
cospectrum Apr 29, 2024
4d3429a
sep tests/becnehs in geom transformations
cospectrum Apr 29, 2024
d60c538
sep tests/becnehs in suppress
cospectrum Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: ""
15 changes: 11 additions & 4 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,6 +324,15 @@ 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};

#[bench]
#[ignore]
Expand Down
3 changes: 2 additions & 1 deletion src/binary_descriptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ pub fn match_binary_descriptors<'a, T: BinaryDescriptor>(
matches
}

#[cfg(not(miri))]
#[cfg(test)]
mod tests {
mod benches {
use super::*;
use crate::{binary_descriptors::brief::brief, utils::gray_bench_image};
use test::{black_box, Bencher};
Expand Down
10 changes: 10 additions & 0 deletions src/contrast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ mod tests {
}
}

#[cfg_attr(miri, ignore)]
cospectrum marked this conversation as resolved.
Show resolved Hide resolved
#[bench]
fn bench_adaptive_threshold(b: &mut Bencher) {
let image = gray_bench_image(200, 200);
Expand All @@ -374,6 +375,7 @@ mod tests {
});
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_match_histogram(b: &mut Bencher) {
let target = GrayImage::from_pixel(200, 200, Luma([150]));
Expand All @@ -384,6 +386,7 @@ mod tests {
});
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_match_histogram_mut(b: &mut Bencher) {
let target = GrayImage::from_pixel(200, 200, Luma([150]));
Expand Down Expand Up @@ -465,6 +468,7 @@ mod tests {
assert_eq!(level, 120);
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_otsu_level(b: &mut Bencher) {
let image = gray_bench_image(200, 200);
Expand Down Expand Up @@ -508,6 +512,7 @@ mod tests {
assert_pixels_eq!(expected, actual);
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_equalize_histogram(b: &mut Bencher) {
let image = gray_bench_image(500, 500);
Expand All @@ -517,6 +522,7 @@ mod tests {
});
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_equalize_histogram_mut(b: &mut Bencher) {
let mut image = gray_bench_image(500, 500);
Expand All @@ -526,6 +532,7 @@ mod tests {
});
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_threshold(b: &mut Bencher) {
let image = gray_bench_image(500, 500);
Expand All @@ -535,6 +542,7 @@ mod tests {
});
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_threshold_mut(b: &mut Bencher) {
let mut image = gray_bench_image(500, 500);
Expand All @@ -544,6 +552,7 @@ mod tests {
});
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_stretch_contrast(b: &mut Bencher) {
let image = gray_bench_image(500, 500);
Expand All @@ -553,6 +562,7 @@ mod tests {
});
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_stretch_contrast_mut(b: &mut Bencher) {
let mut image = gray_bench_image(500, 500);
Expand Down
5 changes: 5 additions & 0 deletions src/corners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ mod tests {
assert!(!is_corner_fast12(&image, 8, 3, 3));
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_is_corner_fast12_12_noncontiguous(b: &mut Bencher) {
let image = black_box(gray_image!(
Expand Down Expand Up @@ -644,6 +645,7 @@ mod tests {
);
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_intensity_centroid(b: &mut Bencher) {
let image = gray_image!(
Expand All @@ -658,6 +660,7 @@ mod tests {
b.iter(|| black_box(intensity_centroid(&image, 3, 3, 3)));
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_oriented_fast_corner(b: &mut Bencher) {
let image = gray_image!(
Expand All @@ -672,6 +675,7 @@ mod tests {
b.iter(|| black_box(oriented_fast(&image, Some(0), 1, 0, Some(0xc0))));
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_oriented_fast_non_corner(b: &mut Bencher) {
let image = gray_image!(
Expand All @@ -686,6 +690,7 @@ mod tests {
b.iter(|| black_box(oriented_fast(&image, Some(255), 0, 0, Some(0xc0))));
}

#[cfg_attr(miri, ignore)]
#[bench]
fn bench_is_corner_fast9_9_contiguous_lighter_pixels(b: &mut Bencher) {
let image = black_box(gray_image!(
Expand Down
11 changes: 9 additions & 2 deletions src/distance_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,11 @@ mod tests {
use super::*;
use crate::definitions::Image;
use crate::property_testing::GrayTestImage;
use crate::utils::{gray_bench_image, pixel_diff_summary};
use crate::utils::pixel_diff_summary;
use image::{GrayImage, Luma};
use quickcheck::{quickcheck, Arbitrary, Gen, TestResult};
use std::cmp::max;
use std::f64;
use test::{black_box, Bencher};

/// Avoid generating garbage floats during certain calculations below.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -581,6 +580,14 @@ mod tests {
let dist = euclidean_squared_distance_transform(&image);
assert_pixels_eq_within!(dist, expected, 1e-6);
}
}

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

macro_rules! bench_euclidean_squared_distance_transform {
($name:ident, side: $s:expr) => {
Expand Down
3 changes: 2 additions & 1 deletion src/drawing/bezier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ pub fn draw_cubic_bezier_curve_mut<C>(
}
}

#[cfg(not(miri))]
#[cfg(test)]
mod tests {
mod benches {
use image::{GrayImage, Luma};

macro_rules! bench_cubic_bezier_curve {
Expand Down
8 changes: 8 additions & 0 deletions 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 @@ -376,6 +377,13 @@ mod tests {
const EPS: f32 = 0.0019;
check_filled_ellipse(&img, ellipse, inner_color, outer_color, EPS);
}
}

#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
use image::{GrayImage, Luma};

macro_rules! bench_hollow_ellipse {
($name:ident, $center:expr, $width_radius:expr, $height_radius:expr) => {
Expand Down
69 changes: 38 additions & 31 deletions src/drawing/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,44 @@ mod tests {
assert_pixels_eq!(oct3, expected);
}

#[test]
fn test_draw_line_segment_horizontal_using_bresenham_line_pixel_iter_mut() {
let image = GrayImage::from_pixel(5, 5, Luma([1u8]));

let expected = gray_image!(
1, 1, 1, 1, 1;
4, 4, 4, 4, 4;
1, 1, 1, 1, 1;
1, 1, 1, 1, 1;
1, 1, 1, 1, 1);

let mut right = image.clone();
{
let right_iter =
BresenhamLinePixelIterMut::new(&mut right, (-3f32, 1f32), (6f32, 1f32));
for p in right_iter {
*p = Luma([4u8]);
}
}
assert_pixels_eq!(right, expected);

let mut left = image.clone();
{
let left_iter = BresenhamLinePixelIterMut::new(&mut left, (6f32, 1f32), (-3f32, 1f32));
for p in left_iter {
*p = Luma([4u8]);
}
}
assert_pixels_eq!(left, expected);
}
}

#[cfg(not(miri))]
#[cfg(test)]
mod benches {
use super::*;
use image::{GrayImage, Luma};

macro_rules! bench_antialiased_lines {
($name:ident, $start:expr, $end:expr) => {
#[bench]
Expand Down Expand Up @@ -601,35 +639,4 @@ mod tests {
(10, 10),
(450, 80)
);

#[test]
fn test_draw_line_segment_horizontal_using_bresenham_line_pixel_iter_mut() {
let image = GrayImage::from_pixel(5, 5, Luma([1u8]));

let expected = gray_image!(
1, 1, 1, 1, 1;
4, 4, 4, 4, 4;
1, 1, 1, 1, 1;
1, 1, 1, 1, 1;
1, 1, 1, 1, 1);

let mut right = image.clone();
{
let right_iter =
BresenhamLinePixelIterMut::new(&mut right, (-3f32, 1f32), (6f32, 1f32));
for p in right_iter {
*p = Luma([4u8]);
}
}
assert_pixels_eq!(right, expected);

let mut left = image.clone();
{
let left_iter = BresenhamLinePixelIterMut::new(&mut left, (6f32, 1f32), (-3f32, 1f32));
for p in left_iter {
*p = Luma([4u8]);
}
}
assert_pixels_eq!(left, expected);
}
}
1 change: 1 addition & 0 deletions src/drawing/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ mod tests {
use test::{black_box, Bencher};

#[bench]
#[cfg_attr(miri, ignore)]
fn bench_draw_filled_rect_mut_rgb(b: &mut Bencher) {
let mut image = RgbImage::new(200, 200);
let color = Rgb([120u8, 60u8, 47u8]);
Expand Down
3 changes: 2 additions & 1 deletion src/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ fn hysteresis(
out
}

#[cfg(not(miri))]
#[cfg(test)]
mod tests {
mod benches {
use super::canny;
use crate::drawing::draw_filled_rect_mut;
use crate::rect::Rect;
Expand Down
18 changes: 12 additions & 6 deletions src/filter/median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,11 @@ impl HistSet {
}
}

#[cfg(not(miri))]
#[cfg(test)]
mod tests {
mod benches {
use super::*;
use crate::property_testing::GrayTestImage;
use crate::utils::gray_bench_image;
use crate::utils::pixel_diff_summary;
use image::{GrayImage, Luma};
use quickcheck::{quickcheck, TestResult};
use std::cmp::{max, min};
use test::{black_box, Bencher};

macro_rules! bench_median_filter {
Expand All @@ -358,6 +354,16 @@ mod tests {
bench_median_filter!(bench_median_filter_s100_rx1_ry8, side: 100, x_radius: 1,y_radius: 8);
bench_median_filter!(bench_median_filter_s100_rx4_ry8, side: 100, x_radius: 4,y_radius: 1);
bench_median_filter!(bench_median_filter_s100_rx8_ry1, side: 100, x_radius: 8,y_radius: 1);
}

#[cfg(test)]
mod tests {
use super::*;
use crate::property_testing::GrayTestImage;
use crate::utils::pixel_diff_summary;
use image::{GrayImage, Luma};
use quickcheck::{quickcheck, TestResult};
use std::cmp::{max, min};

// Reference implementation of median filter - written to be as simple as possible,
// to validate faster versions against.
Expand Down
Loading
Loading