mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-18 21:21:37 +00:00
dm: core: Add tests for stringlist functions
These functions currently lack tests so add some. The error handling differs betwee livetree and flattree at present, so only check the error codes with livetree. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
8ce465e48d
commit
fb933d070e
2 changed files with 77 additions and 0 deletions
|
@ -207,6 +207,7 @@
|
|||
test4-gpios = <&gpio_a 14>, <&gpio_b 4 1 3 2 1>;
|
||||
test5-gpios = <&gpio_a 19>;
|
||||
|
||||
bool-value;
|
||||
int-value = <1234>;
|
||||
uint-value = <(-1234)>;
|
||||
int64-value = /bits/ 64 <0x1111222233334444>;
|
||||
|
|
|
@ -351,3 +351,79 @@ static int dm_test_ofnode_for_each_compatible_node(struct unit_test_state *uts)
|
|||
return 0;
|
||||
}
|
||||
DM_TEST(dm_test_ofnode_for_each_compatible_node, UT_TESTF_SCAN_FDT);
|
||||
|
||||
static int dm_test_ofnode_string(struct unit_test_state *uts)
|
||||
{
|
||||
const char *out;
|
||||
ofnode node;
|
||||
|
||||
node = ofnode_path("/a-test");
|
||||
ut_assert(ofnode_valid(node));
|
||||
|
||||
/* single string */
|
||||
ut_asserteq(1, ofnode_read_string_count(node, "str-value"));
|
||||
ut_assertok(ofnode_read_string_index(node, "str-value", 0, &out));
|
||||
ut_asserteq_str("test string", out);
|
||||
ut_asserteq(0, ofnode_stringlist_search(node, "str-value",
|
||||
"test string"));
|
||||
|
||||
/* list of strings */
|
||||
ut_asserteq(5, ofnode_read_string_count(node, "mux-control-names"));
|
||||
ut_assertok(ofnode_read_string_index(node, "mux-control-names", 0,
|
||||
&out));
|
||||
ut_asserteq_str("mux0", out);
|
||||
ut_asserteq(0, ofnode_stringlist_search(node, "mux-control-names",
|
||||
"mux0"));
|
||||
|
||||
ut_assertok(ofnode_read_string_index(node, "mux-control-names", 4,
|
||||
&out));
|
||||
ut_asserteq_str("mux4", out);
|
||||
ut_asserteq(4, ofnode_stringlist_search(node, "mux-control-names",
|
||||
"mux4"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
DM_TEST(dm_test_ofnode_string, 0);
|
||||
|
||||
static int dm_test_ofnode_string_err(struct unit_test_state *uts)
|
||||
{
|
||||
const char *out;
|
||||
ofnode node;
|
||||
|
||||
/*
|
||||
* Test error codes only on livetree, as they are different with
|
||||
* flattree
|
||||
*/
|
||||
node = ofnode_path("/a-test");
|
||||
ut_assert(ofnode_valid(node));
|
||||
|
||||
/* non-existent property */
|
||||
ut_asserteq(-EINVAL, ofnode_read_string_count(node, "missing"));
|
||||
ut_asserteq(-EINVAL, ofnode_read_string_index(node, "missing", 0,
|
||||
&out));
|
||||
|
||||
/* empty property */
|
||||
ut_asserteq(-ENODATA, ofnode_read_string_count(node, "bool-value"));
|
||||
ut_asserteq(-ENODATA, ofnode_read_string_index(node, "bool-value", 0,
|
||||
&out));
|
||||
|
||||
/* badly formatted string list */
|
||||
ut_asserteq(-EILSEQ, ofnode_read_string_count(node, "int64-value"));
|
||||
ut_asserteq(-EILSEQ, ofnode_read_string_index(node, "int64-value", 0,
|
||||
&out));
|
||||
|
||||
/* out of range / not found */
|
||||
ut_asserteq(-ENODATA, ofnode_read_string_index(node, "str-value", 1,
|
||||
&out));
|
||||
ut_asserteq(-ENODATA, ofnode_stringlist_search(node, "str-value",
|
||||
"other"));
|
||||
|
||||
/* negative value for index is not allowed, so don't test for that */
|
||||
|
||||
ut_asserteq(-ENODATA, ofnode_read_string_index(node,
|
||||
"mux-control-names", 5,
|
||||
&out));
|
||||
|
||||
return 0;
|
||||
}
|
||||
DM_TEST(dm_test_ofnode_string_err, UT_TESTF_LIVE_TREE);
|
||||
|
|
Loading…
Add table
Reference in a new issue