CS318 - Pintos
Pintos source browser for JHU CS318 course
write-boundary.c
Go to the documentation of this file.
1 /** Writes 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 *sample_p;
17 
18  sample_p = copy_string_across_boundary (sample);
19 
20  CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
21 
22  byte_cnt = write (handle, sample_p, sizeof sample - 1);
23  if (byte_cnt != sizeof sample - 1)
24  fail ("write() returned %d instead of %zu", byte_cnt, sizeof sample - 1);
25 }
lib.h
string.h
write
int write(int fd, const void *buffer, unsigned size)
Definition: syscall.c:121
CHECK
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
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
open
int open(const char *file)
Definition: syscall.c:103
copy_string_across_boundary
char * copy_string_across_boundary(const char *src)
Returns a copy of SRC split across the boundary between two pages.
Definition: boundary.c:29
test_main
void test_main(void)
Writes data spanning two pages in virtual address space, which must succeed.
Definition: write-boundary.c:12
fail
void fail(const char *format,...)
Definition: lib.c:40
main.h
boundary.h