1 /***************************************************************************
2 * Copyright 1995, Technion, Israel Institute of Technology
3 * Electrical Eng, Software Lab.
4 * Author: Michael Veksler.
5 ***************************************************************************
6 * File: shm_fragment_test.c
7 * Purpose: Test data fragments and free list items. Allocate and free blocks.
8 ***************************************************************************
12 #define DEBUG_DEFINE_VARIABLES /* just avoid dumb errors */
13 #include "debugtools.h" /* for "stddeb" */
16 #include "shm_block.h"
17 #include "shm_fragment.h"
20 #define DO_FREE(id) (-id)
21 #define LIST_LENGTH 20
25 struct shm_block
*block
;
30 /* important: The test will work only for the current implementation of */
31 /* allocation, if the implementation will change, the list should also */
33 static int sizes
[LIST_LENGTH
]={
34 SHM_MINBLOCK
, /* 0: should fail */
38 0x4000-4+1, /* 4: should fail */
40 /* allocated(5,3,2,1) free() */
45 /* allocated(9,8,7,3,2,1) free() */
49 /* allocated(8,7,2) free(9,3,1) */
53 /* allocated(8,7,15,2) free(9,[3-15],1) */
55 /* allocated(8,7,15) free(9,[3-15],1+2) */
61 static char *ptr
[LIST_LENGTH
];
63 block
=xmalloc(SHM_MINBLOCK
);
65 /* setup first item in the free list */
66 shm_FragmentInit(block
, sizeof(*block
), SHM_MINBLOCK
);
68 fprintf(stddeb
,"After shm_FragmentInit\n");
69 shm_print_free_list(block
);
71 for(i
=0 ; i
< LIST_LENGTH
; i
++) {
73 if (size
>0) { /* allocate */
74 ret
=shm_FragPtrAlloc(block
, size
);
77 "%d: After shm_FragmentAlloc(block, 0x%06x) == ",
80 fprintf(stddeb
, "NULL\n");
82 fprintf(stddeb
, "0x%06x\n", (int)ret
-(int)block
);
83 memset( ret
,0, size
); /* test boundaries */
86 /* free shm fragment */
88 fprintf(stddeb
, "%d: Doing shm_FragmentFree(block, ", i
);
90 fprintf(stddeb
, "NULL)\n");
92 fprintf(stddeb
, "0x%06x)\n", (int)ret
-(int)block
);
94 shm_FragPtrFree(block
, ret
);
96 shm_print_free_list(block
);