Skip to content

Commit 0d6fe0b

Browse files
committed
Run Miri in a GitHub workflow
Miri is an undefined behavior detection tool for Rust. This PR adds a GitHub workflow that runs TrieDB's tests under Miri to detect potential undefined behavior in the code base.
1 parent f31e31b commit 0d6fe0b

File tree

6 files changed

+83
-2
lines changed

6 files changed

+83
-2
lines changed

.github/workflows/miri.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: PR
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
14+
jobs:
15+
miri:
16+
strategy:
17+
matrix:
18+
partition: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Harden the runner (Audit all outbound calls)
24+
uses: step-security/harden-runner@6c439dc8bdf85cadbbce9ed30d1c7b959517bc49 # v2.12.2
25+
with:
26+
egress-policy: audit
27+
28+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
- uses: dtolnay/rust-toolchain@b95584d8105b9ab200e15821fa671848cf2b7017 # nightly
30+
with:
31+
components: miri
32+
33+
- name: Install cargo-nextest
34+
run: |
35+
cargo install --locked cargo-nextest
36+
37+
- name: Run unit tests under Miri
38+
run: |
39+
MIRIFLAGS=-Zmiri-disable-isolation cargo +nightly miri nextest run \
40+
--partition=hash:${{ matrix.partition }}/10 \
41+
--test-threads=$(nproc)

.github/workflows/pr.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ name: PR
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: [ main ]
66
pull_request:
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
711

812
env:
913
CARGO_TERM_COLOR: always
@@ -117,3 +121,32 @@ jobs:
117121
echo "::error::CLI Cargo.lock is out of date. Please run 'cargo update' in the cli directory and commit the changes."
118122
exit 1
119123
fi
124+
125+
miri:
126+
strategy:
127+
matrix:
128+
partition: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
129+
130+
runs-on: ubuntu-latest
131+
132+
steps:
133+
- name: Harden the runner (Audit all outbound calls)
134+
uses: step-security/harden-runner@6c439dc8bdf85cadbbce9ed30d1c7b959517bc49 # v2.12.2
135+
with:
136+
egress-policy: audit
137+
138+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
139+
140+
- uses: dtolnay/rust-toolchain@b95584d8105b9ab200e15821fa671848cf2b7017 # nightly
141+
with:
142+
components: "miri, rust-src"
143+
- uses: cargo-bins/cargo-binstall@main
144+
- name: Install cargo-nextest
145+
run: |
146+
cargo binstall cargo-nextest --secure
147+
148+
- name: Run unit tests under Miri
149+
run: |
150+
MIRIFLAGS=-Zmiri-disable-isolation PROPTEST_CASES=16 cargo +nightly miri nextest run \
151+
--partition=hash:${{ matrix.partition }}/10 \
152+
--test-threads=$(nproc)

src/database.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ mod tests {
384384
}
385385

386386
#[test]
387+
#[cfg_attr(miri, ignore = "persistence is not implemented with miri")]
387388
fn test_data_persistence() {
388389
let tmp_dir = TempDir::new("test_db").unwrap();
389390
let file_path = tmp_dir.path().join("test.db");

src/executor/threadpool.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ mod tests {
6161
use std::panic;
6262

6363
#[test]
64+
#[cfg_attr(miri, ignore = "crossbeam (used by rayon) does not play nicely with miri")]
6465
fn defer() {
6566
let pool = builder().build().expect("building thread pool failed");
6667
let future = pool.defer(|| 123);
6768
assert_eq!(future.wait(), &123);
6869
}
6970

7071
#[test]
72+
#[cfg_attr(miri, ignore = "crossbeam (used by rayon) does not play nicely with miri")]
7173
fn poisoning() {
7274
let pool = builder().build().expect("building thread pool failed");
7375
let future = pool.defer(|| panic!("something went wrong"));

src/meta/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ mod tests {
675675
use crate::page::page_id;
676676

677677
#[test]
678+
#[cfg_attr(miri, ignore = "persistence is not implemented with miri")]
678679
fn persistence() {
679680
let f = tempfile::tempfile().expect("failed to open temporary file");
680681
let mut manager =
@@ -875,6 +876,7 @@ mod tests {
875876
}
876877

877878
#[test]
879+
#[cfg_attr(miri, ignore = "persistence is not implemented with miri")]
878880
fn crash_recovery() {
879881
let f = tempfile::tempfile().expect("failed to open temporary file");
880882
let mut manager =

src/page/manager/options.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ impl PageManagerOptions {
1818

1919
let max_pages = if cfg!(not(test)) {
2020
Page::MAX_COUNT
21-
} else {
21+
} else if cfg!(not(miri)) {
2222
// Because tests run in parallel, it's easy to exhaust the address space, so use a more
2323
// conservative limit
2424
Page::MAX_COUNT / 1024
25+
} else {
26+
2048
2527
};
2628

2729
Self { open_options, page_count: 0, max_pages }

0 commit comments

Comments
 (0)