From patchwork Wed Apr 1 22:55:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1265402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (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 48t1l36zg8z9sRR for ; Thu, 2 Apr 2020 09:55:59 +1100 (AEDT) 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=ltEqCQac; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48t1l35BwFzDqS4 for ; Thu, 2 Apr 2020 09:55:59 +1100 (AEDT) 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 48t1kg3Ck3zDqS4 for ; Thu, 2 Apr 2020 09:55:39 +1100 (AEDT) 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=ltEqCQac; 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 48t1kg0rQhz9sRN; Thu, 2 Apr 2020 09:55:39 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1585781739; bh=ZfGhrGm1bcJOCsqpNK4Ov/Fna4/HrzM13pauH9ON4mE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ltEqCQacpv5PVt9L7DmYnu180ukwvISN5ceqSSGsfxilYT1P5IEEgB76UxW8r7sQu B8iQw4+CRTjgDUIQT5YqR/OQA+vaS3mfLH3mUwV5YuHaXoxmV1ttlO2rhwFK7IIB0W GEgoMhEY/wze4cINbMkDSnDmV6b4sUclKg9y4mM1pjTczbe69Pq3MYh02UCDjZN/ZR /jkUDoJ3VSLzIcrhP1QgU8G0pkv8X4m8BbAQ+0sO6LD6yWjQH3qMX4tuJASYiFo6Co m/3R+Jca5yVSkZnkPHAO5dwltkHSG6auGL04a3EyLb9pho7AyP6zeSxH0zrBYm0tHx IwFkc0/tixm8w== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 2 Apr 2020 09:55:24 +1100 Message-Id: <20200401225526.1105288-5-amitay@ozlabs.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200401225526.1105288-1-amitay@ozlabs.org> References: <20200401225526.1105288-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 4/6] tests: Add test code for testing attribute api 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 | 7 +- src/tests/libpdbg_attr_test.c | 322 ++++++++++++++++++++++++++++++++++ 2 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 src/tests/libpdbg_attr_test.c diff --git a/Makefile.am b/Makefile.am index a4ca5f3..84e1a1d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,7 +18,7 @@ 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_prop_test libpdbg_attr_test PDBG_TESTS = \ tests/test_selection.sh \ @@ -274,6 +274,11 @@ libpdbg_prop_test_CFLAGS = $(libpdbg_test_cflags) libpdbg_prop_test_LDFLAGS = $(libpdbg_test_ldflags) libpdbg_prop_test_LDADD = $(libpdbg_test_ldadd) +libpdbg_attr_test_SOURCES = src/tests/libpdbg_attr_test.c +libpdbg_attr_test_CFLAGS = $(libpdbg_test_cflags) +libpdbg_attr_test_LDFLAGS = $(libpdbg_test_ldflags) +libpdbg_attr_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_attr_test.c b/src/tests/libpdbg_attr_test.c new file mode 100644 index 0000000..759f1fc --- /dev/null +++ b/src/tests/libpdbg_attr_test.c @@ -0,0 +1,322 @@ +/* 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 +#include +#include +#include + +#include + +static void usage(void) +{ + fprintf(stderr, "Usage: libpdbg_attr_test read array 1|2|4|8 \n"); + fprintf(stderr, " libpdbg_attr_test write array 1|2|4|8 [ ...]\n"); + fprintf(stderr, " libpdbg_attr_test read packed \n"); + fprintf(stderr, " libpdbg_attr_test write packed [ ...]\n"); + exit(1); +} + +static void read_array(struct pdbg_target *target, + const char *attr, + unsigned int size, + unsigned int count) +{ + void *buf; + unsigned int i; + + buf = malloc(size * count); + assert(buf); + + if (!pdbg_target_get_attribute(target, attr, size, count, buf)) + exit(88); + + if (size == 1) { + uint8_t *v = (uint8_t *)buf; + + for (i=0; i 0); + + buf = malloc(size); + assert(buf); + + if (!pdbg_target_get_attribute_packed(target, attr, spec, buf)) + exit(88); + + pos = 0; + for (i=0; i 0); + + buf = malloc(size); + assert(buf); + + pos = 0; + for (i=0; i