From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2E38945B26; Sun, 13 Oct 2024 08:53:10 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EAC4F40151; Sun, 13 Oct 2024 08:53:09 +0200 (CEST) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id A14314003C for ; Sun, 13 Oct 2024 08:53:08 +0200 (CEST) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id F3D4CA99B for ; Sun, 13 Oct 2024 08:53:07 +0200 (CEST) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id DB7A7A99A; Sun, 13 Oct 2024 08:53:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on hermod.lysator.liu.se X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,AWL, T_SCC_BODY_TEXT_LINE autolearn=disabled version=4.0.0 X-Spam-Score: -1.2 Received: from [192.168.1.85] (h-62-63-215-114.A163.priv.bahnhof.se [62.63.215.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id 9196FA8D9; Sun, 13 Oct 2024 08:53:05 +0200 (CEST) Message-ID: <55889d87-e94c-4a94-9850-a2b3b7e8d5a4@lysator.liu.se> Date: Sun, 13 Oct 2024 08:53:04 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] test/bitops: check worker lcore availability To: David Marchand , dev@dpdk.org Cc: Jack Bond-Preston , =?UTF-8?Q?Morten_Br=C3=B8rup?= , =?UTF-8?Q?Mattias_R=C3=B6nnblom?= , Tyler Retzlaff References: <20241011152533.3189097-1-david.marchand@redhat.com> Content-Language: en-US From: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= In-Reply-To: <20241011152533.3189097-1-david.marchand@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP 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 On 2024-10-11 17:25, David Marchand wrote: > Coverity is not able to understand that having 2 lcores means that > rte_get_next_lcore(-1, 0, 1) can't return RTE_MAX_LCORE. > Add an assert. > > Coverity issue: 445382, 445383, 445384, 445387, 445389, 445391 > Fixes: 35326b61aecb ("bitops: add atomic bit operations in new API") > > Signed-off-by: David Marchand > --- > Note: > - a better fix would be to check lcore id validity in the EAL launch API, > but it requires inspecting all functions and it could result in some > API change, so sending this as a simple fix for now, > > --- > app/test/test_bitops.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/app/test/test_bitops.c b/app/test/test_bitops.c > index 4200073ae4..4ed54709fb 100644 > --- a/app/test/test_bitops.c > +++ b/app/test/test_bitops.c > @@ -159,6 +159,7 @@ test_bit_atomic_parallel_assign ## size(void) \ > return TEST_SKIPPED; \ > } \ > worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ > + TEST_ASSERT(worker_lcore_id < RTE_MAX_LCORE, "Failed to find a worker lcore"); \ How about: static unsigned int get_worker_lcore(void) { unsigned int lcore_id; lcore_id = rte_get_next_lcore(-1, 1, 0); /* avoid Coverity false positives */ RTE_VERIFY(lcore_id < RTE_MAX_LCORE); return lcore_id; } In the macros: worker_lcore_id = get_worker_lcore(-1, 1, 0); Makes the macros a tiny bit smaller/less redundant and gives an opportunity for a comment. Also, it's more appropriate to use RTE_VERIFY I would argue, since rte_get_next_lcore() is not the SUT. > lmain.bit = rte_rand_max(size); \ > do { \ > lworker.bit = rte_rand_max(size); \ > @@ -218,6 +219,7 @@ test_bit_atomic_parallel_test_and_modify ## size(void) \ > return TEST_SKIPPED; \ > } \ > worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ > + TEST_ASSERT(worker_lcore_id < RTE_MAX_LCORE, "Failed to find a worker lcore"); \ > int rc = rte_eal_remote_launch(run_parallel_test_and_modify ## size, &lworker, \ > worker_lcore_id); \ > TEST_ASSERT(rc == 0, "Worker thread launch failed"); \ > @@ -267,6 +269,7 @@ test_bit_atomic_parallel_flip ## size(void) \ > return TEST_SKIPPED; \ > } \ > worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ > + TEST_ASSERT(worker_lcore_id < RTE_MAX_LCORE, "Failed to find a worker lcore"); \ > int rc = rte_eal_remote_launch(run_parallel_flip ## size, &lworker, worker_lcore_id); \ > TEST_ASSERT(rc == 0, "Worker thread launch failed"); \ > run_parallel_flip ## size(&lmain); \