Add bread test app
authorJens Axboe <jaxboe@fusionio.com>
Thu, 7 Oct 2010 13:04:43 +0000 (15:04 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Thu, 7 Oct 2010 13:04:43 +0000 (15:04 +0200)
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
test/Makefile [new file with mode: 0644]
test/bread.c [new file with mode: 0644]

diff --git a/test/Makefile b/test/Makefile
new file mode 100644 (file)
index 0000000..6bd767c
--- /dev/null
@@ -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 (file)
index 0000000..d16ba7d
--- /dev/null
@@ -0,0 +1,87 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <linux/types.h>
+#include <sys/ioctl.h>
+
+#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;
+}