From patchwork Sun Mar 19 18:59:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 740734 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3vmT521h5Sz9s3l for ; Mon, 20 Mar 2017 06:03:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="fSCfOOL9"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id E1793C21C5E; Sun, 19 Mar 2017 19:02:37 +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_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID 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 57376C21C86; Sun, 19 Mar 2017 19:00:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 94423C21C3F; Sun, 19 Mar 2017 19:00:14 +0000 (UTC) Received: from mail-ot0-f178.google.com (mail-ot0-f178.google.com [74.125.82.178]) by lists.denx.de (Postfix) with ESMTPS id 4C800C21C79 for ; Sun, 19 Mar 2017 19:00:09 +0000 (UTC) Received: by mail-ot0-f178.google.com with SMTP id i1so121335010ota.3 for ; Sun, 19 Mar 2017 12:00:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=G1WYzoGqpXcSL4lcjqP7lOP18R5QqaSvUvdjGkkXmas=; b=fSCfOOL9mgsCLoMFgDMolCBkr/nToCTE7SMJ+KCEcdy50mdO/pTZm6DBkfYBpAF/ee oDoQnZIGulPIQGK0j/LLUEVLj9tcOWKYnkBNeM7H+Ia2DdrC09ggHKeAbCYW62jVMtfs bH6grYAvlaK/oVRMqm7utr48597UeoFXtD4Szes+NNM9tv3sHwezJ/99SG6vxINTUAtW sd/LCWEX8eCbn/U1yXCQUGshYeEm50+0180QXX7Pv5Q/ry6W8nAKiqgfUd3VVi+it0KP s36IHdMvmRwvCcttu2Dh4navCdgV6oy6KwdskCG0XS1L+pxE6dGmXm2CKJYzzbFgj6y1 VEmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=G1WYzoGqpXcSL4lcjqP7lOP18R5QqaSvUvdjGkkXmas=; b=YW9r39sgThJPqDRv9AeeAM97FJi2fNzk9z5lLn1w3O9pbcizAQbDfFKUiUXZa/aS31 XG7D3VB8EqNdRM4zM/98bjB0VWBnBDZ+Zp50I4v9kSNU5dJgC/V+IDlxwKb9KeZH21aJ kpheEfBqbUVgqO9boHdujL0oKTmO452nLxV9VupM+1XHYlb4QhldAh6tjW/7Jv6CN4H4 +csL9LEXMQELuqmNDL73ez77a11B+Y6q1Mjxr3g3KJJmYKa7A7XdphwpUB1n0b0HDMDx 5VPiE7Ix6WlESKjUyWyHqhd32WX/CqwDqoPnjMEhCR1lxHunNe9jyXp/KHuH4RXx4CSz rAQQ== X-Gm-Message-State: AFeK/H0NopEdQoszrdhoLeXNVxI6jGfUXdCoLKjyAOcmNg4Nbb6rqSwkYjcS2smtOkOmenyA X-Received: by 10.157.7.50 with SMTP id 47mr12816724ote.17.1489950007931; Sun, 19 Mar 2017 12:00:07 -0700 (PDT) Received: from kaki.bld.corp.google.com ([2620:0:1005:11:4b6:487f:844b:c8b6]) by smtp.gmail.com with ESMTPSA id r8sm1746111oia.13.2017.03.19.12.00.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Mar 2017 12:00:07 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id ACDB940083; Sun, 19 Mar 2017 13:00:06 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Sun, 19 Mar 2017 12:59:28 -0600 Message-Id: <20170319185935.20950-10-sjg@chromium.org> X-Mailer: git-send-email 2.12.0.367.g23dc2f6d3c-goog In-Reply-To: <20170319185935.20950-1-sjg@chromium.org> References: <20170319185935.20950-1-sjg@chromium.org> Cc: Tom Rini , Stefan Roese , Stephen Warren , Tom Warren Subject: [U-Boot] [PATCH 09/16] dm: board: Add tests for the board uclass 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add some tests which define some devices and check the operation of the various init functions. Signed-off-by: Simon Glass --- arch/sandbox/dts/test.dts | 12 +++++++ arch/sandbox/include/asm/state.h | 3 ++ arch/sandbox/include/asm/test.h | 9 +++++ drivers/misc/Makefile | 1 + drivers/misc/board_sandbox.c | 44 ++++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/board.c | 74 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 144 insertions(+) create mode 100644 drivers/misc/board_sandbox.c create mode 100644 test/dm/board.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index fff175d1b7..084c3dff63 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -52,6 +52,18 @@ reg = <2 1>; }; + board-test0 { + compatible = "sandbox,board-test0"; + }; + + board-test1 { + compatible = "sandbox,board-test1"; + }; + + board-test2 { + compatible = "sandbox,board-test2"; + }; + b-test { reg = <3 1>; compatible = "denx,u-boot-fdt-test"; diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index 149f28d873..d531531d72 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -9,6 +9,7 @@ #include #include #include +#include #include /** @@ -65,6 +66,8 @@ struct sandbox_state { enum state_terminal_raw term_raw; /* Terminal raw/cooked */ bool skip_delays; /* Ignore any time delays (for test) */ bool show_test_output; /* Don't suppress stdout in tests */ + /* Return values for board_sandbox */ + int board_sandbox_ret[BOARD_TEST_COUNT]; /* Pointer to information for each SPI bus/cs */ struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS] diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 451a78e590..12b3b9bc1e 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -79,4 +79,13 @@ long sandbox_i2c_rtc_get_set_base_time(struct udevice *dev, long base_time); int sandbox_usb_keyb_add_string(struct udevice *dev, const char *str); +/* For testing the BOARD uclass */ +enum { + BOARD_TEST0, + BOARD_TEST1, + BOARD_TEST2, + + BOARD_TEST_COUNT, +}; + #endif diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index e3151ea097..88015cc8af 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_MISC) += misc-uclass.o obj-$(CONFIG_ALI152X) += ali512x.o obj-$(CONFIG_ALTERA_SYSID) += altera_sysid.o +obj-$(CONFIG_SANDBOX) += board_sandbox.o obj-$(CONFIG_DS4510) += ds4510.o obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o ifndef CONFIG_SPL_BUILD diff --git a/drivers/misc/board_sandbox.c b/drivers/misc/board_sandbox.c new file mode 100644 index 0000000000..9ccdbfbbe8 --- /dev/null +++ b/drivers/misc/board_sandbox.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include + +static int board_sandbox_phase(struct udevice *dev, enum board_phase_t phase) +{ + struct sandbox_state *state = state_get_current(); + int id = dev_get_driver_data(dev); + + return state->board_sandbox_ret[id]; +} + +static int board_sandbox_probe(struct udevice *dev) +{ + return board_support_phase(dev, BOARD_PHASE_TEST); +} + +static const struct board_ops board_sandbox_ops = { + .phase = board_sandbox_phase, +}; + + +static const struct udevice_id board_sandbox_ids[] = { + { .compatible = "sandbox,board-test0", BOARD_TEST0 }, + { .compatible = "sandbox,board-test1", BOARD_TEST1 }, + { .compatible = "sandbox,board-test2", BOARD_TEST2 }, + { } +}; + +U_BOOT_DRIVER(board_sandbox_drv) = { + .name = "board_sandbox", + .id = UCLASS_BOARD, + .ops = &board_sandbox_ops, + .of_match = board_sandbox_ids, + .probe = board_sandbox_probe, +}; diff --git a/test/dm/Makefile b/test/dm/Makefile index 1885e17c38..c84a966708 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o # subsystem you must add sandbox tests here. obj-$(CONFIG_UT_DM) += core.o ifneq ($(CONFIG_SANDBOX),) +obj-$(CONFIG_BOARD) += board.o obj-$(CONFIG_BLK) += blk.o obj-$(CONFIG_CLK) += clk.o obj-$(CONFIG_DM_ETH) += eth.o diff --git a/test/dm/board.c b/test/dm/board.c new file mode 100644 index 0000000000..986746632b --- /dev/null +++ b/test/dm/board.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2015 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/* Test invoking a board phase with three active devices */ +static int dm_test_board(struct unit_test_state *uts) +{ + struct sandbox_state *state = state_get_current(); + + /* We should start with a count of 0 for our test phase */ + ut_asserteq(0, gd->phase_count[BOARD_PHASE_TEST]); + + /* Check that we can detect there being no driver */ + ut_asserteq(-ENOSYS, board_walk_phase_count(BOARD_PHASE_INVALID, + false)); + ut_asserteq(0, board_walk_opt_phase(BOARD_PHASE_INVALID)); + ut_asserteq(-ENOSYS, board_walk_phase(BOARD_PHASE_INVALID)); + + /* If no devices respond, we should get no action */ + state->board_sandbox_ret[BOARD_TEST0] = -ENOSYS; + state->board_sandbox_ret[BOARD_TEST1] = -ENOSYS; + state->board_sandbox_ret[BOARD_TEST2] = -ENOSYS; + ut_asserteq(-ENOSYS, board_walk_phase_count(BOARD_PHASE_TEST, false)); + ut_asserteq(0, board_walk_opt_phase(BOARD_PHASE_TEST)); + ut_asserteq(0, gd->phase_count[BOARD_PHASE_TEST]); + + /* Enable the first device */ + state->board_sandbox_ret[BOARD_TEST0] = 0; + ut_asserteq(1, board_walk_phase_count(BOARD_PHASE_TEST, false)); + ut_asserteq(1, gd->phase_count[BOARD_PHASE_TEST]); + + /* Enable the second device too */ + state->board_sandbox_ret[BOARD_TEST1] = 0; + ut_asserteq(2, board_walk_phase_count(BOARD_PHASE_TEST, false)); + ut_asserteq(3, gd->phase_count[BOARD_PHASE_TEST]); + + /* Enable all three devices */ + state->board_sandbox_ret[BOARD_TEST2] = 0; + ut_asserteq(3, board_walk_phase_count(BOARD_PHASE_TEST, false)); + ut_asserteq(6, gd->phase_count[BOARD_PHASE_TEST]); + + /* + * Check that the first device can claim the phase and lock out the + * other devices. + */ + state->board_sandbox_ret[BOARD_TEST0] = BOARD_PHASE_CLAIMED; + ut_asserteq(1, board_walk_phase_count(BOARD_PHASE_TEST, false)); + ut_asserteq(0, board_walk_phase(BOARD_PHASE_TEST)); + ut_asserteq(0, board_walk_opt_phase(BOARD_PHASE_TEST)); + ut_asserteq(9, gd->phase_count[BOARD_PHASE_TEST]); + + /* Any error should be reported, but previous devices should still get + * to process the phase. + */ + state->board_sandbox_ret[BOARD_TEST0] = 0; + state->board_sandbox_ret[BOARD_TEST1] = -ENOENT; + ut_asserteq(-ENOENT, board_walk_phase_count(BOARD_PHASE_TEST, false)); + ut_asserteq(-ENOENT, board_walk_phase(BOARD_PHASE_TEST)); + ut_asserteq(-ENOENT, board_walk_opt_phase(BOARD_PHASE_TEST)); + ut_asserteq(12, gd->phase_count[BOARD_PHASE_TEST]); + + return 0; +} +DM_TEST(dm_test_board, DM_TESTF_SCAN_FDT);