Move problem 1-2 (join) into project 2 as the "wait" system call.
[pintos-anon] / grading / vm / mmap-exit.c
1 #include <stdio.h>
2 #include <string.h>
3 #ifdef PINTOS
4 #include <syscall.h>
5 #else
6 #include "posix-compat.h"
7 #endif
8 #include "sample.inc"
9
10 #define ACTUAL ((void *) 0x10000000)
11
12 int
13 main (void) 
14 {
15   pid_t child;
16   int code;
17   int fd;
18   char buf[1024];
19
20   printf ("(mmap-exit) begin\n");
21
22   /* Make child write file. */
23   printf ("(mmap-exit) run child\n");
24   child = exec ("child-mm-wrt");
25   if (child == -1) 
26     {
27       printf ("(mmap-exit) exec() failed\n");
28       return 1;
29     }
30   code = wait (child);
31   if (code != 234) 
32     {
33       printf ("(mmap-exit) wait() returned bad exit code: %d\n", code);
34       return 1;
35     }
36   printf ("(mmap-exit) child finished\n");
37
38   /* Read back via read(). */
39   fd = open ("sample.txt");
40   if (fd < 0) 
41     {
42       printf ("(mmap-exit) open() failed\n");
43       return 1;
44     }
45
46   read (fd, buf, strlen (sample));
47   if (memcmp (buf, sample, strlen (sample)))
48     {
49       printf ("(mmap-exit) read of mmap-written file reported bad data\n");
50       return 1;
51     }
52   close (fd);
53
54   /* Done. */
55   printf ("(mmap-exit) end\n");
56
57   return 0;
58 }