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"
21 #define DO_FREE(id) (-id)
22 #define LIST_LENGTH 20
26 struct shm_block *block;
31 /* important: The test will work only for the current implementation of */
32 /* allocation, if the implementation will change, the list should also */
34 static int sizes[LIST_LENGTH]={
35 SHM_MINBLOCK, /* 0: should fail */
39 0x4000-4+1, /* 4: should fail */
41 /* allocated(5,3,2,1) free() */
46 /* allocated(9,8,7,3,2,1) free() */
50 /* allocated(8,7,2) free(9,3,1) */
54 /* allocated(8,7,15,2) free(9,[3-15],1) */
56 /* allocated(8,7,15) free(9,[3-15],1+2) */
62 static char *ptr[LIST_LENGTH];
64 block=xmalloc(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 memset( ret,0, 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);