aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2015-09-29 11:09:08 +0200
committerDavid Gibson <david@gibson.dropbear.id.au>2015-09-30 13:26:31 +1000
commit604e61e081e3c6c8fa1a8189c71cb3908a5bbc1e (patch)
tree9316f9c3d5fc3918b48926a2e99335b3ce02b934 /tests
parent8702bd1d3b430c16aaa37056cb24b6d984da48f7 (diff)
downloaddtc-604e61e081e3c6c8fa1a8189c71cb3908a5bbc1e.tar.gz
fdt: Add functions to retrieve strings
Given a device tree node, a property name and an index, the new function fdt_stringlist_get() will return a pointer to the index'th string in the property's value and return its length (or an error code on failure) in an output argument. Signed-off-by: Thierry Reding <treding@nvidia.com> [Fix some -Wshadow warnings --dwg] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'tests')
-rw-r--r--tests/stringlist.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/stringlist.c b/tests/stringlist.c
index b8835b7..a9d3e73 100644
--- a/tests/stringlist.c
+++ b/tests/stringlist.c
@@ -58,6 +58,13 @@ static void check_expected_failure(const void *fdt, const char *path,
err = fdt_stringlist_search(fdt, offset, "#address-cells", "");
if (err != 0)
FAIL("empty string not found in #address-cells: %d\n", err);
+
+ /*
+ * fdt_get_string() can successfully extract strings from non-string
+ * properties. This is because it doesn't necessarily parse the whole
+ * property value, which would be necessary for it to determine if a
+ * valid string or string list is present.
+ */
}
static void check_string_count(const void *fdt, const char *path,
@@ -96,6 +103,27 @@ static void check_string_index(const void *fdt, const char *path,
string, property, path, err, idx);
}
+static void check_string(const void *fdt, const char *path,
+ const char *property, int idx,
+ const char *string)
+{
+ const char *result;
+ int offset, len;
+
+ offset = fdt_path_offset(fdt, path);
+ if (offset < 0)
+ FAIL("Couldn't find path %s", path);
+
+ result = fdt_stringlist_get(fdt, offset, property, idx, &len);
+ if (!result)
+ FAIL("Couldn't extract string %d from property %s of node %s: %d\n",
+ idx, property, path, len);
+
+ if (strcmp(string, result) != 0)
+ FAIL("String %d in property %s of node %s is %s, expected %s\n",
+ idx, property, path, result, string);
+}
+
int main(int argc, char *argv[])
{
void *fdt;
@@ -118,5 +146,9 @@ int main(int argc, char *argv[])
check_string_index(fdt, "/device", "compatible", "bar", 1);
check_string_index(fdt, "/device", "big-endian", "baz", -1);
+ check_string(fdt, "/", "compatible", 0, "test-strings");
+ check_string(fdt, "/device", "compatible", 0, "foo");
+ check_string(fdt, "/device", "compatible", 1, "bar");
+
PASS();
}