unison

Fork of Unison, a bi-directional file synchronization tool
git clone git://git.laack.co/unison.git
Log | Files | Refs | README | LICENSE

test-limits.c (749B)


      1 /*
      2  * test-limit.c: Test memory size limits.
      3  * Allocate memory until failure.
      4  * Print amount allocated.
      5  *
      6  * https://pubs.opengroup.org/onlinepubs/9799919799/utilities/ulimit.html
      7  * https://pubs.opengroup.org/onlinepubs/9799919799/functions/setrlimit.html
      8  */
      9 
     10 #include <stdio.h>
     11 #include <stdlib.h>
     12 
     13 #define BUFSIZK	4
     14 
     15 int
     16 main(int argc, char **argv)
     17 {
     18   int i;
     19   int *buf;
     20 
     21   /*
     22    * Limit to 4 GB, to avoid problems if memory limits are not
     23    * working as expected.
     24    */
     25   for (i = 0; i < (4 * 1024 * 1024) / BUFSIZK; i++) {
     26     /* Allocate, write to force a page, and discard. */
     27     buf = malloc(BUFSIZK * 1024);
     28     if (buf == NULL)
     29       break;
     30     buf[0] = 0;
     31     buf = NULL;
     32   }
     33 
     34   /* Print in kB. */
     35   printf("%d\n", i * BUFSIZK);
     36 }