diff options
Diffstat (limited to 'test/testheap.c')
-rw-r--r-- | test/testheap.c | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/test/testheap.c b/test/testheap.c index 6545893ce..ba839e6d4 100644 --- a/test/testheap.c +++ b/test/testheap.c @@ -77,59 +77,67 @@ static void heap1_execute(void) { void *p1, *p2, *p3;
size_t n, sz;
- /* Test skipped if the heap is already fragmented. */
+ /*
+ * Test on the default heap in order to cover the core allocator at
+ * least one time. + */
+ (void)chHeapStatus(NULL, &sz);
+ p1 = chHeapAlloc(NULL, SIZE);
+ test_assert(1, p1 != NULL, "allocation failed");
+ chHeapFree(p1);
+ p1 = chHeapAlloc(NULL, 0x1000000);
+ test_assert(2, p1 == NULL, "allocation not failed");
+
+ /* Initial local heap state.*/
(void)chHeapStatus(&test_heap, &sz);
- test_print("--- Size : ");
- test_printn(sz);
- test_println(" bytes");
- /* Same order */
+ /* Same order.*/
p1 = chHeapAlloc(&test_heap, SIZE);
p2 = chHeapAlloc(&test_heap, SIZE);
p3 = chHeapAlloc(&test_heap, SIZE);
- chHeapFree(p1); /* Does not merge */
- chHeapFree(p2); /* Merges backward */
- chHeapFree(p3); /* Merges both sides */
- test_assert(1, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+ chHeapFree(p1); /* Does not merge.*/
+ chHeapFree(p2); /* Merges backward.*/
+ chHeapFree(p3); /* Merges both sides.*/
+ test_assert(3, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
- /* Reverse order */
+ /* Reverse order.*/
p1 = chHeapAlloc(&test_heap, SIZE);
p2 = chHeapAlloc(&test_heap, SIZE);
p3 = chHeapAlloc(&test_heap, SIZE);
- chHeapFree(p3); /* Merges forward */
- chHeapFree(p2); /* Merges forward */
- chHeapFree(p1); /* Merges forward */
- test_assert(2, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+ chHeapFree(p3); /* Merges forward.*/
+ chHeapFree(p2); /* Merges forward.*/
+ chHeapFree(p1); /* Merges forward.*/
+ test_assert(4, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
- /* Small fragments handling */
+ /* Small fragments handling.*/
p1 = chHeapAlloc(&test_heap, SIZE + 1);
p2 = chHeapAlloc(&test_heap, SIZE);
chHeapFree(p1);
- test_assert(3, chHeapStatus(&test_heap, &n) == 2, "invalid state");
+ test_assert(5, chHeapStatus(&test_heap, &n) == 2, "invalid state");
p1 = chHeapAlloc(&test_heap, SIZE);
- test_assert(4, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+ test_assert(6, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
chHeapFree(p2);
chHeapFree(p1);
- test_assert(5, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+ test_assert(7, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
- /* Skip fragment handling */
+ /* Skip fragment handling.*/
p1 = chHeapAlloc(&test_heap, SIZE);
p2 = chHeapAlloc(&test_heap, SIZE);
chHeapFree(p1);
- test_assert(6, chHeapStatus(&test_heap, &n) == 2, "invalid state");
- p1 = chHeapAlloc(&test_heap, SIZE * 2); /* Skips first fragment */
+ test_assert(8, chHeapStatus(&test_heap, &n) == 2, "invalid state");
+ p1 = chHeapAlloc(&test_heap, SIZE * 2); /* Skips first fragment.*/
chHeapFree(p1);
chHeapFree(p2);
- test_assert(7, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+ test_assert(9, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
- /* Allocate all handling */
+ /* Allocate all handling.*/
(void)chHeapStatus(&test_heap, &n);
p1 = chHeapAlloc(&test_heap, n);
- test_assert(8, chHeapStatus(&test_heap, &n) == 0, "not empty");
+ test_assert(10, chHeapStatus(&test_heap, &n) == 0, "not empty");
chHeapFree(p1);
- test_assert(9, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
- test_assert(10, n == sz, "size changed");
+ test_assert(11, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+ test_assert(12, n == sz, "size changed");
}
const struct testcase testheap1 = {
@@ -139,7 +147,7 @@ const struct testcase testheap1 = { heap1_execute
};
-#endif /* CH_USE_HEAP */
+#endif /* CH_USE_HEAP.*/
/*
* Test sequence for heap pattern.
|