diff options
Diffstat (limited to 'test_ffi/tests/test.js')
| -rw-r--r-- | test_ffi/tests/test.js | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js index ab31dcb83..03c166a7c 100644 --- a/test_ffi/tests/test.js +++ b/test_ffi/tests/test.js @@ -130,6 +130,12 @@ const dylib = Deno.dlopen(libPath, { parameters: ["function"], result: "void", }, + call_fn_ptr_thread_safe: { + name: "call_fn_ptr", + parameters: ["function"], + result: "void", + nonblocking: true, + }, call_fn_ptr_many_parameters: { parameters: ["function"], result: "void", @@ -138,6 +144,11 @@ const dylib = Deno.dlopen(libPath, { parameters: ["function"], result: "void", }, + call_fn_ptr_return_u8_thread_safe: { + name: "call_fn_ptr_return_u8", + parameters: ["function"], + result: "void", + }, call_fn_ptr_return_buffer: { parameters: ["function"], result: "void", @@ -292,15 +303,16 @@ console.log("After sleep_blocking"); console.log(performance.now() - start >= 100); start = performance.now(); -dylib.symbols.sleep_nonblocking(100).then(() => { +const promise_2 = dylib.symbols.sleep_nonblocking(100).then(() => { console.log("After"); console.log(performance.now() - start >= 100); - // Close after task is complete. - cleanup(); }); console.log("Before"); console.log(performance.now() - start < 100); +// Await to make sure `sleep_nonblocking` calls and logs before we proceed +await promise_2; + // Test calls with callback parameters const logCallback = new Deno.UnsafeCallback( { parameters: [], result: "void" }, @@ -376,6 +388,24 @@ dylib.symbols.store_function(ptr(nestedCallback)); dylib.symbols.store_function(null); dylib.symbols.store_function_2(null); +let counter = 0; +const addToFooCallback = new Deno.UnsafeCallback({ + parameters: [], + result: "void", +}, () => counter++); + +// Test thread safe callbacks +console.log("Thread safe call counter:", counter); +addToFooCallback.ref(); +await dylib.symbols.call_fn_ptr_thread_safe(ptr(addToFooCallback)); +addToFooCallback.unref(); +logCallback.ref(); +await dylib.symbols.call_fn_ptr_thread_safe(ptr(logCallback)); +logCallback.unref(); +console.log("Thread safe call counter:", counter); +returnU8Callback.ref(); +await dylib.symbols.call_fn_ptr_return_u8_thread_safe(ptr(returnU8Callback)); + // Test statics console.log("Static u32:", dylib.symbols.static_u32); console.log("Static i64:", dylib.symbols.static_i64); @@ -386,7 +416,7 @@ console.log( const view = new Deno.UnsafePointerView(dylib.symbols.static_ptr); console.log("Static ptr value:", view.getUint32()); -function cleanup() { +(function cleanup() { dylib.close(); throwCallback.close(); logCallback.close(); @@ -395,6 +425,7 @@ function cleanup() { returnBufferCallback.close(); add10Callback.close(); nestedCallback.close(); + addToFooCallback.close(); const resourcesPost = Deno.resources(); @@ -409,4 +440,4 @@ After: ${postStr}`, } console.log("Correct number of resources"); -} +})(); |
