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 48523C6FD1D for ; Sun, 2 Apr 2023 02:42:14 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7C5FB85ED8; Sun, 2 Apr 2023 04:41:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Eb6Nf/2A"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4365585F06; Sun, 2 Apr 2023 04:41:17 +0200 (CEST) Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 771F385E71 for ; Sun, 2 Apr 2023 04:40:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-ed1-x536.google.com with SMTP id b20so104569112edd.1 for ; Sat, 01 Apr 2023 19:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1680403257; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JiwHuOUi7/hbihtntREoBhcGFF2k5IC3Q+GNwUXPDK4=; b=Eb6Nf/2AlaqOXriiZhDkpMkG7t6mvrpo9fcOgA4w4111qC6FBukmbCKN5bzJrV+7F/ 0cvAcK3ym2pSpOw2Lw+GRzjyBay2toLWum7VSJ5Oyw5XMgxcDxXacwU3fGEDb3mngJke jBmh2/YCt3drHQuPgyGsJVWIXnkyWu7sDmkcM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680403257; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JiwHuOUi7/hbihtntREoBhcGFF2k5IC3Q+GNwUXPDK4=; b=bZd1gqKCb+t+RtragWfW0BS0O3k4zZtAtdYOLH0RqOX4xW6rr83kgiiV75UJlncF5e fzX2GtiaL0dP0cws+W6G8L1fmsv6wiDCUCRkzK2mK6CwyUyCB9g338kkk4PlgH9QlefA wt8TmgYS10dstQDoKjbawYxDIV8dR+Ra5p6iZDnE6YkhXHu55vgYRN748IvgIp4/uiia 6ku8tvAs6MM+p+Fpkol6AHKEe52F1uTdB/b5CnTfTE/Ap6jqFNn/VqGqFEi34vp8d/0T ovz2Prn94I3FeUkRv41FIL7PcgAl5AGjzDeKvHjBWJevQCYbyzIqfEGQwOYCzgIGwi32 6tLQ== X-Gm-Message-State: AAQBX9eoRTcASgbbWX27EB3CopktibrEe1JqVqG4HC8gfUBDdZSQxtiZ hqoKrc7Vhq12c6rvXMpU4tdZd45e+Jb3iNO4ywG3mg== X-Google-Smtp-Source: AKy350YQR8UefSO4Z67O7pP7RTGWH9dr6Z2JmWcFnLIrxJ1y3PfNT2SJXUWMvI82uSFGGMj8FiJgOfKh9ylgIM20e2o= X-Received: by 2002:a17:906:b884:b0:932:a33a:3754 with SMTP id hb4-20020a170906b88400b00932a33a3754mr15724064ejb.14.1680403256707; Sat, 01 Apr 2023 19:40:56 -0700 (PDT) MIME-Version: 1.0 References: <20230328161157.219375-1-abdellatif.elkhlifi@arm.com> <20230328161157.219375-8-abdellatif.elkhlifi@arm.com> In-Reply-To: <20230328161157.219375-8-abdellatif.elkhlifi@arm.com> From: Simon Glass Date: Sun, 2 Apr 2023 14:40:44 +1200 Message-ID: Subject: Re: [PATCH v10 07/10] arm_ffa: introduce sandbox test cases for UCLASS_FFA To: Abdellatif El Khlifi Cc: Drew.Reed@arm.com, achin.gupta@arm.com, Ilias Apalodimas , Jens Wiklander , nd , Rob Herring , Sudeep Holla , Tom Rini , U-Boot Mailing List , Xueliang Zhong , Heinrich Schuchardt Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.39 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 Hi Abdellatif, On Wed, 29 Mar 2023 at 05:12, Abdellatif El Khlifi < abdellatif.elkhlifi@arm.com> wrote: > > Add functional test cases for the FF-A support > > These tests rely on the FF-A sandbox emulator and FF-A > sandbox driver which help in inspecting the FF-A communication. > > Signed-off-by: Abdellatif El Khlifi > Cc: Tom Rini > Cc: Simon Glass > Cc: Ilias Apalodimas > Cc: Jens Wiklander > Cc: Heinrich Schuchardt > > --- > Changelog: > =============== > > v10: > > * use the FF-A driver Uclass operations > * use uclass_first_device() > * replace CONFIG_SANDBOX_FFA with CONFIG_ARM_FFA_TRANSPORT > * address nits > > v9: align FF-A sandbox tests with FF-A discovery through DM > > v8: > > * update partition_info_get() second argument to be an SP count > * pass NULL device pointer to the FF-A bus discovery and operations > > v7: set the tests to use 64-bit direct messaging > > v4: align sandbox tests with the new FF-A driver interfaces > and new way of error handling > > v1: introduce sandbox tests > > MAINTAINERS | 1 + > doc/arch/arm64.ffa.rst | 1 + > test/dm/Makefile | 2 + > test/dm/ffa.c | 357 +++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 361 insertions(+) > create mode 100644 test/dm/ffa.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index b8019517ba..8f698b3f20 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -276,6 +276,7 @@ F: doc/arch/arm64.ffa.rst > F: doc/usage/cmd/armffa.rst > F: drivers/firmware/arm-ffa/ > F: include/arm_ffa.h > +F: test/dm/ffa.c > > ARM FREESCALE IMX > M: Stefano Babic > diff --git a/doc/arch/arm64.ffa.rst b/doc/arch/arm64.ffa.rst > index 457a0e112e..5b1450f579 100644 > --- a/doc/arch/arm64.ffa.rst > +++ b/doc/arch/arm64.ffa.rst > @@ -38,6 +38,7 @@ The U-Boot FF-A support provides the following parts: > FF-A ABIs inspection methods. > - An FF-A sandbox device driver for FF-A communication with the emulated Secure World. > The driver leverages the FF-A Uclass to establish FF-A communication. > +- Sandbox FF-A test cases. > > FF-A and SMC specifications > ------------------------------------------- > diff --git a/test/dm/Makefile b/test/dm/Makefile > index 7a79b6e1a2..45563bdfb4 100644 > --- a/test/dm/Makefile > +++ b/test/dm/Makefile > @@ -1,6 +1,7 @@ > # SPDX-License-Identifier: GPL-2.0+ > # > # Copyright (c) 2013 Google, Inc > +# Copyright 2022-2023 Arm Limited and/or its affiliates < open-source-office@arm.com> > > obj-$(CONFIG_UT_DM) += test-dm.o > > @@ -85,6 +86,7 @@ obj-$(CONFIG_POWER_DOMAIN) += power-domain.o > obj-$(CONFIG_ACPI_PMC) += pmc.o > obj-$(CONFIG_DM_PMIC) += pmic.o > obj-$(CONFIG_DM_PWM) += pwm.o > +obj-$(CONFIG_ARM_FFA_TRANSPORT) += ffa.o > obj-$(CONFIG_QFW) += qfw.o > obj-$(CONFIG_RAM) += ram.o > obj-y += regmap.o > diff --git a/test/dm/ffa.c b/test/dm/ffa.c > new file mode 100644 > index 0000000000..d493597521 > --- /dev/null > +++ b/test/dm/ffa.c > @@ -0,0 +1,357 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Functional tests for UCLASS_FFA class > + * > + * Copyright 2022-2023 Arm Limited and/or its affiliates < open-source-office@arm.com> > + * > + * Authors: > + * Abdellatif El Khlifi > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* Macros */ > + > +#define LOG_MSG_SZ (100) > +#define LOG_CMD_SZ (LOG_MSG_SZ * 2) > + > +/* Functional tests for the UCLASS_FFA */ > + > +static int dm_test_ffa_log(struct unit_test_state *uts, char *msg) > +{ > + char cmd[LOG_CMD_SZ] = {0}; > + > + console_record_reset(); > + > + snprintf(cmd, LOG_CMD_SZ, "echo \"%s\"", msg); > + run_command(cmd, 0); > + > + ut_assert_console_end(); > + > + return 0; > +} > + > +static int check_fwk_version(struct ffa_priv *priv, struct unit_test_state *uts) > +{ > + struct ffa_sandbox_data func_data; > + u32 fwk_version = 0; > + > + func_data.data0 = &fwk_version; > + func_data.data0_size = sizeof(fwk_version); > + ut_assertok(sandbox_ffa_query_core_state(FFA_VERSION, &func_data)); > + > + if (priv->dscvry_info.fwk_version != fwk_version) { > + char msg[LOG_MSG_SZ] = {0}; > + > + snprintf(msg, LOG_MSG_SZ, > + "[%s]: Error: framework version: core = 0x%x , sandbox = 0x%x", __func__, > + priv->dscvry_info.fwk_version, > + fwk_version); > + > + dm_test_ffa_log(uts, msg); > + return CMD_RET_FAILURE; This is not a command. You should use ut_assert(false) here, perhaps? Please fix throughout. > + } > + return 0; > +} > + > +static int check_endpoint_id(struct ffa_priv *priv, struct unit_test_state *uts) > +{ > + if (priv->id) { > + char msg[LOG_MSG_SZ] = {0}; > + > + snprintf(msg, LOG_MSG_SZ, > + "[%s]: Error: endpoint id: core = 0x%x", __func__, priv->id); > + dm_test_ffa_log(uts, msg); > + return CMD_RET_FAILURE; > + } > + return 0; > +} > + > +static int check_rxtxbuf(struct ffa_priv *priv, struct unit_test_state *uts) > +{ > + if (!priv->pair.rxbuf || !priv->pair.txbuf) { > + char msg[LOG_MSG_SZ] = {0}; > + > + snprintf(msg, LOG_MSG_SZ, "[%s]: Error: rxbuf = %p txbuf = %p", __func__, > + priv->pair.rxbuf, > + priv->pair.txbuf); > + dm_test_ffa_log(uts, msg); > + return CMD_RET_FAILURE; > + } > + return 0; > +} > + > +static int check_features(struct ffa_priv *priv, struct unit_test_state *uts) > +{ > + char msg[LOG_MSG_SZ] = {0}; > + > + if (priv->pair.rxtx_min_pages != RXTX_4K && > + priv->pair.rxtx_min_pages != RXTX_16K && > + priv->pair.rxtx_min_pages != RXTX_64K) { > + snprintf(msg, > + LOG_MSG_SZ, > + "[%s]: Error: FFA_RXTX_MAP features = 0x%lx", > + __func__, > + priv->pair.rxtx_min_pages); > + dm_test_ffa_log(uts, msg); > + return CMD_RET_FAILURE; It's not clear to me why you are printing these messages? If should be enough to use ut_assert() as it shows you where the error happened, in a backtrace. Perhaps I am missing something? > + } > + > + return 0; > +} > + > +static int check_rxbuf_mapped_flag(u32 queried_func_id, > + u8 rxbuf_mapped, > + struct unit_test_state *uts) > +{ > + char msg[LOG_MSG_SZ] = {0}; > + > + switch (queried_func_id) { > + case FFA_RXTX_MAP: > + if (rxbuf_mapped) > + return 0; > + break; > + case FFA_RXTX_UNMAP: > + if (!rxbuf_mapped) > + return 0; > + break; > + default: > + return CMD_RET_FAILURE; > + } > + > + snprintf(msg, LOG_MSG_SZ, "[%s]: Error: %s mapping issue", __func__, > + (queried_func_id == FFA_RXTX_MAP ? "FFA_RXTX_MAP" : "FFA_RXTX_UNMAP")); > + dm_test_ffa_log(uts, msg); > + > + return CMD_RET_FAILURE; > +} > + > +static int check_rxbuf_release_flag(u8 rxbuf_owned, struct unit_test_state *uts) > +{ > + if (rxbuf_owned) { > + char msg[LOG_MSG_SZ]; > + > + snprintf(msg, LOG_MSG_SZ, "[%s]: Error: RX buffer not released", __func__); > + dm_test_ffa_log(uts, msg); > + return CMD_RET_FAILURE; > + } > + return 0; > +} > + > +static int test_ffa_msg_send_direct_req(u16 part_id, struct unit_test_state *uts) > +{ > + struct ffa_send_direct_data msg; > + u8 cnt; > + struct udevice *dev; > + > + uclass_first_device(UCLASS_FFA, &dev); > + ut_assertnonnull(dev); > + > + ut_assertok(ffa_sync_send_receive(dev, part_id, &msg, 1)); > + > + for (cnt = 0; cnt < sizeof(struct ffa_send_direct_data) / sizeof(u64); cnt++) > + ut_asserteq_64(-1UL, ((u64 *)&msg)[cnt]); > + > + return 0; > +} > + > +static int test_partitions_and_comms(const char *service_uuid, > + struct unit_test_state *uts) > +{ > + u32 count; > + struct ffa_partition_info *parts_info; > + u32 info_idx, exp_info_idx; > + int ret; > + struct udevice *dev; > + struct ffa_sandbox_data func_data; > + struct ffa_partitions *partitions; > + > + uclass_first_device(UCLASS_FFA, &dev); > + ut_assertnonnull(dev); ut_assertok(uclass_first_device_err(... > + > + /* Get from the driver the count of the SPs matching the UUID */ > + ret = ffa_partition_info_get(dev, service_uuid, &count, NULL); > + /* Make sure partitions are detected */ > + ut_assertok(ret); > + ut_asserteq(SANDBOX_SP_COUNT_PER_VALID_SERVICE, count); > + > + /* Pre-allocate a buffer to be filled by the driver with ffa_partition_info structs */ > + > + parts_info = calloc(count, sizeof(struct ffa_partition_info)); > + ut_assertnonnull(parts_info); Use a local var > + > + /* Ask the driver to fill the buffer with the SPs info */ > + ret = ffa_partition_info_get(dev, service_uuid, &count, parts_info); > + if (ret != 0) { > + free(parts_info); > + ut_assertok(ret); > + } > + > + /* SPs found , verify the partitions information */ > + > + func_data.data0 = &partitions; > + func_data.data0_size = sizeof(struct ffa_partitions *); > + ut_assertok(sandbox_ffa_query_core_state(FFA_PARTITION_INFO_GET, &func_data)); > + > + ret = CMD_RET_FAILURE; > + > + for (info_idx = 0; info_idx < count ; info_idx++) { > + for (exp_info_idx = 0; > + exp_info_idx < partitions->count; > + exp_info_idx++) { > + if (parts_info[info_idx].id == > + partitions->descs[exp_info_idx].info.id) { > + ret = memcmp(&parts_info[info_idx], > + &partitions->descs[exp_info_idx] > + .info, > + sizeof(struct ffa_partition_info)); ut_asserteq_mem(). Please take a look at the functions available. > + if (ret) > + free(parts_info); > + ut_assertok(ret); > + /* Send and receive data from the current partition */ > + test_ffa_msg_send_direct_req(parts_info[info_idx].id, uts); > + } > + ret = 0; > + } > + } > + > + free(parts_info); > + > + /* Verify expected partitions found in the emulated secure world */ > + ut_assertok(ret); > + > + return 0; > +} > + > +static int dm_test_ffa_ack(struct unit_test_state *uts) > +{ > + struct ffa_priv *priv; > + struct ffa_sandbox_data func_data; > + u8 rxbuf_flag = 0; > + const char *svc1_uuid = SANDBOX_SERVICE1_UUID; > + const char *svc2_uuid = SANDBOX_SERVICE2_UUID; > + int ret; > + struct udevice *dev; > + > + /* Test probing the sandbox FF-A bus */ > + uclass_first_device(UCLASS_FFA, &dev); > + ut_assertnonnull(dev); > + > + /* Get a pointer to the sandbox FF-A bus private data */ > + priv = dev_get_priv(dev); I think you want dev_get_uclass_priv() here, based on my othe rcomment > + > + /* Make sure the private data pointer is retrieved */ > + ut_assertnonnull(priv); > + > + /* Test FFA_VERSION */ [..] Regards, Simon