From nobody Tue Feb 10 05:42:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1559751967; cv=none; d=zoho.com; s=zohoarc; b=Qwfi1ggZ7XPGFBG8dck3XG/vW97YcSCJm/T7MIOz0AXCoBpFx/MCjS3r0O4KlnslJHlHBebH6+qXOsNJ7JGmgeOwHVpflqhj4QZz9RyL3uwFo3pAXjEmT8/f5BdEiIL7Gt3KaO5wtNrDybQzcee+5eFjTOx4YLHB6qS4CH1yrvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559751967; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=rgBvXlBNWOdKdXf6eUYyvBxYKbwloU7UKvzHljRF0GU=; b=IHDe+G0tcE22woiWOiozwvb+rFq3reigcL+Qg+oB/p5zsVNtiKDGcAXF4/bQVAE1an2i3H4Oyof8hzB26tpeFGTTT6EMPdDAO7DvVlyExITOdG5yraHwM34Hu6Tjpa40bJUTa67cErROBNb/80tnhWpcCn3jBTo+BoeZ1Nabg8Q= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559751967988994.8175873023422; Wed, 5 Jun 2019 09:26:07 -0700 (PDT) Received: from localhost ([127.0.0.1]:45976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYYjm-0000sI-Vd for importer@patchew.org; Wed, 05 Jun 2019 12:26:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYYhH-0007Mj-DE for qemu-devel@nongnu.org; Wed, 05 Jun 2019 12:23:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYYhG-0008RJ-0t for qemu-devel@nongnu.org; Wed, 05 Jun 2019 12:23:31 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:36782) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hYYhF-0008ON-Pe for qemu-devel@nongnu.org; Wed, 05 Jun 2019 12:23:29 -0400 Received: by mail-wr1-x441.google.com with SMTP id n4so17088806wrs.3 for ; Wed, 05 Jun 2019 09:23:29 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l18sm18893090wrv.38.2019.06.05.09.23.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 05 Jun 2019 09:23:27 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id BA9781FF8F; Wed, 5 Jun 2019 17:23:26 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rgBvXlBNWOdKdXf6eUYyvBxYKbwloU7UKvzHljRF0GU=; b=kP2zDC8FAHOIZ3KFQtxk4US8fuYGuxYs8OBDx3Sa1g2pD5/C6XAaCm9FtYwqPuGca+ QVQSYUWmfY1lCh2fdJG0PLLcyyxDuVZQ2xueGM0Qfw9iVm9fgjk4QjJZ+fQoRVW8x7rS JiebdhrFIjmBGSBDIGoGm2ydL575jxXbBI6Tz3XWUqW9Us2DniOD1Fk4vgEB9yvoPAFG DiG8Gq09WkJ1Jm3w55FKtqRAxUA8jiMqaNzYMXoxtYRwp9txv3G3rffD3VglndayBKFL dZiSkNzbhyWKjVNotKyaRLKmQi0FDqYUQxSscjm2jpurHeVgtAU7uB0aX/FuhovMaFJL sdqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rgBvXlBNWOdKdXf6eUYyvBxYKbwloU7UKvzHljRF0GU=; b=N9XfMCbpnpT281B1HbipWM2pVOe5zktcgpU1vyTKfoZldUn2TUtbsEsgtl0AUralvQ 8qnP3HS6b1Okm7XlKh/9xDq23i/h3wZy5s/bnt7apQ66PATDIEU4jD5FCfXlfrBmF9Fz uu2S0cqIlUNJJn+HsQAe/gZkBzXid3oSr3mbFGAqUctUfMuFWdmksiuAw3DvKovqf7Xu wKBwxJB19pV/Dax9m1TJtOZ7kGvCPN6cl/ptYIrViNxkOlw2Qa82w+CryEdXvgBZE9zp 0fzxGwtS7AIkVOZ6JsNKgSZezTc51QmcxFELVovqsGKQ/Ld0zw2ehsZAWF5S0qDYImkN VUWg== X-Gm-Message-State: APjAAAU0gncs8I2dXYH2j2fO05YhO2vGV4a0Iw/xBnessb4Gn4lUrTiI hRLJ7p+y+7c98vfIyBcRBp1RxA== X-Google-Smtp-Source: APXvYqzFgjekIQ895yxEMzdRMYtGAnXpCUar2MotWFKkusL9akKJN/h3fvQF/tm8W4uiRF5KKWEYgg== X-Received: by 2002:a05:6000:100a:: with SMTP id a10mr25150382wrx.323.1559751808802; Wed, 05 Jun 2019 09:23:28 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 5 Jun 2019 17:23:24 +0100 Message-Id: <20190605162326.13896-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190605162326.13896-1-alex.bennee@linaro.org> References: <20190605162326.13896-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v1 2/4] tests/tcg: better detect truncated reads X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e --- 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/syst= em/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) =20 for (i =3D 0; i < max; i++) { uint8_t b1, b2, b3, b4; + int zeros =3D 0; word =3D *ptr++; =20 b1 =3D word >> 24 & 0xff; @@ -215,6 +216,16 @@ static bool read_test_data_u32(int offset) b3 =3D word >> 8 & 0xff; b4 =3D word & 0xff; =20 + zeros +=3D (b1 =3D=3D 0 ? 1 : 0); + zeros +=3D (b2 =3D=3D 0 ? 1 : 0); + zeros +=3D (b3 =3D=3D 0 ? 1 : 0); + zeros +=3D (b4 =3D=3D 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 !=3D 0) || (b2 < b3 && b2 !=3D 0) || (b3 < b4 && b3 !=3D 0)) { @@ -238,6 +249,7 @@ static bool read_test_data_u64(int offset) =20 for (i =3D 0; i < max; i++) { uint8_t b1, b2, b3, b4, b5, b6, b7, b8; + int zeros =3D 0; word =3D *ptr++; =20 b1 =3D ((uint64_t) (word >> 56)) & 0xff; @@ -249,6 +261,20 @@ static bool read_test_data_u64(int offset) b7 =3D (word >> 8) & 0xff; b8 =3D (word >> 0) & 0xff; =20 + zeros +=3D (b1 =3D=3D 0 ? 1 : 0); + zeros +=3D (b2 =3D=3D 0 ? 1 : 0); + zeros +=3D (b3 =3D=3D 0 ? 1 : 0); + zeros +=3D (b4 =3D=3D 0 ? 1 : 0); + zeros +=3D (b5 =3D=3D 0 ? 1 : 0); + zeros +=3D (b6 =3D=3D 0 ? 1 : 0); + zeros +=3D (b7 =3D=3D 0 ? 1 : 0); + zeros +=3D (b8 =3D=3D 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 !=3D 0) || (b2 < b3 && b2 !=3D 0) || (b3 < b4 && b3 !=3D 0) || @@ -272,7 +298,7 @@ read_ufn read_ufns[] =3D { read_test_data_u16, read_test_data_u32, read_test_data_u64 }; =20 -bool do_unsigned_reads(void) +bool do_unsigned_reads(int start_off) { int i; bool ok =3D true; @@ -280,11 +306,11 @@ bool do_unsigned_reads(void) for (i =3D 0; i < ARRAY_SIZE(read_ufns) && ok; i++) { #if CHECK_UNALIGNED int off; - for (off =3D 0; off < 8 && ok; off++) { + for (off =3D start_off; off < 8 && ok; off++) { ok =3D read_ufns[i](off); } #else - ok =3D read_ufns[i](0); + ok =3D read_ufns[i](start_off); #endif } =20 @@ -298,11 +324,11 @@ static bool do_unsigned_test(init_ufn fn) int i; for (i =3D 0; i < 8 && ok; i++) { fn(i); - ok =3D do_unsigned_reads(); + ok =3D do_unsigned_reads(i); } #else fn(0); - return do_unsigned_reads(); + return do_unsigned_reads(0); #endif } =20 --=20 2.20.1