LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Isabella Basso <isabellabdoamaral@usp.br>
To: linux@sciencehorizons.net, geert@linux-m68k.org
Cc: ferreiraenzoa@gmail.com, augusto.duraes33@gmail.com,
	brendanhiggins@google.com, dlatypov@google.com,
	davidgow@google.com, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com,
	~lkcamp/patches@lists.sr.ht, rodrigosiqueiramelo@gmail.com,
	Isabella Basso <isabellabdoamaral@usp.br>
Subject: [PATCH 4/6] test_hash.c: split test_hash_init
Date: Wed, 25 Aug 2021 22:26:24 -0300	[thread overview]
Message-ID: <20210826012626.1163705-5-isabellabdoamaral@usp.br> (raw)
In-Reply-To: <20210826012626.1163705-1-isabellabdoamaral@usp.br>

Split up test_hash_init so that it calls each test more explicitly
insofar it is possible without rewriting the entire file. This aims at
improving readability.

Split tests performed on string_or as they don't interfere with those
performed in hash_or. Also separate pr_info calls about skipped tests as
they're not part of the tests themselves, but only warn about
(un)defined arch-specific hash functions.

Signed-off-by: Isabella Basso <isabellabdoamaral@usp.br>
---
 lib/test_hash.c | 65 ++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 54 insertions(+), 11 deletions(-)

diff --git a/lib/test_hash.c b/lib/test_hash.c
index ed75c768c231..c168823b0963 100644
--- a/lib/test_hash.c
+++ b/lib/test_hash.c
@@ -152,8 +152,37 @@ test_int_hash(unsigned long long h64)
 	return true;
 }
 
-static int __init
-test_hash_init(void)
+static int __init test_string_or(void)
+{
+	char buf[SIZE+1];
+	int i, j;
+	u32 h0;
+
+	string_or = 0;
+	fill_buf(buf, SIZE, 1);
+
+	/* Test every possible non-empty substring in the buffer. */
+	for (j = SIZE; j > 0; j--) {
+		buf[j] = '\0';
+
+		for (i = 0; i <= j; i++) {
+			h0 = full_name_hash(buf+i, buf+i, j-i);
+
+			string_or |= h0;
+		} /* i */
+	} /* j */
+
+	/* The OR of all the hash values should cover all the bits */
+	if (~string_or) {
+		pr_err("OR of all string hash results = %#x != %#x",
+		       string_or, -1u);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int __init test_hash_or(void)
 {
 	char buf[SIZE+1];
 	unsigned tests = 0;
@@ -186,7 +215,6 @@ test_hash_init(void)
 				return -EINVAL;
 			}
 
-			string_or |= h0;
 			h64 = h64 << 32 | h0;	/* For use with hash_64 */
 			if (!test_int_hash(h64))
 				return -EINVAL;
@@ -194,12 +222,6 @@ test_hash_init(void)
 		} /* i */
 	} /* j */
 
-	/* The OR of all the hash values should cover all the bits */
-	if (~string_or) {
-		pr_err("OR of all string hash results = %#x != %#x",
-			string_or, -1u);
-		return -EINVAL;
-	}
 	if (~hash_or[0][0]) {
 		pr_err("OR of all __hash_32 results = %#x != %#x",
 		       hash_or[0][0], -1u);
@@ -231,6 +253,13 @@ test_hash_init(void)
 		}
 	}
 
+	pr_notice("%u tests passed.", tests);
+
+	return 0;
+}
+
+static void __init notice_skipped_tests(void)
+{
 	/* Issue notices about skipped tests. */
 #ifdef HAVE_ARCH__HASH_32
 #if HAVE_ARCH__HASH_32 != 1
@@ -246,10 +275,24 @@ test_hash_init(void)
 #else
 	pr_info("hash_64() has no arch implementation to test.");
 #endif
+}
 
-	pr_notice("%u tests passed.", tests);
+static int __init
+test_hash_init(void)
+{
+	int ret;
 
-	return 0;
+	ret = test_string_or();
+	if (ret < 0)
+		return ret;
+
+	ret = test_hash_or();
+	if (ret < 0)
+		return ret;
+
+	notice_skipped_tests();
+
+	return ret;
 }
 
 static void __exit test_hash_exit(void)
-- 
2.33.0


  parent reply	other threads:[~2021-08-26  1:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26  1:26 [PATCH 0/6] test_hash.c: refactor into KUnit Isabella Basso
2021-08-26  1:26 ` [PATCH 1/6] hash.h: remove unused define directive Isabella Basso
2021-08-26  4:01   ` David Gow
2021-09-05 22:31     ` Isabella B do Amaral
2021-08-26  1:26 ` [PATCH 2/6] test_hash.c: move common definitions to top of file Isabella Basso
2021-08-26 14:36   ` Marco Elver
2021-09-05 22:40     ` Isabella B do Amaral
2021-08-26  1:26 ` [PATCH 3/6] test_hash.c: split test_int_hash into arch-specific functions Isabella Basso
2021-08-26  4:21   ` David Gow
2021-09-05 22:53     ` Isabella B do Amaral
2021-08-26  1:26 ` Isabella Basso [this message]
2021-08-26  1:26 ` [PATCH 5/6] lib/Kconfig.debug: properly split hash test kernel entries Isabella Basso
2021-08-26  1:26 ` [PATCH 6/6] test_hash.c: refactor into kunit Isabella Basso
2021-08-26  4:26   ` David Gow
2021-09-05 23:32     ` Isabella B do Amaral
2021-08-26  6:00   ` kernel test robot
2021-08-26 10:10   ` kernel test robot
2021-08-26  1:36 ` [PATCH 0/6] test_hash.c: refactor into KUnit Daniel Latypov

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=20210826012626.1163705-5-isabellabdoamaral@usp.br \
    --to=isabellabdoamaral@usp.br \
    --cc=augusto.duraes33@gmail.com \
    --cc=brendanhiggins@google.com \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=ferreiraenzoa@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux@sciencehorizons.net \
    --cc=rodrigosiqueiramelo@gmail.com \
    --cc=~lkcamp/patches@lists.sr.ht \
    --subject='Re: [PATCH 4/6] test_hash.c: split test_hash_init' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).