-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_rollback.c
71 lines (54 loc) · 1.39 KB
/
test_rollback.c
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
69
70
71
#ifdef TEST_ROLLBACK
#include "bitmap_v4.h"
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
/* override alloc functions */
static int alloc_times = 0;
void * alloc_node(struct mm *m, int nb_node, int level)
{
if(nb_node == 0)
return NULL;
if(alloc_times == 3)
/* manually cause alloc fail */
return NULL;
alloc_times ++;
void * ret = calloc(nb_node, NODE_SIZE);
if(ret) {
m->ms.mem += nb_node * NODE_SIZE;
m->ms.node += nb_node;
m->ms.lmem[level] += nb_node * NODE_SIZE;
m->ms.lnode[level] += nb_node;
}
return ret;
}
void test_1(void) {
alloc_times = 0;
uint32_t ip = inet_network("192.168.0.0");
uint32_t cidr = 24;
struct mb_node root = {0,0,NULL};
struct mm m;
memset(&m, 0, sizeof(m));
int ret = bitmap_insert_prefix(&root, &m, ip, cidr, (void*)1);
assert(ret == -1);
assert(root.internal == 0 && root.external == 0 && \
root.child_ptr == NULL);
assert(m.ms.mem == 0 && m.ms.node == 0);
}
void test_2() {
alloc_times = 0;
uint32_t ip = inet_network("192.0.0.0");
uint32_t cidr = 8;
struct mb_node root = {0,0,NULL};
struct mm m;
memset(&m, 0, sizeof(m));
int ret = bitmap_insert_prefix(&root, &m, ip, cidr, (void*)1);
assert(ret == 0);
}
int main() {
test_1();
test_2();
return 0;
}
#endif