diff options
author | Oleksandr Tymoshenko <gonzo@FreeBSD.org> | 2017-03-10 03:28:43 +0000 |
---|---|---|
committer | Oleksandr Tymoshenko <gonzo@FreeBSD.org> | 2017-03-10 03:28:43 +0000 |
commit | f059bd1ebfc4cf2e96c4639ad7fa6cf3a3198a2f (patch) | |
tree | 74d52c3db99ba80520d6142e9bc77e2802093021 /tests | |
parent | b903311b940763cafe4fb3d8ab3da9c135c17b0c (diff) | |
download | src-f059bd1ebfc4cf2e96c4639ad7fa6cf3a3198a2f.tar.gz src-f059bd1ebfc4cf2e96c4639ad7fa6cf3a3198a2f.zip |
Import dtc 1.4.3vendor/dtc/1.4.3
Notes
Notes:
svn path=/vendor/dtc/dist/; revision=314985
svn path=/vendor/dtc/1.4.3/; revision=314986; tag=vendor/dtc/1.4.3
Diffstat (limited to 'tests')
62 files changed, 1778 insertions, 127 deletions
diff --git a/tests/Makefile.tests b/tests/Makefile.tests index dafb61848744..3d7a4f82f067 100644 --- a/tests/Makefile.tests +++ b/tests/Makefile.tests @@ -8,6 +8,8 @@ LIB_TESTS_L = get_mem_rsv \ char_literal \ sized_cells \ notfound \ + addr_size_cells \ + stringlist \ setprop_inplace nop_property nop_node \ sw_tree1 \ move_and_save mangle-layout nopulate \ @@ -21,7 +23,10 @@ LIB_TESTS_L = get_mem_rsv \ add_subnode_with_nops path_offset_aliases \ utilfdt_test \ integer-expressions \ - subnode_iterate + property_iterate \ + subnode_iterate \ + overlay overlay_bad_fixup \ + check_path LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%) LIBTREE_TESTS_L = truncated_property diff --git a/tests/addr_size_cells.c b/tests/addr_size_cells.c new file mode 100644 index 000000000000..6090d93b3345 --- /dev/null +++ b/tests/addr_size_cells.c @@ -0,0 +1,64 @@ +/* + * libfdt - Flat Device Tree manipulation + * Testcase for #address-cells and #size-cells handling + * Copyright (C) 2014 David Gibson, <david@gibson.dropbear.id.au> + * + * 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" + +static void check_node(const void *fdt, const char *path, int ac, int sc) +{ + int offset; + int xac, xsc; + + offset = fdt_path_offset(fdt, path); + if (offset < 0) + FAIL("Couldn't find path %s", path); + + xac = fdt_address_cells(fdt, offset); + xsc = fdt_size_cells(fdt, offset); + + if (xac != ac) + FAIL("Address cells for %s is %d instead of %d\n", + path, xac, ac); + if (xsc != sc) + FAIL("Size cells for %s is %d instead of %d\n", + path, xsc, sc); +} + +int main(int argc, char *argv[]) +{ + void *fdt; + + if (argc != 2) + CONFIG("Usage: %s <dtb file>\n", argv[0]); + + test_init(argc, argv); + fdt = load_blob(argv[1]); + + check_node(fdt, "/", 2, 2); + check_node(fdt, "/identity-bus@0", 2, 2); + check_node(fdt, "/simple-bus@1000000", 2, 1); + PASS(); +} diff --git a/tests/addresses.dts b/tests/addresses.dts new file mode 100644 index 000000000000..a2faaf59fd7a --- /dev/null +++ b/tests/addresses.dts @@ -0,0 +1,15 @@ +/dts-v1/; + +/ { + compatible = "test_addresses"; + #address-cells = <2>; + #size-cells = <2>; + + identity-bus@0 { + }; + + simple-bus@1000000 { + #address-cells = <2>; + #size-cells = <1>; + }; +}; diff --git a/tests/bad-octal-literal.dts b/tests/bad-octal-literal.dts new file mode 100644 index 000000000000..26558a2740f4 --- /dev/null +++ b/tests/bad-octal-literal.dts @@ -0,0 +1,5 @@ +/dts-v1/; + +/ { + x = <09>; +}; diff --git a/tests/bad-size-cells.dts b/tests/bad-size-cells.dts new file mode 100644 index 000000000000..515c0cc7ba45 --- /dev/null +++ b/tests/bad-size-cells.dts @@ -0,0 +1,12 @@ +/dts-v1/; + +/ { + mangled { + #address-cells = <0x0>; + #size-cells = <0x0>; + + valid { + reg = <0x0 0x4000000>; + }; + }; +}; diff --git a/tests/check_path.c b/tests/check_path.c new file mode 100644 index 000000000000..f12f9503b22d --- /dev/null +++ b/tests/check_path.c @@ -0,0 +1,83 @@ +/* + * libfdt - Flat Device Tree manipulation + * Testcase for node existence + * Copyright (C) 2016 Konsulko Inc. + * + * 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 <stdio.h> + +#include <libfdt.h> + +#include "tests.h" + +#define CHECK(code) \ + { \ + int err = (code); \ + if (err) \ + FAIL(#code ": %s", fdt_strerror(err)); \ + } + +/* 4k ought to be enough for anybody */ +#define FDT_COPY_SIZE (4 * 1024) + +static void *open_dt(char *path) +{ + void *dt, *copy; + + dt = load_blob(path); + copy = xmalloc(FDT_COPY_SIZE); + + /* + * Resize our DTs to 4k so that we have room to operate on + */ + CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE)); + + return copy; +} + +int main(int argc, char *argv[]) +{ + void *fdt_base; + int fail_config, exists, check_exists; + + test_init(argc, argv); + fail_config = 0; + + if (argc != 4) + fail_config = 1; + + if (!fail_config) { + if (!strcmp(argv[2], "exists")) + check_exists = 1; + else if (!strcmp(argv[2], "not-exists")) + check_exists = 0; + else + fail_config = 1; + } + + if (fail_config) + CONFIG("Usage: %s <base dtb> <[exists|not-exists]> <node-path>", argv[0]); + + fdt_base = open_dt(argv[1]); + + exists = fdt_path_offset(fdt_base, argv[3]) >= 0; + + if (exists == check_exists) + PASS(); + else + FAIL(); +} diff --git a/tests/division-by-zero.dts b/tests/division-by-zero.dts new file mode 100644 index 000000000000..2984b29ff62b --- /dev/null +++ b/tests/division-by-zero.dts @@ -0,0 +1,6 @@ +/dts-v1/; + +/ { + prop-div = < (1/0) >; + prop-mod = < (1%0) >; +}; diff --git a/tests/dumptrees.c b/tests/dumptrees.c index bebf553c9bfe..a49dbfab1567 100644 --- a/tests/dumptrees.c +++ b/tests/dumptrees.c @@ -36,6 +36,7 @@ struct { #define TREE(name) { &_##name, #name ".dtb" } TREE(test_tree1), TREE(bad_node_char), TREE(bad_node_format), TREE(bad_prop_char), + TREE(ovf_size_strings), }; #define NUM_TREES (sizeof(trees) / sizeof(trees[0])) diff --git a/tests/embedded_nul.dts b/tests/embedded_nul.dts Binary files differnew file mode 100644 index 000000000000..7b4993cc5452 --- /dev/null +++ b/tests/embedded_nul.dts diff --git a/tests/embedded_nul_equiv.dts b/tests/embedded_nul_equiv.dts new file mode 100644 index 000000000000..e978204f063d --- /dev/null +++ b/tests/embedded_nul_equiv.dts @@ -0,0 +1,6 @@ +/dts-v1/; + +/ { + reserved-names = "aaaaaaaaaaaaaaaaaa\0bbbbbb\0ccccccccccccc"; + reserved-ranges = < 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 >; +}; diff --git a/tests/fdtdump-runtest.sh b/tests/fdtdump-runtest.sh new file mode 100755 index 000000000000..77593cf6cd1e --- /dev/null +++ b/tests/fdtdump-runtest.sh @@ -0,0 +1,30 @@ +#! /bin/sh + +# Arguments: +# $1 - source file to compile and compare with fdtdump output of the +# compiled file. + +. ./tests.sh + +dts="$1" +dtb="${dts}.dtb" +out="${dts}.out" +LOG=tmp.log.$$ + +files="$dtb $out $LOG" + +rm -f $files +trap "rm -f $files" 0 + +verbose_run_log_check "$LOG" $VALGRIND $DTC -O dtb $dts -o $dtb +$FDTDUMP ${dtb} | grep -v "//" >${out} + +if diff -w $dts $out >/dev/null; then + PASS +else + if [ -z "$QUIET_TEST" ]; then + echo "DIFF :-:" + diff -u -w $dts $out + fi + FAIL "Results differ from expected" +fi diff --git a/tests/fdtdump.dts b/tests/fdtdump.dts new file mode 100644 index 000000000000..b83b7dffab97 --- /dev/null +++ b/tests/fdtdump.dts @@ -0,0 +1,38 @@ +/dts-v1/; + +/memreserve/ 0 0xe; +/ { + model = "MyBoardName"; + compatible = "MyBoardName", "MyBoardFamilyName"; + #address-cells = <0x00000002>; + #size-cells = <0x00000002>; + cpus { + linux,phandle = <0x00000001>; + #address-cells = <0x00000001>; + #size-cells = <0x00000000>; + PowerPC,970@0 { + device_type = "cpu"; + reg = <0x00000000>; + linux,boot-cpu; + }; + PowerPC,970@1 { + device_type = "cpu"; + reg = <0x00000001>; + }; + }; + randomnode { + string = "foo", "stuff"; + bytes = [61 62 63 64 65]; + nbytes = [80 ff]; + child { + }; + }; + memory@0 { + device_type = "memory"; + reg = <0x00000000 0x00000123 0x00000456 0x87654321>; + }; + chosen { + bootargs = "root=/dev/sda2"; + linux,platform = <0x00000600>; + }; +}; diff --git a/tests/get_phandle.c b/tests/get_phandle.c index 2079591d4c49..22bd7b81b3f0 100644 --- a/tests/get_phandle.c +++ b/tests/get_phandle.c @@ -44,6 +44,7 @@ static void check_phandle(void *fdt, const char *path, uint32_t checkhandle) int main(int argc, char *argv[]) { + uint32_t max; void *fdt; test_init(argc, argv); @@ -53,5 +54,10 @@ int main(int argc, char *argv[]) check_phandle(fdt, "/subnode@2", PHANDLE_1); check_phandle(fdt, "/subnode@2/subsubnode@0", PHANDLE_2); + max = fdt_get_max_phandle(fdt); + if (max != PHANDLE_2) + FAIL("fdt_get_max_phandle returned 0x%x instead of 0x%x\n", + max, PHANDLE_2); + PASS(); } diff --git a/tests/line_directives.dts b/tests/line_directives.dts index 046ef3715ad6..67b5e084f15c 100644 --- a/tests/line_directives.dts +++ b/tests/line_directives.dts @@ -18,4 +18,9 @@ # 10 "qux.dts" 0x12345678 >; +/* + * Check processing of escapes in filenames + */ +# 100 "\".dts" +# 200 "\\.dts" }; diff --git a/tests/multilabel.dts b/tests/multilabel.dts index 31116ceab2d6..77da06cc4174 100644 --- a/tests/multilabel.dts +++ b/tests/multilabel.dts @@ -5,6 +5,8 @@ m1: mq: /memreserve/ 0 0x1000; / { p0: pw: prop = "foo"; + rref = <&{/}>; + /* Explicit phandles */ n1: nx: node1 { linux,phandle = <0x2000>; diff --git a/tests/multilabel_merge.dts b/tests/multilabel_merge.dts index 1632300e6aca..3e8029897405 100644 --- a/tests/multilabel_merge.dts +++ b/tests/multilabel_merge.dts @@ -64,3 +64,7 @@ m1: mq: /memreserve/ 0 0x1000; }; }; + +/ { + rref = <&{/}>; +}; diff --git a/tests/nul-in-escape.dts b/tests/nul-in-escape.dts Binary files differnew file mode 100644 index 000000000000..9bed351cf021 --- /dev/null +++ b/tests/nul-in-escape.dts diff --git a/tests/nul-in-line-info1.dts b/tests/nul-in-line-info1.dts Binary files differnew file mode 100644 index 000000000000..ceb7261b7ef6 --- /dev/null +++ b/tests/nul-in-line-info1.dts diff --git a/tests/nul-in-line-info2.dts b/tests/nul-in-line-info2.dts new file mode 100644 index 000000000000..1157d2324f37 --- /dev/null +++ b/tests/nul-in-line-info2.dts @@ -0,0 +1 @@ +# 0 "\0" diff --git a/tests/overlay.c b/tests/overlay.c new file mode 100644 index 000000000000..3093eec67a91 --- /dev/null +++ b/tests/overlay.c @@ -0,0 +1,233 @@ +/* + * libfdt - Flat Device Tree manipulation + * Testcase for DT overlays() + * Copyright (C) 2016 Free Electrons + * Copyright (C) 2016 NextThing Co. + * + * 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 <stdio.h> + +#include <libfdt.h> + +#include "tests.h" + +#define CHECK(code) \ + { \ + int err = (code); \ + if (err) \ + FAIL(#code ": %s", fdt_strerror(err)); \ + } + +/* 4k ought to be enough for anybody */ +#define FDT_COPY_SIZE (4 * 1024) + +static int fdt_getprop_u32_by_poffset(void *fdt, const char *path, + const char *name, int poffset, + unsigned long *out) +{ + const fdt32_t *val; + int node_off; + int len; + + node_off = fdt_path_offset(fdt, path); + if (node_off < 0) + return node_off; + + val = fdt_getprop(fdt, node_off, name, &len); + if (!val || (len < (sizeof(uint32_t) * (poffset + 1)))) + return -FDT_ERR_NOTFOUND; + + *out = fdt32_to_cpu(*(val + poffset)); + + return 0; +} + +static int check_getprop_string_by_name(void *fdt, const char *path, + const char *name, const char *val) +{ + int node_off; + + node_off = fdt_path_offset(fdt, path); + if (node_off < 0) + return node_off; + + check_getprop_string(fdt, node_off, name, val); + + return 0; +} + +static int check_getprop_u32_by_name(void *fdt, const char *path, + const char *name, uint32_t val) +{ + int node_off; + + node_off = fdt_path_offset(fdt, path); + CHECK(node_off < 0); + + check_getprop_cell(fdt, node_off, name, val); + + return 0; +} + +static int check_getprop_null_by_name(void *fdt, const char *path, + const char *name) +{ + int node_off; + + node_off = fdt_path_offset(fdt, path); + CHECK(node_off < 0); + + check_property(fdt, node_off, name, 0, NULL); + + return 0; +} + +static int fdt_overlay_change_int_property(void *fdt) +{ + return check_getprop_u32_by_name(fdt, "/test-node", "test-int-property", + 43); +} + +static int fdt_overlay_change_str_property(void *fdt) +{ + return check_getprop_string_by_name(fdt, "/test-node", + "test-str-property", "foobar"); +} + +static int fdt_overlay_add_str_property(void *fdt) +{ + return check_getprop_string_by_name(fdt, "/test-node", + "test-str-property-2", "foobar2"); +} + +static int fdt_overlay_add_node(void *fdt) +{ + return check_getprop_null_by_name(fdt, "/test-node/new-node", + "new-property"); +} + +static int fdt_overlay_add_subnode_property(void *fdt) +{ + check_getprop_null_by_name(fdt, "/test-node/sub-test-node", + "sub-test-property"); + check_getprop_null_by_name(fdt, "/test-node/sub-test-node", + "new-sub-test-property"); + + return 0; +} + +static int fdt_overlay_local_phandle(void *fdt) +{ + uint32_t local_phandle; + unsigned long val = 0; + int off; + + off = fdt_path_offset(fdt, "/test-node/new-local-node"); + CHECK(off < 0); + + local_phandle = fdt_get_phandle(fdt, off); + CHECK(!local_phandle); + + CHECK(fdt_getprop_u32_by_poffset(fdt, "/test-node", + "test-several-phandle", + 0, &val)); + CHECK(val != local_phandle); + + CHECK(fdt_getprop_u32_by_poffset(fdt, "/test-node", + "test-several-phandle", + 1, &val)); + CHECK(val != local_phandle); + + return 0; +} + +static int fdt_overlay_local_phandles(void *fdt) +{ + uint32_t local_phandle, test_phandle; + unsigned long val = 0; + int off; + + off = fdt_path_offset(fdt, "/test-node/new-local-node"); + CHECK(off < 0); + + local_phandle = fdt_get_phandle(fdt, off); + CHECK(!local_phandle); + + off = fdt_path_offset(fdt, "/test-node"); + CHECK(off < 0); + + test_phandle = fdt_get_phandle(fdt, off); + CHECK(!test_phandle); + + CHECK(fdt_getprop_u32_by_poffset(fdt, "/test-node", + "test-phandle", 0, &val)); + CHECK(test_phandle != val); + + CHECK(fdt_getprop_u32_by_poffset(fdt, "/test-node", + "test-phandle", 1, &val)); + CHECK(local_phandle != val); + + return 0; +} + +static void *open_dt(char *path) +{ + void *dt, *copy; + + dt = load_blob(path); + copy = xmalloc(FDT_COPY_SIZE); + + /* + * Resize our DTs to 4k so that we have room to operate on + */ + CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE)); + + return copy; +} + +int main(int argc, char *argv[]) +{ + void *fdt_base, *fdt_overlay; + + test_init(argc, argv); + if (argc != 3) + CONFIG("Usage: %s <base dtb> <overlay dtb>", argv[0]); + + fdt_base = open_dt(argv[1]); + fdt_overlay = open_dt(argv[2]); + + /* Apply the overlay */ + CHECK(fdt_overlay_apply(fdt_base, fdt_overlay)); + + fdt_overlay_change_int_property(fdt_base); + fdt_overlay_change_str_property(fdt_base); + fdt_overlay_add_str_property(fdt_base); + fdt_overlay_add_node(fdt_base); + fdt_overlay_add_subnode_property(fdt_base); + + /* + * If the base tree has a __symbols__ node, do the tests that + * are only successful with a proper phandle support, and thus + * dtc -@ + */ + if (fdt_path_offset(fdt_base, "/__symbols__") >= 0) { + fdt_overlay_local_phandle(fdt_base); + fdt_overlay_local_phandles(fdt_base); + } + + PASS(); +} diff --git a/tests/overlay_bad_fixup.c b/tests/overlay_bad_fixup.c new file mode 100644 index 000000000000..5014f5ec0868 --- /dev/null +++ b/tests/overlay_bad_fixup.c @@ -0,0 +1,70 @@ +/* + * libfdt - Flat Device Tree manipulation + * Testcase for DT overlays() + * Copyright (C) 2016 Free Electrons + * Copyright (C) 2016 NextThing Co. + * + * 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 <stdio.h> + +#include <libfdt.h> + +#include "tests.h" + +#define CHECK(code, expected) \ + { \ + err = (code); \ + if (err != expected) \ + FAIL(#code ": %s", fdt_strerror(err)); \ + } + +/* 4k ought to be enough for anybody */ +#define FDT_COPY_SIZE (4 * 1024) + +static void *open_dt(char *path) +{ + void *dt, *copy; + int err; + + dt = load_blob(path); + copy = xmalloc(FDT_COPY_SIZE); + + /* + * Resize our DTs to 4k so that we have room to operate on + */ + CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE), 0); + + return copy; +} + +int main(int argc, char *argv[]) +{ + void *fdt_base, *fdt_overlay; + int err; + + test_init(argc, argv); + if (argc != 3) + CONFIG("Usage: %s <base dtb> <overlay dtb>", argv[0]); + + fdt_base = open_dt(argv[1]); + fdt_overlay = open_dt(argv[2]); + + /* Apply the overlay */ + CHECK(fdt_overlay_apply(fdt_base, fdt_overlay), -FDT_ERR_BADOVERLAY); + + PASS(); +} diff --git a/tests/overlay_bad_fixup_bad_index.dts b/tests/overlay_bad_fixup_bad_index.dts new file mode 100644 index 000000000000..b5cf13137169 --- /dev/null +++ b/tests/overlay_bad_fixup_bad_index.dts @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/include/ "overlay_bad_fixup_base.dtsi" + +/ { + __fixups__ { + test = "/fragment@0:target:ab"; + }; +}; diff --git a/tests/overlay_bad_fixup_base.dtsi b/tests/overlay_bad_fixup_base.dtsi new file mode 100644 index 000000000000..216bcab52263 --- /dev/null +++ b/tests/overlay_bad_fixup_base.dtsi @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/dts-v1/; + +/ { + fragment@0 { + target = <0xffffffff>; + + __overlay__ { + test-property; + }; + }; +}; diff --git a/tests/overlay_bad_fixup_empty.dts b/tests/overlay_bad_fixup_empty.dts new file mode 100644 index 000000000000..e111db4c8527 --- /dev/null +++ b/tests/overlay_bad_fixup_empty.dts @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/include/ "overlay_bad_fixup_base.dtsi" + +/ { + __fixups__ { + test = ""; + }; +}; diff --git a/tests/overlay_bad_fixup_empty_index.dts b/tests/overlay_bad_fixup_empty_index.dts new file mode 100644 index 000000000000..9e12e2177ad5 --- /dev/null +++ b/tests/overlay_bad_fixup_empty_index.dts @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/include/ "overlay_bad_fixup_base.dtsi" + +/ { + __fixups__ { + test = "/fragment@0:target:"; + }; +}; diff --git a/tests/overlay_bad_fixup_index_trailing.dts b/tests/overlay_bad_fixup_index_trailing.dts new file mode 100644 index 000000000000..f586bef4d374 --- /dev/null +++ b/tests/overlay_bad_fixup_index_trailing.dts @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/include/ "overlay_bad_fixup_base.dtsi" + +/ { + __fixups__ { + test = "/fragment@0:target:0a"; + }; +}; diff --git a/tests/overlay_bad_fixup_path_empty_prop.dts b/tests/overlay_bad_fixup_path_empty_prop.dts new file mode 100644 index 000000000000..608b5f9247b5 --- /dev/null +++ b/tests/overlay_bad_fixup_path_empty_prop.dts @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/include/ "overlay_bad_fixup_base.dtsi" + +/ { + __fixups__ { + test = "/fragment@0::"; + }; +}; diff --git a/tests/overlay_bad_fixup_path_only.dts b/tests/overlay_bad_fixup_path_only.dts new file mode 100644 index 000000000000..2485dd965ee5 --- /dev/null +++ b/tests/overlay_bad_fixup_path_only.dts @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/include/ "overlay_bad_fixup_base.dtsi" + +/ { + __fixups__ { + test = "/fragment@0"; + }; +}; diff --git a/tests/overlay_bad_fixup_path_only_sep.dts b/tests/overlay_bad_fixup_path_only_sep.dts new file mode 100644 index 000000000000..3cbf6c40fba5 --- /dev/null +++ b/tests/overlay_bad_fixup_path_only_sep.dts @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/include/ "overlay_bad_fixup_base.dtsi" + +/ { + __fixups__ { + test = "/fragment@0:"; + }; +}; diff --git a/tests/overlay_bad_fixup_path_prop.dts b/tests/overlay_bad_fixup_path_prop.dts new file mode 100644 index 000000000000..ca79b52bcb22 --- /dev/null +++ b/tests/overlay_bad_fixup_path_prop.dts @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/include/ "overlay_bad_fixup_base.dtsi" + +/ { + __fixups__ { + test = "/fragment@0:target"; + }; +}; diff --git a/tests/overlay_base.dts b/tests/overlay_base.dts new file mode 100644 index 000000000000..2603adb6821e --- /dev/null +++ b/tests/overlay_base.dts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/dts-v1/; + +/ { + test: test-node { + test-int-property = <42>; + test-str-property = "foo"; + + subtest: sub-test-node { + sub-test-property; + }; + }; +}; + + diff --git a/tests/overlay_base_manual_symbols.dts b/tests/overlay_base_manual_symbols.dts new file mode 100644 index 000000000000..7e4d17dcb06c --- /dev/null +++ b/tests/overlay_base_manual_symbols.dts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/dts-v1/; + +/ { + test: test-node { + phandle = <&test>; /* Force phandle generation */ + test-int-property = <42>; + test-str-property = "foo"; + + subtest: sub-test-node { + sub-test-property; + }; + }; + __symbols__ { + test = &test; + }; +}; + + diff --git a/tests/overlay_overlay.dts b/tests/overlay_overlay.dts new file mode 100644 index 000000000000..b6d841b1f011 --- /dev/null +++ b/tests/overlay_overlay.dts @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * Copyright (c) 2016 Konsulko Inc. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/dts-v1/; +/plugin/; + +/ { + /* Test that we can change an int by another */ + fragment@0 { + target = <&test>; + + __overlay__ { + test-int-property = <43>; + }; + }; + + /* Test that we can replace a string by a longer one */ + fragment@1 { + target = <&test>; + + __overlay__ { + test-str-property = "foobar"; + }; + }; + + /* Test that we add a new property */ + fragment@2 { + target = <&test>; + + __overlay__ { + test-str-property-2 = "foobar2"; + }; + }; + + /* Test that we add a new node (by phandle) */ + fragment@3 { + target = <&test>; + + __overlay__ { + new-node { + new-property; + }; + }; + }; + + fragment@5 { + target = <&test>; + + __overlay__ { + local: new-local-node { + new-property; + }; + }; + }; + + fragment@6 { + target = <&test>; + + __overlay__ { + test-phandle = <&test>, <&local>; + }; + }; + + fragment@7 { + target = <&test>; + + __overlay__ { + test-several-phandle = <&local>, <&local>; + }; + }; + + fragment@8 { + target = <&test>; + + __overlay__ { + sub-test-node { + new-sub-test-property; + }; + }; + }; +}; diff --git a/tests/overlay_overlay_manual_fixups.dts b/tests/overlay_overlay_manual_fixups.dts new file mode 100644 index 000000000000..e34c4fc63085 --- /dev/null +++ b/tests/overlay_overlay_manual_fixups.dts @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * Copyright (c) 2016 Konsulko Inc. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/dts-v1/; + +/* Note no /plugin/ tag - we're manually generating the metadata for + testing purposes */ + +/ { + /* Test that we can change an int by another */ + fragment@0 { + target = <0xffffffff /*&test*/>; + + __overlay__ { + test-int-property = <43>; + }; + }; + + /* Test that we can replace a string by a longer one */ + fragment@1 { + target = <0xffffffff /*&test*/>; + + __overlay__ { + test-str-property = "foobar"; + }; + }; + + /* Test that we add a new property */ + fragment@2 { + target = <0xffffffff /*&test*/>; + + __overlay__ { + test-str-property-2 = "foobar2"; + }; + }; + + /* Test that we add a new node (by phandle) */ + fragment@3 { + target = <0xffffffff /*&test*/>; + + __overlay__ { + new-node { + new-property; + }; + }; + }; + + fragment@5 { + target = <0xffffffff /*&test*/>; + + __overlay__ { + local: new-local-node { + new-property; + }; + }; + }; + + fragment@6 { + target = <0xffffffff /*&test*/>; + + __overlay__ { + test-phandle = <0xffffffff /*&test*/>, <&local>; + }; + }; + + fragment@7 { + target = <0xffffffff /*&test*/>; + + __overlay__ { + test-several-phandle = <&local>, <&local>; + }; + }; + + fragment@8 { + target = <0xffffffff /*&test*/>; + + __overlay__ { + sub-test-node { + new-sub-test-property; + }; + }; + }; + + __local_fixups__ { + fragment@6 { + __overlay__ { + test-phandle = <4>; + }; + }; + fragment@7 { + __overlay__ { + test-several-phandle = <0 4>; + }; + }; + }; + __fixups__ { + test = "/fragment@0:target:0", + "/fragment@1:target:0", + "/fragment@2:target:0", + "/fragment@3:target:0", + "/fragment@5:target:0", + "/fragment@6:target:0", + "/fragment@6/__overlay__:test-phandle:0", + "/fragment@7:target:0", + "/fragment@8:target:0"; + }; +}; diff --git a/tests/overlay_overlay_no_fixups.dts b/tests/overlay_overlay_no_fixups.dts new file mode 100644 index 000000000000..e8d0f96d889c --- /dev/null +++ b/tests/overlay_overlay_no_fixups.dts @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016 NextThing Co + * Copyright (c) 2016 Free Electrons + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/dts-v1/; + +/ { + fragment@0 { + target-path = "/test-node"; + + __overlay__ { + test-int-property = <43>; + }; + }; + + /* Test that we can replace a string by a longer one */ + fragment@1 { + target-path = "/test-node"; + + __overlay__ { + test-str-property = "foobar"; + }; + }; + + /* Test that we add a new property */ + fragment@2 { + target-path = "/test-node"; + + __overlay__ { + test-str-property-2 = "foobar2"; + }; + }; + + fragment@3 { + target-path = "/test-node"; + + __overlay__ { + new-node { + new-property; + }; + }; + }; + + fragment@4 { + target-path = "/"; + + __overlay__ { + local: new-local-node { + new-property; + }; + }; + }; + + fragment@5 { + target-path = "/"; + + __overlay__ { + test-several-phandle = <&local>, <&local>; + }; + }; + + fragment@6 { + target-path = "/test-node"; + + __overlay__ { + sub-test-node { + new-sub-test-property; + }; + }; + }; + + __local_fixups__ { + fragment@5 { + __overlay__ { + test-several-phandle = <0 4>; + }; + }; + }; +}; diff --git a/tests/overlay_overlay_simple.dts b/tests/overlay_overlay_simple.dts new file mode 100644 index 000000000000..8657e1e7a15a --- /dev/null +++ b/tests/overlay_overlay_simple.dts @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2016 Konsulko Inc. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/dts-v1/; +/plugin/; + +&test { + test-int-property = <43>; +}; diff --git a/tests/path-references.c b/tests/path-references.c index 0746b3f7e324..c8d25fb85fdd 100644 --- a/tests/path-references.c +++ b/tests/path-references.c @@ -47,6 +47,20 @@ static void check_ref(const void *fdt, int node, const char *checkpath) node, p, checkpath); } +static void check_rref(const void *fdt) +{ + const char *p; + int len; + + /* Check reference to root node */ + p = fdt_getprop(fdt, 0, "rref", &len); + if (!p) + FAIL("fdt_getprop(0, \"rref\"): %s", fdt_strerror(len)); + if (!streq(p, "/")) + FAIL("'rref' in root node has value \"%s\" instead of \"/\"", + p); +} + int main(int argc, char *argv[]) { void *fdt; @@ -78,5 +92,7 @@ int main(int argc, char *argv[]) if ((!streq(p, "/node1") || !streq(p + strlen("/node1") + 1, "/node2"))) FAIL("multiref has wrong value"); + check_rref(fdt); + PASS(); } diff --git a/tests/path-references.dts b/tests/path-references.dts index 91e7ef745aae..b00fd79061fa 100644 --- a/tests/path-references.dts +++ b/tests/path-references.dts @@ -1,6 +1,7 @@ /dts-v1/; / { + rref = &{/}; /* Check multiple references case */ multiref = &n1 , &n2; n1: node1 { diff --git a/tests/path_offset.c b/tests/path_offset.c index 4e5b7a11f70d..bfebe9fff853 100644 --- a/tests/path_offset.c +++ b/tests/path_offset.c @@ -54,58 +54,84 @@ static int check_subnode(void *fdt, int parent, const char *name) return offset; } +static void check_path_offset(void *fdt, char *path, int offset) +{ + int rc; + + verbose_printf("Checking offset of \"%s\" is %d...\n", path, offset); + + rc = fdt_path_offset(fdt, path); + if (rc < 0) + FAIL("fdt_path_offset(\"%s\") failed: %s", + path, fdt_strerror(rc)); + if (rc != offset) + FAIL("fdt_path_offset(\"%s\") returned incorrect offset" + " %d instead of %d", path, rc, offset); +} + +static void check_path_offset_namelen(void *fdt, char *path, int namelen, + int offset) +{ + int rc; + + verbose_printf("Checking offset of \"%s\" [first %d characters]" + " is %d...\n", path, namelen, offset); + + rc = fdt_path_offset_namelen(fdt, path, namelen); + if (rc == offset) + return; + + if (rc < 0) + FAIL("fdt_path_offset_namelen(\"%s\", %d) failed: %s", + path, namelen, fdt_strerror(rc)); + else + FAIL("fdt_path_offset_namelen(\"%s\", %d) returned incorrect" + " offset %d instead of %d", path, namelen, rc, offset); +} + int main(int argc, char *argv[]) { void *fdt; - int root_offset; int subnode1_offset, subnode2_offset; - int subnode1_offset_p, subnode2_offset_p; int subsubnode1_offset, subsubnode2_offset, subsubnode2_offset2; - int subsubnode1_offset_p, subsubnode2_offset_p, subsubnode2_offset2_p; test_init(argc, argv); fdt = load_blob_arg(argc, argv); - root_offset = fdt_path_offset(fdt, "/"); - if (root_offset < 0) - FAIL("fdt_path_offset(\"/\") failed: %s", - fdt_strerror(root_offset)); - else if (root_offset != 0) - FAIL("fdt_path_offset(\"/\") returns incorrect offset %d", - root_offset); + check_path_offset(fdt, "/", 0); + subnode1_offset = check_subnode(fdt, 0, "subnode@1"); subnode2_offset = check_subnode(fdt, 0, "subnode@2"); - subnode1_offset_p = fdt_path_offset(fdt, "/subnode@1"); - subnode2_offset_p = fdt_path_offset(fdt, "/subnode@2"); - - if (subnode1_offset != subnode1_offset_p) - FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)", - subnode1_offset, subnode1_offset_p); - - if (subnode2_offset != subnode2_offset_p) - FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)", - subnode2_offset, subnode2_offset_p); + check_path_offset(fdt, "/subnode@1", subnode1_offset); + check_path_offset(fdt, "/subnode@2", subnode2_offset); subsubnode1_offset = check_subnode(fdt, subnode1_offset, "subsubnode"); subsubnode2_offset = check_subnode(fdt, subnode2_offset, "subsubnode@0"); subsubnode2_offset2 = check_subnode(fdt, subnode2_offset, "subsubnode"); - subsubnode1_offset_p = fdt_path_offset(fdt, "/subnode@1/subsubnode"); - subsubnode2_offset_p = fdt_path_offset(fdt, "/subnode@2/subsubnode@0"); - subsubnode2_offset2_p = fdt_path_offset(fdt, "/subnode@2/subsubnode"); - - if (subsubnode1_offset != subsubnode1_offset_p) - FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)", - subsubnode1_offset, subsubnode1_offset_p); - - if (subsubnode2_offset != subsubnode2_offset_p) - FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)", - subsubnode2_offset, subsubnode2_offset_p); - - if (subsubnode2_offset2 != subsubnode2_offset2_p) - FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)", - subsubnode2_offset2, subsubnode2_offset2_p); + check_path_offset(fdt, "/subnode@1/subsubnode", subsubnode1_offset); + check_path_offset(fdt, "/subnode@2/subsubnode@0", subsubnode2_offset); + check_path_offset(fdt, "/subnode@2/subsubnode", subsubnode2_offset2); + + /* Test paths with extraneous separators */ + check_path_offset(fdt, "//", 0); + check_path_offset(fdt, "///", 0); + check_path_offset(fdt, "//subnode@1", subnode1_offset); + check_path_offset(fdt, "/subnode@1/", subnode1_offset); + check_path_offset(fdt, "//subnode@1///", subnode1_offset); + check_path_offset(fdt, "/subnode@2////subsubnode", subsubnode2_offset2); + + /* Test fdt_path_offset_namelen() */ + check_path_offset_namelen(fdt, "/subnode@1", 1, 0); + check_path_offset_namelen(fdt, "/subnode@1/subsubnode", 10, subnode1_offset); + check_path_offset_namelen(fdt, "/subnode@1/subsubnode", 11, subnode1_offset); + check_path_offset_namelen(fdt, "/subnode@2TRAILINGGARBAGE", 10, subnode2_offset); + check_path_offset_namelen(fdt, "/subnode@2TRAILINGGARBAGE", 11, -FDT_ERR_NOTFOUND); + check_path_offset_namelen(fdt, "/subnode@2/subsubnode@0/more", 23, subsubnode2_offset2); + check_path_offset_namelen(fdt, "/subnode@2/subsubnode@0/more", 22, -FDT_ERR_NOTFOUND); + check_path_offset_namelen(fdt, "/subnode@2/subsubnode@0/more", 24, subsubnode2_offset2); + check_path_offset_namelen(fdt, "/subnode@2/subsubnode@0/more", 25, -FDT_ERR_NOTFOUND); PASS(); } diff --git a/tests/property_iterate.c b/tests/property_iterate.c new file mode 100644 index 000000000000..0f3959cb8c22 --- /dev/null +++ b/tests/property_iterate.c @@ -0,0 +1,97 @@ +/* + * libfdt - Flat Device Tree manipulation + * Tests that fdt_next_subnode() works as expected + * + * Copyright (C) 2013 Google, Inc + * + * Copyright (C) 2007 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" + +static void test_node(void *fdt, int parent_offset) +{ + fdt32_t properties; + const fdt32_t *prop; + int offset, property; + int count; + int len; + + /* + * This property indicates the number of properties in our + * test node to expect + */ + prop = fdt_getprop(fdt, parent_offset, "test-properties", &len); + if (!prop || len != sizeof(fdt32_t)) { + FAIL("Missing/invalid test-properties property at '%s'", + fdt_get_name(fdt, parent_offset, NULL)); + } + properties = cpu_to_fdt32(*prop); + + count = 0; + offset = fdt_first_subnode(fdt, parent_offset); + if (offset < 0) + FAIL("Missing test node\n"); + + fdt_for_each_property_offset(property, fdt, offset) + count++; + + if (count != properties) { + FAIL("Node '%s': Expected %d properties, got %d\n", + fdt_get_name(fdt, parent_offset, NULL), properties, + count); + } +} + +static void check_fdt_next_subnode(void *fdt) +{ + int offset; + int count = 0; + + fdt_for_each_subnode(offset, fdt, 0) { + test_node(fdt, offset); + count++; + } + + if (count != 2) + FAIL("Expected %d tests, got %d\n", 2, count); +} + +int main(int argc, char *argv[]) +{ + void *fdt; + + test_init(argc, argv); + if (argc != 2) + CONFIG("Usage: %s <dtb file>", argv[0]); + + fdt = load_blob(argv[1]); + if (!fdt) + FAIL("No device tree available"); + + check_fdt_next_subnode(fdt); + + PASS(); +} diff --git a/tests/property_iterate.dts b/tests/property_iterate.dts new file mode 100644 index 000000000000..e8f5f8f4fedd --- /dev/null +++ b/tests/property_iterate.dts @@ -0,0 +1,23 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <0>; + + test1 { + test-properties = <3>; + + test { + linux,phandle = <0x1>; + #address-cells = <1>; + #size-cells = <0>; + }; + }; + + test2 { + test-properties = <0>; + + test { + }; + }; +}; diff --git a/tests/references.c b/tests/references.c index c9d05a2f2962..46662fc0faa7 100644 --- a/tests/references.c +++ b/tests/references.c @@ -56,6 +56,23 @@ static void check_ref(const void *fdt, int node, uint32_t checkref) node, ref, checkref); } +static void check_rref(const void *fdt) +{ + const uint32_t *p; + uint32_t ref; + int len; + + p = fdt_getprop(fdt, 0, "rref", &len); + if (!p) + FAIL("fdt_getprop(0, \"rref\"): %s", fdt_strerror(len)); + if (len != sizeof(*p)) + FAIL("'rref' in root node has wrong size (%d instead of %zd)", + len, sizeof(*p)); + ref = fdt32_to_cpu(*p); + if (ref != fdt_get_phandle(fdt, 0)) + FAIL("'rref' in root node has value 0x%x instead of 0x0", ref); +} + int main(int argc, char *argv[]) { void *fdt; @@ -104,5 +121,7 @@ int main(int argc, char *argv[]) check_ref(fdt, n2, h1); check_ref(fdt, n3, h4); + check_rref(fdt); + PASS(); } diff --git a/tests/references.dts b/tests/references.dts index 640c9315911c..f783e8bc8643 100644 --- a/tests/references.dts +++ b/tests/references.dts @@ -1,6 +1,8 @@ /dts-v1/; / { + rref = <&{/}>; + /* Explicit phandles */ n1: node1 { linux,phandle = <0x2000>; diff --git a/tests/references_dts0.dts b/tests/references_dts0.dts deleted file mode 100644 index d34dbb2913fd..000000000000 --- a/tests/references_dts0.dts +++ /dev/null @@ -1,26 +0,0 @@ -/dts-v1/; - -/ { - /* Explicit phandles */ - n1: node1 { - linux,phandle = <0x2000>; - ref = <&{/node2}>; /* reference precedes target */ - lref = <&n2>; - }; - n2: node2 { - linux,phandle = <0x1>; - ref = <&{/node1}>; /* reference after target */ - lref = <&n1>; - }; - - /* Implicit phandles */ - n3: node3 { - ref = <&{/node4}>; - lref = <&n4>; - }; - n4: node4 { - }; - n5: node5 { - linux,phandle = <&n5>; - }; -}; diff --git a/tests/reg-without-unit-addr.dts b/tests/reg-without-unit-addr.dts new file mode 100644 index 000000000000..aaf8af7a8cd2 --- /dev/null +++ b/tests/reg-without-unit-addr.dts @@ -0,0 +1,10 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + node { + reg = <0 1>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 97e016b1aef9..ed489dbdd269 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -42,20 +42,20 @@ base_run_test() { shorten_echo () { limit=32 - echo -n "$1" + printf "$1" shift for x; do if [ ${#x} -le $limit ]; then - echo -n " $x" + printf " $x" else short=$(echo "$x" | head -c$limit) - echo -n " \"$short\"...<${#x} bytes>" + printf " \"$short\"...<${#x} bytes>" fi done } run_test () { - echo -n "$@: " + printf "$*: " if [ -n "$VALGRIND" -a -f $1.supp ]; then VGSUPP="--suppressions=$1.supp" fi @@ -63,7 +63,7 @@ run_test () { } run_sh_test () { - echo -n "$@: " + printf "$*: " base_run_test sh "$@" } @@ -106,12 +106,27 @@ wrap_error () { run_wrap_error_test () { shorten_echo "$@" - echo -n " {!= 0}: " + printf " {!= 0}: " base_run_test wrap_error "$@" } +# $1: dtb file +# $2: align base +check_align () { + shorten_echo "check_align $@: " + local size=$(stat -c %s "$1") + local align="$2" + ( + if [ $(($size % $align)) -eq 0 ] ;then + PASS + else + FAIL "Output size $size is not $align-byte aligned" + fi + ) +} + run_dtc_test () { - echo -n "dtc $@: " + printf "dtc $*: " base_run_test wrap_test $VALGRIND $DTC "$@" } @@ -126,7 +141,7 @@ asm_to_so_test () { run_fdtget_test () { expect="$1" shift - echo -n "fdtget-runtest.sh "$expect" $@: " + printf "fdtget-runtest.sh %s $*: " "$(echo $expect)" base_run_test sh fdtget-runtest.sh "$expect" "$@" } @@ -134,10 +149,90 @@ run_fdtput_test () { expect="$1" shift shorten_echo fdtput-runtest.sh "$expect" "$@" - echo -n ": " + printf ": " base_run_test sh fdtput-runtest.sh "$expect" "$@" } +run_fdtdump_test() { + file="$1" + shorten_echo fdtdump-runtest.sh "$file" + printf ": " + base_run_test sh fdtdump-runtest.sh "$file" +} + +BAD_FIXUP_TREES="bad_index \ + empty \ + empty_index \ + index_trailing \ + path_empty_prop \ + path_only \ + path_only_sep \ + path_prop" + +# Test to exercise libfdt overlay application without dtc's overlay support +libfdt_overlay_tests () { + # First test a doctored overlay which requires only local fixups + run_dtc_test -I dts -O dtb -o overlay_base_no_symbols.test.dtb overlay_base.dts + run_test check_path overlay_base_no_symbols.test.dtb not-exists "/__symbols__" + run_test check_path overlay_base_no_symbols.test.dtb not-exists "/__fixups__" + run_test check_path overlay_base_no_symbols.test.dtb not-exists "/__local_fixups__" + + run_dtc_test -I dts -O dtb -o overlay_overlay_no_fixups.test.dtb overlay_overlay_no_fixups.dts + run_test check_path overlay_overlay_no_fixups.test.dtb not-exists "/__symbols__" + run_test check_path overlay_overlay_no_fixups.test.dtb not-exists "/__fixups__" + run_test check_path overlay_overlay_no_fixups.test.dtb exists "/__local_fixups__" + + run_test overlay overlay_base_no_symbols.test.dtb overlay_overlay_no_fixups.test.dtb + + # Then test with manually constructed fixups + run_dtc_test -I dts -O dtb -o overlay_base_manual_symbols.test.dtb overlay_base_manual_symbols.dts + run_test check_path overlay_base_manual_symbols.test.dtb exists "/__symbols__" + run_test check_path overlay_base_manual_symbols.test.dtb not-exists "/__fixups__" + run_test check_path overlay_base_manual_symbols.test.dtb not-exists "/__local_fixups__" + + run_dtc_test -I dts -O dtb -o overlay_overlay_manual_fixups.test.dtb overlay_overlay_manual_fixups.dts + run_test check_path overlay_overlay_manual_fixups.test.dtb not-exists "/__symbols__" + run_test check_path overlay_overlay_manual_fixups.test.dtb exists "/__fixups__" + run_test check_path overlay_overlay_manual_fixups.test.dtb exists "/__local_fixups__" + + run_test overlay overlay_base_manual_symbols.test.dtb overlay_overlay_manual_fixups.test.dtb + + # Bad fixup tests + for test in $BAD_FIXUP_TREES; do + tree="overlay_bad_fixup_$test" + run_dtc_test -I dts -O dtb -o $tree.test.dtb $tree.dts + run_test overlay_bad_fixup overlay_base_no_symbols.test.dtb $tree.test.dtb + done +} + +# Tests to exercise dtc's overlay generation support +dtc_overlay_tests () { + # Overlay tests for dtc + run_dtc_test -@ -I dts -O dtb -o overlay_base.test.dtb overlay_base.dts + run_test check_path overlay_base.test.dtb exists "/__symbols__" + run_test check_path overlay_base.test.dtb not-exists "/__fixups__" + run_test check_path overlay_base.test.dtb not-exists "/__local_fixups__" + + run_dtc_test -I dts -O dtb -o overlay_overlay.test.dtb overlay_overlay.dts + run_test check_path overlay_overlay.test.dtb not-exists "/__symbols__" + run_test check_path overlay_overlay.test.dtb exists "/__fixups__" + run_test check_path overlay_overlay.test.dtb exists "/__local_fixups__" + + run_test overlay overlay_base.test.dtb overlay_overlay.test.dtb + + # test plugin source to dtb and back + run_dtc_test -I dtb -O dts -o overlay_overlay_decompile.test.dts overlay_overlay.test.dtb + run_dtc_test -I dts -O dtb -o overlay_overlay_decompile.test.dtb overlay_overlay_decompile.test.dts + run_test dtbs_equal_ordered overlay_overlay.test.dtb overlay_overlay_decompile.test.dtb + + # Test generation of aliases insted of symbols + run_dtc_test -A -I dts -O dtb -o overlay_base_with_aliases.dtb overlay_base.dts + run_test check_path overlay_base_with_aliases.dtb exists "/aliases" + run_test check_path overlay_base_with_aliases.dtb not-exists "/__symbols__" + run_test check_path overlay_base_with_aliases.dtb not-exists "/__fixups__" + run_test check_path overlay_base_with_aliases.dtb not-exists "/__local_fixups__" +} + tree1_tests () { TREE=$1 @@ -188,6 +283,12 @@ ALL_LAYOUTS="mts mst tms tsm smt stm" libfdt_tests () { tree1_tests test_tree1.dtb + run_dtc_test -I dts -O dtb -o addresses.test.dtb addresses.dts + run_test addr_size_cells addresses.test.dtb + + run_dtc_test -I dts -O dtb -o stringlist.test.dtb stringlist.dts + run_test stringlist stringlist.test.dtb + # Sequential write tests run_test sw_tree1 tree1_tests sw_tree1.test.dtb @@ -245,6 +346,7 @@ libfdt_tests () { run_test appendprop2 appendprop1.test.dtb run_dtc_test -I dts -O dtb -o appendprop.test.dtb appendprop.dts run_test dtbs_equal_ordered appendprop2.test.dtb appendprop.test.dtb + libfdt_overlay_tests for basetree in test_tree1.dtb sw_tree1.test.dtb rw_tree1.test.dtb; do run_test nopulate $basetree @@ -256,11 +358,37 @@ libfdt_tests () { run_dtc_test -I dts -O dtb -o subnode_iterate.dtb subnode_iterate.dts run_test subnode_iterate subnode_iterate.dtb + run_dtc_test -I dts -O dtb -o property_iterate.dtb property_iterate.dts + run_test property_iterate property_iterate.dtb + # Tests for behaviour on various sorts of corrupted trees run_test truncated_property + # 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 + # Specific bug tests run_test add_subnode_with_nops + run_dtc_test -I dts -O dts -o sourceoutput.test.dts sourceoutput.dts + run_dtc_test -I dts -O dtb -o sourceoutput.test.dtb sourceoutput.dts + run_dtc_test -I dts -O dtb -o sourceoutput.test.dts.test.dtb sourceoutput.test.dts + run_test dtbs_equal_ordered sourceoutput.test.dtb sourceoutput.test.dts.test.dtb + + run_dtc_test -I dts -O dtb -o embedded_nul.test.dtb embedded_nul.dts + run_dtc_test -I dts -O dtb -o embedded_nul_equiv.test.dtb embedded_nul_equiv.dts + run_test dtbs_equal_ordered embedded_nul.test.dtb embedded_nul_equiv.test.dtb + + run_dtc_test -I dts -O dtb bad-size-cells.dts + + run_wrap_error_test $DTC division-by-zero.dts + run_wrap_error_test $DTC bad-octal-literal.dts + run_dtc_test -I dts -O dtb nul-in-escape.dts + run_wrap_error_test $DTC nul-in-line-info1.dts + run_wrap_error_test $DTC nul-in-line-info2.dts + + run_wrap_error_test $DTC -I dtb -O dts -o /dev/null ovf_size_strings.dtb } dtc_tests () { @@ -307,11 +435,6 @@ dtc_tests () { run_dtc_test -I dts -O dtb -o dtc_comments-cmp.test.dtb comments-cmp.dts run_test dtbs_equal_ordered dtc_comments.test.dtb dtc_comments-cmp.test.dtb - # 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 run_dtc_test -I dts -O dtb -o includes.test.dtb include0.dts run_test dtbs_equal_ordered includes.test.dtb test_tree1.dtb @@ -381,11 +504,14 @@ dtc_tests () { tree1_tests dtc_tree1_merge.test.dtb test_tree1.dtb run_dtc_test -I dts -O dtb -o dtc_tree1_merge_labelled.test.dtb test_tree1_merge_labelled.dts tree1_tests dtc_tree1_merge_labelled.test.dtb test_tree1.dtb + run_dtc_test -I dts -O dtb -o dtc_tree1_label_noderef.test.dtb test_tree1_label_noderef.dts + run_test dtbs_equal_unordered dtc_tree1_label_noderef.test.dtb test_tree1.dtb run_dtc_test -I dts -O dtb -o multilabel_merge.test.dtb multilabel_merge.dts run_test references multilabel.test.dtb run_test dtbs_equal_ordered multilabel.test.dtb multilabel_merge.test.dtb run_dtc_test -I dts -O dtb -o dtc_tree1_merge_path.test.dtb test_tree1_merge_path.dts tree1_tests dtc_tree1_merge_path.test.dtb test_tree1.dtb + run_wrap_error_test $DTC -I dts -O dtb -o /dev/null test_label_ref.dts # Check prop/node delete functionality run_dtc_test -I dts -O dtb -o dtc_tree1_delete.test.dtb test_tree1_delete.dts @@ -412,6 +538,8 @@ dtc_tests () { check_tests reg-ranges-root.dts reg_format ranges_format check_tests default-addr-size.dts avoid_default_addr_size check_tests obsolete-chosen-interrupt-controller.dts obsolete_chosen_interrupt_controller + check_tests reg-without-unit-addr.dts unit_address_vs_reg + check_tests unit-addr-without-reg.dts unit_address_vs_reg run_sh_test dtc-checkfails.sh node_name_chars -- -I dtb -O dtb bad_node_char.dtb run_sh_test dtc-checkfails.sh node_name_format -- -I dtb -O dtb bad_node_format.dtb run_sh_test dtc-checkfails.sh prop_name_chars -- -I dtb -O dtb bad_prop_char.dtb @@ -423,6 +551,9 @@ dtc_tests () { run_sh_test dtc-checkfails.sh duplicate_label -- -I dts -O dtb reuse-label5.dts run_sh_test dtc-checkfails.sh duplicate_label -- -I dts -O dtb reuse-label6.dts + run_test check_path test_tree1.dtb exists "/subnode@1" + run_test check_path test_tree1.dtb not-exists "/subnode@10" + # Check warning options run_sh_test dtc-checkfails.sh address_cells_is_cell interrupt_cells_is_cell -n size_cells_is_cell -- -Wno_size_cells_is_cell -I dts -O dtb bad-ncells.dts run_sh_test dtc-fails.sh -n test-warn-output.test.dtb -I dts -O dtb bad-ncells.dts @@ -465,6 +596,19 @@ dtc_tests () { -o search_paths_b.dtb search_paths_b.dts run_dtc_test -I dts -O dtb -o search_paths_subdir.dtb \ search_dir_b/search_paths_subdir.dts + + # Check -a option + for align in 2 4 8 16 32 64; do + # -p -a + run_dtc_test -O dtb -p 1000 -a $align -o align0.dtb subnode_iterate.dts + check_align align0.dtb $align + # -S -a + run_dtc_test -O dtb -S 1999 -a $align -o align1.dtb subnode_iterate.dts + check_align align1.dtb $align + done + + # Tests for overlay/plugin generation + dtc_overlay_tests } cmp_tests () { @@ -592,6 +736,28 @@ fdtput_tests () { run_wrap_test $DTPUT $dtb -cp /chosen run_wrap_test $DTPUT $dtb -cp /chosen/son + # Start again with a fresh dtb + run_dtc_test -O dtb -p $(stat -c %s $text) -o $dtb $dts + + # Node delete + run_wrap_test $DTPUT $dtb -c /chosen/node1 /chosen/node2 /chosen/node3 + run_fdtget_test "node3\nnode2\nnode1" $dtb -l /chosen + run_wrap_test $DTPUT $dtb -r /chosen/node1 /chosen/node2 + run_fdtget_test "node3" $dtb -l /chosen + + # Delete the non-existent node + run_wrap_error_test $DTPUT $dtb -r /non-existent/node + + # Property delete + run_fdtput_test "eva" $dtb /chosen/ name "" -ts "eva" + run_fdtput_test "016" $dtb /chosen/ age "" -ts "016" + run_fdtget_test "age\nname\nbootargs\nlinux,platform" $dtb -p /chosen + run_wrap_test $DTPUT $dtb -d /chosen/ name age + run_fdtget_test "bootargs\nlinux,platform" $dtb -p /chosen + + # Delete the non-existent property + run_wrap_error_test $DTPUT $dtb -d /chosen non-existent-prop + # TODO: Add tests for verbose mode? } @@ -599,6 +765,10 @@ utilfdt_tests () { run_test utilfdt_test } +fdtdump_tests () { + run_fdtdump_test fdtdump.dts +} + while getopts "vt:me" ARG ; do case $ARG in "v") @@ -617,7 +787,7 @@ while getopts "vt:me" ARG ; do done if [ -z "$TESTSETS" ]; then - TESTSETS="libfdt utilfdt dtc dtbs_equal fdtget fdtput" + TESTSETS="libfdt utilfdt dtc dtbs_equal fdtget fdtput fdtdump" fi # Make sure we don't have stale blobs lying around @@ -643,6 +813,9 @@ for set in $TESTSETS; do "fdtput") fdtput_tests ;; + "fdtdump") + fdtdump_tests + ;; esac done diff --git a/tests/setprop.c b/tests/setprop.c index d089f8d5ab5e..be1b1478f7f0 100644 --- a/tests/setprop.c +++ b/tests/setprop.c @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) TEST_STRING_1); verbose_printf("Old string value was \"%s\"\n", strp); - err = fdt_setprop(fdt, 0, "prop-str", NULL, 0); + err = fdt_setprop_empty(fdt, 0, "prop-str"); if (err) FAIL("Failed to empty \"prop-str\": %s", fdt_strerror(err)); diff --git a/tests/setprop_inplace.c b/tests/setprop_inplace.c index daef182d0b28..80447a0b13ab 100644 --- a/tests/setprop_inplace.c +++ b/tests/setprop_inplace.c @@ -83,5 +83,15 @@ int main(int argc, char *argv[]) strp = check_getprop(fdt, 0, "prop-str", xlen+1, xstr); verbose_printf("New string value is \"%s\"\n", strp); + err = fdt_setprop_inplace_namelen_partial(fdt, 0, "compatible", + strlen("compatible"), 4, + TEST_STRING_4_PARTIAL, + strlen(TEST_STRING_4_PARTIAL)); + if (err) + FAIL("Failed to set \"compatible\": %s\n", fdt_strerror(err)); + + check_getprop(fdt, 0, "compatible", strlen(TEST_STRING_4_RESULT) + 1, + TEST_STRING_4_RESULT); + PASS(); } diff --git a/tests/sourceoutput.dts b/tests/sourceoutput.dts new file mode 100644 index 000000000000..477762f5aaa7 --- /dev/null +++ b/tests/sourceoutput.dts @@ -0,0 +1,14 @@ +/dts-v1/; + +/ { + /* Some versions had an off-by-2 bug which caused an abort + * when outputing labels within strings like this in source + * format */ + prop1: prop1 = start1: "foo", mid1: "bar" end1: ; + + /* Make sure that we correctly handle source output of things + * which could almost be expressed as strings, except for the + * embedded labels */ + prop2 = start2: [66 6f 6f], mid2: "bar" end2: ; +}; + diff --git a/tests/stringlist.c b/tests/stringlist.c new file mode 100644 index 000000000000..a9d3e73920ca --- /dev/null +++ b/tests/stringlist.c @@ -0,0 +1,154 @@ +/* + * libfdt - Flat Device Tree manipulation + * Testcase for string handling + * Copyright (C) 2015 NVIDIA 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" + +static void check_expected_failure(const void *fdt, const char *path, + const char *property) +{ + int offset, err; + + offset = fdt_path_offset(fdt, "/"); + if (offset < 0) + FAIL("Couldn't find path %s", path); + + err = fdt_stringlist_count(fdt, offset, "#address-cells"); + if (err != -FDT_ERR_BADVALUE) + FAIL("unexpectedly succeeded in parsing #address-cells\n"); + + err = fdt_stringlist_search(fdt, offset, "#address-cells", "foo"); + if (err != -FDT_ERR_BADVALUE) + FAIL("found string in #address-cells: %d\n", err); + + /* + * Note that the #address-cells property contains a small 32-bit + * unsigned integer, hence some bytes will be zero, and searching for + * the empty string will succeed. + * + * The reason for this oddity is that the function will exit when the + * first occurrence of the string is found, but in order to determine + * that the property does not contain a valid string list it would + * need to process the whole value. + */ + 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, + const char *property, int count) +{ + int offset, err; + + offset = fdt_path_offset(fdt, path); + if (offset < 0) + FAIL("Couldn't find path %s", path); + + err = fdt_stringlist_count(fdt, offset, property); + if (err < 0) + FAIL("Couldn't count strings in property %s of node %s: %d\n", + property, path, err); + + if (err != count) + FAIL("String count for property %s of node %s is %d instead of %d\n", + path, property, err, count); +} + +static void check_string_index(const void *fdt, const char *path, + const char *property, const char *string, + int idx) +{ + int offset, err; + + offset = fdt_path_offset(fdt, path); + if (offset < 0) + FAIL("Couldn't find path %s", path); + + err = fdt_stringlist_search(fdt, offset, property, string); + + if (err != idx) + FAIL("Index of %s in property %s of node %s is %d, expected %d\n", + 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; + + if (argc != 2) + CONFIG("Usage: %s <dtb file>\n", argv[0]); + + test_init(argc, argv); + fdt = load_blob(argv[1]); + + check_expected_failure(fdt, "/", "#address-cells"); + check_expected_failure(fdt, "/", "#size-cells"); + + check_string_count(fdt, "/", "compatible", 1); + check_string_count(fdt, "/device", "compatible", 2); + check_string_count(fdt, "/device", "big-endian", 0); + + check_string_index(fdt, "/", "compatible", "test-strings", 0); + check_string_index(fdt, "/device", "compatible", "foo", 0); + 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(); +} diff --git a/tests/stringlist.dts b/tests/stringlist.dts new file mode 100644 index 000000000000..1e4d3140458f --- /dev/null +++ b/tests/stringlist.dts @@ -0,0 +1,12 @@ +/dts-v1/; + +/ { + compatible = "test-strings"; + #address-cells = <2>; + #size-cells = <2>; + + device { + compatible = "foo", "bar"; + big-endian; + }; +}; diff --git a/tests/subnode_iterate.c b/tests/subnode_iterate.c index b9f379d5963c..0fb5c901ebd7 100644 --- a/tests/subnode_iterate.c +++ b/tests/subnode_iterate.c @@ -48,9 +48,7 @@ static void test_node(void *fdt, int parent_offset) subnodes = cpu_to_fdt32(*prop); count = 0; - for (offset = fdt_first_subnode(fdt, parent_offset); - offset >= 0; - offset = fdt_next_subnode(fdt, offset)) + fdt_for_each_subnode(offset, fdt, parent_offset) count++; if (count != subnodes) { @@ -65,9 +63,7 @@ static void check_fdt_next_subnode(void *fdt) int offset; int count = 0; - for (offset = fdt_first_subnode(fdt, 0); - offset >= 0; - offset = fdt_next_subnode(fdt, offset)) { + fdt_for_each_subnode(offset, fdt, 0) { test_node(fdt, offset); count++; } diff --git a/tests/test_label_ref.dts b/tests/test_label_ref.dts new file mode 100644 index 000000000000..7009c79531a7 --- /dev/null +++ b/tests/test_label_ref.dts @@ -0,0 +1,9 @@ +/dts-v1/; + +/ { + +}; + +label: &handle { + +}; diff --git a/tests/test_tree1.dts b/tests/test_tree1.dts index c7b170c5af60..67ecfd0ea28f 100644 --- a/tests/test_tree1.dts +++ b/tests/test_tree1.dts @@ -1,3 +1,45 @@ /dts-v1/; -/include/ "test_tree1_body.dtsi" +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; + +/ { + compatible = "test_tree1"; + prop-int = <0xdeadbeef>; + prop-int64 = /bits/ 64 <0xdeadbeef01abcdef>; + prop-str = "hello world"; + #address-cells = <1>; + #size-cells = <0>; + + subnode@1 { + compatible = "subnode1"; + reg = <1>; + prop-int = [deadbeef]; + + subsubnode { + compatible = "subsubnode1", "subsubnode"; + prop-int = <0xdeadbeef>; + }; + + ss1 { + }; + }; + + subnode@2 { + reg = <2>; + linux,phandle = <0x2000>; + prop-int = <123456789>; + #address-cells = <1>; + #size-cells = <0>; + + ssn0: subsubnode@0 { + reg = <0>; + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + + ss2 { + }; + }; +}; diff --git a/tests/test_tree1_delete.dts b/tests/test_tree1_delete.dts index a2f1bfdc51c9..b95ef1e7185f 100644 --- a/tests/test_tree1_delete.dts +++ b/tests/test_tree1_delete.dts @@ -1,6 +1,6 @@ /dts-v1/; -/include/ "test_tree1_body.dtsi" +/include/ "test_tree1.dts" / { nonexistant-property = <0xdeadbeef>; diff --git a/tests/test_tree1_dts0.dts b/tests/test_tree1_dts0.dts deleted file mode 100644 index 032d540abc08..000000000000 --- a/tests/test_tree1_dts0.dts +++ /dev/null @@ -1,37 +0,0 @@ -/dts-v1/; - -/memreserve/ 0xdeadbeef00000000 0x0000000000100000; -/memreserve/ 0x00000000075bcd15 0x0000000000001000; - -/ { - compatible = "test_tree1"; - prop-int = <0xdeadbeef>; - prop-str = "hello world"; - - subnode@1 { - compatible = "subnode1"; - prop-int = [deadbeef]; - - subsubnode { - compatible = "subsubnode1", "subsubnode"; - prop-int = < 0xdeadbeef>; - }; - - ss1 { - }; - }; - - subnode@2 { - linux,phandle = <0x2000>; - prop-int = < 123456789>; - - subsubnode@0 { - linux,phandle = <0x2001>; - compatible = "subsubnode2", "subsubnode"; - prop-int = < 0726746425>; - }; - - ss2 { - }; - }; -}; diff --git a/tests/test_tree1_body.dtsi b/tests/test_tree1_label_noderef.dts index 24a5e1ee35d0..b2b194c6df64 100644 --- a/tests/test_tree1_body.dtsi +++ b/tests/test_tree1_label_noderef.dts @@ -1,3 +1,5 @@ +/dts-v1/; + /memreserve/ 0xdeadbeef00000000 0x100000; /memreserve/ 123456789 010000; @@ -31,13 +33,23 @@ #size-cells = <0>; ssn0: subsubnode@0 { - reg = <0>; phandle = <0x2001>; - compatible = "subsubnode2", "subsubnode"; - prop-int = <0726746425>; + prop-int = <0xbad>; }; ss2 { }; }; }; + +/* Add label to a noderef */ +ssn1: &ssn0 { + reg = <0>; + prop-int = <123456789>; +}; + +/* Use the new label for merging */ +&ssn1 { + prop-int = <0726746425>; + compatible = "subsubnode2", "subsubnode"; +}; diff --git a/tests/testdata.h b/tests/testdata.h index ce715e4c679e..3588778ad159 100644 --- a/tests/testdata.h +++ b/tests/testdata.h @@ -21,6 +21,9 @@ #define TEST_STRING_2 "nastystring: \a\b\t\n\v\f\r\\\"" #define TEST_STRING_3 "\xde\xad\xbe\xef" +#define TEST_STRING_4_PARTIAL "foobar" +#define TEST_STRING_4_RESULT "testfoobar" + #define TEST_CHAR1 '\r' #define TEST_CHAR2 'b' #define TEST_CHAR3 '\0' @@ -33,4 +36,5 @@ extern struct fdt_header _truncated_property; extern struct fdt_header _bad_node_char; extern struct fdt_header _bad_node_format; extern struct fdt_header _bad_prop_char; +extern struct fdt_header _ovf_size_strings; #endif /* ! __ASSEMBLY */ diff --git a/tests/tests.sh b/tests/tests.sh index 31530d5e228f..818fd09c2ff0 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -21,6 +21,7 @@ FAIL_IF_SIGNAL () { DTC=../dtc DTGET=../fdtget DTPUT=../fdtput +FDTDUMP=../fdtdump verbose_run () { if [ -z "$QUIET_TEST" ]; then diff --git a/tests/testutils.c b/tests/testutils.c index f185133a82b5..521f4f1eaf99 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -144,7 +144,6 @@ int nodename_eq(const char *s1, const char *s2) { int len = strlen(s2); - len = strlen(s2); if (strncmp(s1, s2, len) != 0) return 0; if (s1[len] == '\0') diff --git a/tests/trees.S b/tests/trees.S index 2389cd379621..3d24aa2dcbc8 100644 --- a/tests/trees.S +++ b/tests/trees.S @@ -209,3 +209,34 @@ bad_prop_char_strings: STRING(bad_prop_char, prop, "prop$erty") bad_prop_char_strings_end: bad_prop_char_end: + + + /* overflow_size_strings */ + .balign 8 + .globl _ovf_size_strings +_ovf_size_strings: +ovf_size_strings: + FDTLONG(FDT_MAGIC) + FDTLONG(ovf_size_strings_end - ovf_size_strings) + FDTLONG(ovf_size_strings_struct - ovf_size_strings) + FDTLONG(ovf_size_strings_strings - ovf_size_strings) + FDTLONG(ovf_size_strings_rsvmap - ovf_size_strings) + FDTLONG(0x11) + FDTLONG(0x10) + FDTLONG(0) + FDTLONG(0xffffffff) + FDTLONG(ovf_size_strings_struct_end - ovf_size_strings_struct) + EMPTY_RSVMAP(ovf_size_strings) + +ovf_size_strings_struct: + BEGIN_NODE("") + PROP_INT(ovf_size_strings, bad_string, 0) + END_NODE + FDTLONG(FDT_END) +ovf_size_strings_struct_end: + +ovf_size_strings_strings: + STRING(ovf_size_strings, x, "x") + ovf_size_strings_bad_string = ovf_size_strings_strings + 0x10000000 +ovf_size_strings_strings_end: +ovf_size_strings_end: diff --git a/tests/unit-addr-without-reg.dts b/tests/unit-addr-without-reg.dts new file mode 100644 index 000000000000..ac786ebb6bb8 --- /dev/null +++ b/tests/unit-addr-without-reg.dts @@ -0,0 +1,9 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + node@1 { + }; +}; |