aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPantelis Antoniou <pantelis.antoniou@konsulko.com>2016-12-07 14:48:19 +0200
committerDavid Gibson <david@gibson.dropbear.id.au>2016-12-09 13:26:39 +1100
commit9637e3f772a944d28ab5b039f110763a25665fd6 (patch)
tree6e17eae726d110137803d2dc71d15903e679d0e0
parent20f29d8d41f6d1bd2fbe466aa5676026eb012832 (diff)
downloaddtc-9637e3f772a944d28ab5b039f110763a25665fd6.tar.gz
tests: Add check_path test
Add a test that checks for existence or not of a node. It is useful for testing the various cases when generating symbols and fixups for dynamic device tree objects. Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.tests3
-rw-r--r--tests/check_path.c82
-rwxr-xr-xtests/run_tests.sh3
4 files changed, 88 insertions, 1 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 354b565..9e209d5 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -8,6 +8,7 @@ tmp.*
/asm_tree_dump
/boot-cpuid
/char_literal
+/check_path
/del_node
/del_property
/dtbs_equal_ordered
diff --git a/tests/Makefile.tests b/tests/Makefile.tests
index eb039c5..3d7a4f8 100644
--- a/tests/Makefile.tests
+++ b/tests/Makefile.tests
@@ -25,7 +25,8 @@ LIB_TESTS_L = get_mem_rsv \
integer-expressions \
property_iterate \
subnode_iterate \
- overlay overlay_bad_fixup
+ overlay overlay_bad_fixup \
+ check_path
LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%)
LIBTREE_TESTS_L = truncated_property
diff --git a/tests/check_path.c b/tests/check_path.c
new file mode 100644
index 0000000..0d6a73b
--- /dev/null
+++ b/tests/check_path.c
@@ -0,0 +1,82 @@
+/*
+ * 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) \
+ { \
+ if (code) \
+ FAIL(#code ": %s", fdt_strerror(code)); \
+ }
+
+/* 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/run_tests.sh b/tests/run_tests.sh
index e4139dd..d64cb2a 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -508,6 +508,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