diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/core/iomgr/resource_quota_test.c | 253 | ||||
-rw-r--r-- | test/core/util/mock_endpoint.c | 33 | ||||
-rw-r--r-- | test/core/util/passthru_endpoint.c | 18 |
3 files changed, 115 insertions, 189 deletions
diff --git a/test/core/iomgr/resource_quota_test.c b/test/core/iomgr/resource_quota_test.c index 34dee1aee1..22c4e4e989 100644 --- a/test/core/iomgr/resource_quota_test.c +++ b/test/core/iomgr/resource_quota_test.c @@ -81,11 +81,7 @@ grpc_closure *make_unused_reclaimer(grpc_closure *then) { static void destroy_user(grpc_resource_user *usr) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - bool done = false; - grpc_resource_user_shutdown(&exec_ctx, usr, set_bool(&done)); - grpc_exec_ctx_flush(&exec_ctx); - GPR_ASSERT(done); - grpc_resource_user_destroy(&exec_ctx, usr); + grpc_resource_user_unref(&exec_ctx, usr); grpc_exec_ctx_finish(&exec_ctx); } @@ -106,10 +102,9 @@ static void test_resource_user_no_op(void) { gpr_log(GPR_INFO, "** test_resource_user_no_op **"); grpc_resource_quota *q = grpc_resource_quota_create("test_resource_user_no_op"); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_quota_unref(q); - destroy_user(&usr); + destroy_user(usr); } static void test_instant_alloc_then_free(void) { @@ -117,20 +112,19 @@ static void test_instant_alloc_then_free(void) { grpc_resource_quota *q = grpc_resource_quota_create("test_instant_alloc_then_free"); grpc_resource_quota_resize(q, 1024 * 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, NULL); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, NULL); grpc_exec_ctx_finish(&exec_ctx); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr, 1024); + grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); - destroy_user(&usr); + destroy_user(usr); } static void test_instant_alloc_free_pair(void) { @@ -138,16 +132,15 @@ static void test_instant_alloc_free_pair(void) { grpc_resource_quota *q = grpc_resource_quota_create("test_instant_alloc_free_pair"); grpc_resource_quota_resize(q, 1024 * 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, NULL); - grpc_resource_user_free(&exec_ctx, &usr, 1024); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, NULL); + grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); - destroy_user(&usr); + destroy_user(usr); } static void test_simple_async_alloc(void) { @@ -155,22 +148,21 @@ static void test_simple_async_alloc(void) { grpc_resource_quota *q = grpc_resource_quota_create("test_simple_async_alloc"); grpc_resource_quota_resize(q, 1024 * 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); { bool done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr, 1024); + grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); - destroy_user(&usr); + destroy_user(usr); } static void test_async_alloc_blocked_by_size(void) { @@ -178,12 +170,11 @@ static void test_async_alloc_blocked_by_size(void) { grpc_resource_quota *q = grpc_resource_quota_create("test_async_alloc_blocked_by_size"); grpc_resource_quota_resize(q, 1); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); bool done = false; { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(!done); } @@ -191,87 +182,83 @@ static void test_async_alloc_blocked_by_size(void) { GPR_ASSERT(done); { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr, 1024); + grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); - destroy_user(&usr); + destroy_user(usr); } static void test_scavenge(void) { gpr_log(GPR_INFO, "** test_scavenge **"); grpc_resource_quota *q = grpc_resource_quota_create("test_scavenge"); grpc_resource_quota_resize(q, 1024); - grpc_resource_user usr1; - grpc_resource_user usr2; - grpc_resource_user_init(&usr1, q, "usr1"); - grpc_resource_user_init(&usr2, q, "usr2"); + grpc_resource_user *usr1 = grpc_resource_user_create(q, "usr1"); + grpc_resource_user *usr2 = grpc_resource_user_create(q, "usr2"); { bool done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr1, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr1, 1024); + grpc_resource_user_free(&exec_ctx, usr1, 1024); grpc_exec_ctx_finish(&exec_ctx); } { bool done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr2, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr2, 1024); + grpc_resource_user_free(&exec_ctx, usr2, 1024); grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); - destroy_user(&usr1); - destroy_user(&usr2); + destroy_user(usr1); + destroy_user(usr2); } static void test_scavenge_blocked(void) { gpr_log(GPR_INFO, "** test_scavenge_blocked **"); grpc_resource_quota *q = grpc_resource_quota_create("test_scavenge_blocked"); grpc_resource_quota_resize(q, 1024); - grpc_resource_user usr1; - grpc_resource_user usr2; - grpc_resource_user_init(&usr1, q, "usr1"); - grpc_resource_user_init(&usr2, q, "usr2"); + grpc_resource_user *usr1 = grpc_resource_user_create(q, "usr1"); + grpc_resource_user *usr2 = grpc_resource_user_create(q, "usr2"); bool done; { done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr1, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); } { done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr2, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(!done); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr1, 1024); + grpc_resource_user_free(&exec_ctx, usr1, 1024); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr2, 1024); + grpc_resource_user_free(&exec_ctx, usr2, 1024); grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); - destroy_user(&usr1); - destroy_user(&usr2); + destroy_user(usr1); + destroy_user(usr2); } static void test_blocked_until_scheduled_reclaim(void) { @@ -279,12 +266,11 @@ static void test_blocked_until_scheduled_reclaim(void) { grpc_resource_quota *q = grpc_resource_quota_create("test_blocked_until_scheduled_reclaim"); grpc_resource_quota_resize(q, 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); { bool done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); } @@ -292,25 +278,25 @@ static void test_blocked_until_scheduled_reclaim(void) { { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - &exec_ctx, &usr, false, - make_reclaimer(&usr, 1024, set_bool(&reclaim_done))); + &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_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_resource_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_resource_user_free(&exec_ctx, &usr, 1024); + grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); - destroy_user(&usr); + destroy_user(usr); } static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { @@ -318,14 +304,12 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { grpc_resource_quota *q = grpc_resource_quota_create( "test_blocked_until_scheduled_reclaim_and_scavenge"); grpc_resource_quota_resize(q, 1024); - grpc_resource_user usr1; - grpc_resource_user usr2; - grpc_resource_user_init(&usr1, q, "usr1"); - grpc_resource_user_init(&usr2, q, "usr2"); + grpc_resource_user *usr1 = grpc_resource_user_create(q, "usr1"); + grpc_resource_user *usr2 = grpc_resource_user_create(q, "usr2"); { bool done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr1, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); } @@ -333,26 +317,26 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) { { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - &exec_ctx, &usr1, false, - make_reclaimer(&usr1, 1024, set_bool(&reclaim_done))); + &exec_ctx, usr1, false, + make_reclaimer(usr1, 1024, set_bool(&reclaim_done))); grpc_exec_ctx_finish(&exec_ctx); } { bool done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr2, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr2, 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_resource_user_free(&exec_ctx, &usr2, 1024); + grpc_resource_user_free(&exec_ctx, usr2, 1024); grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); - destroy_user(&usr1); - destroy_user(&usr2); + destroy_user(usr1); + destroy_user(usr2); } static void test_blocked_until_scheduled_destructive_reclaim(void) { @@ -360,12 +344,11 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { grpc_resource_quota *q = grpc_resource_quota_create( "test_blocked_until_scheduled_destructive_reclaim"); grpc_resource_quota_resize(q, 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); { bool done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); } @@ -373,25 +356,25 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) { { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - &exec_ctx, &usr, true, - make_reclaimer(&usr, 1024, set_bool(&reclaim_done))); + &exec_ctx, usr, true, + 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_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_resource_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_resource_user_free(&exec_ctx, &usr, 1024); + grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); - destroy_user(&usr); + destroy_user(usr); } static void test_unused_reclaim_is_cancelled(void) { @@ -399,23 +382,22 @@ static void test_unused_reclaim_is_cancelled(void) { grpc_resource_quota *q = grpc_resource_quota_create("test_unused_reclaim_is_cancelled"); grpc_resource_quota_resize(q, 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); bool benign_done = false; bool destructive_done = false; { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - &exec_ctx, &usr, false, make_unused_reclaimer(set_bool(&benign_done))); + &exec_ctx, usr, false, make_unused_reclaimer(set_bool(&benign_done))); grpc_resource_user_post_reclaimer( - &exec_ctx, &usr, true, + &exec_ctx, usr, true, make_unused_reclaimer(set_bool(&destructive_done))); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(!benign_done); GPR_ASSERT(!destructive_done); } grpc_resource_quota_unref(q); - destroy_user(&usr); + destroy_user(usr); GPR_ASSERT(benign_done); GPR_ASSERT(destructive_done); } @@ -425,24 +407,23 @@ static void test_benign_reclaim_is_preferred(void) { grpc_resource_quota *q = grpc_resource_quota_create("test_benign_reclaim_is_preferred"); grpc_resource_quota_resize(q, 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); bool benign_done = false; bool destructive_done = false; { bool done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - &exec_ctx, &usr, false, - make_reclaimer(&usr, 1024, set_bool(&benign_done))); + &exec_ctx, usr, false, + make_reclaimer(usr, 1024, set_bool(&benign_done))); grpc_resource_user_post_reclaimer( - &exec_ctx, &usr, true, + &exec_ctx, usr, true, make_unused_reclaimer(set_bool(&destructive_done))); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(!benign_done); @@ -451,7 +432,7 @@ static void test_benign_reclaim_is_preferred(void) { { bool done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(benign_done); GPR_ASSERT(!destructive_done); @@ -459,11 +440,11 @@ static void test_benign_reclaim_is_preferred(void) { } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr, 1024); + grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); - destroy_user(&usr); + destroy_user(usr); GPR_ASSERT(benign_done); GPR_ASSERT(destructive_done); } @@ -473,25 +454,24 @@ static void test_multiple_reclaims_can_be_triggered(void) { grpc_resource_quota *q = grpc_resource_quota_create("test_multiple_reclaims_can_be_triggered"); grpc_resource_quota_resize(q, 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); bool benign_done = false; bool destructive_done = false; { bool done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(done); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - &exec_ctx, &usr, false, - make_reclaimer(&usr, 512, set_bool(&benign_done))); + &exec_ctx, usr, false, + make_reclaimer(usr, 512, set_bool(&benign_done))); grpc_resource_user_post_reclaimer( - &exec_ctx, &usr, true, - make_reclaimer(&usr, 512, set_bool(&destructive_done))); + &exec_ctx, usr, true, + make_reclaimer(usr, 512, set_bool(&destructive_done))); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(!benign_done); GPR_ASSERT(!destructive_done); @@ -499,7 +479,7 @@ static void test_multiple_reclaims_can_be_triggered(void) { { bool done = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done)); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(benign_done); GPR_ASSERT(destructive_done); @@ -507,11 +487,11 @@ static void test_multiple_reclaims_can_be_triggered(void) { } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr, 1024); + grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_exec_ctx_finish(&exec_ctx); } grpc_resource_quota_unref(q); - destroy_user(&usr); + destroy_user(usr); GPR_ASSERT(benign_done); GPR_ASSERT(destructive_done); } @@ -522,30 +502,21 @@ static void test_resource_user_stays_allocated_until_memory_released(void) { grpc_resource_quota *q = grpc_resource_quota_create( "test_resource_user_stays_allocated_until_memory_released"); grpc_resource_quota_resize(q, 1024 * 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); - bool done = false; + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, NULL); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, NULL); grpc_exec_ctx_finish(&exec_ctx); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_quota_unref(q); - grpc_resource_user_shutdown(&exec_ctx, &usr, set_bool(&done)); + grpc_resource_user_unref(&exec_ctx, usr); grpc_exec_ctx_finish(&exec_ctx); - GPR_ASSERT(!done); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr, 1024); - grpc_exec_ctx_finish(&exec_ctx); - GPR_ASSERT(done); - } - { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_destroy(&exec_ctx, &usr); + grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_exec_ctx_finish(&exec_ctx); } } @@ -562,14 +533,12 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( "released"); grpc_resource_quota_resize(q, 1024); for (int i = 0; i < 10; i++) { - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); - bool done = false; + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); bool reclaimer_cancelled = false; { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - &exec_ctx, &usr, false, + &exec_ctx, usr, false, make_unused_reclaimer(set_bool(&reclaimer_cancelled))); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(!reclaimer_cancelled); @@ -577,30 +546,23 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released( { bool allocated = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&allocated)); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&allocated)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(allocated); GPR_ASSERT(!reclaimer_cancelled); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_shutdown(&exec_ctx, &usr, set_bool(&done)); + grpc_resource_user_unref(&exec_ctx, usr); grpc_exec_ctx_finish(&exec_ctx); - GPR_ASSERT(!done); GPR_ASSERT(!reclaimer_cancelled); } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr, 1024); + grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_exec_ctx_finish(&exec_ctx); - GPR_ASSERT(done); GPR_ASSERT(reclaimer_cancelled); } - { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_destroy(&exec_ctx, &usr); - grpc_exec_ctx_finish(&exec_ctx); - } } grpc_resource_quota_unref(q); } @@ -610,12 +572,11 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { grpc_resource_quota *q = grpc_resource_quota_create("test_reclaimers_can_be_posted_repeatedly"); grpc_resource_quota_resize(q, 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); { bool allocated = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&allocated)); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&allocated)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(allocated); } @@ -624,15 +585,15 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_resource_user_post_reclaimer( - &exec_ctx, &usr, false, - make_reclaimer(&usr, 1024, set_bool(&reclaimer_done))); + &exec_ctx, usr, false, + make_reclaimer(usr, 1024, set_bool(&reclaimer_done))); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(!reclaimer_done); } { bool allocated = false; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&allocated)); + grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&allocated)); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(allocated); GPR_ASSERT(reclaimer_done); @@ -640,10 +601,10 @@ static void test_reclaimers_can_be_posted_repeatedly(void) { } { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_free(&exec_ctx, &usr, 1024); + grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_exec_ctx_finish(&exec_ctx); } - destroy_user(&usr); + destroy_user(usr); grpc_resource_quota_unref(q); } @@ -653,13 +614,11 @@ static void test_one_slice(void) { grpc_resource_quota *q = grpc_resource_quota_create("test_one_slice"); grpc_resource_quota_resize(q, 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_user_slice_allocator alloc; int num_allocs = 0; - grpc_resource_user_slice_allocator_init(&alloc, &usr, inc_int_cb, - &num_allocs); + grpc_resource_user_slice_allocator_init(&alloc, usr, inc_int_cb, &num_allocs); gpr_slice_buffer buffer; gpr_slice_buffer_init(&buffer); @@ -673,7 +632,7 @@ static void test_one_slice(void) { } gpr_slice_buffer_destroy(&buffer); - destroy_user(&usr); + destroy_user(usr); grpc_resource_quota_unref(q); } @@ -684,13 +643,11 @@ static void test_one_slice_deleted_late(void) { grpc_resource_quota_create("test_one_slice_deleted_late"); grpc_resource_quota_resize(q, 1024); - grpc_resource_user usr; - grpc_resource_user_init(&usr, q, "usr"); + grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_user_slice_allocator alloc; int num_allocs = 0; - grpc_resource_user_slice_allocator_init(&alloc, &usr, inc_int_cb, - &num_allocs); + grpc_resource_user_slice_allocator_init(&alloc, usr, inc_int_cb, &num_allocs); gpr_slice_buffer buffer; gpr_slice_buffer_init(&buffer); @@ -703,22 +660,14 @@ static void test_one_slice_deleted_late(void) { GPR_ASSERT(num_allocs == start_allocs + 1); } - bool done = false; { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_shutdown(&exec_ctx, &usr, set_bool(&done)); + grpc_resource_user_unref(&exec_ctx, usr); grpc_exec_ctx_finish(&exec_ctx); - GPR_ASSERT(!done); } grpc_resource_quota_unref(q); gpr_slice_buffer_destroy(&buffer); - GPR_ASSERT(done); - { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_resource_user_destroy(&exec_ctx, &usr); - grpc_exec_ctx_finish(&exec_ctx); - } } int main(int argc, char **argv) { diff --git a/test/core/util/mock_endpoint.c b/test/core/util/mock_endpoint.c index 2b041a4484..2dac877a65 100644 --- a/test/core/util/mock_endpoint.c +++ b/test/core/util/mock_endpoint.c @@ -41,12 +41,11 @@ typedef struct grpc_mock_endpoint { grpc_endpoint base; gpr_mu mu; - int refs; void (*on_write)(gpr_slice slice); gpr_slice_buffer read_buffer; gpr_slice_buffer *on_read_out; grpc_closure *on_read; - grpc_resource_user resource_user; + grpc_resource_user *resource_user; } grpc_mock_endpoint; static void me_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, @@ -78,24 +77,6 @@ static void me_add_to_pollset(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, static void me_add_to_pollset_set(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, grpc_pollset_set *pollset) {} -static void unref(grpc_exec_ctx *exec_ctx, grpc_mock_endpoint *m) { - gpr_mu_lock(&m->mu); - if (0 == --m->refs) { - gpr_mu_unlock(&m->mu); - gpr_slice_buffer_destroy(&m->read_buffer); - grpc_resource_user_destroy(exec_ctx, &m->resource_user); - gpr_free(m); - } else { - gpr_mu_unlock(&m->mu); - } -} - -static void me_finish_shutdown(grpc_exec_ctx *exec_ctx, void *me, - grpc_error *error) { - grpc_mock_endpoint *m = me; - unref(exec_ctx, m); -} - static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { grpc_mock_endpoint *m = (grpc_mock_endpoint *)ep; gpr_mu_lock(&m->mu); @@ -104,14 +85,15 @@ static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { GRPC_ERROR_CREATE("Endpoint Shutdown"), NULL); m->on_read = NULL; } - grpc_resource_user_shutdown(exec_ctx, &m->resource_user, - grpc_closure_create(me_finish_shutdown, m)); gpr_mu_unlock(&m->mu); + grpc_resource_user_shutdown(exec_ctx, m->resource_user); } static void me_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { grpc_mock_endpoint *m = (grpc_mock_endpoint *)ep; - unref(exec_ctx, m); + gpr_slice_buffer_destroy(&m->read_buffer); + grpc_resource_user_unref(exec_ctx, m->resource_user); + gpr_free(m); } static char *me_get_peer(grpc_endpoint *ep) { @@ -120,7 +102,7 @@ static char *me_get_peer(grpc_endpoint *ep) { static grpc_resource_user *me_get_resource_user(grpc_endpoint *ep) { grpc_mock_endpoint *m = (grpc_mock_endpoint *)ep; - return &m->resource_user; + return m->resource_user; } static grpc_workqueue *me_get_workqueue(grpc_endpoint *ep) { return NULL; } @@ -141,10 +123,9 @@ grpc_endpoint *grpc_mock_endpoint_create(void (*on_write)(gpr_slice slice), grpc_resource_quota *resource_quota) { grpc_mock_endpoint *m = gpr_malloc(sizeof(*m)); m->base.vtable = &vtable; - m->refs = 2; char *name; gpr_asprintf(&name, "mock_endpoint_%" PRIxPTR, (intptr_t)m); - grpc_resource_user_init(&m->resource_user, resource_quota, name); + m->resource_user = grpc_resource_user_create(resource_quota, name); gpr_free(name); gpr_slice_buffer_init(&m->read_buffer); gpr_mu_init(&m->mu); diff --git a/test/core/util/passthru_endpoint.c b/test/core/util/passthru_endpoint.c index ee6ef7da60..a920a15aa5 100644 --- a/test/core/util/passthru_endpoint.c +++ b/test/core/util/passthru_endpoint.c @@ -46,7 +46,7 @@ typedef struct { gpr_slice_buffer read_buffer; gpr_slice_buffer *on_read_out; grpc_closure *on_read; - grpc_resource_user resource_user; + grpc_resource_user *resource_user; } half; struct passthru_endpoint { @@ -123,10 +123,10 @@ static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { m->on_read = NULL; } gpr_mu_unlock(&m->parent->mu); + grpc_resource_user_shutdown(exec_ctx, m->resource_user); } -static void me_really_destroy(grpc_exec_ctx *exec_ctx, void *ep, - grpc_error *error) { +static void me_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { passthru_endpoint *p = ((half *)ep)->parent; gpr_mu_lock(&p->mu); if (0 == --p->halves) { @@ -134,18 +134,14 @@ static void me_really_destroy(grpc_exec_ctx *exec_ctx, void *ep, gpr_mu_destroy(&p->mu); gpr_slice_buffer_destroy(&p->client.read_buffer); gpr_slice_buffer_destroy(&p->server.read_buffer); + grpc_resource_user_unref(exec_ctx, p->client.resource_user); + grpc_resource_user_unref(exec_ctx, p->server.resource_user); gpr_free(p); } else { gpr_mu_unlock(&p->mu); } } -static void me_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { - half *m = (half *)ep; - grpc_resource_user_shutdown(exec_ctx, &m->resource_user, - grpc_closure_create(me_really_destroy, m)); -} - static char *me_get_peer(grpc_endpoint *ep) { return gpr_strdup("fake:mock_endpoint"); } @@ -154,7 +150,7 @@ static grpc_workqueue *me_get_workqueue(grpc_endpoint *ep) { return NULL; } static grpc_resource_user *me_get_resource_user(grpc_endpoint *ep) { half *m = (half *)ep; - return &m->resource_user; + return m->resource_user; } static const grpc_endpoint_vtable vtable = { @@ -179,7 +175,7 @@ static void half_init(half *m, passthru_endpoint *parent, char *name; gpr_asprintf(&name, "passthru_endpoint_%s_%" PRIxPTR, half_name, (intptr_t)parent); - grpc_resource_user_init(&m->resource_user, resource_quota, name); + m->resource_user = grpc_resource_user_create(resource_quota, name); gpr_free(name); } |