Made the malloc tests run on Windows

This commit is contained in:
Matthew Parkinson
2019-02-15 11:45:28 +00:00
committed by David Chisnall
parent bf58015c25
commit e7d90966f6
2 changed files with 12 additions and 20 deletions

View File

@@ -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);