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>main
parent
607b8586b3
commit
82a52ce457
|
@ -28,6 +28,7 @@ tmp.*
|
|||
/get_path
|
||||
/get_phandle
|
||||
/getprop
|
||||
/get_prop_offset
|
||||
/incbin
|
||||
/integer-expressions
|
||||
/fs_tree1
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue