diff mbox series

[v3,4/8] of: unittest: Add test for of_dma_get_max_cpu_address()

Message ID 20201014191211.27029-5-nsaenzjulienne@suse.de
State Changes Requested, archived
Headers show
Series arm64: Default to 32-bit wide ZONE_DMA | expand

Checks

Context Check Description
robh/checkpatch success

Commit Message

Nicolas Saenz Julienne Oct. 14, 2020, 7:12 p.m. UTC
Introduce a test for of_dma_get_max_cup_address(), it uses the same DT
data as the rest of dma-ranges unit tests.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 drivers/of/unittest.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Rob Herring Oct. 14, 2020, 10:04 p.m. UTC | #1
On Wed, Oct 14, 2020 at 2:12 PM Nicolas Saenz Julienne
<nsaenzjulienne@suse.de> wrote:
>
> Introduce a test for of_dma_get_max_cup_address(), it uses the same DT
> data as the rest of dma-ranges unit tests.
>
> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> ---
>  drivers/of/unittest.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> index 06cc988faf78..2cbf2a585c9f 100644
> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c
> @@ -869,6 +869,25 @@ static void __init of_unittest_changeset(void)
>  #endif
>  }
>
> +static void __init of_unittest_dma_get_max_cpu_address(void)
> +{
> +#ifdef CONFIG_HAS_DMA

Can't the unittest run without this? I run the unittests under UML.

> +       struct device_node *np;
> +       phys_addr_t cpu_addr;
> +
> +       np = of_find_node_by_path("/testcase-data/address-tests");
> +       if (!np) {
> +               pr_err("missing testcase data\n");
> +               return;
> +       }
> +
> +       cpu_addr = of_dma_get_max_cpu_address(np);
> +       unittest(cpu_addr == 0x50000000ULL,
> +                "of_dma_get_max_cpu_address: wrong CPU addr %pad (expecting %llx)\n",
> +                &cpu_addr, 0x50000000ULL);
> +#endif
> +}
> +
>  static void __init of_unittest_dma_ranges_one(const char *path,
>                 u64 expect_dma_addr, u64 expect_paddr)
>  {
> @@ -3266,6 +3285,7 @@ static int __init of_unittest(void)
>         of_unittest_changeset();
>         of_unittest_parse_interrupts();
>         of_unittest_parse_interrupts_extended();
> +       of_unittest_dma_get_max_cpu_address();
>         of_unittest_parse_dma_ranges();
>         of_unittest_pci_dma_ranges();
>         of_unittest_match_node();
> --
> 2.28.0
>
Nicolas Saenz Julienne Oct. 15, 2020, 9:51 a.m. UTC | #2
On Wed, 2020-10-14 at 17:04 -0500, Rob Herring wrote:
> On Wed, Oct 14, 2020 at 2:12 PM Nicolas Saenz Julienne
> <nsaenzjulienne@suse.de> wrote:
> > Introduce a test for of_dma_get_max_cup_address(), it uses the same DT
> > data as the rest of dma-ranges unit tests.
> > 
> > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> > ---
> >  drivers/of/unittest.c | 20 ++++++++++++++++++++
> >  1 file changed, 20 insertions(+)
> > 
> > diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> > index 06cc988faf78..2cbf2a585c9f 100644
> > --- a/drivers/of/unittest.c
> > +++ b/drivers/of/unittest.c
> > @@ -869,6 +869,25 @@ static void __init of_unittest_changeset(void)
> >  #endif
> >  }
> > 
> > +static void __init of_unittest_dma_get_max_cpu_address(void)
> > +{
> > +#ifdef CONFIG_HAS_DMA
> 
> Can't the unittest run without this? I run the unittests under UML.

It was cargo culted from its sibling of_unittest_dma_ranges_one(), now that you
mention it, I can't seem to find the reason why it's here in the first place,
nor for other similar usages in OF code.

I ran the test in UML with all HAS_DMA conditionals removed from OF code and
things went well. I'll prepare a fix for that.

> > +       struct device_node *np;
> > +       phys_addr_t cpu_addr;
> > +
> > +       np = of_find_node_by_path("/testcase-data/address-tests");
> > +       if (!np) {
> > +               pr_err("missing testcase data\n");
> > +               return;
> > +       }
> > +
> > +       cpu_addr = of_dma_get_max_cpu_address(np);
> > +       unittest(cpu_addr == 0x50000000ULL,
> > +                "of_dma_get_max_cpu_address: wrong CPU addr %pad (expecting %llx)\n",
> > +                &cpu_addr, 0x50000000ULL);
> > +#endif
> > +}
> > +
> >  static void __init of_unittest_dma_ranges_one(const char *path,
> >                 u64 expect_dma_addr, u64 expect_paddr)
> >  {
> > @@ -3266,6 +3285,7 @@ static int __init of_unittest(void)
> >         of_unittest_changeset();
> >         of_unittest_parse_interrupts();
> >         of_unittest_parse_interrupts_extended();
> > +       of_unittest_dma_get_max_cpu_address();
> >         of_unittest_parse_dma_ranges();
> >         of_unittest_pci_dma_ranges();
> >         of_unittest_match_node();
> > --
> > 2.28.0
> >
diff mbox series

Patch

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 06cc988faf78..2cbf2a585c9f 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -869,6 +869,25 @@  static void __init of_unittest_changeset(void)
 #endif
 }
 
+static void __init of_unittest_dma_get_max_cpu_address(void)
+{
+#ifdef CONFIG_HAS_DMA
+	struct device_node *np;
+	phys_addr_t cpu_addr;
+
+	np = of_find_node_by_path("/testcase-data/address-tests");
+	if (!np) {
+		pr_err("missing testcase data\n");
+		return;
+	}
+
+	cpu_addr = of_dma_get_max_cpu_address(np);
+	unittest(cpu_addr == 0x50000000ULL,
+		 "of_dma_get_max_cpu_address: wrong CPU addr %pad (expecting %llx)\n",
+		 &cpu_addr, 0x50000000ULL);
+#endif
+}
+
 static void __init of_unittest_dma_ranges_one(const char *path,
 		u64 expect_dma_addr, u64 expect_paddr)
 {
@@ -3266,6 +3285,7 @@  static int __init of_unittest(void)
 	of_unittest_changeset();
 	of_unittest_parse_interrupts();
 	of_unittest_parse_interrupts_extended();
+	of_unittest_dma_get_max_cpu_address();
 	of_unittest_parse_dma_ranges();
 	of_unittest_pci_dma_ranges();
 	of_unittest_match_node();