Add arena-level name.

An arena-level name can help identify manual arenas.
This commit is contained in:
Guangli Dai
2022-09-01 16:42:56 -07:00
committed by Qi Wang
parent a0734fd6ee
commit ba19d2cb78
8 changed files with 146 additions and 9 deletions

View File

@@ -266,7 +266,7 @@
#define expect_false(a, ...) expect_b_eq(a, false, __VA_ARGS__)
#define verify_str_eq(may_abort, a, b, ...) do { \
if (strcmp((a), (b))) { \
if (strcmp((a), (b)) != 0) { \
char prefix[ASSERT_BUFSIZE]; \
char message[ASSERT_BUFSIZE]; \
malloc_snprintf(prefix, sizeof(prefix), \
@@ -284,7 +284,7 @@
} while (0)
#define verify_str_ne(may_abort, a, b, ...) do { \
if (!strcmp((a), (b))) { \
if (strcmp((a), (b)) == 0) { \
char prefix[ASSERT_BUFSIZE]; \
char message[ASSERT_BUFSIZE]; \
malloc_snprintf(prefix, sizeof(prefix), \

View File

@@ -711,6 +711,48 @@ TEST_BEGIN(test_arena_i_dss) {
}
TEST_END
TEST_BEGIN(test_arena_i_name) {
unsigned arena_ind;
size_t ind_sz = sizeof(arena_ind);
size_t mib[3];
size_t miblen;
char name_old[ARENA_NAME_LEN];
char *name_oldp = name_old;
size_t sz = sizeof(name_oldp);
char default_name[ARENA_NAME_LEN];
const char *name_new = "test name";
const char *super_long_name = "A name longer than ARENA_NAME_LEN";
size_t super_long_name_len = strlen(super_long_name);
assert(super_long_name_len > ARENA_NAME_LEN);
miblen = sizeof(mib)/sizeof(size_t);
expect_d_eq(mallctlnametomib("arena.0.name", mib, &miblen), 0,
"Unexpected mallctlnametomib() error");
expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &ind_sz, NULL,
0), 0, "Unexpected mallctl() failure");
mib[1] = arena_ind;
malloc_snprintf(default_name, sizeof(default_name), "manual_%u",
arena_ind);
expect_d_eq(mallctlbymib(mib, miblen, (void *)&name_oldp, &sz,
(void *)&name_new, sizeof(name_new)), 0,
"Unexpected mallctl() failure");
expect_str_eq(name_old, default_name,
"Unexpected default value for arena name");
expect_d_eq(mallctlbymib(mib, miblen, (void *)&name_oldp, &sz,
(void *)&super_long_name, sizeof(super_long_name)), 0,
"Unexpected mallctl() failure");
expect_str_eq(name_old, name_new, "Unexpected value for arena name");
expect_d_eq(mallctlbymib(mib, miblen, (void *)&name_oldp, &sz,
NULL, 0), 0, "Unexpected mallctl() failure");
int cmp = strncmp(name_old, super_long_name, ARENA_NAME_LEN - 1);
expect_true(cmp == 0, "Unexpected value for long arena name ");
}
TEST_END
TEST_BEGIN(test_arena_i_retain_grow_limit) {
size_t old_limit, new_limit, default_limit;
size_t mib[3];
@@ -1258,6 +1300,7 @@ main(void) {
test_arena_i_purge,
test_arena_i_decay,
test_arena_i_dss,
test_arena_i_name,
test_arena_i_retain_grow_limit,
test_arenas_dirty_decay_ms,
test_arenas_muzzy_decay_ms,