On Thu, Nov 22, 2018 at 01:15:06PM -0700, Simon Glass wrote: > This function does not have its own test at present. Add one. We don't have one specifically named for it, but property_iterate.c does cover fdt_getprop_by_offset(). Does this new test cover anything the existing one doesn't? > > Signed-off-by: Simon Glass <sjg@xxxxxxxxxxxx> > --- > > tests/.gitignore | 1 + > tests/Makefile.tests | 2 +- > tests/get_prop_offset.c | 56 +++++++++++++++++++++++++++++++++++++++++ > tests/run_tests.sh | 1 + > tests/tests.h | 10 ++++++++ > tests/testutils.c | 25 ++++++++++++++++++ > 6 files changed, 94 insertions(+), 1 deletion(-) > create mode 100644 tests/get_prop_offset.c > > diff --git a/tests/.gitignore b/tests/.gitignore > index 70a8c95..34f80df 100644 > --- a/tests/.gitignore > +++ b/tests/.gitignore > @@ -27,6 +27,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 6ddf444..bc7fe1c 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 547aedc..22e432b 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); -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Attachment:
signature.asc
Description: PGP signature