DPDK patches and discussions
 help / color / mirror / Atom feed
From: Pablo de Lara <pablo.de.lara.guarch@intel.com>
To: byron.marohn@intel.com
Cc: dev@dpdk.org, Pablo de Lara <pablo.de.lara.guarch@intel.com>
Subject: [dpdk-dev] [PATCH] app/test: fix overflow in EFD test
Date: Wed, 25 Jan 2017 11:29:18 +0000	[thread overview]
Message-ID: <1485343758-179761-1-git-send-email-pablo.de.lara.guarch@intel.com> (raw)

When RTE_EFD_VALUE_NUM_BITS is 32, there was a compilation issue
because of an overflow:

app/test/test_efd.c:157:55: error: overflow in expression;
result is 2147483647 with type 'int' [-Werror,-Winteger-overflow]
        data[0] = mrand48() & ((1 << RTE_EFD_VALUE_NUM_BITS) - 1);

This commit fixes the issue by using a setting a different
macro VALUE_BITMASK with a conditional

Fixes: 0e925aef2779 ("app/test: add EFD functional and perf tests")

Reported-by: Yong Liu <yong.liu@intel.com>
Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 app/test/test_efd.c      | 12 +++++++++---
 app/test/test_efd_perf.c |  9 ++++++++-
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/app/test/test_efd.c b/app/test/test_efd.c
index d5c3bd9..de49e1d 100644
--- a/app/test/test_efd.c
+++ b/app/test/test_efd.c
@@ -44,6 +44,12 @@
 #define EFD_TEST_KEY_LEN 8
 #define TABLE_SIZE (1 << 21)
 #define ITERATIONS 3
+
+#if RTE_EFD_VALUE_NUM_BITS == 32
+#define VALUE_BITMASK 0xffffffff
+#else
+#define VALUE_BITMASK ((1 << RTE_EFD_VALUE_NUM_BITS) - 1)
+#endif
 static unsigned int test_socket_id;
 
 /* 5-tuple key type */
@@ -154,7 +160,7 @@ static int test_add_delete(void)
 			efd_get_all_sockets_bitmask(), test_socket_id);
 	TEST_ASSERT_NOT_NULL(handle, "Error creating the EFD table\n");
 
-	data[0] = mrand48() & ((1 << RTE_EFD_VALUE_NUM_BITS) - 1);
+	data[0] = mrand48() & VALUE_BITMASK;
 	TEST_ASSERT_SUCCESS(rte_efd_update(handle, test_socket_id, &keys[0],
 			data[0]),
 			"Error inserting the key");
@@ -191,7 +197,7 @@ static int test_add_update_delete(void)
 	printf("Entering %s\n", __func__);
 	/* test with standard add/lookup/delete functions */
 	efd_value_t prev_value;
-	data[1] = mrand48() & ((1 << RTE_EFD_VALUE_NUM_BITS) - 1);
+	data[1] = mrand48() & VALUE_BITMASK;
 
 	handle = rte_efd_create("test_add_update_delete", TABLE_SIZE,
 			sizeof(struct flow_key),
@@ -285,7 +291,7 @@ static int test_five_keys(void)
 
 	/* Setup data */
 	for (i = 0; i < 5; i++)
-		data[i] = mrand48() & ((1 << RTE_EFD_VALUE_NUM_BITS) - 1);
+		data[i] = mrand48() & VALUE_BITMASK;
 
 	/* Add */
 	for (i = 0; i < 5; i++) {
diff --git a/app/test/test_efd_perf.c b/app/test/test_efd_perf.c
index 998a25b..2b8a8ea 100644
--- a/app/test/test_efd_perf.c
+++ b/app/test/test_efd_perf.c
@@ -43,12 +43,19 @@
 #include <rte_thash.h>
 
 #include "test.h"
+
 #define NUM_KEYSIZES 10
 #define NUM_SHUFFLES 10
 #define MAX_KEYSIZE 64
 #define MAX_ENTRIES (1 << 19)
 #define KEYS_TO_ADD (MAX_ENTRIES * 3 / 4) /* 75% table utilization */
 #define NUM_LOOKUPS (KEYS_TO_ADD * 5) /* Loop among keys added, several times */
+
+#if RTE_EFD_VALUE_NUM_BITS == 32
+#define VALUE_BITMASK 0xffffffff
+#else
+#define VALUE_BITMASK ((1 << RTE_EFD_VALUE_NUM_BITS) - 1)
+#endif
 static unsigned int test_socket_id;
 
 static inline uint8_t efd_get_all_sockets_bitmask(void)
@@ -154,7 +161,7 @@ setup_keys_and_data(struct efd_perf_params *params, unsigned int cycle)
 		for (j = 0; j < params->key_size; j++)
 			keys[i][j] = rte_rand() & 0xFF;
 
-		data[i] = rte_rand() & ((1 << RTE_EFD_VALUE_NUM_BITS) - 1);
+		data[i] = rte_rand() & VALUE_BITMASK;
 	}
 
 	/* Remove duplicates from the keys array */
-- 
2.7.4

             reply	other threads:[~2017-01-25 11:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-25 11:29 Pablo de Lara [this message]
2017-01-30 16:14 ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1485343758-179761-1-git-send-email-pablo.de.lara.guarch@intel.com \
    --to=pablo.de.lara.guarch@intel.com \
    --cc=byron.marohn@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).