From patchwork Tue Mar 12 15:59:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 10849509 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2698C1515 for ; Tue, 12 Mar 2019 16:36:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12905297A5 for ; Tue, 12 Mar 2019 16:36:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 072A6297AC; Tue, 12 Mar 2019 16:36:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 67697297A5 for ; Tue, 12 Mar 2019 16:36:50 +0000 (UTC) Received: from localhost ([127.0.0.1]:55495 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3kOX-0002cw-KD for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Mar 2019 12:36:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3ju4-0002YW-Kh for qemu-devel@nongnu.org; Tue, 12 Mar 2019 12:05:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3ju1-00037g-Sw for qemu-devel@nongnu.org; Tue, 12 Mar 2019 12:05:20 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:35599) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3ju1-00031a-7l for qemu-devel@nongnu.org; Tue, 12 Mar 2019 12:05:17 -0400 Received: by mail-wr1-x442.google.com with SMTP id t18so3336902wrx.2 for ; Tue, 12 Mar 2019 09:05:10 -0700 (PDT) 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=Cz2tKdSyxnqqt8wMVGvROwJ8Tc7g4IuH5oTOYIKht/g=; b=CS/2qp00wB0/uFAIKoyT0O+2wQTT5O2De8HD2QNG8SpjWtMfkx1rX5uIxjSPNvO/RA TwxLQq+/wv9SeORIJR5etJNl6nHDi+J1FXIFngCawuyVBeby5cVDAJVoGarpCzIErSKO qV2/ccFo3RUEcyzZIfS1VKw1mHfxISKjxfzBkbkagVb5uZ1KrAgHCgGYclCDpwTPgEvB 0llSvtbiEB1vG9ztyGBnNom80NeeoHTFBVliLBIUqNwpHCGkBTwtCImRZEXnGr2ZVtBh nnCHin9lJ8uE9DXkPMnl1PMc0k/vyUYsMhsy2u+O5R+A9xLUVyP4Rn3NukEYnmJFQYk7 hguw== 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=Cz2tKdSyxnqqt8wMVGvROwJ8Tc7g4IuH5oTOYIKht/g=; b=GLajY1DBKc9azGQOKjpcNq7G0xJexWJlzdSvunMtye7ACfJoXuObY0Y82O1RWLAIRG V9OlT0qeD2gV+vksM6m/uuuYvR7kXMoh3sAsrVuqyBDmpm5mXVJN8AgPrTu2a7TDdFUQ c0CO3uRfmIP6oEcMaeQDoMSAp+PeEv3UMZL73DvNlZD7m06xZDJn6NwV1W1AhMintfCZ 0xaL/kUvbjBDjAq/v7x9IG6vlpdCYZaH5LQBQ5u4cgreqcJ/iQNwF35RNkZNGT158mGp Y0cE4wh/U5Y0oH4GiAnnLsP/6lNxDlr5bSHNDCIicQ/5jf3Izk/AduJWmbcjfevnl9mV Y76A== X-Gm-Message-State: APjAAAUKHFq45BJY6IhzbBlzMosea+5Tw7Vswok2lUhalcEfYOX97H6i SELQKAPSAL/72k1ErXw5qrfs4A== X-Google-Smtp-Source: APXvYqxTAySYyHjKMOQ5DEgrt4tDARRS384SMX+miA01xNwfJVLvrr0V9sLys7NJvMYVi42rpaSoHw== X-Received: by 2002:adf:ef11:: with SMTP id e17mr1358795wro.93.1552406709659; Tue, 12 Mar 2019 09:05:09 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f196sm6084662wme.36.2019.03.12.09.05.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Mar 2019 09:05:09 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9E6FA1FF9C; Tue, 12 Mar 2019 15:59:48 +0000 (UTC) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 15:59:44 +0000 Message-Id: <20190312155947.14918-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190312155947.14918-1-alex.bennee@linaro.org> References: <20190312155947.14918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 18/21] tests/tcg/i386: add memory test to exercise softmmu 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: peter.maydell@linaro.org, famz@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, agraf@suse.de, cota@braap.org, aurelien@aurel32.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is a simple test to check various access patterns to memory including unaligned access. Signed-off-by: Alex Bennée --- tests/tcg/i386/system/memory.c | 243 +++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 tests/tcg/i386/system/memory.c diff --git a/tests/tcg/i386/system/memory.c b/tests/tcg/i386/system/memory.c new file mode 100644 index 0000000000..a7a0a8e978 --- /dev/null +++ b/tests/tcg/i386/system/memory.c @@ -0,0 +1,243 @@ +/* + * Memory Test + * + * This is intended to test the softmmu code and ensure we properly + * 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: + + * + */ + +#include +#include + +#define TEST_SIZE (4096 * 4) /* 4 pages */ + +static uint8_t test_data[TEST_SIZE]; + +static void pdot(int count) +{ + if (count % 128 == 0) { + ml_printf("."); + } +} + + +/* + * 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. + */ + +static void init_test_data_u8(void) +{ + uint8_t count = 0, *ptr = &test_data[0]; + int i; + + ml_printf("Filling test area with u8:"); + for (i = 0; i < TEST_SIZE; i++) { + *ptr++ = count++; + pdot(i); + } + ml_printf("done\n"); +} + +static void init_test_data_u16(int offset) +{ + uint8_t count = 0; + uint16_t word, *ptr = (uint16_t *) &test_data[0]; + const int max = (TEST_SIZE - offset) / sizeof(word); + int i; + + ml_printf("Filling test area with u16 (offset %d):", offset); + + /* Leading zeros */ + for (i = 0; i < offset; i++) { + *ptr = 0; + } + + ptr = (uint16_t *) &test_data[offset]; + for (i = 0; i < max; i++) { + uint8_t high, low; + low = count++; + high = count++; + word = (high << 8) | low; + *ptr++ = word; + pdot(i); + } + ml_printf("done\n"); +} + +static void init_test_data_u32(int offset) +{ + uint8_t count = 0; + uint32_t word, *ptr = (uint32_t *) &test_data[0]; + const int max = (TEST_SIZE - offset) / sizeof(word); + int i; + + ml_printf("Filling test area with u32 (offset %d):", offset); + + /* Leading zeros */ + for (i = 0; i < offset; i++) { + *ptr = 0; + } + + ptr = (uint32_t *) &test_data[offset]; + for (i = 0; i < max; i++) { + uint8_t b1, b2, b3, b4; + b4 = count++; + b3 = count++; + b2 = count++; + b1 = count++; + word = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; + *ptr++ = word; + pdot(i); + } + ml_printf("done\n"); +} + + +static int read_test_data_u16(int offset) +{ + uint16_t word, *ptr = (uint16_t *)&test_data[offset]; + int i; + const int max = (TEST_SIZE - offset) / sizeof(word); + + ml_printf("Reading u16 from %#lx (offset %d):", ptr, offset); + + for (i = 0; i < max; i++) { + uint8_t high, low; + word = *ptr++; + high = (word >> 8) & 0xff; + low = word & 0xff; + if (high < low && high != 0) { + ml_printf("Error %d < %d\n", high, low); + return 1; + } else { + pdot(i); + } + + } + ml_printf("done\n"); + return 0; +} + +static int read_test_data_u32(int offset) +{ + uint32_t word, *ptr = (uint32_t *)&test_data[offset]; + int i; + const int max = (TEST_SIZE - offset) / sizeof(word); + + ml_printf("Reading u32 from %#lx (offset %d):", ptr, offset); + + for (i = 0; i < max; i++) { + uint8_t b1, b2, b3, b4; + word = *ptr++; + + b1 = word >> 24 & 0xff; + b2 = word >> 16 & 0xff; + b3 = word >> 8 & 0xff; + b4 = word & 0xff; + + if ((b1 < b2 && b1 != 0) || + (b2 < b3 && b2 != 0) || + (b3 < b4 && b3 != 0)) { + ml_printf("Error %d, %d, %d, %d", b1, b2, b3, b4); + return 2; + } else { + pdot(i); + } + } + ml_printf("done\n"); + return 0; +} + +static int read_test_data_u64(int offset) +{ + uint64_t word, *ptr = (uint64_t *)&test_data[offset]; + int i; + const int max = (TEST_SIZE - offset) / sizeof(word); + + ml_printf("Reading u64 from %#lx (offset %d):", ptr, offset); + + for (i = 0; i < max; i++) { + uint8_t b1, b2, b3, b4, b5, b6, b7, b8; + word = *ptr++; + + b1 = ((uint64_t) (word >> 56)) & 0xff; + b2 = ((uint64_t) (word >> 48)) & 0xff; + b3 = ((uint64_t) (word >> 40)) & 0xff; + b4 = (word >> 32) & 0xff; + b5 = (word >> 24) & 0xff; + b6 = (word >> 16) & 0xff; + b7 = (word >> 8) & 0xff; + b8 = (word >> 0) & 0xff; + + if ((b1 < b2 && b1 != 0) || + (b2 < b3 && b2 != 0) || + (b3 < b4 && b3 != 0) || + (b4 < b5 && b4 != 0) || + (b5 < b6 && b5 != 0) || + (b6 < b7 && b6 != 0) || + (b7 < b8 && b7 != 0)) { + ml_printf("Error %d, %d, %d, %d, %d, %d, %d, %d", + b1, b2, b3, b4, b5, b6, b7, b8); + return 2; + } else { + pdot(i); + } + } + ml_printf("done\n"); + return 0; +} + +/* Read the test data and verify at various offsets */ +int do_reads(void) +{ + int r = 0; + int off = 0; + + while (r == 0 && off < 8) { + r = read_test_data_u16(off); + r |= read_test_data_u32(off); + r |= read_test_data_u64(off); + off++; + } + + return r; +} + +int main(void) +{ + int i, r = 0; + + + init_test_data_u8(); + r = do_reads(); + if (r) { + return r; + } + + for (i = 0; i < 8; i++) { + init_test_data_u16(i); + + r = do_reads(); + if (r) { + return r; + } + } + + for (i = 0; i < 8; i++) { + init_test_data_u32(i); + + r = do_reads(); + if (r) { + return r; + } + } + + ml_printf("Test complete: %s\n", r == 0 ? "PASSED" : "FAILED"); + return r; +}