Reformat the codebase with the clang-format 18.

This commit is contained in:
guangli-dai 2025-06-13 12:31:12 -07:00 committed by Guangli Dai
parent 0a6215c171
commit f1bba4a87c
346 changed files with 18286 additions and 17770 deletions

View file

@ -3,37 +3,31 @@
#include "test/extent_hooks.h"
static extent_hooks_t hooks_null = {
extent_alloc_hook,
NULL, /* dalloc */
NULL, /* destroy */
NULL, /* commit */
NULL, /* decommit */
NULL, /* purge_lazy */
NULL, /* purge_forced */
NULL, /* split */
NULL /* merge */
extent_alloc_hook, NULL, /* dalloc */
NULL, /* destroy */
NULL, /* commit */
NULL, /* decommit */
NULL, /* purge_lazy */
NULL, /* purge_forced */
NULL, /* split */
NULL /* merge */
};
static extent_hooks_t hooks_not_null = {
extent_alloc_hook,
extent_dalloc_hook,
extent_destroy_hook,
NULL, /* commit */
extent_decommit_hook,
extent_purge_lazy_hook,
extent_purge_forced_hook,
NULL, /* split */
NULL /* merge */
extent_alloc_hook, extent_dalloc_hook, extent_destroy_hook,
NULL, /* commit */
extent_decommit_hook, extent_purge_lazy_hook, extent_purge_forced_hook,
NULL, /* split */
NULL /* merge */
};
TEST_BEGIN(test_base_hooks_default) {
base_t *base;
size_t allocated0, allocated1, edata_allocated,
rtree_allocated, resident, mapped, n_thp;
size_t allocated0, allocated1, edata_allocated, rtree_allocated,
resident, mapped, n_thp;
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
base = base_new(tsdn, 0,
(extent_hooks_t *)&ehooks_default_extent_hooks,
base = base_new(tsdn, 0, (extent_hooks_t *)&ehooks_default_extent_hooks,
/* metadata_use_hooks */ true);
if (config_stats) {
@ -42,13 +36,13 @@ TEST_BEGIN(test_base_hooks_default) {
expect_zu_ge(allocated0, sizeof(base_t),
"Base header should count as allocated");
if (opt_metadata_thp == metadata_thp_always) {
expect_zu_gt(n_thp, 0,
"Base should have 1 THP at least.");
expect_zu_gt(
n_thp, 0, "Base should have 1 THP at least.");
}
}
expect_ptr_not_null(base_alloc(tsdn, base, 42, 1),
"Unexpected base_alloc() failure");
expect_ptr_not_null(
base_alloc(tsdn, base, 42, 1), "Unexpected base_alloc() failure");
if (config_stats) {
base_stats_get(tsdn, base, &allocated1, &edata_allocated,
@ -63,9 +57,9 @@ TEST_END
TEST_BEGIN(test_base_hooks_null) {
extent_hooks_t hooks_orig;
base_t *base;
size_t allocated0, allocated1, edata_allocated,
rtree_allocated, resident, mapped, n_thp;
base_t *base;
size_t allocated0, allocated1, edata_allocated, rtree_allocated,
resident, mapped, n_thp;
extent_hooks_prep();
try_dalloc = false;
@ -86,13 +80,13 @@ TEST_BEGIN(test_base_hooks_null) {
expect_zu_ge(allocated0, sizeof(base_t),
"Base header should count as allocated");
if (opt_metadata_thp == metadata_thp_always) {
expect_zu_gt(n_thp, 0,
"Base should have 1 THP at least.");
expect_zu_gt(
n_thp, 0, "Base should have 1 THP at least.");
}
}
expect_ptr_not_null(base_alloc(tsdn, base, 42, 1),
"Unexpected base_alloc() failure");
expect_ptr_not_null(
base_alloc(tsdn, base, 42, 1), "Unexpected base_alloc() failure");
if (config_stats) {
base_stats_get(tsdn, base, &allocated1, &edata_allocated,
@ -109,8 +103,8 @@ TEST_END
TEST_BEGIN(test_base_hooks_not_null) {
extent_hooks_t hooks_orig;
base_t *base;
void *p, *q, *r, *r_exp;
base_t *base;
void *p, *q, *r, *r_exp;
extent_hooks_prep();
try_dalloc = false;
@ -133,33 +127,34 @@ TEST_BEGIN(test_base_hooks_not_null) {
*/
{
const size_t alignments[] = {
1,
QUANTUM,
QUANTUM << 1,
CACHELINE,
CACHELINE << 1,
1,
QUANTUM,
QUANTUM << 1,
CACHELINE,
CACHELINE << 1,
};
unsigned i;
for (i = 0; i < sizeof(alignments) / sizeof(size_t); i++) {
size_t alignment = alignments[i];
size_t align_ceil = ALIGNMENT_CEILING(alignment,
QUANTUM);
size_t align_ceil = ALIGNMENT_CEILING(
alignment, QUANTUM);
p = base_alloc(tsdn, base, 1, alignment);
expect_ptr_not_null(p,
"Unexpected base_alloc() failure");
expect_ptr_not_null(
p, "Unexpected base_alloc() failure");
expect_ptr_eq(p,
(void *)(ALIGNMENT_CEILING((uintptr_t)p,
alignment)), "Expected quantum alignment");
(void *)(ALIGNMENT_CEILING(
(uintptr_t)p, alignment)),
"Expected quantum alignment");
q = base_alloc(tsdn, base, alignment, alignment);
expect_ptr_not_null(q,
"Unexpected base_alloc() failure");
expect_ptr_not_null(
q, "Unexpected base_alloc() failure");
expect_ptr_eq((void *)((uintptr_t)p + align_ceil), q,
"Minimal allocation should take up %zu bytes",
align_ceil);
r = base_alloc(tsdn, base, 1, alignment);
expect_ptr_not_null(r,
"Unexpected base_alloc() failure");
expect_ptr_not_null(
r, "Unexpected base_alloc() failure");
expect_ptr_eq((void *)((uintptr_t)q + align_ceil), r,
"Minimal allocation should take up %zu bytes",
align_ceil);
@ -193,21 +188,18 @@ TEST_BEGIN(test_base_hooks_not_null) {
* Check for proper alignment support when normal blocks are too small.
*/
{
const size_t alignments[] = {
HUGEPAGE,
HUGEPAGE << 1
};
unsigned i;
const size_t alignments[] = {HUGEPAGE, HUGEPAGE << 1};
unsigned i;
for (i = 0; i < sizeof(alignments) / sizeof(size_t); i++) {
size_t alignment = alignments[i];
p = base_alloc(tsdn, base, QUANTUM, alignment);
expect_ptr_not_null(p,
"Unexpected base_alloc() failure");
expect_ptr_not_null(
p, "Unexpected base_alloc() failure");
expect_ptr_eq(p,
(void *)(ALIGNMENT_CEILING((uintptr_t)p,
alignment)), "Expected %zu-byte alignment",
alignment);
(void *)(ALIGNMENT_CEILING(
(uintptr_t)p, alignment)),
"Expected %zu-byte alignment", alignment);
}
}
@ -237,12 +229,11 @@ TEST_BEGIN(test_base_ehooks_get_for_metadata_default_hook) {
base = base_new(tsdn, 0, &hooks, /* metadata_use_hooks */ false);
ehooks_t *ehooks = base_ehooks_get_for_metadata(base);
expect_true(ehooks_are_default(ehooks),
"Expected default extent hook functions pointer");
"Expected default extent hook functions pointer");
base_delete(tsdn, base);
}
TEST_END
TEST_BEGIN(test_base_ehooks_get_for_metadata_custom_hook) {
extent_hooks_prep();
memcpy(&hooks, &hooks_not_null, sizeof(extent_hooks_t));
@ -251,17 +242,15 @@ TEST_BEGIN(test_base_ehooks_get_for_metadata_custom_hook) {
base = base_new(tsdn, 0, &hooks, /* metadata_use_hooks */ true);
ehooks_t *ehooks = base_ehooks_get_for_metadata(base);
expect_ptr_eq(&hooks, ehooks_get_extent_hooks_ptr(ehooks),
"Expected user-specified extend hook functions pointer");
"Expected user-specified extend hook functions pointer");
base_delete(tsdn, base);
}
TEST_END
int
main(void) {
return test(
test_base_hooks_default,
test_base_hooks_null,
return test(test_base_hooks_default, test_base_hooks_null,
test_base_hooks_not_null,
test_base_ehooks_get_for_metadata_default_hook,
test_base_ehooks_get_for_metadata_custom_hook);
test_base_ehooks_get_for_metadata_default_hook,
test_base_ehooks_get_for_metadata_custom_hook);
}