From 5a7d91e1917dfb02f290e6bc06634eb1cabaf385 Mon Sep 17 00:00:00 2001 From: Dor Laor <dor@cloudius-systems.com> Date: Mon, 11 Feb 2013 10:33:32 +0200 Subject: [PATCH] Conduct further IO to vblk by looping over 100 pwrite/read requests and verify their content. The image is been run over but the content is restored after each write --- tests/tst-vblk.c | 56 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/tests/tst-vblk.c b/tests/tst-vblk.c index 9dea0a92b..73eb6d6a6 100644 --- a/tests/tst-vblk.c +++ b/tests/tst-vblk.c @@ -10,35 +10,53 @@ int main(int argc, char **argv) { int fd; - char *wbuf,*rbuf; + char *wbuf,*rbuf,*origin; + int i; - // malloc is used since virt_to_phys doesn't work - // on stack addresses and virtio needs that - wbuf = malloc(BUF_SIZE); - rbuf = malloc(BUF_SIZE); + // malloc is used since virt_to_phys doesn't work + // on stack addresses and virtio needs that + wbuf = malloc(BUF_SIZE); + rbuf = malloc(BUF_SIZE); + origin = malloc(BUF_SIZE); //preserves the prev content for next boot.. - fd = open("/dev/vblk0", O_RDWR); + fd = open("/dev/vblk0", O_RDWR); if (fd < 0) { perror("open"); return 1; } - memset(wbuf, 0xab, BUF_SIZE); - if (pwrite(fd, wbuf, BUF_SIZE, 0) != BUF_SIZE) { - perror("pwrite"); - return 1; - } + for (i=0;i<100;i++) { + + if (pread(fd, origin, BUF_SIZE, i) != BUF_SIZE) { + perror("pread, origin"); + return 1; + } + + memset(wbuf, i, BUF_SIZE); + if (pwrite(fd, wbuf, BUF_SIZE, i) != BUF_SIZE) { + perror("pwrite"); + return 1; + } + + memset(rbuf, i, BUF_SIZE); + if (pread(fd, rbuf, BUF_SIZE, i) != BUF_SIZE) { + perror("pread"); + return 1; + } + if (memcmp(wbuf, wbuf, BUF_SIZE) != 0) { + fprintf(stderr, "read error %i\n", i); + return 1; + } + + if (pwrite(fd, origin, BUF_SIZE, i) != BUF_SIZE) { + perror("pwrite origin"); + return 1; + } - memset(rbuf, 0, BUF_SIZE); - if (pread(fd, rbuf, BUF_SIZE, 0) != BUF_SIZE) { - perror("pwrite"); - return 1; - } - if (memcmp(wbuf, wbuf, BUF_SIZE) != 0) { - fprintf(stderr, "read error\n"); - return 1; } + fprintf(stdout, "vblk test passed\n"); + close(fd); return 0; } -- GitLab