From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 81DC7EB64DC for ; Thu, 20 Jul 2023 14:50:51 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DD22586806; Thu, 20 Jul 2023 16:50:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="bkJWryrW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4DC78867E8; Thu, 20 Jul 2023 16:50:20 +0200 (CEST) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A2AD0867EA for ; Thu, 20 Jul 2023 16:50:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=detlev.casanova@collabora.com Received: from arisu.mtl.collabora.ca (mtl.collabora.ca [66.171.169.34]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: detlev) by madras.collabora.co.uk (Postfix) with ESMTPSA id 9CB4E660708B; Thu, 20 Jul 2023 15:50:16 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1689864617; bh=nC9jXag5xCXpokuv/mIt+hGuhce8BXy5RAshtlcI++E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bkJWryrWVBGywsw+II/gQmKfVqBfzndwyzbcSPYkN2El+ub3E55z8I7eYrCyFn9tr tV7UTVTJlo6s1B1s5Eshqi+ijx8P5cu6l3qEtQWhB2/3qt+F8PKJgir2xnJwCE9S7L imWgY7UiKus76SxRh8KpDFMXQMwFqGy0A438aQSPzh6IGXHBvoh5kj0v7Fvjz2etc2 MM2QR6raPfKpuo9DSKrVuXAOU3wbkGJfPPKM1yJyjkpqNnhyNkQbMxZW6Rxhv1eW3T S0TxTEuteafriMHs0pWR9hHOe1Qku36jU14SDlrk1fq9RxncEuX8DvZlmVQhreHCKu NTCWRjinRy+mw== From: Detlev Casanova To: u-boot@lists.denx.de Cc: Marek Vasut , Hai Pham , Tam Nguyen , Simon Glass , Detlev Casanova Subject: [PATCH v4 3/6] sysinfo: Add a test Date: Thu, 20 Jul 2023 10:49:44 -0400 Message-ID: <20230720145010.84791-4-detlev.casanova@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720145010.84791-1-detlev.casanova@collabora.com> References: <20230720145010.84791-1-detlev.casanova@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The test runs one of each subcommand and checks that the output matches the values in the sandbox sysinfo driver. Reviewed-by: Marek Vasut Signed-off-by: Detlev Casanova --- configs/sandbox_defconfig | 1 + drivers/sysinfo/sandbox.c | 17 +++++++++++++ test/cmd/Makefile | 1 + test/cmd/test_sysinfo.c | 51 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 test/cmd/test_sysinfo.c diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 19cc6701e62..a51762aa3ae 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -130,6 +130,7 @@ CONFIG_CMD_EROFS=y CONFIG_CMD_EXT4_WRITE=y CONFIG_CMD_SQUASHFS=y CONFIG_CMD_MTDPARTS=y +CONFIG_CMD_SYSINFO=y CONFIG_CMD_STACKPROTECTOR_TEST=y CONFIG_MAC_PARTITION=y CONFIG_AMIGA_PARTITION=y diff --git a/drivers/sysinfo/sandbox.c b/drivers/sysinfo/sandbox.c index d270a26aa43..cc7783907a9 100644 --- a/drivers/sysinfo/sandbox.c +++ b/drivers/sysinfo/sandbox.c @@ -7,9 +7,14 @@ #include #include #include +#include #include "sandbox.h" +#define SANDBOX_BOARD_ID 0x42 +#define SANDBOX_BOARD_REV_MAJOR U_BOOT_VERSION_NUM +#define SANDBOX_BOARD_REV_MINOR U_BOOT_VERSION_NUM_PATCH + struct sysinfo_sandbox_priv { bool called_detect; int test_i1; @@ -48,6 +53,15 @@ int sysinfo_sandbox_get_int(struct udevice *dev, int id, int *val) struct sysinfo_sandbox_priv *priv = dev_get_priv(dev); switch (id) { + case SYSINFO_ID_BOARD_ID: + *val = SANDBOX_BOARD_ID; + return 0; + case SYSINFO_ID_BOARD_REV_MAJOR: + *val = SANDBOX_BOARD_REV_MAJOR; + return 0; + case SYSINFO_ID_BOARD_REV_MINOR: + *val = SANDBOX_BOARD_REV_MINOR; + return 0; case INT_TEST1: *val = priv->test_i1; /* Increments with every call */ @@ -71,6 +85,9 @@ int sysinfo_sandbox_get_str(struct udevice *dev, int id, size_t size, char *val) int index = (i1 * i2) % ARRAY_SIZE(vacation_spots); switch (id) { + case SYSINFO_ID_BOARD_MODEL: + snprintf(val, size, "sandbox"); + return 0; case STR_VACATIONSPOT: /* Picks a vacation spot depending on i1 and i2 */ snprintf(val, size, vacation_spots[index]); diff --git a/test/cmd/Makefile b/test/cmd/Makefile index a3cf983739e..d3ac5bf2d5e 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_CMD_SEAMA) += seama.o ifdef CONFIG_SANDBOX obj-$(CONFIG_CMD_READ) += rw.o obj-$(CONFIG_CMD_SETEXPR) += setexpr.o +obj-$(CONFIG_CMD_SYSINFO) += test_sysinfo.o endif obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o obj-$(CONFIG_CMD_WGET) += wget.o diff --git a/test/cmd/test_sysinfo.c b/test/cmd/test_sysinfo.c new file mode 100644 index 00000000000..7ba6dd0df89 --- /dev/null +++ b/test/cmd/test_sysinfo.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for sysinfo command + * + * Copyright 2023, Detlev Casanova + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +#define REV_(x, y) #x "." #y +#define REV(x, y) REV_(x, y) + +struct test_data { + char *cmd; + char *expected; +}; + +static struct test_data sysinfo_data[] = { + {"sysinfo model", "sandbox"}, + {"sysinfo id", "0x42"}, + {"sysinfo revision", REV(U_BOOT_VERSION_NUM, U_BOOT_VERSION_NUM_PATCH)}, +}; + +static int lib_test_sysinfo(struct unit_test_state *uts) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(sysinfo_data); ++i) { + ut_silence_console(uts); + console_record_reset_enable(); + ut_assertok(run_command(sysinfo_data[i].cmd, 0)); + ut_unsilence_console(uts); + console_record_readline(uts->actual_str, + sizeof(uts->actual_str)); + ut_asserteq_str(sysinfo_data[i].expected, uts->actual_str); + ut_assertok(ut_check_console_end(uts)); + } + + return 0; +} + +LIB_TEST(lib_test_sysinfo, 0); -- 2.41.0