vm-data3.c 922 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. /* This is creating a program that has
  5. * a few more text pages than the average
  6. * program we usually have.
  7. */
  8. extern void call_all();
  9. void write_data(void);
  10. void read_data(void);
  11. #define PAGE_SIZE (4096)
  12. #define PAGES (128)
  13. #define SIZE (PAGE_SIZE * PAGES / sizeof(int))
  14. #define NUM_REFS (2)
  15. unsigned int array[SIZE];
  16. void
  17. write_data(void)
  18. {
  19. unsigned int refs = 0;
  20. unsigned int i = 0;
  21. for (refs = 0; refs < NUM_REFS-1; refs++) {
  22. for (i=0; i<SIZE; i+= PAGE_SIZE) {
  23. array[i] = i;
  24. }
  25. }
  26. }
  27. void
  28. read_data(void)
  29. {
  30. unsigned int i = 0;
  31. for (i=0; i<SIZE; i+= PAGE_SIZE) {
  32. if (array[i] != i) {
  33. printf("FAILED array[%d] = %u != %d\n", i, array[i], i);
  34. exit(1);
  35. }
  36. }
  37. }
  38. int
  39. main()
  40. {
  41. unsigned int i = 0;
  42. for (i=0; i<5; i++) {
  43. call_all();
  44. write_data();
  45. call_all();
  46. read_data();
  47. }
  48. printf("SUCCEEDED\n");
  49. exit(0);
  50. }