Initial file system tests.
[pintos-anon] / grading / vm / mmap-close.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "../lib/arc4.h"
4 #include "sample.inc"
5 #ifdef PINTOS
6 #include <syscall.h>
7 #else
8 #include "posix-compat.h"
9 #endif
10
11 #define ACTUAL ((void *) 0x10000000)
12
13 int
14 main (void) 
15 {
16   int fd;
17
18   printf ("(mmap-close) begin\n");
19
20   fd = open ("sample.txt");
21   if (fd < 0) 
22     {
23       printf ("(mmap-close) open() failed\n");
24       return 1;
25     }
26
27   if (!mmap (fd, ACTUAL, strlen (sample)))
28     {
29       printf ("(mmap-close) mmap() failed\n");
30       return 1;
31     }
32
33   close (fd);
34
35   if (memcmp (ACTUAL, sample, strlen (sample)))
36     {
37       printf ("(mmap-close) read of mmap'd file reported bad data\n");
38       return 1;
39     }
40
41   munmap (ACTUAL, strlen (sample));
42
43   /* Done. */
44   printf ("(mmap-close) end\n");
45
46   return 0;
47 }