-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconst_mem_pool-test.c
More file actions
69 lines (51 loc) · 1.81 KB
/
const_mem_pool-test.c
File metadata and controls
69 lines (51 loc) · 1.81 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
#include "const_mem_pool.h"
#include "hash.h"
#include "hash_uint32.h"
#define words(x) ((x)/sizeof(void*))
void test_const_mem_pool_1(void) {
char mem[2048];
struct const_mem_pool *pool = const_mem_pool_create(sizeof(mem), mem);
assert(pool);
fprintf(stdout, "available mem in pool (words): %zu\n", words(const_mem_pool_avail(pool)));
struct hash *h = hash_create( hash_size
, const_mem_pool_alloc(pool, hash_size)
, sizeof(uint32_t)
, sizeof(uint32_t)
, 32
, uint32_hash
, uint32_eq
, uint32_cpy
, uint32_cpy
, pool
, const_mem_pool_alloc
, const_mem_pool_dealloc );
fprintf(stdout, "hash allocated? %s\n", h ? "yes" : "no");
fprintf(stdout, "available mem in pool (words): %zu\n", words(const_mem_pool_avail(pool)));
size_t i = 0;
for(;;i++) {
uint32_t k = i;
uint32_t v = i;
if( !hash_add(h, &k, &v) ) {
break;
}
}
fprintf(stdout, "added something? %s\n", i > 0 ? "yes" : "no");
// platform-dependend
fprintf(stderr, "added %zu\n", i);
// should be not
fprintf(stdout, "available mem in pool (words): %zu\n", words(const_mem_pool_avail(pool)));
size_t j = 0;
for(; j < i; j++ ) {
uint32_t k = j;
if( !hash_get(h, &k) ) {
break;
}
}
fprintf(stdout, "found all ? %s\n", i == j ? "yes" : "no");
hash_destroy(h);
const_mem_pool_destroy(pool);
}