home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / CFF51B.ZIP / PUSHTEST.C < prev    next >
C/C++ Source or Header  |  1993-10-22  |  10KB  |  397 lines

  1. /* PUSHTEST.C */
  2. /* Copyright 1990, 1991, 1992, 1993 Norman D. Culver Ft. Lauderdale, FL */
  3. /*                    All Rights Reserved                                   */
  4.  
  5. #include <stdlib.h>
  6. #include "../cff.h"
  7.  
  8. #define CLOCKS_PER_SECOND 1000000L
  9.  
  10. /* TEST CHOICES */
  11. #define PFLAGS 0
  12. #define MEMFILE 1
  13. #define EXTDMEM 1
  14. #define DOHASH 1
  15. #define DOTREE 1
  16.  
  17. extern int errno;
  18. extern long clock();
  19. extern int rand();
  20. static void push_test1(void *hd, void *hd1);
  21. static void push_test2(void *hd, void *hd1);
  22.  
  23. OPNINFO info;
  24.  
  25. void
  26. main()
  27. {
  28. void *hxxx;
  29. void *huniq;
  30. void *huniq1;
  31. void *huniq2;
  32. void *huniq3;
  33. void *hsxxx;
  34. void *hsxxx1;
  35. void *hsxxx2;
  36. void *hsxxx3;
  37.  
  38.     cfport_settestflags(1);
  39.     cfinit("pushtest",512,NULL);
  40.     cfprintf("PUSH/POP test of stack property -- stack depth == 10000\n");
  41.  
  42.     /* SET UP PREALLOC FOR THE HASH DIRECTORIES */
  43.  
  44. #if MEMFILE
  45.     /* EXTRANEOUS DIRECTORY just to add flavor */
  46.     cfprintf("MEMORY FILE\n");
  47.     hxxx = cfopen("MEMORY/XXX",F_RDWR|F_CREAT,NULL);
  48.     if(!hxxx) {
  49.         cfprintf("ERROR: create XXX err=%d\n", errno);
  50.         exit(0);
  51.     }
  52.  
  53.     /* HASH DIRECTORY WITH PREALLOC OF MAPS ONLY */
  54.     info.initial_entries = 10000;
  55.     info.bitmap_prealloc = 0;
  56.     info.data_prealloc = 0;
  57.     huniq = cfopen("MEMORY/XXX",
  58.                     F_RDWR|F_CREAT|F_TEMP|F_UNIQ|F_HUGEDIR, &info);
  59.     if(!huniq) {
  60.         cfprintf("ERROR: create UNIQUE TEMP FILE0 err=%d\n", errno);
  61.         exit(0);
  62.     }
  63.  
  64.     /* TREE DIRECTORY no prealloc */
  65.     huniq1 = cfopen("MEMORY/XXX",
  66.                     F_RDWR|F_CREAT|F_TEMP|F_UNIQ|F_SORTED, NULL);
  67.     if(!huniq1) {
  68.         cfprintf("ERROR: create UNIQUE TEMP FILE1 err=%d\n", errno);
  69.         exit(0);
  70.     }
  71.     /* HASH DIRECTORY WITH PREALLOC OF MAPS AND DATA */
  72.     info.initial_entries = 10000;
  73.     info.bitmap_prealloc = 0;
  74.     info.data_prealloc = 64;
  75.     huniq2 = cfopen("MEMORY/XXX",
  76.                     F_RDWR|F_CREAT|F_TEMP|F_UNIQ|F_HUGEDIR, &info);
  77.     if(!huniq2) {
  78.         cfprintf("ERROR: create UNIQUE TEMP FILE2 err=%d\n", errno);
  79.         exit(0);
  80.     }
  81.     /* TREE DIRECTORY no prealloc */
  82.     huniq3 = cfopen("MEMORY/XXX",
  83.                     F_RDWR|F_CREAT|F_TEMP|F_UNIQ|F_SORTED, NULL);
  84.     if(!huniq3) {
  85.         cfprintf("ERROR: create UNIQUE TEMP FILE3 err=%d\n", errno);
  86.         exit(0);
  87.     }
  88. #if PFLAGS
  89.     cfpflags("hxxx", hxxx);
  90.     cfpflags("huniq", huniq);
  91.     cfpflags("huniq1", huniq1);
  92.     cfpflags("huniq2", huniq2);
  93.     cfpflags("huniq3", huniq3);
  94. #endif
  95.  
  96.     cfsetverylazy(huniq);
  97.     cfsetverylazy(huniq1);
  98.     push_test1(huniq, huniq1);
  99.  
  100.     cfsetverylazy(huniq2);
  101.     cfsetverylazy(huniq3);
  102.     push_test2(huniq2, huniq3);
  103.  
  104. cfprintf("NOW CLOSING\n");
  105.     cfclose(huniq);
  106.     cfclose(huniq1);
  107.     cfclose(huniq2);
  108.     cfclose(huniq3);
  109. #endif /* MEMFILE */
  110.  
  111.  
  112. #if EXTDMEM
  113.     cfprintf("EXTDMEM FILE\n");
  114.  
  115.     /* HASH DIRECTORY WITH PREALLOC OF MAPS ONLY */
  116.     info.initial_entries = 10000;
  117.     info.bitmap_prealloc = 0;
  118.     info.data_prealloc = 0;
  119.     hsxxx = cfopen("EXTDMEM/XXX", F_RDWR|F_CREAT|F_HUGEDIR, &info);
  120.     if(!hsxxx) {
  121.         cfprintf("ERROR: create EXTDMEM/XXX err=%d\n", errno);
  122.         exit(0);
  123.     }
  124.  
  125.     /* TREE DIRECTORY no prealloc */
  126.     hsxxx1 = cfopen("EXTDMEM/XXX1", F_RDWR|F_CREAT|F_SORTED, NULL);
  127.     if(!hsxxx1) {
  128.         cfprintf("ERROR: create EXTDMEM/XXX1 err=%d\n", errno);
  129.         exit(0);
  130.     }
  131.  
  132.     /* HASH DIRECTORY WITH PREALLOC OF MAPS and DATA */
  133.     info.initial_entries = 10000;
  134.     info.bitmap_prealloc = 0;
  135.     info.data_prealloc = 64;
  136.     hsxxx2 = cfopen("EXTDMEM/XXX2", F_RDWR|F_CREAT|F_HUGEDIR, &info);
  137.     if(!hsxxx2) {
  138.         cfprintf("ERROR: create EXTDMEM/XXX2 err=%d\n", errno);
  139.         exit(0);
  140.     }
  141.  
  142.     /* TREE DIRECTORY no prealloc */
  143.     hsxxx3 = cfopen("EXTDMEM/XXX3", F_RDWR|F_CREAT|F_SORTED, NULL);
  144.     if(!hsxxx3) {
  145.         cfprintf("ERROR: create EXTDMEM/XXX3 err=%d\n", errno);
  146.         exit(0);
  147.     }
  148.  
  149. #if PFLAGS
  150.     cfpflags("hsxxx", hsxxx);
  151.     cfpflags("hsxxx1", hsxxx1);
  152.     cfpflags("hsxxx2", hsxxx2);
  153.     cfpflags("hsxxx3", hsxxx3);
  154. #endif
  155.  
  156.     cfsetverylazy(hsxxx);
  157.     cfsetverylazy(hsxxx1);
  158.     push_test1(hsxxx, hsxxx1);
  159.  
  160.     cfsetverylazy(hsxxx2);
  161.     cfsetverylazy(hsxxx3);
  162.     push_test2(hsxxx2, hsxxx3);
  163.  
  164. cfprintf("NOW CLOSING\n");
  165.     cfclose(hsxxx);
  166.     cfclose(hsxxx1);
  167.     cfclose(hsxxx2);
  168.     cfclose(hsxxx3);
  169.  
  170.     cfprintf("REOPEN EXTDMEM FILE\n");    
  171.     hsxxx = cfopen("EXTDMEM/XXX", F_RDWR, NULL);
  172.     if(!hsxxx) {
  173.         cfprintf("ERROR: reopen EXTDMEM:/XXX err=%d\n", errno);
  174.         exit(0);
  175.     }
  176.     hsxxx1 = cfopen("EXTDMEM/XXX1", F_RDWR, NULL);
  177.     if(!hsxxx1) {
  178.         cfprintf("ERROR: reopen EXTDMEM:/XXX1 err=%d\n", errno);
  179.         exit(0);
  180.     }
  181.     hsxxx2 = cfopen("EXTDMEM/XXX2", F_RDWR, NULL);
  182.     if(!hsxxx2) {
  183.         cfprintf("ERROR: reopen EXTDMEM:/XXX2 err=%d\n", errno);
  184.         exit(0);
  185.     }
  186.     hsxxx3 = cfopen("EXTDMEM/XXX3", F_RDWR, NULL);
  187.     if(!hsxxx3) {
  188.         cfprintf("ERROR: reopen EXTDMEM:/XXX3 err=%d\n", errno);
  189.         exit(0);
  190.     }
  191.  
  192.     cfsetverylazy(hsxxx);
  193.     cfsetverylazy(hsxxx1);
  194.     push_test1(hsxxx,hsxxx1);
  195.  
  196.     cfsetverylazy(hsxxx2);
  197.     cfsetverylazy(hsxxx3);
  198.     push_test2(hsxxx2,hsxxx3);
  199.  
  200. cfprintf("NOW UNLINKING\n");
  201.     cfunlink(hsxxx, NULL);
  202.     cfunlink(hsxxx1, NULL);
  203.     cfunlink(hsxxx2, NULL);
  204.     cfunlink(hsxxx3, NULL);
  205. #endif /* EXTDMEM */
  206. cfprintf("UNLINK DONE\n");
  207.     cfexit();
  208. } /* END: MAIN */
  209. static Item myitem;
  210. static long buf[16];
  211.  
  212. static void
  213. push_test1(void *hd, void *hd1)
  214. {
  215. long i, start, end, diff, result;
  216.  
  217.     cfprintf("Begin push_test1 ITEMS\n");
  218.  
  219. #if DOHASH == 1
  220.     if((result = cfstackdepth(hd)) != 0)
  221.         cfprintf("STACKDEPTH begin hash wrong =%d should be 0\n", result);
  222.  
  223.     start = clock();
  224.     for (i = 0; i < 10000; ++i)
  225.     {
  226.         myitem.a0 = i+2;
  227.         if((result = cfpush_item(hd, &myitem)) != i+1)
  228.             cfprintf("PUSH ITEM hash failed =%d should be %d\n", result, i+1);
  229.     }
  230.     end = clock();
  231.     diff = end - start;
  232.     diff /= CLOCKS_PER_SECOND/10;
  233.     if(diff == 0) diff = 1;
  234.     cfprintf("  PUSH ITEMS hash PER SEC = %ld\n", (i*10) / diff);
  235.  
  236.     if((result = cfstackdepth(hd)) != 10000)
  237.     cfprintf("STACKDEPTH push hash item wrong =%d should be 10000\n", result);
  238.  
  239.     start = clock();
  240.     for (i = 9999; i >= 0; --i)
  241.     {
  242.         myitem.a0 = 0;
  243.         if((result = cfpop_item(hd, &myitem)) != i)
  244.             cfprintf("POP ITEM hash failed =%d should be %d\n", result, i+1);
  245.         if(myitem.a0 != i+2)
  246.             cfprintf("POP ITEM returned wrong value %d should be %d\n",
  247.             myitem.a0, i+2);
  248.     }
  249.     end = clock();
  250.     diff = end - start;
  251.     diff /= CLOCKS_PER_SECOND/10;
  252.     if(diff == 0) diff = 1;
  253.     cfprintf("  POP ITEMS hash PER SEC = %ld\n", (10000*10) / diff);
  254.  
  255.     if((result = cfstackdepth(hd)) != 0)
  256.     cfprintf("STACKDEPTH pop hash item wrong =%d should be 0\n", result);
  257.  
  258. #endif
  259. #if DOTREE == 1
  260.     if((result = cfstackdepth(hd1)) != 0)
  261.         cfprintf("STACKDEPTH begin tree wrong =%d should be 0\n", result);
  262.  
  263.     start = clock();
  264.     for (i = 0; i < 10000; ++i)
  265.     {
  266.         myitem.a0 = i+2;
  267.         if((result = cfpush_item(hd1, &myitem)) != i+1)
  268.             cfprintf("PUSH ITEM tree failed =%d should be %d\n", result, i+1);
  269.     }
  270.     end = clock();
  271.     diff = end - start;
  272.     diff /= CLOCKS_PER_SECOND/10;
  273.     if(diff == 0) diff = 1;
  274.     cfprintf("  PUSH ITEMS tree PER SEC = %ld\n", (i*10) / diff);
  275.  
  276.     if((result = cfstackdepth(hd1)) != 10000)
  277.     cfprintf("STACKDEPTH push tree item wrong =%d should be 10000\n", result);
  278.  
  279.  
  280.     start = clock();
  281.     for (i = 9999; i >= 0; --i)
  282.     {
  283.         myitem.a0 = 0;
  284.         if((result = cfpop_item(hd1, &myitem)) != i)
  285.             cfprintf("POP ITEM tree failed =%d should be %d\n", result, i+1);
  286.         if(myitem.a0 != i+2)
  287.             cfprintf("POP ITEM tree returned wrong value %d should be %d\n",
  288.             myitem.a0, i+2);
  289.     }
  290.     end = clock();
  291.     diff = end - start;
  292.     diff /= CLOCKS_PER_SECOND/10;
  293.     if(diff == 0) diff = 1;
  294.     cfprintf("  POP ITEMS tree PER SEC = %ld\n", (10000*10) / diff);
  295.  
  296.     if((result = cfstackdepth(hd1)) != 0)
  297.     cfprintf("STACKDEPTH pop tree item wrong =%d should be 0\n", result);
  298.  
  299. #endif
  300.  
  301.     cfprintf("End push_test1\n");
  302. }
  303. static void
  304. push_test2(void *hd, void *hd1)
  305. {
  306. long i, start, end, diff, result;
  307.  
  308.     cfprintf("Begin push_test2 DATA (64 bytes) \n");
  309.  
  310. #if DOHASH == 1
  311.     if((result = cfstackdepth(hd)) != 0)
  312.         cfprintf("STACKDEPTH begin hash wrong =%d should be 0\n", result);
  313.  
  314.     start = clock();
  315.     for (i = 0; i < 10000; ++i)
  316.     {
  317.         buf[0] = i+2;
  318.         buf[15] = i+3;
  319.         if((result = cfpush_data(hd, buf, 64)) != i+1)
  320.             cfprintf("PUSH DATA  hash failed =%d should be %d\n", result, i+1);
  321.     }
  322.     end = clock();
  323.     diff = end - start;
  324.     diff /= CLOCKS_PER_SECOND/10;
  325.     if(diff == 0) diff = 1;
  326.     cfprintf("  PUSH DATA hash PER SEC = %ld\n", (i*10) / diff);
  327.  
  328.     if((result = cfstackdepth(hd)) != 10000)
  329.     cfprintf("STACKDEPTH push hash data wrong =%d should be 10000\n", result);
  330.  
  331.     start = clock();
  332.     for (i = 9999; i >= 0; --i)
  333.     {
  334.         if((result = cfpop_data(hd, buf, 64)) != i)
  335.             cfprintf("POP DATA hash failed =%d should be %d\n", result, i+1);
  336.         if(buf[0] != i+2 || buf[15] != i+3)
  337.             cfprintf("POP DATA returned wrong value %d should be %d\n",
  338.             buf[0], i+2);
  339.     }
  340.     end = clock();
  341.     diff = end - start;
  342.     diff /= CLOCKS_PER_SECOND/10;
  343.     if(diff == 0) diff = 1;
  344.     cfprintf("  POP DATA hash PER SEC = %ld\n", (10000*10) / diff);
  345.  
  346.     if((result = cfstackdepth(hd)) != 0)
  347.     cfprintf("STACKDEPTH pop hash item wrong =%d should be 0\n", result);
  348.  
  349.  
  350. #endif
  351. #if DOTREE == 1
  352.     if((result = cfstackdepth(hd1)) != 0)
  353.         cfprintf("STACKDEPTH begin tree wrong =%d should be 0\n", result);
  354.  
  355.     start = clock();
  356.     for (i = 0; i < 10000; ++i)
  357.     {
  358.         buf[0] = i+2;
  359.         buf[15] = i+3;
  360.         if((result = cfpush_data(hd1, buf, 64)) != i+1)
  361.             cfprintf("PUSH DATA tree failed =%d should be %d\n", result, i+1);
  362.     }
  363.     end = clock();
  364.     diff = end - start;
  365.     diff /= CLOCKS_PER_SECOND/10;
  366.     if(diff == 0) diff = 1;
  367.     cfprintf("  PUSH DATA tree PER SEC = %ld\n", (i*10) / diff);
  368.  
  369.     if((result = cfstackdepth(hd1)) != 10000)
  370.     cfprintf("STACKDEPTH push tree data wrong =%d should be 10000\n", result);
  371.  
  372.  
  373.     start = clock();
  374.     for (i = 9999; i >= 0; --i)
  375.     {
  376.         if((result = cfpop_data(hd1, buf, 64)) != i)
  377.             cfprintf("POP DATA tree failed =%d should be %d\n", result, i+1);
  378.         if(buf[0] != i+2 || buf[15] != i+3)
  379.             cfprintf("POP DATA tree returned wrong value %d should be %d\n",
  380.             buf[0], i+2);
  381.     }
  382.     end = clock();
  383.     diff = end - start;
  384.     diff /= CLOCKS_PER_SECOND/10;
  385.     if(diff == 0) diff = 1;
  386.     cfprintf("  POP DATA tree PER SEC = %ld\n", (10000*10) / diff);
  387.  
  388.     if((result = cfstackdepth(hd1)) != 0)
  389.     cfprintf("STACKDEPTH pop tree data wrong =%d should be 0\n", result);
  390.  
  391.  
  392. #endif
  393.  
  394.     cfprintf("End push_test2\n");
  395. }
  396.  
  397.