Skip to content

Commit 48008c5

Browse files
author
SS-42
committed
test(memory): cover slab destroy with foreign live chunk
1 parent 0414810 commit 48008c5

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tests/test_mem.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,26 @@ TEST(slab_reclaim_with_foreign_live_chunk_is_safe) {
575575
PASS();
576576
}
577577

578+
TEST(slab_destroy_with_foreign_live_chunk_is_safe) {
579+
cbm_slab_install();
580+
581+
void *p = cbm_slab_test_malloc(32);
582+
ASSERT_NOT_NULL(p);
583+
memset(p, 0x3C, 32);
584+
585+
atomic_int go;
586+
atomic_init(&go, 0);
587+
slab_cross_thread_free_ctx_t ctx = {.ptr = p, .go = &go};
588+
cbm_thread_t t;
589+
ASSERT_EQ(cbm_thread_create(&t, 0, slab_cross_thread_free_worker, &ctx), 0);
590+
591+
cbm_slab_destroy_thread();
592+
atomic_store_explicit(&go, 1, memory_order_release);
593+
ASSERT_EQ(cbm_thread_join(&t), 0);
594+
595+
PASS();
596+
}
597+
578598
/* ── Parallel extraction integration test ──────────────────── */
579599

580600
static char g_mem_tmpdir[256];
@@ -721,6 +741,7 @@ SUITE(mem) {
721741
RUN_TEST(slab_mixed_alloc_free_stress);
722742
RUN_TEST(slab_cross_thread_free_is_safe);
723743
RUN_TEST(slab_reclaim_with_foreign_live_chunk_is_safe);
744+
RUN_TEST(slab_destroy_with_foreign_live_chunk_is_safe);
724745
/* Integration */
725746
RUN_TEST(parallel_extract_with_slab);
726747
}

0 commit comments

Comments
 (0)