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 83798A0597; Wed, 8 Apr 2020 20:20:29 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5896B1C210; Wed, 8 Apr 2020 20:20:09 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id C041A1C1F5 for ; Wed, 8 Apr 2020 20:20:06 +0200 (CEST) IronPort-SDR: BzUz7AA795e+Gl6ixxZcZ8ftt/MD6sDepZKpYby2FIghSOI/QIzP2uHW1yfttSt9GydNGPMNls wIHGnAynVJZQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2020 11:20:06 -0700 IronPort-SDR: 7L3Yi1Y9sP/X5GSnv04ISd2CX/V1c6cZzk8yI8kNMEjK4o7OUhTTWk/E2PZ2siwncm9kbuVF/4 yWbwRpAyi/wQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,359,1580803200"; d="scan'208";a="254878121" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by orsmga006.jf.intel.com with ESMTP; 08 Apr 2020 11:20:04 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com Date: Wed, 8 Apr 2020 19:19:56 +0100 Message-Id: <8e057b65e96d1f7bcfe06581f19ab81525bcecac.1586369591.git.vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 3/4] test: add k32v64 hash autotests X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add autotests for rte_k32v64_hash library Signed-off-by: Vladimir Medvedkin --- app/test/Makefile | 1 + app/test/autotest_data.py | 12 +++ app/test/meson.build | 3 + app/test/test_k32v64_hash.c | 229 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 app/test/test_k32v64_hash.c diff --git a/app/test/Makefile b/app/test/Makefile index 1f080d1..f132230 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_k32v64_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..e7ec502 100644 --- a/app/test/autotest_data.py +++ b/app/test/autotest_data.py @@ -99,6 +99,18 @@ "Report": None, }, { + "Name": "K32V64 hash autotest", + "Command": "k32v64_hash_autotest", + "Func": default_autotest, + "Report": None, + }, + { + "Name": "K32V64 hash autotest", + "Command": "k32v64_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 0a2ce71..cb619ba 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_k32v64_hash.c', 'test_fib.c', 'test_fib_perf.c', 'test_fib6.c', @@ -185,6 +186,7 @@ fast_test_names = [ 'flow_classify_autotest', 'hash_autotest', 'interrupt_autotest', + 'k32v64_hash_autotest', 'logs_autotest', 'lpm_autotest', 'lpm6_autotest', @@ -270,6 +272,7 @@ perf_test_names = [ 'rand_perf_autotest', 'hash_readwrite_perf_autotest', 'hash_readwrite_lf_perf_autotest', + 'k32v64_hash_slow_autotest', ] driver_test_names = [ diff --git a/app/test/test_k32v64_hash.c b/app/test/test_k32v64_hash.c new file mode 100644 index 0000000..3cf3b8d --- /dev/null +++ b/app/test/test_k32v64_hash.c @@ -0,0 +1,229 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Intel Corporation + */ + +#include +#include +#include + +#include +#include +#include + +#include "test.h" + +typedef int32_t (*rte_k32v64_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_k32v64_hash_create fails gracefully for incorrect user input + * arguments + */ +int32_t +test_create_invalid(void) +{ + struct rte_k32v64_hash_table *k32v64_hash = NULL; + struct rte_k32v64_hash_params config; + + /* rte_k32v64_hash_create: k32v64_hash name == NULL */ + config.name = NULL; + k32v64_hash = rte_k32v64_hash_create(&config); + RTE_TEST_ASSERT(k32v64_hash == NULL, + "Call succeeded with invalid parameters\n"); + config.name = "test_k32v64_hash"; + + /* rte_k32v64_hash_create: config == NULL */ + k32v64_hash = rte_k32v64_hash_create(NULL); + RTE_TEST_ASSERT(k32v64_hash == NULL, + "Call succeeded with invalid parameters\n"); + + /* socket_id < -1 is invalid */ + config.socket_id = -2; + k32v64_hash = rte_k32v64_hash_create(&config); + RTE_TEST_ASSERT(k32v64_hash == NULL, + "Call succeeded with invalid parameters\n"); + config.socket_id = rte_socket_id(); + + /* rte_k32v64_hash_create: entries = 0 */ + config.entries = 0; + k32v64_hash = rte_k32v64_hash_create(&config); + RTE_TEST_ASSERT(k32v64_hash == NULL, + "Call succeeded with invalid parameters\n"); + config.entries = MAX_ENT; + + return TEST_SUCCESS; +} + +/* + * Create k32v64_hash table then delete k32v64_hash table 10 times + * Use a slightly different rules size each time + */ +#include +int32_t +test_multiple_create(void) +{ + struct rte_k32v64_hash_table *k32v64_hash = NULL; + struct rte_k32v64_hash_params config; + int32_t i; + + + for (i = 0; i < 100; i++) { + config.name = "test_k32v64_hash"; + config.socket_id = -1; + config.entries = MAX_ENT - i; + + k32v64_hash = rte_k32v64_hash_create(&config); + RTE_TEST_ASSERT(k32v64_hash != NULL, + "Failed to create k32v64 hash\n"); + rte_k32v64_hash_free(k32v64_hash); + } + + return TEST_SUCCESS; +} + +/* + * Call rte_k32v64_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_k32v64_hash_table *k32v64_hash = NULL; + struct rte_k32v64_hash_params config; + + config.name = "test_k32v64"; + config.socket_id = -1; + config.entries = MAX_ENT; + + k32v64_hash = rte_k32v64_hash_create(&config); + RTE_TEST_ASSERT(k32v64_hash != NULL, "Failed to create k32v64 hash\n"); + + rte_k32v64_hash_free(k32v64_hash); + rte_k32v64_hash_free(NULL); + return TEST_SUCCESS; +} + +/* + * Check that rte_k32v64_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; + + /* rte_k32v64_hash_add: k32v64_hash == NULL */ + ret = rte_k32v64_hash_add(NULL, key, rte_hash_crc_4byte(key, 0), val); + RTE_TEST_ASSERT(ret == -EINVAL, + "Call succeeded with invalid parameters\n"); + + /* rte_k32v64_hash_delete: k32v64_hash == NULL */ + ret = rte_k32v64_hash_delete(NULL, key, rte_hash_crc_4byte(key, 0)); + 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_k32v64_hash_table *k32v64_hash = NULL; + struct rte_k32v64_hash_params config; + uint32_t key = 10; + uint64_t value = 20; + uint64_t ret_val = 0; + int ret; + + config.name = "test_k32v64"; + config.socket_id = -1; + config.entries = MAX_ENT; + + k32v64_hash = rte_k32v64_hash_create(&config); + RTE_TEST_ASSERT(k32v64_hash != NULL, "Failed to create k32v64 hash\n"); + + ret = rte_k32v64_hash_lookup(k32v64_hash, key, + rte_hash_crc_4byte(key, 0), &ret_val); + RTE_TEST_ASSERT(ret == -ENOENT, "Lookup return incorrect result\n"); + + ret = rte_k32v64_hash_delete(k32v64_hash, key, + rte_hash_crc_4byte(key, 0)); + RTE_TEST_ASSERT(ret == -ENOENT, "Delete return incorrect result\n"); + + ret = rte_k32v64_hash_add(k32v64_hash, key, + rte_hash_crc_4byte(key, 0), value); + RTE_TEST_ASSERT(ret == 0, "Can not add key into the table\n"); + + ret = rte_k32v64_hash_lookup(k32v64_hash, key, + rte_hash_crc_4byte(key, 0), &ret_val); + RTE_TEST_ASSERT(((ret == 0) && (value == ret_val)), + "Lookup return incorrect result\n"); + + ret = rte_k32v64_hash_delete(k32v64_hash, key, + rte_hash_crc_4byte(key, 0)); + RTE_TEST_ASSERT(ret == 0, "Can not delete key from table\n"); + + ret = rte_k32v64_hash_lookup(k32v64_hash, key, + rte_hash_crc_4byte(key, 0), &ret_val); + RTE_TEST_ASSERT(ret == -ENOENT, "Lookup return incorrect result\n"); + + rte_k32v64_hash_free(k32v64_hash); + + return TEST_SUCCESS; +} + +static struct unit_test_suite k32v64_hash_tests = { + .suite_name = "k32v64_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 k32v64_hash_slow_tests = { + .suite_name = "k32v64_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_k32v64_hash(void) +{ + return unit_test_suite_runner(&k32v64_hash_tests); +} + +static int +test_slow_k32v64_hash(void) +{ + return unit_test_suite_runner(&k32v64_hash_slow_tests); +} + +REGISTER_TEST_COMMAND(k32v64_hash_autotest, test_k32v64_hash); +REGISTER_TEST_COMMAND(k32v64_hash_slow_autotest, test_slow_k32v64_hash); -- 2.7.4