Skip to content

Commit d8cf8a2

Browse files
committed
run Miri on CI
1 parent 9a51109 commit d8cf8a2

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

.github/workflows/main.yml

+14
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ jobs:
159159
rm -rf /tmp/.buildx-cache
160160
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
161161
162+
miri:
163+
name: Miri
164+
runs-on: ubuntu-latest
165+
steps:
166+
- uses: actions/checkout@v4
167+
with:
168+
submodules: true
169+
- name: Install Rust (rustup)
170+
run: rustup update nightly --no-self-update && rustup default nightly
171+
shell: bash
172+
- run: rustup component add miri
173+
- run: cargo miri setup
174+
- run: ./ci/miri.sh
175+
162176
rustfmt:
163177
name: Rustfmt
164178
runs-on: ubuntu-latest

ci/miri.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
# We need Tree Borrows as some of our raw pointer patterns are not
5+
# compatible with Stacked Borrows.
6+
export MIRIFLAGS="-Zmiri-tree-borrows"
7+
8+
# One target that sets `mem-unaligned` and one that does not,
9+
# and a big-endian target.
10+
TARGETS=(x86_64-unknown-linux-gnu \
11+
armv7-unknown-linux-gnueabihf \
12+
s390x-unknown-linux-gnu)
13+
for TARGET in "${TARGETS[@]}"; do
14+
# Only run the `mem` tests to avoid this taking too long.
15+
cargo miri test --manifest-path testcrate/Cargo.toml --features no-asm --target $TARGET -- mem
16+
done

testcrate/tests/mem.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,13 @@ fn memcmp_eq() {
128128
#[test]
129129
fn memcmp_ne() {
130130
let arr1 @ arr2 = gen_arr::<256>();
131-
for i in 0..256 {
131+
// Reduce iteration count in Miri as it is too slow otherwise.
132+
let limit = if cfg!(miri) { 64 } else { 256 };
133+
for i in 0..limit {
132134
let mut diff_arr = arr1;
133135
diff_arr.0[i] = 127;
134136
let expect = diff_arr.0[i].cmp(&arr2.0[i]);
135-
for k in i + 1..256 {
137+
for k in i + 1..limit {
136138
let result = unsafe { memcmp(diff_arr.0.as_ptr(), arr2.0.as_ptr(), k) };
137139
assert_eq!(expect, result.cmp(&0));
138140
}

0 commit comments

Comments
 (0)