diff --git a/src/tests/system/kernel/Jamfile b/src/tests/system/kernel/Jamfile index 4caaf25ffb..812eded212 100644 --- a/src/tests/system/kernel/Jamfile +++ b/src/tests/system/kernel/Jamfile @@ -71,4 +71,5 @@ SubInclude HAIKU_TOP src tests system kernel cache ; SubInclude HAIKU_TOP src tests system kernel device_manager ; SubInclude HAIKU_TOP src tests system kernel scheduler ; SubInclude HAIKU_TOP src tests system kernel slab ; +SubInclude HAIKU_TOP src tests system kernel swap ; SubInclude HAIKU_TOP src tests system kernel util ; diff --git a/src/tests/system/kernel/swap/Jamfile b/src/tests/system/kernel/swap/Jamfile new file mode 100644 index 0000000000..c46562ff92 --- /dev/null +++ b/src/tests/system/kernel/swap/Jamfile @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src tests system kernel swap ; + +SimpleTest swap_test_heap : swap_test_heap.cpp ; diff --git a/src/tests/system/kernel/swap/swap_test_heap.cpp b/src/tests/system/kernel/swap/swap_test_heap.cpp new file mode 100644 index 0000000000..a651241ea9 --- /dev/null +++ b/src/tests/system/kernel/swap/swap_test_heap.cpp @@ -0,0 +1,74 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include +#include +#include + + +#ifndef PAGE_SIZE +# define PAGE_SIZE 4096 +#endif + +#define PAGE_ELEMENT_COUNT (PAGE_SIZE / 4) + + +int +main(int argc, const char* const* argv) +{ + size_t allocationSize = 256; + + if (argc > 1) { + allocationSize = atoi(argv[1]); + if (allocationSize == 0) { + fprintf(stderr, "Usage: %s [ ]\n", argv[0]); + return 1; + } + } + + allocationSize *= 1024 * 1024; + size_t elementCount = allocationSize / 4; + + // allocate memory + uint32_t* allocation = (uint32_t*)malloc(allocationSize); + if (allocation == NULL) { + fprintf(stderr, "Allocation failed!\n"); + return 1; + } + + printf("Allocated %lu MB at %p. Filling the allocation...\n", + (unsigned long)allocationSize / 1024 / 1024, allocation); + + // fill the pages + for (size_t i = 0; i < elementCount; i++) + allocation[i] = i; + + printf("Done filled the allocation. Starting test iterations...\n"); + + for (int testIteration = 0; testIteration < 5; testIteration++) { + sleep(1); + + printf("Test iteration %d...\n", testIteration); + + // test the pages + for (size_t i = 0; i < elementCount; i++) { + if (allocation[i] != i) { + printf(" incorrect value in page %lu\n", + (unsigned long)i / PAGE_ELEMENT_COUNT); + + // skip the rest of the page + i = i / PAGE_ELEMENT_COUNT * PAGE_ELEMENT_COUNT + + PAGE_ELEMENT_COUNT - 1; + } else if ((i + 1) % PAGE_ELEMENT_COUNT == 0) { +// printf(" page %lu ok\n", +// (unsigned long)i / PAGE_ELEMENT_COUNT); + } + } + } + + return 0; +}