Make "cargo miri test" actually run

This commit is contained in:
bakaq
2024-01-09 02:37:38 -03:00
parent f9eadc8e6a
commit f02c0eacd8
17 changed files with 51 additions and 8 deletions

View File

@@ -821,9 +821,9 @@ impl AllocSlab {
} }
fn payload_offset<T>(&self) -> *mut T { fn payload_offset<T>(&self) -> *mut T {
let mut ptr = (self as *const AllocSlab) as usize; // This looks really scary, should this method be marked as unsafe?
ptr += mem::size_of::<AllocSlab>(); // Also, this seems to cause UB.
ptr as *mut T unsafe { (self as *const AllocSlab).add(1) as *mut T }
} }
} }
@@ -864,6 +864,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn heap_cell_value_const_cast() { fn heap_cell_value_const_cast() {
let mut wam = MockWAM::new(); let mut wam = MockWAM::new();
#[cfg(target_pointer_width = "32")] #[cfg(target_pointer_width = "32")]
@@ -907,6 +908,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on arena.rs UB")]
fn heap_put_literal_tests() { fn heap_put_literal_tests() {
let mut wam = MockWAM::new(); let mut wam = MockWAM::new();

View File

@@ -239,6 +239,7 @@ impl Atom {
} else if let Some(ptr) = self.as_ptr() { } else if let Some(ptr) = self.as_ptr() {
AtomString::Dynamic(AtomTableRef::map(ptr, |ptr| { AtomString::Dynamic(AtomTableRef::map(ptr, |ptr| {
let header = let header =
// Miri seems to hit this line a lot
unsafe { ptr::read::<AtomHeader>(ptr as *const u8 as *const AtomHeader) }; unsafe { ptr::read::<AtomHeader>(ptr as *const u8 as *const AtomHeader) };
let len = header.len() as usize; let len = header.len() as usize;
let buf = unsafe { (ptr as *const u8).add(mem::size_of::<AtomHeader>()) }; let buf = unsafe { (ptr as *const u8).add(mem::size_of::<AtomHeader>()) };
@@ -265,7 +266,7 @@ impl Atom {
unsafe fn write_to_ptr(string: &str, ptr: *mut u8) { unsafe fn write_to_ptr(string: &str, ptr: *mut u8) {
ptr::write(ptr as *mut _, AtomHeader::build_with(string.len() as u64)); ptr::write(ptr as *mut _, AtomHeader::build_with(string.len() as u64));
let str_ptr = (ptr as usize + mem::size_of::<AtomHeader>()) as *mut u8; let str_ptr = ptr.add(mem::size_of::<AtomHeader>());
ptr::copy_nonoverlapping(string.as_ptr(), str_ptr, string.len()); ptr::copy_nonoverlapping(string.as_ptr(), str_ptr, string.len());
} }

View File

@@ -685,6 +685,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn heap_stackless_iter_tests() { fn heap_stackless_iter_tests() {
let mut wam = MockWAM::new(); let mut wam = MockWAM::new();
@@ -1756,6 +1757,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on atom_table.rs UB")]
fn heap_stackful_iter_tests() { fn heap_stackful_iter_tests() {
let mut wam = MockWAM::new(); let mut wam = MockWAM::new();
@@ -2348,6 +2350,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on atom_table.rs UB")]
fn heap_stackful_post_order_iter() { fn heap_stackful_post_order_iter() {
let mut wam = MockWAM::new(); let mut wam = MockWAM::new();
@@ -2831,6 +2834,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on atom_table.rs UB")]
fn heap_stackless_post_order_iter() { fn heap_stackless_post_order_iter() {
let mut wam = MockWAM::new(); let mut wam = MockWAM::new();

View File

@@ -1835,6 +1835,7 @@ mod tests {
use crate::machine::mock_wam::*; use crate::machine::mock_wam::*;
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn term_printing_tests() { fn term_printing_tests() {
let mut wam = MockWAM::new(); let mut wam = MockWAM::new();

View File

@@ -1423,6 +1423,7 @@ mod tests {
use crate::machine::mock_wam::*; use crate::machine::mock_wam::*;
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn arith_eval_by_metacall_tests() { fn arith_eval_by_metacall_tests() {
let mut wam = MachineState::new(); let mut wam = MachineState::new();
let mut op_dir = default_op_dir(); let mut op_dir = default_op_dir();

View File

@@ -398,6 +398,7 @@ mod tests {
use crate::machine::mock_wam::*; use crate::machine::mock_wam::*;
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on atom_table.rs UB")]
fn copier_tests() { fn copier_tests() {
let mut wam = MockWAM::new(); let mut wam = MockWAM::new();

View File

@@ -369,6 +369,7 @@ mod tests {
use crate::machine::mock_wam::*; use crate::machine::mock_wam::*;
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn heap_marking_tests() { fn heap_marking_tests() {
let mut wam = MockWAM::new(); let mut wam = MockWAM::new();

View File

@@ -236,6 +236,7 @@ mod tests {
use crate::machine::{QueryMatch, QueryResolution, Value}; use crate::machine::{QueryMatch, QueryResolution, Value};
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn programatic_query() { fn programatic_query() {
let mut machine = Machine::new_lib(); let mut machine = Machine::new_lib();
@@ -275,6 +276,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn failing_query() { fn failing_query() {
let mut machine = Machine::new_lib(); let mut machine = Machine::new_lib();
let query = String::from(r#"triple("a",P,"b")."#); let query = String::from(r#"triple("a",P,"b")."#);
@@ -288,6 +290,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)]
fn complex_results() { fn complex_results() {
let mut machine = Machine::new_lib(); let mut machine = Machine::new_lib();
machine.load_module_string( machine.load_module_string(
@@ -344,6 +347,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn empty_predicate() { fn empty_predicate() {
let mut machine = Machine::new_lib(); let mut machine = Machine::new_lib();
machine.load_module_string( machine.load_module_string(
@@ -359,6 +363,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn list_results() { fn list_results() {
let mut machine = Machine::new_lib(); let mut machine = Machine::new_lib();
machine.load_module_string( machine.load_module_string(
@@ -387,6 +392,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn consult() { fn consult() {
let mut machine = Machine::new_lib(); let mut machine = Machine::new_lib();
@@ -445,6 +451,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn integration_test() { fn integration_test() {
let mut machine = Machine::new_lib(); let mut machine = Machine::new_lib();
@@ -486,6 +493,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn findall() { fn findall() {
let mut machine = Machine::new_lib(); let mut machine = Machine::new_lib();

View File

@@ -260,6 +260,7 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn unify_tests() { fn unify_tests() {
let mut wam = MachineState::new(); let mut wam = MachineState::new();
let mut op_dir = default_op_dir(); let mut op_dir = default_op_dir();
@@ -481,6 +482,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn test_unify_with_occurs_check() { fn test_unify_with_occurs_check() {
let mut wam = MachineState::new(); let mut wam = MachineState::new();
let mut op_dir = default_op_dir(); let mut op_dir = default_op_dir();

View File

@@ -785,6 +785,7 @@ mod test {
use crate::machine::mock_wam::*; use crate::machine::mock_wam::*;
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn pstr_iter_tests() { fn pstr_iter_tests() {
let mut wam = MockWAM::new(); let mut wam = MockWAM::new();

View File

@@ -189,7 +189,7 @@ impl Stack {
for idx in 0..num_cells { for idx in 0..num_cells {
ptr::write( ptr::write(
(new_ptr as usize + offset) as *mut HeapCellValue, new_ptr.add(offset) as *mut HeapCellValue,
stack_loc_as_cell!(AndFrame, e, idx + 1), stack_loc_as_cell!(AndFrame, e, idx + 1),
); );
@@ -242,7 +242,8 @@ impl Stack {
#[inline(always)] #[inline(always)]
pub(crate) fn index_and_frame_mut(&mut self, e: usize) -> &mut AndFrame { pub(crate) fn index_and_frame_mut(&mut self, e: usize) -> &mut AndFrame {
unsafe { unsafe {
let ptr = self.buf.base as usize + e; // This is doing alignment wrong
let ptr = self.buf.base.add(e);
&mut *(ptr as *mut AndFrame) &mut *(ptr as *mut AndFrame)
} }
} }
@@ -280,6 +281,7 @@ mod tests {
use crate::machine::mock_wam::*; use crate::machine::mock_wam::*;
#[test] #[test]
#[cfg_attr(miri, ignore)]
fn stack_tests() { fn stack_tests() {
let mut wam = MockWAM::new(); let mut wam = MockWAM::new();

View File

@@ -469,6 +469,7 @@ macro_rules! arena_allocated_impl_for_stream {
#[inline] #[inline]
fn copy_to_arena(self, dst: *mut Self) -> Self::PtrToAllocated { fn copy_to_arena(self, dst: *mut Self) -> Self::PtrToAllocated {
unsafe { unsafe {
// Miri seems to hit this a lot
ptr::write(dst, self); ptr::write(dst, self);
TypedArenaPtr::new(dst as *mut Self) TypedArenaPtr::new(dst as *mut Self)
} }

View File

@@ -377,6 +377,7 @@ mod tests {
use std::io::Cursor; use std::io::Cursor;
#[test] #[test]
#[cfg_attr(miri, ignore = "slow and not very relevant")]
fn plain_string() { fn plain_string() {
let mut read_string = CharReader::new(Cursor::new("a string")); let mut read_string = CharReader::new(Cursor::new("a string"));
@@ -389,6 +390,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "slow and not very relevant")]
fn greek_string() { fn greek_string() {
let mut read_string = CharReader::new(Cursor::new("λέξη")); let mut read_string = CharReader::new(Cursor::new("λέξη"));
@@ -401,6 +403,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "slow and not very relevant")]
fn russian_string() { fn russian_string() {
let mut read_string = CharReader::new(Cursor::new("слово")); let mut read_string = CharReader::new(Cursor::new("слово"));
@@ -413,6 +416,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "slow and not very relevant")]
fn greek_lorem_ipsum() { fn greek_lorem_ipsum() {
let lorem_ipsum = "Λορεμ ιπσθμ δολορ σιτ αμετ, οφφενδιτ let lorem_ipsum = "Λορεμ ιπσθμ δολορ σιτ αμετ, οφφενδιτ
εφφιcιενδι σιτ ει, ηαρθμ λεγερε αερενδθμ ιθσ νε. Ηασ νο εροσ εφφιcιενδι σιτ ει, ηαρθμ λεγερε αερενδθμ ιθσ νε. Ηασ νο εροσ
@@ -484,6 +488,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "slow and not very relevant")]
fn armenian_lorem_ipsum() { fn armenian_lorem_ipsum() {
let lorem_ipsum = "լոռեմ իպսում դոլոռ սիթ ամեթ, նովում գռաեծո let lorem_ipsum = "լոռեմ իպսում դոլոռ սիթ ամեթ, նովում գռաեծո
սեա եա, աբհոռռեանթ դիսպութանդո եի քուի. իդ քուոդ ինդոծթում սեա եա, աբհոռռեանթ դիսպութանդո եի քուի. իդ քուոդ ինդոծթում
@@ -557,6 +562,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(miri, ignore = "slow and not very relevant")]
fn russian_lorem_ipsum() { fn russian_lorem_ipsum() {
let lorem_ipsum = "Лорем ипсум долор сит амет, атяуи дицам еи let lorem_ipsum = "Лорем ипсум долор сит амет, атяуи дицам еи
сит, ид сеа фацилис елаборарет. Меа еу яуас алияуид, те яуи сит, ид сеа фацилис елаборарет. Меа еу яуас алияуид, те яуи

View File

@@ -43,7 +43,7 @@ impl<T: RawBlockTraits> RawBlock<T> {
let layout = alloc::Layout::from_size_align_unchecked(cap, T::align()); let layout = alloc::Layout::from_size_align_unchecked(cap, T::align());
self.base = alloc::alloc(layout) as *const _; self.base = alloc::alloc(layout) as *const _;
self.top = (self.base as usize + cap) as *const _; self.top = self.base.add(cap);
*self.ptr.get_mut() = self.base as *mut _; *self.ptr.get_mut() = self.base as *mut _;
} }
@@ -98,7 +98,7 @@ impl<T: RawBlockTraits> RawBlock<T> {
pub unsafe fn alloc(&self, size: usize) -> *mut u8 { pub unsafe fn alloc(&self, size: usize) -> *mut u8 {
if self.free_space() >= size { if self.free_space() >= size {
let ptr = *self.ptr.get(); let ptr = *self.ptr.get();
*self.ptr.get() = (ptr as usize + size) as *mut _; *self.ptr.get() = ptr.add(size) as *mut _;
ptr ptr
} else { } else {
ptr::null_mut() ptr::null_mut()

View File

@@ -4,6 +4,7 @@ use serial_test::serial;
// issue #831 // issue #831
#[serial] #[serial]
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn call_0() { fn call_0() {
load_module_test( load_module_test(
"tests-pl/issue831-call0.pl", "tests-pl/issue831-call0.pl",

View File

@@ -13,6 +13,7 @@ mod src_tests;
/// to re-generate all reference output files run `TRYCMD=overwrite cargo test -- cli_test` /// to re-generate all reference output files run `TRYCMD=overwrite cargo test -- cli_test`
/// then check that the changes are as expected e.g. by looking at the `git diff` /// then check that the changes are as expected e.g. by looking at the `git diff`
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on crossbeam UB")]
fn cli_tests() { fn cli_tests() {
trycmd::TestCases::new() trycmd::TestCases::new()
.default_bin_name("scryer-prolog") .default_bin_name("scryer-prolog")

View File

@@ -3,30 +3,35 @@ use serial_test::serial;
#[serial] #[serial]
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn builtins() { fn builtins() {
load_module_test("src/tests/builtins.pl", ""); load_module_test("src/tests/builtins.pl", "");
} }
#[serial] #[serial]
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn call_with_inference_limit() { fn call_with_inference_limit() {
load_module_test("src/tests/call_with_inference_limit.pl", ""); load_module_test("src/tests/call_with_inference_limit.pl", "");
} }
#[serial] #[serial]
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn facts() { fn facts() {
load_module_test("src/tests/facts.pl", ""); load_module_test("src/tests/facts.pl", "");
} }
#[serial] #[serial]
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn hello_world() { fn hello_world() {
load_module_test("src/tests/hello_world.pl", "Hello World!\n"); load_module_test("src/tests/hello_world.pl", "Hello World!\n");
} }
#[serial] #[serial]
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn syntax_error() { fn syntax_error() {
load_module_test( load_module_test(
"tests-pl/syntax_error.pl", "tests-pl/syntax_error.pl",
@@ -36,18 +41,21 @@ fn syntax_error() {
#[serial] #[serial]
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn predicates() { fn predicates() {
load_module_test("src/tests/predicates.pl", ""); load_module_test("src/tests/predicates.pl", "");
} }
#[serial] #[serial]
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn rules() { fn rules() {
load_module_test("src/tests/rules.pl", ""); load_module_test("src/tests/rules.pl", "");
} }
#[serial] #[serial]
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn setup_call_cleanup_load() { fn setup_call_cleanup_load() {
load_module_test( load_module_test(
"src/tests/setup_call_cleanup.pl", "src/tests/setup_call_cleanup.pl",
@@ -57,12 +65,14 @@ fn setup_call_cleanup_load() {
#[serial] #[serial]
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn clpz_load() { fn clpz_load() {
load_module_test("src/tests/clpz/test_clpz.pl", ""); load_module_test("src/tests/clpz/test_clpz.pl", "");
} }
#[serial] #[serial]
#[test] #[test]
#[cfg_attr(miri, ignore = "blocked on streams.rs UB")]
fn iso_conformity_tests() { fn iso_conformity_tests() {
load_module_test("tests-pl/iso-conformity-tests.pl", "All tests passed"); load_module_test("tests-pl/iso-conformity-tests.pl", "All tests passed");
} }