From patchwork Wed Nov 23 23:43:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 120124 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D5386A00C2; Thu, 24 Nov 2022 00:43:30 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 084A842DB4; Thu, 24 Nov 2022 00:43:23 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 41C0E42B8C for ; Thu, 24 Nov 2022 00:43:20 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id 96F5520B83CB; Wed, 23 Nov 2022 15:43:19 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 96F5520B83CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669246999; bh=shh2OIO65oOPvBzjsYO7wj7MYFqMwSukc3FDBi30hdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EPMISPTLoXM5UGpQa0UKroYVugavEB89yKjmffn52j2DutiQsU4gKD0b+x0TQ/jTU zRBQy7vTpVXDDOsYTbUbiHxHu6OfjEX19MB8K4cptVYrFncN8jy1XfuB9Y7x0/yBOW k7+CBVQWSDJGtzJn0TxZDnB8fKSbORrUEF7e9+f0= From: Tyler Retzlaff To: dev@dpdk.org Cc: Tyler Retzlaff Subject: [PATCH v2 2/2] test/bitcount: add bitcount tests Date: Wed, 23 Nov 2022 15:43:17 -0800 Message-Id: <1669246997-30592-3-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669246997-30592-1-git-send-email-roretzla@linux.microsoft.com> References: <1669241687-18810-1-git-send-email-roretzla@linux.microsoft.com> <1669246997-30592-1-git-send-email-roretzla@linux.microsoft.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org basic unit test of following functions rte_clz rte_clzl rte_clzll rte_ctz rte_ctzl rte_ctzll Signed-off-by: Tyler Retzlaff --- app/test/meson.build | 2 ++ app/test/test_bitcount.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 app/test/test_bitcount.c 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..7b71fdf --- /dev/null +++ b/app/test/test_bitcount.c @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (C) 2022 Microsoft Corporation + */ + +#include + +#include +#include + +#include "test.h" + +RTE_LOG_REGISTER(bitcount_logtype_test, test.bitcount, INFO); + +static int +test_clz(void) +{ + unsigned int v = 1; + RTE_TEST_ASSERT(rte_clz(v) == sizeof(v) * CHAR_BIT - 1, + "Unexpected count."); + + return 0; +} + +static int +test_clzl(void) +{ + unsigned long v = 1; + RTE_TEST_ASSERT(rte_clzl(v) == sizeof(v) * CHAR_BIT - 1, + "Unexpected count."); + + return 0; +} + +static int +test_clzll(void) +{ + unsigned long long v = 1; + RTE_TEST_ASSERT(rte_clzll(v) == sizeof(v) * CHAR_BIT - 1, + "Unexpected count."); + + return 0; +} + +static int +test_ctz(void) +{ + unsigned int v = 2; + RTE_TEST_ASSERT(rte_ctz(v) == 1, "Unexpected count."); + + return 0; +} + +static int +test_ctzl(void) +{ + unsigned long v = 2; + RTE_TEST_ASSERT(rte_ctzl(v) == 1, "Unexpected count."); + + return 0; +} + +static int +test_ctzll(void) +{ + unsigned long long v = 2; + RTE_TEST_ASSERT(rte_ctzll(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_clz), + TEST_CASE(test_clzl), + TEST_CASE(test_clzll), + TEST_CASE(test_ctz), + TEST_CASE(test_ctzl), + TEST_CASE(test_ctzll), + TEST_CASES_END() + } +}; + +static int +test_bitcount(void) +{ + return unit_test_suite_runner(&bitcount_test_suite); +} + +REGISTER_TEST_COMMAND(bitcount_autotest, test_bitcount);