From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id A76C7A04F3;
	Fri, 20 Dec 2019 15:02:18 +0100 (CET)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id E30BA2C52;
	Fri, 20 Dec 2019 15:02:17 +0100 (CET)
Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com
 [207.211.31.120]) by dpdk.org (Postfix) with ESMTP id 45F651F1C
 for <dev@dpdk.org>; Fri, 20 Dec 2019 15:02:16 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1576850533;
 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=hEJiayW3RkwrNS26SLhlHxARf56PJJzKc1auRT9S3Ap+UPNciRcWXtiU4W6AlkHxKjT6us
 umCmiuoaQtjKGr1KAlS3XXPxaPMNk9QzfgfldTR7uB58hDh1ETf2vHNDP0OiljfX4wSi5J
 uTvHSUQLL85kdERdrQPHQnp8I4mwfmQ=
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 <david.marchand@redhat.com>
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-dev] [PATCH v2] test/common: fix log2 check
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

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 <david.marchand@redhat.com>
Acked-by: Aaron Conole <aconole@redhat.com>
---
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