Message ID | 20190923084841.18057-14-amitay@ozlabs.org |
---|---|
State | Superseded |
Headers | show |
Series | Add system device tree to libpdbg | expand |
Context | Check | Description |
---|---|---|
snowpatch_ozlabs/apply_patch | success | Successfully applied on branch master (da6691975ea6a06d79cfd2ba9a7a1af39f839a41) |
snowpatch_ozlabs/build-multiarch | success | Test build-multiarch on branch master |
I'm glad we have tests for this traversal stuff, it's all kinda hairy. Acked-by: Alistair Popple <alistair@popple.id.au> On Monday, 23 September 2019 6:48:32 PM AEST Amitay Isaacs wrote: > This test checks system device tree (view) traverse and backend device > tree traverse. > > Signed-off-by: Amitay Isaacs <amitay@ozlabs.org> > --- > Makefile.am | 11 +- > src/tests/libpdbg_dtree_test.c | 117 ++++++++++ > tests/test_tree.sh | 387 +++++++++++++++++++++++++++++++++ > 3 files changed, 513 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 f2c3335..d5bc9ac 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) > > @@ -245,6 +247,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..f6d4cbf > --- /dev/null > +++ b/src/tests/libpdbg_dtree_test.c > @@ -0,0 +1,117 @@ > +/* 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> > + > +extern struct pdbg_target *get_parent(struct pdbg_target *target, bool system); > + > +#define for_each_child(parent, target, system) \ > + for (target = __pdbg_next_child_target(parent, NULL, system); \ > + target; \ > + target = __pdbg_next_child_target(parent, target, system)) > + > +static void print_tree(struct pdbg_target *target, bool system, 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, system) > + print_tree(child, system, level+1); > +} > + > +static void print_rtree(struct pdbg_target *target, bool system, int level) > +{ > + struct pdbg_target *root = pdbg_target_root(); > + const char *name; > + int i; > + > + for (i=0; i<level; i++) > + printf(" "); > + > + name = pdbg_target_dn_name(target); > + if (!name || name[0] == '\0') > + name = "/"; > + > + printf("%s\n", name); > + > + if (target != root) { > + target = get_parent(target, system); > + print_rtree(target, system, level+1); > + } > +} > + > +static void usage(void) > +{ > + fprintf(stderr, "Usage: libpdbg_dtree_test tree|rtree system|backend <path>\n"); > + exit(1); > +} > + > +int main(int argc, const char **argv) > +{ > + struct pdbg_target *target; > + bool do_system; > + bool do_tree; > + > + if (argc != 4) > + usage(); > + > + if (strcmp(argv[1], "tree") == 0) { > + do_tree = true; > + } else if (strcmp(argv[1], "rtree") == 0) { > + do_tree = false; > + } else { > + usage(); > + } > + > + if (strcmp(argv[2], "system") == 0) { > + do_system = true; > + } else if (strcmp(argv[2], "backend") == 0) { > + do_system = false; > + } else { > + usage(); > + } > + > + pdbg_targets_init(NULL); > + > + target = pdbg_target_from_path(NULL, argv[3]); > + if (!target) > + exit(1); > + > + if (do_tree) { > + print_tree(target, do_system, 0); > + } else { > + print_rtree(target, do_system, 0); > + } > + > + return 0; > +} > diff --git a/tests/test_tree.sh b/tests/test_tree.sh > new file mode 100755 > index 0000000..5a9daff > --- /dev/null > +++ b/tests/test_tree.sh > @@ -0,0 +1,387 @@ > +#!/bin/sh > + > +. $(dirname "$0")/driver.sh > + > +test_group "tree tests" > + > +test_result 0 <<EOF > +/ (/) > + proc0 (/proc0) > + fsi@20000 (/proc0/fsi) > + pib@20100 (/proc0/pib) > + core@10010 (/proc0/pib/core@10010) > + thread@0 (/proc0/pib/core@10010/thread@0) > + thread@1 (/proc0/pib/core@10010/thread@1) > + core@10020 (/proc0/pib/core@10020) > + thread@0 (/proc0/pib/core@10020/thread@0) > + thread@1 (/proc0/pib/core@10020/thread@1) > + core@10030 (/proc0/pib/core@10030) > + thread@0 (/proc0/pib/core@10030/thread@0) > + thread@1 (/proc0/pib/core@10030/thread@1) > + core@10040 (/proc0/pib/core@10040) > + thread@0 (/proc0/pib/core@10040/thread@0) > + thread@1 (/proc0/pib/core@10040/thread@1) > + proc1 (/proc1) > + fsi@21000 (/proc1/fsi) > + pib@21100 (/proc1/pib) > + core@10010 (/proc1/pib/core@10010) > + thread@0 (/proc1/pib/core@10010/thread@0) > + thread@1 (/proc1/pib/core@10010/thread@1) > + core@10020 (/proc1/pib/core@10020) > + thread@0 (/proc1/pib/core@10020/thread@0) > + thread@1 (/proc1/pib/core@10020/thread@1) > + core@10030 (/proc1/pib/core@10030) > + thread@0 (/proc1/pib/core@10030/thread@0) > + thread@1 (/proc1/pib/core@10030/thread@1) > + core@10040 (/proc1/pib/core@10040) > + thread@0 (/proc1/pib/core@10040/thread@0) > + thread@1 (/proc1/pib/core@10040/thread@1) > + proc2 (/proc2) > + fsi@22000 (/proc2/fsi) > + pib@22100 (/proc2/pib) > + core@10010 (/proc2/pib/core@10010) > + thread@0 (/proc2/pib/core@10010/thread@0) > + thread@1 (/proc2/pib/core@10010/thread@1) > + core@10020 (/proc2/pib/core@10020) > + thread@0 (/proc2/pib/core@10020/thread@0) > + thread@1 (/proc2/pib/core@10020/thread@1) > + core@10030 (/proc2/pib/core@10030) > + thread@0 (/proc2/pib/core@10030/thread@0) > + thread@1 (/proc2/pib/core@10030/thread@1) > + core@10040 (/proc2/pib/core@10040) > + thread@0 (/proc2/pib/core@10040/thread@0) > + thread@1 (/proc2/pib/core@10040/thread@1) > + proc3 (/proc3) > + fsi@23000 (/proc3/fsi) > + pib@23100 (/proc3/pib) > + core@10010 (/proc3/pib/core@10010) > + thread@0 (/proc3/pib/core@10010/thread@0) > + thread@1 (/proc3/pib/core@10010/thread@1) > + core@10020 (/proc3/pib/core@10020) > + thread@0 (/proc3/pib/core@10020/thread@0) > + thread@1 (/proc3/pib/core@10020/thread@1) > + core@10030 (/proc3/pib/core@10030) > + thread@0 (/proc3/pib/core@10030/thread@0) > + thread@1 (/proc3/pib/core@10030/thread@1) > + core@10040 (/proc3/pib/core@10040) > + thread@0 (/proc3/pib/core@10040/thread@0) > + thread@1 (/proc3/pib/core@10040/thread@1) > + proc4 (/proc4) > + fsi@24000 (/proc4/fsi) > + pib@24100 (/proc4/pib) > + core@10010 (/proc4/pib/core@10010) > + thread@0 (/proc4/pib/core@10010/thread@0) > + thread@1 (/proc4/pib/core@10010/thread@1) > + core@10020 (/proc4/pib/core@10020) > + thread@0 (/proc4/pib/core@10020/thread@0) > + thread@1 (/proc4/pib/core@10020/thread@1) > + core@10030 (/proc4/pib/core@10030) > + thread@0 (/proc4/pib/core@10030/thread@0) > + thread@1 (/proc4/pib/core@10030/thread@1) > + core@10040 (/proc4/pib/core@10040) > + thread@0 (/proc4/pib/core@10040/thread@0) > + thread@1 (/proc4/pib/core@10040/thread@1) > + proc5 (/proc5) > + fsi@25000 (/proc5/fsi) > + pib@25100 (/proc5/pib) > + core@10010 (/proc5/pib/core@10010) > + thread@0 (/proc5/pib/core@10010/thread@0) > + thread@1 (/proc5/pib/core@10010/thread@1) > + core@10020 (/proc5/pib/core@10020) > + thread@0 (/proc5/pib/core@10020/thread@0) > + thread@1 (/proc5/pib/core@10020/thread@1) > + core@10030 (/proc5/pib/core@10030) > + thread@0 (/proc5/pib/core@10030/thread@0) > + thread@1 (/proc5/pib/core@10030/thread@1) > + core@10040 (/proc5/pib/core@10040) > + thread@0 (/proc5/pib/core@10040/thread@0) > + thread@1 (/proc5/pib/core@10040/thread@1) > + proc6 (/proc6) > + fsi@26000 (/proc6/fsi) > + pib@26100 (/proc6/pib) > + core@10010 (/proc6/pib/core@10010) > + thread@0 (/proc6/pib/core@10010/thread@0) > + thread@1 (/proc6/pib/core@10010/thread@1) > + core@10020 (/proc6/pib/core@10020) > + thread@0 (/proc6/pib/core@10020/thread@0) > + thread@1 (/proc6/pib/core@10020/thread@1) > + core@10030 (/proc6/pib/core@10030) > + thread@0 (/proc6/pib/core@10030/thread@0) > + thread@1 (/proc6/pib/core@10030/thread@1) > + core@10040 (/proc6/pib/core@10040) > + thread@0 (/proc6/pib/core@10040/thread@0) > + thread@1 (/proc6/pib/core@10040/thread@1) > + proc7 (/proc7) > + fsi@27000 (/proc7/fsi) > + pib@27100 (/proc7/pib) > + core@10010 (/proc7/pib/core@10010) > + thread@0 (/proc7/pib/core@10010/thread@0) > + thread@1 (/proc7/pib/core@10010/thread@1) > + core@10020 (/proc7/pib/core@10020) > + thread@0 (/proc7/pib/core@10020/thread@0) > + thread@1 (/proc7/pib/core@10020/thread@1) > + core@10030 (/proc7/pib/core@10030) > + thread@0 (/proc7/pib/core@10030/thread@0) > + thread@1 (/proc7/pib/core@10030/thread@1) > + core@10040 (/proc7/pib/core@10040) > + thread@0 (/proc7/pib/core@10040/thread@0) > + thread@1 (/proc7/pib/core@10040/thread@1) > +EOF > + > +test_run libpdbg_dtree_test tree system / > + > + > +test_result 0 <<EOF > +/ (/) > + fsi@20000 (/proc0/fsi) > + pib@20100 (/proc0/pib) > + core@10010 (/proc0/pib/core@10010) > + thread@0 (/proc0/pib/core@10010/thread@0) > + thread@1 (/proc0/pib/core@10010/thread@1) > + core@10020 (/proc0/pib/core@10020) > + thread@0 (/proc0/pib/core@10020/thread@0) > + thread@1 (/proc0/pib/core@10020/thread@1) > + core@10030 (/proc0/pib/core@10030) > + thread@0 (/proc0/pib/core@10030/thread@0) > + thread@1 (/proc0/pib/core@10030/thread@1) > + core@10040 (/proc0/pib/core@10040) > + thread@0 (/proc0/pib/core@10040/thread@0) > + thread@1 (/proc0/pib/core@10040/thread@1) > + fsi@21000 (/proc1/fsi) > + pib@21100 (/proc1/pib) > + core@10010 (/proc1/pib/core@10010) > + thread@0 (/proc1/pib/core@10010/thread@0) > + thread@1 (/proc1/pib/core@10010/thread@1) > + core@10020 (/proc1/pib/core@10020) > + thread@0 (/proc1/pib/core@10020/thread@0) > + thread@1 (/proc1/pib/core@10020/thread@1) > + core@10030 (/proc1/pib/core@10030) > + thread@0 (/proc1/pib/core@10030/thread@0) > + thread@1 (/proc1/pib/core@10030/thread@1) > + core@10040 (/proc1/pib/core@10040) > + thread@0 (/proc1/pib/core@10040/thread@0) > + thread@1 (/proc1/pib/core@10040/thread@1) > + fsi@22000 (/proc2/fsi) > + pib@22100 (/proc2/pib) > + core@10010 (/proc2/pib/core@10010) > + thread@0 (/proc2/pib/core@10010/thread@0) > + thread@1 (/proc2/pib/core@10010/thread@1) > + core@10020 (/proc2/pib/core@10020) > + thread@0 (/proc2/pib/core@10020/thread@0) > + thread@1 (/proc2/pib/core@10020/thread@1) > + core@10030 (/proc2/pib/core@10030) > + thread@0 (/proc2/pib/core@10030/thread@0) > + thread@1 (/proc2/pib/core@10030/thread@1) > + core@10040 (/proc2/pib/core@10040) > + thread@0 (/proc2/pib/core@10040/thread@0) > + thread@1 (/proc2/pib/core@10040/thread@1) > + fsi@23000 (/proc3/fsi) > + pib@23100 (/proc3/pib) > + core@10010 (/proc3/pib/core@10010) > + thread@0 (/proc3/pib/core@10010/thread@0) > + thread@1 (/proc3/pib/core@10010/thread@1) > + core@10020 (/proc3/pib/core@10020) > + thread@0 (/proc3/pib/core@10020/thread@0) > + thread@1 (/proc3/pib/core@10020/thread@1) > + core@10030 (/proc3/pib/core@10030) > + thread@0 (/proc3/pib/core@10030/thread@0) > + thread@1 (/proc3/pib/core@10030/thread@1) > + core@10040 (/proc3/pib/core@10040) > + thread@0 (/proc3/pib/core@10040/thread@0) > + thread@1 (/proc3/pib/core@10040/thread@1) > + fsi@24000 (/proc4/fsi) > + pib@24100 (/proc4/pib) > + core@10010 (/proc4/pib/core@10010) > + thread@0 (/proc4/pib/core@10010/thread@0) > + thread@1 (/proc4/pib/core@10010/thread@1) > + core@10020 (/proc4/pib/core@10020) > + thread@0 (/proc4/pib/core@10020/thread@0) > + thread@1 (/proc4/pib/core@10020/thread@1) > + core@10030 (/proc4/pib/core@10030) > + thread@0 (/proc4/pib/core@10030/thread@0) > + thread@1 (/proc4/pib/core@10030/thread@1) > + core@10040 (/proc4/pib/core@10040) > + thread@0 (/proc4/pib/core@10040/thread@0) > + thread@1 (/proc4/pib/core@10040/thread@1) > + fsi@25000 (/proc5/fsi) > + pib@25100 (/proc5/pib) > + core@10010 (/proc5/pib/core@10010) > + thread@0 (/proc5/pib/core@10010/thread@0) > + thread@1 (/proc5/pib/core@10010/thread@1) > + core@10020 (/proc5/pib/core@10020) > + thread@0 (/proc5/pib/core@10020/thread@0) > + thread@1 (/proc5/pib/core@10020/thread@1) > + core@10030 (/proc5/pib/core@10030) > + thread@0 (/proc5/pib/core@10030/thread@0) > + thread@1 (/proc5/pib/core@10030/thread@1) > + core@10040 (/proc5/pib/core@10040) > + thread@0 (/proc5/pib/core@10040/thread@0) > + thread@1 (/proc5/pib/core@10040/thread@1) > + fsi@26000 (/proc6/fsi) > + pib@26100 (/proc6/pib) > + core@10010 (/proc6/pib/core@10010) > + thread@0 (/proc6/pib/core@10010/thread@0) > + thread@1 (/proc6/pib/core@10010/thread@1) > + core@10020 (/proc6/pib/core@10020) > + thread@0 (/proc6/pib/core@10020/thread@0) > + thread@1 (/proc6/pib/core@10020/thread@1) > + core@10030 (/proc6/pib/core@10030) > + thread@0 (/proc6/pib/core@10030/thread@0) > + thread@1 (/proc6/pib/core@10030/thread@1) > + core@10040 (/proc6/pib/core@10040) > + thread@0 (/proc6/pib/core@10040/thread@0) > + thread@1 (/proc6/pib/core@10040/thread@1) > + fsi@27000 (/proc7/fsi) > + pib@27100 (/proc7/pib) > + core@10010 (/proc7/pib/core@10010) > + thread@0 (/proc7/pib/core@10010/thread@0) > + thread@1 (/proc7/pib/core@10010/thread@1) > + core@10020 (/proc7/pib/core@10020) > + thread@0 (/proc7/pib/core@10020/thread@0) > + thread@1 (/proc7/pib/core@10020/thread@1) > + core@10030 (/proc7/pib/core@10030) > + thread@0 (/proc7/pib/core@10030/thread@0) > + thread@1 (/proc7/pib/core@10030/thread@1) > + core@10040 (/proc7/pib/core@10040) > + thread@0 (/proc7/pib/core@10040/thread@0) > + thread@1 (/proc7/pib/core@10040/thread@1) > +EOF > + > +test_run libpdbg_dtree_test tree backend / > + > + > +test_result 0 <<EOF > +proc1 (/proc1) > + fsi@21000 (/proc1/fsi) > + pib@21100 (/proc1/pib) > + core@10010 (/proc1/pib/core@10010) > + thread@0 (/proc1/pib/core@10010/thread@0) > + thread@1 (/proc1/pib/core@10010/thread@1) > + core@10020 (/proc1/pib/core@10020) > + thread@0 (/proc1/pib/core@10020/thread@0) > + thread@1 (/proc1/pib/core@10020/thread@1) > + core@10030 (/proc1/pib/core@10030) > + thread@0 (/proc1/pib/core@10030/thread@0) > + thread@1 (/proc1/pib/core@10030/thread@1) > + core@10040 (/proc1/pib/core@10040) > + thread@0 (/proc1/pib/core@10040/thread@0) > + thread@1 (/proc1/pib/core@10040/thread@1) > +EOF > + > +test_run libpdbg_dtree_test tree system /proc1 > + > + > +test_result 0 <<EOF > +proc1 (/proc1) > +EOF > + > +test_run libpdbg_dtree_test tree backend /proc1 > + > + > +test_result 0 <<EOF > +fsi@20000 (/proc0/fsi) > +EOF > + > +test_run libpdbg_dtree_test tree system /proc0/fsi > + > + > +test_result 0 <<EOF > +fsi@20000 (/proc0/fsi) > + pib@20100 (/proc0/pib) > + core@10010 (/proc0/pib/core@10010) > + thread@0 (/proc0/pib/core@10010/thread@0) > + thread@1 (/proc0/pib/core@10010/thread@1) > + core@10020 (/proc0/pib/core@10020) > + thread@0 (/proc0/pib/core@10020/thread@0) > + thread@1 (/proc0/pib/core@10020/thread@1) > + core@10030 (/proc0/pib/core@10030) > + thread@0 (/proc0/pib/core@10030/thread@0) > + thread@1 (/proc0/pib/core@10030/thread@1) > + core@10040 (/proc0/pib/core@10040) > + thread@0 (/proc0/pib/core@10040/thread@0) > + thread@1 (/proc0/pib/core@10040/thread@1) > +EOF > + > +test_run libpdbg_dtree_test tree backend /proc0/fsi > + > + > +test_result 0 <<EOF > +pib@22100 (/proc2/pib) > + core@10010 (/proc2/pib/core@10010) > + thread@0 (/proc2/pib/core@10010/thread@0) > + thread@1 (/proc2/pib/core@10010/thread@1) > + core@10020 (/proc2/pib/core@10020) > + thread@0 (/proc2/pib/core@10020/thread@0) > + thread@1 (/proc2/pib/core@10020/thread@1) > + core@10030 (/proc2/pib/core@10030) > + thread@0 (/proc2/pib/core@10030/thread@0) > + thread@1 (/proc2/pib/core@10030/thread@1) > + core@10040 (/proc2/pib/core@10040) > + thread@0 (/proc2/pib/core@10040/thread@0) > + thread@1 (/proc2/pib/core@10040/thread@1) > +EOF > + > +test_run libpdbg_dtree_test tree system /proc2/pib > + > + > +test_result 0 <<EOF > +pib@22100 (/proc2/pib) > + core@10010 (/proc2/pib/core@10010) > + thread@0 (/proc2/pib/core@10010/thread@0) > + thread@1 (/proc2/pib/core@10010/thread@1) > + core@10020 (/proc2/pib/core@10020) > + thread@0 (/proc2/pib/core@10020/thread@0) > + thread@1 (/proc2/pib/core@10020/thread@1) > + core@10030 (/proc2/pib/core@10030) > + thread@0 (/proc2/pib/core@10030/thread@0) > + thread@1 (/proc2/pib/core@10030/thread@1) > + core@10040 (/proc2/pib/core@10040) > + thread@0 (/proc2/pib/core@10040/thread@0) > + thread@1 (/proc2/pib/core@10040/thread@1) > +EOF > + > +test_run libpdbg_dtree_test tree backend /proc2/pib > + > + > +test_result 0 <<EOF > +thread@1 > + core@10040 > + pib@27100 > + proc7 > + / > +EOF > + > +test_run libpdbg_dtree_test rtree system /proc7/pib/core@10040/thread@1 > + > + > +test_result 0 <<EOF > +thread@1 > + core@10040 > + pib@27100 > + proc7 > + / > +EOF > + > +test_run libpdbg_dtree_test rtree system /fsi@27000/pib@27100/core@10040/ thread@1 > + > + > +test_result 0 <<EOF > +thread@1 > + core@10040 > + pib@27100 > + fsi@27000 > + / > +EOF > + > +test_run libpdbg_dtree_test rtree backend /proc7/pib/core@10040/thread@1 > + > + > +test_result 0 <<EOF > +thread@1 > + core@10040 > + pib@27100 > + fsi@27000 > + / > +EOF > + > +test_run libpdbg_dtree_test rtree backend /fsi@27000/pib@27100/core@10040/ thread@1 >
On Thu, 2019-09-26 at 15:29 +1000, Alistair Popple wrote: > I'm glad we have tests for this traversal stuff, it's all kinda > hairy. I agree. Some of the code I could get right only after looking at the test failures. In couple of places, the obvious code turned out to be wrong. I spent quite a bit of time restructuring the tests to ensure I can catch all the corner cases in both system and backend traversals. > > Acked-by: Alistair Popple <alistair@popple.id.au> > > On Monday, 23 September 2019 6:48:32 PM AEST Amitay Isaacs wrote: > > This test checks system device tree (view) traverse and backend > > device > > tree traverse. > > > > Signed-off-by: Amitay Isaacs <amitay@ozlabs.org> > > --- > > Makefile.am | 11 +- > > src/tests/libpdbg_dtree_test.c | 117 ++++++++++ > > tests/test_tree.sh | 387 > > +++++++++++++++++++++++++++++++++ > > 3 files changed, 513 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 f2c3335..d5bc9ac 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) > > > > @@ -245,6 +247,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..f6d4cbf > > --- /dev/null > > +++ b/src/tests/libpdbg_dtree_test.c > > @@ -0,0 +1,117 @@ > > +/* 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> > > + > > +extern struct pdbg_target *get_parent(struct pdbg_target *target, > > bool > system); > > + > > +#define for_each_child(parent, target, system) \ > > + for (target = __pdbg_next_child_target(parent, NULL, system); \ > > + target; \ > > + target = __pdbg_next_child_target(parent, target, system)) > > + > > +static void print_tree(struct pdbg_target *target, bool system, > > 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, system) > > + print_tree(child, system, level+1); > > +} > > + > > +static void print_rtree(struct pdbg_target *target, bool system, > > int level) > > +{ > > + struct pdbg_target *root = pdbg_target_root(); > > + const char *name; > > + int i; > > + > > + for (i=0; i<level; i++) > > + printf(" "); > > + > > + name = pdbg_target_dn_name(target); > > + if (!name || name[0] == '\0') > > + name = "/"; > > + > > + printf("%s\n", name); > > + > > + if (target != root) { > > + target = get_parent(target, system); > > + print_rtree(target, system, level+1); > > + } > > +} > > + > > +static void usage(void) > > +{ > > + fprintf(stderr, "Usage: libpdbg_dtree_test tree|rtree > > system|backend > <path>\n"); > > + exit(1); > > +} > > + > > +int main(int argc, const char **argv) > > +{ > > + struct pdbg_target *target; > > + bool do_system; > > + bool do_tree; > > + > > + if (argc != 4) > > + usage(); > > + > > + if (strcmp(argv[1], "tree") == 0) { > > + do_tree = true; > > + } else if (strcmp(argv[1], "rtree") == 0) { > > + do_tree = false; > > + } else { > > + usage(); > > + } > > + > > + if (strcmp(argv[2], "system") == 0) { > > + do_system = true; > > + } else if (strcmp(argv[2], "backend") == 0) { > > + do_system = false; > > + } else { > > + usage(); > > + } > > + > > + pdbg_targets_init(NULL); > > + > > + target = pdbg_target_from_path(NULL, argv[3]); > > + if (!target) > > + exit(1); > > + > > + if (do_tree) { > > + print_tree(target, do_system, 0); > > + } else { > > + print_rtree(target, do_system, 0); > > + } > > + > > + return 0; > > +} > > diff --git a/tests/test_tree.sh b/tests/test_tree.sh > > new file mode 100755 > > index 0000000..5a9daff > > --- /dev/null > > +++ b/tests/test_tree.sh > > @@ -0,0 +1,387 @@ > > +#!/bin/sh > > + > > +. $(dirname "$0")/driver.sh > > + > > +test_group "tree tests" > > + > > +test_result 0 <<EOF > > +/ (/) > > + proc0 (/proc0) > > + fsi@20000 (/proc0/fsi) > > + pib@20100 (/proc0/pib) > > + core@10010 (/proc0/pib/core@10010) > > + thread@0 (/proc0/pib/core@10010/thread@0) > > + thread@1 (/proc0/pib/core@10010/thread@1) > > + core@10020 (/proc0/pib/core@10020) > > + thread@0 (/proc0/pib/core@10020/thread@0) > > + thread@1 (/proc0/pib/core@10020/thread@1) > > + core@10030 (/proc0/pib/core@10030) > > + thread@0 (/proc0/pib/core@10030/thread@0) > > + thread@1 (/proc0/pib/core@10030/thread@1) > > + core@10040 (/proc0/pib/core@10040) > > + thread@0 (/proc0/pib/core@10040/thread@0) > > + thread@1 (/proc0/pib/core@10040/thread@1) > > + proc1 (/proc1) > > + fsi@21000 (/proc1/fsi) > > + pib@21100 (/proc1/pib) > > + core@10010 (/proc1/pib/core@10010) > > + thread@0 (/proc1/pib/core@10010/thread@0) > > + thread@1 (/proc1/pib/core@10010/thread@1) > > + core@10020 (/proc1/pib/core@10020) > > + thread@0 (/proc1/pib/core@10020/thread@0) > > + thread@1 (/proc1/pib/core@10020/thread@1) > > + core@10030 (/proc1/pib/core@10030) > > + thread@0 (/proc1/pib/core@10030/thread@0) > > + thread@1 (/proc1/pib/core@10030/thread@1) > > + core@10040 (/proc1/pib/core@10040) > > + thread@0 (/proc1/pib/core@10040/thread@0) > > + thread@1 (/proc1/pib/core@10040/thread@1) > > + proc2 (/proc2) > > + fsi@22000 (/proc2/fsi) > > + pib@22100 (/proc2/pib) > > + core@10010 (/proc2/pib/core@10010) > > + thread@0 (/proc2/pib/core@10010/thread@0) > > + thread@1 (/proc2/pib/core@10010/thread@1) > > + core@10020 (/proc2/pib/core@10020) > > + thread@0 (/proc2/pib/core@10020/thread@0) > > + thread@1 (/proc2/pib/core@10020/thread@1) > > + core@10030 (/proc2/pib/core@10030) > > + thread@0 (/proc2/pib/core@10030/thread@0) > > + thread@1 (/proc2/pib/core@10030/thread@1) > > + core@10040 (/proc2/pib/core@10040) > > + thread@0 (/proc2/pib/core@10040/thread@0) > > + thread@1 (/proc2/pib/core@10040/thread@1) > > + proc3 (/proc3) > > + fsi@23000 (/proc3/fsi) > > + pib@23100 (/proc3/pib) > > + core@10010 (/proc3/pib/core@10010) > > + thread@0 (/proc3/pib/core@10010/thread@0) > > + thread@1 (/proc3/pib/core@10010/thread@1) > > + core@10020 (/proc3/pib/core@10020) > > + thread@0 (/proc3/pib/core@10020/thread@0) > > + thread@1 (/proc3/pib/core@10020/thread@1) > > + core@10030 (/proc3/pib/core@10030) > > + thread@0 (/proc3/pib/core@10030/thread@0) > > + thread@1 (/proc3/pib/core@10030/thread@1) > > + core@10040 (/proc3/pib/core@10040) > > + thread@0 (/proc3/pib/core@10040/thread@0) > > + thread@1 (/proc3/pib/core@10040/thread@1) > > + proc4 (/proc4) > > + fsi@24000 (/proc4/fsi) > > + pib@24100 (/proc4/pib) > > + core@10010 (/proc4/pib/core@10010) > > + thread@0 (/proc4/pib/core@10010/thread@0) > > + thread@1 (/proc4/pib/core@10010/thread@1) > > + core@10020 (/proc4/pib/core@10020) > > + thread@0 (/proc4/pib/core@10020/thread@0) > > + thread@1 (/proc4/pib/core@10020/thread@1) > > + core@10030 (/proc4/pib/core@10030) > > + thread@0 (/proc4/pib/core@10030/thread@0) > > + thread@1 (/proc4/pib/core@10030/thread@1) > > + core@10040 (/proc4/pib/core@10040) > > + thread@0 (/proc4/pib/core@10040/thread@0) > > + thread@1 (/proc4/pib/core@10040/thread@1) > > + proc5 (/proc5) > > + fsi@25000 (/proc5/fsi) > > + pib@25100 (/proc5/pib) > > + core@10010 (/proc5/pib/core@10010) > > + thread@0 (/proc5/pib/core@10010/thread@0) > > + thread@1 (/proc5/pib/core@10010/thread@1) > > + core@10020 (/proc5/pib/core@10020) > > + thread@0 (/proc5/pib/core@10020/thread@0) > > + thread@1 (/proc5/pib/core@10020/thread@1) > > + core@10030 (/proc5/pib/core@10030) > > + thread@0 (/proc5/pib/core@10030/thread@0) > > + thread@1 (/proc5/pib/core@10030/thread@1) > > + core@10040 (/proc5/pib/core@10040) > > + thread@0 (/proc5/pib/core@10040/thread@0) > > + thread@1 (/proc5/pib/core@10040/thread@1) > > + proc6 (/proc6) > > + fsi@26000 (/proc6/fsi) > > + pib@26100 (/proc6/pib) > > + core@10010 (/proc6/pib/core@10010) > > + thread@0 (/proc6/pib/core@10010/thread@0) > > + thread@1 (/proc6/pib/core@10010/thread@1) > > + core@10020 (/proc6/pib/core@10020) > > + thread@0 (/proc6/pib/core@10020/thread@0) > > + thread@1 (/proc6/pib/core@10020/thread@1) > > + core@10030 (/proc6/pib/core@10030) > > + thread@0 (/proc6/pib/core@10030/thread@0) > > + thread@1 (/proc6/pib/core@10030/thread@1) > > + core@10040 (/proc6/pib/core@10040) > > + thread@0 (/proc6/pib/core@10040/thread@0) > > + thread@1 (/proc6/pib/core@10040/thread@1) > > + proc7 (/proc7) > > + fsi@27000 (/proc7/fsi) > > + pib@27100 (/proc7/pib) > > + core@10010 (/proc7/pib/core@10010) > > + thread@0 (/proc7/pib/core@10010/thread@0) > > + thread@1 (/proc7/pib/core@10010/thread@1) > > + core@10020 (/proc7/pib/core@10020) > > + thread@0 (/proc7/pib/core@10020/thread@0) > > + thread@1 (/proc7/pib/core@10020/thread@1) > > + core@10030 (/proc7/pib/core@10030) > > + thread@0 (/proc7/pib/core@10030/thread@0) > > + thread@1 (/proc7/pib/core@10030/thread@1) > > + core@10040 (/proc7/pib/core@10040) > > + thread@0 (/proc7/pib/core@10040/thread@0) > > + thread@1 (/proc7/pib/core@10040/thread@1) > > +EOF > > + > > +test_run libpdbg_dtree_test tree system / > > + > > + > > +test_result 0 <<EOF > > +/ (/) > > + fsi@20000 (/proc0/fsi) > > + pib@20100 (/proc0/pib) > > + core@10010 (/proc0/pib/core@10010) > > + thread@0 (/proc0/pib/core@10010/thread@0) > > + thread@1 (/proc0/pib/core@10010/thread@1) > > + core@10020 (/proc0/pib/core@10020) > > + thread@0 (/proc0/pib/core@10020/thread@0) > > + thread@1 (/proc0/pib/core@10020/thread@1) > > + core@10030 (/proc0/pib/core@10030) > > + thread@0 (/proc0/pib/core@10030/thread@0) > > + thread@1 (/proc0/pib/core@10030/thread@1) > > + core@10040 (/proc0/pib/core@10040) > > + thread@0 (/proc0/pib/core@10040/thread@0) > > + thread@1 (/proc0/pib/core@10040/thread@1) > > + fsi@21000 (/proc1/fsi) > > + pib@21100 (/proc1/pib) > > + core@10010 (/proc1/pib/core@10010) > > + thread@0 (/proc1/pib/core@10010/thread@0) > > + thread@1 (/proc1/pib/core@10010/thread@1) > > + core@10020 (/proc1/pib/core@10020) > > + thread@0 (/proc1/pib/core@10020/thread@0) > > + thread@1 (/proc1/pib/core@10020/thread@1) > > + core@10030 (/proc1/pib/core@10030) > > + thread@0 (/proc1/pib/core@10030/thread@0) > > + thread@1 (/proc1/pib/core@10030/thread@1) > > + core@10040 (/proc1/pib/core@10040) > > + thread@0 (/proc1/pib/core@10040/thread@0) > > + thread@1 (/proc1/pib/core@10040/thread@1) > > + fsi@22000 (/proc2/fsi) > > + pib@22100 (/proc2/pib) > > + core@10010 (/proc2/pib/core@10010) > > + thread@0 (/proc2/pib/core@10010/thread@0) > > + thread@1 (/proc2/pib/core@10010/thread@1) > > + core@10020 (/proc2/pib/core@10020) > > + thread@0 (/proc2/pib/core@10020/thread@0) > > + thread@1 (/proc2/pib/core@10020/thread@1) > > + core@10030 (/proc2/pib/core@10030) > > + thread@0 (/proc2/pib/core@10030/thread@0) > > + thread@1 (/proc2/pib/core@10030/thread@1) > > + core@10040 (/proc2/pib/core@10040) > > + thread@0 (/proc2/pib/core@10040/thread@0) > > + thread@1 (/proc2/pib/core@10040/thread@1) > > + fsi@23000 (/proc3/fsi) > > + pib@23100 (/proc3/pib) > > + core@10010 (/proc3/pib/core@10010) > > + thread@0 (/proc3/pib/core@10010/thread@0) > > + thread@1 (/proc3/pib/core@10010/thread@1) > > + core@10020 (/proc3/pib/core@10020) > > + thread@0 (/proc3/pib/core@10020/thread@0) > > + thread@1 (/proc3/pib/core@10020/thread@1) > > + core@10030 (/proc3/pib/core@10030) > > + thread@0 (/proc3/pib/core@10030/thread@0) > > + thread@1 (/proc3/pib/core@10030/thread@1) > > + core@10040 (/proc3/pib/core@10040) > > + thread@0 (/proc3/pib/core@10040/thread@0) > > + thread@1 (/proc3/pib/core@10040/thread@1) > > + fsi@24000 (/proc4/fsi) > > + pib@24100 (/proc4/pib) > > + core@10010 (/proc4/pib/core@10010) > > + thread@0 (/proc4/pib/core@10010/thread@0) > > + thread@1 (/proc4/pib/core@10010/thread@1) > > + core@10020 (/proc4/pib/core@10020) > > + thread@0 (/proc4/pib/core@10020/thread@0) > > + thread@1 (/proc4/pib/core@10020/thread@1) > > + core@10030 (/proc4/pib/core@10030) > > + thread@0 (/proc4/pib/core@10030/thread@0) > > + thread@1 (/proc4/pib/core@10030/thread@1) > > + core@10040 (/proc4/pib/core@10040) > > + thread@0 (/proc4/pib/core@10040/thread@0) > > + thread@1 (/proc4/pib/core@10040/thread@1) > > + fsi@25000 (/proc5/fsi) > > + pib@25100 (/proc5/pib) > > + core@10010 (/proc5/pib/core@10010) > > + thread@0 (/proc5/pib/core@10010/thread@0) > > + thread@1 (/proc5/pib/core@10010/thread@1) > > + core@10020 (/proc5/pib/core@10020) > > + thread@0 (/proc5/pib/core@10020/thread@0) > > + thread@1 (/proc5/pib/core@10020/thread@1) > > + core@10030 (/proc5/pib/core@10030) > > + thread@0 (/proc5/pib/core@10030/thread@0) > > + thread@1 (/proc5/pib/core@10030/thread@1) > > + core@10040 (/proc5/pib/core@10040) > > + thread@0 (/proc5/pib/core@10040/thread@0) > > + thread@1 (/proc5/pib/core@10040/thread@1) > > + fsi@26000 (/proc6/fsi) > > + pib@26100 (/proc6/pib) > > + core@10010 (/proc6/pib/core@10010) > > + thread@0 (/proc6/pib/core@10010/thread@0) > > + thread@1 (/proc6/pib/core@10010/thread@1) > > + core@10020 (/proc6/pib/core@10020) > > + thread@0 (/proc6/pib/core@10020/thread@0) > > + thread@1 (/proc6/pib/core@10020/thread@1) > > + core@10030 (/proc6/pib/core@10030) > > + thread@0 (/proc6/pib/core@10030/thread@0) > > + thread@1 (/proc6/pib/core@10030/thread@1) > > + core@10040 (/proc6/pib/core@10040) > > + thread@0 (/proc6/pib/core@10040/thread@0) > > + thread@1 (/proc6/pib/core@10040/thread@1) > > + fsi@27000 (/proc7/fsi) > > + pib@27100 (/proc7/pib) > > + core@10010 (/proc7/pib/core@10010) > > + thread@0 (/proc7/pib/core@10010/thread@0) > > + thread@1 (/proc7/pib/core@10010/thread@1) > > + core@10020 (/proc7/pib/core@10020) > > + thread@0 (/proc7/pib/core@10020/thread@0) > > + thread@1 (/proc7/pib/core@10020/thread@1) > > + core@10030 (/proc7/pib/core@10030) > > + thread@0 (/proc7/pib/core@10030/thread@0) > > + thread@1 (/proc7/pib/core@10030/thread@1) > > + core@10040 (/proc7/pib/core@10040) > > + thread@0 (/proc7/pib/core@10040/thread@0) > > + thread@1 (/proc7/pib/core@10040/thread@1) > > +EOF > > + > > +test_run libpdbg_dtree_test tree backend / > > + > > + > > +test_result 0 <<EOF > > +proc1 (/proc1) > > + fsi@21000 (/proc1/fsi) > > + pib@21100 (/proc1/pib) > > + core@10010 (/proc1/pib/core@10010) > > + thread@0 (/proc1/pib/core@10010/thread@0) > > + thread@1 (/proc1/pib/core@10010/thread@1) > > + core@10020 (/proc1/pib/core@10020) > > + thread@0 (/proc1/pib/core@10020/thread@0) > > + thread@1 (/proc1/pib/core@10020/thread@1) > > + core@10030 (/proc1/pib/core@10030) > > + thread@0 (/proc1/pib/core@10030/thread@0) > > + thread@1 (/proc1/pib/core@10030/thread@1) > > + core@10040 (/proc1/pib/core@10040) > > + thread@0 (/proc1/pib/core@10040/thread@0) > > + thread@1 (/proc1/pib/core@10040/thread@1) > > +EOF > > + > > +test_run libpdbg_dtree_test tree system /proc1 > > + > > + > > +test_result 0 <<EOF > > +proc1 (/proc1) > > +EOF > > + > > +test_run libpdbg_dtree_test tree backend /proc1 > > + > > + > > +test_result 0 <<EOF > > +fsi@20000 (/proc0/fsi) > > +EOF > > + > > +test_run libpdbg_dtree_test tree system /proc0/fsi > > + > > + > > +test_result 0 <<EOF > > +fsi@20000 (/proc0/fsi) > > + pib@20100 (/proc0/pib) > > + core@10010 (/proc0/pib/core@10010) > > + thread@0 (/proc0/pib/core@10010/thread@0) > > + thread@1 (/proc0/pib/core@10010/thread@1) > > + core@10020 (/proc0/pib/core@10020) > > + thread@0 (/proc0/pib/core@10020/thread@0) > > + thread@1 (/proc0/pib/core@10020/thread@1) > > + core@10030 (/proc0/pib/core@10030) > > + thread@0 (/proc0/pib/core@10030/thread@0) > > + thread@1 (/proc0/pib/core@10030/thread@1) > > + core@10040 (/proc0/pib/core@10040) > > + thread@0 (/proc0/pib/core@10040/thread@0) > > + thread@1 (/proc0/pib/core@10040/thread@1) > > +EOF > > + > > +test_run libpdbg_dtree_test tree backend /proc0/fsi > > + > > + > > +test_result 0 <<EOF > > +pib@22100 (/proc2/pib) > > + core@10010 (/proc2/pib/core@10010) > > + thread@0 (/proc2/pib/core@10010/thread@0) > > + thread@1 (/proc2/pib/core@10010/thread@1) > > + core@10020 (/proc2/pib/core@10020) > > + thread@0 (/proc2/pib/core@10020/thread@0) > > + thread@1 (/proc2/pib/core@10020/thread@1) > > + core@10030 (/proc2/pib/core@10030) > > + thread@0 (/proc2/pib/core@10030/thread@0) > > + thread@1 (/proc2/pib/core@10030/thread@1) > > + core@10040 (/proc2/pib/core@10040) > > + thread@0 (/proc2/pib/core@10040/thread@0) > > + thread@1 (/proc2/pib/core@10040/thread@1) > > +EOF > > + > > +test_run libpdbg_dtree_test tree system /proc2/pib > > + > > + > > +test_result 0 <<EOF > > +pib@22100 (/proc2/pib) > > + core@10010 (/proc2/pib/core@10010) > > + thread@0 (/proc2/pib/core@10010/thread@0) > > + thread@1 (/proc2/pib/core@10010/thread@1) > > + core@10020 (/proc2/pib/core@10020) > > + thread@0 (/proc2/pib/core@10020/thread@0) > > + thread@1 (/proc2/pib/core@10020/thread@1) > > + core@10030 (/proc2/pib/core@10030) > > + thread@0 (/proc2/pib/core@10030/thread@0) > > + thread@1 (/proc2/pib/core@10030/thread@1) > > + core@10040 (/proc2/pib/core@10040) > > + thread@0 (/proc2/pib/core@10040/thread@0) > > + thread@1 (/proc2/pib/core@10040/thread@1) > > +EOF > > + > > +test_run libpdbg_dtree_test tree backend /proc2/pib > > + > > + > > +test_result 0 <<EOF > > +thread@1 > > + core@10040 > > + pib@27100 > > + proc7 > > + / > > +EOF > > + > > +test_run libpdbg_dtree_test rtree system /proc7/pib/core@10040 > > /thread@1 > > + > > + > > +test_result 0 <<EOF > > +thread@1 > > + core@10040 > > + pib@27100 > > + proc7 > > + / > > +EOF > > + > > +test_run libpdbg_dtree_test rtree system /fsi@27000/pib@27100 > > /core@10040/ > thread@1 > > + > > + > > +test_result 0 <<EOF > > +thread@1 > > + core@10040 > > + pib@27100 > > + fsi@27000 > > + / > > +EOF > > + > > +test_run libpdbg_dtree_test rtree backend /proc7/pib/core@10040 > > /thread@1 > > + > > + > > +test_result 0 <<EOF > > +thread@1 > > + core@10040 > > + pib@27100 > > + fsi@27000 > > + / > > +EOF > > + > > +test_run libpdbg_dtree_test rtree backend /fsi@27000/pib@27100 > > /core@10040/ > thread@1 > > > Amitay.
diff --git a/Makefile.am b/Makefile.am index f2c3335..d5bc9ac 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) @@ -245,6 +247,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..f6d4cbf --- /dev/null +++ b/src/tests/libpdbg_dtree_test.c @@ -0,0 +1,117 @@ +/* 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> + +extern struct pdbg_target *get_parent(struct pdbg_target *target, bool system); + +#define for_each_child(parent, target, system) \ + for (target = __pdbg_next_child_target(parent, NULL, system); \ + target; \ + target = __pdbg_next_child_target(parent, target, system)) + +static void print_tree(struct pdbg_target *target, bool system, 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, system) + print_tree(child, system, level+1); +} + +static void print_rtree(struct pdbg_target *target, bool system, int level) +{ + struct pdbg_target *root = pdbg_target_root(); + const char *name; + int i; + + for (i=0; i<level; i++) + printf(" "); + + name = pdbg_target_dn_name(target); + if (!name || name[0] == '\0') + name = "/"; + + printf("%s\n", name); + + if (target != root) { + target = get_parent(target, system); + print_rtree(target, system, level+1); + } +} + +static void usage(void) +{ + fprintf(stderr, "Usage: libpdbg_dtree_test tree|rtree system|backend <path>\n"); + exit(1); +} + +int main(int argc, const char **argv) +{ + struct pdbg_target *target; + bool do_system; + bool do_tree; + + if (argc != 4) + usage(); + + if (strcmp(argv[1], "tree") == 0) { + do_tree = true; + } else if (strcmp(argv[1], "rtree") == 0) { + do_tree = false; + } else { + usage(); + } + + if (strcmp(argv[2], "system") == 0) { + do_system = true; + } else if (strcmp(argv[2], "backend") == 0) { + do_system = false; + } else { + usage(); + } + + pdbg_targets_init(NULL); + + target = pdbg_target_from_path(NULL, argv[3]); + if (!target) + exit(1); + + if (do_tree) { + print_tree(target, do_system, 0); + } else { + print_rtree(target, do_system, 0); + } + + return 0; +} diff --git a/tests/test_tree.sh b/tests/test_tree.sh new file mode 100755 index 0000000..5a9daff --- /dev/null +++ b/tests/test_tree.sh @@ -0,0 +1,387 @@ +#!/bin/sh + +. $(dirname "$0")/driver.sh + +test_group "tree tests" + +test_result 0 <<EOF +/ (/) + proc0 (/proc0) + fsi@20000 (/proc0/fsi) + pib@20100 (/proc0/pib) + core@10010 (/proc0/pib/core@10010) + thread@0 (/proc0/pib/core@10010/thread@0) + thread@1 (/proc0/pib/core@10010/thread@1) + core@10020 (/proc0/pib/core@10020) + thread@0 (/proc0/pib/core@10020/thread@0) + thread@1 (/proc0/pib/core@10020/thread@1) + core@10030 (/proc0/pib/core@10030) + thread@0 (/proc0/pib/core@10030/thread@0) + thread@1 (/proc0/pib/core@10030/thread@1) + core@10040 (/proc0/pib/core@10040) + thread@0 (/proc0/pib/core@10040/thread@0) + thread@1 (/proc0/pib/core@10040/thread@1) + proc1 (/proc1) + fsi@21000 (/proc1/fsi) + pib@21100 (/proc1/pib) + core@10010 (/proc1/pib/core@10010) + thread@0 (/proc1/pib/core@10010/thread@0) + thread@1 (/proc1/pib/core@10010/thread@1) + core@10020 (/proc1/pib/core@10020) + thread@0 (/proc1/pib/core@10020/thread@0) + thread@1 (/proc1/pib/core@10020/thread@1) + core@10030 (/proc1/pib/core@10030) + thread@0 (/proc1/pib/core@10030/thread@0) + thread@1 (/proc1/pib/core@10030/thread@1) + core@10040 (/proc1/pib/core@10040) + thread@0 (/proc1/pib/core@10040/thread@0) + thread@1 (/proc1/pib/core@10040/thread@1) + proc2 (/proc2) + fsi@22000 (/proc2/fsi) + pib@22100 (/proc2/pib) + core@10010 (/proc2/pib/core@10010) + thread@0 (/proc2/pib/core@10010/thread@0) + thread@1 (/proc2/pib/core@10010/thread@1) + core@10020 (/proc2/pib/core@10020) + thread@0 (/proc2/pib/core@10020/thread@0) + thread@1 (/proc2/pib/core@10020/thread@1) + core@10030 (/proc2/pib/core@10030) + thread@0 (/proc2/pib/core@10030/thread@0) + thread@1 (/proc2/pib/core@10030/thread@1) + core@10040 (/proc2/pib/core@10040) + thread@0 (/proc2/pib/core@10040/thread@0) + thread@1 (/proc2/pib/core@10040/thread@1) + proc3 (/proc3) + fsi@23000 (/proc3/fsi) + pib@23100 (/proc3/pib) + core@10010 (/proc3/pib/core@10010) + thread@0 (/proc3/pib/core@10010/thread@0) + thread@1 (/proc3/pib/core@10010/thread@1) + core@10020 (/proc3/pib/core@10020) + thread@0 (/proc3/pib/core@10020/thread@0) + thread@1 (/proc3/pib/core@10020/thread@1) + core@10030 (/proc3/pib/core@10030) + thread@0 (/proc3/pib/core@10030/thread@0) + thread@1 (/proc3/pib/core@10030/thread@1) + core@10040 (/proc3/pib/core@10040) + thread@0 (/proc3/pib/core@10040/thread@0) + thread@1 (/proc3/pib/core@10040/thread@1) + proc4 (/proc4) + fsi@24000 (/proc4/fsi) + pib@24100 (/proc4/pib) + core@10010 (/proc4/pib/core@10010) + thread@0 (/proc4/pib/core@10010/thread@0) + thread@1 (/proc4/pib/core@10010/thread@1) + core@10020 (/proc4/pib/core@10020) + thread@0 (/proc4/pib/core@10020/thread@0) + thread@1 (/proc4/pib/core@10020/thread@1) + core@10030 (/proc4/pib/core@10030) + thread@0 (/proc4/pib/core@10030/thread@0) + thread@1 (/proc4/pib/core@10030/thread@1) + core@10040 (/proc4/pib/core@10040) + thread@0 (/proc4/pib/core@10040/thread@0) + thread@1 (/proc4/pib/core@10040/thread@1) + proc5 (/proc5) + fsi@25000 (/proc5/fsi) + pib@25100 (/proc5/pib) + core@10010 (/proc5/pib/core@10010) + thread@0 (/proc5/pib/core@10010/thread@0) + thread@1 (/proc5/pib/core@10010/thread@1) + core@10020 (/proc5/pib/core@10020) + thread@0 (/proc5/pib/core@10020/thread@0) + thread@1 (/proc5/pib/core@10020/thread@1) + core@10030 (/proc5/pib/core@10030) + thread@0 (/proc5/pib/core@10030/thread@0) + thread@1 (/proc5/pib/core@10030/thread@1) + core@10040 (/proc5/pib/core@10040) + thread@0 (/proc5/pib/core@10040/thread@0) + thread@1 (/proc5/pib/core@10040/thread@1) + proc6 (/proc6) + fsi@26000 (/proc6/fsi) + pib@26100 (/proc6/pib) + core@10010 (/proc6/pib/core@10010) + thread@0 (/proc6/pib/core@10010/thread@0) + thread@1 (/proc6/pib/core@10010/thread@1) + core@10020 (/proc6/pib/core@10020) + thread@0 (/proc6/pib/core@10020/thread@0) + thread@1 (/proc6/pib/core@10020/thread@1) + core@10030 (/proc6/pib/core@10030) + thread@0 (/proc6/pib/core@10030/thread@0) + thread@1 (/proc6/pib/core@10030/thread@1) + core@10040 (/proc6/pib/core@10040) + thread@0 (/proc6/pib/core@10040/thread@0) + thread@1 (/proc6/pib/core@10040/thread@1) + proc7 (/proc7) + fsi@27000 (/proc7/fsi) + pib@27100 (/proc7/pib) + core@10010 (/proc7/pib/core@10010) + thread@0 (/proc7/pib/core@10010/thread@0) + thread@1 (/proc7/pib/core@10010/thread@1) + core@10020 (/proc7/pib/core@10020) + thread@0 (/proc7/pib/core@10020/thread@0) + thread@1 (/proc7/pib/core@10020/thread@1) + core@10030 (/proc7/pib/core@10030) + thread@0 (/proc7/pib/core@10030/thread@0) + thread@1 (/proc7/pib/core@10030/thread@1) + core@10040 (/proc7/pib/core@10040) + thread@0 (/proc7/pib/core@10040/thread@0) + thread@1 (/proc7/pib/core@10040/thread@1) +EOF + +test_run libpdbg_dtree_test tree system / + + +test_result 0 <<EOF +/ (/) + fsi@20000 (/proc0/fsi) + pib@20100 (/proc0/pib) + core@10010 (/proc0/pib/core@10010) + thread@0 (/proc0/pib/core@10010/thread@0) + thread@1 (/proc0/pib/core@10010/thread@1) + core@10020 (/proc0/pib/core@10020) + thread@0 (/proc0/pib/core@10020/thread@0) + thread@1 (/proc0/pib/core@10020/thread@1) + core@10030 (/proc0/pib/core@10030) + thread@0 (/proc0/pib/core@10030/thread@0) + thread@1 (/proc0/pib/core@10030/thread@1) + core@10040 (/proc0/pib/core@10040) + thread@0 (/proc0/pib/core@10040/thread@0) + thread@1 (/proc0/pib/core@10040/thread@1) + fsi@21000 (/proc1/fsi) + pib@21100 (/proc1/pib) + core@10010 (/proc1/pib/core@10010) + thread@0 (/proc1/pib/core@10010/thread@0) + thread@1 (/proc1/pib/core@10010/thread@1) + core@10020 (/proc1/pib/core@10020) + thread@0 (/proc1/pib/core@10020/thread@0) + thread@1 (/proc1/pib/core@10020/thread@1) + core@10030 (/proc1/pib/core@10030) + thread@0 (/proc1/pib/core@10030/thread@0) + thread@1 (/proc1/pib/core@10030/thread@1) + core@10040 (/proc1/pib/core@10040) + thread@0 (/proc1/pib/core@10040/thread@0) + thread@1 (/proc1/pib/core@10040/thread@1) + fsi@22000 (/proc2/fsi) + pib@22100 (/proc2/pib) + core@10010 (/proc2/pib/core@10010) + thread@0 (/proc2/pib/core@10010/thread@0) + thread@1 (/proc2/pib/core@10010/thread@1) + core@10020 (/proc2/pib/core@10020) + thread@0 (/proc2/pib/core@10020/thread@0) + thread@1 (/proc2/pib/core@10020/thread@1) + core@10030 (/proc2/pib/core@10030) + thread@0 (/proc2/pib/core@10030/thread@0) + thread@1 (/proc2/pib/core@10030/thread@1) + core@10040 (/proc2/pib/core@10040) + thread@0 (/proc2/pib/core@10040/thread@0) + thread@1 (/proc2/pib/core@10040/thread@1) + fsi@23000 (/proc3/fsi) + pib@23100 (/proc3/pib) + core@10010 (/proc3/pib/core@10010) + thread@0 (/proc3/pib/core@10010/thread@0) + thread@1 (/proc3/pib/core@10010/thread@1) + core@10020 (/proc3/pib/core@10020) + thread@0 (/proc3/pib/core@10020/thread@0) + thread@1 (/proc3/pib/core@10020/thread@1) + core@10030 (/proc3/pib/core@10030) + thread@0 (/proc3/pib/core@10030/thread@0) + thread@1 (/proc3/pib/core@10030/thread@1) + core@10040 (/proc3/pib/core@10040) + thread@0 (/proc3/pib/core@10040/thread@0) + thread@1 (/proc3/pib/core@10040/thread@1) + fsi@24000 (/proc4/fsi) + pib@24100 (/proc4/pib) + core@10010 (/proc4/pib/core@10010) + thread@0 (/proc4/pib/core@10010/thread@0) + thread@1 (/proc4/pib/core@10010/thread@1) + core@10020 (/proc4/pib/core@10020) + thread@0 (/proc4/pib/core@10020/thread@0) + thread@1 (/proc4/pib/core@10020/thread@1) + core@10030 (/proc4/pib/core@10030) + thread@0 (/proc4/pib/core@10030/thread@0) + thread@1 (/proc4/pib/core@10030/thread@1) + core@10040 (/proc4/pib/core@10040) + thread@0 (/proc4/pib/core@10040/thread@0) + thread@1 (/proc4/pib/core@10040/thread@1) + fsi@25000 (/proc5/fsi) + pib@25100 (/proc5/pib) + core@10010 (/proc5/pib/core@10010) + thread@0 (/proc5/pib/core@10010/thread@0) + thread@1 (/proc5/pib/core@10010/thread@1) + core@10020 (/proc5/pib/core@10020) + thread@0 (/proc5/pib/core@10020/thread@0) + thread@1 (/proc5/pib/core@10020/thread@1) + core@10030 (/proc5/pib/core@10030) + thread@0 (/proc5/pib/core@10030/thread@0) + thread@1 (/proc5/pib/core@10030/thread@1) + core@10040 (/proc5/pib/core@10040) + thread@0 (/proc5/pib/core@10040/thread@0) + thread@1 (/proc5/pib/core@10040/thread@1) + fsi@26000 (/proc6/fsi) + pib@26100 (/proc6/pib) + core@10010 (/proc6/pib/core@10010) + thread@0 (/proc6/pib/core@10010/thread@0) + thread@1 (/proc6/pib/core@10010/thread@1) + core@10020 (/proc6/pib/core@10020) + thread@0 (/proc6/pib/core@10020/thread@0) + thread@1 (/proc6/pib/core@10020/thread@1) + core@10030 (/proc6/pib/core@10030) + thread@0 (/proc6/pib/core@10030/thread@0) + thread@1 (/proc6/pib/core@10030/thread@1) + core@10040 (/proc6/pib/core@10040) + thread@0 (/proc6/pib/core@10040/thread@0) + thread@1 (/proc6/pib/core@10040/thread@1) + fsi@27000 (/proc7/fsi) + pib@27100 (/proc7/pib) + core@10010 (/proc7/pib/core@10010) + thread@0 (/proc7/pib/core@10010/thread@0) + thread@1 (/proc7/pib/core@10010/thread@1) + core@10020 (/proc7/pib/core@10020) + thread@0 (/proc7/pib/core@10020/thread@0) + thread@1 (/proc7/pib/core@10020/thread@1) + core@10030 (/proc7/pib/core@10030) + thread@0 (/proc7/pib/core@10030/thread@0) + thread@1 (/proc7/pib/core@10030/thread@1) + core@10040 (/proc7/pib/core@10040) + thread@0 (/proc7/pib/core@10040/thread@0) + thread@1 (/proc7/pib/core@10040/thread@1) +EOF + +test_run libpdbg_dtree_test tree backend / + + +test_result 0 <<EOF +proc1 (/proc1) + fsi@21000 (/proc1/fsi) + pib@21100 (/proc1/pib) + core@10010 (/proc1/pib/core@10010) + thread@0 (/proc1/pib/core@10010/thread@0) + thread@1 (/proc1/pib/core@10010/thread@1) + core@10020 (/proc1/pib/core@10020) + thread@0 (/proc1/pib/core@10020/thread@0) + thread@1 (/proc1/pib/core@10020/thread@1) + core@10030 (/proc1/pib/core@10030) + thread@0 (/proc1/pib/core@10030/thread@0) + thread@1 (/proc1/pib/core@10030/thread@1) + core@10040 (/proc1/pib/core@10040) + thread@0 (/proc1/pib/core@10040/thread@0) + thread@1 (/proc1/pib/core@10040/thread@1) +EOF + +test_run libpdbg_dtree_test tree system /proc1 + + +test_result 0 <<EOF +proc1 (/proc1) +EOF + +test_run libpdbg_dtree_test tree backend /proc1 + + +test_result 0 <<EOF +fsi@20000 (/proc0/fsi) +EOF + +test_run libpdbg_dtree_test tree system /proc0/fsi + + +test_result 0 <<EOF +fsi@20000 (/proc0/fsi) + pib@20100 (/proc0/pib) + core@10010 (/proc0/pib/core@10010) + thread@0 (/proc0/pib/core@10010/thread@0) + thread@1 (/proc0/pib/core@10010/thread@1) + core@10020 (/proc0/pib/core@10020) + thread@0 (/proc0/pib/core@10020/thread@0) + thread@1 (/proc0/pib/core@10020/thread@1) + core@10030 (/proc0/pib/core@10030) + thread@0 (/proc0/pib/core@10030/thread@0) + thread@1 (/proc0/pib/core@10030/thread@1) + core@10040 (/proc0/pib/core@10040) + thread@0 (/proc0/pib/core@10040/thread@0) + thread@1 (/proc0/pib/core@10040/thread@1) +EOF + +test_run libpdbg_dtree_test tree backend /proc0/fsi + + +test_result 0 <<EOF +pib@22100 (/proc2/pib) + core@10010 (/proc2/pib/core@10010) + thread@0 (/proc2/pib/core@10010/thread@0) + thread@1 (/proc2/pib/core@10010/thread@1) + core@10020 (/proc2/pib/core@10020) + thread@0 (/proc2/pib/core@10020/thread@0) + thread@1 (/proc2/pib/core@10020/thread@1) + core@10030 (/proc2/pib/core@10030) + thread@0 (/proc2/pib/core@10030/thread@0) + thread@1 (/proc2/pib/core@10030/thread@1) + core@10040 (/proc2/pib/core@10040) + thread@0 (/proc2/pib/core@10040/thread@0) + thread@1 (/proc2/pib/core@10040/thread@1) +EOF + +test_run libpdbg_dtree_test tree system /proc2/pib + + +test_result 0 <<EOF +pib@22100 (/proc2/pib) + core@10010 (/proc2/pib/core@10010) + thread@0 (/proc2/pib/core@10010/thread@0) + thread@1 (/proc2/pib/core@10010/thread@1) + core@10020 (/proc2/pib/core@10020) + thread@0 (/proc2/pib/core@10020/thread@0) + thread@1 (/proc2/pib/core@10020/thread@1) + core@10030 (/proc2/pib/core@10030) + thread@0 (/proc2/pib/core@10030/thread@0) + thread@1 (/proc2/pib/core@10030/thread@1) + core@10040 (/proc2/pib/core@10040) + thread@0 (/proc2/pib/core@10040/thread@0) + thread@1 (/proc2/pib/core@10040/thread@1) +EOF + +test_run libpdbg_dtree_test tree backend /proc2/pib + + +test_result 0 <<EOF +thread@1 + core@10040 + pib@27100 + proc7 + / +EOF + +test_run libpdbg_dtree_test rtree system /proc7/pib/core@10040/thread@1 + + +test_result 0 <<EOF +thread@1 + core@10040 + pib@27100 + proc7 + / +EOF + +test_run libpdbg_dtree_test rtree system /fsi@27000/pib@27100/core@10040/thread@1 + + +test_result 0 <<EOF +thread@1 + core@10040 + pib@27100 + fsi@27000 + / +EOF + +test_run libpdbg_dtree_test rtree backend /proc7/pib/core@10040/thread@1 + + +test_result 0 <<EOF +thread@1 + core@10040 + pib@27100 + fsi@27000 + / +EOF + +test_run libpdbg_dtree_test rtree backend /fsi@27000/pib@27100/core@10040/thread@1
This test checks system device tree (view) traverse and backend device tree traverse. Signed-off-by: Amitay Isaacs <amitay@ozlabs.org> --- Makefile.am | 11 +- src/tests/libpdbg_dtree_test.c | 117 ++++++++++ tests/test_tree.sh | 387 +++++++++++++++++++++++++++++++++ 3 files changed, 513 insertions(+), 2 deletions(-) create mode 100644 src/tests/libpdbg_dtree_test.c create mode 100755 tests/test_tree.sh