Made the malloc tests run on Windows
This commit is contained in:
committed by
David Chisnall
parent
bf58015c25
commit
e7d90966f6
@@ -76,18 +76,11 @@ subdirlist(TEST_CATEGORIES ${TESTDIR})
|
||||
foreach(SUPER_SLAB_SIZE 1;16)
|
||||
foreach(TEST_CATEGORY ${TEST_CATEGORIES})
|
||||
subdirlist(TESTS ${TESTDIR}/${TEST_CATEGORY})
|
||||
if(MSVC)
|
||||
list(REMOVE_ITEM TESTS "malloc")
|
||||
endif()
|
||||
foreach(TEST ${TESTS})
|
||||
unset(SRC)
|
||||
aux_source_directory(${TESTDIR}/${TEST_CATEGORY}/${TEST} SRC)
|
||||
set(TESTNAME "${TEST_CATEGORY}-${TEST}-${SUPER_SLAB_SIZE}")
|
||||
if(${TEST} STREQUAL "malloc")
|
||||
add_executable(${TESTNAME} ${SRC} src/override/malloc.cc)
|
||||
else()
|
||||
add_executable(${TESTNAME} ${SRC} src/override/new.cc)
|
||||
endif()
|
||||
add_executable(${TESTNAME} ${SRC} src/override/new.cc)
|
||||
if (${SUPER_SLAB_SIZE} EQUAL 1)
|
||||
target_compile_definitions(${TESTNAME} PRIVATE IS_ADDRESS_SPACE_CONSTRAINED)
|
||||
endif()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <cerrno>
|
||||
#include <malloc.h>
|
||||
#include <snmalloc.h>
|
||||
#define SNMALLOC_NAME_MANGLE(a) our_##a
|
||||
#include "../../../override/malloc.cc"
|
||||
|
||||
using namespace snmalloc;
|
||||
|
||||
@@ -16,13 +15,13 @@ void check_result(size_t size, size_t align, void* p, int err, bool null)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (malloc_usable_size(p) < size)
|
||||
if (our_malloc_usable_size(p) < size)
|
||||
abort();
|
||||
|
||||
if (((uintptr_t)p % align) != 0)
|
||||
abort();
|
||||
|
||||
free(p);
|
||||
our_free(p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +29,7 @@ void test_calloc(size_t nmemb, size_t size, int err, bool null)
|
||||
{
|
||||
fprintf(stderr, "calloc(%d, %d)\n", (int)nmemb, (int)size);
|
||||
errno = 0;
|
||||
void* p = calloc(nmemb, size);
|
||||
void* p = our_calloc(nmemb, size);
|
||||
|
||||
if ((p != nullptr) && (errno == 0))
|
||||
{
|
||||
@@ -47,7 +46,7 @@ void test_realloc(void* p, size_t size, int err, bool null)
|
||||
{
|
||||
fprintf(stderr, "realloc(%p(%d), %d)\n", p, int(size), (int)size);
|
||||
errno = 0;
|
||||
p = realloc(p, size);
|
||||
p = our_realloc(p, size);
|
||||
check_result(size, 1, p, err, null);
|
||||
}
|
||||
|
||||
@@ -55,7 +54,7 @@ void test_posix_memalign(size_t size, size_t align, int err, bool null)
|
||||
{
|
||||
fprintf(stderr, "posix_memalign(&p, %d, %d)\n", (int)align, (int)size);
|
||||
void* p = nullptr;
|
||||
errno = posix_memalign(&p, align, size);
|
||||
errno = our_posix_memalign(&p, align, size);
|
||||
check_result(size, align, p, err, null);
|
||||
}
|
||||
|
||||
@@ -63,7 +62,7 @@ void test_memalign(size_t size, size_t align, int err, bool null)
|
||||
{
|
||||
fprintf(stderr, "memalign(%d, %d)\n", (int)align, (int)size);
|
||||
errno = 0;
|
||||
void* p = memalign(align, size);
|
||||
void* p = our_memalign(align, size);
|
||||
check_result(size, align, p, err, null);
|
||||
}
|
||||
|
||||
@@ -91,10 +90,10 @@ int main(int argc, char** argv)
|
||||
}
|
||||
test_calloc(0, size, SUCCESS, false);
|
||||
|
||||
test_realloc(malloc(size), size, SUCCESS, false);
|
||||
test_realloc(malloc(size), 0, SUCCESS, true);
|
||||
test_realloc(our_malloc(size), size, SUCCESS, false);
|
||||
test_realloc(our_malloc(size), 0, SUCCESS, true);
|
||||
test_realloc(nullptr, size, SUCCESS, false);
|
||||
test_realloc(malloc(size), (size_t)-1, ENOMEM, true);
|
||||
test_realloc(our_malloc(size), (size_t)-1, ENOMEM, true);
|
||||
}
|
||||
|
||||
test_posix_memalign(0, 0, EINVAL, true);
|
||||
|
||||
Reference in New Issue
Block a user