From 5b9af1c34746e20b4596c1812b683624bdcfc152 Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Sun, 10 Mar 2024 09:50:24 -0700 Subject: [PATCH] test_miri_smoketest --- .github/workflows/ci.yml | 13 +++++++++++++ src/test.rs | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c31d4d..97fc8e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -336,3 +336,16 @@ jobs: run: cmake -S c -B c/build -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/target - name: CMake build / install run: cmake --build c/build --target install + + miri_smoketest: + name: Miri smoketest + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@nightly + with: + components: miri + # Currently the test search "miri" only matches "test_miri_smoketest", but + # we might add more. If this accidentally picks up anything incompatible or + # slow, we can narrow it. + - run: cargo miri test miri diff --git a/src/test.rs b/src/test.rs index 2744d90..c76cbbc 100644 --- a/src/test.rs +++ b/src/test.rs @@ -818,3 +818,21 @@ fn test_serde() { let hash2: crate::Hash = serde_json::from_str(&json).unwrap(); assert_eq!(hash, hash2); } + +// `cargo +nightly miri test` currently works, but it takes forever, because some of our test +// inputs are quite large. Most of our unsafe code is platform specific and incompatible with Miri +// anyway, but we'd like it to be possible for callers to run their own tests under Miri, assuming +// they don't use incompatible features like Rayon or mmap. This test should get reasonable +// coverage of our public API without using any large inputs, so we can run it in CI and catch +// obvious breaks. (For example, constant_time_eq is not compatible with Miri.) +#[test] +fn test_miri_smoketest() { + let mut hasher = crate::Hasher::new_derive_key("Miri smoketest"); + hasher.update(b"foo"); + #[cfg(feature = "std")] + hasher.update_reader(&b"bar"[..]).unwrap(); + assert_eq!(hasher.finalize(), hasher.finalize()); + let mut reader = hasher.finalize_xof(); + reader.set_position(999999); + reader.fill(&mut [0]); +}