Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LvCag-000415-5z for qemu-devel@nongnu.org; Sat, 18 Apr 2009 11:36:26 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LvCaf-00040W-7S for qemu-devel@nongnu.org; Sat, 18 Apr 2009 11:36:25 -0400 Received: from [199.232.76.173] (port=45683 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LvCae-00040M-UD for qemu-devel@nongnu.org; Sat, 18 Apr 2009 11:36:24 -0400 Received: from savannah.gnu.org ([199.232.41.3]:40175 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LvCae-0005GH-FJ for qemu-devel@nongnu.org; Sat, 18 Apr 2009 11:36:24 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LvCad-0006kX-Uk for qemu-devel@nongnu.org; Sat, 18 Apr 2009 15:36:24 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LvCad-0006kS-NF for qemu-devel@nongnu.org; Sat, 18 Apr 2009 15:36:23 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Sat, 18 Apr 2009 15:36:23 +0000 Subject: [Qemu-devel] [7182] qemu-io: Verify read data by patterns (Kevin Wolf) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 7182 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7182 Author: aliguori Date: 2009-04-18 15:36:23 +0000 (Sat, 18 Apr 2009) Log Message: ----------- qemu-io: Verify read data by patterns (Kevin Wolf) This patch adds a -P option to read and readv which allows to compare the read data to a given pattern. This can be used to verify data written by write -P. Signed-off-by: Kevin Wolf Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/qemu-io.c Modified: trunk/qemu-io.c =================================================================== --- trunk/qemu-io.c 2009-04-18 15:36:19 UTC (rev 7181) +++ trunk/qemu-io.c 2009-04-18 15:36:23 UTC (rev 7182) @@ -192,6 +192,7 @@ " Reads a segment of the currently open file, optionally dumping it to the\n" " standard output stream (with -v option) for subsequent inspection.\n" " -p, -- use bdrv_pread to read the file\n" +" -P, -- use a pattern to verify read data\n" " -C, -- report statistics in a machine parsable format\n" " -v, -- dump buffer to standard output\n" " -q, -- quite mode, do not show I/O statistics\n" @@ -207,8 +208,10 @@ char *buf; int64_t offset; int count, total; + int pattern = 0; + int Pflag = 0; - while ((c = getopt(argc, argv, "Cpqv")) != EOF) { + while ((c = getopt(argc, argv, "CpP:qv")) != EOF) { switch (c) { case 'C': Cflag = 1; @@ -216,6 +219,10 @@ case 'p': pflag = 1; break; + case 'P': + Pflag = 1; + pattern = atoi(optarg); + break; case 'q': qflag = 1; break; @@ -270,6 +277,17 @@ return 0; } + if (Pflag) { + void* cmp_buf = malloc(count); + memset(cmp_buf, pattern, count); + if (memcmp(buf, cmp_buf, count)) { + printf("Pattern verification failed at offset %lld, " + "%d bytes\n", + (long long) offset, count); + } + free(cmp_buf); + } + if (qflag) return 0; @@ -291,7 +309,7 @@ .cfunc = read_f, .argmin = 2, .argmax = -1, - .args = "[-aCpqv] off len", + .args = "[-aCpqv] [-P pattern ] off len", .oneline = "reads a number of bytes at a specified offset", .help = read_help, }; @@ -312,6 +330,7 @@ " standard output stream (with -v option) for subsequent inspection.\n" " Uses multiple iovec buffers if more than one byte range is specified.\n" " -C, -- report statistics in a machine parsable format\n" +" -P, -- use a pattern to verify read data\n" " -v, -- dump buffer to standard output\n" " -q, -- quite mode, do not show I/O statistics\n" "\n"); @@ -328,12 +347,18 @@ int count = 0, total; int nr_iov, i; QEMUIOVector qiov; + int pattern = 0; + int Pflag = 0; - while ((c = getopt(argc, argv, "Cqv")) != EOF) { + while ((c = getopt(argc, argv, "CP:qv")) != EOF) { switch (c) { case 'C': Cflag = 1; break; + case 'P': + Pflag = 1; + pattern = atoi(optarg); + break; case 'q': qflag = 1; break; @@ -406,6 +431,17 @@ return 0; } + if (Pflag) { + void* cmp_buf = malloc(count); + memset(cmp_buf, pattern, count); + if (memcmp(buf, cmp_buf, count)) { + printf("Pattern verification failed at offset %lld, " + "%d bytes\n", + (long long) offset, count); + } + free(cmp_buf); + } + if (qflag) return 0; @@ -426,7 +462,7 @@ .cfunc = readv_f, .argmin = 2, .argmax = -1, - .args = "[-Cqv] off len [len..]", + .args = "[-Cqv] [-P pattern ] off len [len..]", .oneline = "reads a number of bytes at a specified offset", .help = readv_help, };