Skip to content

Commit

Permalink
ensures that miri also covers the 'no_memory_leak' test
Browse files Browse the repository at this point in the history
  • Loading branch information
pchampin committed Sep 11, 2024
1 parent 815c793 commit d27f233
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ mod test {
}

#[cfg(target_os = "linux")]
#[cfg_attr(miri, ignore)]
#[test]
fn no_memory_leak() {
// performs several MownStr allocation in sequence,
Expand All @@ -482,6 +481,10 @@ mod test {
// If there is no memory leak,
// the increase in memory should be roughly 1 time the allocated size;
// otherwise, it should be roghly 10 times that size.
//
// NB: in miri, the value returned by get_rss_anon is fake,
// so no memory leak will ever be detected;
// but the test is still executed in miri to detect UB.

let m0 = get_rss_anon();
println!("memory = {} kB", m0);
Expand Down Expand Up @@ -514,6 +517,9 @@ mod test {
const CAP: usize = 100_000_000;

fn get_rss_anon() -> usize {
if cfg!(miri) {
return CAP; // return dummy value, as miri can not open files
}
let txt = fs::read_to_string("/proc/self/status").expect("read proc status");
let txt = txt.split("RssAnon:").nth(1).unwrap();
let txt = txt.split(" kB").next().unwrap();
Expand Down

0 comments on commit d27f233

Please sign in to comment.