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