mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vadim Pasternak <vadimp@mellanox.com>
To: andy@infradead.org, dvhart@infradead.org
Cc: platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Vadim Pasternak <vadimp@mellanox.com>
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	[thread overview]
Message-ID: <20200714120203.10352-3-vadimp@mellanox.com> (raw)
In-Reply-To: <20200714120203.10352-1-vadimp@mellanox.com>

Add few of simple tests for string_upper() and string_lower() helpers.

Signed-off-by: Vadim Pasternak <vadimp@mellanox.com>
---
 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


  parent reply	other threads:[~2020-07-14 12:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14 12:01 [PATCH platform-next v2 00/11] platform/x86: Add new features for Mellanox systems Vadim Pasternak
2020-07-14 12:01 ` [PATCH platform-next v2 01/11] lib/string_helpers: Introduce string_upper() and string_lower() helpers Vadim Pasternak
2020-07-14 12:01 ` Vadim Pasternak [this message]
2020-07-14 12:01 ` [PATCH platform-next v2 03/11] platform/mellanox: mlxreg-hotplug: Modify module license Vadim Pasternak
2020-07-14 12:01 ` [PATCH platform-next v2 04/11] platform/mellanox: mlxreg-hotplug: Use capability register for attribute creation Vadim Pasternak
2020-07-14 12:01 ` [PATCH platform-next v2 05/11] platform/mellanox: mlxreg-hotplug: Add environmental data to uevent Vadim Pasternak
2020-07-14 12:01 ` [PATCH platform-next v2 06/11] platform_data/mlxreg: Add support for complex attributes Vadim Pasternak
2020-07-14 12:01 ` [PATCH platform-next v2 07/11] platform/x86: mlx-platform: Add more definitions for system attributes Vadim Pasternak
2020-07-14 12:02 ` [PATCH platform-next v2 08/11] platform/mellanox: mlxreg-io: Add support for complex attributes Vadim Pasternak
2020-07-14 12:02 ` [PATCH platform-next v2 09/11] Documentation/ABI: Add new attribute for mlxreg-io sysfs interfaces Vadim Pasternak
2020-07-14 12:02 ` [PATCH platform-next v2 10/11] platform_data/mlxreg: Add presence register field for FAN devices Vadim Pasternak
2020-07-14 12:02 ` [PATCH platform-next v2 11/11] platform/x86: mlx-platform: Extend FAN platform data description Vadim Pasternak
2020-07-15 10:01 ` [PATCH platform-next v2 00/11] platform/x86: Add new features for Mellanox systems Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200714120203.10352-3-vadimp@mellanox.com \
    --to=vadimp@mellanox.com \
    --cc=andy@infradead.org \
    --cc=dvhart@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®