root/user/uw-testbin/vm-stack2/vm-stack2.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 #include <stdio.h>
   2 #include <stdlib.h>
   3 
   4 #define PAGE_SIZE             (4096)
   5 #define STACK_PAGES_USED      (9)
   6 #define STACK_ARRAY_ELEMS     (PAGE_SIZE * STACK_PAGES_USED / sizeof(int))
   7 #define UNINIT_PAGES          (9)
   8 #define UNINIT_ARRAY_ELEMS    (PAGE_SIZE * UNINIT_PAGES / sizeof(int))
   9 
  10 unsigned int uninit[UNINIT_ARRAY_ELEMS];
  11 unsigned int init[] = {
  12         0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
  13  10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  14  20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 
  15  30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 
  16  40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 
  17  50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 
  18 };
  19 
  20 #define INIT_ARRAY_ELEMS     (sizeof(init) / sizeof(int))
  21 
  22 int
  23 main()
  24 {
  25         unsigned int array[STACK_ARRAY_ELEMS];
  26         unsigned int i = 0;
  27 
  28         /* check the uninitialized array before initialization */
  29         for (i=0; i<UNINIT_ARRAY_ELEMS; i++) {
  30                 if (uninit[i] != 0) {
  31                         printf("FAILED uninit[%d] = %u != %d\n", i, uninit[i], 0);
  32                         exit(1);
  33                 }
  34         }
  35 
  36         /* initialize the uninitialized data */
  37         for (i=0; i<UNINIT_ARRAY_ELEMS; i++) {
  38                 uninit[i] = i * 100;
  39         }
  40 
  41         /* initialize the array on the stack */
  42         for (i=0; i<STACK_ARRAY_ELEMS; i++) {
  43                 array[i] = i * 1000;
  44         }
  45 
  46         /* check the array on the stack */
  47         for (i=0; i<STACK_ARRAY_ELEMS; i++) {
  48                 if (array[i] != i * 1000) {
  49                         printf("FAILED array[%d] = %u != %d\n", i, array[i], i);
  50                         exit(1);
  51                 }
  52         }
  53 
  54         /* check the uninitialized array after initialization */
  55         for (i=0; i<UNINIT_ARRAY_ELEMS; i++) {
  56                 if (uninit[i] != i * 100) {
  57                         printf("FAILED uninit[%d] = %u != %d\n", i, uninit[i], i);
  58                         exit(1);
  59                 }
  60         }
  61 
  62         /* check the initialized array */
  63         for (i=0; i<INIT_ARRAY_ELEMS; i++) {
  64                 if (init[i] != i) {
  65                         printf("FAILED init[%d] = %u != %d\n", i, init[i], i);
  66                         exit(1);
  67                 }
  68         }
  69 
  70         printf("SUCCEEDED\n");
  71         exit(0);
  72 }

/* [<][>][^][v][top][bottom][index][help] */