Lines Matching full:data
32 /* Check that the HBitmap and the shadow bitmap contain the same data,
35 static void hbitmap_test_check(TestHBitmapData *data, in hbitmap_test_check() argument
44 hbitmap_iter_init(&hbi, data->hb, first); in hbitmap_test_check()
50 next = data->size; in hbitmap_test_check()
57 g_assert_cmpint(data->bits[pos] & (1UL << bit), ==, 0); in hbitmap_test_check()
60 if (next == data->size) { in hbitmap_test_check()
68 g_assert_cmpint(data->bits[pos] & (1UL << bit), !=, 0); in hbitmap_test_check()
72 g_assert_cmpint(count << data->granularity, ==, hbitmap_count(data->hb)); in hbitmap_test_check()
78 static void hbitmap_test_init(TestHBitmapData *data, in hbitmap_test_init() argument
82 data->hb = hbitmap_alloc(size, granularity); in hbitmap_test_init()
88 data->bits = g_new0(unsigned long, n); in hbitmap_test_init()
89 data->size = size; in hbitmap_test_init()
90 data->granularity = granularity; in hbitmap_test_init()
92 hbitmap_test_check(data, 0); in hbitmap_test_init()
102 static void hbitmap_test_truncate_impl(TestHBitmapData *data, in hbitmap_test_truncate_impl() argument
107 data->old_size = data->size; in hbitmap_test_truncate_impl()
108 data->size = size; in hbitmap_test_truncate_impl()
110 if (data->size == data->old_size) { in hbitmap_test_truncate_impl()
115 m = hbitmap_test_array_size(data->old_size); in hbitmap_test_truncate_impl()
116 data->bits = g_renew(unsigned long, data->bits, n); in hbitmap_test_truncate_impl()
118 memset(&data->bits[m], 0x00, sizeof(unsigned long) * (n - m)); in hbitmap_test_truncate_impl()
123 if (data->size < data->old_size) { in hbitmap_test_truncate_impl()
127 data->bits[n-1] &= mask; in hbitmap_test_truncate_impl()
131 hbitmap_truncate(data->hb, size); in hbitmap_test_truncate_impl()
134 static void hbitmap_test_teardown(TestHBitmapData *data, in hbitmap_test_teardown() argument
137 if (data->hb) { in hbitmap_test_teardown()
138 hbitmap_free(data->hb); in hbitmap_test_teardown()
139 data->hb = NULL; in hbitmap_test_teardown()
141 g_free(data->bits); in hbitmap_test_teardown()
142 data->bits = NULL; in hbitmap_test_teardown()
148 static void hbitmap_test_set(TestHBitmapData *data, in hbitmap_test_set() argument
151 hbitmap_set(data->hb, first, count); in hbitmap_test_set()
157 data->bits[pos] |= 1UL << bit; in hbitmap_test_set()
160 if (data->granularity == 0) { in hbitmap_test_set()
161 hbitmap_test_check(data, 0); in hbitmap_test_set()
167 static void hbitmap_test_reset(TestHBitmapData *data, in hbitmap_test_reset() argument
170 hbitmap_reset(data->hb, first, count); in hbitmap_test_reset()
176 data->bits[pos] &= ~(1UL << bit); in hbitmap_test_reset()
179 if (data->granularity == 0) { in hbitmap_test_reset()
180 hbitmap_test_check(data, 0); in hbitmap_test_reset()
184 static void hbitmap_test_reset_all(TestHBitmapData *data) in hbitmap_test_reset_all() argument
188 hbitmap_reset_all(data->hb); in hbitmap_test_reset_all()
190 n = DIV_ROUND_UP(data->size, BITS_PER_LONG); in hbitmap_test_reset_all()
194 memset(data->bits, 0, n * sizeof(unsigned long)); in hbitmap_test_reset_all()
196 if (data->granularity == 0) { in hbitmap_test_reset_all()
197 hbitmap_test_check(data, 0); in hbitmap_test_reset_all()
201 static void hbitmap_test_check_get(TestHBitmapData *data) in hbitmap_test_check_get() argument
206 for (i = 0; i < data->size; i++) { in hbitmap_test_check_get()
209 unsigned long val = data->bits[pos] & (1UL << bit); in hbitmap_test_check_get()
210 count += hbitmap_get(data->hb, i); in hbitmap_test_check_get()
211 g_assert_cmpint(hbitmap_get(data->hb, i), ==, val != 0); in hbitmap_test_check_get()
213 g_assert_cmpint(count, ==, hbitmap_count(data->hb)); in hbitmap_test_check_get()
216 static void test_hbitmap_zero(TestHBitmapData *data, in test_hbitmap_zero() argument
219 hbitmap_test_init(data, 0, 0); in test_hbitmap_zero()
222 static void test_hbitmap_unaligned(TestHBitmapData *data, in test_hbitmap_unaligned() argument
225 hbitmap_test_init(data, L3 + 23, 0); in test_hbitmap_unaligned()
226 hbitmap_test_set(data, 0, 1); in test_hbitmap_unaligned()
227 hbitmap_test_set(data, L3 + 22, 1); in test_hbitmap_unaligned()
230 static void test_hbitmap_iter_empty(TestHBitmapData *data, in test_hbitmap_iter_empty() argument
233 hbitmap_test_init(data, L1, 0); in test_hbitmap_iter_empty()
236 static void test_hbitmap_iter_partial(TestHBitmapData *data, in test_hbitmap_iter_partial() argument
239 hbitmap_test_init(data, L3, 0); in test_hbitmap_iter_partial()
240 hbitmap_test_set(data, 0, L3); in test_hbitmap_iter_partial()
241 hbitmap_test_check(data, 1); in test_hbitmap_iter_partial()
242 hbitmap_test_check(data, L1 - 1); in test_hbitmap_iter_partial()
243 hbitmap_test_check(data, L1); in test_hbitmap_iter_partial()
244 hbitmap_test_check(data, L1 * 2 - 1); in test_hbitmap_iter_partial()
245 hbitmap_test_check(data, L2 - 1); in test_hbitmap_iter_partial()
246 hbitmap_test_check(data, L2); in test_hbitmap_iter_partial()
247 hbitmap_test_check(data, L2 + 1); in test_hbitmap_iter_partial()
248 hbitmap_test_check(data, L2 + L1); in test_hbitmap_iter_partial()
249 hbitmap_test_check(data, L2 + L1 * 2 - 1); in test_hbitmap_iter_partial()
250 hbitmap_test_check(data, L2 * 2 - 1); in test_hbitmap_iter_partial()
251 hbitmap_test_check(data, L2 * 2); in test_hbitmap_iter_partial()
252 hbitmap_test_check(data, L2 * 2 + 1); in test_hbitmap_iter_partial()
253 hbitmap_test_check(data, L2 * 2 + L1); in test_hbitmap_iter_partial()
254 hbitmap_test_check(data, L2 * 2 + L1 * 2 - 1); in test_hbitmap_iter_partial()
255 hbitmap_test_check(data, L3 / 2); in test_hbitmap_iter_partial()
258 static void test_hbitmap_set_all(TestHBitmapData *data, in test_hbitmap_set_all() argument
261 hbitmap_test_init(data, L3, 0); in test_hbitmap_set_all()
262 hbitmap_test_set(data, 0, L3); in test_hbitmap_set_all()
265 static void test_hbitmap_get_all(TestHBitmapData *data, in test_hbitmap_get_all() argument
268 hbitmap_test_init(data, L3, 0); in test_hbitmap_get_all()
269 hbitmap_test_set(data, 0, L3); in test_hbitmap_get_all()
270 hbitmap_test_check_get(data); in test_hbitmap_get_all()
273 static void test_hbitmap_get_some(TestHBitmapData *data, in test_hbitmap_get_some() argument
276 hbitmap_test_init(data, 2 * L2, 0); in test_hbitmap_get_some()
277 hbitmap_test_set(data, 10, 1); in test_hbitmap_get_some()
278 hbitmap_test_check_get(data); in test_hbitmap_get_some()
279 hbitmap_test_set(data, L1 - 1, 1); in test_hbitmap_get_some()
280 hbitmap_test_check_get(data); in test_hbitmap_get_some()
281 hbitmap_test_set(data, L1, 1); in test_hbitmap_get_some()
282 hbitmap_test_check_get(data); in test_hbitmap_get_some()
283 hbitmap_test_set(data, L2 - 1, 1); in test_hbitmap_get_some()
284 hbitmap_test_check_get(data); in test_hbitmap_get_some()
285 hbitmap_test_set(data, L2, 1); in test_hbitmap_get_some()
286 hbitmap_test_check_get(data); in test_hbitmap_get_some()
289 static void test_hbitmap_set_one(TestHBitmapData *data, in test_hbitmap_set_one() argument
292 hbitmap_test_init(data, 2 * L2, 0); in test_hbitmap_set_one()
293 hbitmap_test_set(data, 10, 1); in test_hbitmap_set_one()
294 hbitmap_test_set(data, L1 - 1, 1); in test_hbitmap_set_one()
295 hbitmap_test_set(data, L1, 1); in test_hbitmap_set_one()
296 hbitmap_test_set(data, L2 - 1, 1); in test_hbitmap_set_one()
297 hbitmap_test_set(data, L2, 1); in test_hbitmap_set_one()
300 static void test_hbitmap_set_two_elem(TestHBitmapData *data, in test_hbitmap_set_two_elem() argument
303 hbitmap_test_init(data, 2 * L2, 0); in test_hbitmap_set_two_elem()
304 hbitmap_test_set(data, L1 - 1, 2); in test_hbitmap_set_two_elem()
305 hbitmap_test_set(data, L1 * 2 - 1, 4); in test_hbitmap_set_two_elem()
306 hbitmap_test_set(data, L1 * 4, L1 + 1); in test_hbitmap_set_two_elem()
307 hbitmap_test_set(data, L1 * 8 - 1, L1 + 1); in test_hbitmap_set_two_elem()
308 hbitmap_test_set(data, L2 - 1, 2); in test_hbitmap_set_two_elem()
309 hbitmap_test_set(data, L2 + L1 - 1, 8); in test_hbitmap_set_two_elem()
310 hbitmap_test_set(data, L2 + L1 * 4, L1 + 1); in test_hbitmap_set_two_elem()
311 hbitmap_test_set(data, L2 + L1 * 8 - 1, L1 + 1); in test_hbitmap_set_two_elem()
314 static void test_hbitmap_set(TestHBitmapData *data, in test_hbitmap_set() argument
317 hbitmap_test_init(data, L3 * 2, 0); in test_hbitmap_set()
318 hbitmap_test_set(data, L1 - 1, L1 + 2); in test_hbitmap_set()
319 hbitmap_test_set(data, L1 * 3 - 1, L1 + 2); in test_hbitmap_set()
320 hbitmap_test_set(data, L1 * 5, L1 * 2 + 1); in test_hbitmap_set()
321 hbitmap_test_set(data, L1 * 8 - 1, L1 * 2 + 1); in test_hbitmap_set()
322 hbitmap_test_set(data, L2 - 1, L1 + 2); in test_hbitmap_set()
323 hbitmap_test_set(data, L2 + L1 * 2 - 1, L1 + 2); in test_hbitmap_set()
324 hbitmap_test_set(data, L2 + L1 * 4, L1 * 2 + 1); in test_hbitmap_set()
325 hbitmap_test_set(data, L2 + L1 * 7 - 1, L1 * 2 + 1); in test_hbitmap_set()
326 hbitmap_test_set(data, L2 * 2 - 1, L3 * 2 - L2 * 2); in test_hbitmap_set()
329 static void test_hbitmap_set_twice(TestHBitmapData *data, in test_hbitmap_set_twice() argument
332 hbitmap_test_init(data, L1 * 3, 0); in test_hbitmap_set_twice()
333 hbitmap_test_set(data, 0, L1 * 3); in test_hbitmap_set_twice()
334 hbitmap_test_set(data, L1, 1); in test_hbitmap_set_twice()
337 static void test_hbitmap_set_overlap(TestHBitmapData *data, in test_hbitmap_set_overlap() argument
340 hbitmap_test_init(data, L3 * 2, 0); in test_hbitmap_set_overlap()
341 hbitmap_test_set(data, L1 - 1, L1 + 2); in test_hbitmap_set_overlap()
342 hbitmap_test_set(data, L1 * 2 - 1, L1 * 2 + 2); in test_hbitmap_set_overlap()
343 hbitmap_test_set(data, 0, L1 * 3); in test_hbitmap_set_overlap()
344 hbitmap_test_set(data, L1 * 8 - 1, L2); in test_hbitmap_set_overlap()
345 hbitmap_test_set(data, L2, L1); in test_hbitmap_set_overlap()
346 hbitmap_test_set(data, L2 - L1 - 1, L1 * 8 + 2); in test_hbitmap_set_overlap()
347 hbitmap_test_set(data, L2, L3 - L2 + 1); in test_hbitmap_set_overlap()
348 hbitmap_test_set(data, L3 - L1, L1 * 3); in test_hbitmap_set_overlap()
349 hbitmap_test_set(data, L3 - 1, 3); in test_hbitmap_set_overlap()
350 hbitmap_test_set(data, L3 - 1, L2); in test_hbitmap_set_overlap()
353 static void test_hbitmap_reset_empty(TestHBitmapData *data, in test_hbitmap_reset_empty() argument
356 hbitmap_test_init(data, L3, 0); in test_hbitmap_reset_empty()
357 hbitmap_test_reset(data, 0, L3); in test_hbitmap_reset_empty()
360 static void test_hbitmap_reset(TestHBitmapData *data, in test_hbitmap_reset() argument
363 hbitmap_test_init(data, L3 * 2, 0); in test_hbitmap_reset()
364 hbitmap_test_set(data, L1 - 1, L1 + 2); in test_hbitmap_reset()
365 hbitmap_test_reset(data, L1 * 2 - 1, L1 * 2 + 2); in test_hbitmap_reset()
366 hbitmap_test_set(data, 0, L1 * 3); in test_hbitmap_reset()
367 hbitmap_test_reset(data, L1 * 8 - 1, L2); in test_hbitmap_reset()
368 hbitmap_test_set(data, L2, L1); in test_hbitmap_reset()
369 hbitmap_test_reset(data, L2 - L1 - 1, L1 * 8 + 2); in test_hbitmap_reset()
370 hbitmap_test_set(data, L2, L3 - L2 + 1); in test_hbitmap_reset()
371 hbitmap_test_reset(data, L3 - L1, L1 * 3); in test_hbitmap_reset()
372 hbitmap_test_set(data, L3 - 1, 3); in test_hbitmap_reset()
373 hbitmap_test_reset(data, L3 - 1, L2); in test_hbitmap_reset()
374 hbitmap_test_set(data, 0, L3 * 2); in test_hbitmap_reset()
375 hbitmap_test_reset(data, 0, L1); in test_hbitmap_reset()
376 hbitmap_test_reset(data, 0, L2); in test_hbitmap_reset()
377 hbitmap_test_reset(data, L3, L3); in test_hbitmap_reset()
378 hbitmap_test_set(data, L3 / 2, L3); in test_hbitmap_reset()
381 static void test_hbitmap_reset_all(TestHBitmapData *data, in test_hbitmap_reset_all() argument
384 hbitmap_test_init(data, L3 * 2, 0); in test_hbitmap_reset_all()
385 hbitmap_test_set(data, L1 - 1, L1 + 2); in test_hbitmap_reset_all()
386 hbitmap_test_reset_all(data); in test_hbitmap_reset_all()
387 hbitmap_test_set(data, 0, L1 * 3); in test_hbitmap_reset_all()
388 hbitmap_test_reset_all(data); in test_hbitmap_reset_all()
389 hbitmap_test_set(data, L2, L1); in test_hbitmap_reset_all()
390 hbitmap_test_reset_all(data); in test_hbitmap_reset_all()
391 hbitmap_test_set(data, L2, L3 - L2 + 1); in test_hbitmap_reset_all()
392 hbitmap_test_reset_all(data); in test_hbitmap_reset_all()
393 hbitmap_test_set(data, L3 - 1, 3); in test_hbitmap_reset_all()
394 hbitmap_test_reset_all(data); in test_hbitmap_reset_all()
395 hbitmap_test_set(data, 0, L3 * 2); in test_hbitmap_reset_all()
396 hbitmap_test_reset_all(data); in test_hbitmap_reset_all()
397 hbitmap_test_set(data, L3 / 2, L3); in test_hbitmap_reset_all()
398 hbitmap_test_reset_all(data); in test_hbitmap_reset_all()
401 static void test_hbitmap_granularity(TestHBitmapData *data, in test_hbitmap_granularity() argument
405 hbitmap_test_init(data, L1, 1); in test_hbitmap_granularity()
406 hbitmap_test_set(data, 0, 1); in test_hbitmap_granularity()
407 g_assert_cmpint(hbitmap_count(data->hb), ==, 2); in test_hbitmap_granularity()
408 hbitmap_test_check(data, 0); in test_hbitmap_granularity()
409 hbitmap_test_set(data, 2, 1); in test_hbitmap_granularity()
410 g_assert_cmpint(hbitmap_count(data->hb), ==, 4); in test_hbitmap_granularity()
411 hbitmap_test_check(data, 0); in test_hbitmap_granularity()
412 hbitmap_test_set(data, 0, 3); in test_hbitmap_granularity()
413 g_assert_cmpint(hbitmap_count(data->hb), ==, 4); in test_hbitmap_granularity()
414 hbitmap_test_reset(data, 0, 2); in test_hbitmap_granularity()
415 g_assert_cmpint(hbitmap_count(data->hb), ==, 2); in test_hbitmap_granularity()
418 static void test_hbitmap_iter_granularity(TestHBitmapData *data, in test_hbitmap_iter_granularity() argument
424 hbitmap_test_init(data, 131072 << 7, 7); in test_hbitmap_iter_granularity()
425 hbitmap_iter_init(&hbi, data->hb, 0); in test_hbitmap_iter_granularity()
428 hbitmap_test_set(data, ((L2 + L1 + 1) << 7) + 8, 8); in test_hbitmap_iter_granularity()
429 hbitmap_iter_init(&hbi, data->hb, 0); in test_hbitmap_iter_granularity()
433 hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7); in test_hbitmap_iter_granularity()
436 hbitmap_test_set(data, (131072 << 7) - 8, 8); in test_hbitmap_iter_granularity()
437 hbitmap_iter_init(&hbi, data->hb, 0); in test_hbitmap_iter_granularity()
442 hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7); in test_hbitmap_iter_granularity()
447 static void hbitmap_test_set_boundary_bits(TestHBitmapData *data, ssize_t diff) in hbitmap_test_set_boundary_bits() argument
449 size_t size = data->size; in hbitmap_test_set_boundary_bits()
452 hbitmap_test_set(data, 0, 1); in hbitmap_test_set_boundary_bits()
455 hbitmap_test_set(data, size + diff - 1, 1); in hbitmap_test_set_boundary_bits()
458 hbitmap_test_set(data, size + diff, 1); in hbitmap_test_set_boundary_bits()
461 hbitmap_test_set(data, size - 1, 1); in hbitmap_test_set_boundary_bits()
462 if (data->granularity == 0) { in hbitmap_test_set_boundary_bits()
463 hbitmap_test_check_get(data); in hbitmap_test_set_boundary_bits()
467 static void hbitmap_test_check_boundary_bits(TestHBitmapData *data) in hbitmap_test_check_boundary_bits() argument
469 size_t size = MIN(data->size, data->old_size); in hbitmap_test_check_boundary_bits()
471 if (data->granularity == 0) { in hbitmap_test_check_boundary_bits()
472 hbitmap_test_check_get(data); in hbitmap_test_check_boundary_bits()
473 hbitmap_test_check(data, 0); in hbitmap_test_check_boundary_bits()
483 g_assert(hbitmap_get(data->hb, 0)); in hbitmap_test_check_boundary_bits()
484 g_assert(hbitmap_get(data->hb, size - 1)); in hbitmap_test_check_boundary_bits()
485 g_assert_cmpint(2 << data->granularity, ==, hbitmap_count(data->hb)); in hbitmap_test_check_boundary_bits()
490 static void hbitmap_test_truncate(TestHBitmapData *data, in hbitmap_test_truncate() argument
495 hbitmap_test_init(data, size, granularity); in hbitmap_test_truncate()
496 hbitmap_test_set_boundary_bits(data, diff); in hbitmap_test_truncate()
497 hbitmap_test_truncate_impl(data, size + diff); in hbitmap_test_truncate()
498 hbitmap_test_check_boundary_bits(data); in hbitmap_test_truncate()
501 static void test_hbitmap_truncate_nop(TestHBitmapData *data, in test_hbitmap_truncate_nop() argument
504 hbitmap_test_truncate(data, L2, 0, 0); in test_hbitmap_truncate_nop()
511 static void test_hbitmap_truncate_grow_negligible(TestHBitmapData *data, in test_hbitmap_truncate_grow_negligible() argument
518 hbitmap_test_truncate(data, size, diff, granularity); in test_hbitmap_truncate_grow_negligible()
525 static void test_hbitmap_truncate_shrink_negligible(TestHBitmapData *data, in test_hbitmap_truncate_shrink_negligible() argument
532 hbitmap_test_truncate(data, size, diff, granularity); in test_hbitmap_truncate_shrink_negligible()
539 static void test_hbitmap_truncate_grow_tiny(TestHBitmapData *data, in test_hbitmap_truncate_grow_tiny() argument
546 hbitmap_test_truncate(data, size, diff, granularity); in test_hbitmap_truncate_grow_tiny()
553 static void test_hbitmap_truncate_shrink_tiny(TestHBitmapData *data, in test_hbitmap_truncate_shrink_tiny() argument
560 hbitmap_test_truncate(data, size, diff, granularity); in test_hbitmap_truncate_shrink_tiny()
567 static void test_hbitmap_truncate_grow_small(TestHBitmapData *data, in test_hbitmap_truncate_grow_small() argument
573 hbitmap_test_truncate(data, size, diff, 0); in test_hbitmap_truncate_grow_small()
580 static void test_hbitmap_truncate_shrink_small(TestHBitmapData *data, in test_hbitmap_truncate_shrink_small() argument
586 hbitmap_test_truncate(data, size, -diff, 0); in test_hbitmap_truncate_shrink_small()
593 static void test_hbitmap_truncate_grow_medium(TestHBitmapData *data, in test_hbitmap_truncate_grow_medium() argument
599 hbitmap_test_truncate(data, size, diff, 0); in test_hbitmap_truncate_grow_medium()
606 static void test_hbitmap_truncate_shrink_medium(TestHBitmapData *data, in test_hbitmap_truncate_shrink_medium() argument
612 hbitmap_test_truncate(data, size, -diff, 0); in test_hbitmap_truncate_shrink_medium()
618 static void test_hbitmap_truncate_grow_large(TestHBitmapData *data, in test_hbitmap_truncate_grow_large() argument
624 hbitmap_test_truncate(data, size, diff, 0); in test_hbitmap_truncate_grow_large()
630 static void test_hbitmap_truncate_shrink_large(TestHBitmapData *data, in test_hbitmap_truncate_shrink_large() argument
636 hbitmap_test_truncate(data, size, -diff, 0); in test_hbitmap_truncate_shrink_large()
639 static void test_hbitmap_serialize_align(TestHBitmapData *data, in test_hbitmap_serialize_align() argument
644 hbitmap_test_init(data, L3 * 2, 3); in test_hbitmap_serialize_align()
645 g_assert(hbitmap_is_serializable(data->hb)); in test_hbitmap_serialize_align()
647 r = hbitmap_serialization_align(data->hb); in test_hbitmap_serialize_align()
651 static void hbitmap_test_serialize_range(TestHBitmapData *data, in hbitmap_test_serialize_range() argument
658 assert(hbitmap_granularity(data->hb) == 0); in hbitmap_test_serialize_range()
659 hbitmap_reset_all(data->hb); in hbitmap_test_serialize_range()
662 hbitmap_set(data->hb, pos, count); in hbitmap_test_serialize_range()
665 g_assert(hbitmap_is_serializable(data->hb)); in hbitmap_test_serialize_range()
666 hbitmap_serialize_part(data->hb, buf, 0, data->size); in hbitmap_test_serialize_range()
673 for (i = 0; i < data->size; i++) { in hbitmap_test_serialize_range()
684 hbitmap_serialize_part(data->hb, buf, 0, data->size); in hbitmap_test_serialize_range()
685 hbitmap_reset_all(data->hb); in hbitmap_test_serialize_range()
687 g_assert(hbitmap_is_serializable(data->hb)); in hbitmap_test_serialize_range()
688 hbitmap_deserialize_part(data->hb, buf, 0, data->size, true); in hbitmap_test_serialize_range()
690 for (i = 0; i < data->size; i++) { in hbitmap_test_serialize_range()
691 int is_set = hbitmap_get(data->hb, i); in hbitmap_test_serialize_range()
700 static void test_hbitmap_serialize_basic(TestHBitmapData *data, in test_hbitmap_serialize_basic() argument
709 hbitmap_test_init(data, L3, 0); in test_hbitmap_serialize_basic()
710 g_assert(hbitmap_is_serializable(data->hb)); in test_hbitmap_serialize_basic()
711 buf_size = hbitmap_serialization_size(data->hb, 0, data->size); in test_hbitmap_serialize_basic()
716 hbitmap_test_serialize_range(data, buf, buf_size, in test_hbitmap_serialize_basic()
725 static void test_hbitmap_serialize_part(TestHBitmapData *data, in test_hbitmap_serialize_part() argument
734 hbitmap_test_init(data, L3, 0); in test_hbitmap_serialize_part()
739 hbitmap_set(data->hb, positions[i], 1); in test_hbitmap_serialize_part()
742 g_assert(hbitmap_is_serializable(data->hb)); in test_hbitmap_serialize_part()
744 for (i = 0; i < data->size; i += buf_size) { in test_hbitmap_serialize_part()
746 hbitmap_serialize_part(data->hb, buf, i, buf_size); in test_hbitmap_serialize_part()
766 static void test_hbitmap_serialize_zeroes(TestHBitmapData *data, in test_hbitmap_serialize_zeroes() argument
776 hbitmap_test_init(data, L3, 0); in test_hbitmap_serialize_zeroes()
779 hbitmap_set(data->hb, positions[i], L1); in test_hbitmap_serialize_zeroes()
782 g_assert(hbitmap_is_serializable(data->hb)); in test_hbitmap_serialize_zeroes()
785 hbitmap_deserialize_zeroes(data->hb, positions[i], min_l1, true); in test_hbitmap_serialize_zeroes()
786 hbitmap_iter_init(&iter, data->hb, 0); in test_hbitmap_serialize_zeroes()
797 void (*test_func)(TestHBitmapData *data, const void *user_data)) in hbitmap_test_add() argument
803 static void test_hbitmap_iter_and_reset(TestHBitmapData *data, in test_hbitmap_iter_and_reset() argument
808 hbitmap_test_init(data, L1 * 2, 0); in test_hbitmap_iter_and_reset()
809 hbitmap_set(data->hb, 0, data->size); in test_hbitmap_iter_and_reset()
811 hbitmap_iter_init(&hbi, data->hb, BITS_PER_LONG - 1); in test_hbitmap_iter_and_reset()
815 hbitmap_reset_all(data->hb); in test_hbitmap_iter_and_reset()
819 static void test_hbitmap_next_x_check_range(TestHBitmapData *data, in test_hbitmap_next_x_check_range() argument
823 int64_t next_zero = hbitmap_next_zero(data->hb, start, count); in test_hbitmap_next_x_check_range()
824 int64_t next_dirty = hbitmap_next_dirty(data->hb, start, count); in test_hbitmap_next_x_check_range()
826 int64_t end = start >= data->size || data->size - start < count ? in test_hbitmap_next_x_check_range()
827 data->size : start + count; in test_hbitmap_next_x_check_range()
828 bool first_bit = hbitmap_get(data->hb, start); in test_hbitmap_next_x_check_range()
831 next < end && hbitmap_get(data->hb, next) == first_bit; in test_hbitmap_next_x_check_range()
845 static void test_hbitmap_next_x_check(TestHBitmapData *data, int64_t start) in test_hbitmap_next_x_check() argument
847 test_hbitmap_next_x_check_range(data, start, INT64_MAX); in test_hbitmap_next_x_check()
850 static void test_hbitmap_next_x_do(TestHBitmapData *data, int granularity) in test_hbitmap_next_x_do() argument
852 hbitmap_test_init(data, L3, granularity); in test_hbitmap_next_x_do()
853 test_hbitmap_next_x_check(data, 0); in test_hbitmap_next_x_do()
854 test_hbitmap_next_x_check(data, L3 - 1); in test_hbitmap_next_x_do()
855 test_hbitmap_next_x_check_range(data, 0, 1); in test_hbitmap_next_x_do()
856 test_hbitmap_next_x_check_range(data, L3 - 1, 1); in test_hbitmap_next_x_do()
858 hbitmap_set(data->hb, L2, 1); in test_hbitmap_next_x_do()
859 test_hbitmap_next_x_check(data, 0); in test_hbitmap_next_x_do()
860 test_hbitmap_next_x_check(data, L2 - 1); in test_hbitmap_next_x_do()
861 test_hbitmap_next_x_check(data, L2); in test_hbitmap_next_x_do()
862 test_hbitmap_next_x_check(data, L2 + 1); in test_hbitmap_next_x_do()
863 test_hbitmap_next_x_check_range(data, 0, 1); in test_hbitmap_next_x_do()
864 test_hbitmap_next_x_check_range(data, 0, L2); in test_hbitmap_next_x_do()
865 test_hbitmap_next_x_check_range(data, L2 - 1, 1); in test_hbitmap_next_x_do()
866 test_hbitmap_next_x_check_range(data, L2 - 1, 2); in test_hbitmap_next_x_do()
867 test_hbitmap_next_x_check_range(data, L2, 1); in test_hbitmap_next_x_do()
868 test_hbitmap_next_x_check_range(data, L2 + 1, 1); in test_hbitmap_next_x_do()
870 hbitmap_set(data->hb, L2 + 5, L1); in test_hbitmap_next_x_do()
871 test_hbitmap_next_x_check(data, 0); in test_hbitmap_next_x_do()
872 test_hbitmap_next_x_check(data, L2 - L1); in test_hbitmap_next_x_do()
873 test_hbitmap_next_x_check(data, L2 + 1); in test_hbitmap_next_x_do()
874 test_hbitmap_next_x_check(data, L2 + 2); in test_hbitmap_next_x_do()
875 test_hbitmap_next_x_check(data, L2 + 5); in test_hbitmap_next_x_do()
876 test_hbitmap_next_x_check(data, L2 + L1 - 1); in test_hbitmap_next_x_do()
877 test_hbitmap_next_x_check(data, L2 + L1); in test_hbitmap_next_x_do()
878 test_hbitmap_next_x_check(data, L2 + L1 + 1); in test_hbitmap_next_x_do()
879 test_hbitmap_next_x_check_range(data, L2 - 2, L1); in test_hbitmap_next_x_do()
880 test_hbitmap_next_x_check_range(data, L2, 4); in test_hbitmap_next_x_do()
881 test_hbitmap_next_x_check_range(data, L2, 6); in test_hbitmap_next_x_do()
882 test_hbitmap_next_x_check_range(data, L2 + 1, 3); in test_hbitmap_next_x_do()
883 test_hbitmap_next_x_check_range(data, L2 + 4, L1); in test_hbitmap_next_x_do()
884 test_hbitmap_next_x_check_range(data, L2 + 5, L1); in test_hbitmap_next_x_do()
885 test_hbitmap_next_x_check_range(data, L2 + 5 + L1 - 1, 1); in test_hbitmap_next_x_do()
886 test_hbitmap_next_x_check_range(data, L2 + 5 + L1, 1); in test_hbitmap_next_x_do()
887 test_hbitmap_next_x_check_range(data, L2 + 5 + L1 + 1, 1); in test_hbitmap_next_x_do()
889 hbitmap_set(data->hb, L2 * 2, L3 - L2 * 2); in test_hbitmap_next_x_do()
890 test_hbitmap_next_x_check(data, L2 * 2 - L1); in test_hbitmap_next_x_do()
891 test_hbitmap_next_x_check(data, L2 * 2 - 2); in test_hbitmap_next_x_do()
892 test_hbitmap_next_x_check(data, L2 * 2 - 1); in test_hbitmap_next_x_do()
893 test_hbitmap_next_x_check(data, L2 * 2); in test_hbitmap_next_x_do()
894 test_hbitmap_next_x_check(data, L2 * 2 + 1); in test_hbitmap_next_x_do()
895 test_hbitmap_next_x_check(data, L2 * 2 + L1); in test_hbitmap_next_x_do()
896 test_hbitmap_next_x_check(data, L3 - 1); in test_hbitmap_next_x_do()
897 test_hbitmap_next_x_check_range(data, L2 * 2 - L1, L1 + 1); in test_hbitmap_next_x_do()
898 test_hbitmap_next_x_check_range(data, L2 * 2, L2); in test_hbitmap_next_x_do()
900 hbitmap_set(data->hb, 0, L3); in test_hbitmap_next_x_do()
901 test_hbitmap_next_x_check(data, 0); in test_hbitmap_next_x_do()
904 static void test_hbitmap_next_x_0(TestHBitmapData *data, const void *unused) in test_hbitmap_next_x_0() argument
906 test_hbitmap_next_x_do(data, 0); in test_hbitmap_next_x_0()
909 static void test_hbitmap_next_x_4(TestHBitmapData *data, const void *unused) in test_hbitmap_next_x_4() argument
911 test_hbitmap_next_x_do(data, 4); in test_hbitmap_next_x_4()
914 static void test_hbitmap_next_x_after_truncate(TestHBitmapData *data, in test_hbitmap_next_x_after_truncate() argument
917 hbitmap_test_init(data, L1, 0); in test_hbitmap_next_x_after_truncate()
918 hbitmap_test_truncate_impl(data, L1 * 2); in test_hbitmap_next_x_after_truncate()
919 hbitmap_set(data->hb, 0, L1); in test_hbitmap_next_x_after_truncate()
920 test_hbitmap_next_x_check(data, 0); in test_hbitmap_next_x_after_truncate()
923 static void test_hbitmap_next_dirty_area_check_limited(TestHBitmapData *data, in test_hbitmap_next_dirty_area_check_limited() argument
933 ret1 = hbitmap_next_dirty_area(data->hb, in test_hbitmap_next_dirty_area_check_limited()
937 end = offset > data->size || data->size - offset < count ? data->size : in test_hbitmap_next_dirty_area_check_limited()
940 for (off2 = offset; off2 < end && !hbitmap_get(data->hb, off2); off2++) { in test_hbitmap_next_dirty_area_check_limited()
945 hbitmap_get(data->hb, off2 + len2)); len2++) in test_hbitmap_next_dirty_area_check_limited()
959 static void test_hbitmap_next_dirty_area_check(TestHBitmapData *data, in test_hbitmap_next_dirty_area_check() argument
962 test_hbitmap_next_dirty_area_check_limited(data, offset, count, INT64_MAX); in test_hbitmap_next_dirty_area_check()
965 static void test_hbitmap_next_dirty_area_do(TestHBitmapData *data, in test_hbitmap_next_dirty_area_do() argument
968 hbitmap_test_init(data, L3, granularity); in test_hbitmap_next_dirty_area_do()
969 test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); in test_hbitmap_next_dirty_area_do()
970 test_hbitmap_next_dirty_area_check(data, 0, 1); in test_hbitmap_next_dirty_area_do()
971 test_hbitmap_next_dirty_area_check(data, L3 - 1, 1); in test_hbitmap_next_dirty_area_do()
972 test_hbitmap_next_dirty_area_check_limited(data, 0, INT64_MAX, 1); in test_hbitmap_next_dirty_area_do()
974 hbitmap_set(data->hb, L2, 1); in test_hbitmap_next_dirty_area_do()
975 test_hbitmap_next_dirty_area_check(data, 0, 1); in test_hbitmap_next_dirty_area_do()
976 test_hbitmap_next_dirty_area_check(data, 0, L2); in test_hbitmap_next_dirty_area_do()
977 test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); in test_hbitmap_next_dirty_area_do()
978 test_hbitmap_next_dirty_area_check(data, L2 - 1, INT64_MAX); in test_hbitmap_next_dirty_area_do()
979 test_hbitmap_next_dirty_area_check(data, L2 - 1, 1); in test_hbitmap_next_dirty_area_do()
980 test_hbitmap_next_dirty_area_check(data, L2 - 1, 2); in test_hbitmap_next_dirty_area_do()
981 test_hbitmap_next_dirty_area_check(data, L2 - 1, 3); in test_hbitmap_next_dirty_area_do()
982 test_hbitmap_next_dirty_area_check(data, L2, INT64_MAX); in test_hbitmap_next_dirty_area_do()
983 test_hbitmap_next_dirty_area_check(data, L2, 1); in test_hbitmap_next_dirty_area_do()
984 test_hbitmap_next_dirty_area_check(data, L2 + 1, 1); in test_hbitmap_next_dirty_area_do()
985 test_hbitmap_next_dirty_area_check_limited(data, 0, INT64_MAX, 1); in test_hbitmap_next_dirty_area_do()
986 test_hbitmap_next_dirty_area_check_limited(data, L2 - 1, 2, 1); in test_hbitmap_next_dirty_area_do()
988 hbitmap_set(data->hb, L2 + 5, L1); in test_hbitmap_next_dirty_area_do()
989 test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); in test_hbitmap_next_dirty_area_do()
990 test_hbitmap_next_dirty_area_check(data, L2 - 2, 8); in test_hbitmap_next_dirty_area_do()
991 test_hbitmap_next_dirty_area_check(data, L2 + 1, 5); in test_hbitmap_next_dirty_area_do()
992 test_hbitmap_next_dirty_area_check(data, L2 + 1, 3); in test_hbitmap_next_dirty_area_do()
993 test_hbitmap_next_dirty_area_check(data, L2 + 4, L1); in test_hbitmap_next_dirty_area_do()
994 test_hbitmap_next_dirty_area_check(data, L2 + 5, L1); in test_hbitmap_next_dirty_area_do()
995 test_hbitmap_next_dirty_area_check(data, L2 + 7, L1); in test_hbitmap_next_dirty_area_do()
996 test_hbitmap_next_dirty_area_check(data, L2 + L1, L1); in test_hbitmap_next_dirty_area_do()
997 test_hbitmap_next_dirty_area_check(data, L2, 0); in test_hbitmap_next_dirty_area_do()
998 test_hbitmap_next_dirty_area_check(data, L2 + 1, 0); in test_hbitmap_next_dirty_area_do()
999 test_hbitmap_next_dirty_area_check_limited(data, L2 + 3, INT64_MAX, 3); in test_hbitmap_next_dirty_area_do()
1000 test_hbitmap_next_dirty_area_check_limited(data, L2 + 3, 7, 10); in test_hbitmap_next_dirty_area_do()
1002 hbitmap_set(data->hb, L2 * 2, L3 - L2 * 2); in test_hbitmap_next_dirty_area_do()
1003 test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); in test_hbitmap_next_dirty_area_do()
1004 test_hbitmap_next_dirty_area_check(data, L2, INT64_MAX); in test_hbitmap_next_dirty_area_do()
1005 test_hbitmap_next_dirty_area_check(data, L2 + 1, INT64_MAX); in test_hbitmap_next_dirty_area_do()
1006 test_hbitmap_next_dirty_area_check(data, L2 + 5 + L1 - 1, INT64_MAX); in test_hbitmap_next_dirty_area_do()
1007 test_hbitmap_next_dirty_area_check(data, L2 + 5 + L1, 5); in test_hbitmap_next_dirty_area_do()
1008 test_hbitmap_next_dirty_area_check(data, L2 * 2 - L1, L1 + 1); in test_hbitmap_next_dirty_area_do()
1009 test_hbitmap_next_dirty_area_check(data, L2 * 2, L2); in test_hbitmap_next_dirty_area_do()
1010 test_hbitmap_next_dirty_area_check_limited(data, L2 * 2 + 1, INT64_MAX, 5); in test_hbitmap_next_dirty_area_do()
1011 test_hbitmap_next_dirty_area_check_limited(data, L2 * 2 + 1, 10, 5); in test_hbitmap_next_dirty_area_do()
1012 test_hbitmap_next_dirty_area_check_limited(data, L2 * 2 + 1, 2, 5); in test_hbitmap_next_dirty_area_do()
1014 hbitmap_set(data->hb, 0, L3); in test_hbitmap_next_dirty_area_do()
1015 test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); in test_hbitmap_next_dirty_area_do()
1018 static void test_hbitmap_next_dirty_area_0(TestHBitmapData *data, in test_hbitmap_next_dirty_area_0() argument
1021 test_hbitmap_next_dirty_area_do(data, 0); in test_hbitmap_next_dirty_area_0()
1024 static void test_hbitmap_next_dirty_area_1(TestHBitmapData *data, in test_hbitmap_next_dirty_area_1() argument
1027 test_hbitmap_next_dirty_area_do(data, 1); in test_hbitmap_next_dirty_area_1()
1030 static void test_hbitmap_next_dirty_area_4(TestHBitmapData *data, in test_hbitmap_next_dirty_area_4() argument
1033 test_hbitmap_next_dirty_area_do(data, 4); in test_hbitmap_next_dirty_area_4()
1036 static void test_hbitmap_next_dirty_area_after_truncate(TestHBitmapData *data, in test_hbitmap_next_dirty_area_after_truncate() argument
1039 hbitmap_test_init(data, L1, 0); in test_hbitmap_next_dirty_area_after_truncate()
1040 hbitmap_test_truncate_impl(data, L1 * 2); in test_hbitmap_next_dirty_area_after_truncate()
1041 hbitmap_set(data->hb, L1 + 1, 1); in test_hbitmap_next_dirty_area_after_truncate()
1042 test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); in test_hbitmap_next_dirty_area_after_truncate()