PKUOS - Pintos
Pintos source browser for PKU Operating System course
mmap-shuffle.c
Go to the documentation of this file.
1/** Creates a 128 kB file and repeatedly shuffles data in it
2 through a memory mapping. */
3
4#include <stdio.h>
5#include <string.h>
6#include <syscall.h>
7#include "tests/arc4.h"
8#include "tests/cksum.h"
9#include "tests/lib.h"
10#include "tests/main.h"
11
12#define SIZE (128 * 1024)
13
14static char *buf = (char *) 0x10000000;
15
16void
18{
19 size_t i;
20 int handle;
21
22 /* Create file, mmap. */
23 CHECK (create ("buffer", SIZE), "create \"buffer\"");
24 CHECK ((handle = open ("buffer")) > 1, "open \"buffer\"");
25 CHECK (mmap (handle, buf) != MAP_FAILED, "mmap \"buffer\"");
26
27 /* Initialize. */
28 for (i = 0; i < SIZE; i++)
29 buf[i] = i * 257;
30 msg ("init: cksum=%lu", cksum (buf, SIZE));
31
32 /* Shuffle repeatedly. */
33 for (i = 0; i < 10; i++)
34 {
35 shuffle (buf, SIZE, 1);
36 msg ("shuffle %zu: cksum=%lu", i, cksum (buf, SIZE));
37 }
38}
unsigned long cksum(const void *b_, size_t n)
This is the algorithm used by the Posix ‘cksum’ utility.
Definition: cksum.c:63
mapid_t mmap(int fd, void *addr)
Project 3 and optionally project 4.
Definition: syscall.c:145
bool create(const char *file, unsigned initial_size)
Definition: syscall.c:91
int open(const char *file)
Definition: syscall.c:103
#define MAP_FAILED
Definition: syscall.h:13
void msg(const char *format,...)
Definition: lib.c:28
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
static char * buf
Definition: mmap-shuffle.c:14
#define SIZE
Creates a 128 kB file and repeatedly shuffles data in it through a memory mapping.
Definition: mmap-shuffle.c:12
void test_main(void)
tests/main.h
Definition: mmap-shuffle.c:17
static void shuffle(struct value[], size_t)