From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5D97FA04F3 for ; Fri, 20 Dec 2019 15:02:23 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4B37737AF; Fri, 20 Dec 2019 15:02:23 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 8603037AF for ; Fri, 20 Dec 2019 15:02:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576850542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4cC6buajkxwPh7wWiVa6l+OdPivR1DzXqgVRL3bAURY=; b=YGkYoE/QcYSlg6a20tFISIystNGclfEiM6RPeymL/T8x8XO0OINnJG/iAbjDnnk2vNoUbt uuEt5a8asdLRdMYuuz7X+TCdGVT75HmV5fs/fp2WOWFaGyVMFzQlUe+BvzpakGRjjsb122 vLbGLzJao/TL1PCzC/6ZpuU6YQ8i+4Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-75-5TdD0LQ6MGGUmk0zg6CBpQ-1; Fri, 20 Dec 2019 09:02:04 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CBBD2800EB5; Fri, 20 Dec 2019 14:02:03 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-206-38.brq.redhat.com [10.40.206.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5B6C6E41F; Fri, 20 Dec 2019 14:02:02 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: aconole@redhat.com, stable@dpdk.org Date: Fri, 20 Dec 2019 15:01:49 +0100 Message-Id: <20191220140149.1043-1-david.marchand@redhat.com> In-Reply-To: <20191204205241.5691-1-david.marchand@redhat.com> References: <20191204205241.5691-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 5TdD0LQ6MGGUmk0zg6CBpQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] [PATCH v2] test/common: fix log2 check X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" We recently started to get random failures on the common_autotest ut with clang on Ubuntu 16.04.6. Example: https://travis-ci.com/DPDK/dpdk/jobs/263177424 Wrong rte_log2_u64(0) val 0, expected ffffffff Test Failed The ut passes 0 to log2() to get an expected value. Quoting log2 / log(3) manual: If x is zero, then a pole error occurs, and the functions return -HUGE_VAL, -HUGE_VALF, or -HUGE_VALL, respectively. rte_log2_uXX helpers handle 0 as a special value and return 0. Let's have dedicated tests for this case. Fixes: 05c4345ef5c2 ("test: add unit test for integer log2 function") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Aaron Conole --- Changelog since v1: - added comment in rte_log2_uXX API descriptions, --- app/test/test_common.c | 14 +++++++++++++- lib/librte_eal/common/include/rte_common.h | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/test/test_common.c b/app/test/test_common.c index 2b856f8ba5..12bd1cad90 100644 --- a/app/test/test_common.c +++ b/app/test/test_common.c @@ -216,7 +216,19 @@ test_log2(void) =09const uint32_t max =3D 0x10000; =09const uint32_t step =3D 1; =20 -=09for (i =3D 0; i < max; i =3D i + step) { +=09compare =3D rte_log2_u32(0); +=09if (compare !=3D 0) { +=09=09printf("Wrong rte_log2_u32(0) val %x, expected 0\n", compare); +=09=09return TEST_FAILED; +=09} + +=09compare =3D rte_log2_u64(0); +=09if (compare !=3D 0) { +=09=09printf("Wrong rte_log2_u64(0) val %x, expected 0\n", compare); +=09=09return TEST_FAILED; +=09} + +=09for (i =3D 1; i < max; i =3D i + step) { =09=09uint64_t i64; =20 =09=09/* extend range for 64-bit */ diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/co= mmon/include/rte_common.h index 459d082d14..7a98071ffe 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -538,6 +538,9 @@ rte_bsf32_safe(uint64_t v, uint32_t *pos) /** * Return the rounded-up log2 of a integer. * + * @note Contrary to the logarithm mathematical operation, + * rte_log2_u32(0) =3D=3D 0 and not -inf. + * * @param v * The input parameter. * @return @@ -632,6 +635,9 @@ rte_fls_u64(uint64_t x) /** * Return the rounded-up log2 of a 64-bit integer. * + * @note Contrary to the logarithm mathematical operation, + * rte_log2_u32(0) =3D=3D 0 and not -inf. + * * @param v * The input parameter. * @return --=20 2.23.0