CS318 - Pintos
Pintos source browser for JHU CS318 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 
11 void
12 test_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 }
lib.h
string.h
strcmp
int strcmp(const char *a_, const char *b_)
Finds the first differing characters in strings A and B.
Definition: string.c:73
CHECK
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
get_boundary_area
void * get_boundary_area(void)
Returns the beginning of a page.
Definition: boundary.c:18
byte_cnt
static size_t byte_cnt(size_t bit_cnt)
Returns the number of bytes required for BIT_CNT bits.
Definition: bitmap.c:58
buffer
static struct intq buffer
Stores keys from the keyboard and serial port.
Definition: input.c:7
test_main
void test_main(void)
Reads data spanning two pages in virtual address space, which must succeed.
Definition: read-boundary.c:12
open
int open(const char *file)
Definition: syscall.c:103
fail
void fail(const char *format,...)
Definition: lib.c:40
main.h
msg
void msg(const char *format,...)
Definition: lib.c:28
boundary.h
read
int read(int fd, void *buffer, unsigned size)
Definition: syscall.c:115