hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Copyright (C) 2018 Philippe Gerum <rpm@xenomai.org>
 *
 * SPDX-License-Identifier: MIT
 */
#include <boilerplate/heapmem.h>
#include "memcheck/memcheck.h"
 
smokey_test_plugin(memory_heapmem,
          MEMCHECK_ARGS,
          "Check for the heapmem allocator sanity.\n"
          MEMCHECK_HELP_STRINGS
   );
 
#define MIN_HEAP_SIZE  8192
#define MAX_HEAP_SIZE  (1024 * 1024 * 2)
#define RANDOM_ROUNDS  1024
 
#define PATTERN_HEAP_SIZE  (128*1024)
#define PATTERN_ROUNDS     128
 
static struct heap_memory heap;
 
static size_t get_arena_size(size_t heap_size)
{
   return HEAPMEM_ARENA_SIZE(heap_size);
}
 
static struct memcheck_descriptor heapmem_descriptor = {
   .name = "heapmem",
   .init = HEAP_INIT_T(heapmem_init),
   .destroy = HEAP_DESTROY_T(heapmem_destroy),
   .alloc = HEAP_ALLOC_T(heapmem_alloc),
   .free = HEAP_FREE_T(heapmem_free),
   .get_usable_size = HEAP_USABLE_T(heapmem_usable_size),
   .get_used_size = HEAP_USED_T(heapmem_used_size),
   .seq_min_heap_size = MIN_HEAP_SIZE,
   .seq_max_heap_size = MAX_HEAP_SIZE,
   .random_rounds = RANDOM_ROUNDS,
   .pattern_heap_size = PATTERN_HEAP_SIZE,
   .pattern_rounds = PATTERN_ROUNDS,
   .heap = &heap,
   .get_arena_size = get_arena_size,
   .valid_flags = MEMCHECK_ALL_FLAGS,
};
 
static int run_memory_heapmem(struct smokey_test *t,
                 int argc, char *const argv[])
{
   return memcheck_run(&heapmem_descriptor, t, argc, argv);
}