CS318 - Pintos
Pintos source browser for JHU CS318 course
syn-remove.c
Go to the documentation of this file.
1 /** Verifies that a deleted file may still be written to and read
2  from. */
3 
4 #include <random.h>
5 #include <string.h>
6 #include <syscall.h>
7 #include "tests/lib.h"
8 #include "tests/main.h"
9 
10 char buf1[1234];
11 char buf2[1234];
12 
13 void
14 test_main (void)
15 {
16  const char *file_name = "deleteme";
17  int fd;
18 
19  CHECK (create (file_name, sizeof buf1), "create \"%s\"", file_name);
20  CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
21  CHECK (remove (file_name), "remove \"%s\"", file_name);
22  random_bytes (buf1, sizeof buf1);
23  CHECK (write (fd, buf1, sizeof buf1) > 0, "write \"%s\"", file_name);
24  msg ("seek \"%s\" to 0", file_name);
25  seek (fd, 0);
26  CHECK (read (fd, buf2, sizeof buf2) > 0, "read \"%s\"", file_name);
27  compare_bytes (buf2, buf1, sizeof buf1, 0, file_name);
28  msg ("close \"%s\"", file_name);
29  close (fd);
30 }
lib.h
buf1
char buf1[1234]
Verifies that a deleted file may still be written to and read from.
Definition: syn-remove.c:10
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
random_bytes
void random_bytes(void *buf_, size_t size)
Writes SIZE random bytes into BUF.
Definition: random.c:54
compare_bytes
void compare_bytes(const void *read_data_, const void *expected_data_, size_t size, size_t ofs, const char *file_name)
test/lib.h
Definition: lib.c:163
random.h
remove
bool remove(const char *file)
Definition: syscall.c:97
open
int open(const char *file)
Definition: syscall.c:103
seek
void seek(int fd, unsigned position)
Definition: syscall.c:127
buf2
char buf2[1234]
Definition: syn-remove.c:11
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
test_main
void test_main(void)
tests/main.h
Definition: syn-remove.c:14
msg
void msg(const char *format,...)
Definition: lib.c:28
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