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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/*
* Copyright (C) 2011 Codership Oy <info@codership.com>
*
* $Id$
*/
#include "gcache_rb_store.hpp"
#include "gcache_bh.hpp"
#include "gcache_rb_test.hpp"
using namespace gcache;
START_TEST(test1)
{
std::string const rb_name = "rb_test";
ssize_t const bh_size = sizeof(gcache::BufferHeader);
ssize_t const rb_size (4 + 2*bh_size);
std::map<int64_t, const void*> s2p;
RingBuffer rb(rb_name, rb_size, s2p);
fail_if (rb.size() != rb_size, "Expected %zd, got %zd", rb_size, rb.size());
void* buf1 = rb.malloc (3 + bh_size);
fail_if (NULL != buf1); // > 1/2 size
buf1 = rb.malloc (1 + bh_size);
fail_if (NULL == buf1);
BufferHeader* bh1(ptr2BH(buf1));
fail_if (bh1->seqno_g != SEQNO_NONE);
fail_if (BH_is_released(bh1));
void* buf2 = rb.malloc (2 + bh_size);
fail_if (NULL == buf2);
fail_if (BH_is_released(bh1));
BufferHeader* bh2(ptr2BH(buf2));
fail_if (bh2->seqno_g != SEQNO_NONE);
fail_if (BH_is_released(bh2));
void* tmp = rb.realloc (buf1, 2 + bh_size);
fail_if (NULL != tmp);
rb.free (buf2);
fail_if (!BH_is_released(bh2));
tmp = rb.realloc (buf1, 2 + bh_size);
fail_if (NULL != tmp);
rb.free (buf1);
fail_if (!BH_is_released(bh1));
buf1 = rb.malloc (1 + bh_size);
fail_if (NULL == buf1);
tmp = rb.realloc (buf1, 2 + bh_size);
fail_if (NULL == tmp);
fail_if (tmp != buf1);
buf2 = rb.malloc (1 + bh_size);
fail_if (NULL == buf2);
tmp = rb.realloc (buf2, 2 + bh_size);
fail_if (NULL == tmp);
fail_if (tmp != buf2);
tmp = rb.malloc (1 + bh_size);
fail_if (NULL != tmp);
rb.free(buf1);
fail_if (!BH_is_released(ptr2BH(buf1)));
rb.free(buf2);
fail_if (!BH_is_released(ptr2BH(buf2)));
tmp = rb.malloc (2 + bh_size);
fail_if (NULL == tmp);
mark_point();
}
END_TEST
Suite* gcache_rb_suite()
{
Suite* s = suite_create("gcache::RbStore");
TCase* tc;
tc = tcase_create("test");
tcase_add_test(tc, test1);
suite_add_tcase(s, tc);
return s;
}
|