From patchwork Wed Apr 10 05:25:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1083181 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44fCLT5GKzz9s7T for ; Wed, 10 Apr 2019 15:26:09 +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.b="j/Ydv7Vm"; 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 44fCLT2FltzDqJR for ; Wed, 10 Apr 2019 15:26:09 +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 44fCLJ0cYJzDqJQ for ; Wed, 10 Apr 2019 15:26:00 +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.b="j/Ydv7Vm"; 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 44fCLH5DQjz9s9T; Wed, 10 Apr 2019 15:25:59 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1554873959; bh=eR2DCN24oJcXAMRQmYfBSHd0qjP6Ii2NU1E1/0QAWA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/Ydv7Vm+39Dzk1/bzfkRDrrDXEDvTUHo5d7veB3nIGfnO1gLgW3iHCQrMoQg95D2 x2HR5CbEe9uwRl33+gZhy7bK493YZZJCdkvnXS5c7oOfPcE9qfI40wjzHncTIp3qA/ ahjzr+Q/uEgLxpsokeO4hTqbu3Zn3MdG+CvJ5RShilDl5HdUAtKstyG0D9jQa952PV /k6KRioiGa3+PfxdsOLwAbzwAuP1rhkmZPtTurlmxQxSl+I0drHZzyJldht6C5DhxF 3INO7/bF162CrX36LwZ204199J5X/PY5esjgpDEnK6u/PQ/e9yhF4HrHF3K5NkbgOh WPJwNmr4VtbNg== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 10 Apr 2019 15:25:51 +1000 Message-Id: <20190410052553.395843-3-amitay@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190410052553.395843-1-amitay@ozlabs.org> References: <20190410052553.395843-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 2/4] tests: Add tests for hexdump() 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 | 8 ++- src/tests/hexdump_test.c | 83 +++++++++++++++++++++++++++ tests/test_hexdump.sh | 119 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 src/tests/hexdump_test.c create mode 100755 tests/test_hexdump.sh diff --git a/Makefile.am b/Makefile.am index f1e06f6..d34cf20 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,12 +9,13 @@ libpdbg_tests = libpdbg_target_test \ libpdbg_probe_test3 bin_PROGRAMS = pdbg -check_PROGRAMS = $(libpdbg_tests) optcmd_test +check_PROGRAMS = $(libpdbg_tests) optcmd_test hexdump_test PDBG_TESTS = \ tests/test_selection.sh \ tests/test_selection2.sh \ - tests/test_hw_bmc.sh + tests/test_hw_bmc.sh \ + tests/test_hexdump.sh TESTS = $(libpdbg_tests) optcmd_test $(PDBG_TESTS) @@ -67,6 +68,9 @@ DT_headers = $(DT:.dts=.dt.h) optcmd_test_SOURCES = src/optcmd.c src/parsers.c src/tests/optcmd_test.c optcmd_test_CFLAGS = -Wall -g +hexdump_test_SOURCES = src/util.c src/tests/hexdump_test.c +hexdump_test_CFLAGS = -Wall -g + pdbg_SOURCES = \ src/cfam.c \ src/htm.c \ diff --git a/src/tests/hexdump_test.c b/src/tests/hexdump_test.c new file mode 100644 index 0000000..05ecc8b --- /dev/null +++ b/src/tests/hexdump_test.c @@ -0,0 +1,83 @@ +#include +#include + +#include "../util.h" + +static void test1(uint8_t *bytes, int size) +{ + hexdump(0, bytes, size, 1); + hexdump(0, bytes, size, 2); + hexdump(0, bytes, size, 4); + hexdump(0, bytes, size, 8); +} + +static void test2(uint8_t *bytes) +{ + int i; + + for (i=16; i>0; i--) { + hexdump(0x1000, bytes, i, 1); + } +} + +static void test3(uint8_t *bytes) +{ + int i; + + for (i=15; i>=0; i--) { + hexdump(0x1000+i, bytes, 16-i, 1); + } +} + +static void test4(uint8_t *bytes) +{ + int i; + + for (i=0; i<16; i++) { + hexdump(0x2000+i, bytes, 16, 1); + } +} + +int main(int argc, const char **argv) +{ + uint8_t bytes[1000]; + int test_num, i; + int count = 0; + + for (i=0; i<1000; i++) + bytes[i] = i % 0xff; + + if (argc < 2) { + exit(1); + } + + test_num = atoi(argv[1]); + + switch (test_num) { + case 1: + if (argc == 3) + count = atoi(argv[2]); + if (count <= 0 || count > 1000) + count = 100; + + test1(bytes, count); + break; + + case 2: + test2(bytes); + break; + + case 3: + test3(bytes); + break; + + case 4: + test4(bytes); + break; + + default: + exit(1); + } + + return 0; +} diff --git a/tests/test_hexdump.sh b/tests/test_hexdump.sh new file mode 100755 index 0000000..9289d2c --- /dev/null +++ b/tests/test_hexdump.sh @@ -0,0 +1,119 @@ +#!/bin/sh + +. $(dirname "$0")/driver.sh + +test_group "hexdump tests" + +test_result 0 <