qemu-io: correctly print non-integer values as decimals

qemu-io's cvtstr function sometimes will incorrectly omit the
decimal part of the number, and sometimes will incorrectly include
it.  This patch fixes both.  The former is more serious, and can
be seen in the patches to 027.out and 033.out.

The changes to all other files were scripted with sed, so there were
no "surprises" beyond 027.out and 033.out.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Paolo Bonzini
2012-05-10 10:32:12 +02:00
committed by Kevin Wolf
parent dc5a137125
commit 8655d2de0a
13 changed files with 4196 additions and 4190 deletions
+23 -17
View File
@@ -418,31 +418,37 @@ cvtstr(
char *str,
size_t size)
{
const char *fmt;
int precise;
precise = ((double)value * 1000 == (double)(int)value * 1000);
char *trim;
const char *suffix;
if (value >= EXABYTES(1)) {
fmt = precise ? "%.f EiB" : "%.3f EiB";
snprintf(str, size, fmt, TO_EXABYTES(value));
suffix = " EiB";
snprintf(str, size - 4, "%.3f", TO_EXABYTES(value));
} else if (value >= PETABYTES(1)) {
fmt = precise ? "%.f PiB" : "%.3f PiB";
snprintf(str, size, fmt, TO_PETABYTES(value));
suffix = " PiB";
snprintf(str, size - 4, "%.3f", TO_PETABYTES(value));
} else if (value >= TERABYTES(1)) {
fmt = precise ? "%.f TiB" : "%.3f TiB";
snprintf(str, size, fmt, TO_TERABYTES(value));
suffix = " TiB";
snprintf(str, size - 4, "%.3f", TO_TERABYTES(value));
} else if (value >= GIGABYTES(1)) {
fmt = precise ? "%.f GiB" : "%.3f GiB";
snprintf(str, size, fmt, TO_GIGABYTES(value));
suffix = " GiB";
snprintf(str, size - 4, "%.3f", TO_GIGABYTES(value));
} else if (value >= MEGABYTES(1)) {
fmt = precise ? "%.f MiB" : "%.3f MiB";
snprintf(str, size, fmt, TO_MEGABYTES(value));
suffix = " MiB";
snprintf(str, size - 4, "%.3f", TO_MEGABYTES(value));
} else if (value >= KILOBYTES(1)) {
fmt = precise ? "%.f KiB" : "%.3f KiB";
snprintf(str, size, fmt, TO_KILOBYTES(value));
suffix = " KiB";
snprintf(str, size - 4, "%.3f", TO_KILOBYTES(value));
} else {
snprintf(str, size, "%f bytes", value);
suffix = " bytes";
snprintf(str, size - 6, "%f", value);
}
trim = strstr(str, ".000");
if (trim) {
strcpy(trim, suffix);
} else {
strcat(str, suffix);
}
}
+2 -2
View File
@@ -15,9 +15,9 @@ read 134217728/134217728 bytes at offset 0
unaligned pwrite
wrote 42/42 bytes at offset 66
42.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
42 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
verify pattern
read 42/42 bytes at offset 66
42.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
42 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
*** done
+1 -1
View File
@@ -5,5 +5,5 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
== read from read-only image
read 512/512 bytes at offset 0
512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
*** done
+6 -6
View File
@@ -3,21 +3,21 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
== reading at EOF ==
read 512/512 bytes at offset 134217728
512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== reading far past EOF ==
read 512/512 bytes at offset 268435456
512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== writing at EOF ==
wrote 512/512 bytes at offset 134217728
512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 512/512 bytes at offset 134217728
512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== writing far past EOF ==
wrote 512/512 bytes at offset 268435456
512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 512/512 bytes at offset 268435456
512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
*** done
+512 -512
View File
File diff suppressed because it is too large Load Diff
+512 -512
View File
File diff suppressed because it is too large Load Diff
+768 -768
View File
File diff suppressed because it is too large Load Diff
+512 -512
View File
File diff suppressed because it is too large Load Diff
+1440 -1440
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -19,5 +19,5 @@ read 2048/2048 bytes at offset 0
== verify zeroes after sub-cluster pattern ==
read 2560/2560 bytes at offset 1024
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
2.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
*** done
+224 -224
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -5,17 +5,17 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
wrote 1024/1024 bytes at offset 512
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
wrote 1536/1536 bytes at offset 131072
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
1.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
wrote 131072/131072 bytes at offset 1024
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== verifying patterns (1) ==
read 512/512 bytes at offset 512
512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 131072/131072 bytes at offset 1024
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
read 512/512 bytes at offset 132096
512.000000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== rewriting zeroes ==
wrote 65536/65536 bytes at offset 65536
+192 -192
View File
File diff suppressed because it is too large Load Diff