test(pool): run C pool tests through the Rust implementation
Link poolTests against the multithreaded object set and Rust static archive,
so its C callbacks exercise the migrated pool rather than compiling a private
C implementation. Preserve ZSTD_MULTITHREAD for the test translation unit;
without it, its pthread test helpers become no-ops while the Rust pool runs
concurrently. Add a Rust regression for draining a small queue after reducing
the worker limit.
Test Plan:
- cargo clippy
- cargo clippy --benches
- cargo clippy --tests
- cargo +nightly fmt
- cargo test shrinking_the_limit_keeps_draining_a_small_queue -- --nocapture
- make -B -C tests poolTests && timeout 20s stdbuf -oL ./tests/poolTests
Refs: Rust pool migration 26b5e202
This commit is contained in:
@@ -664,6 +664,46 @@ mod tests {
|
||||
assert_eq!(count.load(Ordering::Relaxed), 16);
|
||||
}
|
||||
|
||||
unsafe extern "C" fn delayed_increment(opaque: *mut c_void) {
|
||||
thread::sleep(Duration::from_millis(10));
|
||||
unsafe { increment(opaque) };
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shrinking_the_limit_keeps_draining_a_small_queue() {
|
||||
let ctx = POOL_create(4, 2);
|
||||
assert!(!ctx.is_null());
|
||||
let count = AtomicUsize::new(0);
|
||||
|
||||
for _ in 0..16 {
|
||||
unsafe {
|
||||
POOL_add(
|
||||
ctx,
|
||||
delayed_increment,
|
||||
ptr::from_ref(&count).cast_mut().cast(),
|
||||
)
|
||||
};
|
||||
}
|
||||
unsafe { POOL_joinJobs(ctx) };
|
||||
assert_eq!(count.load(Ordering::Relaxed), 16);
|
||||
|
||||
assert_eq!(unsafe { POOL_resize(ctx, 2) }, 0);
|
||||
for _ in 0..16 {
|
||||
unsafe {
|
||||
POOL_add(
|
||||
ctx,
|
||||
delayed_increment,
|
||||
ptr::from_ref(&count).cast_mut().cast(),
|
||||
)
|
||||
};
|
||||
}
|
||||
unsafe {
|
||||
POOL_joinJobs(ctx);
|
||||
POOL_free(ctx);
|
||||
}
|
||||
assert_eq!(count.load(Ordering::Relaxed), 32);
|
||||
}
|
||||
|
||||
struct AllocStats {
|
||||
allocations: AtomicUsize,
|
||||
frees: AtomicUsize,
|
||||
|
||||
+3
-2
@@ -324,8 +324,9 @@ decodecorpus : LDLIBS += -lm
|
||||
decodecorpus : $(filter-out zstdc_zstd_compress.o, $(ZSTD_OBJECTS)) $(ZDICT_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c decodecorpus.c
|
||||
|
||||
CLEAN += poolTests
|
||||
poolTests : $(PRGDIR)/util.c $(PRGDIR)/timefn.c poolTests.c $(LIB_SRCDIR)/common/pool.c $(LIB_SRCDIR)/common/threading.c $(LIB_SRCDIR)/common/zstd_common.c $(LIB_SRCDIR)/common/error_private.c
|
||||
$(LINK.c) $(MULTITHREAD) $^ -o $@$(EXT)
|
||||
poolTests : CPPFLAGS += -D_POSIX_C_SOURCE=200809L $(MULTITHREAD_CPP)
|
||||
poolTests : $(ZSTDMT_OBJECTS) $(PRGDIR)/util.c $(PRGDIR)/timefn.c poolTests.c
|
||||
$(LINK.c) $(MULTITHREAD_LD) $^ -o $@$(EXT)
|
||||
|
||||
# These static C test executables exercise Rust replacements. The normal
|
||||
# prerequisite is also an archive input, placed after C sources by `$^`, and
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "timefn.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#define ASSERT_TRUE(p) \
|
||||
do { \
|
||||
|
||||
Reference in New Issue
Block a user