2014-01-03 08:08:28 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
2017-05-24 05:26:31 +08:00
|
|
|
#include "jemalloc/internal/rtree.h"
|
|
|
|
|
2019-09-21 09:20:22 +08:00
|
|
|
#define INVALID_ARENA_IND ((1U << MALLOCX_ARENA_BITS) - 1)
|
|
|
|
|
2017-03-23 07:38:03 +08:00
|
|
|
/* Potentially too large to safely place on the stack. */
|
|
|
|
rtree_t test_rtree;
|
2016-04-16 15:36:11 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_rtree_read_empty) {
|
2016-04-16 15:36:11 +08:00
|
|
|
tsdn_t *tsdn;
|
2014-01-03 08:08:28 +08:00
|
|
|
|
2016-04-16 15:36:11 +08:00
|
|
|
tsdn = tsdn_fetch();
|
|
|
|
|
2020-02-18 05:11:10 +08:00
|
|
|
base_t *base = base_new(tsdn, 0, &ehooks_default_extent_hooks);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(base, "Unexpected base_new failure");
|
2020-02-18 05:11:10 +08:00
|
|
|
|
2017-03-23 07:38:03 +08:00
|
|
|
rtree_t *rtree = &test_rtree;
|
2017-03-30 04:18:02 +08:00
|
|
|
rtree_ctx_t rtree_ctx;
|
|
|
|
rtree_ctx_data_init(&rtree_ctx);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_false(rtree_new(rtree, base, false),
|
2020-02-18 05:11:10 +08:00
|
|
|
"Unexpected rtree_new() failure");
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_null(rtree_edata_read(tsdn, rtree, &rtree_ctx, PAGE,
|
2019-12-10 06:36:45 +08:00
|
|
|
false), "rtree_edata_read() should return NULL for empty tree");
|
2020-02-18 05:11:10 +08:00
|
|
|
|
|
|
|
base_delete(tsdn, base);
|
2014-01-03 08:08:28 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2016-03-28 18:06:35 +08:00
|
|
|
#undef NTHREADS
|
|
|
|
#undef NITERS
|
|
|
|
#undef SEED
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_rtree_extrema) {
|
2019-12-10 06:36:45 +08:00
|
|
|
edata_t edata_a, edata_b;
|
|
|
|
edata_init(&edata_a, INVALID_ARENA_IND, NULL, SC_LARGE_MINCLASS,
|
2019-09-21 09:20:22 +08:00
|
|
|
false, sz_size2index(SC_LARGE_MINCLASS), 0,
|
2019-07-13 07:20:23 +08:00
|
|
|
extent_state_active, false, false, true, EXTENT_NOT_HEAD);
|
2019-12-10 06:36:45 +08:00
|
|
|
edata_init(&edata_b, INVALID_ARENA_IND, NULL, 0, false, SC_NSIZES, 0,
|
2019-07-13 07:20:23 +08:00
|
|
|
extent_state_active, false, false, true, EXTENT_NOT_HEAD);
|
2016-04-16 15:36:11 +08:00
|
|
|
|
2017-03-17 08:57:52 +08:00
|
|
|
tsdn_t *tsdn = tsdn_fetch();
|
2014-01-03 08:08:28 +08:00
|
|
|
|
2020-02-18 05:11:10 +08:00
|
|
|
base_t *base = base_new(tsdn, 0, &ehooks_default_extent_hooks);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(base, "Unexpected base_new failure");
|
2020-02-18 05:11:10 +08:00
|
|
|
|
2017-03-23 07:38:03 +08:00
|
|
|
rtree_t *rtree = &test_rtree;
|
2017-03-30 04:18:02 +08:00
|
|
|
rtree_ctx_t rtree_ctx;
|
|
|
|
rtree_ctx_data_init(&rtree_ctx);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_false(rtree_new(rtree, base, false),
|
2020-02-18 05:11:10 +08:00
|
|
|
"Unexpected rtree_new() failure");
|
2014-01-03 08:08:28 +08:00
|
|
|
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_false(rtree_write(tsdn, rtree, &rtree_ctx, PAGE, &edata_a,
|
2019-12-10 06:36:45 +08:00
|
|
|
edata_szind_get(&edata_a), edata_slab_get(&edata_a)),
|
2017-02-07 05:17:12 +08:00
|
|
|
"Unexpected rtree_write() failure");
|
2017-03-23 07:38:03 +08:00
|
|
|
rtree_szind_slab_update(tsdn, rtree, &rtree_ctx, PAGE,
|
2019-12-10 06:36:45 +08:00
|
|
|
edata_szind_get(&edata_a), edata_slab_get(&edata_a));
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_eq(rtree_edata_read(tsdn, rtree, &rtree_ctx, PAGE, true),
|
2019-12-10 06:36:45 +08:00
|
|
|
&edata_a,
|
|
|
|
"rtree_edata_read() should return previously set value");
|
2014-01-03 08:08:28 +08:00
|
|
|
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_false(rtree_write(tsdn, rtree, &rtree_ctx, ~((uintptr_t)0),
|
2019-12-10 06:36:45 +08:00
|
|
|
&edata_b, edata_szind_get_maybe_invalid(&edata_b),
|
|
|
|
edata_slab_get(&edata_b)), "Unexpected rtree_write() failure");
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_eq(rtree_edata_read(tsdn, rtree, &rtree_ctx,
|
2019-12-10 06:36:45 +08:00
|
|
|
~((uintptr_t)0), true), &edata_b,
|
|
|
|
"rtree_edata_read() should return previously set value");
|
2017-02-07 05:17:12 +08:00
|
|
|
|
2020-02-18 05:11:10 +08:00
|
|
|
base_delete(tsdn, base);
|
2014-01-03 08:08:28 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_rtree_bits) {
|
2017-02-07 05:17:12 +08:00
|
|
|
tsdn_t *tsdn = tsdn_fetch();
|
2020-02-18 05:11:10 +08:00
|
|
|
base_t *base = base_new(tsdn, 0, &ehooks_default_extent_hooks);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(base, "Unexpected base_new failure");
|
2014-01-03 08:08:28 +08:00
|
|
|
|
2017-02-05 18:50:59 +08:00
|
|
|
uintptr_t keys[] = {PAGE, PAGE + 1,
|
|
|
|
PAGE + (((uintptr_t)1) << LG_PAGE) - 1};
|
2016-04-16 15:36:11 +08:00
|
|
|
|
2019-12-10 06:36:45 +08:00
|
|
|
edata_t edata;
|
|
|
|
edata_init(&edata, INVALID_ARENA_IND, NULL, 0, false, SC_NSIZES, 0,
|
2019-07-13 07:20:23 +08:00
|
|
|
extent_state_active, false, false, true, EXTENT_NOT_HEAD);
|
2017-03-17 08:57:52 +08:00
|
|
|
|
2017-03-23 07:38:03 +08:00
|
|
|
rtree_t *rtree = &test_rtree;
|
2017-03-30 04:18:02 +08:00
|
|
|
rtree_ctx_t rtree_ctx;
|
|
|
|
rtree_ctx_data_init(&rtree_ctx);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_false(rtree_new(rtree, base, false),
|
2020-02-18 05:11:10 +08:00
|
|
|
"Unexpected rtree_new() failure");
|
2017-02-07 05:17:12 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < sizeof(keys)/sizeof(uintptr_t); i++) {
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_false(rtree_write(tsdn, rtree, &rtree_ctx, keys[i],
|
2019-12-10 06:36:45 +08:00
|
|
|
&edata, SC_NSIZES, false),
|
2017-03-17 08:57:52 +08:00
|
|
|
"Unexpected rtree_write() failure");
|
2017-02-07 05:17:12 +08:00
|
|
|
for (unsigned j = 0; j < sizeof(keys)/sizeof(uintptr_t); j++) {
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_eq(rtree_edata_read(tsdn, rtree, &rtree_ctx,
|
2019-12-10 06:36:45 +08:00
|
|
|
keys[j], true), &edata,
|
|
|
|
"rtree_edata_read() should return previously set "
|
2017-03-23 07:38:03 +08:00
|
|
|
"value and ignore insignificant key bits; i=%u, "
|
|
|
|
"j=%u, set key=%#"FMTxPTR", get key=%#"FMTxPTR, i,
|
|
|
|
j, keys[i], keys[j]);
|
2017-02-07 05:17:12 +08:00
|
|
|
}
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_null(rtree_edata_read(tsdn, rtree, &rtree_ctx,
|
2017-02-05 18:50:59 +08:00
|
|
|
(((uintptr_t)2) << LG_PAGE), false),
|
2017-02-07 05:17:12 +08:00
|
|
|
"Only leftmost rtree leaf should be set; i=%u", i);
|
2017-03-23 07:38:03 +08:00
|
|
|
rtree_clear(tsdn, rtree, &rtree_ctx, keys[i]);
|
2014-01-03 08:08:28 +08:00
|
|
|
}
|
2017-02-07 05:17:12 +08:00
|
|
|
|
2020-02-18 05:11:10 +08:00
|
|
|
base_delete(tsdn, base);
|
2014-01-03 08:08:28 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_rtree_random) {
|
2017-01-20 13:41:41 +08:00
|
|
|
#define NSET 16
|
|
|
|
#define SEED 42
|
2017-02-07 05:17:12 +08:00
|
|
|
sfmt_t *sfmt = init_gen_rand(SEED);
|
|
|
|
tsdn_t *tsdn = tsdn_fetch();
|
2020-02-18 05:11:10 +08:00
|
|
|
|
|
|
|
base_t *base = base_new(tsdn, 0, &ehooks_default_extent_hooks);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(base, "Unexpected base_new failure");
|
2020-02-18 05:11:10 +08:00
|
|
|
|
2017-02-07 05:17:12 +08:00
|
|
|
uintptr_t keys[NSET];
|
2017-03-23 07:38:03 +08:00
|
|
|
rtree_t *rtree = &test_rtree;
|
2017-03-30 04:18:02 +08:00
|
|
|
rtree_ctx_t rtree_ctx;
|
|
|
|
rtree_ctx_data_init(&rtree_ctx);
|
2017-02-07 05:17:12 +08:00
|
|
|
|
2019-12-10 06:36:45 +08:00
|
|
|
edata_t edata;
|
|
|
|
edata_init(&edata, INVALID_ARENA_IND, NULL, 0, false, SC_NSIZES, 0,
|
2019-07-13 07:20:23 +08:00
|
|
|
extent_state_active, false, false, true, EXTENT_NOT_HEAD);
|
2017-03-17 08:57:52 +08:00
|
|
|
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_false(rtree_new(rtree, base, false),
|
2020-02-18 05:11:10 +08:00
|
|
|
"Unexpected rtree_new() failure");
|
2017-02-07 05:17:12 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < NSET; i++) {
|
|
|
|
keys[i] = (uintptr_t)gen_rand64(sfmt);
|
2017-05-16 05:23:51 +08:00
|
|
|
rtree_leaf_elm_t *elm = rtree_leaf_elm_lookup(tsdn, rtree,
|
2017-03-17 00:46:42 +08:00
|
|
|
&rtree_ctx, keys[i], false, true);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(elm,
|
2017-05-16 05:23:51 +08:00
|
|
|
"Unexpected rtree_leaf_elm_lookup() failure");
|
2020-03-14 02:47:51 +08:00
|
|
|
rtree_leaf_elm_contents_t contents;
|
|
|
|
contents.edata = &edata;
|
|
|
|
contents.szind = SC_NSIZES;
|
|
|
|
contents.slab = false;
|
|
|
|
rtree_leaf_elm_write(tsdn, rtree, elm, contents);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_eq(rtree_edata_read(tsdn, rtree, &rtree_ctx,
|
2019-12-10 06:36:45 +08:00
|
|
|
keys[i], true), &edata,
|
|
|
|
"rtree_edata_read() should return previously set value");
|
2017-02-07 05:17:12 +08:00
|
|
|
}
|
|
|
|
for (unsigned i = 0; i < NSET; i++) {
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_eq(rtree_edata_read(tsdn, rtree, &rtree_ctx,
|
2019-12-10 06:36:45 +08:00
|
|
|
keys[i], true), &edata,
|
|
|
|
"rtree_edata_read() should return previously set value, "
|
2017-03-17 08:57:52 +08:00
|
|
|
"i=%u", i);
|
2017-02-07 05:17:12 +08:00
|
|
|
}
|
2014-01-03 08:08:28 +08:00
|
|
|
|
2017-02-07 05:17:12 +08:00
|
|
|
for (unsigned i = 0; i < NSET; i++) {
|
2017-03-23 07:38:03 +08:00
|
|
|
rtree_clear(tsdn, rtree, &rtree_ctx, keys[i]);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_null(rtree_edata_read(tsdn, rtree, &rtree_ctx,
|
2017-03-17 08:57:52 +08:00
|
|
|
keys[i], true),
|
2019-12-10 06:36:45 +08:00
|
|
|
"rtree_edata_read() should return previously set value");
|
2014-01-03 08:08:28 +08:00
|
|
|
}
|
2017-02-07 05:17:12 +08:00
|
|
|
for (unsigned i = 0; i < NSET; i++) {
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_null(rtree_edata_read(tsdn, rtree, &rtree_ctx,
|
2017-03-17 08:57:52 +08:00
|
|
|
keys[i], true),
|
2019-12-10 06:36:45 +08:00
|
|
|
"rtree_edata_read() should return previously set value");
|
2017-02-07 05:17:12 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 05:11:10 +08:00
|
|
|
base_delete(tsdn, base);
|
2014-01-03 08:08:28 +08:00
|
|
|
fini_gen_rand(sfmt);
|
|
|
|
#undef NSET
|
|
|
|
#undef SEED
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
2017-01-16 08:56:30 +08:00
|
|
|
main(void) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return test(
|
2016-03-28 18:06:35 +08:00
|
|
|
test_rtree_read_empty,
|
2014-01-03 08:08:28 +08:00
|
|
|
test_rtree_extrema,
|
|
|
|
test_rtree_bits,
|
2017-01-20 10:15:45 +08:00
|
|
|
test_rtree_random);
|
2014-01-03 08:08:28 +08:00
|
|
|
}
|