* Fixed the build of the boot loader's heap test.
* Added realloc() test that actually succeeds. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34413 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,31 +1,18 @@
|
|||||||
SubDir HAIKU_TOP src tests system boot heap ;
|
SubDir HAIKU_TOP src tests system boot heap ;
|
||||||
|
|
||||||
UsePublicHeaders support ;
|
UsePrivateKernelHeaders ;
|
||||||
UsePrivateHeaders kernel ;
|
|
||||||
|
|
||||||
SubDirHdrs $(HAIKU_TOP) headers private kernel arch $(TARGET_ARCH) ;
|
ObjectDefines heap.cpp : malloc=heap_malloc free=heap_free realloc=heap_realloc
|
||||||
SubDirHdrs $(HAIKU_TOP) headers private kernel boot platform $(TARGET_BOOT_PLATFORM) ;
|
HEAP_TEST=1 ;
|
||||||
|
|
||||||
ObjectDefines heap.cpp : malloc=heap_malloc free=heap_free realloc=heap_realloc HEAP_TEST=1 ;
|
SimpleTest heapTest :
|
||||||
|
|
||||||
# This lets the correct stdio.h header be available
|
|
||||||
# on the build platform.
|
|
||||||
# This will be fixed with the move to GNU's stdio header
|
|
||||||
if $(OS) = "LINUX" {
|
|
||||||
SubDirC++Flags -include /usr/include/stdio.h ;
|
|
||||||
} else {
|
|
||||||
SubDirC++Flags -include /boot/develop/headers/posix/stdio.h ;
|
|
||||||
}
|
|
||||||
|
|
||||||
BuildPlatformTest heapTest :
|
|
||||||
heapTest.cpp
|
heapTest.cpp
|
||||||
|
|
||||||
|
# from the boot loader:
|
||||||
heap.cpp
|
heap.cpp
|
||||||
:
|
|
||||||
;
|
;
|
||||||
|
|
||||||
# Tell Jam where to find the utility sources
|
# Tell Jam where to find the utility sources
|
||||||
SEARCH on [ FGristFiles
|
SEARCH on [ FGristFiles
|
||||||
heap.cpp
|
heap.cpp
|
||||||
] = [ FDirName $(HAIKU_TOP) src system boot loader ] ;
|
] = [ FDirName $(HAIKU_TOP) src system boot loader ] ;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2003, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2003-2009, Axel Dörfler, [email protected].
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
|
|
||||||
extern "C" void* heap_malloc(size_t size);
|
extern "C" void* heap_malloc(size_t size);
|
||||||
|
extern "C" void* heap_realloc(void* oldBuffer, size_t size);
|
||||||
extern "C" void heap_free(void* buffer);
|
extern "C" void heap_free(void* buffer);
|
||||||
extern void dump_chunks(void);
|
extern void dump_chunks(void);
|
||||||
extern uint32 heap_available(void);
|
extern uint32 heap_available(void);
|
||||||
@@ -58,6 +59,17 @@ panic(const char *format, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
dprintf(const char* format, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
|
vfprintf(stdout, format, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -68,7 +80,8 @@ dump_allocated_chunk(int32 index, void *buffer)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
size_t* size = (size_t*)((uint8*)buffer - sizeof(uint32));
|
size_t* size = (size_t*)((uint8*)buffer - sizeof(uint32));
|
||||||
printf("\t%ld. allocation at %p, chunk at %p, size = %ld\n", index, buffer, size, *size);
|
printf("\t%ld. allocation at %p, chunk at %p, size = %ld\n", index, buffer,
|
||||||
|
size, *size);
|
||||||
|
|
||||||
if (gVerbosity > 3)
|
if (gVerbosity > 3)
|
||||||
dump_chunks();
|
dump_chunks();
|
||||||
@@ -82,6 +95,13 @@ test_malloc(size_t bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void*
|
||||||
|
test_realloc(void* oldBuffer, size_t size)
|
||||||
|
{
|
||||||
|
return heap_realloc(oldBuffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_free(void* buffer)
|
test_free(void* buffer)
|
||||||
{
|
{
|
||||||
@@ -244,6 +264,30 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
puts("* realloc() test");
|
||||||
|
|
||||||
|
uint8* buffer = (uint8*)test_malloc(1);
|
||||||
|
buffer[0] = 'h';
|
||||||
|
|
||||||
|
uint8* newBuffer = (uint8*)test_realloc(buffer, 2);
|
||||||
|
if (newBuffer != buffer)
|
||||||
|
panic(" could not reuse buffer");
|
||||||
|
newBuffer[1] = 'a';
|
||||||
|
newBuffer = (uint8*)test_realloc(buffer, 3);
|
||||||
|
if (newBuffer != buffer)
|
||||||
|
panic(" could not reuse buffer");
|
||||||
|
newBuffer[2] = 'i';
|
||||||
|
newBuffer = (uint8*)test_realloc(buffer, 4);
|
||||||
|
if (newBuffer != buffer)
|
||||||
|
panic(" could not reuse buffer");
|
||||||
|
newBuffer[3] = 'k';
|
||||||
|
newBuffer = (uint8*)test_realloc(buffer, 5);
|
||||||
|
if (newBuffer == buffer)
|
||||||
|
panic(" could reuse buffer!");
|
||||||
|
newBuffer[4] = 'u';
|
||||||
|
if (memcmp(newBuffer, "haiku", 5))
|
||||||
|
panic(" contents differ!");
|
||||||
|
|
||||||
heap_release(&args);
|
heap_release(&args);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user