mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-21 16:59:30 +00:00
Hammers one shared context from several threads, alternating the two ABIs of the same library: the native path (EchoRequest struct in, typed EchoResponse* back) and the CBOR path (encoded request in, CBOR map back), each verifying the echoed message round-trips. Exercises the POD deep-copy/free on the way in, the respPod deliver/free on the way out, and the request channel under contention. Run plain or with SAN=address / SAN=thread. Clean at 6 threads x 1500 iters (9000 calls per ABI) under both ASAN and TSAN — no leaks, use-after-free, or data races. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
49 lines
1.5 KiB
Makefile
49 lines
1.5 KiB
Makefile
# Build + run the native/CBOR concurrency stress test for the timer example.
|
|
#
|
|
# make stress # plain build + run
|
|
# make stress SAN=address # AddressSanitizer
|
|
# make stress SAN=thread # ThreadSanitizer
|
|
# make clean
|
|
#
|
|
# Drives the real exported ABI of the timer example library, so it links the
|
|
# same dylib the C/Go consumers do. The library is built from the repo root so
|
|
# its vendored Nimble dependencies resolve.
|
|
|
|
REPO_ROOT := $(abspath ../../..)
|
|
NIM_SRC := $(REPO_ROOT)/examples/timer/timer.nim
|
|
HDR_DIR := $(REPO_ROOT)/examples/timer/c_bindings
|
|
|
|
UNAME_S := $(shell uname -s)
|
|
ifeq ($(UNAME_S),Darwin)
|
|
LIBNAME := libmy_timer.dylib
|
|
RPATH := -Wl,-rpath,.
|
|
else
|
|
LIBNAME := libmy_timer.so
|
|
RPATH := -Wl,-rpath,'$$ORIGIN'
|
|
endif
|
|
|
|
CC ?= cc
|
|
CFLAGS ?= -std=c11 -Wall -Wextra -O1 -g -I$(HDR_DIR)
|
|
NIMFLAGS := --mm:orc -d:chronicles_log_level=WARN --app:lib --noMain \
|
|
--nimMainPrefix:libmy_timer
|
|
|
|
# Optional sanitizer: SAN=address | thread | undefined
|
|
ifneq ($(SAN),)
|
|
SANFLAGS := -fsanitize=$(SAN) -fno-omit-frame-pointer
|
|
CFLAGS += $(SANFLAGS)
|
|
LDSAN := $(SANFLAGS)
|
|
NIMFLAGS += -d:useMalloc --passC:-fsanitize=$(SAN) --passL:-fsanitize=$(SAN)
|
|
endif
|
|
|
|
.PHONY: stress clean
|
|
|
|
$(LIBNAME):
|
|
cd $(REPO_ROOT) && nim c $(NIMFLAGS) -o:$(CURDIR)/$(LIBNAME) $(NIM_SRC)
|
|
|
|
stress: stress.c $(HDR_DIR)/my_timer.h $(LIBNAME)
|
|
$(CC) $(CFLAGS) stress.c -L. -lmy_timer -lpthread $(RPATH) $(LDSAN) -o stress
|
|
./stress
|
|
|
|
clean:
|
|
rm -f stress $(LIBNAME)
|