diff mbox

[U-Boot,V5,2/3] dm: test: Add tests for get/find uclass's device by name

Message ID 1429529554-3551-2-git-send-email-p.marczak@samsung.com
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Przemyslaw Marczak April 20, 2015, 11:32 a.m. UTC
This commit introduces simple tests for functions:
- uclass_find_device_by_name()
- uclass_get_device_by_name()

Tests added by this commit:
- Test: dm_test_uclass_devices_find_by_name: for uclass id: UCLASS_TEST_FDT
 * get uclass's devices by uclass_find_first/next_device() each as 'testdev',
 * for each returned device, call: uclass_find_device_by_name(),
   with previously returned device's name as an argument ('testdev->name').
 * for the found device ('founddev') check if:
   * founddev != NULL
   * testdev == founddev
   * testdev->name == founddev->name (by strcmp)

- Test: dm_test_uclass_devices_get_by_name: for uclass id: UCLASS_TEST_FDT
 * get uclass's devices by uclass_get_first/next_device() each as 'testdev',
 * for each returned device, call: uclass_get_device_by_name(),
   with previously returned device's name as an argument ('testdev->name').
 * for the found device ('founddev') check if:
   * founddev != NULL
   * founddev is active
   * testdev == founddev
   * testdev->name == founddev->name (by strcmp)

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
---
Changes V4:
-new commit

Changes V5:
- code cleanup
---
 test/dm/core.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

Comments

Simon Glass April 20, 2015, 9:24 p.m. UTC | #1
On 20 April 2015 at 05:32, Przemyslaw Marczak <p.marczak@samsung.com> wrote:
> This commit introduces simple tests for functions:
> - uclass_find_device_by_name()
> - uclass_get_device_by_name()
>
> Tests added by this commit:
> - Test: dm_test_uclass_devices_find_by_name: for uclass id: UCLASS_TEST_FDT
>  * get uclass's devices by uclass_find_first/next_device() each as 'testdev',
>  * for each returned device, call: uclass_find_device_by_name(),
>    with previously returned device's name as an argument ('testdev->name').
>  * for the found device ('founddev') check if:
>    * founddev != NULL
>    * testdev == founddev
>    * testdev->name == founddev->name (by strcmp)
>
> - Test: dm_test_uclass_devices_get_by_name: for uclass id: UCLASS_TEST_FDT
>  * get uclass's devices by uclass_get_first/next_device() each as 'testdev',
>  * for each returned device, call: uclass_get_device_by_name(),
>    with previously returned device's name as an argument ('testdev->name').
>  * for the found device ('founddev') check if:
>    * founddev != NULL
>    * founddev is active
>    * testdev == founddev
>    * testdev->name == founddev->name (by strcmp)
>
> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
> Cc: Simon Glass <sjg@chromium.org>
> ---
> Changes V4:
> -new commit
>
> Changes V5:
> - code cleanup
> ---
>  test/dm/core.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 81 insertions(+)

Acked-by: Simon Glass <sjg@chromium.org>
Simon Glass April 22, 2015, 4:52 p.m. UTC | #2
On 20 April 2015 at 15:24, Simon Glass <sjg@chromium.org> wrote:
> On 20 April 2015 at 05:32, Przemyslaw Marczak <p.marczak@samsung.com> wrote:
>> This commit introduces simple tests for functions:
>> - uclass_find_device_by_name()
>> - uclass_get_device_by_name()
>>
>> Tests added by this commit:
>> - Test: dm_test_uclass_devices_find_by_name: for uclass id: UCLASS_TEST_FDT
>>  * get uclass's devices by uclass_find_first/next_device() each as 'testdev',
>>  * for each returned device, call: uclass_find_device_by_name(),
>>    with previously returned device's name as an argument ('testdev->name').
>>  * for the found device ('founddev') check if:
>>    * founddev != NULL
>>    * testdev == founddev
>>    * testdev->name == founddev->name (by strcmp)
>>
>> - Test: dm_test_uclass_devices_get_by_name: for uclass id: UCLASS_TEST_FDT
>>  * get uclass's devices by uclass_get_first/next_device() each as 'testdev',
>>  * for each returned device, call: uclass_get_device_by_name(),
>>    with previously returned device's name as an argument ('testdev->name').
>>  * for the found device ('founddev') check if:
>>    * founddev != NULL
>>    * founddev is active
>>    * testdev == founddev
>>    * testdev->name == founddev->name (by strcmp)
>>
>> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
>> Cc: Simon Glass <sjg@chromium.org>
>> ---
>> Changes V4:
>> -new commit
>>
>> Changes V5:
>> - code cleanup
>> ---
>>  test/dm/core.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 81 insertions(+)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!
diff mbox

Patch

diff --git a/test/dm/core.c b/test/dm/core.c
index 3a8dd1d..7f7b977 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -674,6 +674,43 @@  static int dm_test_uclass_devices_find(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA);
 
+static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms)
+{
+	struct udevice *finddev;
+	struct udevice *testdev;
+	int findret, ret;
+
+	/*
+	 * For each test device found in fdt like: "a-test", "b-test", etc.,
+	 * use its name and try to find it by uclass_find_device_by_name().
+	 * Then, on success check if:
+	 * - current 'testdev' name is equal to the returned 'finddev' name
+	 * - current 'testdev' pointer is equal to the returned 'finddev'
+	 *
+	 * We assume that, each uclass's device name is unique, so if not, then
+	 * this will fail on checking condition: testdev == finddev, since the
+	 * uclass_find_device_by_name(), returns the first device by given name.
+	*/
+	for (ret = uclass_find_first_device(UCLASS_TEST_FDT, &testdev);
+	     testdev;
+	     ret = uclass_find_next_device(&testdev)) {
+		ut_assertok(ret);
+		ut_assert(testdev);
+
+		findret = uclass_find_device_by_name(UCLASS_TEST_FDT,
+						     testdev->name,
+						     &finddev);
+
+		ut_assertok(findret);
+		ut_assert(testdev);
+		ut_asserteq_str(testdev->name, finddev->name);
+		ut_asserteq_ptr(testdev, finddev);
+	}
+
+	return 0;
+}
+DM_TEST(dm_test_uclass_devices_find_by_name, DM_TESTF_SCAN_FDT);
+
 static int dm_test_uclass_devices_get(struct dm_test_state *dms)
 {
 	struct udevice *dev;
@@ -691,6 +728,50 @@  static int dm_test_uclass_devices_get(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA);
 
+static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms)
+{
+	struct udevice *finddev;
+	struct udevice *testdev;
+	int ret, findret;
+
+	/*
+	 * For each test device found in fdt like: "a-test", "b-test", etc.,
+	 * use its name and try to get it by uclass_get_device_by_name().
+	 * On success check if:
+	 * - returned finddev' is active
+	 * - current 'testdev' name is equal to the returned 'finddev' name
+	 * - current 'testdev' pointer is equal to the returned 'finddev'
+	 *
+	 * We asserts that the 'testdev' is active on each loop entry, so we
+	 * could be sure that the 'finddev' is activated too, but for sure
+	 * we check it again.
+	 *
+	 * We assume that, each uclass's device name is unique, so if not, then
+	 * this will fail on checking condition: testdev == finddev, since the
+	 * uclass_get_device_by_name(), returns the first device by given name.
+	*/
+	for (ret = uclass_first_device(UCLASS_TEST_FDT, &testdev);
+	     testdev;
+	     ret = uclass_next_device(&testdev)) {
+		ut_assertok(ret);
+		ut_assert(testdev);
+		ut_assert(device_active(testdev));
+
+		findret = uclass_get_device_by_name(UCLASS_TEST_FDT,
+						    testdev->name,
+						    &finddev);
+
+		ut_assertok(findret);
+		ut_assert(finddev);
+		ut_assert(device_active(finddev));
+		ut_asserteq_str(testdev->name, finddev->name);
+		ut_asserteq_ptr(testdev, finddev);
+	}
+
+	return 0;
+}
+DM_TEST(dm_test_uclass_devices_get_by_name, DM_TESTF_SCAN_FDT);
+
 static int dm_test_device_get_uclass_id(struct dm_test_state *dms)
 {
 	struct udevice *dev;