1 /* Deletes and closes file that is mapped into memory
2 and verifies that it can still be read through the mapping. */
6 #include "tests/vm/sample.inc"
8 #include "tests/main.h"
13 char *actual = (char *) 0x10000000;
19 CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
20 CHECK ((map = mmap (handle, actual)) != MAP_FAILED, "mmap \"sample.txt\"");
22 /* Close file and delete it. */
24 CHECK (remove ("sample.txt"), "remove \"sample.txt\"");
25 CHECK (open ("sample.txt") == -1, "try to open \"sample.txt\"");
27 /* Create a new file in hopes of overwriting data from the old
28 one, in case the file system has incorrectly freed the
30 CHECK (create ("another", 4096 * 10), "create \"another\"");
32 /* Check that mapped data is correct. */
33 if (memcmp (actual, sample, strlen (sample)))
34 fail ("read of mmap'd file reported bad data");
36 /* Verify that data is followed by zeros. */
37 for (i = strlen (sample); i < 4096; i++)
39 fail ("byte %zu of mmap'd region has value %02hhx (should be 0)",