Skip to content

Commit 01c90a6

Browse files
committed
run Miri on CI
1 parent c84d03c commit 01c90a6

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

.github/workflows/main.yml

Lines changed: 14 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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

Lines changed: 4 additions & 2 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy