00001 #include "tests/filesys/seq-test.h"
00002 #include <random.h>
00003 #include <syscall.h>
00004 #include "tests/lib.h"
00005
00006 void
00007 seq_test (const char *file_name, void *buf, size_t size, size_t initial_size,
00008 size_t (*block_size_func) (void),
00009 void (*check_func) (int fd, long ofs))
00010 {
00011 size_t ofs;
00012 int fd;
00013
00014 random_bytes (buf, size);
00015 CHECK (create (file_name, initial_size), "create \"%s\"", file_name);
00016 CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
00017
00018 ofs = 0;
00019 msg ("writing \"%s\"", file_name);
00020 while (ofs < size)
00021 {
00022 size_t block_size = block_size_func ();
00023 if (block_size > size - ofs)
00024 block_size = size - ofs;
00025
00026 if (write (fd, buf + ofs, block_size) != (int) block_size)
00027 fail ("write %zu bytes at offset %zu in \"%s\" failed",
00028 block_size, ofs, file_name);
00029
00030 ofs += block_size;
00031 if (check_func != NULL)
00032 check_func (fd, ofs);
00033 }
00034 msg ("close \"%s\"", file_name);
00035 close (fd);
00036 check_file (file_name, buf, size);
00037 }