| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016, the Dartino project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE.md file. | |
| 4 | |
| 5 #include <stdio.h> | |
| 6 #include <cinttypes> | |
| 7 | |
| 8 #define TESTING | |
| 9 #include "src/shared/assert.h" | |
| 10 | |
| 11 #include "platforms/stm/disco_fletch/src/cmpctmalloc.h" | |
| 12 #include "platforms/stm/disco_fletch/src/page_allocator.h" | |
| 13 | |
| 14 PageAllocator* page_allocator; | |
| 15 | |
| 16 extern "C" void* page_alloc(size_t pages) { | |
| 17 return page_allocator->AllocatePages(pages); | |
| 18 } | |
| 19 | |
| 20 extern "C" void page_free(void* start, size_t pages) { | |
| 21 return page_allocator->FreePages(start, pages); | |
| 22 } | |
| 23 | |
| 24 // Tests in cmpctmalloc.c. | |
| 25 extern "C" void cmpct_test_buckets(); | |
| 26 extern "C" void cmpct_test_get_back_newly_freed(); | |
| 27 extern "C" void cmpct_test_return_to_os(); | |
| 28 extern "C" void cmpct_test_trim(); | |
| 29 | |
| 30 int main(int argc, char **argv) { | |
| 31 page_allocator = new PageAllocator(); | |
| 32 | |
| 33 // Test that nothing can be allocated in the empty page allocator. | |
| 34 void *p = cmpct_alloc(1); | |
| 35 EXPECT(p == NULL); | |
| 36 | |
| 37 // Add an arena to the heap for the rest of the tests. | |
| 38 size_t heap_size = 60 * PAGE_SIZE; // TODO(sgjesse): Test with few pages. | |
| 39 heap_size = 0x800000; | |
| 40 void* heap_memory; | |
| 41 int result = posix_memalign(&heap_memory, PAGE_SIZE, heap_size); | |
| 42 EXPECT_EQ(0, result); | |
| 43 int arena1_bitmap = page_allocator->AddArena( | |
| 44 "test", reinterpret_cast<uintptr_t>(heap_memory), heap_size); | |
| 45 EXPECT_EQ(1, arena1_bitmap); | |
| 46 | |
| 47 cmpct_test_buckets(); | |
| 48 #ifdef FLETCH_TARGET_OS_LK | |
| 49 // TODO(sgjesse): This test crashes. | |
| 50 cmpct_test_get_back_newly_freed(); | |
| 51 #endif | |
| 52 cmpct_test_return_to_os(); | |
| 53 cmpct_test_trim(); | |
| 54 cmpct_dump(); | |
| 55 } | |
| OLD | NEW |