Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 3 | #include <dm.h> |
| 4 | #include <dm/test.h> |
| 5 | #include <test/ut.h> |
| 6 | |
Simon Glass | d0aff8b | 2022-09-06 20:27:14 -0600 | [diff] [blame] | 7 | static int dm_test_ofprop_get_property(struct unit_test_state *uts) |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 8 | { |
| 9 | ofnode node; |
| 10 | struct ofprop prop; |
| 11 | const void *value; |
| 12 | const char *propname; |
| 13 | int res, len, count = 0; |
| 14 | |
| 15 | node = ofnode_path("/cros-ec/flash"); |
Simon Glass | fec058d | 2022-09-06 20:27:13 -0600 | [diff] [blame] | 16 | for (res = ofnode_first_property(node, &prop); |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 17 | !res; |
Simon Glass | fec058d | 2022-09-06 20:27:13 -0600 | [diff] [blame] | 18 | res = ofnode_next_property(&prop)) { |
Simon Glass | d0aff8b | 2022-09-06 20:27:14 -0600 | [diff] [blame] | 19 | value = ofprop_get_property(&prop, &propname, &len); |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 20 | ut_assertnonnull(value); |
| 21 | switch (count) { |
| 22 | case 0: |
| 23 | ut_asserteq_str("image-pos", propname); |
| 24 | ut_asserteq(4, len); |
| 25 | break; |
| 26 | case 1: |
| 27 | ut_asserteq_str("size", propname); |
| 28 | ut_asserteq(4, len); |
| 29 | break; |
| 30 | case 2: |
| 31 | ut_asserteq_str("erase-value", propname); |
| 32 | ut_asserteq(4, len); |
| 33 | break; |
| 34 | case 3: |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 35 | /* only for plat */ |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 36 | ut_asserteq_str("name", propname); |
| 37 | ut_asserteq(6, len); |
| 38 | ut_asserteq_str("flash", value); |
| 39 | break; |
| 40 | default: |
| 41 | break; |
| 42 | } |
| 43 | count++; |
| 44 | } |
| 45 | |
| 46 | return 0; |
| 47 | } |
Simon Glass | d0aff8b | 2022-09-06 20:27:14 -0600 | [diff] [blame] | 48 | DM_TEST(dm_test_ofprop_get_property, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |