PKUOS - Pintos
Pintos source browser for PKU Operating System 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
6void
7seq_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}
block_sector_t block_size(struct block *block)
Returns the number of sectors in BLOCK.
Definition: block.c:144
static char buf[BUF_SIZE]
bool create(const char *file, unsigned initial_size)
Definition: syscall.c:91
void close(int fd)
Definition: syscall.c:139
int open(const char *file)
Definition: syscall.c:103
int write(int fd, const void *buffer, unsigned size)
Definition: syscall.c:121
void fail(const char *format,...)
Definition: lib.c:40
void check_file(const char *file_name, const void *buf, size_t size)
Definition: lib.c:151
void msg(const char *format,...)
Definition: lib.c:28
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
void random_bytes(void *buf_, size_t size)
Writes SIZE random bytes into BUF.
Definition: random.c:54
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
#define NULL
Definition: stddef.h:4
static const char file_name[]
tests/filesys/base/syn-read.h
Definition: syn-read.h:5