os161-1.99
 All Data Structures
vm-data3.c
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 
00005 /* This is creating a program that has
00006  * a few more text pages than the average
00007  * program we usually have.
00008  */
00009 
00010 extern void     call_all();
00011 void write_data(void);
00012 void read_data(void);
00013 
00014 #define PAGE_SIZE (4096)
00015 #define PAGES     (128)
00016 #define SIZE      (PAGE_SIZE * PAGES / sizeof(int))
00017 #define NUM_REFS  (2)
00018 
00019 unsigned int array[SIZE];
00020 
00021 void
00022 write_data(void)
00023 {
00024         unsigned int refs = 0;
00025         unsigned int i = 0;
00026 
00027         for (refs = 0; refs < NUM_REFS-1; refs++) {
00028                 for (i=0; i<SIZE; i+= PAGE_SIZE) {
00029                         array[i] = i;
00030                 }
00031         }
00032 }
00033 
00034 void
00035 read_data(void)
00036 {
00037         unsigned int i = 0;
00038 
00039         for (i=0; i<SIZE; i+= PAGE_SIZE) {
00040                 if (array[i] != i) {
00041                         printf("FAILED array[%d] = %u != %d\n", i, array[i], i);
00042                         exit(1);
00043                 }
00044         }
00045 }
00046 
00047 
00048 int
00049 main()
00050 {
00051         unsigned int i = 0;
00052 
00053         for (i=0; i<5; i++) {
00054           call_all();
00055           write_data();
00056           call_all();
00057           read_data();
00058         }
00059 
00060         printf("SUCCEEDED\n");
00061         exit(0);
00062 }
 All Data Structures