DPDK patches and discussions
 help / color / mirror / Atom feed
From: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
To: dev@dpdk.org
Cc: konstantin.ananyev@intel.com, yipeng1.wang@intel.com,
	sameh.gobriel@intel.com, bruce.richardson@intel.com
Subject: [dpdk-dev] [PATCH v4 3/4] test: add kv hash autotests
Date: Fri,  8 May 2020 20:58:52 +0100	[thread overview]
Message-ID: <79e3e7c72c0b72c45ee6a9ac3c8a6268417157aa.1588967562.git.vladimir.medvedkin@intel.com> (raw)
In-Reply-To: <cover.1588967562.git.vladimir.medvedkin@intel.com>
In-Reply-To: <cover.1588967562.git.vladimir.medvedkin@intel.com>

Add autotests for rte_kv_hash library

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
---
 app/test/Makefile         |   1 +
 app/test/autotest_data.py |  12 +++
 app/test/meson.build      |   3 +
 app/test/test_kv_hash.c   | 242 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 258 insertions(+)
 create mode 100644 app/test/test_kv_hash.c

diff --git a/app/test/Makefile b/app/test/Makefile
index 4e8ecab..298650f 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -73,6 +73,7 @@ SRCS-y += test_bitmap.c
 SRCS-y += test_reciprocal_division.c
 SRCS-y += test_reciprocal_division_perf.c
 SRCS-y += test_fbarray.c
+SRCS-y += test_kv_hash.c
 SRCS-y += test_external_mem.c
 SRCS-y += test_rand_perf.c
 
diff --git a/app/test/autotest_data.py b/app/test/autotest_data.py
index 7b1d013..a1351b7 100644
--- a/app/test/autotest_data.py
+++ b/app/test/autotest_data.py
@@ -99,6 +99,18 @@
         "Report":  None,
     },
     {
+        "Name":    "KV hash autotest",
+        "Command": "kv_hash_autotest",
+        "Func":    default_autotest,
+        "Report":  None,
+    },
+    {
+        "Name":    "KV hash autotest",
+        "Command": "kv_hash_slow_autotest",
+        "Func":    default_autotest,
+        "Report":  None,
+    },
+    {
         "Name":    "LPM autotest",
         "Command": "lpm_autotest",
         "Func":    default_autotest,
diff --git a/app/test/meson.build b/app/test/meson.build
index f8ed9d8..8740255 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -45,6 +45,7 @@ test_sources = files('commands.c',
 	'test_eventdev.c',
 	'test_external_mem.c',
 	'test_fbarray.c',
+	'test_kv_hash.c',
 	'test_fib.c',
 	'test_fib_perf.c',
 	'test_fib6.c',
@@ -203,6 +204,7 @@ fast_tests = [
         ['hash_autotest', true],
         ['interrupt_autotest', true],
         ['ipfrag_autotest', false],
+        ['kv_hash_autotest', true],
         ['logs_autotest', true],
         ['lpm_autotest', true],
         ['lpm6_autotest', true],
@@ -291,6 +293,7 @@ perf_test_names = [
         'hash_readwrite_perf_autotest',
         'hash_readwrite_lf_perf_autotest',
         'trace_perf_autotest',
+	'kv_hash_slow_autotest',
 ]
 
 driver_test_names = [
diff --git a/app/test/test_kv_hash.c b/app/test/test_kv_hash.c
new file mode 100644
index 0000000..646bead
--- /dev/null
+++ b/app/test/test_kv_hash.c
@@ -0,0 +1,242 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2020 Intel Corporation
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <rte_lcore.h>
+#include <rte_kv_hash.h>
+#include <rte_hash_crc.h>
+
+#include "test.h"
+
+typedef int32_t (*rte_kv_hash_test)(void);
+
+static int32_t test_create_invalid(void);
+static int32_t test_multiple_create(void);
+static int32_t test_free_null(void);
+static int32_t test_add_del_invalid(void);
+static int32_t test_basic(void);
+
+#define MAX_ENT (1 << 22)
+
+/*
+ * Check that rte_kv_hash_create fails gracefully for incorrect user input
+ * arguments
+ */
+int32_t
+test_create_invalid(void)
+{
+	struct rte_kv_hash_table *kv_hash = NULL;
+	struct rte_kv_hash_params config;
+
+	config.name = "test_kv_hash";
+	config.socket_id = rte_socket_id();
+	config.entries = MAX_ENT;
+	config.type = RTE_KV_HASH_K32V64;
+
+	/* rte_kv_hash_create: kv_hash name == NULL */
+	config.name = NULL;
+	kv_hash = rte_kv_hash_create(&config);
+	RTE_TEST_ASSERT(kv_hash == NULL,
+		"Call succeeded with invalid parameters\n");
+	config.name = "test_kv_hash";
+
+	/* rte_kv_hash_create: config == NULL */
+	kv_hash = rte_kv_hash_create(NULL);
+	RTE_TEST_ASSERT(kv_hash == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	/* socket_id < -1 is invalid */
+	config.socket_id = -2;
+	kv_hash = rte_kv_hash_create(&config);
+	RTE_TEST_ASSERT(kv_hash == NULL,
+		"Call succeeded with invalid parameters\n");
+	config.socket_id = rte_socket_id();
+
+	/* rte_kv_hash_create: entries = 0 */
+	config.entries = 0;
+	kv_hash = rte_kv_hash_create(&config);
+	RTE_TEST_ASSERT(kv_hash == NULL,
+		"Call succeeded with invalid parameters\n");
+	config.entries = MAX_ENT;
+
+	/* rte_kv_hash_create: invalid type*/
+	config.type = RTE_KV_HASH_MAX;
+	kv_hash = rte_kv_hash_create(&config);
+	RTE_TEST_ASSERT(kv_hash == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	return TEST_SUCCESS;
+}
+
+/*
+ * Create kv_hash table then delete kv_hash table 10 times
+ * Use a slightly different rules size each time
+ */
+#include <rte_errno.h>
+int32_t
+test_multiple_create(void)
+{
+	struct rte_kv_hash_table *kv_hash = NULL;
+	struct rte_kv_hash_params config;
+	int32_t i;
+
+	for (i = 0; i < 100; i++) {
+		config.name = "test_kv_hash";
+		config.socket_id = -1;
+		config.entries = MAX_ENT - i;
+		config.type = RTE_KV_HASH_K32V64;
+
+		kv_hash = rte_kv_hash_create(&config);
+		RTE_TEST_ASSERT(kv_hash != NULL,
+			"Failed to create kv hash\n");
+		rte_kv_hash_free(kv_hash);
+	}
+
+	return TEST_SUCCESS;
+}
+
+/*
+ * Call rte_kv_hash_free for NULL pointer user input.
+ * Note: free has no return and therefore it is impossible
+ * to check for failure but this test is added to
+ * increase function coverage metrics and to validate that
+ * freeing null does not crash.
+ */
+int32_t
+test_free_null(void)
+{
+	struct rte_kv_hash_table *kv_hash = NULL;
+	struct rte_kv_hash_params config;
+
+	config.name = "test_kv";
+	config.socket_id = -1;
+	config.entries = MAX_ENT;
+	config.type = RTE_KV_HASH_K32V64;
+
+	kv_hash = rte_kv_hash_create(&config);
+	RTE_TEST_ASSERT(kv_hash != NULL, "Failed to create kv hash\n");
+
+	rte_kv_hash_free(kv_hash);
+	rte_kv_hash_free(NULL);
+	return TEST_SUCCESS;
+}
+
+/*
+ * Check that rte_kv_hash_add fails gracefully for
+ * incorrect user input arguments
+ */
+int32_t
+test_add_del_invalid(void)
+{
+	uint32_t key = 10;
+	uint64_t val = 20;
+	int ret, found;
+
+	/* rte_kv_hash_add: kv_hash == NULL */
+	ret = rte_kv_hash_add(NULL, &key, rte_hash_crc_4byte(key, 0),
+		&val, &found);
+	RTE_TEST_ASSERT(ret == -EINVAL,
+		"Call succeeded with invalid parameters\n");
+
+	/* rte_kv_hash_delete: kv_hash == NULL */
+	ret = rte_kv_hash_delete(NULL, &key, rte_hash_crc_4byte(key, 0), &val);
+	RTE_TEST_ASSERT(ret == -EINVAL,
+		"Call succeeded with invalid parameters\n");
+
+	return TEST_SUCCESS;
+}
+
+/*
+ * Call add, lookup and delete for a single rule
+ */
+int32_t
+test_basic(void)
+{
+	struct rte_kv_hash_table *kv_hash = NULL;
+	struct rte_kv_hash_params config;
+	uint32_t key = 10;
+	uint64_t value = 20;
+	uint64_t ret_val = 0;
+	int ret, found;
+	uint32_t hash_sig;
+
+	config.name = "test_kv";
+	config.socket_id = -1;
+	config.entries = MAX_ENT;
+	config.type = RTE_KV_HASH_K32V64;
+
+	kv_hash = rte_kv_hash_create(&config);
+	RTE_TEST_ASSERT(kv_hash != NULL, "Failed to create kv hash\n");
+
+	hash_sig = rte_hash_crc_4byte(key, 0);
+	ret = rte_kv_hash_bulk_lookup(kv_hash, &key,
+		&hash_sig, &ret_val, 1);
+	RTE_TEST_ASSERT(ret == 0, "Lookup return incorrect result\n");
+
+	ret = rte_kv_hash_delete(kv_hash, &key, hash_sig, &ret_val);
+	RTE_TEST_ASSERT(ret == -ENOENT, "Delete return incorrect result\n");
+
+	ret = rte_kv_hash_add(kv_hash, &key, hash_sig, &value, &found);
+	RTE_TEST_ASSERT(ret == 0, "Can not add key into the table\n");
+
+	ret = rte_kv_hash_bulk_lookup(kv_hash, &key,
+		&hash_sig, &ret_val, 1);
+	RTE_TEST_ASSERT(((ret == 1) && (value == ret_val)),
+		"Lookup return incorrect result\n");
+
+	ret = rte_kv_hash_delete(kv_hash, &key, hash_sig, &ret_val);
+	RTE_TEST_ASSERT(ret == 0, "Can not delete key from table\n");
+
+	ret = rte_kv_hash_bulk_lookup(kv_hash, &key,
+		&hash_sig, &ret_val, 1);
+	RTE_TEST_ASSERT(ret == 0, "Lookup return incorrect result\n");
+
+	rte_kv_hash_free(kv_hash);
+
+	return TEST_SUCCESS;
+}
+
+static struct unit_test_suite kv_hash_tests = {
+	.suite_name = "kv_hash autotest",
+	.setup = NULL,
+	.teardown = NULL,
+	.unit_test_cases = {
+		TEST_CASE(test_create_invalid),
+		TEST_CASE(test_free_null),
+		TEST_CASE(test_add_del_invalid),
+		TEST_CASE(test_basic),
+		TEST_CASES_END()
+	}
+};
+
+static struct unit_test_suite kv_hash_slow_tests = {
+	.suite_name = "kv_hash slow autotest",
+	.setup = NULL,
+	.teardown = NULL,
+	.unit_test_cases = {
+		TEST_CASE(test_multiple_create),
+		TEST_CASES_END()
+	}
+};
+
+/*
+ * Do all unit tests.
+ */
+static int
+test_kv_hash(void)
+{
+	return unit_test_suite_runner(&kv_hash_tests);
+}
+
+static int
+test_slow_kv_hash(void)
+{
+	return unit_test_suite_runner(&kv_hash_slow_tests);
+}
+
+REGISTER_TEST_COMMAND(kv_hash_autotest, test_kv_hash);
+REGISTER_TEST_COMMAND(kv_hash_slow_autotest, test_slow_kv_hash);
-- 
2.7.4


  parent reply	other threads:[~2020-05-08 19:59 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-16 13:38 [dpdk-dev] [PATCH 0/3] add new Double Word Key hash table Vladimir Medvedkin
2020-03-16 13:38 ` [dpdk-dev] [PATCH 1/3] hash: add dwk hash library Vladimir Medvedkin
2020-03-16 13:38 ` [dpdk-dev] [PATCH 2/3] test: add dwk hash autotests Vladimir Medvedkin
2020-03-16 13:38 ` [dpdk-dev] [PATCH 3/3] test: add dwk perf tests Vladimir Medvedkin
2020-03-16 14:39 ` [dpdk-dev] [PATCH 0/3] add new Double Word Key hash table Morten Brørup
2020-03-16 18:27   ` Medvedkin, Vladimir
2020-03-16 19:32     ` Stephen Hemminger
2020-03-17 19:52       ` Wang, Yipeng1
2020-03-26 17:28         ` Medvedkin, Vladimir
2020-03-31 19:55           ` Thomas Monjalon
2020-03-31 21:17             ` Honnappa Nagarahalli
2020-04-01 18:37               ` Medvedkin, Vladimir
2020-04-01 18:28             ` Medvedkin, Vladimir
2020-03-16 19:33     ` Morten Brørup
2020-04-08 18:19 ` [dpdk-dev] [PATCH v2 0/4] add new k32v64 " Vladimir Medvedkin
2020-04-15 18:17   ` [dpdk-dev] [PATCH v3 " Vladimir Medvedkin
2020-04-15 18:51     ` Mattias Rönnblom
2020-04-16 10:18       ` Medvedkin, Vladimir
2020-04-16 11:40         ` Mattias Rönnblom
2020-04-17  0:21           ` Wang, Yipeng1
2020-04-23 16:19             ` Ananyev, Konstantin
2020-05-08 20:08             ` Medvedkin, Vladimir
2020-04-16  9:39     ` Thomas Monjalon
2020-04-16 14:02       ` Medvedkin, Vladimir
2020-04-16 14:38         ` Thomas Monjalon
2020-05-08 19:58     ` [dpdk-dev] [PATCH v4 0/4] add new kv " Vladimir Medvedkin
2020-06-16 16:37       ` Thomas Monjalon
2021-03-24 21:28       ` Thomas Monjalon
2021-03-25 12:03         ` Medvedkin, Vladimir
2023-06-12 16:11           ` Stephen Hemminger
2020-05-08 19:58     ` [dpdk-dev] [PATCH v4 1/4] hash: add kv hash library Vladimir Medvedkin
2020-06-23 15:44       ` Ananyev, Konstantin
2020-06-23 23:06         ` Ananyev, Konstantin
2020-06-25 19:56           ` Medvedkin, Vladimir
2020-06-25 19:49         ` Medvedkin, Vladimir
2020-06-24  1:19       ` Wang, Yipeng1
2020-06-25 20:26         ` Medvedkin, Vladimir
2020-06-25  4:27       ` Honnappa Nagarahalli
2020-05-08 19:58     ` [dpdk-dev] [PATCH v4 2/4] hash: add documentation for " Vladimir Medvedkin
2020-05-08 19:58     ` Vladimir Medvedkin [this message]
2020-05-08 19:58     ` [dpdk-dev] [PATCH v4 4/4] test: add kv perf tests Vladimir Medvedkin
2020-04-15 18:17   ` [dpdk-dev] [PATCH v3 1/4] hash: add k32v64 hash library Vladimir Medvedkin
2020-04-15 18:59     ` Mattias Rönnblom
2020-04-16 10:23       ` Medvedkin, Vladimir
2020-04-23 13:31     ` Ananyev, Konstantin
2020-05-08 20:14       ` Medvedkin, Vladimir
2020-04-29 21:29     ` Honnappa Nagarahalli
2020-05-08 20:38       ` Medvedkin, Vladimir
2020-04-15 18:17   ` [dpdk-dev] [PATCH v3 2/4] hash: add documentation for " Vladimir Medvedkin
2020-04-15 18:17   ` [dpdk-dev] [PATCH v3 3/4] test: add k32v64 hash autotests Vladimir Medvedkin
2020-04-15 18:17   ` [dpdk-dev] [PATCH v3 4/4] test: add k32v64 perf tests Vladimir Medvedkin
2020-04-08 18:19 ` [dpdk-dev] [PATCH v2 1/4] hash: add k32v64 hash library Vladimir Medvedkin
2020-04-08 23:23   ` Ananyev, Konstantin
2020-04-08 18:19 ` [dpdk-dev] [PATCH v2 2/4] hash: add documentation for " Vladimir Medvedkin
2020-04-08 18:19 ` [dpdk-dev] [PATCH v2 3/4] test: add k32v64 hash autotests Vladimir Medvedkin
2020-04-08 18:19 ` [dpdk-dev] [PATCH v2 4/4] test: add k32v64 perf tests Vladimir Medvedkin

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=79e3e7c72c0b72c45ee6a9ac3c8a6268417157aa.1588967562.git.vladimir.medvedkin@intel.com \
    --to=vladimir.medvedkin@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=konstantin.ananyev@intel.com \
    --cc=sameh.gobriel@intel.com \
    --cc=yipeng1.wang@intel.com \
    /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).