diff mbox series

[v2,09/12] test: dm: add SCMI base protocol test

Message ID 20230726083808.140780-10-takahiro.akashi@linaro.org
State Superseded
Headers show
Series firmware: scmi: add SCMI base protocol support | expand

Commit Message

AKASHI Takahiro July 26, 2023, 8:38 a.m. UTC
Added is a new unit test for SCMI base protocol, which will exercise all
the commands provided by the protocol, except SCMI_BASE_NOTIFY_ERRORS.
  $ ut dm scmi_base
It is assumed that test.dtb is used as sandbox's device tree.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
v2
* use helper functions, removing direct uses of ops
---
 test/dm/scmi.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 109 insertions(+)

Comments

Simon Glass July 27, 2023, 12:53 a.m. UTC | #1
\On Wed, 26 Jul 2023 at 02:39, AKASHI Takahiro
<takahiro.akashi@linaro.org> wrote:
>
> Added is a new unit test for SCMI base protocol, which will exercise all
> the commands provided by the protocol, except SCMI_BASE_NOTIFY_ERRORS.
>   $ ut dm scmi_base
> It is assumed that test.dtb is used as sandbox's device tree.
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
> v2
> * use helper functions, removing direct uses of ops
> ---
>  test/dm/scmi.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 109 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Etienne CARRIERE Aug. 3, 2023, 10:25 a.m. UTC | #2
> From: AKASHI Takahiro <takahiro.akashi@linaro.org>
> Sent: Wednesday, July 26, 2023 10:38
>  
> Added is a new unit test for SCMI base protocol, which will exercise all
> the commands provided by the protocol, except SCMI_BASE_NOTIFY_ERRORS.
>   $ ut dm scmi_base
> It is assumed that test.dtb is used as sandbox's device tree.
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
> v2
> * use helper functions, removing direct uses of ops
> ---

Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>
with reported issue fixed.


>  test/dm/scmi.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 109 insertions(+)
> 
> diff --git a/test/dm/scmi.c b/test/dm/scmi.c
> index 881be3171b7c..41d46548f7fd 100644
> --- a/test/dm/scmi.c
> +++ b/test/dm/scmi.c
> @@ -16,6 +16,9 @@
>  #include <clk.h>
>  #include <dm.h>
>  #include <reset.h>
> +#include <scmi_agent.h>
> +#include <scmi_agent-uclass.h>
> +#include <scmi_protocols.h>
>  #include <asm/scmi_test.h>
>  #include <dm/device-internal.h>
>  #include <dm/test.h>
> @@ -95,6 +98,112 @@ static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts)
>  }
>  DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT);
>  
> +static int dm_test_scmi_base(struct unit_test_state *uts)
> +{
> +       struct udevice *agent_dev, *base;
> +       struct scmi_agent_priv *priv;
> +       u32 version, num_agents, num_protocols, impl_version;
> +       u32 attributes, agent_id;
> +       char vendor[SCMI_BASE_NAME_LENGTH_MAX],
> +            agent_name[SCMI_BASE_NAME_LENGTH_MAX];
> +       u8 *protocols;
> +       int ret;
> +
> +       /* preparation */
> +       ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
> +                                             &agent_dev));
> +       ut_assertnonnull(agent_dev);
> +       ut_assertnonnull(priv = dev_get_uclass_plat(agent_dev));
> +       ut_assertnonnull(base = scmi_get_protocol(agent_dev,
> +                                                 SCMI_PROTOCOL_ID_BASE));
> +
> +       /* version */
> +       ret = scmi_base_protocol_version(base, &version);
> +       ut_assertok(ret);
> +       ut_asserteq(priv->version, version);
> +
> +       /* protocol attributes */
> +       ret = scmi_base_protocol_attrs(base, &num_agents, &num_protocols);
Typo: s/scmi_base_protocol_attrs/scmi_base_protocol_message_attrs/

This issue is fixed in patch 12/12 but should be squashed here to
prevent a build error.

BR,
etienne

> +       ut_assertok(ret);
> +       ut_asserteq(priv->num_agents, num_agents);
> +       ut_asserteq(priv->num_protocols, num_protocols);
> +
> +       /* discover vendor */
> +       ret = scmi_base_discover_vendor(base, vendor);
> +       ut_assertok(ret);
> +       ut_asserteq_str(priv->vendor, vendor);
> +
> +       /* message attributes */
> +       ret = scmi_protocol_message_attrs(base,
> +                                         SCMI_BASE_DISCOVER_SUB_VENDOR,
> +                                         &attributes);
> +       ut_assertok(ret);
> +       ut_assertok(attributes);
> +
> +       /* discover sub vendor */
> +       ret = scmi_base_discover_sub_vendor(base, vendor);
> +       ut_assertok(ret);
> +       ut_asserteq_str(priv->sub_vendor, vendor);
> +
> +       /* impl version */
> +       ret = scmi_base_discover_impl_version(base, &impl_version);
> +       ut_assertok(ret);
> +       ut_asserteq(priv->impl_version, impl_version);
> +
> +       /* discover agent (my self) */
> +       ret = scmi_base_discover_agent(base, 0xffffffff, &agent_id, agent_name);
> +       ut_assertok(ret);
> +       ut_asserteq(priv->agent_id, agent_id);
> +       ut_asserteq_str(priv->agent_name, agent_name);
> +
> +       /* discover protocols */
> +       ret = scmi_base_discover_list_protocols(base, &protocols);
> +       ut_asserteq(num_protocols, ret);
> +       ut_asserteq_mem(priv->protocols, protocols, sizeof(u8) * num_protocols);
> +       free(protocols);
> +
> +       /*
> +        * NOTE: Sandbox SCMI driver handles device-0 only. It supports setting
> +        * access and protocol permissions, but doesn't allow unsetting them nor
> +        * resetting the configurations.
> +        */
> +       /* set device permissions */
> +       ret = scmi_base_set_device_permissions(base, agent_id, 0,
> +                                              SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
> +       ut_assertok(ret); /* SCMI_SUCCESS */
> +       ret = scmi_base_set_device_permissions(base, agent_id, 1,
> +                                              SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
> +       ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
> +       ret = scmi_base_set_device_permissions(base, agent_id, 0, 0);
> +       ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
> +
> +       /* set protocol permissions */
> +       ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
> +                                                SCMI_PROTOCOL_ID_CLOCK,
> +                                                SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
> +       ut_assertok(ret); /* SCMI_SUCCESS */
> +       ret = scmi_base_set_protocol_permissions(base, agent_id, 1,
> +                                                SCMI_PROTOCOL_ID_CLOCK,
> +                                                SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
> +       ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
> +       ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
> +                                                SCMI_PROTOCOL_ID_CLOCK, 0);
> +       ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
> +
> +       /* reset agent configuration */
> +       ret = scmi_base_reset_agent_configuration(base, agent_id, 0);
> +       ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
> +       ret = scmi_base_reset_agent_configuration(base, agent_id,
> +                                                 SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS);
> +       ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
> +       ret = scmi_base_reset_agent_configuration(base, agent_id, 0);
> +       ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
> +
> +       return 0;
> +}
> +
> +DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT);
> +
>  static int dm_test_scmi_clocks(struct unit_test_state *uts)
>  {
>          struct sandbox_scmi_agent *agent;
> --
> 2.41.0
>
diff mbox series

Patch

diff --git a/test/dm/scmi.c b/test/dm/scmi.c
index 881be3171b7c..41d46548f7fd 100644
--- a/test/dm/scmi.c
+++ b/test/dm/scmi.c
@@ -16,6 +16,9 @@ 
 #include <clk.h>
 #include <dm.h>
 #include <reset.h>
+#include <scmi_agent.h>
+#include <scmi_agent-uclass.h>
+#include <scmi_protocols.h>
 #include <asm/scmi_test.h>
 #include <dm/device-internal.h>
 #include <dm/test.h>
@@ -95,6 +98,112 @@  static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT);
 
+static int dm_test_scmi_base(struct unit_test_state *uts)
+{
+	struct udevice *agent_dev, *base;
+	struct scmi_agent_priv *priv;
+	u32 version, num_agents, num_protocols, impl_version;
+	u32 attributes, agent_id;
+	char vendor[SCMI_BASE_NAME_LENGTH_MAX],
+	     agent_name[SCMI_BASE_NAME_LENGTH_MAX];
+	u8 *protocols;
+	int ret;
+
+	/* preparation */
+	ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
+					      &agent_dev));
+	ut_assertnonnull(agent_dev);
+	ut_assertnonnull(priv = dev_get_uclass_plat(agent_dev));
+	ut_assertnonnull(base = scmi_get_protocol(agent_dev,
+						  SCMI_PROTOCOL_ID_BASE));
+
+	/* version */
+	ret = scmi_base_protocol_version(base, &version);
+	ut_assertok(ret);
+	ut_asserteq(priv->version, version);
+
+	/* protocol attributes */
+	ret = scmi_base_protocol_attrs(base, &num_agents, &num_protocols);
+	ut_assertok(ret);
+	ut_asserteq(priv->num_agents, num_agents);
+	ut_asserteq(priv->num_protocols, num_protocols);
+
+	/* discover vendor */
+	ret = scmi_base_discover_vendor(base, vendor);
+	ut_assertok(ret);
+	ut_asserteq_str(priv->vendor, vendor);
+
+	/* message attributes */
+	ret = scmi_protocol_message_attrs(base,
+					  SCMI_BASE_DISCOVER_SUB_VENDOR,
+					  &attributes);
+	ut_assertok(ret);
+	ut_assertok(attributes);
+
+	/* discover sub vendor */
+	ret = scmi_base_discover_sub_vendor(base, vendor);
+	ut_assertok(ret);
+	ut_asserteq_str(priv->sub_vendor, vendor);
+
+	/* impl version */
+	ret = scmi_base_discover_impl_version(base, &impl_version);
+	ut_assertok(ret);
+	ut_asserteq(priv->impl_version, impl_version);
+
+	/* discover agent (my self) */
+	ret = scmi_base_discover_agent(base, 0xffffffff, &agent_id, agent_name);
+	ut_assertok(ret);
+	ut_asserteq(priv->agent_id, agent_id);
+	ut_asserteq_str(priv->agent_name, agent_name);
+
+	/* discover protocols */
+	ret = scmi_base_discover_list_protocols(base, &protocols);
+	ut_asserteq(num_protocols, ret);
+	ut_asserteq_mem(priv->protocols, protocols, sizeof(u8) * num_protocols);
+	free(protocols);
+
+	/*
+	 * NOTE: Sandbox SCMI driver handles device-0 only. It supports setting
+	 * access and protocol permissions, but doesn't allow unsetting them nor
+	 * resetting the configurations.
+	 */
+	/* set device permissions */
+	ret = scmi_base_set_device_permissions(base, agent_id, 0,
+					       SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
+	ut_assertok(ret); /* SCMI_SUCCESS */
+	ret = scmi_base_set_device_permissions(base, agent_id, 1,
+					       SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
+	ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
+	ret = scmi_base_set_device_permissions(base, agent_id, 0, 0);
+	ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
+
+	/* set protocol permissions */
+	ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
+						 SCMI_PROTOCOL_ID_CLOCK,
+						 SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
+	ut_assertok(ret); /* SCMI_SUCCESS */
+	ret = scmi_base_set_protocol_permissions(base, agent_id, 1,
+						 SCMI_PROTOCOL_ID_CLOCK,
+						 SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
+	ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
+	ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
+						 SCMI_PROTOCOL_ID_CLOCK, 0);
+	ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
+
+	/* reset agent configuration */
+	ret = scmi_base_reset_agent_configuration(base, agent_id, 0);
+	ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
+	ret = scmi_base_reset_agent_configuration(base, agent_id,
+						  SCMI_BASE_RESET_ALL_ACCESS_PERMISSIONS);
+	ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
+	ret = scmi_base_reset_agent_configuration(base, agent_id, 0);
+	ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
+
+	return 0;
+}
+
+DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT);
+
 static int dm_test_scmi_clocks(struct unit_test_state *uts)
 {
 	struct sandbox_scmi_agent *agent;