CS318 - Pintos
Pintos source browser for JHU CS318 course
grow-sparse.c
Go to the documentation of this file.
1 /** Tests that seeking past the end of a file and writing will
2  properly zero out the region in between. */
3 
4 #include <syscall.h>
5 #include "tests/lib.h"
6 #include "tests/main.h"
7 
8 static char buf[76543];
9 
10 void
11 test_main (void)
12 {
13  const char *file_name = "testfile";
14  char zero = 0;
15  int fd;
16 
17  CHECK (create (file_name, 0), "create \"%s\"", file_name);
18  CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
19  msg ("seek \"%s\"", file_name);
20  seek (fd, sizeof buf - 1);
21  CHECK (write (fd, &zero, 1) > 0, "write \"%s\"", file_name);
22  msg ("close \"%s\"", file_name);
23  close (fd);
24  check_file (file_name, buf, sizeof buf);
25 }
lib.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
test_main
void test_main(void)
tests/main.h
Definition: grow-sparse.c:11
open
int open(const char *file)
Definition: syscall.c:103
seek
void seek(int fd, unsigned position)
Definition: syscall.c:127
file_name
static const char file_name[]
tests/filesys/base/syn-read.h
Definition: syn-read.h:5
main.h
close
void close(int fd)
Definition: syscall.c:139
msg
void msg(const char *format,...)
Definition: lib.c:28
buf
static char buf[76543]
Tests that seeking past the end of a file and writing will properly zero out the region in between.
Definition: grow-sparse.c:8
check_file
void check_file(const char *file_name, const void *buf, size_t size)
Definition: lib.c:151
create
bool create(const char *file, unsigned initial_size)
Definition: syscall.c:91