[v3,3/3] test/bitcount: add bitcount tests

Message ID 1673042505-756-4-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series eal: provide leading and trailing zero bit count |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Tyler Retzlaff Jan. 6, 2023, 10:01 p.m. UTC
  basic unit test of following functions

    rte_clz32
    rte_clz64
    rte_ctz32
    rte_ctz64

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 app/test/meson.build     |  2 ++
 app/test/test_bitcount.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100644 app/test/test_bitcount.c
  

Comments

Thomas Monjalon Jan. 7, 2023, 8:15 a.m. UTC | #1
06/01/2023 23:01, Tyler Retzlaff:
> basic unit test of following functions
> 
>     rte_clz32
>     rte_clz64
>     rte_ctz32
>     rte_ctz64

This can be squashed with implementation in previous patch.
  
Morten Brørup Jan. 7, 2023, 1:40 p.m. UTC | #2
> From: Tyler Retzlaff [mailto:roretzla@linux.microsoft.com]
> Sent: Friday, 6 January 2023 23.02
> 
> basic unit test of following functions
> 
>     rte_clz32
>     rte_clz64
>     rte_ctz32
>     rte_ctz64
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---

Series-acked-by: Morten Brørup <mb@smartsharesystems.com>
  
Tyler Retzlaff Jan. 9, 2023, 4:57 p.m. UTC | #3
On Sat, Jan 07, 2023 at 09:15:27AM +0100, Thomas Monjalon wrote:
> 06/01/2023 23:01, Tyler Retzlaff:
> > basic unit test of following functions
> > 
> >     rte_clz32
> >     rte_clz64
> >     rte_ctz32
> >     rte_ctz64
> 
> This can be squashed with implementation in previous patch.
> 
> 

if you mean squashed into the patch that moves the existing functions
sure it can be, but really the addtions are a self contained change
separate from the move of the existing functions.

ordinarily i'd rather see history order be as follows.

- here is a change that just moves code (no addtions no deletions).
- here is a change that adds new apis (no moves).

you sure you want the move and additions all combined into one change?

either way confirm what you want and if needed i'll combine and push a
v4.

thanks
  
Tyler Retzlaff Jan. 9, 2023, 5:26 p.m. UTC | #4
On Mon, Jan 09, 2023 at 08:57:32AM -0800, Tyler Retzlaff wrote:
> On Sat, Jan 07, 2023 at 09:15:27AM +0100, Thomas Monjalon wrote:
> > 06/01/2023 23:01, Tyler Retzlaff:
> > > basic unit test of following functions
> > > 
> > >     rte_clz32
> > >     rte_clz64
> > >     rte_ctz32
> > >     rte_ctz64
> > 
> > This can be squashed with implementation in previous patch.
> > 
> > 
> 
> if you mean squashed into the patch that moves the existing functions
> sure it can be, but really the addtions are a self contained change
> separate from the move of the existing functions.
> 
> ordinarily i'd rather see history order be as follows.
> 
> - here is a change that just moves code (no addtions no deletions).
> - here is a change that adds new apis (no moves).
> 
> you sure you want the move and additions all combined into one change?
> 
> either way confirm what you want and if needed i'll combine and push a
> v4.
> 

ignore the above, i misread what you were asking for.  i will submit a
new version with the unit tests squished in to the new function
additions.


> thanks
  

Patch

diff --git a/app/test/meson.build b/app/test/meson.build
index f34d19e..d1277bc 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -13,6 +13,7 @@  test_sources = files(
         'test_alarm.c',
         'test_atomic.c',
         'test_barrier.c',
+        'test_bitcount.c',
         'test_bitops.c',
         'test_bitmap.c',
         'test_bpf.c',
@@ -160,6 +161,7 @@  test_deps += ['bus_pci', 'bus_vdev']
 fast_tests = [
         ['acl_autotest', true, true],
         ['atomic_autotest', false, true],
+        ['bitcount_autotest', true, true],
         ['bitmap_autotest', true, true],
         ['bpf_autotest', true, true],
         ['bpf_convert_autotest', true, true],
diff --git a/app/test/test_bitcount.c b/app/test/test_bitcount.c
new file mode 100644
index 0000000..36eb05c
--- /dev/null
+++ b/app/test/test_bitcount.c
@@ -0,0 +1,71 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2022 Microsoft Corporation
+ */
+
+#include <string.h>
+
+#include <rte_bitops.h>
+#include <rte_debug.h>
+
+#include "test.h"
+
+RTE_LOG_REGISTER(bitcount_logtype_test, test.bitcount, INFO);
+
+static int
+test_clz32(void)
+{
+	uint32_t v = 1;
+	RTE_TEST_ASSERT(rte_clz32(v) == sizeof(v) * CHAR_BIT - 1,
+	    "Unexpected count.");
+
+	return 0;
+}
+
+static int
+test_clz64(void)
+{
+	uint64_t v = 1;
+	RTE_TEST_ASSERT(rte_clz64(v) == sizeof(v) * CHAR_BIT - 1,
+	    "Unexpected count.");
+
+	return 0;
+}
+
+static int
+test_ctz32(void)
+{
+	uint32_t v = 2;
+	RTE_TEST_ASSERT(rte_ctz32(v) == 1, "Unexpected count.");
+
+	return 0;
+}
+
+static int
+test_ctz64(void)
+{
+	uint64_t v = 2;
+	RTE_TEST_ASSERT(rte_ctz64(v) == 1, "Unexpected count.");
+
+	return 0;
+}
+
+static struct unit_test_suite bitcount_test_suite = {
+	.suite_name = "bitcount autotest",
+	.setup = NULL,
+	.teardown = NULL,
+	.unit_test_cases = {
+		TEST_CASE(test_clz32),
+		TEST_CASE(test_clz64),
+		TEST_CASE(test_ctz32),
+		TEST_CASE(test_ctz64),
+		TEST_CASES_END()
+	}
+};
+
+static int
+test_bitcount(void)
+{
+	return unit_test_suite_runner(&bitcount_test_suite);
+}
+
+REGISTER_TEST_COMMAND(bitcount_autotest, test_bitcount);