1 #include <gtest/gtest.h>
8 #include <jellyfish/offsets_key_value.hpp>
11 #define UINT64_C(x) ((uint64_t)x)
14 using namespace jellyfish
;
17 uint_t key_len
, val_len
;
20 class ComputeOffsetsTest
: public ::testing::TestWithParam
<offset_test_param
>
23 Offsets
<uint64_t> offsets
;
25 ComputeOffsetsTest() :
26 offsets(GetParam().key_len
, GetParam().val_len
, 15)
29 ~ComputeOffsetsTest() { }
32 TEST_P(ComputeOffsetsTest
, CheckCoherency
) {
33 const Offsets
<uint64_t>::offset_t
*it
= NULL
, *pit
= NULL
;
34 const Offsets
<uint64_t>::offset_t
*lit
= NULL
, *lpit
= NULL
;
35 uint_t k_len
= GetParam().key_len
;
36 uint_t v_len
= GetParam().val_len
;
37 uint_t kv_len
= k_len
+ v_len
;
39 uint_t lv_len
= kv_len
- lk_len
;
44 // * - testing of value masks
46 EXPECT_EQ(lk_len
, this->offsets
.get_reprobe_len());
47 EXPECT_EQ(lv_len
, this->offsets
.get_lval_len());
49 for(i
= 0; true; i
++) {
50 w
= this->offsets
.get_word_offset(i
, &it
, &lit
, NULL
);
52 pw
= this->offsets
.get_word_offset(i
-1, &pit
, &lpit
, NULL
);
54 uint_t noff
= pit
->key
.boff
+ kv_len
;
56 EXPECT_EQ(pit
->key
.woff
+ 1, it
->key
.woff
) <<
57 i
<< ": Word offset should go up";
59 EXPECT_EQ(pit
->key
.woff
, it
->key
.woff
) <<
60 i
<< ": Word offset should NOT go up";
63 if(pit
->key
.mask2
) { // key between two words
64 EXPECT_LT((uint_t
)64, pit
->key
.boff
+ k_len
) <<
65 i
<< ": Key not between words, should not have mask2";
67 EXPECT_GE((uint_t
)64, pit
->key
.boff
- 1 + k_len
+ 1) <<
68 i
<< ": Key between words, should have mask2";
70 EXPECT_EQ((pit
->key
.boff
+ kv_len
+ 1 + (pit
->key
.mask2
? 2 : 0)) % 64,
72 i
<< ": Invalid jump of bit offset";
73 EXPECT_EQ((pit
->key
.boff
+ kv_len
+ 1 + (pit
->key
.mask2
? 2 : 0)) % 64,
75 i
<< ": Invalid jump of bit offset large field";
78 EXPECT_EQ((it
->key
.boff
+ k_len
+ (it
->key
.mask2
? 2 : 0)) % 64, it
->val
.boff
) <<
79 i
<< ": Invalid value offset";
80 EXPECT_EQ((lit
->key
.boff
+ lk_len
+ (lit
->key
.mask2
? 2 : 0)) % 64, lit
->val
.boff
) <<
81 i
<< ": Invalid value offset large field";
82 EXPECT_EQ(UINT64_C(1) << (it
->key
.boff
- 1), it
->key
.lb_mask
) <<
83 i
<< ": Invalid lb_mask";
84 EXPECT_EQ(UINT64_C(1) << (lit
->key
.boff
- 1), lit
->key
.lb_mask
) <<
85 i
<< ": Invalid lb_mask";
87 EXPECT_EQ(64 - it
->key
.boff
- 1, it
->key
.shift
) <<
88 i
<< ": invalid key shift";
89 EXPECT_EQ(UINT64_C(1) << (64 - it
->key
.boff
+ 1), 1 + (it
->key
.mask1
>> (it
->key
.boff
- 1))) <<
90 i
<< ": invalid key mask";
91 EXPECT_EQ(UINT64_C(1) << (it
->key
.boff
+ k_len
- 64 + 2), 1 + it
->key
.mask2
) <<
92 i
<< ": invalid key mask2";
93 EXPECT_EQ(k_len
, it
->key
.shift
+ it
->key
.cshift
);
94 EXPECT_EQ(UINT64_C(1) << 63, it
->key
.sb_mask1
) <<
95 i
<< ": invalid key key sb_mask1";
96 EXPECT_EQ(UINT64_C(1) << it
->key
.cshift
, it
->key
.sb_mask2
) <<
97 i
<< ": invalid key sb_mask2";
99 EXPECT_EQ(0u, it
->key
.shift
) <<
100 i
<< ": key shift should be zero, no mask";
101 EXPECT_EQ(UINT64_C(1) << (k_len
+ 1), 1 + (it
->key
.mask1
>> (it
->key
.boff
- 1))) <<
102 i
<< ": invalid key mask " << it
->key
.boff
;
103 EXPECT_EQ(0u, it
->key
.cshift
);
104 EXPECT_EQ(0u, it
->key
.sb_mask1
| it
->key
.sb_mask2
) <<
105 i
<< ": set bit masks should be 0";
108 EXPECT_EQ(64 - lit
->key
.boff
- 1, lit
->key
.shift
) <<
109 i
<< ": invalid key shift large field";
110 EXPECT_EQ(UINT64_C(1) << (64 - lit
->key
.boff
+ 1), 1 + (lit
->key
.mask1
>> (lit
->key
.boff
- 1))) <<
111 i
<< ": invalid key mask large field";
112 EXPECT_EQ(UINT64_C(1) << (lit
->key
.boff
+ lk_len
- 64 + 2), 1 + lit
->key
.mask2
) <<
113 i
<< ": invalid key mask2 large field";
114 EXPECT_EQ(lk_len
, lit
->key
.shift
+ lit
->key
.cshift
);
115 EXPECT_EQ(UINT64_C(1) << 63, lit
->key
.sb_mask1
) <<
116 i
<< ": invalid key key sb_mask1";
117 EXPECT_EQ(UINT64_C(1) << lit
->key
.cshift
, lit
->key
.sb_mask2
) <<
118 i
<< ": invalid key sb_mask2";
120 EXPECT_EQ(0u, lit
->key
.shift
) <<
121 i
<< ": key shift should be zero, no mask, large field";
122 EXPECT_EQ(0u, lit
->key
.cshift
);
123 EXPECT_EQ(UINT64_C(1) << (lk_len
+ 1), 1 + (lit
->key
.mask1
>> (lit
->key
.boff
- 1))) <<
124 i
<< ": invalid key mask large field " << lit
->key
.boff
;
128 EXPECT_LT((uint_t
)64, it
->val
.boff
+ v_len
) <<
129 i
<< ": val not between words, should not have mask2";
130 EXPECT_EQ(64 - it
->val
.boff
, it
->val
.shift
) <<
131 i
<< ": invalid val shift";
132 EXPECT_EQ(UINT64_C(1) << (64 - it
->val
.boff
), 1 + (it
->val
.mask1
>> it
->val
.boff
)) <<
133 i
<< ": invalid val mask1";
134 EXPECT_EQ(UINT64_C(1) << (it
->val
.boff
+ v_len
- 64), 1 + it
->val
.mask2
) <<
135 i
<< ": invalid val mask2";
137 EXPECT_GE((uint_t
)64, it
->val
.boff
+ v_len
) <<
138 i
<< ": val between words, should have mask2";
139 EXPECT_EQ(v_len
, it
->val
.shift
) <<
140 i
<< ": invalid val shift";
141 EXPECT_EQ(UINT64_C(1) << v_len
, 1 + (it
->val
.mask1
>> it
->val
.boff
)) <<
142 i
<< ": invalid val mask1";
144 EXPECT_EQ(v_len
, it
->val
.shift
+ it
->val
.cshift
);
146 EXPECT_LT((uint_t
)64, lit
->val
.boff
+ lv_len
) <<
147 i
<< ": val not between words, should not have mask2 large field";
148 EXPECT_EQ(64 - lit
->val
.boff
, lit
->val
.shift
) <<
149 i
<< ": invalid val shift large field";
150 EXPECT_EQ(UINT64_C(1) << (64 - lit
->val
.boff
), 1 + (lit
->val
.mask1
>> lit
->val
.boff
)) <<
151 i
<< ": invalid val mask1 large field";
152 EXPECT_EQ(UINT64_C(1) << (lit
->val
.boff
+ lv_len
- 64), 1 + lit
->val
.mask2
) <<
153 i
<< ": invalid val mask2 large field";
155 EXPECT_GE((uint_t
)64, lit
->val
.boff
+ lv_len
) <<
156 i
<< ": val between words, should have mask2 large field " << lit
->val
.boff
<< " " << lv_len
;
157 EXPECT_EQ(lv_len
, lit
->val
.shift
) <<
158 i
<< ": invalid val shift large field";
159 EXPECT_EQ(UINT64_C(1) << lv_len
, 1 + (lit
->val
.mask1
>> lit
->val
.boff
)) <<
160 i
<< ": invalid val mask1 large field";
162 EXPECT_EQ(lv_len
, lit
->val
.shift
+ lit
->val
.cshift
);
164 uint_t noff
= it
->key
.boff
+ kv_len
;
165 if(noff
== 62 || noff
== 63 || noff
== 64)
170 offset_test_param params
[] = { {10, 10}, { 22, 5 }, {20, 5} };
171 INSTANTIATE_TEST_CASE_P(OffsetsTest
, ComputeOffsetsTest
, ::testing::ValuesIn(params
));