[PATCH v2 08/12] test: dm: simplify SCMI unit test on sandbox

Etienne CARRIERE etienne.carriere at st.com
Thu Aug 3 12:23:28 CEST 2023


> From: AKASHI Takahiro <takahiro.akashi at linaro.org>
> Sent: Wednesday, July 26, 2023 10:38
>  
> Adding SCMI base protocol makes it inconvenient to hold the agent instance
> (udevice) locally since the agent device will be re-created per each test.
> Just remove it and simplify the test flows.
> The test scenario is not changed at all.
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
> Reviewed-by: Simon Glass <sjg at chromium.org>
> ---

Reviewed-by: Etienne Carriere <etienne.carriere at foss.st.com>

>  arch/sandbox/include/asm/scmi_test.h       |  7 ++-
>  drivers/firmware/scmi/sandbox-scmi_agent.c | 20 +------
>  drivers/firmware/scmi/scmi_agent-uclass.c  |  3 -
>  test/dm/scmi.c                             | 64 +++++++---------------
>  4 files changed, 26 insertions(+), 68 deletions(-)
> 
> diff --git a/arch/sandbox/include/asm/scmi_test.h b/arch/sandbox/include/asm/scmi_test.h
> index c72ec1e1cb25..2718336a9a50 100644
> --- a/arch/sandbox/include/asm/scmi_test.h
> +++ b/arch/sandbox/include/asm/scmi_test.h
> @@ -89,10 +89,11 @@ struct sandbox_scmi_devices {
>  
>  #ifdef CONFIG_SCMI_FIRMWARE
>  /**
> - * sandbox_scmi_service_ctx - Get the simulated SCMI services context
> + * sandbox_scmi_agent_ctx - Get the simulated SCMI agent context
> + * @dev:       Reference to the test agent
>   * @return:    Reference to backend simulated resources state
>   */
> -struct sandbox_scmi_service *sandbox_scmi_service_ctx(void);
> +struct sandbox_scmi_agent *sandbox_scmi_agent_ctx(struct udevice *dev);
>  
>  /**
>   * sandbox_scmi_devices_ctx - Get references to devices accessed through SCMI
> @@ -101,7 +102,7 @@ struct sandbox_scmi_service *sandbox_scmi_service_ctx(void);
>   */
>  struct sandbox_scmi_devices *sandbox_scmi_devices_ctx(struct udevice *dev);
>  #else
> -static inline struct sandbox_scmi_service *sandbox_scmi_service_ctx(void)
> +static struct sandbox_scmi_agent *sandbox_scmi_agent_ctx(struct udevice *dev)
>  {
>          return NULL;
>  }
> diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c b/drivers/firmware/scmi/sandbox-scmi_agent.c
> index 1f0261ea5c94..ab8afb01de40 100644
> --- a/drivers/firmware/scmi/sandbox-scmi_agent.c
> +++ b/drivers/firmware/scmi/sandbox-scmi_agent.c
> @@ -66,11 +66,9 @@ static struct sandbox_scmi_voltd scmi_voltd[] = {
>          { .id = 1, .voltage_uv = 1800000 },
>  };
>  
> -static struct sandbox_scmi_service sandbox_scmi_service_state;
> -
> -struct sandbox_scmi_service *sandbox_scmi_service_ctx(void)
> +struct sandbox_scmi_agent *sandbox_scmi_agent_ctx(struct udevice *dev)
>  {
> -       return &sandbox_scmi_service_state;
> +       return dev_get_priv(dev);
>  }
>  
>  static void debug_print_agent_state(struct udevice *dev, char *str)
> @@ -898,16 +896,8 @@ static int sandbox_scmi_test_process_msg(struct udevice *dev,
>  
>  static int sandbox_scmi_test_remove(struct udevice *dev)
>  {
> -       struct sandbox_scmi_agent *agent = dev_get_priv(dev);
> -
> -       if (agent != sandbox_scmi_service_ctx()->agent)
> -               return -EINVAL;
> -
>          debug_print_agent_state(dev, "removed");
>  
> -       /* We only need to dereference the agent in the context */
> -       sandbox_scmi_service_ctx()->agent = NULL;
> -
>          return 0;
>  }
>  
> @@ -915,9 +905,6 @@ static int sandbox_scmi_test_probe(struct udevice *dev)
>  {
>          struct sandbox_scmi_agent *agent = dev_get_priv(dev);
>  
> -       if (sandbox_scmi_service_ctx()->agent)
> -               return -EINVAL;
> -
>          *agent = (struct sandbox_scmi_agent){
>                  .clk = scmi_clk,
>                  .clk_count = ARRAY_SIZE(scmi_clk),
> @@ -929,9 +916,6 @@ static int sandbox_scmi_test_probe(struct udevice *dev)
>  
>          debug_print_agent_state(dev, "probed");
>  
> -       /* Save reference for tests purpose */
> -       sandbox_scmi_service_ctx()->agent = agent;
> -
>          return 0;
>  };
>  
> diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c
> index 279c2c218913..91cb172f3005 100644
> --- a/drivers/firmware/scmi/scmi_agent-uclass.c
> +++ b/drivers/firmware/scmi/scmi_agent-uclass.c
> @@ -412,9 +412,6 @@ static int scmi_bind_protocols(struct udevice *dev)
>                  }
>          }
>  
> -       if (!ret)
> -               scmi_agent = dev;
> -
>          return ret;
>  }
>  
> diff --git a/test/dm/scmi.c b/test/dm/scmi.c
> index d87e2731ce42..881be3171b7c 100644
> --- a/test/dm/scmi.c
> +++ b/test/dm/scmi.c
> @@ -23,22 +23,11 @@
>  #include <power/regulator.h>
>  #include <test/ut.h>
>  
> -static int ut_assert_scmi_state_preprobe(struct unit_test_state *uts)
> -{
> -       struct sandbox_scmi_service *scmi_ctx = sandbox_scmi_service_ctx();
> -
> -       ut_assertnonnull(scmi_ctx);
> -       ut_assertnull(scmi_ctx->agent);
> -
> -       return 0;
> -}
> -
>  static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts,
> +                                         struct sandbox_scmi_agent *agent,
>                                            struct udevice *dev)
>  {
>          struct sandbox_scmi_devices *scmi_devices;
> -       struct sandbox_scmi_service *scmi_ctx;
> -       struct sandbox_scmi_agent *agent;
>  
>          /* Device references to check context against test sequence */
>          scmi_devices = sandbox_scmi_devices_ctx(dev);
> @@ -48,10 +37,6 @@ static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts,
>          ut_asserteq(2, scmi_devices->regul_count);
>  
>          /* State of the simulated SCMI server exposed */
> -       scmi_ctx = sandbox_scmi_service_ctx();
> -       ut_assertnonnull(scmi_ctx);
> -       agent = scmi_ctx->agent;
> -       ut_assertnonnull(agent);
>          ut_asserteq(3, agent->clk_count);
>          ut_assertnonnull(agent->clk);
>          ut_asserteq(1, agent->reset_count);
> @@ -63,27 +48,32 @@ static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts,
>  }
>  
>  static int load_sandbox_scmi_test_devices(struct unit_test_state *uts,
> +                                         struct sandbox_scmi_agent **ctx,
>                                            struct udevice **dev)
>  {
> -       int ret;
> +       struct udevice *agent_dev;
>  
> -       ret = ut_assert_scmi_state_preprobe(uts);
> -       if (ret)
> -               return ret;
> +       ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
> +                                             &agent_dev));
> +       ut_assertnonnull(agent_dev);
> +
> +       *ctx = sandbox_scmi_agent_ctx(agent_dev);
> +       ut_assertnonnull(*ctx);
>  
> +       /* probe */
>          ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_scmi",
>                                                dev));
>          ut_assertnonnull(*dev);
>  
> -       return ut_assert_scmi_state_postprobe(uts, *dev);
> +       return ut_assert_scmi_state_postprobe(uts, *ctx, *dev);
>  }
>  
>  static int release_sandbox_scmi_test_devices(struct unit_test_state *uts,
>                                               struct udevice *dev)
>  {
> +       /* un-probe */
>          ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
>  
> -       /* Not sure test devices are fully removed, agent may not be visible */
>          return 0;
>  }
>  
> @@ -93,10 +83,11 @@ static int release_sandbox_scmi_test_devices(struct unit_test_state *uts,
>   */
>  static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts)
>  {
> +       struct sandbox_scmi_agent *ctx;
>          struct udevice *dev = NULL;
>          int ret;
>  
> -       ret = load_sandbox_scmi_test_devices(uts, &dev);
> +       ret = load_sandbox_scmi_test_devices(uts, &ctx, &dev);
>          if (!ret)
>                  ret = release_sandbox_scmi_test_devices(uts, dev);
>  
> @@ -106,23 +97,18 @@ DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT);
>  
>  static int dm_test_scmi_clocks(struct unit_test_state *uts)
>  {
> -       struct sandbox_scmi_devices *scmi_devices;
> -       struct sandbox_scmi_service *scmi_ctx;
>          struct sandbox_scmi_agent *agent;
> +       struct sandbox_scmi_devices *scmi_devices;
>          struct udevice *dev;
>          int ret_dev;
>          int ret;
>  
> -       ret = load_sandbox_scmi_test_devices(uts, &dev);
> +       ret = load_sandbox_scmi_test_devices(uts, &agent, &dev);
>          if (ret)
>                  return ret;
>  
>          scmi_devices = sandbox_scmi_devices_ctx(dev);
>          ut_assertnonnull(scmi_devices);
> -       scmi_ctx = sandbox_scmi_service_ctx();
> -       ut_assertnonnull(scmi_ctx);
> -       agent = scmi_ctx->agent;
> -       ut_assertnonnull(agent);
>  
>          /* Test SCMI clocks rate manipulation */
>          ut_asserteq(333, agent->clk[0].rate);
> @@ -169,22 +155,17 @@ DM_TEST(dm_test_scmi_clocks, UT_TESTF_SCAN_FDT);
>  
>  static int dm_test_scmi_resets(struct unit_test_state *uts)
>  {
> -       struct sandbox_scmi_devices *scmi_devices;
> -       struct sandbox_scmi_service *scmi_ctx;
>          struct sandbox_scmi_agent *agent;
> +       struct sandbox_scmi_devices *scmi_devices;
>          struct udevice *dev = NULL;
>          int ret;
>  
> -       ret = load_sandbox_scmi_test_devices(uts, &dev);
> +       ret = load_sandbox_scmi_test_devices(uts, &agent, &dev);
>          if (ret)
>                  return ret;
>  
>          scmi_devices = sandbox_scmi_devices_ctx(dev);
>          ut_assertnonnull(scmi_devices);
> -       scmi_ctx = sandbox_scmi_service_ctx();
> -       ut_assertnonnull(scmi_ctx);
> -       agent = scmi_ctx->agent;
> -       ut_assertnonnull(agent);
>  
>          /* Test SCMI resect controller manipulation */
>          ut_assert(!agent->reset[0].asserted);
> @@ -201,21 +182,16 @@ DM_TEST(dm_test_scmi_resets, UT_TESTF_SCAN_FDT);
>  
>  static int dm_test_scmi_voltage_domains(struct unit_test_state *uts)
>  {
> -       struct sandbox_scmi_devices *scmi_devices;
> -       struct sandbox_scmi_service *scmi_ctx;
>          struct sandbox_scmi_agent *agent;
> +       struct sandbox_scmi_devices *scmi_devices;
>          struct dm_regulator_uclass_plat *uc_pdata;
>          struct udevice *dev;
>          struct udevice *regul0_dev;
>  
> -       ut_assertok(load_sandbox_scmi_test_devices(uts, &dev));
> +       ut_assertok(load_sandbox_scmi_test_devices(uts, &agent, &dev));
>  
>          scmi_devices = sandbox_scmi_devices_ctx(dev);
>          ut_assertnonnull(scmi_devices);
> -       scmi_ctx = sandbox_scmi_service_ctx();
> -       ut_assertnonnull(scmi_ctx);
> -       agent = scmi_ctx->agent;
> -       ut_assertnonnull(agent);
>  
>          /* Set/Get an SCMI voltage domain level */
>          regul0_dev = scmi_devices->regul[0];
> -- 
> 2.41.0
> 


More information about the U-Boot mailing list