make uninit_mask a unit test

This commit is contained in:
Ralf Jung 2022-11-06 16:26:02 +01:00
parent 6b7f6b98c7
commit edbbb10477
4 changed files with 22 additions and 29 deletions

View File

@ -2,6 +2,8 @@
mod init_mask;
mod provenance_map;
#[cfg(test)]
mod tests;
use std::borrow::Cow;
use std::fmt;

View File

@ -150,7 +150,7 @@ impl InitMask {
}
#[inline]
fn get(&self, i: Size) -> bool {
pub fn get(&self, i: Size) -> bool {
let (block, bit) = Self::bit_index(i);
(self.blocks[block] & (1 << bit)) != 0
}

View File

@ -0,0 +1,19 @@
use super::*;
#[test]
fn uninit_mask() {
let mut mask = InitMask::new(Size::from_bytes(500), false);
assert!(!mask.get(Size::from_bytes(499)));
mask.set_range(alloc_range(Size::from_bytes(499), Size::from_bytes(1)), true);
assert!(mask.get(Size::from_bytes(499)));
mask.set_range((100..256).into(), true);
for i in 0..100 {
assert!(!mask.get(Size::from_bytes(i)), "{i} should not be set");
}
for i in 100..256 {
assert!(mask.get(Size::from_bytes(i)), "{i} should be set");
}
for i in 256..499 {
assert!(!mask.get(Size::from_bytes(i)), "{i} should not be set");
}
}

View File

@ -1,28 +0,0 @@
// run-pass
// ignore-cross-compile
// ignore-stage1
#![feature(rustc_private)]
extern crate rustc_middle;
extern crate rustc_target;
use rustc_middle::mir::interpret::InitMask;
use rustc_target::abi::Size;
fn main() {
let mut mask = InitMask::new(Size::from_bytes(500), false);
assert!(!mask.get(Size::from_bytes(499)));
mask.set(Size::from_bytes(499), true);
assert!(mask.get(Size::from_bytes(499)));
mask.set_range_inbounds(Size::from_bytes(100), Size::from_bytes(256), true);
for i in 0..100 {
assert!(!mask.get(Size::from_bytes(i)));
}
for i in 100..256 {
assert!(mask.get(Size::from_bytes(i)));
}
for i in 256..499 {
assert!(!mask.get(Size::from_bytes(i)));
}
}