From patchwork Mon Jul 7 15:21:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 4496081 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 505AD9F1C4 for ; Mon, 7 Jul 2014 15:25:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 83759202A1 for ; Mon, 7 Jul 2014 15:25:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9ECCC20265 for ; Mon, 7 Jul 2014 15:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751802AbaGGPWA (ORCPT ); Mon, 7 Jul 2014 11:22:00 -0400 Received: from mga02.intel.com ([134.134.136.20]:51283 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751689AbaGGPV7 (ORCPT ); Mon, 7 Jul 2014 11:21:59 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 07 Jul 2014 08:21:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,618,1400050800"; d="scan'208";a="569435564" Received: from smile.fi.intel.com ([10.237.72.73]) by orsmga002.jf.intel.com with ESMTP; 07 Jul 2014 08:21:55 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1X4Ajp-0003Ka-Sl; Mon, 07 Jul 2014 18:21:53 +0300 From: Andy Shevchenko To: "John W . Linville" , Johannes Berg , devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Andrew Morton , Joe Perches Cc: Andy Shevchenko Subject: [PATCH v2 02/10] lib / string_helpers: refactoring the test suite Date: Mon, 7 Jul 2014 18:21:44 +0300 Message-Id: <1404746512-12749-3-git-send-email-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.0.1 In-Reply-To: <1404746512-12749-1-git-send-email-andriy.shevchenko@linux.intel.com> References: <1404746512-12749-1-git-send-email-andriy.shevchenko@linux.intel.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch prepares test suite for a following update. It introduces test_string_check_buf() helper which checks the result and dumps an error. Signed-off-by: Andy Shevchenko --- lib/test-string_helpers.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c index 6ac48de..ac44c92 100644 --- a/lib/test-string_helpers.c +++ b/lib/test-string_helpers.c @@ -10,6 +10,26 @@ #include #include +static __init bool test_string_check_buf(const char *name, unsigned int flags, + char *in, size_t p, + char *out_real, size_t q_real, + char *out_test, size_t q_test) +{ + if (q_real == q_test && !memcmp(out_test, out_real, q_test)) + return true; + + pr_warn("Test '%s' failed: flags = %u\n", name, flags); + + print_hex_dump(KERN_WARNING, "Input: ", DUMP_PREFIX_NONE, 16, 1, + in, p, true); + print_hex_dump(KERN_WARNING, "Expected: ", DUMP_PREFIX_NONE, 16, 1, + out_test, q_test, true); + print_hex_dump(KERN_WARNING, "Got: ", DUMP_PREFIX_NONE, 16, 1, + out_real, q_real, true); + + return false; +} + struct test_string { const char *in; const char *out; @@ -39,7 +59,8 @@ static const struct test_string strings[] __initconst = { }, }; -static void __init test_string_unescape(unsigned int flags, bool inplace) +static void __init test_string_unescape(const char *name, unsigned int flags, + bool inplace) { char in[256]; char out_test[256]; @@ -77,15 +98,8 @@ static void __init test_string_unescape(unsigned int flags, bool inplace) q_real = string_unescape(in, out_real, q_real, flags); } - if (q_real != q_test || memcmp(out_test, out_real, q_test)) { - pr_warn("Test failed: flags = %u\n", flags); - print_hex_dump(KERN_WARNING, "Input: ", - DUMP_PREFIX_NONE, 16, 1, in, p - 1, true); - print_hex_dump(KERN_WARNING, "Expected: ", - DUMP_PREFIX_NONE, 16, 1, out_test, q_test, true); - print_hex_dump(KERN_WARNING, "Got: ", - DUMP_PREFIX_NONE, 16, 1, out_real, q_real, true); - } + test_string_check_buf(name, flags, in, p - 1, out_real, q_real, + out_test, q_test); } static int __init test_string_helpers_init(void) @@ -94,8 +108,9 @@ static int __init test_string_helpers_init(void) pr_info("Running tests...\n"); for (i = 0; i < UNESCAPE_ANY + 1; i++) - test_string_unescape(i, false); - test_string_unescape(get_random_int() % (UNESCAPE_ANY + 1), true); + test_string_unescape("unescape", i, false); + test_string_unescape("unescape inplace", + get_random_int() % (UNESCAPE_ANY + 1), true); return -EINVAL; }