mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/9] tlsf: use bselftest for testing ffs/fls
Date: Tue,  4 Oct 2022 17:54:00 +0200	[thread overview]
Message-ID: <20221004155405.3458479-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20221004155405.3458479-1-a.fatoum@pengutronix.de>

The driver has two instances of #ifdef _DEBUG, but when the symbol is
actually defined, we get a build error because of the old-style C
function definition. Fix this and while at it, turn it into a
bselftest.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/tlsf.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/common/tlsf.c b/common/tlsf.c
index 3ca58e3abbfb..8dbb41077cad 100644
--- a/common/tlsf.c
+++ b/common/tlsf.c
@@ -1,14 +1,19 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
+#define pr_fmt(fmt) "tlsf: " fmt
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <tlsf.h>
+#include <bselftest.h>
 #include "tlsfbits.h"
 #include <linux/kasan.h>
 
 #define CHAR_BIT	8
 
+BSELFTEST_GLOBALS();
+
 #ifndef CONFIG_KASAN
 #define __memcpy memcpy
 #endif
@@ -870,11 +875,13 @@ void tlsf_remove_pool(tlsf_t tlsf, pool_t pool)
 ** TLSF main interface.
 */
 
-#ifdef _DEBUG
-int test_ffs_fls()
+static int test_tlfs_ffs_fls(void)
 {
-	/* Verify ffs/fls work properly. */
 	int rv = 0;
+
+	total_tests = 8;
+
+	/* Verify ffs/fls work properly. */
 	rv += (tlsf_ffs(0) == -1) ? 0 : 0x1;
 	rv += (tlsf_fls(0) == -1) ? 0 : 0x2;
 	rv += (tlsf_ffs(1) == 0) ? 0 : 0x4;
@@ -885,28 +892,21 @@ int test_ffs_fls()
 	rv += (tlsf_fls(0x7FFFFFFF) == 30) ? 0 : 0x80;
 
 #if defined (TLSF_64BIT)
+	total_tests += 3;
 	rv += (tlsf_fls_sizet(0x80000000) == 31) ? 0 : 0x100;
 	rv += (tlsf_fls_sizet(0x100000000) == 32) ? 0 : 0x200;
 	rv += (tlsf_fls_sizet(0xffffffffffffffff) == 63) ? 0 : 0x400;
+#else
+	skipped_tests += 3;
 #endif
 
-	if (rv)
-	{
-		printf("test_ffs_fls: %x ffs/fls tests failed.\n", rv);
-	}
-	return rv;
+	failed_tests = rv;
+	return 0;
 }
-#endif
+bselftest(core, test_tlfs_ffs_fls);
 
 tlsf_t tlsf_create(void* mem)
 {
-#ifdef _DEBUG
-	if (test_ffs_fls())
-	{
-		return 0;
-	}
-#endif
-
 	if (((tlsfptr_t)mem % ALIGN_SIZE) != 0)
 	{
 		printf("tlsf_create: Memory must be aligned to %u bytes.\n",
-- 
2.30.2




  parent reply	other threads:[~2022-10-04 15:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-04 15:53 [PATCH 0/9] tlsf: use 8-byte alignment for normal malloc allocations Ahmad Fatoum
2022-10-04 15:53 ` [PATCH 1/9] test: include <linux/printk.h> Ahmad Fatoum
2022-10-04 15:54 ` Ahmad Fatoum [this message]
2022-10-04 15:54 ` [PATCH 3/9] tlsf: ensure malloc pool is aligned Ahmad Fatoum
2022-10-04 15:54 ` [PATCH 4/9] tlsf: fix sizeof(size_t) == sizeof(void *) assumption Ahmad Fatoum
2022-10-04 15:54 ` [PATCH 5/9] tlsf: decouple maximum allocation size from sizeof(size_t) Ahmad Fatoum
2022-10-04 15:54 ` [PATCH 6/9] tlsf: use 8-byte alignment for normal malloc allocations Ahmad Fatoum
2022-10-04 15:54 ` [PATCH 7/9] common: malloc: ensure alignment is always at least 8 byte Ahmad Fatoum
2022-10-04 15:54 ` [PATCH 8/9] test: self: refactor to allow alignment check Ahmad Fatoum
2022-10-04 15:54 ` [PATCH 9/9] test: self: malloc: fix memory leaks Ahmad Fatoum
2022-10-04 16:23 ` [PATCH 0/9] tlsf: use 8-byte alignment for normal malloc allocations Enrico Scholz
2022-10-04 16:34   ` Ahmad Fatoum
2022-10-14  8:54 ` Sascha Hauer
2022-10-20 13:11   ` Ahmad Fatoum

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=20221004155405.3458479-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=enrico.scholz@sigma-chemnitz.de \
    /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