Fix test when using GWP-Asan (#758)

This commit is contained in:
Matthew Parkinson
2025-03-17 15:37:54 +00:00
committed by GitHub
parent a106a2e69d
commit 3348bf9e56

View File

@@ -247,9 +247,12 @@ void test_external_pointer()
if (size != snmalloc::alloc_size(p1)) if (size != snmalloc::alloc_size(p1))
{ {
std::cout << "Requested size: " << size if (size > snmalloc::alloc_size(p1) || snmalloc::is_owned(p1))
<< " alloc_size: " << snmalloc::alloc_size(p1) << std::endl; {
abort(); std::cout << "Requested size: " << size
<< " alloc_size: " << snmalloc::alloc_size(p1) << std::endl;
abort();
}
} }
for (size_t offset = 0; offset < size; offset += 17) for (size_t offset = 0; offset < size; offset += 17)
@@ -259,19 +262,26 @@ void test_external_pointer()
void* p4 = snmalloc::external_pointer<End>(p2); void* p4 = snmalloc::external_pointer<End>(p2);
if (p1 != p3) if (p1 != p3)
{ {
std::cout << "size: " << size if (p3 > p1 || snmalloc::is_owned(p1))
<< " alloc_size: " << snmalloc::alloc_size(p1) {
<< " offset: " << offset << " p1: " << p1 << " p3: " << p3 std::cout << "size: " << size
<< std::endl; << " alloc_size: " << snmalloc::alloc_size(p1)
<< " offset: " << offset << " p1: " << p1 << " p3: " << p3
<< std::endl;
abort();
}
} }
SNMALLOC_CHECK(p1 == p3);
if ((size_t)p4 != (size_t)p1 + size - 1) if ((size_t)p4 != (size_t)p1 + size - 1)
{ {
std::cout << "size: " << size << " end(p4): " << p4 << " p1: " << p1 if (((size_t)p4 < (size_t)p1 + size - 1) || snmalloc::is_owned(p1))
<< " p1+size-1: " << pointer_offset(p1, size - 1) {
<< std::endl; std::cout << "size: " << size << " end(p4): " << p4 << " p1: " << p1
<< " p1+size-1: " << pointer_offset(p1, size - 1)
<< std::endl;
abort();
}
} }
SNMALLOC_CHECK((size_t)p4 == (size_t)p1 + size - 1);
} }
snmalloc::dealloc(p1, size); snmalloc::dealloc(p1, size);
@@ -285,9 +295,12 @@ void check_offset(void* base, void* interior)
void* calced_base = snmalloc::external_pointer((void*)interior); void* calced_base = snmalloc::external_pointer((void*)interior);
if (calced_base != (void*)base) if (calced_base != (void*)base)
{ {
std::cout << "Calced base: " << calced_base << " actual base: " << base if (calced_base > base || snmalloc::is_owned(base))
<< " for interior: " << interior << std::endl; {
abort(); std::cout << "Calced base: " << calced_base << " actual base: " << base
<< " for interior: " << interior << std::endl;
abort();
}
} }
} }
@@ -483,14 +496,16 @@ void test_remaining_bytes()
snmalloc::remaining_bytes(address_cast(pointer_offset(p, offset))); snmalloc::remaining_bytes(address_cast(pointer_offset(p, offset)));
if (rem != (size - offset)) if (rem != (size - offset))
{ {
printf( if (rem < (size - offset) || snmalloc::is_owned(p))
"Allocation size: %zu, Offset: %zu, Remaining bytes: %zu, " {
"Expected: %zu\n", report_fatal_error(
size, "Allocation size: {}, Offset: {}, Remaining bytes: {}, "
offset, "Expected: {}",
rem, size,
size - offset); offset,
abort(); rem,
size - offset);
}
} }
} }
snmalloc::dealloc(p); snmalloc::dealloc(p);
@@ -541,19 +556,25 @@ int main(int argc, char** argv)
#else #else
UNUSED(argc, argv); UNUSED(argc, argv);
#endif #endif
test_alloc_dealloc_64k(); #define TEST(testname) \
test_random_allocation(); std::cout << "Running " #testname << std::endl; \
test_calloc(); for (size_t i = 0; i < 100; i++) \
test_double_alloc(); testname();
test_remaining_bytes();
test_static_sized_allocs(); TEST(test_alloc_dealloc_64k);
test_calloc_large_bug(); TEST(test_random_allocation);
test_external_pointer_stack(); TEST(test_calloc);
test_external_pointer_dealloc_bug(); TEST(test_double_alloc);
test_external_pointer_large(); TEST(test_remaining_bytes);
test_external_pointer(); TEST(test_static_sized_allocs);
test_alloc_16M(); TEST(test_calloc_large_bug);
test_calloc_16M(); TEST(test_external_pointer_stack);
test_consolidaton_bug(); TEST(test_external_pointer_dealloc_bug);
TEST(test_external_pointer_large);
TEST(test_external_pointer);
TEST(test_alloc_16M);
TEST(test_calloc_16M);
TEST(test_consolidaton_bug);
return 0; return 0;
} }