19 static char buf[1024];
28msg (
const char *format, ...)
35 vmsg (format, args,
"\n");
40fail (
const char *format, ...)
45 vmsg (format, args,
": FAILED\n");
52swap (
void *a_,
void *b_,
size_t size)
58 for (i = 0; i < size; i++)
67shuffle (
void *buf_,
size_t cnt,
size_t size)
72 for (i = 0; i < cnt; i++)
84 for (i = 0; i < child_cnt; i++)
87 snprintf (cmd_line,
sizeof cmd_line,
"%s %zu", child_name, i);
89 "exec child %zu of %zu: \"%s\"", i + 1, child_cnt, cmd_line);
98 for (i = 0; i < child_cnt; i++)
100 int status =
wait (pids[i]);
101 CHECK (status == (
int) i,
102 "wait for child %zu of %zu returned %d (expected %zu)",
103 i + 1, child_cnt, status, i);
109 const char *
file_name,
const void *buf_,
size_t size)
111 const char *
buf = buf_;
119 if (file_size != size)
120 msg (
"size of %s (%zu) differs from expected (%zu)",
135 fail (
"read of %zu bytes at offset %zu in \"%s\" returned %zu",
143 if (file_size != size)
144 fail (
"size of %s (%zu) differs from expected (%zu)",
163compare_bytes (
const void *read_data_,
const void *expected_data_,
size_t size,
166 const uint8_t *read_data = read_data_;
167 const uint8_t *expected_data = expected_data_;
171 if (!
memcmp (read_data, expected_data, size))
174 for (i = 0; i < size; i++)
175 if (read_data[i] != expected_data[i])
177 for (j = i + 1; j < size; j++)
178 if (read_data[j] == expected_data[j])
182 msg (
"%zu bytes read starting at offset %zu in \"%s\" differ "
183 "from expected.", j - i, ofs + i,
file_name);
188 msg (
"Showing first differing %zu bytes.", show_cnt);
190 msg (
"Data actually read:");
191 hex_dump (ofs + i, read_data + i, show_cnt,
true);
192 msg (
"Expected data:");
193 hex_dump (ofs + i, expected_data + i, show_cnt,
true);
194 fail (
"%zu bytes read starting at offset %zu in \"%s\" differ "
195 "from expected", j - i, ofs + i,
file_name);
block_sector_t block_size(struct block *block)
Returns the number of sectors in BLOCK.
static char buf[BUF_SIZE]
static void wait(struct intq *q, struct thread **waiter)
int vsnprintf(char *buffer, size_t buf_size, const char *format, va_list args)
Like vprintf(), except that output is stored into BUFFER, which must have space for BUF_SIZE characte...
int snprintf(char *buffer, size_t buf_size, const char *format,...)
Like printf(), except that output is stored into BUFFER, which must have space for BUF_SIZE character...
void hex_dump(uintptr_t ofs, const void *buf_, size_t size, bool ascii)
Dumps the SIZE bytes in BUF to the console as hex bytes arranged 16 per line.
int open(const char *file)
int write(int fd, const void *buffer, unsigned size)
pid_t exec(const char *file)
int read(int fd, void *buffer, unsigned size)
int pid_t
Process identifier.
static void vmsg(const char *format, va_list args, const char *suffix)
void compare_bytes(const void *read_data_, const void *expected_data_, size_t size, size_t ofs, const char *file_name)
test/lib.h
void fail(const char *format,...)
void check_file(const char *file_name, const void *buf, size_t size)
void msg(const char *format,...)
static void swap(void *a_, void *b_, size_t size)
const char * test_name
Child process for syn-read test.
void shuffle(void *buf_, size_t cnt, size_t size)
void check_file_handle(int fd, const char *file_name, const void *buf_, size_t size)
void wait_children(pid_t pids[], size_t child_cnt)
void exec_children(const char *child_name, pid_t pids[], size_t child_cnt)
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
unsigned long random_ulong(void)
Returns a pseudo-random unsigned long.
#define va_start(LIST, ARG)
__builtin_va_list va_list
GCC has <stdarg.h> functionality as built-ins, so all we need is to use it.
int memcmp(const void *a_, const void *b_, size_t size)
Find the first differing byte in the two blocks of SIZE bytes at A and B.
size_t strlen(const char *string)
Returns the length of STRING.
size_t strlcpy(char *dst, const char *src, size_t size)
Copies string SRC to DST.
static const char file_name[]
tests/filesys/base/syn-read.h