PKUOS - Pintos
Pintos source browser for PKU Operating System 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
10void
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}
mapid_t mmap(int fd, void *addr)
Project 3 and optionally project 4.
Definition: syscall.c:145
int open(const char *file)
Definition: syscall.c:103
#define MAP_FAILED
Definition: syscall.h:13
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
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
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
size_t strlen(const char *string)
Returns the length of STRING.
Definition: string.c:293