PKUOS - Pintos
Pintos source browser for PKU Operating System course
read-boundary.c
Go to the documentation of this file.
1/** Reads data spanning two pages in virtual address space,
2 which must succeed. */
3
4#include <string.h>
5#include <syscall.h>
7#include "tests/userprog/sample.inc"
8#include "tests/lib.h"
9#include "tests/main.h"
10
11void
12test_main (void)
13{
14 int handle;
15 int byte_cnt;
16 char *buffer;
17
18 CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
19
20 buffer = get_boundary_area () - sizeof sample / 2;
21 byte_cnt = read (handle, buffer, sizeof sample - 1);
22 if (byte_cnt != sizeof sample - 1)
23 fail ("read() returned %d instead of %zu", byte_cnt, sizeof sample - 1);
24 else if (strcmp (sample, buffer))
25 {
26 msg ("expected text:\n%s", sample);
27 msg ("text actually read:\n%s", buffer);
28 fail ("expected text differs from actual");
29 }
30}
static size_t byte_cnt(size_t bit_cnt)
Returns the number of bytes required for BIT_CNT bits.
Definition: bitmap.c:58
void * get_boundary_area(void)
Returns the beginning of a page.
Definition: boundary.c:18
static struct intq buffer
Stores keys from the keyboard and serial port.
Definition: input.c:7
int open(const char *file)
Definition: syscall.c:103
int read(int fd, void *buffer, unsigned size)
Definition: syscall.c:115
void fail(const char *format,...)
Definition: lib.c:40
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
void test_main(void)
Reads data spanning two pages in virtual address space, which must succeed.
Definition: read-boundary.c:12
int strcmp(const char *a_, const char *b_)
Finds the first differing characters in strings A and B.
Definition: string.c:73