From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>
Subject: [Qemu-devel] [PATCH v1 2/4] tests/tcg: better detect truncated reads
Date: Wed, 5 Jun 2019 17:23:24 +0100 [thread overview]
Message-ID: <20190605162326.13896-3-alex.bennee@linaro.org> (raw)
In-Reply-To: <20190605162326.13896-1-alex.bennee@linaro.org>
If we've truncated a wider read we can detect the condition earlier by
looking at the number of zeros we've read. So we don't trip up on
cases where we have written zeros to the start of the buffer we also
ensure we only start each offset read from the right address.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
tests/tcg/multiarch/system/memory.c | 36 +++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 5 deletions(-)
diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/system/memory.c
index dc1d8a98ff..d124502d73 100644
--- a/tests/tcg/multiarch/system/memory.c
+++ b/tests/tcg/multiarch/system/memory.c
@@ -208,6 +208,7 @@ static bool read_test_data_u32(int offset)
for (i = 0; i < max; i++) {
uint8_t b1, b2, b3, b4;
+ int zeros = 0;
word = *ptr++;
b1 = word >> 24 & 0xff;
@@ -215,6 +216,16 @@ static bool read_test_data_u32(int offset)
b3 = word >> 8 & 0xff;
b4 = word & 0xff;
+ zeros += (b1 == 0 ? 1 : 0);
+ zeros += (b2 == 0 ? 1 : 0);
+ zeros += (b3 == 0 ? 1 : 0);
+ zeros += (b4 == 0 ? 1 : 0);
+ if (zeros > 1) {
+ ml_printf("Error @ %p, more zeros than expected: %d, %d, %d, %d",
+ ptr - 1, b1, b2, b3, b4);
+ return false;
+ }
+
if ((b1 < b2 && b1 != 0) ||
(b2 < b3 && b2 != 0) ||
(b3 < b4 && b3 != 0)) {
@@ -238,6 +249,7 @@ static bool read_test_data_u64(int offset)
for (i = 0; i < max; i++) {
uint8_t b1, b2, b3, b4, b5, b6, b7, b8;
+ int zeros = 0;
word = *ptr++;
b1 = ((uint64_t) (word >> 56)) & 0xff;
@@ -249,6 +261,20 @@ static bool read_test_data_u64(int offset)
b7 = (word >> 8) & 0xff;
b8 = (word >> 0) & 0xff;
+ zeros += (b1 == 0 ? 1 : 0);
+ zeros += (b2 == 0 ? 1 : 0);
+ zeros += (b3 == 0 ? 1 : 0);
+ zeros += (b4 == 0 ? 1 : 0);
+ zeros += (b5 == 0 ? 1 : 0);
+ zeros += (b6 == 0 ? 1 : 0);
+ zeros += (b7 == 0 ? 1 : 0);
+ zeros += (b8 == 0 ? 1 : 0);
+ if (zeros > 1) {
+ ml_printf("Error @ %p, more zeros than expected: %d, %d, %d, %d, %d, %d, %d, %d",
+ ptr - 1, b1, b2, b3, b4, b5, b6, b7, b8);
+ return false;
+ }
+
if ((b1 < b2 && b1 != 0) ||
(b2 < b3 && b2 != 0) ||
(b3 < b4 && b3 != 0) ||
@@ -272,7 +298,7 @@ read_ufn read_ufns[] = { read_test_data_u16,
read_test_data_u32,
read_test_data_u64 };
-bool do_unsigned_reads(void)
+bool do_unsigned_reads(int start_off)
{
int i;
bool ok = true;
@@ -280,11 +306,11 @@ bool do_unsigned_reads(void)
for (i = 0; i < ARRAY_SIZE(read_ufns) && ok; i++) {
#if CHECK_UNALIGNED
int off;
- for (off = 0; off < 8 && ok; off++) {
+ for (off = start_off; off < 8 && ok; off++) {
ok = read_ufns[i](off);
}
#else
- ok = read_ufns[i](0);
+ ok = read_ufns[i](start_off);
#endif
}
@@ -298,11 +324,11 @@ static bool do_unsigned_test(init_ufn fn)
int i;
for (i = 0; i < 8 && ok; i++) {
fn(i);
- ok = do_unsigned_reads();
+ ok = do_unsigned_reads(i);
}
#else
fn(0);
- return do_unsigned_reads();
+ return do_unsigned_reads(0);
#endif
}
--
2.20.1
next prev parent reply other threads:[~2019-06-05 16:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-05 16:23 [Qemu-devel] [PATCH v1 0/4] softmmu de-macro fix with tests Alex Bennée
2019-06-05 16:23 ` [Qemu-devel] [PATCH v1 1/4] cputlb: use uint64_t for interim values for unaligned load Alex Bennée
2019-06-05 16:23 ` Alex Bennée [this message]
2019-06-05 16:23 ` [Qemu-devel] [PATCH v1 3/4] tests/tcg: clean-up VPATH/TESTS for i386 Alex Bennée
2019-06-05 16:23 ` [Qemu-devel] [PATCH v1 4/4] tests/tcg/x86_64: add a PVHVM crt.o for x86_64 system tests Alex Bennée
2019-06-05 16:36 ` Paolo Bonzini
2019-06-05 18:44 ` [Qemu-devel] [PATCH v1 0/4] softmmu de-macro fix with tests no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190605162326.13896-3-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).