summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-11-22 13:15:06 -0700
committerDavid Gibson <david@gibson.dropbear.id.au>2018-11-24 23:20:16 +1100
commit82a52ce4573b7cd0039786f65b280fb99431fe5d (patch)
tree0d12e5f6a0630ec1eccd3d29296fd228b44eea74
parent607b8586b3837f60221c0da2af4f5333a34e50cc (diff)
downloaddevice-tree-compiler-82a52ce4573b7cd0039786f65b280fb99431fe5d.tar.gz
libfdt: Add a test for fdt_getprop_by_offset()
This function does not have its own test at present. Add one. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.tests2
-rw-r--r--tests/get_prop_offset.c56
-rwxr-xr-xtests/run_tests.sh1
-rw-r--r--tests/tests.h10
-rw-r--r--tests/testutils.c25
6 files changed, 94 insertions, 1 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index dfa3bd1..12af438 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -28,6 +28,7 @@ tmp.*
/get_path
/get_phandle
/getprop
+/get_prop_offset
/incbin
/integer-expressions
/fs_tree1
diff --git a/tests/Makefile.tests b/tests/Makefile.tests
index aabc906..b02d8bf 100644
--- a/tests/Makefile.tests
+++ b/tests/Makefile.tests
@@ -1,6 +1,6 @@
LIB_TESTS_L = get_mem_rsv \
root_node find_property subnode_offset path_offset \
- get_name getprop get_phandle \
+ get_name getprop get_prop_offset get_phandle \
get_path supernode_atdepth_offset parent_offset \
node_offset_by_prop_value node_offset_by_phandle \
node_check_compatible node_offset_by_compatible \
diff --git a/tests/get_prop_offset.c b/tests/get_prop_offset.c
new file mode 100644
index 0000000..3daef74
--- /dev/null
+++ b/tests/get_prop_offset.c
@@ -0,0 +1,56 @@
+/*
+ * libfdt - Flat Device Tree manipulation
+ * Testcase for fdt_getprop_by_offset()
+ * Copyright (C) 2006 David Gibson, IBM Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+
+#include <libfdt.h>
+
+#include "tests.h"
+#include "testdata.h"
+
+int main(int argc, char *argv[])
+{
+ bool found_prop_int = false;
+ bool found_prop_str = false;
+ int poffset;
+ void *fdt;
+
+ test_init(argc, argv);
+ fdt = load_blob_arg(argc, argv);
+
+ fdt_for_each_property_offset(poffset, fdt, 0) {
+ if (check_get_prop_offset_cell(fdt, poffset, "prop-int",
+ TEST_VALUE_1))
+ found_prop_int = true;
+ if (check_get_prop_offset(fdt, poffset, "prop-str",
+ strlen(TEST_STRING_1) + 1,
+ TEST_STRING_1))
+ found_prop_str = true;
+ }
+ if (!found_prop_int)
+ FAIL("Property 'prop-int' not found");
+ if (!found_prop_str)
+ FAIL("Property 'prop-str' not found");
+
+ PASS();
+}
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 23e6176..ca3fc86 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -303,6 +303,7 @@ tree1_tests () {
run_test path_offset $TREE
run_test get_name $TREE
run_test getprop $TREE
+ run_test get_prop_offset $TREE
run_test get_phandle $TREE
run_test get_path $TREE
run_test supernode_atdepth_offset $TREE
diff --git a/tests/tests.h b/tests/tests.h
index b7daa26..dc8120e 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -118,6 +118,16 @@ const void *check_getprop(void *fdt, int nodeoffset, const char *name,
})
#define check_getprop_string(fdt, nodeoffset, name, s) \
check_getprop((fdt), (nodeoffset), (name), strlen(s)+1, (s))
+
+/* Returns non-NULL if the property at poffset has the name in_name */
+const void *check_get_prop_offset(void *fdt, int poffset, const char *in_name,
+ int in_len, const void *in_val);
+#define check_get_prop_offset_cell(fdt, poffset, name, val) \
+ ({ \
+ fdt32_t x = cpu_to_fdt32(val); \
+ check_get_prop_offset(fdt, poffset, name, sizeof(x), &x); \
+ })
+
int nodename_eq(const char *s1, const char *s2);
void vg_prepare_blob(void *fdt, size_t bufsize);
void *load_blob(const char *filename);
diff --git a/tests/testutils.c b/tests/testutils.c
index 0217b02..bbfda90 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -160,6 +160,31 @@ const void *check_getprop(void *fdt, int nodeoffset, const char *name,
return propval;
}
+const void *check_get_prop_offset(void *fdt, int poffset, const char *exp_name,
+ int exp_len, const void *exp_val)
+{
+ const void *propval;
+ const char *name;
+ int proplen;
+
+ propval = fdt_getprop_by_offset(fdt, poffset, &name, &proplen);
+ if (!propval)
+ FAIL("fdt_getprop(\"%s\"): %s", name, fdt_strerror(proplen));
+
+ /* Not testing for this field, so ignore */
+ if (strcmp(name, exp_name))
+ return NULL;
+
+ if (proplen != exp_len)
+ FAIL("Size mismatch on property \"%s\": %d insead of %d",
+ name, proplen, exp_len);
+ if (exp_len && memcmp(exp_val, propval, exp_len))
+ FAIL("Data mismatch on property \"%s\"", name);
+
+ return propval;
+}
+
+
int nodename_eq(const char *s1, const char *s2)
{
int len = strlen(s2);