aboutsummaryrefslogtreecommitdiffstats
path: root/test/testheap.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-04-17 14:53:04 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-04-17 14:53:04 +0000
commit0a37ec19f6b6c33c157f8280359e7c4468c26ae1 (patch)
tree98c55e00b84a1a6cb97b21e3089b86cb4fb33232 /test/testheap.c
parente8ae833287d6813305ac676508cb3dbaaf483eeb (diff)
downloadChibiOS-0a37ec19f6b6c33c157f8280359e7c4468c26ae1.tar.gz
ChibiOS-0a37ec19f6b6c33c157f8280359e7c4468c26ae1.tar.bz2
ChibiOS-0a37ec19f6b6c33c157f8280359e7c4468c26ae1.zip
100% code coverage for heap, semaphores and events.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@903 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test/testheap.c')
-rw-r--r--test/testheap.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/test/testheap.c b/test/testheap.c
index a72bad6bb..2740f8a9e 100644
--- a/test/testheap.c
+++ b/test/testheap.c
@@ -44,21 +44,38 @@ static void heap1_execute(void) {
p1 = chHeapAlloc(SIZE);
p2 = chHeapAlloc(SIZE);
p3 = chHeapAlloc(SIZE);
- chHeapFree(p1); /* Does not merge */
- chHeapFree(p2); /* Merges backward */
- chHeapFree(p3); /* Merges both sides */
+ chHeapFree(p1); /* Does not merge */
+ chHeapFree(p2); /* Merges backward */
+ chHeapFree(p3); /* Merges both sides */
test_assert(chHeapStatus(&n) == 1, "#1"); /* Heap fragmented.*/
/* Reverse order */
p1 = chHeapAlloc(SIZE);
p2 = chHeapAlloc(SIZE);
p3 = chHeapAlloc(SIZE);
- chHeapFree(p3); /* Merges forward */
- chHeapFree(p2); /* Merges forward */
- chHeapFree(p1); /* Merges forward */
+ chHeapFree(p3); /* Merges forward */
+ chHeapFree(p2); /* Merges forward */
+ chHeapFree(p1); /* Merges forward */
test_assert(chHeapStatus(&n) == 1, "#2"); /* Heap fragmented.*/
- test_assert(n == sz, "#3"); /* Heap size changed.*/
+ /* Small fragments handling */
+ p1 = chHeapAlloc(SIZE + 1);
+ p2 = chHeapAlloc(SIZE);
+ chHeapFree(p1);
+ test_assert(chHeapStatus(&n) == 2, "#3"); /* Heap must contain 2 blocks.*/
+ p1 = chHeapAlloc(SIZE);
+ test_assert(chHeapStatus(&n) == 1, "#4"); /* Heap fragmented.*/
+ chHeapFree(p2);
+ chHeapFree(p1);
+
+ /* Allocate all handling */
+ (void)chHeapStatus(&n);
+ p1 = chHeapAlloc(n);
+ test_assert(chHeapStatus(&n) == 0, "#5"); /* Heap must be empty.*/
+ chHeapFree(p1);
+
+ test_assert(chHeapStatus(&n) == 1, "#6"); /* Heap fragmented.*/
+ test_assert(n == sz, "#7"); /* Heap size changed.*/
}
else {
test_print("--- Size : ");