diff mbox series

[4/4] test: dm: add SCMI power domain protocol test

Message ID 20230926070043.738340-5-takahiro.akashi@linaro.org
State Superseded
Headers show
Series firmware: scmi: add SCMI power domain protocol support | expand

Commit Message

AKASHI Takahiro Sept. 26, 2023, 7 a.m. UTC
This ut has tests for the SCMI power domain protocol as well as DM
interfaces for power domain devices.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 test/dm/scmi.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 106 insertions(+), 1 deletion(-)

Comments

Simon Glass Oct. 2, 2023, 1:17 a.m. UTC | #1
On Tue, 26 Sept 2023 at 01:01, AKASHI Takahiro
<takahiro.akashi@linaro.org> wrote:
>
> This ut has tests for the SCMI power domain protocol as well as DM
> interfaces for power domain devices.
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>  test/dm/scmi.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 106 insertions(+), 1 deletion(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Oct. 14, 2023, 1:20 a.m. UTC | #2
On Tue, Sep 26, 2023 at 04:00:43PM +0900, AKASHI Takahiro wrote:

> This ut has tests for the SCMI power domain protocol as well as DM
> interfaces for power domain devices.
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> ---
>  test/dm/scmi.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 106 insertions(+), 1 deletion(-)

With v6 of the required series there is no scmi command, so, how do we
test this support now?
AKASHI Takahiro Oct. 16, 2023, 1:59 a.m. UTC | #3
Hi Tom,

On Fri, Oct 13, 2023 at 09:20:48PM -0400, Tom Rini wrote:
> On Tue, Sep 26, 2023 at 04:00:43PM +0900, AKASHI Takahiro wrote:
> 
> > This ut has tests for the SCMI power domain protocol as well as DM
> > interfaces for power domain devices.
> > 
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > Reviewed-by: Simon Glass <sjg@chromium.org>
> > ---
> >  test/dm/scmi.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 106 insertions(+), 1 deletion(-)
> 
> With v6 of the required series there is no scmi command, so, how do we
> test this support now?

Well, "ut dm scmi_power_domains" does test the code at function level
(both for SCMI protocol APIs and DM's power_domain_*() interfaces).

That said, prior to v6, we needed to adjust the output from "smci info"
command and hence "ut dm scmi_cmd" test because it, more specifically base
protocol's DISCOVER_LIST_PROTOCOLS, tries to enumerate available protocols
including power domain protocol.

With v6, we can simply remove the first hunk in this commit.
I will submit a new version with this change.

Thanks,
-Takahiro Akashi

> 
> -- 
> Tom
diff mbox series

Patch

diff --git a/test/dm/scmi.c b/test/dm/scmi.c
index 949e49bd2c35..c2625373d84e 100644
--- a/test/dm/scmi.c
+++ b/test/dm/scmi.c
@@ -15,6 +15,7 @@ 
 #include <common.h>
 #include <clk.h>
 #include <dm.h>
+#include <malloc.h>
 #include <reset.h>
 #include <scmi_agent.h>
 #include <scmi_agent-uclass.h>
@@ -223,7 +224,8 @@  static int dm_test_scmi_cmd(struct unit_test_state *uts)
 	ut_assert_nextline("  # of agents: 2");
 	ut_assert_nextline("      0: platform");
 	ut_assert_nextline("    > 1: OSPM");
-	ut_assert_nextline("  # of protocols: 3");
+	ut_assert_nextline("  # of protocols: 4");
+	ut_assert_nextline("      Power domain management");
 	ut_assert_nextline("      Clock management");
 	ut_assert_nextline("      Reset domain management");
 	ut_assert_nextline("      Voltage domain management");
@@ -259,6 +261,109 @@  static int dm_test_scmi_cmd(struct unit_test_state *uts)
 
 DM_TEST(dm_test_scmi_cmd, UT_TESTF_SCAN_FDT);
 
+static int dm_test_scmi_power_domains(struct unit_test_state *uts)
+{
+	struct sandbox_scmi_agent *agent;
+	struct sandbox_scmi_devices *scmi_devices;
+	struct udevice *agent_dev, *pwd, *dev;
+	u32 version, count, attributes, pstate;
+	u64 stats_addr;
+	size_t stats_len;
+	u8 *name;
+	int ret;
+
+	/* preparation */
+	ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev));
+	ut_assertnonnull(agent);
+	scmi_devices = sandbox_scmi_devices_ctx(dev);
+	ut_assertnonnull(scmi_devices);
+	ut_asserteq(2, scmi_devices->pwdom->id); /* in test.dts */
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
+					      &agent_dev));
+	ut_assertnonnull(agent_dev);
+	pwd = scmi_get_protocol(agent_dev, SCMI_PROTOCOL_ID_POWER_DOMAIN);
+	ut_assertnonnull(pwd);
+
+	/*
+	 * SCMI Power domain management protocol interfaces
+	 */
+	/* version */
+	ret = scmi_generic_protocol_version(pwd, SCMI_PROTOCOL_ID_POWER_DOMAIN,
+					    &version);
+	ut_assertok(ret);
+	ut_asserteq(agent->pwdom_version, version);
+
+	/* protocol attributes */
+	ret = scmi_pwd_protocol_attrs(pwd, &count, &stats_addr, &stats_len);
+	ut_assertok(ret);
+	ut_asserteq(agent->pwdom_count, count);
+	ut_asserteq(0, stats_len);
+
+	/* protocol message attributes */
+	ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_SET,
+					      &attributes);
+	ut_assertok(ret);
+	ret = scmi_pwd_protocol_message_attrs(pwd, SCMI_PWD_STATE_NOTIFY,
+					      &attributes);
+	ut_asserteq(-ENOENT, ret); /* the protocol not supported */
+
+	/* power domain attributes */
+	ret = scmi_pwd_attrs(pwd, 0, &attributes, &name);
+	ut_assertok(ret);
+	ut_asserteq_str("power-domain--0", name);
+	free(name);
+
+	ret = scmi_pwd_attrs(pwd, 10, &attributes, &name);
+	ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */
+
+	/* power domain state set/get */
+	ret = scmi_pwd_state_set(pwd, 0, 0, 0);
+	ut_assertok(ret);
+	ret = scmi_pwd_state_get(pwd, 0, &pstate);
+	ut_assertok(ret);
+	ut_asserteq(0, pstate); /* ON */
+
+	ret = scmi_pwd_state_set(pwd, 0, 0, SCMI_PWD_PSTATE_TYPE_LOST);
+	ut_assertok(ret);
+	ret = scmi_pwd_state_get(pwd, 0, &pstate);
+	ut_assertok(ret);
+	ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */
+
+	ret = scmi_pwd_state_set(pwd, 0, 10, 0);
+	ut_asserteq(-ENOENT, ret);
+
+	/* power domain name get */
+	ret = scmi_pwd_name_get(pwd, 0, &name);
+	ut_assertok(ret);
+	ut_asserteq_str("power-domain--0-extended", name);
+	free(name);
+
+	ret = scmi_pwd_name_get(pwd, 10, &name);
+	ut_asserteq(-ENOENT, ret); /* domain-10 doesn't exist */
+
+	/*
+	 * U-Boot driver model interfaces
+	 */
+	/* power_domain_on */
+	ret = power_domain_on(scmi_devices->pwdom);
+	ut_assertok(ret);
+	ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate);
+	ut_assertok(ret);
+	ut_asserteq(0, pstate); /* ON */
+
+	/* power_domain_off */
+	ret = power_domain_off(scmi_devices->pwdom);
+	ut_assertok(ret);
+	ret = scmi_pwd_state_get(pwd, scmi_devices->pwdom->id, &pstate);
+	ut_assertok(ret);
+	ut_asserteq(SCMI_PWD_PSTATE_TYPE_LOST, pstate); /* OFF */
+
+	return release_sandbox_scmi_test_devices(uts, dev);
+}
+
+DM_TEST(dm_test_scmi_power_domains, UT_TESTF_SCAN_FDT);
+
 static int dm_test_scmi_clocks(struct unit_test_state *uts)
 {
 	struct sandbox_scmi_agent *agent;