CS318 - Pintos
Pintos source browser for JHU CS318 course
mmap-twice.c
Go to the documentation of this file.
1 /** Maps the same file into memory twice and verifies that the
2  same data is readable in both. */
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[2] = {(char *) 0x10000000, (char *) 0x20000000};
14  size_t i;
15  int handle[2];
16 
17  for (i = 0; i < 2; i++)
18  {
19  CHECK ((handle[i] = open ("sample.txt")) > 1,
20  "open \"sample.txt\" #%zu", i);
21  CHECK (mmap (handle[i], actual[i]) != MAP_FAILED,
22  "mmap \"sample.txt\" #%zu at %p", i, (void *) actual[i]);
23  }
24 
25  for (i = 0; i < 2; i++)
26  CHECK (!memcmp (actual[i], sample, strlen (sample)),
27  "compare mmap'd file %zu against data", i);
28 }
lib.h
string.h
CHECK
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
test_main
void test_main(void)
Maps the same file into memory twice and verifies that the same data is readable in both.
Definition: mmap-twice.c:11
MAP_FAILED
#define MAP_FAILED
Definition: syscall.h:13
open
int open(const char *file)
Definition: syscall.c:103
arc4::i
uint8_t i
Definition: arc4.h:11
memcmp
int memcmp(const void *a_, const void *b_, size_t size)
Find the first differing byte in the two blocks of SIZE bytes at A and B.
Definition: string.c:53
strlen
size_t strlen(const char *string)
Returns the length of STRING.
Definition: string.c:293
main.h
mmap
mapid_t mmap(int fd, void *addr)
Project 3 and optionally project 4.
Definition: syscall.c:145