mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-17 00:00:14 +02:00
Change loom tests to use cfg(loom) internally (#314)
This commit is contained in:
@@ -1427,3 +1427,38 @@ unsafe fn shared_v_drop(data: &mut AtomicPtr<()>, _ptr: *const u8, _len: usize)
|
||||
let shared = (*data.get_mut()) as *mut Shared;
|
||||
release_shared(shared as *mut Shared);
|
||||
}
|
||||
|
||||
// fuzz tests
|
||||
#[cfg(all(test, loom))]
|
||||
mod fuzz {
|
||||
use std::sync::Arc;
|
||||
use loom::thread;
|
||||
|
||||
use crate::Bytes;
|
||||
use super::BytesMut;
|
||||
|
||||
#[test]
|
||||
fn bytes_mut_cloning_frozen() {
|
||||
loom::model(|| {
|
||||
let a = BytesMut::from(&b"abcdefgh"[..]).split().freeze();
|
||||
let addr = a.as_ptr() as usize;
|
||||
|
||||
// test the Bytes::clone is Sync by putting it in an Arc
|
||||
let a1 = Arc::new(a);
|
||||
let a2 = a1.clone();
|
||||
|
||||
let t1 = thread::spawn(move || {
|
||||
let b: Bytes = (*a1).clone();
|
||||
assert_eq!(b.as_ptr() as usize, addr);
|
||||
});
|
||||
|
||||
let t2 = thread::spawn(move || {
|
||||
let b: Bytes = (*a2).clone();
|
||||
assert_eq!(b.as_ptr() as usize, addr);
|
||||
});
|
||||
|
||||
t1.join().unwrap();
|
||||
t2.join().unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user