From patchwork Tue Mar 12 17:09:28 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: 160137 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp13200508oce; Tue, 12 Mar 2019 10:21:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFft7eLnN8js6Kfn77/xY8G9P4ZZe17gR3037RV5bwIJfnYyOUuSCZKcoDM558dU9ycEB8 X-Received: by 2002:a25:2a8d:: with SMTP id q135mr34437003ybq.394.1552411272473; Tue, 12 Mar 2019 10:21:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552411272; cv=none; d=google.com; s=arc-20160816; b=OG4r+nv1iWklwvpSdoveLkhDLl8WGlanj7o24xfReL24RVoB5eo6282Fdzkfo961Fx Sx8Jl0o1RqLg1A2CMNE32wyuRTYoIb+3ZN6h+K5+CsjDCMZcRdf+DCpjqXP6xgh5fJYo 3OiaaatimX0h8Mo39i9nYMgK1qSBNAGs4Akn76vKliDfxE0GI2qn0T5a0jMny3hAx3+g 9h6r9MhBqEpof2jpm6DyER7yld2/scSqPbaujtGSxaGyC7B/iFFM9a1LspNaENrnpaBD ylxaTqEqMErtDEz9zY/NgS+0PhS9AUPlPdDdZvZpamMt88dDWLVUF40aMjG8Oq2/x469 cGWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=zQT+b4hrk1dfCTcbQ1yXe96TEFFzqf+SERHmGueS/P4=; b=XkZGB0GRkXC0c38xRmMViP1qDv2DWEKN1FBlC3Y1HvJ2hwTo4wEOxeUo1b1ZduiVty h/i/6f7+9aOB6VB2v9cLSsCx5e7xIK4nJcuS1Wah1aE/eCvjpwtPjakslQ6uBzNr7p8e q/Efhz8gu1HlXNzklCcp02UVfPyAT0xHkgbCxwd5knz83R5C9rllSFuiXURiB1+MxauG zZj9/D+PSBa4ivSYqsBzXbaMY+SFoNfCdCBglBR9gzWGf4DgrmdbTFROYlAAzXh5hUPV Hos0db8AgogyfdaH8sCL+Y1H/7VlK/4dQ9LG637YmJztu4E+lBKVK0fAt5UQ7bUbsd7P jC+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RnT+In0I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i12si5147764ybp.85.2019.03.12.10.21.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Mar 2019 10:21:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RnT+In0I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3l5T-0007G1-TV for patch@linaro.org; Tue, 12 Mar 2019 13:21:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3l2g-0005Wi-1a for qemu-devel@nongnu.org; Tue, 12 Mar 2019 13:18:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3kzo-0003wT-A9 for qemu-devel@nongnu.org; Tue, 12 Mar 2019 13:15:22 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:36120) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3kzn-0003uR-Qk for qemu-devel@nongnu.org; Tue, 12 Mar 2019 13:15:20 -0400 Received: by mail-wm1-x342.google.com with SMTP id e16so3373505wme.1 for ; Tue, 12 Mar 2019 10:15:19 -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=zQT+b4hrk1dfCTcbQ1yXe96TEFFzqf+SERHmGueS/P4=; b=RnT+In0IonNv7+3B5H/sO1x5a/XGYqHiyvIIqCLa23Pzn8bbAuCk3a205r0RLkqsLm yh1pBGmuzRN+12k2PROyZ2fm6IxeK3UEu8UCB3oOVhyWvYRzdQpsAUBsOqiOaOcL8Fb1 ldKew5e9y5zb09nax3KugPGpAvpKAse6RR9UY9BMytPfQfWZ3A7TS4KjeaFopWyptwlK oCUfk9M+fbOC66IjhYP0BCHpVpXMVD2+WiDT3zSQvcIYz7KT2YJfCD5eW5/pg15fXcFc /89bGoFNj9/d6srb71QZ5yTNexdQDLkLNCBeWHOA9QRKXk0MbcX5DSsoTvTXIjFGEDnr TEjg== 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=zQT+b4hrk1dfCTcbQ1yXe96TEFFzqf+SERHmGueS/P4=; b=Rzq2Fn7rC3LZqDQ57DCriHvlqH/3hwla4+LyHJcmg3HKEHDnnIa0aHrW8jKj7+N+MP Qe06tK4Y8oW2iS5+QO49qY9JHLjxxSILY/cyZ8ZLTJ1WEoJ8kjBaj4tUJQcqarEq/xvp q1TKKngo5ckR7eDjTgEBOcjOMwbQPlGvhaH4AFvVUP4U/9/N8KxHWcBMnUZu3jZx6KC2 EWLU2mL26yaZwMrduMIBi62ENXZRE1XB98nFZVOzNu7pFwY7vZ3itifDa+S3CbhYIOxj R/ILeL1n9qlxJPa9kQDlfMsZU7pNM6/5KC1Uy2Uv0t/tCJXpq865vZ4WXca6OGEBaFAk cSgw== X-Gm-Message-State: APjAAAUE2lx33dUSU1N8d1aNE6l+avFUtz1fP0gcMXWsxXdF6/lNw8qD KyJjPmeA9pZPZpcyCcoTcLiSOA== X-Received: by 2002:a1c:9ed5:: with SMTP id h204mr3213188wme.140.1552410918414; Tue, 12 Mar 2019 10:15:18 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o30sm14034167wro.57.2019.03.12.10.15.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Mar 2019 10:15:13 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 81EA11FFA9; Tue, 12 Mar 2019 17:09:32 +0000 (UTC) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Tue, 12 Mar 2019 17:09:28 +0000 Message-Id: <20190312170931.25013-24-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190312170931.25013-1-alex.bennee@linaro.org> References: <20190312170931.25013-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::342 Subject: [Qemu-devel] [PULL 23/26] 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: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is a simple test to check various access patterns to memory including unaligned access. Signed-off-by: Alex Bennée -- 2.20.1 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; +}