Merge pull request #10337 from yang-g/autofuzz

Clamp memory usage estimate
pull/10350/head
Yang Gao 8 years ago committed by GitHub
commit b838bb2411
  1. 14
      src/core/lib/iomgr/resource_quota.c
  2. BIN
      test/core/end2end/fuzzers/api_fuzzer_corpus/poc-c726ee220e980ed6ad17809fd9efe2844ee61555ac08e4f88afd8901cc2dd53a
  3. 52
      test/core/iomgr/resource_quota_test.c
  4. 23
      tools/run_tests/generated/tests.json

@ -279,11 +279,17 @@ static void rq_step_sched(grpc_exec_ctx *exec_ctx,
/* update the atomically available resource estimate - use no barriers since
timeliness of delivery really doesn't matter much */
static void rq_update_estimate(grpc_resource_quota *resource_quota) {
gpr_atm memory_usage_estimation = MEMORY_USAGE_ESTIMATION_MAX;
if (resource_quota->size != 0) {
memory_usage_estimation =
GPR_CLAMP((gpr_atm)((1.0 -
((double)resource_quota->free_pool) /
((double)resource_quota->size)) *
MEMORY_USAGE_ESTIMATION_MAX),
0, MEMORY_USAGE_ESTIMATION_MAX);
}
gpr_atm_no_barrier_store(&resource_quota->memory_usage_estimation,
(gpr_atm)((1.0 -
((double)resource_quota->free_pool) /
((double)resource_quota->size)) *
MEMORY_USAGE_ESTIMATION_MAX));
memory_usage_estimation);
}
/* returns true if all allocations are completed */

@ -682,6 +682,56 @@ static void test_one_slice_deleted_late(void) {
}
}
static void test_resize_to_zero(void) {
gpr_log(GPR_INFO, "** test_resize_to_zero **");
grpc_resource_quota *q = grpc_resource_quota_create("test_resize_to_zero");
grpc_resource_quota_resize(q, 0);
grpc_resource_quota_unref(q);
}
static void test_negative_rq_free_pool(void) {
gpr_log(GPR_INFO, "** test_negative_rq_free_pool **");
grpc_resource_quota *q =
grpc_resource_quota_create("test_negative_rq_free_pool");
grpc_resource_quota_resize(q, 1024);
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_slice_buffer buffer;
grpc_slice_buffer_init(&buffer);
{
const int start_allocs = num_allocs;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc_slices(&exec_ctx, &alloc, 1024, 1, &buffer);
grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(num_allocs == start_allocs + 1);
}
grpc_resource_quota_resize(q, 512);
double eps = 0.0001;
GPR_ASSERT(grpc_resource_quota_get_memory_pressure(q) < 1 + eps);
GPR_ASSERT(grpc_resource_quota_get_memory_pressure(q) > 1 - eps);
{
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_unref(&exec_ctx, usr);
grpc_exec_ctx_finish(&exec_ctx);
}
grpc_resource_quota_unref(q);
{
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_slice_buffer_destroy_internal(&exec_ctx, &buffer);
grpc_exec_ctx_finish(&exec_ctx);
}
}
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
grpc_init();
@ -705,6 +755,8 @@ int main(int argc, char **argv) {
test_reclaimers_can_be_posted_repeatedly();
test_one_slice();
test_one_slice_deleted_late();
test_resize_to_zero();
test_negative_rq_free_pool();
grpc_shutdown();
return 0;
}

@ -94232,6 +94232,29 @@
],
"uses_polling": false
},
{
"args": [
"test/core/end2end/fuzzers/api_fuzzer_corpus/poc-c726ee220e980ed6ad17809fd9efe2844ee61555ac08e4f88afd8901cc2dd53a"
],
"ci_platforms": [
"linux"
],
"cpu_cost": 0.1,
"exclude_configs": [
"tsan"
],
"exclude_iomgrs": [
"uv"
],
"flaky": false,
"language": "c",
"name": "api_fuzzer_one_entry",
"platforms": [
"mac",
"linux"
],
"uses_polling": false
},
{
"args": [
"test/core/end2end/fuzzers/api_fuzzer_corpus/timeout-0fa0559576ad2a45b06d0bfb84115963d7d48206"

Loading…
Cancel
Save