From f0af7a27167edd01b6aeb6903daad569ed1c0be9 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 7 Oct 2010 15:04:43 +0200 Subject: [PATCH] Add bread test app Signed-off-by: Jens Axboe --- test/Makefile | 11 +++++++ test/bread.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 test/Makefile create mode 100644 test/bread.c diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..6bd767c --- /dev/null +++ b/test/Makefile @@ -0,0 +1,11 @@ +CC = gcc +OPTFLAGS= -O2 -g $(EXTFLAGS) +CFLAGS = -Wall -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 $(OPTFLAGS) +PROGS = bread + +all: $(PROGS) + +bread: bread.o + +clean: + -rm -f .depend *.o $(PROGS) core.* core diff --git a/test/bread.c b/test/bread.c new file mode 100644 index 0000000..d16ba7d --- /dev/null +++ b/test/bread.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "../binject.h" + +#define BS 512 +#define DEPTH 1024 + +static void cmd_set_offset(struct b_user_cmd *cmds, unsigned long *off) +{ + int i; + + for (i = 0; i < DEPTH; i++) { +#if 0 + cmds[i].offset = lrand48(); +#else + cmds[i].offset = *off; +#endif + *off += BS; + } +} + +int main(int argc, char *argv[]) +{ + void *buf; + struct b_user_cmd c[DEPTH], d[DEPTH]; + void *r_buf; + unsigned long off; + int fd, i; + + fd = open("/dev/binject0", O_RDWR); + if (fd < 0) { + perror("open dev"); + return 1; + } + + if (posix_memalign(&buf, 4096, DEPTH * BS)) { + perror("posix_memalign"); + return 1; + } + + for (i = 0; i < DEPTH; i++) { + binject_buc_set_magic(&c[i]); + c[i].type = B_TYPE_READ; + c[i].flags = B_FLAG_NOIDLE; + c[i].len = BS; + c[i].buf = (unsigned long) buf + i * BS; + } + + c[DEPTH - 1].flags |= B_FLAG_UNPLUG; + + off = 0; + do { + int write_size, read_size; + + cmd_set_offset(c, &off); + + write_size = sizeof(struct b_user_cmd) * DEPTH; + + if (write(fd, c, write_size) != write_size) { + perror("write"); + break; + } + + read_size = write_size; + r_buf = d; + do { + int ret; + + ret = read(fd, r_buf, read_size); + if (ret < 0) { + perror("read"); + return 1; + } else { + read_size -= ret; + r_buf += ret; + } + } while (read_size); + } while (1); + + return 0; +} -- 2.25.1