home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1987 / 12 / deikman / test.c < prev   
Text File  |  1987-12-21  |  2KB  |  60 lines

  1. #include <stdio.h>
  2.  
  3. #include "cache.h"
  4.  
  5. CACDS *cache;
  6.  
  7. main() {
  8.  
  9.   printf("Cache test routine\n");
  10.   cache = cacallo(8, 128, (char *) 0, 1L);
  11.   printf("Memory allocated = %ld\n\n",  cacamem);
  12.   
  13.   while (ctest()) cprint();
  14.   
  15.   exit(0); }
  16.   
  17.  
  18. int ctest() {
  19.  
  20.   int opt, rec;
  21.   long num;
  22.   
  23.   printf("\n1=old, 2=num, 3=find, 4=proc: ");
  24.   scanf("%d", &opt);
  25.   
  26.   switch (opt) {
  27.     case 0: return 0;
  28.     case 1: printf("cacold returns %lx\n", cacold(cache));  return 1;
  29.     case 2: printf("enter record: ");
  30.             scanf("%ld", &num);
  31.             printf("cacnum returned %lx\n", cacnum(cache, num));
  32.             return 1;
  33.     case 3: printf("input record to find: ");
  34.             scanf("%ld", &num);
  35.             printf("cacfind returned %lx\n", cacfind(cache, num));
  36.             return 1;
  37.     case 4: printf("input record to process: ");
  38.             scanf("%ld", &num);
  39.             cacproc(cache, num);
  40.             printf("cacproc called\n");
  41.             return 1;
  42.     otherwise: return 1; }
  43.   return; }
  44.  
  45. cprint() {
  46.  
  47.   register int i;
  48.   
  49.   printf("Cache print:  hits=%ld  miss=%ld  adds=%ld\n",
  50.           cache->hits, cache->miss, cache->adds);
  51.  
  52.   printf("Block Numbers Next  Prior Mark  LRU=%d  MRU=%d\n", cache->lru, cache->mru);
  53.   printf("----- ------- ----- ----- -----\n");
  54.   for (i = 0; i < cache->maxr; i++) 
  55.     printf("%5d %7ld %5d %5d %4d\n", i, cache->nums[i],
  56.                         cache->next[i],
  57.                         cache->prio[i],
  58.                         cache->mark[i]);
  59.   return; }
  60.