From 13ff8554a175f5165102e8d25f142c8a4fecdbbc Mon Sep 17 00:00:00 2001 From: cuz Date: Fri, 21 Jul 2000 21:39:16 +0000 Subject: [PATCH] More heap test patterns git-svn-id: svn://svn.cc65.org/cc65/trunk@184 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- testcode/lib/heaptest.c | 79 ++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/testcode/lib/heaptest.c b/testcode/lib/heaptest.c index b5470bd2a..9b32178d0 100644 --- a/testcode/lib/heaptest.c +++ b/testcode/lib/heaptest.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include /* From _heap.h */ @@ -29,9 +29,10 @@ static char* Alloc (void) * also allow us to retrieve it later. */ if (P) { - memset (P, Size, Size); + memset (P, Size, Size); } else { - printf ("Could not allocate %u bytes\n", Size); + printf ("Could not allocate %u bytes\n", Size); + exit (EXIT_FAILURE); } return P; } @@ -48,9 +49,10 @@ static void Free (unsigned char* P) /* Scan the block */ for (I = 1; I < Size; ++I) { - if (P[I] != Size) { - printf ("Scan failed - expected %02X, got %02X\n", - Size, P[I]); + if (P[I] != Size) { + printf ("Scan failed - expected %02X, got %02X\n", + Size, P[I]); + exit (EXIT_FAILURE); } } @@ -65,8 +67,8 @@ static void FillArray (void) { unsigned char I = 0; do { - V[I] = Alloc (); - ++I; + V[I] = Alloc (); + ++I; } while (I != 0); } @@ -75,14 +77,30 @@ static void FillArray (void) static void ShowInfo (void) /* Show heap info */ { - printf ("%04X %04X %04X %04X %04X\n", - _horg, _hptr, _hend, _hfirst, _hlast); + /* Count free blocks */ + unsigned Count = 0; + unsigned** P = (unsigned**) _hfirst; + while (P) { + ++Count; + P = P[1]; + } + printf ("%04X %04X %04X %04X %04X %u\n", + _horg, _hptr, _hend, _hfirst, _hlast, Count); + + if (Count) { + P = (unsigned**) _hfirst; + while (P) { + printf ("%04X %04X %04X %04X(%u)\n", + (unsigned) P, P[2], P[1], P[0], P[0]); + P = P[1]; + } + getchar (); + } } static void Test1 (void) -/* First test */ { unsigned char I; FillArray (); @@ -96,7 +114,34 @@ static void Test1 (void) static void Test2 (void) -/* Second test */ +{ + unsigned char I; + FillArray (); + I = 0; + do { + Free (V[I]); + ++I; + } while (I != 0); + ShowInfo (); +} + + + +static void Test3 (void) +{ + unsigned char I; + FillArray (); + I = 0; + do { + --I; + Free (V[I]); + } while (I != 0); + ShowInfo (); +} + + + +static void Test4 (void) { unsigned char I; FillArray (); @@ -115,8 +160,7 @@ static void Test2 (void) -static void Test3 (void) -/* Third test */ +static void Test5 (void) { unsigned char I; FillArray (); @@ -140,7 +184,7 @@ static void Test3 (void) } while (I != 1); I = 0; do { - Free (V[I]); + Free (V[I]); ++I; } while (I != 0); ShowInfo (); @@ -148,8 +192,7 @@ static void Test3 (void) -static void Test4 (void) -/* Fourth test */ +static void Test6 (void) { unsigned char I, J; FillArray (); @@ -186,6 +229,8 @@ int main (void) Test2 (); Test3 (); Test4 (); + Test5 (); + Test6 (); /* Calculate the time and print it */ T = clock () - T; -- 2.39.5