[PATCH v3 09/12] dm: test: Add test case for dev_phys_to_bus()/dev_bus_to_phys()

Simon Glass sjg at chromium.org
Sat Dec 19 03:28:48 CET 2020


On Tue, 15 Dec 2020 at 10:23, Nicolas Saenz Julienne
<nsaenzjulienne at suse.de> wrote:
>
> By reusing DT nodes already available in sandbox's test DT introduce a
> test to validate dev_phys_to_bus()/dev_bus_to_phys().
>
> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne at suse.de>
> ---
>  test/dm/Makefile   |  1 +
>  test/dm/phys2bus.c | 36 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 37 insertions(+)
>  create mode 100644 test/dm/phys2bus.c

Reviewed-by: Simon Glass <sjg at chromium.org>

comment below

>
> diff --git a/test/dm/Makefile b/test/dm/Makefile
> index 5c52d8b6ea..ac86abaa88 100644
> --- a/test/dm/Makefile
> +++ b/test/dm/Makefile
> @@ -16,6 +16,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o
>
>  obj-$(CONFIG_UT_DM) += core.o
>  obj-$(CONFIG_UT_DM) += read.o
> +obj-$(CONFIG_UT_DM) += phys2bus.o
>  ifneq ($(CONFIG_SANDBOX),)
>  obj-$(CONFIG_ACPIGEN) += acpi.o
>  obj-$(CONFIG_ACPIGEN) += acpigen.o
> diff --git a/test/dm/phys2bus.c b/test/dm/phys2bus.c
> new file mode 100644
> index 0000000000..06a045c168
> --- /dev/null
> +++ b/test/dm/phys2bus.c
> @@ -0,0 +1,36 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (c) 2020 Nicolas Saenz Julienne <nsaenzjulienne at suse.de>
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <phys2bus.h>
> +#include <dm/device.h>
> +#include <dm/ofnode.h>
> +#include <dm/root.h>
> +#include <dm/test.h>
> +#include <dm/uclass-internal.h>
> +#include <test/ut.h>
> +
> +static int dm_test_phys_to_bus(struct unit_test_state *uts)
> +{
> +       struct udevice *dev;
> +       ofnode node;
> +
> +       node = ofnode_path("/mmio-bus at 0");
> +       ut_assert(ofnode_valid(node));
> +       ut_assert(!uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev));
> +       /* In this case it should be transparent, no dma-ranges in parent bus */
> +       ut_asserteq_ptr((void*)0xfffffULL, (void*)dev_phys_to_bus(dev, 0xfffff));

ut_asserteq_addr() might be better here? Not sure.

> +       ut_asserteq_ptr((void*)0xfffffULL, (void*)(ulong)dev_bus_to_phys(dev, 0xfffff));
> +
> +       node = ofnode_path("/mmio-bus at 0/subnode at 0");
> +       ut_assert(ofnode_valid(node));
> +       ut_assert(!uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev));
> +       ut_asserteq_ptr((void*)0x100fffffULL, (void*)dev_phys_to_bus(dev, 0xfffff));
> +       ut_asserteq_ptr((void*)0xfffffULL, (void*)(ulong)dev_bus_to_phys(dev, 0x100fffff));
> +
> +       return 0;
> +}
> +DM_TEST(dm_test_phys_to_bus, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
> --
> 2.29.2
>

Regards,
Simon


More information about the U-Boot mailing list