From nobody Mon Dec 15 21:24:36 2025 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=1556644028; cv=none; d=zoho.com; s=zohoarc; b=hfle9pgpxciBFEKqEOVWlwwf+YFZF19Q8Hw65NhJjstJnEdAvIUJrtwVD85C6I/CP/LAQba5UhCVwpkW0W9qxPnAqvg4kodvE3wASYf7ryCaK8FE3s1mMHDVQdRJRDGkzeJqIx5Xu+nWZPfZWeNVbSVQLGBIl0OOyL4D6GtDeq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556644028; 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=EdGFZbKcoEBKfDx7OK4/edboZqTBfkUrZ7ki4QLE8eA=; b=kai2i81ZiVV/RjWZuzJJE9f2plHQI3a6cevQg0Wf/cdZPqIH3i76FJs5+/D8p7kMS0v/XZCafEFHIpfdKj9GaarEpZM0s1OGqYpClcDEaBK0y9amgUroEuYzNwrvAyBYlbcyOy0xUzmBU9doTmYyuAZbnX25CezLQ8EAjqVDgqU= 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 1556644028877164.20066553912693; Tue, 30 Apr 2019 10:07:08 -0700 (PDT) Received: from localhost ([127.0.0.1]:50347 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLWDg-0005cS-ME for importer@patchew.org; Tue, 30 Apr 2019 13:07:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLW2G-0004J9-Op for qemu-devel@nongnu.org; Tue, 30 Apr 2019 12:55:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLVzl-0000ir-Ou for qemu-devel@nongnu.org; Tue, 30 Apr 2019 12:52:43 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:54120) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hLVzl-0000i2-IN for qemu-devel@nongnu.org; Tue, 30 Apr 2019 12:52:41 -0400 Received: by mail-wm1-x341.google.com with SMTP id 26so4621142wmj.3 for ; Tue, 30 Apr 2019 09:52:41 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id w2sm27140431wrm.74.2019.04.30.09.52.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Apr 2019 09:52:37 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C971F1FF93; Tue, 30 Apr 2019 17:52:34 +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=EdGFZbKcoEBKfDx7OK4/edboZqTBfkUrZ7ki4QLE8eA=; b=Vnh4GMUK5QCmlPtHA7hD6oBMmOgnZ8iQETkp3w5KToQkaRL2QaZCOWqBDQ1S7wU778 bKKN9F6RH4P9Fwe2HxiaWUR0QIwUG9kA5r4fXve3QiQaN50s1URvUBO9hu2h4EG3hz6V J7N31K63lhyAFkfgJ77g2mEFKC+V4g1Zv3GMRr0Vblscha8u0wBM7lza2HxOzQJnC0yE 1R7JaxKClioOn2Z1SdMNJu+/CD9ONy7oec/6otDw4+9QmLLR/gIuuIYvNfOldwKnMQOp 2MExU3t174MEfCSOIiX6g1k4vJTf0X6yBxld9MWCXQVOupW/PVtkTbgJiQyXMRgcCbrD k4Vw== 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=EdGFZbKcoEBKfDx7OK4/edboZqTBfkUrZ7ki4QLE8eA=; b=TcHcnidz6F1akgMRtxPJLzYrxQDBWQa6WfokO4zN9mCUWE8f7ul5YOyWPdTg3yMKTg G1TVDH6+N5WpGxccRyrRCdSNJc90Ele4kUdVqCoC7a+AY236NygswbunqmyaqpKau4Qp jv4CUOipy3TvYtk7k0va0OUVMx+dsvb8VxZ8JbTtPZivVGxA/3euwXIqFGzjxt98Cuwu Zl6iFW5NkHNcPbV3nhWyHPvdOSNwQTvn73dew84VdYuxXAUVyOxGvXfTm3FuVJFxifyZ yetg8hE6JMFSLc855znlwo4qJvOS96nBu9TN1U5KnVbwjS7JMbzoxEDCVYiDbxk/wCEr 9eHw== X-Gm-Message-State: APjAAAUP+PVRbX5YeauT/GqXtvUSI4kb8KW8hvFM5mBJsvNdrsv9cQ49 K9P3WZ+eRx8v6/IcKavEZhgQ/w== X-Google-Smtp-Source: APXvYqxIMHLBboSDBeyK8zHHBf9xoLbbYOThU5rMin0J64RCAD/E/ZK7hJ2XHuIr4OajXDoEUKvwBA== X-Received: by 2002:a05:600c:2208:: with SMTP id z8mr3664126wml.89.1556643160443; Tue, 30 Apr 2019 09:52:40 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 30 Apr 2019 17:52:25 +0100 Message-Id: <20190430165234.32272-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190430165234.32272-1-alex.bennee@linaro.org> References: <20190430165234.32272-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::341 Subject: [Qemu-devel] [PATCH v5 06/15] tests/tcg/multiarch: expand system memory test to cover more 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?= , qemu-arm@nongnu.org, mark.cave-ayland@ilande.co.uk, cota@braap.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Expand the memory test to cover move of the softmmu code. Specifically we: - improve commentary - add some helpers (for later BE support) - reduce boiler plate into helpers - add signed reads at various sizes/offsets Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- tests/tcg/multiarch/system/memory.c | 254 ++++++++++++++++++++++++---- 1 file changed, 219 insertions(+), 35 deletions(-) diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/syst= em/memory.c index a7a0a8e978..5befbb36bb 100644 --- a/tests/tcg/multiarch/system/memory.c +++ b/tests/tcg/multiarch/system/memory.c @@ -5,16 +5,21 @@ * behave across normal and unaligned accesses across several pages. * We are not replicating memory tests for stuck bits and other * hardware level failures but looking for issues with different size - * accesses when: - + * accesses when access is: * + * - unaligned at various sizes + * - spanning a (softmmu) page + * - sign extension when loading */ =20 #include +#include #include =20 -#define TEST_SIZE (4096 * 4) /* 4 pages */ +#define PAGE_SIZE 4096 /* nominal 4k "pages" */ +#define TEST_SIZE (PAGE_SIZE * 4) /* 4 pages */ =20 +__attribute__((aligned(PAGE_SIZE))) static uint8_t test_data[TEST_SIZE]; =20 static void pdot(int count) @@ -24,11 +29,19 @@ static void pdot(int count) } } =20 +/* + * Helper macros for shift/extract so we can keep our endian handling + * in one place. + */ +#define BYTE_SHIFT(b, pos) ((uint64_t)b << (pos * 8)) +#define BYTE_EXTRACT(b, pos) ((b >> (pos * 8)) & 0xff) =20 /* - * Fill the data with ascending value bytes. As x86 is a LE machine we - * write in ascending order and then read and high byte should either - * be zero or higher than the lower bytes. + * Fill the data with ascending value bytes. + * + * Currently we only support Little Endian machines so write in + * ascending address order. When we read higher address bytes should + * either be zero or higher than the lower bytes. */ =20 static void init_test_data_u8(void) @@ -44,60 +57,109 @@ static void init_test_data_u8(void) ml_printf("done\n"); } =20 +/* + * Full the data with alternating positive and negative bytes. This + * should mean for reads larger than a byte all subsequent reads will + * stay either negative or positive. We never write 0. + */ + +static inline uint8_t get_byte(int index, bool neg) +{ + return neg ? ( 0xff << (index % 7)) : ( 0xff >> ((index % 6) + 1)); +} + +static void init_test_data_s8(bool neg_first) +{ + uint8_t top, bottom, *ptr =3D &test_data[0]; + int i; + + ml_printf("Filling test area with s8 pairs (%s):", neg_first ? "neg fi= rst":"pos first"); + for (i =3D 0; i < TEST_SIZE / 2; i++) { + *ptr++ =3D get_byte(i, neg_first); + *ptr++ =3D get_byte(i, !neg_first); + pdot(i); + } + ml_printf("done\n"); +} + +/* + * Zero the first few bytes of the test data in preparation for + * new offset values. + */ +static void reset_start_data(int offset) +{ + uint32_t *ptr =3D (uint32_t *) &test_data[0]; + int i; + for (i =3D 0; i < offset; i++) { + *ptr++ =3D 0; + } +} + static void init_test_data_u16(int offset) { uint8_t count =3D 0; - uint16_t word, *ptr =3D (uint16_t *) &test_data[0]; + uint16_t word, *ptr =3D (uint16_t *) &test_data[offset]; const int max =3D (TEST_SIZE - offset) / sizeof(word); int i; =20 - ml_printf("Filling test area with u16 (offset %d):", offset); + ml_printf("Filling test area with u16 (offset %d, %p):", offset, ptr); =20 - /* Leading zeros */ - for (i =3D 0; i < offset; i++) { - *ptr =3D 0; - } + reset_start_data(offset); =20 - ptr =3D (uint16_t *) &test_data[offset]; for (i =3D 0; i < max; i++) { - uint8_t high, low; - low =3D count++; - high =3D count++; - word =3D (high << 8) | low; + uint8_t low =3D count++, high =3D count++; + word =3D BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0); *ptr++ =3D word; pdot(i); } - ml_printf("done\n"); + ml_printf("done @ %p\n", ptr); } =20 static void init_test_data_u32(int offset) { uint8_t count =3D 0; - uint32_t word, *ptr =3D (uint32_t *) &test_data[0]; + uint32_t word, *ptr =3D (uint32_t *) &test_data[offset]; const int max =3D (TEST_SIZE - offset) / sizeof(word); int i; =20 - ml_printf("Filling test area with u32 (offset %d):", offset); + ml_printf("Filling test area with u32 (offset %d, %p):", offset, ptr); =20 - /* Leading zeros */ - for (i =3D 0; i < offset; i++) { - *ptr =3D 0; - } + reset_start_data(offset); =20 - ptr =3D (uint32_t *) &test_data[offset]; for (i =3D 0; i < max; i++) { - uint8_t b1, b2, b3, b4; - b4 =3D count++; - b3 =3D count++; - b2 =3D count++; - b1 =3D count++; - word =3D (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; + uint8_t b4 =3D count++, b3 =3D count++; + uint8_t b2 =3D count++, b1 =3D count++; + word =3D BYTE_SHIFT(b1, 3) | BYTE_SHIFT(b2, 2) | BYTE_SHIFT(b3, 1)= | b4; *ptr++ =3D word; pdot(i); } - ml_printf("done\n"); + ml_printf("done @ %p\n", ptr); } =20 +static void init_test_data_u64(int offset) +{ + uint8_t count =3D 0; + uint64_t word, *ptr =3D (uint64_t *) &test_data[offset]; + const int max =3D (TEST_SIZE - offset) / sizeof(word); + int i; + + ml_printf("Filling test area with u64 (offset %d, %p):", offset, ptr); + + reset_start_data(offset); + + for (i =3D 0; i < max; i++) { + uint8_t b8 =3D count++, b7 =3D count++; + uint8_t b6 =3D count++, b5 =3D count++; + uint8_t b4 =3D count++, b3 =3D count++; + uint8_t b2 =3D count++, b1 =3D count++; + word =3D BYTE_SHIFT(b1, 7) | BYTE_SHIFT(b2, 6) | BYTE_SHIFT(b3, 5)= | + BYTE_SHIFT(b4, 4) | BYTE_SHIFT(b5, 3) | BYTE_SHIFT(b6, 2) | + BYTE_SHIFT(b7, 1) | b8; + *ptr++ =3D word; + pdot(i); + } + ml_printf("done @ %p\n", ptr); +} =20 static int read_test_data_u16(int offset) { @@ -120,7 +182,7 @@ static int read_test_data_u16(int offset) } =20 } - ml_printf("done\n"); + ml_printf("done @ %p\n", ptr); return 0; } =20 @@ -150,7 +212,7 @@ static int read_test_data_u32(int offset) pdot(i); } } - ml_printf("done\n"); + ml_printf("done @ %p\n", ptr); return 0; } =20 @@ -189,7 +251,7 @@ static int read_test_data_u64(int offset) pdot(i); } } - ml_printf("done\n"); + ml_printf("done @ %p\n", ptr); return 0; } =20 @@ -209,6 +271,110 @@ int do_reads(void) return r; } =20 +/* + * We need to ensure signed data is read into a larger data type to + * ensure that sign extension is working properly. + */ + +static int read_test_data_s8(int offset, bool neg_first) +{ + int8_t *ptr =3D (int8_t *)&test_data[offset]; + int i; + const int max =3D (TEST_SIZE - offset) / 2; + + ml_printf("Reading s8 pairs from %#lx (offset %d):", ptr, offset); + + for (i =3D 0; i < max; i++) { + int16_t first, second; + bool ok; + first =3D *ptr++; + second =3D *ptr++; + + if (neg_first && first < 0 && second > 0) { + pdot(i); + } else if (!neg_first && first > 0 && second < 0) { + pdot(i); + } else { + ml_printf("Error %d %c %d\n", first, neg_first ? '<' : '>', se= cond); + return 1; + } + } + ml_printf("done @ %p\n", ptr); + return 0; +} + +static int read_test_data_s16(int offset, bool neg_first) +{ + int16_t *ptr =3D (int16_t *)&test_data[offset]; + int i; + const int max =3D (TEST_SIZE - offset) / (sizeof(*ptr)); + + ml_printf("Reading s16 from %#lx (offset %d, %s):", + ptr, offset, neg_first ? "neg":"pos"); + + for (i =3D 0; i < max; i++) { + int32_t data =3D *ptr++; + + if (neg_first && data < 0) { + pdot(i); + } else if (data > 0) { + pdot(i); + } else { + ml_printf("Error %d %c 0\n", data, neg_first ? '<' : '>'); + return 1; + } + } + ml_printf("done @ %p\n", ptr); + return 0; +} + +static int read_test_data_s32(int offset, bool neg_first) +{ + int32_t *ptr =3D (int32_t *)&test_data[offset]; + int i; + const int max =3D (TEST_SIZE - offset) / (sizeof(int32_t)); + + ml_printf("Reading s32 from %#lx (offset %d, %s):", + ptr, offset, neg_first ? "neg":"pos"); + + for (i =3D 0; i < max; i++) { + int64_t data =3D *ptr++; + + if (neg_first && data < 0) { + pdot(i); + } else if (data > 0) { + pdot(i); + } else { + ml_printf("Error %d %c 0\n", data, neg_first ? '<' : '>'); + return 1; + } + } + ml_printf("done @ %p\n", ptr); + return 0; +} + +/* + * Read the test data and verify at various offsets + * + * For everything except bytes all our reads should be either positive + * or negative depending on what offset we are reading from. Currently + * we only handle LE systems. + */ +int do_signed_reads(bool neg_first) +{ + int r =3D 0; + int off =3D 0; + + while (r =3D=3D 0 && off < 8) { + r =3D read_test_data_s8(off, neg_first ^ (off & 1)); + r |=3D read_test_data_s16(off, !(neg_first ^ (off & 1))); + r |=3D read_test_data_s32(off, !(neg_first ^ (off & 1))); + off++; + } + + return r; +} + int main(void) { int i, r =3D 0; @@ -238,6 +404,24 @@ int main(void) } } =20 + for (i =3D 0; i < 8; i++) { + init_test_data_u64(i); + + r =3D do_reads(); + if (r) { + return r; + } + } + + init_test_data_s8(false); + r =3D do_signed_reads(false); + if (r) { + return r; + } + + init_test_data_s8(true); + r =3D do_signed_reads(true); + ml_printf("Test complete: %s\n", r =3D=3D 0 ? "PASSED" : "FAILED"); return r; } --=20 2.20.1