diff options
author | Przemyslaw Marczak <p.marczak@samsung.com> | 2015-04-15 13:07:19 +0200 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2015-04-22 11:03:14 -0600 |
commit | 754e71e850cb09d53543846fbed74cc5a1491c76 (patch) | |
tree | 8585ba7e94c7ccdac4bc47e1b26a2ce6cda77048 /test | |
parent | 5eaed880282480a5a0a2b555c5f98a11252ed94e (diff) | |
download | u-boot-754e71e850cb09d53543846fbed74cc5a1491c76.tar.gz u-boot-754e71e850cb09d53543846fbed74cc5a1491c76.tar.xz u-boot-754e71e850cb09d53543846fbed74cc5a1491c76.zip |
dm: test: Add tests for device's uclass platform data
This test introduces new test structure type:dm_test_perdev_uc_pdata.
The structure consists of three int values only. For the test purposes,
three pattern values are defined by enum, starting with TEST_UC_PDATA_INTVAL1.
This commit adds two test cases for uclass platform data:
- Test: dm_test_autobind_uclass_pdata_alloc - this tests if:
* uclass driver sets: .per_device_platdata_auto_alloc_size field
* the devices's: dev->uclass_platdata is non-NULL
- Test: dm_test_autobind_uclass_pdata_valid - this tests:
* if the devices's: dev->uclass_platdata is non-NULL
* the structure of type 'dm_test_perdev_uc_pdata' allocated at address
pointed by dev->uclass_platdata. Each structure field, should be equal
to proper pattern data, starting from .intval1 == TEST_UC_PDATA_INTVAL1.
Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/core.c | 55 | ||||
-rw-r--r-- | test/dm/test-uclass.c | 11 |
2 files changed, 66 insertions, 0 deletions
diff --git a/test/dm/core.c b/test/dm/core.c index 990d390d01..009ad36936 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -129,6 +129,61 @@ static int dm_test_autobind(struct dm_test_state *dms) } DM_TEST(dm_test_autobind, 0); +/* Test that binding with uclass platdata allocation occurs correctly */ +static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) +{ + struct dm_test_perdev_uc_pdata *uc_pdata; + struct udevice *dev; + struct uclass *uc; + + ut_assertok(uclass_get(UCLASS_TEST, &uc)); + ut_assert(uc); + + /** + * Test if test uclass driver requires allocation for the uclass + * platform data and then check the dev->uclass_platdata pointer. + */ + ut_assert(uc->uc_drv->per_device_platdata_auto_alloc_size); + + for (uclass_find_first_device(UCLASS_TEST, &dev); + dev; + uclass_find_next_device(&dev)) { + ut_assert(dev); + + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + } + + return 0; +} +DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA); + +/* Test that binding with uclass platdata setting occurs correctly */ +static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) +{ + struct dm_test_perdev_uc_pdata *uc_pdata; + struct udevice *dev; + + /** + * In the test_postbind() method of test uclass driver, the uclass + * platform data should be set to three test int values - test it. + */ + for (uclass_find_first_device(UCLASS_TEST, &dev); + dev; + uclass_find_next_device(&dev)) { + ut_assert(dev); + + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1); + ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2); + ut_assert(uc_pdata->intval3 == TEST_UC_PDATA_INTVAL3); + } + + return 0; +} +DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA); + /* Test that autoprobe finds all the expected devices */ static int dm_test_autoprobe(struct dm_test_state *dms) { diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index 7cb37f70c7..4ae75ef764 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -30,9 +30,18 @@ int test_ping(struct udevice *dev, int pingval, int *pingret) static int test_post_bind(struct udevice *dev) { + struct dm_test_perdev_uc_pdata *uc_pdata; + dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++; ut_assert(!device_active(dev)); + uc_pdata = dev_get_uclass_platdata(dev); + ut_assert(uc_pdata); + + uc_pdata->intval1 = TEST_UC_PDATA_INTVAL1; + uc_pdata->intval2 = TEST_UC_PDATA_INTVAL2; + uc_pdata->intval3 = TEST_UC_PDATA_INTVAL3; + return 0; } @@ -115,4 +124,6 @@ UCLASS_DRIVER(test) = { .destroy = test_destroy, .priv_auto_alloc_size = sizeof(struct dm_test_uclass_priv), .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv), + .per_device_platdata_auto_alloc_size = + sizeof(struct dm_test_perdev_uc_pdata), }; |