aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/json
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-04-12 01:50:51 +0200
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-04-12 01:50:51 +0200
commit85a46dd78080b4060e12330ef6d139f5e6287016 (patch)
tree768e66009a0a8f0fe1d32375033d914f6ef89bda /test/core/json
parentb206c154dd7605bf0dbdc7a69605b6f749d2bef4 (diff)
Moving memory allocation tracking to its own file.
Diffstat (limited to 'test/core/json')
-rw-r--r--test/core/json/fuzzer.c41
1 files changed, 6 insertions, 35 deletions
diff --git a/test/core/json/fuzzer.c b/test/core/json/fuzzer.c
index 044db973ab..e94b41ca99 100644
--- a/test/core/json/fuzzer.c
+++ b/test/core/json/fuzzer.c
@@ -38,42 +38,12 @@
#include <grpc/support/log.h>
#include "src/core/lib/json/json.h"
-
-static size_t g_total_size = 0;
-static gpr_allocation_functions g_old_allocs;
-
-void *guard_malloc(size_t size) {
- size_t *ptr;
- g_total_size += size;
- ptr = g_old_allocs.malloc_fn(size + sizeof(size));
- *ptr++ = size;
- return ptr;
-}
-
-void *guard_realloc(void *vptr, size_t size) {
- size_t *ptr = vptr;
- --ptr;
- g_total_size -= *ptr;
- ptr = g_old_allocs.realloc_fn(ptr, size + sizeof(size));
- g_total_size += size;
- *ptr++ = size;
- return ptr;
-}
-
-void guard_free(void *vptr) {
- size_t *ptr = vptr;
- --ptr;
- g_total_size -= *ptr;
- g_old_allocs.free_fn(ptr);
-}
-
-struct gpr_allocation_functions g_guard_allocs = {guard_malloc, guard_realloc,
- guard_free};
+#include "test/core/util/memory_counters.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
char *s;
- g_old_allocs = gpr_get_allocation_functions();
- gpr_set_allocation_functions(g_guard_allocs);
+ struct grpc_memory_counters counters;
+ grpc_memory_counters_init();
s = gpr_malloc(size);
memcpy(s, data, size);
grpc_json *x;
@@ -81,7 +51,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
grpc_json_destroy(x);
}
gpr_free(s);
- gpr_set_allocation_functions(g_old_allocs);
- GPR_ASSERT(g_total_size == 0);
+ counters = grpc_memory_counters_snapshot();
+ grpc_memory_counters_destroy();
+ GPR_ASSERT(counters.total_size_relative == 0);
return 0;
}