home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / samples / pagetest / pagetest.c < prev   
Encoding:
C/C++ Source or Header  |  1993-11-28  |  949 b   |  52 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pc.h>
  4.  
  5. main(int argc, char **argv)
  6. {
  7.   unsigned long pmax, p, cs, i;
  8.   unsigned long *pp, *pbase;
  9.  
  10.   if (argc < 2)
  11.   {
  12.     printf("pagetest {kb}\n");
  13.     return;
  14.   }
  15.  
  16.   pmax = atoi(argv[1]) / 4;
  17.   printf("%d pages\n", pmax);
  18.  
  19.   pbase = (unsigned long *)sbrk(pmax*4096);
  20.   if (pbase == -1)
  21.   {
  22.     fprintf(stderr, "sbrk failed\n");
  23.     exit(1);
  24.   }
  25.   for (p=0; p<pmax; p++)
  26.   {
  27.     printf("\rinit page %d  ", p);
  28.     fflush(stdout);
  29.     pp = pbase + p*1024;
  30.     cs = 0;
  31.     for (i=0; i<1023; i++)
  32.     {
  33.       pp[i] = random();
  34.       cs += pp[i];
  35.     }
  36.     pp[i] = cs;
  37.   }
  38.   printf("\r                         \r");
  39.   while (!kbhit())
  40.   {
  41.     p = random() % pmax;
  42.     printf("\rpage %d  ", p);
  43.     fflush(stdout);
  44.     pp = pbase + p*1024;
  45.     cs = 0;
  46.     for (i=0; i<1023; i++)
  47.       cs += pp[i];
  48.     if (pp[i] != cs)
  49.       printf("Bad cs!\n");
  50.   }
  51. }
  52.