mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
use stack/heap memory instead of mmap for roc test
This commit is contained in:
parent
f7452b8889
commit
e67e968ba1
2 changed files with 10 additions and 63 deletions
|
@ -401,40 +401,12 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
|
||||||
|
|
||||||
let mut writer = std::io::stdout();
|
let mut writer = std::io::stdout();
|
||||||
|
|
||||||
// IMPORTANT: shared memory object names must begin with / and contain no other slashes!
|
let mut shared_buffer = vec![0u8; SHM_SIZE as usize];
|
||||||
let name = "/roc_expect_buffex";
|
|
||||||
let cstring = CString::new(name).unwrap();
|
|
||||||
|
|
||||||
let shared_ptr = unsafe {
|
let set_shared_buffer = run_roc_dylib!(lib, "set_shared_buffer", (*mut u8, usize), ());
|
||||||
let flags = libc::O_RDWR | libc::O_CREAT;
|
|
||||||
let shared_fd = libc::shm_open(cstring.as_ptr().cast(), flags, 0o666);
|
|
||||||
|
|
||||||
libc::ftruncate(shared_fd, SHM_SIZE);
|
|
||||||
|
|
||||||
let ptr = libc::mmap(
|
|
||||||
std::ptr::null_mut(),
|
|
||||||
SHM_SIZE as usize,
|
|
||||||
libc::PROT_READ | libc::PROT_WRITE,
|
|
||||||
libc::MAP_SHARED,
|
|
||||||
shared_fd,
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
|
|
||||||
if ptr as isize == -1 {
|
|
||||||
internal_error!(
|
|
||||||
"could not set up the expect shared memory region: {:?}",
|
|
||||||
std::io::Error::last_os_error()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr.cast()
|
|
||||||
};
|
|
||||||
|
|
||||||
// communicate the mmapped name to zig/roc
|
|
||||||
let set_mmapped_file = run_roc_dylib!(lib, "set_mmapped_file", (*const i8, usize), ());
|
|
||||||
let mut result = RocCallResult::default();
|
let mut result = RocCallResult::default();
|
||||||
unsafe { set_mmapped_file((cstring.as_ptr(), name.len() + 1), &mut result) };
|
let slice = (shared_buffer.as_mut_ptr(), shared_buffer.len());
|
||||||
std::mem::forget(cstring);
|
unsafe { set_shared_buffer(slice, &mut result) };
|
||||||
|
|
||||||
let (failed, passed) = roc_repl_expect::run::run_expects(
|
let (failed, passed) = roc_repl_expect::run::run_expects(
|
||||||
&mut writer,
|
&mut writer,
|
||||||
|
@ -443,7 +415,7 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
|
||||||
interns,
|
interns,
|
||||||
&lib,
|
&lib,
|
||||||
&mut expectations,
|
&mut expectations,
|
||||||
shared_ptr,
|
shared_buffer.as_mut_ptr(),
|
||||||
expects,
|
expects,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -144,39 +144,14 @@ mod test {
|
||||||
let arena = &bumpalo::Bump::new();
|
let arena = &bumpalo::Bump::new();
|
||||||
let interns = arena.alloc(interns);
|
let interns = arena.alloc(interns);
|
||||||
|
|
||||||
// IMPORTANT: shared memory object names must begin with / and contain no other slashes!
|
const BUFFER_SIZE: usize = 1024;
|
||||||
let name = format!("/roc_expect_{}", src_hash(source));
|
|
||||||
let cstring = CString::new(&*name).unwrap();
|
|
||||||
|
|
||||||
const SHM_SIZE: i64 = 4096;
|
let mut shared_buffer = [0u8; BUFFER_SIZE];
|
||||||
|
|
||||||
let shared_ptr = unsafe {
|
|
||||||
let shared_fd =
|
|
||||||
libc::shm_open(cstring.as_ptr().cast(), libc::O_RDWR | libc::O_CREAT, 0o666);
|
|
||||||
|
|
||||||
libc::ftruncate(shared_fd, SHM_SIZE);
|
|
||||||
|
|
||||||
let ptr = libc::mmap(
|
|
||||||
std::ptr::null_mut(),
|
|
||||||
SHM_SIZE as usize,
|
|
||||||
libc::PROT_READ | libc::PROT_WRITE,
|
|
||||||
libc::MAP_SHARED,
|
|
||||||
shared_fd,
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
|
|
||||||
if ptr as isize == -1 {
|
|
||||||
panic!("could not set up the expect shared memory region")
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr.cast()
|
|
||||||
};
|
|
||||||
|
|
||||||
// communicate the mmapped name to zig/roc
|
// communicate the mmapped name to zig/roc
|
||||||
let set_mmapped_file = run_roc_dylib!(lib, "set_shared_buffer", (*mut u8, usize), ());
|
let set_shared_buffer = run_roc_dylib!(lib, "set_shared_buffer", (*mut u8, usize), ());
|
||||||
let mut result = RocCallResult::default();
|
let mut result = RocCallResult::default();
|
||||||
unsafe { set_mmapped_file((shared_ptr, SHM_SIZE as usize), &mut result) };
|
unsafe { set_shared_buffer((shared_buffer.as_mut_ptr(), BUFFER_SIZE), &mut result) };
|
||||||
std::mem::forget(cstring);
|
|
||||||
|
|
||||||
let mut writer = Vec::with_capacity(1024);
|
let mut writer = Vec::with_capacity(1024);
|
||||||
let (_failed, _passed) = crate::run::run_expects(
|
let (_failed, _passed) = crate::run::run_expects(
|
||||||
|
@ -186,7 +161,7 @@ mod test {
|
||||||
interns,
|
interns,
|
||||||
&lib,
|
&lib,
|
||||||
&mut expectations,
|
&mut expectations,
|
||||||
shared_ptr,
|
shared_buffer.as_mut_ptr(),
|
||||||
expects,
|
expects,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue