From patchwork Tue Nov 6 22:21:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 993962 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42qPXy58HSz9sC7 for ; Wed, 7 Nov 2018 09:36:34 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 65273C22772; Tue, 6 Nov 2018 22:31:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 94E5DC2273A; Tue, 6 Nov 2018 22:26:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 854C4C22560; Tue, 6 Nov 2018 22:23:01 +0000 (UTC) Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by lists.denx.de (Postfix) with ESMTPS id E3C61C221D2 for ; Tue, 6 Nov 2018 22:22:56 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id f8-v6so11028461ybn.22 for ; Tue, 06 Nov 2018 14:22:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Jq9yeYccVeaRBVvK5qqMZc4Pmu2E1aaQ+rX4VY/gPz0=; b=QpvcQr9yLqsmS3rFuv3KzZi/5Hw/DvDobMeE8R9w0ki3fJsfmwZFJyR7KYanaS0qOS pvX5LY0zJAu7R9dZb/zigVqDhCU8O8drSnld9Df/cP5/6QpDnEEOV6R0fxx8LkguNXmf Ey+yKEx2tSIxXdxVzBkNtk6xR7ge+74qNkdYiY+1xUUFzLYWQFqT1ZqZP/HhLpdcXg2o Arf8oyy5ZxEDdqm27cvLGDB5H9bPD8oQPFTlxrpnQwcUKWHNjcwjbpDzcdPIVfy9k1G1 hs1ysgkSfYcps1HbQ22Nu76NXxWX45vWN2Szuet0o15QKwWYANBUosoUu00qAZJHJ4zX Lj1w== X-Gm-Message-State: AGRZ1gJPCN0nCgZnj/2+WuBWMc/GNNuhb/tMEkTxUOUlX/xuStAxfVLu yQYXrA0jFuo3TJNbgGEn+FMOoqw= X-Google-Smtp-Source: AJdET5cAUuejii37dWOSaH8I3YkglZTDC8Lk8gEc3+HdRoBS9ntkjbhW1U72DYEyKDOLInqbM53SOVM= X-Received: by 2002:a81:9a11:: with SMTP id r17-v6mr3395373ywg.16.1541542975832; Tue, 06 Nov 2018 14:22:55 -0800 (PST) Date: Tue, 6 Nov 2018 15:21:40 -0700 In-Reply-To: <20181106222142.94537-1-sjg@chromium.org> Message-Id: <20181106222142.94537-24-sjg@chromium.org> Mime-Version: 1.0 References: <20181106222142.94537-1-sjg@chromium.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog From: Simon Glass To: U-Boot Mailing List Cc: Mike Frysinger Subject: [U-Boot] [PATCH 23/25] test: sf: Add a simple SPI flash test X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The current test is a functional test, covering all the way from the command line to the sandbox SPI driver. This is useful, but it is easier to diagnose failures with a smaller test. Add a simple test which reads and writes data and checks that it is stored and retrieved correctly. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- test/dm/sf.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/test/dm/sf.c b/test/dm/sf.c index 35241b9f574..b23e7f8edd4 100644 --- a/test/dm/sf.c +++ b/test/dm/sf.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -13,8 +15,48 @@ #include #include -/* Test that sandbox SPI flash works correctly */ +/* Simple test of sandbox SPI flash */ static int dm_test_spi_flash(struct unit_test_state *uts) +{ + struct udevice *dev, *emul; + int full_size = 0x200000; + int size = 0x10000; + u8 *src, *dst; + int i; + + src = map_sysmem(0x20000, full_size); + ut_assertok(os_write_file("spi.bin", src, full_size)); + ut_assertok(uclass_first_device_err(UCLASS_SPI_FLASH, &dev)); + + dst = map_sysmem(0x20000 + full_size, full_size); + ut_assertok(spi_flash_read_dm(dev, 0, size, dst)); + ut_assertok(memcmp(src, dst, size)); + + /* Erase */ + ut_assertok(spi_flash_erase_dm(dev, 0, size)); + ut_assertok(spi_flash_read_dm(dev, 0, size, dst)); + for (i = 0; i < size; i++) + ut_asserteq(dst[i], 0xff); + + /* Write some new data */ + for (i = 0; i < size; i++) + src[i] = i; + ut_assertok(spi_flash_write_dm(dev, 0, size, src)); + ut_assertok(spi_flash_read_dm(dev, 0, size, dst)); + ut_assertok(memcmp(src, dst, size)); + + /* + * Since we are about to destroy all devices, we must tell sandbox + * to forget the emulation device + */ + sandbox_sf_unbind_emul(state_get_current(), 0, 0); + + return 0; +} +DM_TEST(dm_test_spi_flash, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Functional test that sandbox SPI flash works correctly */ +static int dm_test_spi_flash_func(struct unit_test_state *uts) { /* * Create an empty test file and run the SPI flash tests. This is a @@ -39,4 +81,4 @@ static int dm_test_spi_flash(struct unit_test_state *uts) return 0; } -DM_TEST(dm_test_spi_flash, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); +DM_TEST(dm_test_spi_flash_func, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);