pintos: Avoid literal control character in Perl variable name.
[pintos-anon] / src / tests / vm / mmap-remove.c
1 /* Deletes and closes file that is mapped into memory
2    and verifies that it can still be read through the mapping. */
3
4 #include <string.h>
5 #include <syscall.h>
6 #include "tests/vm/sample.inc"
7 #include "tests/lib.h"
8 #include "tests/main.h"
9
10 void
11 test_main (void)
12 {
13   char *actual = (char *) 0x10000000;
14   int handle;
15   mapid_t map;
16   size_t i;
17
18   /* Map file. */
19   CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
20   CHECK ((map = mmap (handle, actual)) != MAP_FAILED, "mmap \"sample.txt\"");
21
22   /* Close file and delete it. */
23   close (handle);
24   CHECK (remove ("sample.txt"), "remove \"sample.txt\"");
25   CHECK (open ("sample.txt") == -1, "try to open \"sample.txt\"");
26
27   /* Create a new file in hopes of overwriting data from the old
28      one, in case the file system has incorrectly freed the
29      file's data. */
30   CHECK (create ("another", 4096 * 10), "create \"another\"");
31
32   /* Check that mapped data is correct. */
33   if (memcmp (actual, sample, strlen (sample)))
34     fail ("read of mmap'd file reported bad data");
35
36   /* Verify that data is followed by zeros. */
37   for (i = strlen (sample); i < 4096; i++)
38     if (actual[i] != 0)
39       fail ("byte %zu of mmap'd region has value %02hhx (should be 0)",
40             i, actual[i]);
41
42   munmap (map);
43 }