[Pdbg] [PATCH 14/23] tests: Add device tree traversal tests
Amitay Isaacs
amitay at ozlabs.org
Thu Sep 19 12:33:24 AEST 2019
This test checks system device tree (view) traverse and backend device
tree traverse.
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
Makefile.am | 11 +-
src/tests/libpdbg_dtree_test.c | 85 ++++++++++
tests/test_tree.sh | 278 +++++++++++++++++++++++++++++++++
3 files changed, 372 insertions(+), 2 deletions(-)
create mode 100644 src/tests/libpdbg_dtree_test.c
create mode 100755 tests/test_tree.sh
diff --git a/Makefile.am b/Makefile.am
index cec8799..accc0a4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,13 +15,15 @@ libpdbg_tests = libpdbg_target_test \
libpdbg_probe_test3
bin_PROGRAMS = pdbg
-check_PROGRAMS = $(libpdbg_tests) optcmd_test hexdump_test cronus_proxy
+check_PROGRAMS = $(libpdbg_tests) libpdbg_dtree_test \
+ optcmd_test hexdump_test cronus_proxy
PDBG_TESTS = \
tests/test_selection.sh \
tests/test_selection2.sh \
tests/test_hw_bmc.sh \
- tests/test_hexdump.sh
+ tests/test_hexdump.sh \
+ tests/test_tree.sh
TESTS = $(libpdbg_tests) optcmd_test $(PDBG_TESTS)
@@ -229,6 +231,11 @@ libpdbg_probe_test3_LDADD = $(libpdbg_test_ldadd)
src/tests/libpdbg_probe_test.c: fake.dt.h
+libpdbg_dtree_test_SOURCES = src/tests/libpdbg_dtree_test.c
+libpdbg_dtree_test_CFLAGS = $(libpdbg_test_cflags)
+libpdbg_dtree_test_LDFLAGS = $(libpdbg_test_ldflags)
+libpdbg_dtree_test_LDADD = $(libpdbg_test_ldadd)
+
M4_V = $(M4_V_$(V))
M4_V_ = $(M4_V_$(AM_DEFAULT_VERBOSITY))
M4_V_0 = @echo " M4 " $@;
diff --git a/src/tests/libpdbg_dtree_test.c b/src/tests/libpdbg_dtree_test.c
new file mode 100644
index 0000000..434728a
--- /dev/null
+++ b/src/tests/libpdbg_dtree_test.c
@@ -0,0 +1,85 @@
+/* Copyright 2019 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <libpdbg.h>
+
+#define for_each_child(parent, target, virtual) \
+ for (target = __pdbg_next_child_target(parent, NULL, virtual); \
+ target; \
+ target = __pdbg_next_child_target(parent, target, virtual))
+
+static void print_target(struct pdbg_target *target, bool virtual, int level)
+{
+ struct pdbg_target *child;
+ const char *name;
+ char *path;
+ int i;
+
+ for (i=0; i<level; i++)
+ printf(" ");
+
+ name = pdbg_target_dn_name(target);
+ if (!name || name[0] == '\0')
+ name = "/";
+ path = pdbg_target_path(target);
+ printf("%s (%s)\n", name, path);
+ free(path);
+
+ for_each_child(target, child, virtual)
+ print_target(child, virtual, level+1);
+}
+
+static void usage(void)
+{
+ fprintf(stderr, "Usage: libpdbg_dtree_test tree|rtree|<class>\n");
+ exit(1);
+}
+
+int main(int argc, const char **argv)
+{
+ pdbg_targets_init(NULL);
+
+ if (argc < 2)
+ usage();
+
+ if (strcmp(argv[1], "tree") == 0) {
+ struct pdbg_target *root;
+
+ root = pdbg_target_root();
+ print_target(root, true, 0);
+ } else if (strcmp(argv[1], "rtree") == 0) {
+ struct pdbg_target *root;
+
+ root = pdbg_target_root();
+ print_target(root, false, 0);
+ } else {
+ struct pdbg_target *target;
+ char *path;
+
+ pdbg_for_each_class_target(argv[1], target) {
+ path = pdbg_target_path(target);
+ printf("%s%d: %s\n", argv[1], pdbg_target_index(target), path);
+ free(path);
+ }
+ }
+
+ return 0;
+}
diff --git a/tests/test_tree.sh b/tests/test_tree.sh
new file mode 100755
index 0000000..9ce0ce5
--- /dev/null
+++ b/tests/test_tree.sh
@@ -0,0 +1,278 @@
+#!/bin/sh
+
+. $(dirname "$0")/driver.sh
+
+test_group "tree tests"
+
+test_result 0 <<EOF
+/ (/)
+ proc0 (/proc0)
+ fsi at 20000 (/proc0/fsi)
+ pib at 20100 (/proc0/pib)
+ core at 10010 (/proc0/pib/core at 10010)
+ thread at 0 (/proc0/pib/core at 10010/thread at 0)
+ thread at 1 (/proc0/pib/core at 10010/thread at 1)
+ core at 10020 (/proc0/pib/core at 10020)
+ thread at 0 (/proc0/pib/core at 10020/thread at 0)
+ thread at 1 (/proc0/pib/core at 10020/thread at 1)
+ core at 10030 (/proc0/pib/core at 10030)
+ thread at 0 (/proc0/pib/core at 10030/thread at 0)
+ thread at 1 (/proc0/pib/core at 10030/thread at 1)
+ core at 10040 (/proc0/pib/core at 10040)
+ thread at 0 (/proc0/pib/core at 10040/thread at 0)
+ thread at 1 (/proc0/pib/core at 10040/thread at 1)
+ proc1 (/proc1)
+ fsi at 21000 (/proc1/fsi)
+ pib at 21100 (/proc1/pib)
+ core at 10010 (/proc1/pib/core at 10010)
+ thread at 0 (/proc1/pib/core at 10010/thread at 0)
+ thread at 1 (/proc1/pib/core at 10010/thread at 1)
+ core at 10020 (/proc1/pib/core at 10020)
+ thread at 0 (/proc1/pib/core at 10020/thread at 0)
+ thread at 1 (/proc1/pib/core at 10020/thread at 1)
+ core at 10030 (/proc1/pib/core at 10030)
+ thread at 0 (/proc1/pib/core at 10030/thread at 0)
+ thread at 1 (/proc1/pib/core at 10030/thread at 1)
+ core at 10040 (/proc1/pib/core at 10040)
+ thread at 0 (/proc1/pib/core at 10040/thread at 0)
+ thread at 1 (/proc1/pib/core at 10040/thread at 1)
+ proc2 (/proc2)
+ fsi at 22000 (/proc2/fsi)
+ pib at 22100 (/proc2/pib)
+ core at 10010 (/proc2/pib/core at 10010)
+ thread at 0 (/proc2/pib/core at 10010/thread at 0)
+ thread at 1 (/proc2/pib/core at 10010/thread at 1)
+ core at 10020 (/proc2/pib/core at 10020)
+ thread at 0 (/proc2/pib/core at 10020/thread at 0)
+ thread at 1 (/proc2/pib/core at 10020/thread at 1)
+ core at 10030 (/proc2/pib/core at 10030)
+ thread at 0 (/proc2/pib/core at 10030/thread at 0)
+ thread at 1 (/proc2/pib/core at 10030/thread at 1)
+ core at 10040 (/proc2/pib/core at 10040)
+ thread at 0 (/proc2/pib/core at 10040/thread at 0)
+ thread at 1 (/proc2/pib/core at 10040/thread at 1)
+ proc3 (/proc3)
+ fsi at 23000 (/proc3/fsi)
+ pib at 23100 (/proc3/pib)
+ core at 10010 (/proc3/pib/core at 10010)
+ thread at 0 (/proc3/pib/core at 10010/thread at 0)
+ thread at 1 (/proc3/pib/core at 10010/thread at 1)
+ core at 10020 (/proc3/pib/core at 10020)
+ thread at 0 (/proc3/pib/core at 10020/thread at 0)
+ thread at 1 (/proc3/pib/core at 10020/thread at 1)
+ core at 10030 (/proc3/pib/core at 10030)
+ thread at 0 (/proc3/pib/core at 10030/thread at 0)
+ thread at 1 (/proc3/pib/core at 10030/thread at 1)
+ core at 10040 (/proc3/pib/core at 10040)
+ thread at 0 (/proc3/pib/core at 10040/thread at 0)
+ thread at 1 (/proc3/pib/core at 10040/thread at 1)
+ proc4 (/proc4)
+ fsi at 24000 (/proc4/fsi)
+ pib at 24100 (/proc4/pib)
+ core at 10010 (/proc4/pib/core at 10010)
+ thread at 0 (/proc4/pib/core at 10010/thread at 0)
+ thread at 1 (/proc4/pib/core at 10010/thread at 1)
+ core at 10020 (/proc4/pib/core at 10020)
+ thread at 0 (/proc4/pib/core at 10020/thread at 0)
+ thread at 1 (/proc4/pib/core at 10020/thread at 1)
+ core at 10030 (/proc4/pib/core at 10030)
+ thread at 0 (/proc4/pib/core at 10030/thread at 0)
+ thread at 1 (/proc4/pib/core at 10030/thread at 1)
+ core at 10040 (/proc4/pib/core at 10040)
+ thread at 0 (/proc4/pib/core at 10040/thread at 0)
+ thread at 1 (/proc4/pib/core at 10040/thread at 1)
+ proc5 (/proc5)
+ fsi at 25000 (/proc5/fsi)
+ pib at 25100 (/proc5/pib)
+ core at 10010 (/proc5/pib/core at 10010)
+ thread at 0 (/proc5/pib/core at 10010/thread at 0)
+ thread at 1 (/proc5/pib/core at 10010/thread at 1)
+ core at 10020 (/proc5/pib/core at 10020)
+ thread at 0 (/proc5/pib/core at 10020/thread at 0)
+ thread at 1 (/proc5/pib/core at 10020/thread at 1)
+ core at 10030 (/proc5/pib/core at 10030)
+ thread at 0 (/proc5/pib/core at 10030/thread at 0)
+ thread at 1 (/proc5/pib/core at 10030/thread at 1)
+ core at 10040 (/proc5/pib/core at 10040)
+ thread at 0 (/proc5/pib/core at 10040/thread at 0)
+ thread at 1 (/proc5/pib/core at 10040/thread at 1)
+ proc6 (/proc6)
+ fsi at 26000 (/proc6/fsi)
+ pib at 26100 (/proc6/pib)
+ core at 10010 (/proc6/pib/core at 10010)
+ thread at 0 (/proc6/pib/core at 10010/thread at 0)
+ thread at 1 (/proc6/pib/core at 10010/thread at 1)
+ core at 10020 (/proc6/pib/core at 10020)
+ thread at 0 (/proc6/pib/core at 10020/thread at 0)
+ thread at 1 (/proc6/pib/core at 10020/thread at 1)
+ core at 10030 (/proc6/pib/core at 10030)
+ thread at 0 (/proc6/pib/core at 10030/thread at 0)
+ thread at 1 (/proc6/pib/core at 10030/thread at 1)
+ core at 10040 (/proc6/pib/core at 10040)
+ thread at 0 (/proc6/pib/core at 10040/thread at 0)
+ thread at 1 (/proc6/pib/core at 10040/thread at 1)
+ proc7 (/proc7)
+ fsi at 27000 (/proc7/fsi)
+ pib at 27100 (/proc7/pib)
+ core at 10010 (/proc7/pib/core at 10010)
+ thread at 0 (/proc7/pib/core at 10010/thread at 0)
+ thread at 1 (/proc7/pib/core at 10010/thread at 1)
+ core at 10020 (/proc7/pib/core at 10020)
+ thread at 0 (/proc7/pib/core at 10020/thread at 0)
+ thread at 1 (/proc7/pib/core at 10020/thread at 1)
+ core at 10030 (/proc7/pib/core at 10030)
+ thread at 0 (/proc7/pib/core at 10030/thread at 0)
+ thread at 1 (/proc7/pib/core at 10030/thread at 1)
+ core at 10040 (/proc7/pib/core at 10040)
+ thread at 0 (/proc7/pib/core at 10040/thread at 0)
+ thread at 1 (/proc7/pib/core at 10040/thread at 1)
+EOF
+
+test_run libpdbg_dtree_test tree
+
+
+test_result 0 <<EOF
+/ (/)
+ fsi at 20000 (/proc0/fsi)
+ pib at 20100 (/proc0/pib)
+ core at 10010 (/proc0/pib/core at 10010)
+ thread at 0 (/proc0/pib/core at 10010/thread at 0)
+ thread at 1 (/proc0/pib/core at 10010/thread at 1)
+ core at 10020 (/proc0/pib/core at 10020)
+ thread at 0 (/proc0/pib/core at 10020/thread at 0)
+ thread at 1 (/proc0/pib/core at 10020/thread at 1)
+ core at 10030 (/proc0/pib/core at 10030)
+ thread at 0 (/proc0/pib/core at 10030/thread at 0)
+ thread at 1 (/proc0/pib/core at 10030/thread at 1)
+ core at 10040 (/proc0/pib/core at 10040)
+ thread at 0 (/proc0/pib/core at 10040/thread at 0)
+ thread at 1 (/proc0/pib/core at 10040/thread at 1)
+ fsi at 21000 (/proc1/fsi)
+ pib at 21100 (/proc1/pib)
+ core at 10010 (/proc1/pib/core at 10010)
+ thread at 0 (/proc1/pib/core at 10010/thread at 0)
+ thread at 1 (/proc1/pib/core at 10010/thread at 1)
+ core at 10020 (/proc1/pib/core at 10020)
+ thread at 0 (/proc1/pib/core at 10020/thread at 0)
+ thread at 1 (/proc1/pib/core at 10020/thread at 1)
+ core at 10030 (/proc1/pib/core at 10030)
+ thread at 0 (/proc1/pib/core at 10030/thread at 0)
+ thread at 1 (/proc1/pib/core at 10030/thread at 1)
+ core at 10040 (/proc1/pib/core at 10040)
+ thread at 0 (/proc1/pib/core at 10040/thread at 0)
+ thread at 1 (/proc1/pib/core at 10040/thread at 1)
+ fsi at 22000 (/proc2/fsi)
+ pib at 22100 (/proc2/pib)
+ core at 10010 (/proc2/pib/core at 10010)
+ thread at 0 (/proc2/pib/core at 10010/thread at 0)
+ thread at 1 (/proc2/pib/core at 10010/thread at 1)
+ core at 10020 (/proc2/pib/core at 10020)
+ thread at 0 (/proc2/pib/core at 10020/thread at 0)
+ thread at 1 (/proc2/pib/core at 10020/thread at 1)
+ core at 10030 (/proc2/pib/core at 10030)
+ thread at 0 (/proc2/pib/core at 10030/thread at 0)
+ thread at 1 (/proc2/pib/core at 10030/thread at 1)
+ core at 10040 (/proc2/pib/core at 10040)
+ thread at 0 (/proc2/pib/core at 10040/thread at 0)
+ thread at 1 (/proc2/pib/core at 10040/thread at 1)
+ fsi at 23000 (/proc3/fsi)
+ pib at 23100 (/proc3/pib)
+ core at 10010 (/proc3/pib/core at 10010)
+ thread at 0 (/proc3/pib/core at 10010/thread at 0)
+ thread at 1 (/proc3/pib/core at 10010/thread at 1)
+ core at 10020 (/proc3/pib/core at 10020)
+ thread at 0 (/proc3/pib/core at 10020/thread at 0)
+ thread at 1 (/proc3/pib/core at 10020/thread at 1)
+ core at 10030 (/proc3/pib/core at 10030)
+ thread at 0 (/proc3/pib/core at 10030/thread at 0)
+ thread at 1 (/proc3/pib/core at 10030/thread at 1)
+ core at 10040 (/proc3/pib/core at 10040)
+ thread at 0 (/proc3/pib/core at 10040/thread at 0)
+ thread at 1 (/proc3/pib/core at 10040/thread at 1)
+ fsi at 24000 (/proc4/fsi)
+ pib at 24100 (/proc4/pib)
+ core at 10010 (/proc4/pib/core at 10010)
+ thread at 0 (/proc4/pib/core at 10010/thread at 0)
+ thread at 1 (/proc4/pib/core at 10010/thread at 1)
+ core at 10020 (/proc4/pib/core at 10020)
+ thread at 0 (/proc4/pib/core at 10020/thread at 0)
+ thread at 1 (/proc4/pib/core at 10020/thread at 1)
+ core at 10030 (/proc4/pib/core at 10030)
+ thread at 0 (/proc4/pib/core at 10030/thread at 0)
+ thread at 1 (/proc4/pib/core at 10030/thread at 1)
+ core at 10040 (/proc4/pib/core at 10040)
+ thread at 0 (/proc4/pib/core at 10040/thread at 0)
+ thread at 1 (/proc4/pib/core at 10040/thread at 1)
+ fsi at 25000 (/proc5/fsi)
+ pib at 25100 (/proc5/pib)
+ core at 10010 (/proc5/pib/core at 10010)
+ thread at 0 (/proc5/pib/core at 10010/thread at 0)
+ thread at 1 (/proc5/pib/core at 10010/thread at 1)
+ core at 10020 (/proc5/pib/core at 10020)
+ thread at 0 (/proc5/pib/core at 10020/thread at 0)
+ thread at 1 (/proc5/pib/core at 10020/thread at 1)
+ core at 10030 (/proc5/pib/core at 10030)
+ thread at 0 (/proc5/pib/core at 10030/thread at 0)
+ thread at 1 (/proc5/pib/core at 10030/thread at 1)
+ core at 10040 (/proc5/pib/core at 10040)
+ thread at 0 (/proc5/pib/core at 10040/thread at 0)
+ thread at 1 (/proc5/pib/core at 10040/thread at 1)
+ fsi at 26000 (/proc6/fsi)
+ pib at 26100 (/proc6/pib)
+ core at 10010 (/proc6/pib/core at 10010)
+ thread at 0 (/proc6/pib/core at 10010/thread at 0)
+ thread at 1 (/proc6/pib/core at 10010/thread at 1)
+ core at 10020 (/proc6/pib/core at 10020)
+ thread at 0 (/proc6/pib/core at 10020/thread at 0)
+ thread at 1 (/proc6/pib/core at 10020/thread at 1)
+ core at 10030 (/proc6/pib/core at 10030)
+ thread at 0 (/proc6/pib/core at 10030/thread at 0)
+ thread at 1 (/proc6/pib/core at 10030/thread at 1)
+ core at 10040 (/proc6/pib/core at 10040)
+ thread at 0 (/proc6/pib/core at 10040/thread at 0)
+ thread at 1 (/proc6/pib/core at 10040/thread at 1)
+ fsi at 27000 (/proc7/fsi)
+ pib at 27100 (/proc7/pib)
+ core at 10010 (/proc7/pib/core at 10010)
+ thread at 0 (/proc7/pib/core at 10010/thread at 0)
+ thread at 1 (/proc7/pib/core at 10010/thread at 1)
+ core at 10020 (/proc7/pib/core at 10020)
+ thread at 0 (/proc7/pib/core at 10020/thread at 0)
+ thread at 1 (/proc7/pib/core at 10020/thread at 1)
+ core at 10030 (/proc7/pib/core at 10030)
+ thread at 0 (/proc7/pib/core at 10030/thread at 0)
+ thread at 1 (/proc7/pib/core at 10030/thread at 1)
+ core at 10040 (/proc7/pib/core at 10040)
+ thread at 0 (/proc7/pib/core at 10040/thread at 0)
+ thread at 1 (/proc7/pib/core at 10040/thread at 1)
+EOF
+
+test_run libpdbg_dtree_test rtree
+
+
+test_result 0 <<EOF
+fsi0: /proc0/fsi
+fsi1: /proc1/fsi
+fsi2: /proc2/fsi
+fsi3: /proc3/fsi
+fsi4: /proc4/fsi
+fsi5: /proc5/fsi
+fsi6: /proc6/fsi
+fsi7: /proc7/fsi
+EOF
+
+test_run libpdbg_dtree_test fsi
+
+
+test_result 0 <<EOF
+pib0: /proc0/pib
+pib1: /proc1/pib
+pib2: /proc2/pib
+pib3: /proc3/pib
+pib4: /proc4/pib
+pib5: /proc5/pib
+pib6: /proc6/pib
+pib7: /proc7/pib
+EOF
+
+test_run libpdbg_dtree_test pib
--
2.21.0
More information about the Pdbg
mailing list