-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathcmap_test.c
73 lines (67 loc) · 1.64 KB
/
cmap_test.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
72
73
/*
* Copyright (c) 2014 Wu, Xingbo <wuxb45@gmail.com>
*
* All rights reserved. No warranty, explicit or implicit, provided.
*/
#define _GNU_SOURCE
#define _LARGEFILE64_SOURCE
#include <unistd.h>
#include <assert.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <pthread.h>
#include "cmap.h"
static void
cmap_test(void)
{
const char * const raw_fn = "/tmp/raw_test";
const char * const meta_fn = "/tmp/cm_test";
const uint64_t cap = UINT64_C(1024 * 1024) * 32 * 64;
// create
struct ContainerMap * const cm = containermap_create(raw_fn, cap);
assert(cm);
containermap_show(cm);
// alloc
uint64_t offs[64];
for (uint64_t i = 0; i< 64; i++) {
const uint64_t off = containermap_alloc(cm);
assert(off < cap);
offs[i] = off;
}
const uint64_t offx = containermap_alloc(cm);
assert(offx > cap);
containermap_show(cm);
// release
for (uint64_t i = 0; i< 64; i++) {
containermap_release(cm, offs[i]);
}
containermap_show(cm);
for (uint64_t i = 0; i< 32; i++) {
(void)containermap_alloc(cm);
}
containermap_show(cm);
// store
containermap_dump(cm, meta_fn);
close(cm->raw_fd);
struct ContainerMap * const cm1 = containermap_load(meta_fn, raw_fn);
assert(cm1);
containermap_show(cm1);
assert(cm->nr_units == cm1->nr_units);
assert(cm->nr_used == cm1->nr_used);
assert(cm->total_cap == cm1->total_cap);
assert(cm->discard == cm1->discard);
assert(memcmp(cm->bits, cm1->bits, cm->nr_units/8) == 0);
free(cm);
containermap_destroy(cm1);
}
int
main(int argc, char ** argv)
{
(void)argc;
(void)argv;
cmap_test();
return 0;
}