DPDK patches and discussions
 help / color / Atom feed
From: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com
Subject: [dpdk-dev] [PATCH v5 02/12] test/rib: add RIB library autotests
Date: Wed, 11 Sep 2019 18:09:42 +0100
Message-ID: <8b829507599c5a814d4325c658133fdff84d4cd9.1568221363.git.vladimir.medvedkin@intel.com> (raw)
In-Reply-To: <1524780214-23196-1-git-send-email-medvedkinv@gmail.com>

Functional tests for the new RIB library.

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
---
 app/test/Makefile         |   2 +
 app/test/autotest_data.py |   6 +
 app/test/meson.build      |   3 +
 app/test/test_rib.c       | 351 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 362 insertions(+)
 create mode 100644 app/test/test_rib.c

diff --git a/app/test/Makefile b/app/test/Makefile
index 26ba6fe..5bd8487 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -124,6 +124,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_multiwriter.c
 SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_readwrite.c
 SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_readwrite_lf.c
 
+SRCS-$(CONFIG_RTE_LIBRTE_RIB) += test_rib.c
+
 SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm.c
 SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm_perf.c
 SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm6.c
diff --git a/app/test/autotest_data.py b/app/test/autotest_data.py
index 7405149..3c3b806 100644
--- a/app/test/autotest_data.py
+++ b/app/test/autotest_data.py
@@ -111,6 +111,12 @@
         "Report":  None,
     },
     {
+        "Name":    "RIB autotest",
+        "Command": "rib_autotest",
+        "Func":    default_autotest,
+        "Report":  None,
+    },
+    {
         "Name":    "Memcpy autotest",
         "Command": "memcpy_autotest",
         "Func":    default_autotest,
diff --git a/app/test/meson.build b/app/test/meson.build
index ec40943..98524e1 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -99,6 +99,7 @@ test_sources = files('commands.c',
 	'test_reciprocal_division_perf.c',
 	'test_red.c',
 	'test_reorder.c',
+	'test_rib.c',
 	'test_ring.c',
 	'test_ring_perf.c',
 	'test_rwlock.c',
@@ -147,6 +148,7 @@ test_deps = ['acl',
 	'rawdev',
 	'rcu',
 	'reorder',
+	'rib',
 	'ring',
 	'stack',
 	'timer'
@@ -197,6 +199,7 @@ fast_test_names = [
         'prefetch_autotest',
         'rcu_qsbr_autotest',
         'red_autotest',
+        'rib_autotest',
         'ring_autotest',
         'ring_pmd_autotest',
         'rwlock_test1_autotest',
diff --git a/app/test/test_rib.c b/app/test/test_rib.c
new file mode 100644
index 0000000..c95957a
--- /dev/null
+++ b/app/test/test_rib.c
@@ -0,0 +1,351 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
+ * Copyright(c) 2019 Intel Corporation
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <rte_ip.h>
+#include <rte_rib.h>
+
+#include "test.h"
+
+typedef int32_t (*rte_rib_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_insert_invalid(void);
+static int32_t test_get_fn(void);
+static int32_t test_basic(void);
+static int32_t test_tree_traversal(void);
+
+#define MAX_DEPTH 32
+#define MAX_RULES (1 << 22)
+
+/*
+ * Check that rte_rib_create fails gracefully for incorrect user input
+ * arguments
+ */
+int32_t
+test_create_invalid(void)
+{
+	struct rte_rib *rib = NULL;
+	struct rte_rib_conf config;
+
+	config.max_nodes = MAX_RULES;
+	config.ext_sz = 0;
+
+	/* rte_rib_create: rib name == NULL */
+	rib = rte_rib_create(NULL, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(rib == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	/* rte_rib_create: config == NULL */
+	rib = rte_rib_create(__func__, SOCKET_ID_ANY, NULL);
+	RTE_TEST_ASSERT(rib == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	/* socket_id < -1 is invalid */
+	rib = rte_rib_create(__func__, -2, &config);
+	RTE_TEST_ASSERT(rib == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	/* rte_rib_create: max_nodes = 0 */
+	config.max_nodes = 0;
+	rib = rte_rib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(rib == NULL,
+		"Call succeeded with invalid parameters\n");
+	config.max_nodes = MAX_RULES;
+
+	return TEST_SUCCESS;
+}
+
+/*
+ * Create rib table then delete rib table 10 times
+ * Use a slightly different rules size each time
+ */
+int32_t
+test_multiple_create(void)
+{
+	struct rte_rib *rib = NULL;
+	struct rte_rib_conf config;
+	int32_t i;
+
+	config.ext_sz = 0;
+
+	for (i = 0; i < 10; i++) {
+		config.max_nodes = MAX_RULES - i;
+		rib = rte_rib_create(__func__, SOCKET_ID_ANY, &config);
+		RTE_TEST_ASSERT(rib != NULL, "Failed to create RIB\n");
+		rte_rib_free(rib);
+	}
+	/* Can not test free so return success */
+	return TEST_SUCCESS;
+}
+
+/*
+ * Call rte_rib_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_rib *rib = NULL;
+	struct rte_rib_conf config;
+
+	config.max_nodes = MAX_RULES;
+	config.ext_sz = 0;
+
+	rib = rte_rib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(rib != NULL, "Failed to create RIB\n");
+
+	rte_rib_free(rib);
+	rte_rib_free(NULL);
+	return TEST_SUCCESS;
+}
+
+/*
+ * Check that rte_rib_insert fails gracefully for incorrect user input arguments
+ */
+int32_t
+test_insert_invalid(void)
+{
+	struct rte_rib *rib = NULL;
+	struct rte_rib_node *node, *node1;
+	struct rte_rib_conf config;
+	uint32_t ip = RTE_IPV4(0, 0, 0, 0);
+	uint8_t depth = 24;
+
+	config.max_nodes = MAX_RULES;
+	config.ext_sz = 0;
+
+	/* rte_rib_insert: rib == NULL */
+	node = rte_rib_insert(NULL, ip, depth);
+	RTE_TEST_ASSERT(node == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	/*Create valid rib to use in rest of test. */
+	rib = rte_rib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(rib != NULL, "Failed to create RIB\n");
+
+	/* rte_rib_insert: depth > MAX_DEPTH */
+	node = rte_rib_insert(rib, ip, MAX_DEPTH + 1);
+	RTE_TEST_ASSERT(node == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	/* insert the same ip/depth twice*/
+	node = rte_rib_insert(rib, ip, depth);
+	RTE_TEST_ASSERT(node != NULL, "Failed to insert rule\n");
+	node1 = rte_rib_insert(rib, ip, depth);
+	RTE_TEST_ASSERT(node1 == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	rte_rib_free(rib);
+
+	return TEST_SUCCESS;
+}
+
+/*
+ * Call rte_rib_node access functions with incorrect input.
+ * After call rte_rib_node access functions with correct args
+ * and check the return values for correctness
+ */
+int32_t
+test_get_fn(void)
+{
+	struct rte_rib *rib = NULL;
+	struct rte_rib_node *node;
+	struct rte_rib_conf config;
+	void *ext;
+	uint32_t ip = RTE_IPV4(192, 0, 2, 0);
+	uint32_t ip_ret;
+	uint64_t nh_set = 10;
+	uint64_t nh_ret;
+	uint8_t depth = 24;
+	uint8_t depth_ret;
+	int ret;
+
+	config.max_nodes = MAX_RULES;
+	config.ext_sz = 0;
+
+	rib = rte_rib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(rib != NULL, "Failed to create RIB\n");
+
+	node = rte_rib_insert(rib, ip, depth);
+	RTE_TEST_ASSERT(node != NULL, "Failed to insert rule\n");
+
+	/* test rte_rib_get_ip() with incorrect args */
+	ret = rte_rib_get_ip(NULL, &ip_ret);
+	RTE_TEST_ASSERT(ret < 0,
+		"Call succeeded with invalid parameters\n");
+	ret = rte_rib_get_ip(node, NULL);
+	RTE_TEST_ASSERT(ret < 0,
+		"Call succeeded with invalid parameters\n");
+
+	/* test rte_rib_get_depth() with incorrect args */
+	ret = rte_rib_get_depth(NULL, &depth_ret);
+	RTE_TEST_ASSERT(ret < 0,
+		"Call succeeded with invalid parameters\n");
+	ret = rte_rib_get_depth(node, NULL);
+	RTE_TEST_ASSERT(ret < 0,
+		"Call succeeded with invalid parameters\n");
+
+	/* test rte_rib_set_nh() with incorrect args */
+	ret = rte_rib_set_nh(NULL, nh_set);
+	RTE_TEST_ASSERT(ret < 0,
+		"Call succeeded with invalid parameters\n");
+
+	/* test rte_rib_get_nh() with incorrect args */
+	ret = rte_rib_get_nh(NULL, &nh_ret);
+	RTE_TEST_ASSERT(ret < 0,
+		"Call succeeded with invalid parameters\n");
+	ret = rte_rib_get_nh(node, NULL);
+	RTE_TEST_ASSERT(ret < 0,
+		"Call succeeded with invalid parameters\n");
+
+	/* test rte_rib_get_ext() with incorrect args */
+	ext = rte_rib_get_ext(NULL);
+	RTE_TEST_ASSERT(ext == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	/* check the return values */
+	ret = rte_rib_get_ip(node, &ip_ret);
+	RTE_TEST_ASSERT((ret == 0) && (ip_ret == ip),
+		"Failed to get proper node ip\n");
+	ret = rte_rib_get_depth(node, &depth_ret);
+	RTE_TEST_ASSERT((ret == 0) && (depth_ret == depth),
+		"Failed to get proper node depth\n");
+	ret = rte_rib_set_nh(node, nh_set);
+	RTE_TEST_ASSERT(ret == 0,
+		"Failed to set rte_rib_node nexthop\n");
+	ret = rte_rib_get_nh(node, &nh_ret);
+	RTE_TEST_ASSERT((ret == 0) && (nh_ret == nh_set),
+		"Failed to get proper nexthop\n");
+
+	rte_rib_free(rib);
+
+	return TEST_SUCCESS;
+}
+
+/*
+ * Call insert, lookup/lookup_exact and delete for a single rule
+ */
+int32_t
+test_basic(void)
+{
+	struct rte_rib *rib = NULL;
+	struct rte_rib_node *node;
+	struct rte_rib_conf config;
+
+	uint32_t ip = RTE_IPV4(192, 0, 2, 0);
+	uint64_t next_hop_add = 10;
+	uint64_t next_hop_return;
+	uint8_t depth = 24;
+	int ret;
+
+	config.max_nodes = MAX_RULES;
+	config.ext_sz = 0;
+
+	rib = rte_rib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(rib != NULL, "Failed to create RIB\n");
+
+	node = rte_rib_insert(rib, ip, depth);
+	RTE_TEST_ASSERT(node != NULL, "Failed to insert rule\n");
+
+	ret = rte_rib_set_nh(node, next_hop_add);
+	RTE_TEST_ASSERT(ret == 0,
+		"Failed to set rte_rib_node field\n");
+
+	node = rte_rib_lookup(rib, ip);
+	RTE_TEST_ASSERT(node != NULL, "Failed to lookup\n");
+
+	ret = rte_rib_get_nh(node, &next_hop_return);
+	RTE_TEST_ASSERT((ret == 0) && (next_hop_add == next_hop_return),
+		"Failed to get proper nexthop\n");
+
+	node = rte_rib_lookup_exact(rib, ip, depth);
+	RTE_TEST_ASSERT(node != NULL,
+		"Failed to lookup\n");
+
+	ret = rte_rib_get_nh(node, &next_hop_return);
+	RTE_TEST_ASSERT((ret == 0) && (next_hop_add == next_hop_return),
+		"Failed to get proper nexthop\n");
+
+	rte_rib_remove(rib, ip, depth);
+
+	node = rte_rib_lookup(rib, ip);
+	RTE_TEST_ASSERT(node == NULL,
+		"Lookup returns non existent rule\n");
+	node = rte_rib_lookup_exact(rib, ip, depth);
+	RTE_TEST_ASSERT(node == NULL,
+		"Lookup returns non existent rule\n");
+
+	rte_rib_free(rib);
+
+	return TEST_SUCCESS;
+}
+
+int32_t
+test_tree_traversal(void)
+{
+	struct rte_rib *rib = NULL;
+	struct rte_rib_node *node;
+	struct rte_rib_conf config;
+
+	uint32_t ip1 = RTE_IPV4(10, 10, 10, 0);
+	uint32_t ip2 = RTE_IPV4(10, 10, 130, 80);
+	uint8_t depth = 30;
+
+	config.max_nodes = MAX_RULES;
+	config.ext_sz = 0;
+
+	rib = rte_rib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(rib != NULL, "Failed to create RIB\n");
+
+	node = rte_rib_insert(rib, ip1, depth);
+	RTE_TEST_ASSERT(node != NULL, "Failed to insert rule\n");
+
+	node = rte_rib_insert(rib, ip2, depth);
+	RTE_TEST_ASSERT(node != NULL, "Failed to insert rule\n");
+
+	node = NULL;
+	node = rte_rib_get_nxt(rib, RTE_IPV4(10, 10, 130, 0), 24, node,
+			RTE_RIB_GET_NXT_ALL);
+	RTE_TEST_ASSERT(node != NULL, "Failed to get rib_node\n");
+
+	rte_rib_free(rib);
+
+	return TEST_SUCCESS;
+}
+
+static struct unit_test_suite rib_tests = {
+	.suite_name = "rib autotest",
+	.setup = NULL,
+	.teardown = NULL,
+	.unit_test_cases = {
+		TEST_CASE(test_create_invalid),
+		TEST_CASE(test_multiple_create),
+		TEST_CASE(test_free_null),
+		TEST_CASE(test_insert_invalid),
+		TEST_CASE(test_get_fn),
+		TEST_CASE(test_basic),
+		TEST_CASE(test_tree_traversal),
+		TEST_CASES_END()
+	}
+};
+
+/*
+ * Do all unit tests.
+ */
+static int
+test_rib(void)
+{
+	return unit_test_suite_runner(&rib_tests);
+}
+
+REGISTER_TEST_COMMAND(rib_autotest, test_rib);
-- 
2.7.4


  parent reply index

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-26 22:03 [dpdk-dev] [PATCH v4 0/4] lib/rib: Add Routing Information Base library Medvedkin Vladimir
2018-04-26 22:03 ` [dpdk-dev] [PATCH v4 1/4] Add RIB library Medvedkin Vladimir
2018-04-26 22:17   ` Stephen Hemminger
2018-04-26 22:18   ` Stephen Hemminger
2018-04-26 22:19   ` Stephen Hemminger
2018-04-26 22:19   ` Stephen Hemminger
2018-04-26 22:20   ` Stephen Hemminger
2018-04-27  6:45     ` Vladimir Medvedkin
2018-06-29 13:54   ` Bruce Richardson
2018-06-29 14:02   ` Bruce Richardson
2018-04-26 22:03 ` [dpdk-dev] [PATCH v4 2/4] Add dir24_8 implementation for rib library Medvedkin Vladimir
2018-04-26 22:03 ` [dpdk-dev] [PATCH v4 3/4] Add autotests for RIB library Medvedkin Vladimir
2018-06-29 14:13   ` Bruce Richardson
2018-06-29 15:07   ` Bruce Richardson
2018-06-29 15:31   ` Bruce Richardson
2018-04-26 22:03 ` [dpdk-dev] [PATCH v4 4/4] Add support for lpm and rib bulk lookup Medvedkin Vladimir
2018-04-26 22:24 ` [dpdk-dev] [PATCH v4 0/4] lib/rib: Add Routing Information Base library Stephen Hemminger
2018-04-26 22:27   ` Thomas Monjalon
2018-04-26 22:42     ` Stephen Hemminger
2018-04-26 22:49     ` Stephen Hemminger
2018-04-27  8:27   ` Vladimir Medvedkin
2018-06-29 15:48 ` Bruce Richardson
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 00/12] lib: add RIB and FIB liraries Vladimir Medvedkin
2019-09-12  7:37   ` Morten Brørup
2019-09-12  9:47     ` Medvedkin, Vladimir
2019-09-12 12:00       ` Morten Brørup
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 " Vladimir Medvedkin
2019-11-05 23:14     ` Thomas Monjalon
2019-11-06  5:50       ` David Marchand
2019-11-06  7:50         ` Thomas Monjalon
2019-11-06 11:53           ` Medvedkin, Vladimir
2019-11-06 11:59             ` Thomas Monjalon
2019-11-06 14:37               ` Aaron Conole
2019-11-06 11:50         ` Medvedkin, Vladimir
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 01/12] rib: add RIB library Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 02/12] test/rib: add RIB library autotests Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 03/12] rib: add ipv6 support for RIB Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 04/12] test/rib: add ipv6 support for RIB autotests Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 05/12] fib: add FIB library Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 06/12] fib: add FIB ipv6 support Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 07/12] fib: add DIR24-8 dataplane algorithm Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 08/12] fib: add dataplane algorithm for ipv6 Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 09/12] test/fib: add FIB library autotests Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 10/12] test/fib: add ipv6 support for FIB autotests Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 11/12] test/fib: add FIB library performance autotests Vladimir Medvedkin
2019-11-01 15:21   ` [dpdk-dev] [PATCH v6 12/12] test/fib: add FIB library ipv6 " Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 01/12] rib: add RIB library Vladimir Medvedkin
2019-09-11 17:09 ` Vladimir Medvedkin [this message]
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 03/12] rib: add ipv6 support for RIB Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 04/12] test/rib: add ipv6 support for RIB autotests Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 05/12] fib: add FIB library Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 06/12] fib: add FIB ipv6 support Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 07/12] fib: add DIR24-8 dataplane algorithm Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 08/12] fib: add dataplane algorithm for ipv6 Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 09/12] test/fib: add FIB library autotests Vladimir Medvedkin
2019-09-12 14:07   ` Aaron Conole
2019-10-01 17:12     ` Medvedkin, Vladimir
2019-10-24 15:55       ` Thomas Monjalon
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 10/12] test/fib: add ipv6 support for FIB autotests Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 11/12] test/fib: add FIB library performance autotests Vladimir Medvedkin
2019-09-11 17:09 ` [dpdk-dev] [PATCH v5 12/12] test/fib: add FIB library ipv6 " Vladimir Medvedkin

Reply instructions:

You may reply publically 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=8b829507599c5a814d4325c658133fdff84d4cd9.1568221363.git.vladimir.medvedkin@intel.com \
    --to=vladimir.medvedkin@intel.com \
    --cc=bruce.richardson@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

DPDK patches and discussions

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ http://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox