diff options
author | Craig Tiller <ctiller@google.com> | 2016-09-22 17:04:53 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2016-09-22 17:04:53 -0700 |
commit | 3fe56b52de02079eea98590adcc852dc9e3aaffd (patch) | |
tree | 8e711fda39a68a7f58051c4a258d32b7e4366ccd /test | |
parent | 3b98b2ee33795670a1fec14a8628551c9ac988be (diff) |
Add a test of reclaimation
Diffstat (limited to 'test')
-rw-r--r-- | test/core/iomgr/buffer_pool_test.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/core/iomgr/buffer_pool_test.c b/test/core/iomgr/buffer_pool_test.c index f659c5c5b4..ba44af5144 100644 --- a/test/core/iomgr/buffer_pool_test.c +++ b/test/core/iomgr/buffer_pool_test.c @@ -33,6 +33,7 @@ #include "src/core/lib/iomgr/buffer_pool.h" +#include <grpc/support/alloc.h> #include <grpc/support/log.h> #include "test/core/util/test_config.h" @@ -42,6 +43,28 @@ static void set_bool_cb(grpc_exec_ctx *exec_ctx, void *a, grpc_error *error) { } grpc_closure *set_bool(bool *p) { return grpc_closure_create(set_bool_cb, p); } +typedef struct { + size_t size; + grpc_buffer_user *buffer_user; + grpc_closure *then; +} reclaimer_args; +static void reclaimer_cb(grpc_exec_ctx *exec_ctx, void *args, + grpc_error *error) { + reclaimer_args *a = args; + grpc_buffer_user_free(exec_ctx, a->buffer_user, a->size); + grpc_buffer_user_finish_reclaimation(exec_ctx, a->buffer_user); + grpc_closure_run(exec_ctx, a->then, GRPC_ERROR_NONE); + gpr_free(a); +} +grpc_closure *make_reclaimer(grpc_buffer_user *buffer_user, size_t size, + grpc_closure *then) { + reclaimer_args *a = gpr_malloc(sizeof(*a)); + a->size = size; + a->buffer_user = buffer_user; + a->then = then; + return grpc_closure_create(reclaimer_cb, a); +} + static void destroy_user(grpc_buffer_user *usr) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; bool done = false; @@ -229,6 +252,44 @@ static void test_scavenge_blocked(void) { destroy_user(&usr2); } +static void test_blocked_until_scheduled_reclaim(void) { + gpr_log(GPR_INFO, "** test_blocked_until_scheduled_reclaim **"); + grpc_buffer_pool *p = grpc_buffer_pool_create(); + grpc_buffer_pool_resize(p, 1024); + grpc_buffer_user usr; + grpc_buffer_user_init(&usr, p); + { + bool done = false; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_buffer_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(done); + } + bool reclaim_done = false; + { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_buffer_user_post_reclaimer( + &exec_ctx, &usr, false, + make_reclaimer(&usr, 1024, set_bool(&reclaim_done))); + grpc_exec_ctx_finish(&exec_ctx); + } + { + bool done = false; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_buffer_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_exec_ctx_finish(&exec_ctx); + GPR_ASSERT(reclaim_done); + GPR_ASSERT(done); + } + { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_buffer_user_free(&exec_ctx, &usr, 1024); + grpc_exec_ctx_finish(&exec_ctx); + } + grpc_buffer_pool_unref(p); + destroy_user(&usr); +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); @@ -241,6 +302,7 @@ int main(int argc, char **argv) { test_async_alloc_blocked_by_size(); test_scavenge(); test_scavenge_blocked(); + test_blocked_until_scheduled_reclaim(); grpc_shutdown(); return 0; } |