diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2008-08-20 16:55:14 +1000 |
---|---|---|
committer | Jon Loeliger <jdl@jdl.com> | 2008-10-02 08:49:51 -0500 |
commit | 9c83115351443a132c5c1cbad6cda79d52f63489 (patch) | |
tree | fa20b1561c2bd0ca6bdac1de04a9c0a58a0241d4 /tests | |
parent | b236893fc4bc173877adfa4270b14d7d7209fb10 (diff) | |
download | dtc-9c83115351443a132c5c1cbad6cda79d52f63489.tar.gz |
libfdt: Add function to explicitly expand aliases
Kumar has already added alias expansion to fdt_path_offset().
However, in some circumstances it may be convenient for the user of
libfdt to explicitly get the string expansion of an alias. This patch
adds a function to do this, fdt_get_alias(), and uses it to implement
fdt_path_offset().
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.tests | 1 | ||||
-rw-r--r-- | tests/get_alias.c | 58 | ||||
-rwxr-xr-x | tests/run_tests.sh | 1 |
3 files changed, 60 insertions, 0 deletions
diff --git a/tests/Makefile.tests b/tests/Makefile.tests index 44021b0..5fd4d28 100644 --- a/tests/Makefile.tests +++ b/tests/Makefile.tests @@ -4,6 +4,7 @@ LIB_TESTS_L = get_mem_rsv \ get_path supernode_atdepth_offset parent_offset \ node_offset_by_prop_value node_offset_by_phandle \ node_check_compatible node_offset_by_compatible \ + get_alias \ notfound \ setprop_inplace nop_property nop_node \ sw_tree1 \ diff --git a/tests/get_alias.c b/tests/get_alias.c new file mode 100644 index 0000000..8eeaee4 --- /dev/null +++ b/tests/get_alias.c @@ -0,0 +1,58 @@ +/* + * libfdt - Flat Device Tree manipulation + * Testcase for fdt_get_alias() + * 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 <fdt.h> +#include <libfdt.h> + +#include "tests.h" +#include "testdata.h" + +void check_alias(void *fdt, const char *path, const char *alias) +{ + const char *aliaspath; + + aliaspath = fdt_get_alias(fdt, alias); + + if (path && !aliaspath) + FAIL("fdt_get_alias(%s) failed\n", alias); + + if (strcmp(aliaspath, path) != 0) + FAIL("fdt_get_alias(%s) returned %s instead of %s\n", + alias, aliaspath, path); +} + +int main(int argc, char *argv[]) +{ + void *fdt; + + test_init(argc, argv); + fdt = load_blob_arg(argc, argv); + + check_alias(fdt, "/subnode@1", "s1"); + check_alias(fdt, "/subnode@1/subsubnode", "ss1"); + check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "sss1"); + + PASS(); +} diff --git a/tests/run_tests.sh b/tests/run_tests.sh index eb29462..b424664 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -216,6 +216,7 @@ dtc_tests () { # Check aliases support in fdt_path_offset run_dtc_test -I dts -O dtb -o aliases.dtb aliases.dts + run_test get_alias aliases.dtb run_test path_offset_aliases aliases.dtb # Check /include/ directive |