diff options
Diffstat (limited to 'tests')
52 files changed, 1766 insertions, 0 deletions
diff --git a/tests/appendprop.dts b/tests/appendprop.dts new file mode 100644 index 000000000000..f4bc730e5659 --- /dev/null +++ b/tests/appendprop.dts @@ -0,0 +1,8 @@ +/dts-v1/; + +/ { + prop-str = "hello world", "nastystring: \a\b\t\n\v\f\r\\\""; + prop-int64 = /bits/ 64 <0xdeadbeef01abcdef 0xdeadbeef01abcdef>; + prop-int = <0xdeadbeef 123456789>; + prop-bytes = [00010203040001020304]; +}; diff --git a/tests/appendprop1.c b/tests/appendprop1.c new file mode 100644 index 000000000000..d716f7afde6f --- /dev/null +++ b/tests/appendprop1.c @@ -0,0 +1,71 @@ +/* + * libfdt - Flat Device Tree manipulation + * Testcase for fdt_appendprop() + * 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 <ctype.h> +#include <stdint.h> + +#include <fdt.h> +#include <libfdt.h> + +#include "tests.h" +#include "testdata.h" + +#define SPACE 65536 + +#define CHECK(code) \ + { \ + err = (code); \ + if (err) \ + FAIL(#code ": %s", fdt_strerror(err)); \ + } + +int main(int argc, char *argv[]) +{ + void *fdt; + int err; + uint8_t bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04}; + + test_init(argc, argv); + + /* Create an empty tree first */ + fdt = xmalloc(SPACE); + CHECK(fdt_create(fdt, SPACE)); + CHECK(fdt_finish_reservemap(fdt)); + CHECK(fdt_begin_node(fdt, "")); + CHECK(fdt_end_node(fdt)); + CHECK(fdt_finish(fdt)); + + /* Now use appendprop to add properties */ + CHECK(fdt_open_into(fdt, fdt, SPACE)); + + CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes))); + CHECK(fdt_appendprop_cell(fdt, 0, "prop-int", TEST_VALUE_1)); + CHECK(fdt_appendprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1)); + CHECK(fdt_appendprop_string(fdt, 0, "prop-str", TEST_STRING_1)); + + CHECK(fdt_pack(fdt)); + + save_blob("appendprop1.test.dtb", fdt); + + PASS(); +} diff --git a/tests/appendprop2.c b/tests/appendprop2.c new file mode 100644 index 000000000000..7eb243dfa36e --- /dev/null +++ b/tests/appendprop2.c @@ -0,0 +1,65 @@ +/* + * libfdt - Flat Device Tree manipulation + * Testcase for fdt_appendprop() + * 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 <ctype.h> +#include <stdint.h> + +#include <fdt.h> +#include <libfdt.h> + +#include "tests.h" +#include "testdata.h" + +#define SPACE 65536 + +#define CHECK(code) \ + { \ + err = (code); \ + if (err) \ + FAIL(#code ": %s", fdt_strerror(err)); \ + } + +int main(int argc, char *argv[]) +{ + void *fdt, *buf; + int err; + uint8_t bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04}; + + test_init(argc, argv); + fdt = load_blob_arg(argc, argv); + + buf = xmalloc(SPACE); + CHECK(fdt_open_into(fdt, buf, SPACE)); + fdt = buf; + + CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes))); + CHECK(fdt_appendprop_cell(fdt, 0, "prop-int", TEST_VALUE_2)); + CHECK(fdt_appendprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1)); + CHECK(fdt_appendprop_string(fdt, 0, "prop-str", TEST_STRING_2)); + + CHECK(fdt_pack(fdt)); + + save_blob("appendprop2.test.dtb", fdt); + + PASS(); +} diff --git a/tests/boot-cpuid.dts b/tests/boot-cpuid.dts new file mode 100644 index 000000000000..7021a241f939 --- /dev/null +++ b/tests/boot-cpuid.dts @@ -0,0 +1,16 @@ +/dts-v1/; + +/ { + cpus { + cpu@10 { + device_type = "cpu"; + compatible = "fake-cpu"; + reg = <0x10>; + }; + cpu@11 { + device_type = "cpu"; + compatible = "fake-cpu"; + reg = <0x11>; + }; + }; +}; diff --git a/tests/char_literal.c b/tests/char_literal.c new file mode 100644 index 000000000000..150f2a0c1488 --- /dev/null +++ b/tests/char_literal.c @@ -0,0 +1,50 @@ +/* + * libfdt - Flat Device Tree manipulation + * Testcase for character literals in dtc + * Copyright (C) 2006 David Gibson, IBM Corporation. + * Copyright (C) 2011 The Chromium Authors. All rights reserved. + * + * 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" + +int main(int argc, char *argv[]) +{ + void *fdt; + uint32_t expected_cells[5]; + + expected_cells[0] = cpu_to_fdt32((unsigned char)TEST_CHAR1); + expected_cells[1] = cpu_to_fdt32((unsigned char)TEST_CHAR2); + expected_cells[2] = cpu_to_fdt32((unsigned char)TEST_CHAR3); + expected_cells[3] = cpu_to_fdt32((unsigned char)TEST_CHAR4); + expected_cells[4] = cpu_to_fdt32((unsigned char)TEST_CHAR5); + + test_init(argc, argv); + fdt = load_blob_arg(argc, argv); + + check_getprop(fdt, 0, "char-literal-cells", + sizeof(expected_cells), expected_cells); + + PASS(); +} diff --git a/tests/char_literal.dts b/tests/char_literal.dts new file mode 100644 index 000000000000..22e17edaf7b1 --- /dev/null +++ b/tests/char_literal.dts @@ -0,0 +1,5 @@ +/dts-v1/; + +/ { + char-literal-cells = <'\r' 'b' '\0' '\'' '\xff'>; +}; diff --git a/tests/dependencies.cmp b/tests/dependencies.cmp new file mode 100644 index 000000000000..bcd94320b0cb --- /dev/null +++ b/tests/dependencies.cmp @@ -0,0 +1 @@ +dependencies.test.dtb: dependencies.dts deps_inc1.dtsi deps_inc2.dtsi diff --git a/tests/dependencies.dts b/tests/dependencies.dts new file mode 100644 index 000000000000..2cfe31bd09b9 --- /dev/null +++ b/tests/dependencies.dts @@ -0,0 +1,6 @@ +/dts-v1/; + +/include/ "deps_inc1.dtsi" + +/ { +}; diff --git a/tests/deps_inc1.dtsi b/tests/deps_inc1.dtsi new file mode 100644 index 000000000000..5c607dcf0337 --- /dev/null +++ b/tests/deps_inc1.dtsi @@ -0,0 +1 @@ +/include/ "deps_inc2.dtsi" diff --git a/tests/deps_inc2.dtsi b/tests/deps_inc2.dtsi new file mode 100644 index 000000000000..710cecca972d --- /dev/null +++ b/tests/deps_inc2.dtsi @@ -0,0 +1 @@ +/* Empty */ diff --git a/tests/dtb_reverse.c b/tests/dtb_reverse.c new file mode 100644 index 000000000000..25e1eef81775 --- /dev/null +++ b/tests/dtb_reverse.c @@ -0,0 +1,164 @@ +/* + * libfdt - Flat Device Tree manipulation + * Tests if two given dtbs are structurally equal (including order) + * Copyright (C) 2010 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 <limits.h> + +#include <fdt.h> +#include <libfdt.h> + +#include "tests.h" +#include "testdata.h" + +#define CHECK(code) \ + { \ + err = (code); \ + if (err) \ + FAIL(#code ": %s", fdt_strerror(err)); \ + } + +static void reverse_reservemap(void *in, void *out, int n) +{ + int err; + uint64_t addr, size; + + verbose_printf("reverse_reservemap(): %d/%d\n", + n, fdt_num_mem_rsv(in)); + + if (n < (fdt_num_mem_rsv(in)-1)) + reverse_reservemap(in, out, n+1); + + CHECK(fdt_get_mem_rsv(in, n, &addr, &size)); + CHECK(fdt_add_reservemap_entry(out, addr, size)); + verbose_printf("Added entry 0x%llx 0x%llx\n", + (unsigned long long)addr, (unsigned long long)size); +} + +static void reverse_properties(void *in, void *out, int offset) +{ + int err; + int len; + const char *name; + const void *data; + + data = fdt_getprop_by_offset(in, offset, &name, &len); + if (!data) + FAIL("fdt_getprop_by_offset(): %s\n", fdt_strerror(len)); + + verbose_printf("reverse_properties(): offset=%d name=%s\n", + offset, name); + + offset = fdt_next_property_offset(in, offset); + if (offset >= 0) + reverse_properties(in, out, offset); + else if (offset != -FDT_ERR_NOTFOUND) + FAIL("fdt_next_property_offset(): %s\n", fdt_strerror(offset)); + + CHECK(fdt_property(out, name, data, len)); + verbose_printf(" -> output property %s\n", name); +} + +static void reverse_node(void *in, void *out, int nodeoffset); + +static void reverse_children(void *in, void *out, int offset) +{ + int err; + int nextoffset = offset; + int depth = 1; + + do { + char path[PATH_MAX]; + + CHECK(fdt_get_path(in, nextoffset, path, sizeof(path))); + verbose_printf("reverse_children() offset=%d nextoffset=%d [%s]" + " depth=%d\n", offset, nextoffset, path, depth); + + nextoffset = fdt_next_node(in, nextoffset, &depth); + } while ((depth >= 0) && (depth != 1)); + + if (depth == 1) + reverse_children(in, out, nextoffset); + + reverse_node(in, out, offset); +} + +static void reverse_node(void *in, void *out, int nodeoffset) +{ + const char *name = fdt_get_name(in, nodeoffset, NULL); + char path[PATH_MAX]; + int err; + int offset; + int depth = 0; + + CHECK(fdt_get_path(in, nodeoffset, path, sizeof(path))); + verbose_printf("reverse_node(): nodeoffset=%d [%s]\n", + nodeoffset, path); + + CHECK(fdt_begin_node(out, name)); + + offset = fdt_first_property_offset(in, nodeoffset); + if (offset >= 0) + reverse_properties(in, out, offset); + else if (offset != -FDT_ERR_NOTFOUND) + FAIL("fdt_first_property(): %s\n", fdt_strerror(offset)); + + offset = fdt_next_node(in, nodeoffset, &depth); + + if (depth == 1) + reverse_children(in, out, offset); + + CHECK(fdt_end_node(out)); +} + +int main(int argc, char *argv[]) +{ + void *in, *out; + char outname[PATH_MAX]; + int bufsize; + int err; + + test_init(argc, argv); + if (argc != 2) + CONFIG("Usage: %s <dtb file>", argv[0]); + + in = load_blob(argv[1]); + sprintf(outname, "%s.reversed.test.dtb", argv[1]); + + bufsize = fdt_totalsize(in); + out = xmalloc(bufsize); + + CHECK(fdt_create(out, bufsize)); + + fdt_set_boot_cpuid_phys(out, fdt_boot_cpuid_phys(in)); + + reverse_reservemap(in, out, 0); + CHECK(fdt_finish_reservemap(out)); + + reverse_node(in, out, 0); + + CHECK(fdt_finish(out)); + + save_blob(outname, out); + + PASS(); +} diff --git a/tests/dtbs_equal_unordered.c b/tests/dtbs_equal_unordered.c new file mode 100644 index 000000000000..df5331883b15 --- /dev/null +++ b/tests/dtbs_equal_unordered.c @@ -0,0 +1,224 @@ +/* + * libfdt - Flat Device Tree manipulation + * Tests if two given dtbs are structurally equal (including order) + * 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 <limits.h> + +#include <fdt.h> +#include <libfdt.h> + +#include "tests.h" +#include "testdata.h" + +int notequal; /* = 0 */ + +#define MISMATCH(fmt, ...) \ + do { \ + if (notequal) \ + PASS(); \ + else \ + FAIL(fmt, ##__VA_ARGS__); \ + } while (0) + +#define MATCH() \ + do { \ + if (!notequal) \ + PASS(); \ + else \ + FAIL("Trees match which shouldn't"); \ + } while (0) + +#define CHECK(code) \ + { \ + err = (code); \ + if (err) \ + FAIL(#code ": %s", fdt_strerror(err)); \ + } + +static int mem_rsv_cmp(const void *p1, const void *p2) +{ + const struct fdt_reserve_entry *re1 = p1; + const struct fdt_reserve_entry *re2 = p2; + + if (re1->address < re2->address) + return -1; + else if (re1->address > re2->address) + return 1; + + if (re1->size < re2->size) + return -1; + else if (re1->size > re2->size) + return 1; + + return 0; +} + +static void compare_mem_rsv(void *fdt1, void *fdt2) +{ + int i; + uint64_t addr1, size1, addr2, size2; + int err; + + if (fdt_num_mem_rsv(fdt1) != fdt_num_mem_rsv(fdt2)) + MISMATCH("Trees have different number of reserve entries"); + + qsort((char *)fdt1 + fdt_off_mem_rsvmap(fdt1), fdt_num_mem_rsv(fdt1), + sizeof(struct fdt_reserve_entry), mem_rsv_cmp); + qsort((char *)fdt2 + fdt_off_mem_rsvmap(fdt2), fdt_num_mem_rsv(fdt2), + sizeof(struct fdt_reserve_entry), mem_rsv_cmp); + + for (i = 0; i < fdt_num_mem_rsv(fdt1); i++) { + CHECK(fdt_get_mem_rsv(fdt1, i, &addr1, &size1)); + CHECK(fdt_get_mem_rsv(fdt2, i, &addr2, &size2)); + + if ((addr1 != addr2) || (size1 != size2)) + MISMATCH("Mismatch in reserve entry %d: " + "(0x%llx, 0x%llx) != (0x%llx, 0x%llx)", i, + (unsigned long long)addr1, + (unsigned long long)size1, + (unsigned long long)addr2, + (unsigned long long)size2); + } +} + +static void compare_properties(const void *fdt1, int offset1, + const void *fdt2, int offset2) +{ + int offset = offset1; + + /* Check the properties */ + for (offset = fdt_first_property_offset(fdt1, offset1); + offset >= 0; + offset = fdt_next_property_offset(fdt1, offset)) { + const char *name; + int len1, len2; + const void *data1, *data2; + int i; + + data1 = fdt_getprop_by_offset(fdt1, offset, &name, &len1); + if (!data1) + FAIL("fdt_getprop_by_offset(): %s\n", + fdt_strerror(len1)); + + verbose_printf("Property '%s'\n", name); + + data2 = fdt_getprop(fdt2, offset2, name, &len2); + if (!data2) { + if (len2 == -FDT_ERR_NOTFOUND) + MISMATCH("Property '%s' missing\n", name); + else + FAIL("fdt_get_property(): %s\n", + fdt_strerror(len2)); + } + + verbose_printf("len1=%d data1=", len1); + for (i = 0; i < len1; i++) + verbose_printf(" %02x", ((const char *)data1)[i]); + verbose_printf("\nlen2=%d data2=", len2); + for (i = 0; i < len1; i++) + verbose_printf(" %02x", ((const char *)data2)[i]); + verbose_printf("\n"); + + if (len1 != len2) + MISMATCH("Property '%s' mismatched length %d vs. %d\n", + name, len1, len2); + else if (memcmp(data1, data2, len1) != 0) + MISMATCH("Property '%s' mismatched value\n", name); + } +} + +static void compare_node(const void *fdt1, int offset1, + const void *fdt2, int offset2); + +static void compare_subnodes(const void *fdt1, int offset1, + const void *fdt2, int offset2, + int recurse) +{ + int coffset1, coffset2, depth; + + for (depth = 0, coffset1 = offset1; + (coffset1 >= 0) && (depth >= 0); + coffset1 = fdt_next_node(fdt1, coffset1, &depth)) + if (depth == 1) { + const char *name = fdt_get_name(fdt1, coffset1, NULL); + + verbose_printf("Subnode %s\n", name); + coffset2 = fdt_subnode_offset(fdt2, offset2, name); + if (coffset2 == -FDT_ERR_NOTFOUND) + MISMATCH("Subnode %s missing\n", name); + else if (coffset2 < 0) + FAIL("fdt_subnode_offset(): %s\n", + fdt_strerror(coffset2)); + + if (recurse) + compare_node(fdt1, coffset1, fdt2, coffset2); + } +} + +static void compare_node(const void *fdt1, int offset1, + const void *fdt2, int offset2) +{ + int err; + char path1[PATH_MAX], path2[PATH_MAX]; + + CHECK(fdt_get_path(fdt1, offset1, path1, sizeof(path1))); + CHECK(fdt_get_path(fdt2, offset2, path2, sizeof(path2))); + + if (!streq(path1, path2)) + TEST_BUG("Path mismatch %s vs. %s\n", path1, path2); + + verbose_printf("Checking %s\n", path1); + + compare_properties(fdt1, offset1, fdt2, offset2); + compare_properties(fdt2, offset2, fdt1, offset1); + + compare_subnodes(fdt1, offset1, fdt2, offset2, 1); + compare_subnodes(fdt2, offset2, fdt1, offset1, 0); +} + +int main(int argc, char *argv[]) +{ + void *fdt1, *fdt2; + uint32_t cpuid1, cpuid2; + + test_init(argc, argv); + if ((argc != 3) + && ((argc != 4) || !streq(argv[1], "-n"))) + CONFIG("Usage: %s [-n] <dtb file> <dtb file>", argv[0]); + if (argc == 4) + notequal = 1; + + fdt1 = load_blob(argv[argc-2]); + fdt2 = load_blob(argv[argc-1]); + + compare_mem_rsv(fdt1, fdt2); + compare_node(fdt1, 0, fdt2, 0); + + cpuid1 = fdt_boot_cpuid_phys(fdt1); + cpuid2 = fdt_boot_cpuid_phys(fdt2); + if (cpuid1 != cpuid2) + MISMATCH("boot_cpuid_phys mismatch 0x%x != 0x%x", + cpuid1, cpuid2); + + MATCH(); +} diff --git a/tests/dtc-fails.sh b/tests/dtc-fails.sh new file mode 100755 index 000000000000..4ddcb2732437 --- /dev/null +++ b/tests/dtc-fails.sh @@ -0,0 +1,30 @@ +#! /bin/sh + +. ./tests.sh + +if [ "$1" = "-n" ]; then + NEG="$1" + shift +fi + +OUTPUT="$1" +shift + +verbose_run $VALGRIND "$DTC" -o "$OUTPUT" "$@" +ret="$?" + +FAIL_IF_SIGNAL $ret + +if [ -n "$NEG" ]; then + if [ ! -e "$OUTPUT" ]; then + FAIL "Produced no output" + fi +else + if [ -e "$OUTPUT" ]; then + FAIL "Incorrectly produced output" + fi +fi + +rm -f "$OUTPUT" + +PASS diff --git a/tests/fdtget-runtest.sh b/tests/fdtget-runtest.sh new file mode 100755 index 000000000000..c3a355951dff --- /dev/null +++ b/tests/fdtget-runtest.sh @@ -0,0 +1,24 @@ +#! /bin/sh + +. ./tests.sh + +LOG=tmp.log.$$ +EXPECT=tmp.expect.$$ +rm -f $LOG $EXPECT +trap "rm -f $LOG $EXPECT" 0 + +expect="$1" +/bin/echo -e $expect >$EXPECT +shift + +verbose_run_log_check "$LOG" $VALGRIND $DTGET "$@" + +if cmp $EXPECT $LOG>/dev/null; then + PASS +else + if [ -z "$QUIET_TEST" ]; then + echo "EXPECTED :-:" + cat $EXPECT + fi + FAIL "Results differ from expected" +fi diff --git a/tests/fdtput-runtest.sh b/tests/fdtput-runtest.sh new file mode 100755 index 000000000000..527a9688ea5b --- /dev/null +++ b/tests/fdtput-runtest.sh @@ -0,0 +1,39 @@ +#! /bin/sh + +# Run script for fdtput tests +# We run fdtput to update the device tree, thn fdtget to check it + +# Usage +# fdtput-runtest.sh name expected_output dtb_file node property flags value + +. ./tests.sh + +LOG=tmp.log.$$ +EXPECT=tmp.expect.$$ +rm -f $LOG $EXPECT +trap "rm -f $LOG $EXPECT" 0 + +expect="$1" +echo $expect >$EXPECT +dtb="$2" +node="$3" +property="$4" +flags="$5" +shift 5 +value="$@" + +# First run fdtput +verbose_run_check $VALGRIND "$DTPUT" "$dtb" "$node" "$property" $value $flags + +# Now fdtget to read the value +verbose_run_log_check "$LOG" $VALGRIND "$DTGET" "$dtb" "$node" "$property" $flags + +if cmp $EXPECT $LOG >/dev/null; then + PASS +else + if [ -z "$QUIET_TEST" ]; then + echo "EXPECTED :-:" + cat $EXPECT + fi + FAIL "Results differ from expected" +fi diff --git a/tests/include5a.dts b/tests/include5a.dts new file mode 100644 index 000000000000..39ddba4fbba1 --- /dev/null +++ b/tests/include5a.dts @@ -0,0 +1 @@ += /bits/ 64 <0xdeadbeef01abcdef>
\ No newline at end of file diff --git a/tests/integer-expressions.c b/tests/integer-expressions.c new file mode 100644 index 000000000000..5ba1566ab8e2 --- /dev/null +++ b/tests/integer-expressions.c @@ -0,0 +1,117 @@ +/* + * Testcase for dtc expression support + * + * Copyright (C) 2008 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 <errno.h> + + +#include <fdt.h> +#include <libfdt.h> + +#include "tests.h" +#include "testdata.h" + +struct test_expr { + const char *expr; + uint32_t result; +} expr_table[] = { +#define TE(expr) { #expr, (expr) } + TE(0xdeadbeef), + TE(-0x21524111), + TE(1+1), + TE(2*3), + TE(4/2), + TE(10/3), + TE(19%4), + TE(1 << 13), + TE(0x1000 >> 4), + TE(3*2+1), TE(3*(2+1)), + TE(1+2*3), TE((1+2)*3), + TE(1 < 2), TE(2 < 1), TE(1 < 1), + TE(1 <= 2), TE(2 <= 1), TE(1 <= 1), + TE(1 > 2), TE(2 > 1), TE(1 > 1), + TE(1 >= 2), TE(2 >= 1), TE(1 >= 1), + TE(1 == 1), TE(1 == 2), + TE(1 != 1), TE(1 != 2), + TE(0xabcdabcd & 0xffff0000), + TE(0xdead4110 ^ 0xf0f0f0f0), + TE(0xabcd0000 | 0x0000abcd), + TE(~0x21524110), + TE(~~0xdeadbeef), + TE(0 && 0), TE(17 && 0), TE(0 && 17), TE(17 && 17), + TE(0 || 0), TE(17 || 0), TE(0 || 17), TE(17 || 17), + TE(!0), TE(!1), TE(!17), TE(!!0), TE(!!17), + TE(0 ? 17 : 39), TE(1 ? 17 : 39), TE(17 ? 0xdeadbeef : 0xabcd1234), + TE(11 * 257 * 1321517ULL), + TE(123456790 - 4/2 + 17%4), +}; + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +int main(int argc, char *argv[]) +{ + void *fdt; + const uint32_t *res; + int reslen; + int i; + + test_init(argc, argv); + + if ((argc == 3) && (strcmp(argv[1], "-g") == 0)) { + FILE *f = fopen(argv[2], "w"); + + if (!f) + FAIL("Couldn't open \"%s\" for output: %s\n", + argv[2], strerror(errno)); + + fprintf(f, "/dts-v1/;\n"); + fprintf(f, "/ {\n"); + fprintf(f, "\texpressions = <\n"); + for (i = 0; i < ARRAY_SIZE(expr_table); i++) + fprintf(f, "\t\t(%s)\n", expr_table[i].expr); + fprintf(f, "\t>;\n"); + fprintf(f, "};\n"); + fclose(f); + } else { + fdt = load_blob_arg(argc, argv); + + res = fdt_getprop(fdt, 0, "expressions", &reslen); + + if (!res) + FAIL("Error retreiving expression results: %s\n", + fdt_strerror(reslen)); + + if (reslen != (ARRAY_SIZE(expr_table) * sizeof(uint32_t))) + FAIL("Unexpected length of results %d instead of %zd\n", + reslen, ARRAY_SIZE(expr_table) * sizeof(uint32_t)); + + for (i = 0; i < ARRAY_SIZE(expr_table); i++) + if (fdt32_to_cpu(res[i]) != expr_table[i].result) + FAIL("Incorrect result for expression \"%s\"," + " 0x%x instead of 0x%x\n", + expr_table[i].expr, fdt32_to_cpu(res[i]), + expr_table[i].result); + } + + PASS(); +} diff --git a/tests/label_repeated.dts b/tests/label_repeated.dts new file mode 100644 index 000000000000..34225d331028 --- /dev/null +++ b/tests/label_repeated.dts @@ -0,0 +1,15 @@ +/dts-v1/; + +/ { + l0: prop = "foo"; + + l1: node { + }; +}; + +/ { + l0: prop = "foo"; + + l1: node { + }; +}; diff --git a/tests/lorem.txt b/tests/lorem.txt new file mode 100644 index 000000000000..acff698376bc --- /dev/null +++ b/tests/lorem.txt @@ -0,0 +1,35 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris eros +arcu, egestas non pellentesque non, euismod eu nibh. Proin arcu metus, +dapibus vitae sodales rhoncus, suscipit vel nulla. Etiam lorem est, +aliquam ut fringilla sit amet, condimentum et quam. Duis eu arcu odio, +at pulvinar nisi. Morbi condimentum eros ut turpis rhoncus +pharetra. Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Nam et nulla enim. Etiam fringilla +eleifend neque, at posuere ante lacinia a. Duis orci tortor, dictum ac +gravida ac, euismod eu leo. Sed eget dolor tortor. Pellentesque +venenatis, lectus eu vulputate porta, libero ipsum convallis mi, sit +amet vehicula arcu elit sit amet odio. + +Fusce iaculis massa metus, id sagittis diam. Praesent molestie ante +vel odio tincidunt auctor. Cum sociis natoque penatibus et magnis dis +parturient montes, nascetur ridiculus mus. Duis rutrum vehicula nisl +eget condimentum. In in justo nisl. Nullam id arcu at nisl eleifend +pretium. Nulla interdum ligula id elit mollis dictum a sit amet +quam. Nullam iaculis laoreet ipsum at tempus. Vestibulum in cursus +dui. Curabitur porta lectus eget urna bibendum congue eget elementum +nisi. Proin sit amet lectus ut neque iaculis consectetur eu sit amet +nibh. Maecenas rhoncus dolor ac nunc gravida blandit. Fusce sem felis, +aliquam a porttitor a, porta quis odio. + +Nunc purus lorem, sollicitudin non ultricies id, porta vitae +enim. Nulla tristique gravida leo ut suscipit. Phasellus vitae turpis +libero. Proin ac purus dolor, in suscipit magna. Sed et enim +arcu. Morbi semper aliquet suscipit. Aenean laoreet condimentum massa, +eu pharetra magna fermentum ut. Morbi euismod convallis tortor, eget +fringilla lacus sagittis non. Nullam bibendum posuere feugiat. + +In at pulvinar massa. Mauris nunc lectus, mollis et malesuada +pharetra, cursus sed lacus. Integer dolor urna, interdum a mollis at, +vestibulum non nisl. Sed in urna tortor. Mauris arcu felis, volutpat +quis euismod vel, congue sit amet ipsum. Morbi in aliquet purus. Duis +cras amet. diff --git a/tests/multilabel.dts b/tests/multilabel.dts new file mode 100644 index 000000000000..31116ceab2d6 --- /dev/null +++ b/tests/multilabel.dts @@ -0,0 +1,42 @@ +/dts-v1/; + +m1: mq: /memreserve/ 0 0x1000; + +/ { + p0: pw: prop = "foo"; + + /* Explicit phandles */ + n1: nx: node1 { + linux,phandle = <0x2000>; + ref = <&{/node2}>; /* reference precedes target */ + p1: px: lref = <&ny>; + }; + ny: n2: node2 { + p2: py: phandle = <0x1>; + ref = <&{/node1}>; /* reference after target */ + lref = <&nx>; + }; + + /* Implicit phandles */ + n3: node3 { + p3: ref = <&{/node4}>; + lref = <&n4>; + }; + n4: node4 { + p4: prop; + }; + + /* Explicit phandle with implicit value */ + /* This self-reference is the standard way to tag a node as requiring + * a phandle (perhaps for reference by nodes that will be dynamically + * added) without explicitly allocating it a phandle. + * The self-reference requires some special internal handling, though + * so check it actually works */ + n5: nz: node5 { + linux,phandle = <&n5>; + phandle = <&nz>; + n1 = &n1; + n2 = &n2; + n3 = &n3; + }; +}; diff --git a/tests/multilabel_merge.dts b/tests/multilabel_merge.dts new file mode 100644 index 000000000000..1632300e6aca --- /dev/null +++ b/tests/multilabel_merge.dts @@ -0,0 +1,66 @@ +/dts-v1/; + +m1: mq: /memreserve/ 0 0x1000; + +/ { + p0: pw: prop = "foo"; + + /* Explicit phandles */ + n1: node1 { + linux,phandle = <0x2000>; + ref = <&{/node2}>; /* reference precedes target */ + p1: lref; + }; + node2 { + phandle = <0x1>; + ref = <&{/node1}>; /* reference after target */ + lref = <&nx>; + }; + + /* Implicit phandles */ + n3: node3 { + p3: ref = <&{/node4}>; + lref = <&n4>; + }; + n4: node4 { + p4: prop = "foo"; + }; + + /* Explicit phandle with implicit value */ + /* This self-reference is the standard way to tag a node as requiring + * a phandle (perhaps for reference by nodes that will be dynamically + * added) without explicitly allocating it a phandle. + * The self-reference requires some special internal handling, though + * so check it actually works */ + n5: nz: node5 { + linux,phandle = <&n5>; + phandle = <&nz>; + n1 = &n1; + n2 = &n2; + n3 = &n3; + }; +}; + +/ { + /* Append labels (also changes property content) */ + nx: node1 { + px: lref = <&ny>; + }; + + /* Add multiple labels */ + ny: n2: node2 { + /* Add a label to a property */ + p2: py: phandle = <0x1>; + }; + + /* Reassigning the same label should be a no-op */ + n3: node3 { + p3: ref = <&{/node4}>; + }; + + /* Redefining a node/property should not remove labels */ + node4 { + prop; + }; + +}; diff --git a/tests/nonexist-node-ref2.dts b/tests/nonexist-node-ref2.dts new file mode 100644 index 000000000000..44b4ebeba768 --- /dev/null +++ b/tests/nonexist-node-ref2.dts @@ -0,0 +1,10 @@ +/dts-v1/; + +/ { + label: node { + }; +}; + +/* Try to redefine a node using a non-existent label */ +&nosuchnode { +}; diff --git a/tests/reuse-label.dts b/tests/reuse-label.dts new file mode 100644 index 000000000000..98b5ca9dcad8 --- /dev/null +++ b/tests/reuse-label.dts @@ -0,0 +1,15 @@ +/dts-v1/; + +/ { + label: property1 = "foo"; + label: property2 = "bar"; + + test1 = &label; + + label: node1 { + prop = "foo"; + }; + label: node2 { + prop = "bar"; + }; +}; diff --git a/tests/reuse-label1.dts b/tests/reuse-label1.dts new file mode 100644 index 000000000000..f22956932967 --- /dev/null +++ b/tests/reuse-label1.dts @@ -0,0 +1,10 @@ +/dts-v1/; + +/ { + label: node1 { + prop = "foo"; + }; + label: node2 { + prop = "bar"; + }; +}; diff --git a/tests/reuse-label2.dts b/tests/reuse-label2.dts new file mode 100644 index 000000000000..01ea6b27f03d --- /dev/null +++ b/tests/reuse-label2.dts @@ -0,0 +1,6 @@ +/dts-v1/; + +/ { + label: property1 = "foo"; + label: property2 = "bar"; +}; diff --git a/tests/reuse-label3.dts b/tests/reuse-label3.dts new file mode 100644 index 000000000000..fa3d2c72a264 --- /dev/null +++ b/tests/reuse-label3.dts @@ -0,0 +1,9 @@ +/dts-v1/; + +/ { + label: property = "foo"; + + label: node { + property = "foo"; + }; +}; diff --git a/tests/reuse-label4.dts b/tests/reuse-label4.dts new file mode 100644 index 000000000000..6805de32200d --- /dev/null +++ b/tests/reuse-label4.dts @@ -0,0 +1,5 @@ +/dts-v1/; + +/ { + property = label: "foo" label:; +}; diff --git a/tests/reuse-label5.dts b/tests/reuse-label5.dts new file mode 100644 index 000000000000..b7238e64ac76 --- /dev/null +++ b/tests/reuse-label5.dts @@ -0,0 +1,6 @@ +/dts-v1/; + +/ { + prop1 = label: "foo"; + prop2 = "bar" label:; +}; diff --git a/tests/reuse-label6.dts b/tests/reuse-label6.dts new file mode 100644 index 000000000000..f5d507c6dfd9 --- /dev/null +++ b/tests/reuse-label6.dts @@ -0,0 +1,6 @@ +/dts-v1/; + +/ { + label: prop1 = "foo"; + prop2 = "bar" label:; +}; diff --git a/tests/search_dir/search_test.dtsi b/tests/search_dir/search_test.dtsi new file mode 100644 index 000000000000..217fb80a8a41 --- /dev/null +++ b/tests/search_dir/search_test.dtsi @@ -0,0 +1,4 @@ +/include/ "search_test2.dtsi" + +/ { +}; diff --git a/tests/search_dir/search_test2.dtsi b/tests/search_dir/search_test2.dtsi new file mode 100644 index 000000000000..7b9099e5cd85 --- /dev/null +++ b/tests/search_dir/search_test2.dtsi @@ -0,0 +1,3 @@ + +/ { +}; diff --git a/tests/search_dir_b/search_paths_subdir.dts b/tests/search_dir_b/search_paths_subdir.dts new file mode 100644 index 000000000000..5c5c9622ce54 --- /dev/null +++ b/tests/search_dir_b/search_paths_subdir.dts @@ -0,0 +1,6 @@ +/dts-v1/; + +/include/ "search_test_c.dtsi" + +/ { +}; diff --git a/tests/search_dir_b/search_test_b.dtsi b/tests/search_dir_b/search_test_b.dtsi new file mode 100644 index 000000000000..b06a7d6eca7b --- /dev/null +++ b/tests/search_dir_b/search_test_b.dtsi @@ -0,0 +1,4 @@ +/include/ "search_test_b2.dtsi" + +/ { +}; diff --git a/tests/search_dir_b/search_test_b2.dtsi b/tests/search_dir_b/search_test_b2.dtsi new file mode 100644 index 000000000000..2526b43d6e66 --- /dev/null +++ b/tests/search_dir_b/search_test_b2.dtsi @@ -0,0 +1,5 @@ + +/include/ "search_test.dtsi" + +/ { +}; diff --git a/tests/search_dir_b/search_test_c.dtsi b/tests/search_dir_b/search_test_c.dtsi new file mode 100644 index 000000000000..336d7a250678 --- /dev/null +++ b/tests/search_dir_b/search_test_c.dtsi @@ -0,0 +1,2 @@ +/ { +}; diff --git a/tests/search_paths.dts b/tests/search_paths.dts new file mode 100644 index 000000000000..a2bf179e561d --- /dev/null +++ b/tests/search_paths.dts @@ -0,0 +1,6 @@ +/dts-v1/; + +/include/ "search_test.dtsi" + +/ { +}; diff --git a/tests/search_paths_b.dts b/tests/search_paths_b.dts new file mode 100644 index 000000000000..6ace6e24d272 --- /dev/null +++ b/tests/search_paths_b.dts @@ -0,0 +1,6 @@ +/dts-v1/; + +/include/ "search_test_b.dtsi" + +/ { +}; diff --git a/tests/sized_cells.c b/tests/sized_cells.c new file mode 100644 index 000000000000..847ec96ba4ad --- /dev/null +++ b/tests/sized_cells.c @@ -0,0 +1,84 @@ +/* + * libfdt - Flat Device Tree manipulation + * Testcase for variable sized cells in dtc + * Copyright (C) 2006 David Gibson, IBM Corporation. + * Copyright (C) 2011 The Chromium Authors. All rights reserved. + * + * 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" + +static void check_compare_properties(void *fdt, + char const *name_one, + char const *name_two) +{ + const void *propval; + int proplen; + + propval = fdt_getprop(fdt, 0, name_one, &proplen); + + if (!propval) + FAIL("fdt_getprop(\"%s\"): %s", + name_one, + fdt_strerror(proplen)); + + check_getprop(fdt, 0, name_two, proplen, propval); +} + +int main(int argc, char *argv[]) +{ + void *fdt; + uint8_t expected_8[6] = {TEST_CHAR1, + TEST_CHAR2, + TEST_CHAR3, + TEST_CHAR4, + TEST_CHAR5, + TEST_VALUE_1 >> 24}; + uint16_t expected_16[6]; + uint32_t expected_32[6]; + uint64_t expected_64[6]; + int i; + + for (i = 0; i < 5; ++i) { + expected_16[i] = cpu_to_fdt16(expected_8[i]); + expected_32[i] = cpu_to_fdt32(expected_8[i]); + expected_64[i] = cpu_to_fdt64(expected_8[i]); + } + + expected_16[5] = cpu_to_fdt16(TEST_VALUE_1 >> 16); + expected_32[5] = cpu_to_fdt32(TEST_VALUE_1); + expected_64[5] = cpu_to_fdt64(TEST_ADDR_1); + + test_init(argc, argv); + fdt = load_blob_arg(argc, argv); + + check_getprop(fdt, 0, "cells-8b", sizeof(expected_8), expected_8); + check_getprop(fdt, 0, "cells-16b", sizeof(expected_16), expected_16); + check_getprop(fdt, 0, "cells-32b", sizeof(expected_32), expected_32); + check_getprop(fdt, 0, "cells-64b", sizeof(expected_64), expected_64); + + check_compare_properties(fdt, "cells-one-16b", "cells-one-32b"); + + PASS(); +} diff --git a/tests/sized_cells.dts b/tests/sized_cells.dts new file mode 100644 index 000000000000..efea9f567ba4 --- /dev/null +++ b/tests/sized_cells.dts @@ -0,0 +1,11 @@ +/dts-v1/; + +/ { + cells-8b = /bits/ 8 <'\r' 'b' '\0' '\'' '\xff' 0xde>; + cells-16b = /bits/ 16 <'\r' 'b' '\0' '\'' '\xff' 0xdead>; + cells-32b = /bits/ 32 <'\r' 'b' '\0' '\'' '\xff' 0xdeadbeef>; + cells-64b = /bits/ 64 <'\r' 'b' '\0' '\'' '\xff' 0xdeadbeef00000000>; + + cells-one-16b = /bits/ 16 <0x1234 0x5678 0x0 0xffff>; + cells-one-32b = <0x12345678 0x0000ffff>; +}; diff --git a/tests/test_tree1_merge.dts b/tests/test_tree1_merge.dts new file mode 100644 index 000000000000..ded08d871435 --- /dev/null +++ b/tests/test_tree1_merge.dts @@ -0,0 +1,44 @@ +/dts-v1/; +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; + +/ { + compatible = "test_tree1"; + prop-int = "wrong!"; + prop-str = "hello world"; + + subnode@1 { + compatible = "subnode1"; + + subsubnode { + compatible = "subsubnode1", "subsubnode"; + prop-int = <0xdeadbeef>; + }; + + ss1 { + }; + }; + + subnode@2 { + linux,phandle = <0x2000>; + prop-int = <123456789>; + + ss2 { + }; + }; +}; + +/ { + prop-int = <0xdeadbeef>; + prop-int64 = /bits/ 64 <0xdeadbeef01abcdef>; + subnode@1 { + prop-int = [deadbeef]; + }; + subnode@2 { + ssn0: subsubnode@0 { + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + }; +}; diff --git a/tests/test_tree1_merge_labelled.dts b/tests/test_tree1_merge_labelled.dts new file mode 100644 index 000000000000..29953b0aa1b3 --- /dev/null +++ b/tests/test_tree1_merge_labelled.dts @@ -0,0 +1,42 @@ +/dts-v1/; + +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; + +/ { + compatible = "test_tree1"; + prop-int = <0xdeadbeef>; + prop-int64 = /bits/ 64 <0xdeadbeef01abcdef>; + 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>; + + ssn0: subsubnode@0 { + phandle = <0x2001>; + prop-int = <0xbad>; + }; + + ss2 { + }; + }; +}; + +&ssn0 { + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; +}; diff --git a/tests/test_tree1_merge_path.dts b/tests/test_tree1_merge_path.dts new file mode 100644 index 000000000000..168d066fad08 --- /dev/null +++ b/tests/test_tree1_merge_path.dts @@ -0,0 +1,42 @@ +/dts-v1/; + +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; + +/ { + compatible = "test_tree1"; + prop-int = <0xdeadbeef>; + prop-int64 = /bits/ 64 <0xdeadbeef01abcdef>; + 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>; + + ssn0: subsubnode@0 { + phandle = <0x2001>; + prop-int = <0xbad>; + }; + + ss2 { + }; + }; +}; + +&{/subnode@2/subsubnode@0} { + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; +}; diff --git a/tests/test_tree1_wrong1.dts b/tests/test_tree1_wrong1.dts new file mode 100644 index 000000000000..d71820a23864 --- /dev/null +++ b/tests/test_tree1_wrong1.dts @@ -0,0 +1,36 @@ +/dts-v1/; + +/memreserve/ 123456789 010000; + +/ { + 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 { + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + + ss2 { + }; + }; +}; diff --git a/tests/test_tree1_wrong2.dts b/tests/test_tree1_wrong2.dts new file mode 100644 index 000000000000..ac27023c3c9a --- /dev/null +++ b/tests/test_tree1_wrong2.dts @@ -0,0 +1,36 @@ +/dts-v1/; + +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; + +/ { + compatible = "test_tree1"; + 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 { + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + + ss2 { + }; + }; +}; diff --git a/tests/test_tree1_wrong3.dts b/tests/test_tree1_wrong3.dts new file mode 100644 index 000000000000..80be2fac8f63 --- /dev/null +++ b/tests/test_tree1_wrong3.dts @@ -0,0 +1,36 @@ +/dts-v1/; + +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; + +/ { + compatible = "test_tree1"; + prop-int = <0xdeadbeef>; + prop-str = "hello world"; + + subnode@1 { + compatible = "subnode1"; + + subsubnode { + compatible = "subsubnode1", "subsubnode"; + prop-int = <0xdeadbeef>; + }; + + ss1 { + }; + }; + + subnode@2 { + linux,phandle = <0x2000>; + prop-int = <123456789>; + + subsubnode@0 { + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + + ss2 { + }; + }; +}; diff --git a/tests/test_tree1_wrong4.dts b/tests/test_tree1_wrong4.dts new file mode 100644 index 000000000000..09bb13b8cb89 --- /dev/null +++ b/tests/test_tree1_wrong4.dts @@ -0,0 +1,34 @@ +/dts-v1/; + +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; + +/ { + 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 { + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + }; +}; diff --git a/tests/test_tree1_wrong5.dts b/tests/test_tree1_wrong5.dts new file mode 100644 index 000000000000..ef4c4f7b772d --- /dev/null +++ b/tests/test_tree1_wrong5.dts @@ -0,0 +1,37 @@ +/dts-v1/; + +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; + +/ { + compatible = "test_tree1"; + prop-int = <0xdeadbefe>; + 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 { + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + + ss2 { + }; + }; +}; diff --git a/tests/test_tree1_wrong6.dts b/tests/test_tree1_wrong6.dts new file mode 100644 index 000000000000..98d6eda7fb56 --- /dev/null +++ b/tests/test_tree1_wrong6.dts @@ -0,0 +1,38 @@ +/dts-v1/; + +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; + +/ { + 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 { + extra-prop; + }; + }; + + subnode@2 { + linux,phandle = <0x2000>; + prop-int = <123456789>; + + subsubnode@0 { + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + + ss2 { + }; + }; +}; diff --git a/tests/test_tree1_wrong7.dts b/tests/test_tree1_wrong7.dts new file mode 100644 index 000000000000..f57ace09a30f --- /dev/null +++ b/tests/test_tree1_wrong7.dts @@ -0,0 +1,39 @@ +/dts-v1/; + +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; + +/ { + 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 { + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + + ss2 { + extranode { + }; + }; + }; +}; diff --git a/tests/test_tree1_wrong8.dts b/tests/test_tree1_wrong8.dts new file mode 100644 index 000000000000..811ce6c0e536 --- /dev/null +++ b/tests/test_tree1_wrong8.dts @@ -0,0 +1,37 @@ +/dts-v1/; + +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010001; + +/ { + 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 { + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + + ss2 { + }; + }; +}; diff --git a/tests/test_tree1_wrong9.dts b/tests/test_tree1_wrong9.dts new file mode 100644 index 000000000000..6ff6fab22dd2 --- /dev/null +++ b/tests/test_tree1_wrong9.dts @@ -0,0 +1,38 @@ +/dts-v1/; + +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; +/memreserve/ 0 1; + +/ { + 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 { + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + + ss2 { + }; + }; +}; diff --git a/tests/utilfdt_test.c b/tests/utilfdt_test.c new file mode 100644 index 000000000000..36b4aa54de49 --- /dev/null +++ b/tests/utilfdt_test.c @@ -0,0 +1,128 @@ +/* + * Copyright 2011 The Chromium Authors, All Rights Reserved. + * + * utilfdt_test - Tests for utilfdt library + * + * 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 <assert.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <stdint.h> +#include <stdarg.h> + +#include <fdt.h> +#include <libfdt.h> +#include <util.h> + +#include "tests.h" +#include "testdata.h" + +static void check(const char *fmt, int expect_type, int expect_size) +{ + int type; + int size; + + if (utilfdt_decode_type(fmt, &type, &size)) + FAIL("format '%s': valid format string returned failure", fmt); + if (expect_type != type) + FAIL("format '%s': expected type='%c', got type='%c'", fmt, + expect_type, type); + if (expect_size != size) + FAIL("format '%s': expected size=%d, got size=%d", fmt, + expect_size, size); +} + +static void checkfail(const char *fmt) +{ + int type; + int size; + + if (!utilfdt_decode_type(fmt, &type, &size)) + FAIL("format '%s': invalid format string returned success", + fmt); +} + +/** + * Add the given modifier to each of the valid sizes, and check that we get + * correct values. + * + * \param modifier Modifer string to use as a prefix + * \param expected_size The size (in bytes) that we expect (ignored for + * strings) + */ +static void check_sizes(char *modifier, int expected_size) +{ + char fmt[10], *ptr; + + /* set up a string with a hole in it for the format character */ + if (strlen(modifier) + 2 >= sizeof(fmt)) + FAIL("modifier string '%s' too long", modifier); + strcpy(fmt, modifier); + ptr = fmt + strlen(fmt); + ptr[1] = '\0'; + + /* now try each format character in turn */ + *ptr = 'i'; + check(fmt, 'i', expected_size); + + *ptr = 'u'; + check(fmt, 'u', expected_size); + + *ptr = 'x'; + check(fmt, 'x', expected_size); + + *ptr = 's'; + check(fmt, 's', -1); +} + +static void test_utilfdt_decode_type(void) +{ + char fmt[10]; + int ch; + + /* check all the valid modifiers and sizes */ + check_sizes("", -1); + check_sizes("b", 1); + check_sizes("hh", 1); + check_sizes("h", 2); + check_sizes("l", 4); + + /* try every other character */ + checkfail(""); + for (ch = ' '; ch < 127; ch++) { + if (!strchr("iuxs", ch)) { + *fmt = ch; + fmt[1] = '\0'; + checkfail(fmt); + } + } + + /* try a few modifiers at the end */ + checkfail("sx"); + checkfail("ihh"); + checkfail("xb"); + + /* and one for the doomsday archives */ + checkfail("He has all the virtues I dislike and none of the vices " + "I admire."); +} + +int main(int argc, char *argv[]) +{ + test_utilfdt_decode_type(); + PASS(); +} |