diff --git a/ffi.nimble b/ffi.nimble index 0d323ca..12c9f3a 100644 --- a/ffi.nimble +++ b/ffi.nimble @@ -90,8 +90,11 @@ task test_cpp_e2e, "Build and run the C++ end-to-end tests for the timer example runOrQuit "nimble genbindings_cpp" runOrQuit "nimble genbindings_cpp_echo" runOrQuit "cmake -S tests/e2e/cpp -B tests/e2e/cpp/build" - runOrQuit "cmake --build tests/e2e/cpp/build" - runOrQuit "ctest --test-dir tests/e2e/cpp/build --output-on-failure" + runOrQuit "cmake --build tests/e2e/cpp/build --config Debug" + # `-C Debug` is required on Windows multi-config generators because + # gtest_discover_tests(PRE_TEST) loads per-config include files; harmless on + # single-config generators (Make/Ninja) on Linux/macOS. + runOrQuit "ctest --test-dir tests/e2e/cpp/build --output-on-failure -C Debug" task test_sanitized, "Run all unit tests under a sanitizer (NIM_FFI_SAN) and mm (NIM_FFI_MM)": @@ -124,8 +127,8 @@ task test_cpp_e2e_sanitized, runOrQuit "nimble genbindings_cpp_echo" runOrQuit "cmake -S tests/e2e/cpp -B tests/e2e/cpp/build" & " -DNIM_FFI_MM=" & mm & " -DNIM_FFI_SANITIZER=" & san - runOrQuit "cmake --build tests/e2e/cpp/build -j" - runOrQuit "ctest --test-dir tests/e2e/cpp/build --output-on-failure" + runOrQuit "cmake --build tests/e2e/cpp/build --config Debug -j" + runOrQuit "ctest --test-dir tests/e2e/cpp/build --output-on-failure -C Debug" task genbindings_example, "Generate Rust bindings for the timer example": exec "nim c " & nimFlagsOrc & diff --git a/ffi/ffi_events.nim b/ffi/ffi_events.nim index ba5b3d0..898746c 100644 --- a/ffi/ffi_events.nim +++ b/ffi/ffi_events.nim @@ -233,6 +233,7 @@ template enqueueOrMarkStuck( if not ffiCurrentNotifyEventEnqueued.isNil(): ffiCurrentNotifyEventEnqueued() +template dispatchFFIEvent*(eventName: string, body: untyped) = ## `body` must yield `string` / `seq[byte]`. FFI thread only: encodes into ## a `c_malloc` buffer and enqueues; the event thread fans out to listeners. block: diff --git a/ffi/ffi_thread.nim b/ffi/ffi_thread.nim index 94f561d..9685a45 100644 --- a/ffi/ffi_thread.nim +++ b/ffi/ffi_thread.nim @@ -56,7 +56,8 @@ proc processRequest[T]( ## Invoked within the FFI thread to process a request coming from the FFI API consumer thread. let reqId = $request[].reqId - let reqIdCs = reqId.cstring # keeps reqId alive; implicit string→cstring is a warning. + let reqIdCs = reqId.cstring + # keeps reqId alive; implicit string→cstring is a warning. let retFut = if not ctx[].registeredRequests[].contains(reqIdCs): diff --git a/tests/unit/test_event_thread.nim b/tests/unit/test_event_thread.nim index 51f8829..1b5f252 100644 --- a/tests/unit/test_event_thread.nim +++ b/tests/unit/test_event_thread.nim @@ -130,9 +130,8 @@ suite "event delivery is asynchronous": setupCallbackData(rsp) withPool(ctx): - discard addEventListener( - ctx[].eventRegistry, "latch", captureThreadIdCb, addr evt - ) + discard + addEventListener(ctx[].eventRegistry, "latch", captureThreadIdCb, addr evt) check sendRequestToFFIThread( ctx, CaptureFfiTidRequest.ffiNewReq(captureCb, addr rsp) @@ -164,9 +163,7 @@ suite "FFI thread independence": setupCallbackData(rsp) withPool(ctx): - discard addEventListener( - ctx[].eventRegistry, "latch", slowSleepCb, nil - ) + discard addEventListener(ctx[].eventRegistry, "latch", slowSleepCb, nil) check sendRequestToFFIThread( ctx, EmitLatchEvent.ffiNewReq(captureCb, addr rsp, 0) @@ -178,8 +175,7 @@ suite "FFI thread independence": # chronos's `Moment` — std/times exports a `milliseconds` that # shadows chronos's at this generic-instantiation site. let started = Moment.now() - check sendRequestToFFIThread(ctx, PingEvent.ffiNewReq(captureCb, addr rsp)) - .isOk() + check sendRequestToFFIThread(ctx, PingEvent.ffiNewReq(captureCb, addr rsp)).isOk() waitCallback(rsp) let elapsed = Moment.now() - started @@ -212,8 +208,7 @@ when not defined(gcRefc): # Wedge long enough to cross at least one tick boundary. gBlockingEnabled.store(true) let wedgeMs = - (EventThreadTickInterval + FFIHeartbeatStaleThreshold).milliseconds.int + - 1500 + (EventThreadTickInterval + FFIHeartbeatStaleThreshold).milliseconds.int + 1500 check sendRequestToFFIThread( ctx, BlockingRequest.ffiNewReq(captureCb, addr rsp, wedgeMs) ) @@ -277,9 +272,7 @@ suite "queue overflow": setupCallbackData(rejected) withPool(ctx): - discard addEventListener( - ctx[].eventRegistry, "latch", backpressureCb, addr bp - ) + discard addEventListener(ctx[].eventRegistry, "latch", backpressureCb, addr bp) discard addEventListener( ctx[].eventRegistry, NotRespondingEventName, captureCb, addr notif )