CS318 - Pintos
Pintos source browser for JHU CS318 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 
14 static char *buf = (char *) 0x10000000;
15 
16 void
17 test_main (void)
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 }
lib.h
test_main
void test_main(void)
tests/main.h
Definition: mmap-shuffle.c:17
buf
static char * buf
Definition: mmap-shuffle.c:14
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
SIZE
#define SIZE
Creates a 128 kB file and repeatedly shuffles data in it through a memory mapping.
Definition: mmap-shuffle.c:12
shuffle
static void shuffle(struct value[], size_t)
MAP_FAILED
#define MAP_FAILED
Definition: syscall.h:13
open
int open(const char *file)
Definition: syscall.c:103
arc4.h
arc4::i
uint8_t i
Definition: arc4.h:11
cksum.h
cksum
unsigned long cksum(const void *b_, size_t n)
This is the algorithm used by the Posix ‘cksum’ utility.
Definition: cksum.c:63
main.h
msg
void msg(const char *format,...)
Definition: lib.c:28
mmap
mapid_t mmap(int fd, void *addr)
Project 3 and optionally project 4.
Definition: syscall.c:145
create
bool create(const char *file, unsigned initial_size)
Definition: syscall.c:91