diff mbox series

[2/2] tests: Add traverse tests

Message ID 20200514062640.277933-3-amitay@ozlabs.org
State Accepted
Headers show
Series Add api for traversing over all targets | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (6c10b68bf774a9fe21affd5ef0b40084cd49800d)
snowpatch_ozlabs/build-multiarch success Test build-multiarch on branch master

Commit Message

Amitay Isaacs May 14, 2020, 6:26 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 Makefile.am                       |   9 +-
 src/tests/libpdbg_traverse_test.c |  50 ++++++++++
 tests/test_traverse.sh            | 151 ++++++++++++++++++++++++++++++
 3 files changed, 209 insertions(+), 1 deletion(-)
 create mode 100644 src/tests/libpdbg_traverse_test.c
 create mode 100755 tests/test_traverse.sh
diff mbox series

Patch

diff --git a/Makefile.am b/Makefile.am
index fdcbb09..209e7ce 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -18,7 +18,8 @@  bin_PROGRAMS = pdbg
 check_PROGRAMS = $(libpdbg_tests) libpdbg_dtree_test \
 		libpdbg_p9_fapi_translation_test \
 		optcmd_test hexdump_test cronus_proxy \
-		libpdbg_prop_test libpdbg_attr_test
+		libpdbg_prop_test libpdbg_attr_test \
+		libpdbg_traverse_test
 
 PDBG_TESTS = \
 	tests/test_selection.sh 	\
@@ -30,6 +31,7 @@  PDBG_TESTS = \
 	tests/test_prop.sh		\
 	tests/test_attr_array.sh	\
 	tests/test_attr_packed.sh	\
+	tests/test_traverse.sh		\
 	tests/test_p9_fapi_translation.sh
 
 TESTS = $(libpdbg_tests) optcmd_test $(PDBG_TESTS)
@@ -280,6 +282,11 @@  libpdbg_attr_test_CFLAGS = $(libpdbg_test_cflags)
 libpdbg_attr_test_LDFLAGS = $(libpdbg_test_ldflags)
 libpdbg_attr_test_LDADD = $(libpdbg_test_ldadd)
 
+libpdbg_traverse_test_SOURCES = src/tests/libpdbg_traverse_test.c
+libpdbg_traverse_test_CFLAGS = $(libpdbg_test_cflags)
+libpdbg_traverse_test_LDFLAGS = $(libpdbg_test_ldflags)
+libpdbg_traverse_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_traverse_test.c b/src/tests/libpdbg_traverse_test.c
new file mode 100644
index 0000000..094d45f
--- /dev/null
+++ b/src/tests/libpdbg_traverse_test.c
@@ -0,0 +1,50 @@ 
+/* Copyright 2020 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 <assert.h>
+
+#include <libpdbg.h>
+
+static int print_target(struct pdbg_target *target, void *priv)
+{
+	const char *path;
+	int *level = (int *)priv;
+	int i;
+
+	path = pdbg_target_path(target);
+	assert(path);
+
+	for (i=0; i<*level; i++)
+		printf("  ");
+
+	printf("%s\n", path);
+	return 0;
+}
+
+int main(int argc, const char **argv)
+{
+	struct pdbg_target *parent = NULL;
+	int level = 0;
+
+	assert(pdbg_targets_init(NULL));
+
+	if (argc == 2)
+		parent = pdbg_target_from_path(NULL, argv[1]);
+
+	return pdbg_target_traverse(parent, print_target, &level);
+}
+
diff --git a/tests/test_traverse.sh b/tests/test_traverse.sh
new file mode 100755
index 0000000..14b049b
--- /dev/null
+++ b/tests/test_traverse.sh
@@ -0,0 +1,151 @@ 
+#!/bin/sh
+
+. $(dirname "$0")/driver.sh
+
+test_group "traverse tests for fake.dts"
+
+test_result 0 <<EOF
+/proc0
+/proc0/fsi
+/proc0/pib
+/proc0/pib/core@10010
+/proc0/pib/core@10010/thread@0
+/proc0/pib/core@10010/thread@1
+/proc0/pib/core@10020
+/proc0/pib/core@10020/thread@0
+/proc0/pib/core@10020/thread@1
+/proc0/pib/core@10030
+/proc0/pib/core@10030/thread@0
+/proc0/pib/core@10030/thread@1
+/proc0/pib/core@10040
+/proc0/pib/core@10040/thread@0
+/proc0/pib/core@10040/thread@1
+EOF
+
+test_run libpdbg_traverse_test /proc0
+
+test_result 0 <<EOF
+/
+/proc0
+/proc0/fsi
+/proc0/pib
+/proc0/pib/core@10010
+/proc0/pib/core@10010/thread@0
+/proc0/pib/core@10010/thread@1
+/proc0/pib/core@10020
+/proc0/pib/core@10020/thread@0
+/proc0/pib/core@10020/thread@1
+/proc0/pib/core@10030
+/proc0/pib/core@10030/thread@0
+/proc0/pib/core@10030/thread@1
+/proc0/pib/core@10040
+/proc0/pib/core@10040/thread@0
+/proc0/pib/core@10040/thread@1
+/proc1
+/proc1/fsi
+/proc1/pib
+/proc1/pib/core@10010
+/proc1/pib/core@10010/thread@0
+/proc1/pib/core@10010/thread@1
+/proc1/pib/core@10020
+/proc1/pib/core@10020/thread@0
+/proc1/pib/core@10020/thread@1
+/proc1/pib/core@10030
+/proc1/pib/core@10030/thread@0
+/proc1/pib/core@10030/thread@1
+/proc1/pib/core@10040
+/proc1/pib/core@10040/thread@0
+/proc1/pib/core@10040/thread@1
+/proc2
+/proc2/fsi
+/proc2/pib
+/proc2/pib/core@10010
+/proc2/pib/core@10010/thread@0
+/proc2/pib/core@10010/thread@1
+/proc2/pib/core@10020
+/proc2/pib/core@10020/thread@0
+/proc2/pib/core@10020/thread@1
+/proc2/pib/core@10030
+/proc2/pib/core@10030/thread@0
+/proc2/pib/core@10030/thread@1
+/proc2/pib/core@10040
+/proc2/pib/core@10040/thread@0
+/proc2/pib/core@10040/thread@1
+/proc3
+/proc3/fsi
+/proc3/pib
+/proc3/pib/core@10010
+/proc3/pib/core@10010/thread@0
+/proc3/pib/core@10010/thread@1
+/proc3/pib/core@10020
+/proc3/pib/core@10020/thread@0
+/proc3/pib/core@10020/thread@1
+/proc3/pib/core@10030
+/proc3/pib/core@10030/thread@0
+/proc3/pib/core@10030/thread@1
+/proc3/pib/core@10040
+/proc3/pib/core@10040/thread@0
+/proc3/pib/core@10040/thread@1
+/proc4
+/proc4/fsi
+/proc4/pib
+/proc4/pib/core@10010
+/proc4/pib/core@10010/thread@0
+/proc4/pib/core@10010/thread@1
+/proc4/pib/core@10020
+/proc4/pib/core@10020/thread@0
+/proc4/pib/core@10020/thread@1
+/proc4/pib/core@10030
+/proc4/pib/core@10030/thread@0
+/proc4/pib/core@10030/thread@1
+/proc4/pib/core@10040
+/proc4/pib/core@10040/thread@0
+/proc4/pib/core@10040/thread@1
+/proc5
+/proc5/fsi
+/proc5/pib
+/proc5/pib/core@10010
+/proc5/pib/core@10010/thread@0
+/proc5/pib/core@10010/thread@1
+/proc5/pib/core@10020
+/proc5/pib/core@10020/thread@0
+/proc5/pib/core@10020/thread@1
+/proc5/pib/core@10030
+/proc5/pib/core@10030/thread@0
+/proc5/pib/core@10030/thread@1
+/proc5/pib/core@10040
+/proc5/pib/core@10040/thread@0
+/proc5/pib/core@10040/thread@1
+/proc6
+/proc6/fsi
+/proc6/pib
+/proc6/pib/core@10010
+/proc6/pib/core@10010/thread@0
+/proc6/pib/core@10010/thread@1
+/proc6/pib/core@10020
+/proc6/pib/core@10020/thread@0
+/proc6/pib/core@10020/thread@1
+/proc6/pib/core@10030
+/proc6/pib/core@10030/thread@0
+/proc6/pib/core@10030/thread@1
+/proc6/pib/core@10040
+/proc6/pib/core@10040/thread@0
+/proc6/pib/core@10040/thread@1
+/proc7
+/proc7/fsi
+/proc7/pib
+/proc7/pib/core@10010
+/proc7/pib/core@10010/thread@0
+/proc7/pib/core@10010/thread@1
+/proc7/pib/core@10020
+/proc7/pib/core@10020/thread@0
+/proc7/pib/core@10020/thread@1
+/proc7/pib/core@10030
+/proc7/pib/core@10030/thread@0
+/proc7/pib/core@10030/thread@1
+/proc7/pib/core@10040
+/proc7/pib/core@10040/thread@0
+/proc7/pib/core@10040/thread@1
+EOF
+
+test_run libpdbg_traverse_test