CS318 - Pintos
Pintos source browser for JHU CS318 course
pt-grow-stk-sc.c
Go to the documentation of this file.
1 /** This test checks that the stack is properly extended even if
2  the first access to a stack location occurs inside a system
3  call.
4 
5  From Godmar Back. */
6 
7 #include <string.h>
8 #include <syscall.h>
9 #include "tests/vm/sample.inc"
10 #include "tests/lib.h"
11 #include "tests/main.h"
12 
13 void
14 test_main (void)
15 {
16  int handle;
17  int slen = strlen (sample);
18  char buf2[65536];
19 
20  /* Write file via write(). */
21  CHECK (create ("sample.txt", slen), "create \"sample.txt\"");
22  CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
23  CHECK (write (handle, sample, slen) == slen, "write \"sample.txt\"");
24  close (handle);
25 
26  /* Read back via read(). */
27  CHECK ((handle = open ("sample.txt")) > 1, "2nd open \"sample.txt\"");
28  CHECK (read (handle, buf2 + 32768, slen) == slen, "read \"sample.txt\"");
29 
30  CHECK (!memcmp (sample, buf2 + 32768, slen), "compare written data against read data");
31  close (handle);
32 }
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
open
int open(const char *file)
Definition: syscall.c:103
memcmp
int memcmp(const void *a_, const void *b_, size_t size)
Find the first differing byte in the two blocks of SIZE bytes at A and B.
Definition: string.c:53
test_main
void test_main(void)
This test checks that the stack is properly extended even if the first access to a stack location occ...
Definition: pt-grow-stk-sc.c:14
buf2
char buf2[1234]
Definition: syn-remove.c:11
strlen
size_t strlen(const char *string)
Returns the length of STRING.
Definition: string.c:293
main.h
close
void close(int fd)
Definition: syscall.c:139
read
int read(int fd, void *buffer, unsigned size)
Definition: syscall.c:115
create
bool create(const char *file, unsigned initial_size)
Definition: syscall.c:91