Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1694524ybh; Tue, 14 Jul 2020 05:02:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWmbmodNBIbEqxXbPr0IH627GQ5p+oCupfrdoeSUZOLGOUKndUzWPg7GJmiHBP9bOY//o3 X-Received: by 2002:a17:906:fac1:: with SMTP id lu1mr4322434ejb.427.1594728174961; Tue, 14 Jul 2020 05:02:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594728174; cv=none; d=google.com; s=arc-20160816; b=Yio43mUDYTCaKU/v8K8eUHLAOqL5hLAzRiWGNhlZLV+dhZy8z1GnOUaW8POtdLHhFe boE2vbwY3PVtcC26LxisLhgY0UuvfehYWZYAiVF3H7DOktPT1feYpcD/mrb9GeIIU240 mTnOPCp89YOfj/jcOPs6unwYv0eh8O8qDzzxJNHPbNV/n8WzaNrV40P1pxfgRgbznW5x Vo/gS8nRYPr4gvTFBQT+600OMLnbZE5oer7qOkh8QjcQL+q6rz9XM6l7tRm6dA24ovAh TIS0BtuDkRTYXqY+NlAy1XlRRmFbITcLtfZz8hvLZlOqENUCNgvl8/XLPvLt4rzhkCBE GmBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=IFmXG+efTFkH2Sb+ufmyTzpntxQTGMdZY4cBv6SiBJI=; b=dyJOx4MolojWDN8jqf9fuOlVuzPbSSlTlvHNu8jmwgS7Rx8oaHiex/uM0gzLNAlpa5 m8sNM4Fbqyf3C3LxjmZW1H6xBdPX48YrbftL/DOFhn+zMZhRIgrfjy1lHVoGkSU6ZMNh 3+wKRkdpah5Yqu5gEy9H/GKR8SsphT8jCkFOvGrIR9BOFgyS+rUJW017Qd7+VvkKLJ8s 2svzPDcpOhlZmEKmCBbVEAiJEOU3LusdOgCPA9dd7hUSHjpp4ELpaIzF6nNAw1Gd9imL xeers9Su0Siik91eeOH7CSz1QCjWkUGA4fpxESJn/gCFGgWYJ5u+uNLR14gXxr+jYxpT Hq7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn1si14745725ejc.638.2020.07.14.05.02.30; Tue, 14 Jul 2020 05:02:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728110AbgGNMCO (ORCPT + 99 others); Tue, 14 Jul 2020 08:02:14 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:52577 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728083AbgGNMCN (ORCPT ); Tue, 14 Jul 2020 08:02:13 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from vadimp@mellanox.com) with SMTP; 14 Jul 2020 15:02:08 +0300 Received: from r-build-lowlevel.mtr.labs.mlnx. (r-build-lowlevel.mtr.labs.mlnx [10.209.0.190]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 06EC25df004353; Tue, 14 Jul 2020 15:02:08 +0300 From: Vadim Pasternak To: andy@infradead.org, dvhart@infradead.org Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Vadim Pasternak Subject: [PATCH platform-next v2 02/11] lib/test-string_helpers.c: Add string_upper() and string_lower() tests Date: Tue, 14 Jul 2020 15:01:54 +0300 Message-Id: <20200714120203.10352-3-vadimp@mellanox.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200714120203.10352-1-vadimp@mellanox.com> References: <20200714120203.10352-1-vadimp@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add few of simple tests for string_upper() and string_lower() helpers. Signed-off-by: Vadim Pasternak --- lib/test-string_helpers.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c index 25b5cbfb7615..10360d4ea273 100644 --- a/lib/test-string_helpers.c +++ b/lib/test-string_helpers.c @@ -238,6 +238,28 @@ static const struct test_string_2 escape1[] __initconst = {{ /* terminator */ }}; +static const struct test_string strings_upper[] __initconst = { + { + .in = "abcdefgh1234567890test", + .out = "ABCDEFGH1234567890TEST", + }, + { + .in = "abCdeFgH1234567890TesT", + .out = "ABCDEFGH1234567890TEST", + }, +}; + +static const struct test_string strings_lower[] __initconst = { + { + .in = "ABCDEFGH1234567890TEST", + .out = "abcdefgh1234567890test", + }, + { + .in = "abCdeFgH1234567890TesT", + .out = "abcdefgh1234567890test", + }, +}; + static __init const char *test_string_find_match(const struct test_string_2 *s2, unsigned int flags) { @@ -390,6 +412,48 @@ static __init void test_string_get_size(void) test_string_get_size_one(4096, U64_MAX, "75.6 ZB", "64.0 ZiB"); } +static void __init test_string_upper_lower(void) +{ + char *dst; + int i; + + for (i = 0; i < ARRAY_SIZE(strings_upper); i++) { + const char *s = strings_upper[i].in; + int len = strlen(strings_upper[i].in) + 1; + + dst = kmalloc(len, GFP_KERNEL); + if (!dst) + return; + + string_upper(dst, s); + if (memcmp(dst, strings_upper[i].out, len)) { + pr_warn("Test 'string_upper' failed : expected %s, got %s!\n", + strings_upper[i].out, dst); + kfree(dst); + return; + } + kfree(dst); + } + + for (i = 0; i < ARRAY_SIZE(strings_lower); i++) { + const char *s = strings_lower[i].in; + int len = strlen(strings_lower[i].in) + 1; + + dst = kmalloc(len, GFP_KERNEL); + if (!dst) + return; + + string_lower(dst, s); + if (memcmp(dst, strings_lower[i].out, len)) { + pr_warn("Test 'string_lower failed : : expected %s, got %s!\n", + strings_lower[i].out, dst); + kfree(dst); + return; + } + kfree(dst); + } +} + static int __init test_string_helpers_init(void) { unsigned int i; @@ -411,6 +475,9 @@ static int __init test_string_helpers_init(void) /* Test string_get_size() */ test_string_get_size(); + /* Test string upper(), string_lower() */ + test_string_upper_lower(); + return -EINVAL; } module_init(test_string_helpers_init); -- 2.11.0