Skip to content

Commit cade2b9

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 b0d9d86 commit cade2b9

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-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: 33 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
@@ -96,3 +100,31 @@ jobs:
96100
- name: Run integration tests
97101
run:
98102
make integration-tests cargo_flags=--profile=${{ matrix.profile }} test_flags=--nocapture
103+
104+
miri:
105+
strategy:
106+
matrix:
107+
partition: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
108+
109+
runs-on: ubuntu-latest
110+
111+
steps:
112+
- name: Harden the runner (Audit all outbound calls)
113+
uses: step-security/harden-runner@6c439dc8bdf85cadbbce9ed30d1c7b959517bc49 # v2.12.2
114+
with:
115+
egress-policy: audit
116+
117+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
118+
- uses: dtolnay/rust-toolchain@b95584d8105b9ab200e15821fa671848cf2b7017 # nightly
119+
with:
120+
components: "miri, rust-src"
121+
- uses: cargo-bins/cargo-binstall@main
122+
- name: Install cargo-nextest
123+
run: |
124+
cargo binstall cargo-nextest --secure
125+
126+
- name: Run unit tests under Miri
127+
run: |
128+
MIRIFLAGS=-Zmiri-disable-isolation cargo +nightly miri nextest run \
129+
--partition=hash:${{ matrix.partition }}/10 \
130+
--test-threads=$(nproc)

src/database.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ mod tests {
364364
}
365365

366366
#[test]
367+
#[cfg_attr(miri, ignore = "persistence is not implemented with miri")]
367368
fn test_data_persistence() {
368369
let tmp_dir = TempDir::new("test_db").unwrap();
369370
let file_path = tmp_dir.path().join("test.db");

src/meta/mod.rs

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

751751
#[test]
752+
#[cfg_attr(miri, ignore = "persistence is not implemented with miri")]
752753
fn persistence() {
753754
let f = tempfile::tempfile().expect("failed to open temporary file");
754755
let mut manager =
@@ -912,6 +913,7 @@ mod tests {
912913
}
913914

914915
#[test]
916+
#[cfg_attr(miri, ignore = "persistence is not implemented with miri")]
915917
fn crash_recovery() {
916918
let f = tempfile::tempfile().expect("failed to open temporary file");
917919
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)