CS318 - Pintos
Pintos source browser for JHU CS318 course
seq-test.c
Go to the documentation of this file.
2 #include <random.h>
3 #include <syscall.h>
4 #include "tests/lib.h"
5 
6 void
7 seq_test (const char *file_name, void *buf, size_t size, size_t initial_size,
8  size_t (*block_size_func) (void),
9  void (*check_func) (int fd, long ofs))
10 {
11  size_t ofs;
12  int fd;
13 
14  random_bytes (buf, size);
15  CHECK (create (file_name, initial_size), "create \"%s\"", file_name);
16  CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
17 
18  ofs = 0;
19  msg ("writing \"%s\"", file_name);
20  while (ofs < size)
21  {
22  size_t block_size = block_size_func ();
23  if (block_size > size - ofs)
24  block_size = size - ofs;
25 
26  if (write (fd, buf + ofs, block_size) != (int) block_size)
27  fail ("write %zu bytes at offset %zu in \"%s\" failed",
28  block_size, ofs, file_name);
29 
30  ofs += block_size;
31  if (check_func != NULL)
32  check_func (fd, ofs);
33  }
34  msg ("close \"%s\"", file_name);
35  close (fd);
36  check_file (file_name, buf, size);
37 }
lib.h
NULL
#define NULL
Definition: stddef.h:4
seq_test
void seq_test(const char *file_name, void *buf, size_t size, size_t initial_size, size_t(*block_size_func)(void), void(*check_func)(int fd, long ofs))
tests/filesys/seq-test.h
Definition: seq-test.c:7
buf
static char buf[BUF_SIZE]
Definition: child-syn-read.c:16
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
random.h
open
int open(const char *file)
Definition: syscall.c:103
fail
void fail(const char *format,...)
Definition: lib.c:40
file_name
static const char file_name[]
tests/filesys/base/syn-read.h
Definition: syn-read.h:5
close
void close(int fd)
Definition: syscall.c:139
msg
void msg(const char *format,...)
Definition: lib.c:28
block_size
block_sector_t block_size(struct block *block)
Returns the number of sectors in BLOCK.
Definition: block.c:144
seq-test.h
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