aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2024-03-10 09:50:24 -0700
committerJack O'Connor <[email protected]>2024-03-10 09:54:03 -0700
commit5b9af1c34746e20b4596c1812b683624bdcfc152 (patch)
tree546d201e7e55a60eb2818bcc414fc93c96b4df43
parentd57818afdcf9715aafb1eaf30a34c6fffdb6eed0 (diff)
test_miri_smoketest
-rw-r--r--.github/workflows/ci.yml13
-rw-r--r--src/test.rs18
2 files changed, 31 insertions, 0 deletions
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]);
+}