diff options
author | Qi Wang <interwq@gwu.edu> | 2017-03-30 00:00:52 (GMT) |
---|---|---|
committer | Qi Wang <interwq@gmail.com> | 2017-04-04 07:34:49 (GMT) |
commit | d3cda3423cd7ae47630833e4a888bdaf6a7bf8d9 (patch) | |
tree | 2d2d1200ae1c7a84201fed491bb9477d5c46339a /test | |
parent | 51d368295032910577d4f34b9ff99b3ed41544b9 (diff) | |
download | jemalloc-d3cda3423cd7ae47630833e4a888bdaf6a7bf8d9.zip jemalloc-d3cda3423cd7ae47630833e4a888bdaf6a7bf8d9.tar.gz jemalloc-d3cda3423cd7ae47630833e4a888bdaf6a7bf8d9.tar.bz2 |
Do proper cleanup for tsd_state_reincarnated.
Also enable arena_bind under non-nominal state, as the cleanup will be handled
correctly now.
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/tsd.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/test/unit/tsd.c b/test/unit/tsd.c index ae47d23..e033bb7 100644 --- a/test/unit/tsd.c +++ b/test/unit/tsd.c @@ -90,6 +90,44 @@ TEST_BEGIN(test_tsd_sub_thread) { } TEST_END +static void * +thd_start_reincarnated(void *arg) { + tsd_t *tsd = tsd_fetch(); + assert(tsd); + + void *p = malloc(1); + assert_ptr_not_null(p, "Unexpected malloc() failure"); + + /* Manually trigger reincarnation. */ + assert_ptr_not_null(tsd->arena, "Should have tsd arena set."); + tsd_cleanup((void *)tsd); + assert_ptr_null(tsd->arena, "TSD arena should have been cleared."); + assert_u_eq(tsd->state, tsd_state_purgatory, + "TSD state should be purgatory\n"); + + free(p); + assert_u_eq(tsd->state, tsd_state_reincarnated, + "TSD state should be reincarnated\n"); + p = mallocx(1, MALLOCX_TCACHE_NONE); + assert_ptr_not_null(p, "Unexpected malloc() failure"); + assert_ptr_not_null(tsd->arena, + "Should have tsd arena set after reincarnation."); + + free(p); + tsd_cleanup((void *)tsd); + assert_ptr_null(tsd->arena, + "TSD arena should have been cleared after 2nd cleanup."); + + return NULL; +} + +TEST_BEGIN(test_tsd_reincarnation) { + thd_t thd; + thd_create(&thd, thd_start_reincarnated, NULL); + thd_join(thd, NULL); +} +TEST_END + int main(void) { /* Core tsd bootstrapping must happen prior to data_tsd_boot(). */ @@ -101,5 +139,6 @@ main(void) { return test( test_tsd_main_thread, - test_tsd_sub_thread); + test_tsd_sub_thread, + test_tsd_reincarnation); } |