Add test for volatile_set_memory

This commit is contained in:
niluxv 2021-08-23 12:42:13 +02:00
parent 32c2df87be
commit 083e5e604c

View File

@ -1,3 +1,5 @@
#![feature(core_intrinsics)] // for `volatile_set_memory`
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct Foo { struct Foo {
@ -42,4 +44,42 @@ fn main() {
assert_eq!(w[idx].b, 0xcdcdcdcdcdcdcdcd); assert_eq!(w[idx].b, 0xcdcdcdcdcdcdcdcd);
assert_eq!(w[idx].c, 0xcdcdcdcdcdcdcdcd); assert_eq!(w[idx].c, 0xcdcdcdcdcdcdcdcd);
} }
// -----
// `std::intrinsics::volatile_set_memory` should behave identically
let mut v: [u64; LENGTH] = [0; LENGTH];
for idx in 0..LENGTH {
assert_eq!(v[idx], 0);
}
unsafe {
let p = v.as_mut_ptr();
::std::intrinsics::volatile_set_memory(p, 0xab, LENGTH);
}
for idx in 0..LENGTH {
assert_eq!(v[idx], 0xabababababababab);
}
// -----
let mut w: [Foo; LENGTH] = [Foo { a: 0, b: 0, c: 0 }; LENGTH];
for idx in 0..LENGTH {
assert_eq!(w[idx].a, 0);
assert_eq!(w[idx].b, 0);
assert_eq!(w[idx].c, 0);
}
unsafe {
let p = w.as_mut_ptr();
::std::intrinsics::volatile_set_memory(p, 0xcd, LENGTH);
}
for idx in 0..LENGTH {
assert_eq!(w[idx].a, 0xcdcdcdcdcdcdcdcd);
assert_eq!(w[idx].b, 0xcdcdcdcdcdcdcdcd);
assert_eq!(w[idx].c, 0xcdcdcdcdcdcdcdcd);
}
} }