working expects in roc dev

This commit is contained in:
Folkert 2022-10-05 20:57:37 +02:00
parent 67494e9df2
commit 8c4a2f58fc
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
10 changed files with 129 additions and 21 deletions

View file

@ -21,3 +21,33 @@ pub fn setSharedBuffer(ptr: [*]u8, length: usize) callconv(.C) usize {
pub fn expectFailedStart() callconv(.C) [*]u8 {
return SHARED_BUFFER.ptr;
}
extern fn shm_open(name: *const i8, oflag: c_int, mode: c_uint) c_int;
extern fn mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int, fd: c_int, offset: c_uint) *anyopaque;
extern fn kill(pid: c_int, sig: c_int) c_int;
extern fn getppid() c_int;
pub fn readSharedBufferEnv() callconv(.C) void {
const name = "/roc_expect_buffer"; // IMPORTANT: shared memory object names must begin with / and contain no other slashes!
const shared_fd = shm_open(@ptrCast(*const i8, name), O_RDWR | O_CREAT, 0o666);
const length = 4096;
const shared_ptr = mmap(
null,
length,
PROT_WRITE,
MAP_SHARED,
shared_fd,
0,
);
const ptr = @ptrCast([*]u8, shared_ptr);
SHARED_BUFFER = ptr[0..length];
}
pub fn expectFailedFinalize() callconv(.C) void {
const parent_pid = getppid();
_ = kill(parent_pid, SIGUSR1);
}

View file

@ -168,9 +168,13 @@ comptime {
if (builtin.target.cpu.arch != .wasm32) {
exportUtilsFn(expect.expectFailedStart, "expect_failed_start");
exportUtilsFn(expect.expectFailedFinalize, "expect_failed_finalize");
// sets the buffer used for expect failures
@export(expect.setSharedBuffer, .{ .name = "set_shared_buffer", .linkage = .Weak });
//
exportUtilsFn(expect.readSharedBufferEnv, "read_env_shared_buffer");
}
if (builtin.target.cpu.arch == .aarch64) {