diff mbox

[U-Boot,4/4,v2] dm: test: Add test for device removal

Message ID 20170320115151.15155-4-sr@denx.de
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Stefan Roese March 20, 2017, 11:51 a.m. UTC
Add a test for the correct device removal. Currently two different ways
for device removal are supported:

- Normal device removal via the device_remove() API
- Removal via selective device driver flags (DM_FLAG_ACTIVE_DMA)

This new test "remove_active_dma" adds tests cases for those both ways
of removal.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Simon Glass <sjg@chromium.org>
---
v2:
- New patch in patchset

 test/dm/core.c        | 41 +++++++++++++++++++++++++++++++++++++++++
 test/dm/test-driver.c |  1 +
 2 files changed, 42 insertions(+)

Comments

Simon Glass March 26, 2017, 3:52 a.m. UTC | #1
Hi Stefan,

On 20 March 2017 at 05:51, Stefan Roese <sr@denx.de> wrote:
> Add a test for the correct device removal. Currently two different ways
> for device removal are supported:
>
> - Normal device removal via the device_remove() API
> - Removal via selective device driver flags (DM_FLAG_ACTIVE_DMA)
>
> This new test "remove_active_dma" adds tests cases for those both ways
> of removal.
>
> Signed-off-by: Stefan Roese <sr@denx.de>
> Cc: Simon Glass <sjg@chromium.org>
> ---
> v2:
> - New patch in patchset
>
>  test/dm/core.c        | 41 +++++++++++++++++++++++++++++++++++++++++
>  test/dm/test-driver.c |  1 +
>  2 files changed, 42 insertions(+)
>
> diff --git a/test/dm/core.c b/test/dm/core.c
> index 07b2419ea4..ef85e6b79c 100644
> --- a/test/dm/core.c
> +++ b/test/dm/core.c
> @@ -656,6 +656,47 @@ static int dm_test_pre_reloc(struct unit_test_state *uts)
>  }
>  DM_TEST(dm_test_pre_reloc, 0);
>
> +/*
> + * Test that removal of devices, either via the "normal" device_remove()
> + * API or via the device driver selective flag works as expected
> + */
> +static int dm_test_remove_active_dma(struct unit_test_state *uts)
> +{
> +       struct dm_test_state *dms = uts->priv;
> +       struct udevice *dev;
> +
> +       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
> +                                       &dev));
> +       ut_assert(dev);
> +
> +       /* Probe the device */
> +       ut_assertok(device_probe(dev));
> +
> +       /* Test if device is active right now */
> +       ut_asserteq(true, device_active(dev));
> +
> +       /* Remove the device via selective remove flag */
> +       dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
> +
> +       /* Test if device is inactive right now */
> +       ut_asserteq(false, device_active(dev));
> +
> +       /* Probe the device again */
> +       ut_assertok(device_probe(dev));
> +
> +       /* Test if device is active right now */
> +       ut_asserteq(true, device_active(dev));
> +
> +       /* Remove the device via "normal" remove API */
> +       ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));

This doesn't actually test a device not getting removed (due to its
flag) I think. Can you add a test for that?

> +
> +       /* Test if device is inactive right now */
> +       ut_asserteq(false, device_active(dev));
> +
> +       return 0;
> +}
> +DM_TEST(dm_test_remove_active_dma, 0);
> +
>  static int dm_test_uclass_before_ready(struct unit_test_state *uts)
>  {
>         struct uclass *uc;
> diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c
> index d10af51147..1a2932e519 100644
> --- a/test/dm/test-driver.c
> +++ b/test/dm/test-driver.c
> @@ -145,6 +145,7 @@ U_BOOT_DRIVER(test_manual_drv) = {
>         .probe  = test_manual_probe,
>         .remove = test_manual_remove,
>         .unbind = test_manual_unbind,
> +       .flags  = DM_FLAG_ACTIVE_DMA,
>  };
>
>  U_BOOT_DRIVER(test_pre_reloc_drv) = {
> --
> 2.12.0
>

Regards,
Simon
Stefan Roese March 27, 2017, 6:48 a.m. UTC | #2
Hi Simon,

On 26.03.2017 05:52, Simon Glass wrote:
> On 20 March 2017 at 05:51, Stefan Roese <sr@denx.de> wrote:
>> Add a test for the correct device removal. Currently two different ways
>> for device removal are supported:
>>
>> - Normal device removal via the device_remove() API
>> - Removal via selective device driver flags (DM_FLAG_ACTIVE_DMA)
>>
>> This new test "remove_active_dma" adds tests cases for those both ways
>> of removal.
>>
>> Signed-off-by: Stefan Roese <sr@denx.de>
>> Cc: Simon Glass <sjg@chromium.org>
>> ---
>> v2:
>> - New patch in patchset
>>
>>  test/dm/core.c        | 41 +++++++++++++++++++++++++++++++++++++++++
>>  test/dm/test-driver.c |  1 +
>>  2 files changed, 42 insertions(+)
>>
>> diff --git a/test/dm/core.c b/test/dm/core.c
>> index 07b2419ea4..ef85e6b79c 100644
>> --- a/test/dm/core.c
>> +++ b/test/dm/core.c
>> @@ -656,6 +656,47 @@ static int dm_test_pre_reloc(struct unit_test_state *uts)
>>  }
>>  DM_TEST(dm_test_pre_reloc, 0);
>>
>> +/*
>> + * Test that removal of devices, either via the "normal" device_remove()
>> + * API or via the device driver selective flag works as expected
>> + */
>> +static int dm_test_remove_active_dma(struct unit_test_state *uts)
>> +{
>> +       struct dm_test_state *dms = uts->priv;
>> +       struct udevice *dev;
>> +
>> +       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
>> +                                       &dev));
>> +       ut_assert(dev);
>> +
>> +       /* Probe the device */
>> +       ut_assertok(device_probe(dev));
>> +
>> +       /* Test if device is active right now */
>> +       ut_asserteq(true, device_active(dev));
>> +
>> +       /* Remove the device via selective remove flag */
>> +       dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
>> +
>> +       /* Test if device is inactive right now */
>> +       ut_asserteq(false, device_active(dev));
>> +
>> +       /* Probe the device again */
>> +       ut_assertok(device_probe(dev));
>> +
>> +       /* Test if device is active right now */
>> +       ut_asserteq(true, device_active(dev));
>> +
>> +       /* Remove the device via "normal" remove API */
>> +       ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
>
> This doesn't actually test a device not getting removed (due to its
> flag) I think. Can you add a test for that?

Yes, I forgot to add a test for this "non-removal case". Will add
in the next version.

Thanks,
Stefan
diff mbox

Patch

diff --git a/test/dm/core.c b/test/dm/core.c
index 07b2419ea4..ef85e6b79c 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -656,6 +656,47 @@  static int dm_test_pre_reloc(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_pre_reloc, 0);
 
+/*
+ * Test that removal of devices, either via the "normal" device_remove()
+ * API or via the device driver selective flag works as expected
+ */
+static int dm_test_remove_active_dma(struct unit_test_state *uts)
+{
+	struct dm_test_state *dms = uts->priv;
+	struct udevice *dev;
+
+	ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+					&dev));
+	ut_assert(dev);
+
+	/* Probe the device */
+	ut_assertok(device_probe(dev));
+
+	/* Test if device is active right now */
+	ut_asserteq(true, device_active(dev));
+
+	/* Remove the device via selective remove flag */
+	dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
+
+	/* Test if device is inactive right now */
+	ut_asserteq(false, device_active(dev));
+
+	/* Probe the device again */
+	ut_assertok(device_probe(dev));
+
+	/* Test if device is active right now */
+	ut_asserteq(true, device_active(dev));
+
+	/* Remove the device via "normal" remove API */
+	ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
+
+	/* Test if device is inactive right now */
+	ut_asserteq(false, device_active(dev));
+
+	return 0;
+}
+DM_TEST(dm_test_remove_active_dma, 0);
+
 static int dm_test_uclass_before_ready(struct unit_test_state *uts)
 {
 	struct uclass *uc;
diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c
index d10af51147..1a2932e519 100644
--- a/test/dm/test-driver.c
+++ b/test/dm/test-driver.c
@@ -145,6 +145,7 @@  U_BOOT_DRIVER(test_manual_drv) = {
 	.probe	= test_manual_probe,
 	.remove	= test_manual_remove,
 	.unbind	= test_manual_unbind,
+	.flags	= DM_FLAG_ACTIVE_DMA,
 };
 
 U_BOOT_DRIVER(test_pre_reloc_drv) = {