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 ***************************************************************************
13 #define DEBUG_DEFINE_VARIABLES /* just avoid dumb errors */
14 #include <debug.h> /* for "stddeb" */
17 #include "shm_block.h"
18 #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
=malloc(SHM_MINBLOCK
);
66 /* setup first item in the free list */
67 shm_FragmentInit(block
, sizeof(*block
), SHM_MINBLOCK
);
69 fprintf(stddeb
,"After shm_FragmentInit\n");
70 shm_print_free_list(block
);
72 for(i
=0 ; i
< LIST_LENGTH
; i
++) {
74 if (size
>0) { /* allocate */
75 ret
=shm_FragPtrAlloc(block
, size
);
78 "%d: After shm_FragmentAlloc(block, 0x%06x) == ",
81 fprintf(stddeb
, "NULL\n");
83 fprintf(stddeb
, "0x%06x\n", (int)ret
-(int)block
);
84 bzero (ret
,size
); /* test boundaries */
87 /* free shm fragment */
89 fprintf(stddeb
, "%d: Doing shm_FragmentFree(block, ", i
);
91 fprintf(stddeb
, "NULL)\n");
93 fprintf(stddeb
, "0x%06x)\n", (int)ret
-(int)block
);
95 shm_FragPtrFree(block
, ret
);
97 shm_print_free_list(block
);