[v3,3/6] test/hash: test more corner cases in unit test

Message ID 1540494678-64299-4-git-send-email-yipeng1.wang@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series hash: improve multiple places |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Wang, Yipeng1 Oct. 25, 2018, 7:11 p.m. UTC
  This commit improves the readwrite unit test to cover
more corner cases and reduces the testing time by
reducing the total key count.

Signed-off-by: Yipeng Wang <yipeng1.wang@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
 test/test/test_hash_readwrite.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)
  

Comments

Honnappa Nagarahalli Oct. 26, 2018, 5:03 a.m. UTC | #1
>
> This commit improves the readwrite unit test to cover more corner cases and
> reduces the testing time by reducing the total key count.
>
> Signed-off-by: Yipeng Wang <yipeng1.wang@intel.com>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  test/test/test_hash_readwrite.c | 31 +++++++++++++++++++++++++------
>  1 file changed, 25 insertions(+), 6 deletions(-)
>
> diff --git a/test/test/test_hash_readwrite.c b/test/test/test_hash_readwrite.c
> index a8fadd0..a45c669 100644
> --- a/test/test/test_hash_readwrite.c
> +++ b/test/test/test_hash_readwrite.c
> @@ -18,8 +18,8 @@
>
>  #define RTE_RWTEST_FAIL 0
>
> -#define TOTAL_ENTRY (16*1024*1024)
> -#define TOTAL_INSERT (15*1024*1024)
> +#define TOTAL_ENTRY (5*1024*1024)
> +#define TOTAL_INSERT (4.5*1024*1024)
>
>  #define NUM_TEST 3
>  unsigned int core_cnt[NUM_TEST] = {2, 4, 8}; @@ -59,8 +59,10 @@
> test_hash_readwrite_worker(__attribute__((unused)) void *arg)
>  uint64_t i, offset;
>  uint32_t lcore_id = rte_lcore_id();
>  uint64_t begin, cycles;
> -int ret;
> +int *ret;
>
> +ret = rte_malloc(NULL, sizeof(int) *
> +tbl_rw_test_param.num_insert, 0);
This memory needs to be freed at the end of this function

>  for (i = 0; i < rte_lcore_count(); i++) {
>  if (slave_core_ids[i] == lcore_id)
>  break;
> @@ -79,13 +81,30 @@ test_hash_readwrite_worker(__attribute__((unused))
> void *arg)
>  tbl_rw_test_param.keys + i) > 0)
>  break;
>
> -ret = rte_hash_add_key(tbl_rw_test_param.h,
> +ret[i - offset] = rte_hash_add_key(tbl_rw_test_param.h,
>       tbl_rw_test_param.keys + i);
> -if (ret < 0)
> +if (ret[i - offset] < 0)
> +break;
> +
> +/* lookup a random key */
> +uint32_t rand = rte_rand() % (i + 1 - offset);
> +
> +if (rte_hash_lookup(tbl_rw_test_param.h,
> +tbl_rw_test_param.keys + rand) != ret[rand])
> +break;
> +
> +
> +if (rte_hash_del_key(tbl_rw_test_param.h,
> +tbl_rw_test_param.keys + rand) != ret[rand])
> +break;
> +
> +ret[rand] = rte_hash_add_key(tbl_rw_test_param.h,
> +tbl_rw_test_param.keys + rand);
> +if (ret[rand] < 0)
>  break;
>
>  if (rte_hash_lookup(tbl_rw_test_param.h,
> -tbl_rw_test_param.keys + i) != ret)
> +tbl_rw_test_param.keys + rand) != ret[rand])
>  break;
>  }
>
> --
> 2.7.4

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
  
Thomas Monjalon Oct. 26, 2018, 11:02 a.m. UTC | #2
> > --- a/test/test/test_hash_readwrite.c
> > +++ b/test/test/test_hash_readwrite.c
> > test_hash_readwrite_worker(__attribute__((unused)) void *arg)
> >  uint64_t i, offset;
> >  uint32_t lcore_id = rte_lcore_id();
> >  uint64_t begin, cycles;
> > -int ret;
> > +int *ret;
> >
> > +ret = rte_malloc(NULL, sizeof(int) *
> > +tbl_rw_test_param.num_insert, 0);
> This memory needs to be freed at the end of this function

I am waiting a v4 for this change, please.
  

Patch

diff --git a/test/test/test_hash_readwrite.c b/test/test/test_hash_readwrite.c
index a8fadd0..a45c669 100644
--- a/test/test/test_hash_readwrite.c
+++ b/test/test/test_hash_readwrite.c
@@ -18,8 +18,8 @@ 
 
 #define RTE_RWTEST_FAIL 0
 
-#define TOTAL_ENTRY (16*1024*1024)
-#define TOTAL_INSERT (15*1024*1024)
+#define TOTAL_ENTRY (5*1024*1024)
+#define TOTAL_INSERT (4.5*1024*1024)
 
 #define NUM_TEST 3
 unsigned int core_cnt[NUM_TEST] = {2, 4, 8};
@@ -59,8 +59,10 @@  test_hash_readwrite_worker(__attribute__((unused)) void *arg)
 	uint64_t i, offset;
 	uint32_t lcore_id = rte_lcore_id();
 	uint64_t begin, cycles;
-	int ret;
+	int *ret;
 
+	ret = rte_malloc(NULL, sizeof(int) *
+				tbl_rw_test_param.num_insert, 0);
 	for (i = 0; i < rte_lcore_count(); i++) {
 		if (slave_core_ids[i] == lcore_id)
 			break;
@@ -79,13 +81,30 @@  test_hash_readwrite_worker(__attribute__((unused)) void *arg)
 				tbl_rw_test_param.keys + i) > 0)
 			break;
 
-		ret = rte_hash_add_key(tbl_rw_test_param.h,
+		ret[i - offset] = rte_hash_add_key(tbl_rw_test_param.h,
 				     tbl_rw_test_param.keys + i);
-		if (ret < 0)
+		if (ret[i - offset] < 0)
+			break;
+
+		/* lookup a random key */
+		uint32_t rand = rte_rand() % (i + 1 - offset);
+
+		if (rte_hash_lookup(tbl_rw_test_param.h,
+				tbl_rw_test_param.keys + rand) != ret[rand])
+			break;
+
+
+		if (rte_hash_del_key(tbl_rw_test_param.h,
+				tbl_rw_test_param.keys + rand) != ret[rand])
+			break;
+
+		ret[rand] = rte_hash_add_key(tbl_rw_test_param.h,
+					tbl_rw_test_param.keys + rand);
+		if (ret[rand] < 0)
 			break;
 
 		if (rte_hash_lookup(tbl_rw_test_param.h,
-				tbl_rw_test_param.keys + i) != ret)
+			tbl_rw_test_param.keys + rand) != ret[rand])
 			break;
 	}