From patchwork Wed May 6 05:52:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1284071 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49H5Mk2cdBz9sSt for ; Wed, 6 May 2020 15:52:18 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=Sr6tY9fF; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49H5Mk1mlxzDqlF for ; Wed, 6 May 2020 15:52:18 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49H5Mg0g6GzDqBy for ; Wed, 6 May 2020 15:52:15 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=Sr6tY9fF; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 49H5Mf5czMz9sRY; Wed, 6 May 2020 15:52:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1588744334; bh=zk4JFkgPao0k1hlloe1AiG741KtF2ICL5teEV0aaO/Y=; h=From:To:Cc:Subject:Date:From; b=Sr6tY9fFmQKXno+fR4CT7IXVMndaz+i/DnzRt4B2t2LVFwMGK1AelwhUAV9q1GqEO faPs6worYnfmt+cSCH7U0LaIZnI3MwVcthScfSb1xVlwNA1GYxiibisSkjiEnLPbII VOnxfSuC+16+HaC2/MWTgHKJqvT9fY71IPocszKO5gjwdg6E83128q7aZHzVJpPTYN hqnJLhpzCE4srzKlsr5vhqCpAqBudNyM8PdK/Nr+WB8iPSVu8Oami76b1c6ACR4x98 x06XGncW2m0BisDq1NNmGieffDIjDxbE7LJzN4z/lD8lWR9TPuypJJrTUuXdZkL4jZ fXBz25qbgOclA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 6 May 2020 15:52:08 +1000 Message-Id: <20200506055209.154149-1-amitay@ozlabs.org> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Subject: [Pdbg] [PATCH 1/2] libpdbg: Add api for iterating over all targets X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs --- libpdbg/libpdbg.c | 26 ++++++++++++++++++++++++++ libpdbg/libpdbg.h | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c index 8af6a02..a6797ed 100644 --- a/libpdbg/libpdbg.c +++ b/libpdbg/libpdbg.c @@ -170,6 +170,32 @@ struct pdbg_target *__pdbg_next_child_target(struct pdbg_target *parent, struct return NULL; } +static int _pdbg_traverse(struct pdbg_target *parent, pdbg_traverse_callback_fn func, void *priv) +{ + struct pdbg_target *target; + int ret; + + ret = func(parent, priv); + if (ret) + return ret; + + pdbg_for_each_child_target(parent, target) { + ret = _pdbg_traverse(target, func, priv); + if (ret) + return ret; + } + + return 0; +} + +int pdbg_traverse(struct pdbg_target *parent, pdbg_traverse_callback_fn func, void *priv) +{ + if (!parent) + parent = pdbg_target_root(); + + return _pdbg_traverse(parent, func, priv); +} + enum pdbg_target_status pdbg_target_status(struct pdbg_target *target) { return target->status; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 1c974f5..4337025 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -257,6 +257,28 @@ enum pdbg_backend { target; \ target = __pdbg_next_child_target(parent, target, true)) +/** + * @brief Callback function for pdbg traverse + * + * @param[in] target current target + * @param[in] priv private data assoicated with callback function + * @return 0 to continue traverse, non-zero to stop traverse + */ +typedef int (*pdbg_traverse_callback_fn)(struct pdbg_target *target, void *priv); + +/** + * @brief Loop over all children of the given target + * + * @param[in] parent the head pdbg_target + * @param[in] func callback function to call on each target + * @param[in] priv private data for callback function + * @return 0 on successful traverse of all children, non-zero otherwise + * + * If the callback function returns non-zero value, the traverse will stop and + * return the same return non-zero value. + */ +int pdbg_traverse(struct pdbg_target *parent, pdbg_traverse_callback_fn func, void *priv); + /** * @brief Find a target parent of the given class/type * @param[in] klass the desired parent class From patchwork Wed May 6 05:52:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1284072 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49H5Mp4B6Cz9sRY for ; Wed, 6 May 2020 15:52:22 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=E79RWFYz; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49H5Mp3KR4zDqm9 for ; Wed, 6 May 2020 15:52:22 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49H5Mg3NNrzDqBy for ; Wed, 6 May 2020 15:52:15 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=E79RWFYz; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 49H5Mg18t1z9sSt; Wed, 6 May 2020 15:52:15 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1588744335; bh=LnvFw1N/4wKn5RTVPXNcmzpcWi2b6jTWsrBNZirB46M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E79RWFYzLLHq+jcth+395sBakKhY/P/i2T4Hdu+gtes3FFfHfkdIKMakP1yX95yU4 DnJox56R1ddsribZ2Mj4lRKAVof5+M3F37hYw11ZUkc7vuTLnU3oCWKNGdfDgJkq6m 79jodiAGSva6q7qLZ/mL9DZiqE9ESeWI7OP0SF2qKN90PZ11edZEds9t6n4L2FXi35 bEV7DBGbILiSutCc4wdmMD/By0ZnKYX5KiJhTeBN1xpRiLMuP2wfiM137jgrqYtO4X UU7vtdiMLHmnZ/K80wCsO6kfnbG9VGeviBI5t/jl4n+MfmA8aGCgGFQVsd8O4VKyu1 dkV04icp0KIkA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 6 May 2020 15:52:09 +1000 Message-Id: <20200506055209.154149-2-amitay@ozlabs.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200506055209.154149-1-amitay@ozlabs.org> References: <20200506055209.154149-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH 2/2] tests: Add traverse tests X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs --- 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 --git a/Makefile.am b/Makefile.am index 10306dc..fba6940 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) @@ -282,6 +284,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..993aae7 --- /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 +#include + +#include + +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_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 <