[v5,09/12] test/fib: add FIB library autotests

Message ID 1b5d91331ed1ea35acf2d50461c813e06fe9e683.1568221364.git.vladimir.medvedkin@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series lib: add RIB and FIB liraries |

Checks

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

Commit Message

Vladimir Medvedkin Sept. 11, 2019, 5:09 p.m. UTC
  Functional tests for the new FIB library.

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

Comments

Aaron Conole Sept. 12, 2019, 2:07 p.m. UTC | #1
Vladimir Medvedkin <vladimir.medvedkin@intel.com> writes:

> Functional tests for the new FIB library.
>
> Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
> ---
>  app/test/Makefile         |   1 +
>  app/test/autotest_data.py |   6 +
>  app/test/meson.build      |   3 +
>  app/test/test_fib.c       | 397 ++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 407 insertions(+)
>  create mode 100644 app/test/test_fib.c
>

Thanks so much for adding tests with your library.

Please note that even after 30s, these tests don't complete:

  https://travis-ci.com/ovsrobot/dpdk/jobs/234132379

Can you restrict some of your lpm test vectors rather than looping
through all of combinations?  Or perhaps take the long poll tests and
move them into a perf test?
  
Vladimir Medvedkin Oct. 1, 2019, 5:12 p.m. UTC | #2
Hi Aaron,

On 12/09/2019 15:07, Aaron Conole wrote:
> Vladimir Medvedkin <vladimir.medvedkin@intel.com> writes:
>
>> Functional tests for the new FIB library.
>>
>> Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
>> ---
>>   app/test/Makefile         |   1 +
>>   app/test/autotest_data.py |   6 +
>>   app/test/meson.build      |   3 +
>>   app/test/test_fib.c       | 397 ++++++++++++++++++++++++++++++++++++++++++++++
>>   4 files changed, 407 insertions(+)
>>   create mode 100644 app/test/test_fib.c
>>
> Thanks so much for adding tests with your library.
>
> Please note that even after 30s, these tests don't complete:
>
>    https://travis-ci.com/ovsrobot/dpdk/jobs/234132379
>
> Can you restrict some of your lpm test vectors rather than looping
> through all of combinations?  Or perhaps take the long poll tests and
> move them into a perf test?

Sorry for the late reply. I'll try to make it work faster :)
  
Thomas Monjalon Oct. 24, 2019, 3:55 p.m. UTC | #3
01/10/2019 19:12, Medvedkin, Vladimir:
> On 12/09/2019 15:07, Aaron Conole wrote:
> > Vladimir Medvedkin <vladimir.medvedkin@intel.com> writes:
> >
> >> Functional tests for the new FIB library.
> >>
> >> Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
> >> ---
> >>   app/test/Makefile         |   1 +
> >>   app/test/autotest_data.py |   6 +
> >>   app/test/meson.build      |   3 +
> >>   app/test/test_fib.c       | 397 ++++++++++++++++++++++++++++++++++++++++++++++
> >>   4 files changed, 407 insertions(+)
> >>   create mode 100644 app/test/test_fib.c
> >>
> > Thanks so much for adding tests with your library.
> >
> > Please note that even after 30s, these tests don't complete:
> >
> >    https://travis-ci.com/ovsrobot/dpdk/jobs/234132379
> >
> > Can you restrict some of your lpm test vectors rather than looping
> > through all of combinations?  Or perhaps take the long poll tests and
> > move them into a perf test?
> 
> Sorry for the late reply. I'll try to make it work faster :)

Because of the test duration, this series is waiting for a v6.
I hope we could merge it in 19.11-rc2.
  

Patch

diff --git a/app/test/Makefile b/app/test/Makefile
index 4638426..b67ca16 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -126,6 +126,7 @@  SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_readwrite_lf.c
 
 SRCS-$(CONFIG_RTE_LIBRTE_RIB) += test_rib.c
 SRCS-$(CONFIG_RTE_LIBRTE_RIB) += test_rib6.c
+SRCS-$(CONFIG_RTE_LIBRTE_FIB) += test_fib.c
 
 SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm.c
 SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm_perf.c
diff --git a/app/test/autotest_data.py b/app/test/autotest_data.py
index f35b3cc..e736c03 100644
--- a/app/test/autotest_data.py
+++ b/app/test/autotest_data.py
@@ -123,6 +123,12 @@ 
         "Report":  None,
     },
     {
+        "Name":    "FIB autotest",
+        "Command": "fib_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 49c1de0..9f1895d 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -47,6 +47,7 @@  test_sources = files('commands.c',
 	'test_eventdev.c',
 	'test_external_mem.c',
 	'test_fbarray.c',
+	'test_fib.c',
 	'test_func_reentrancy.c',
 	'test_flow_classify.c',
 	'test_hash.c',
@@ -137,6 +138,7 @@  test_deps = ['acl',
 	'efd',
 	'ethdev',
 	'eventdev',
+	'fib',
 	'flow_classify',
 	'hash',
 	'ipsec',
@@ -180,6 +182,7 @@  fast_test_names = [
         'eal_fs_autotest',
         'errno_autotest',
         'event_ring_autotest',
+        'fib_autotest',
         'func_reentrancy_autotest',
         'flow_classify_autotest',
         'hash_autotest',
diff --git a/app/test/test_fib.c b/app/test/test_fib.c
new file mode 100644
index 0000000..c676a68
--- /dev/null
+++ b/app/test/test_fib.c
@@ -0,0 +1,397 @@ 
+/* 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_log.h>
+#include <rte_fib.h>
+
+#include "test.h"
+
+typedef int32_t (*rte_fib_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_get_invalid(void);
+static int32_t test_lookup(void);
+
+#define MAX_ROUTES (1 << 22)
+
+/*
+ * Check that rte_fib_create fails gracefully for incorrect user input
+ * arguments
+ */
+int32_t
+test_create_invalid(void)
+{
+	struct rte_fib *fib = NULL;
+	struct rte_fib_conf config;
+
+	config.max_routes = MAX_ROUTES;
+	config.default_nh = 0;
+	config.type = RTE_FIB_DUMMY;
+
+	/* rte_fib_create: fib name == NULL */
+	fib = rte_fib_create(NULL, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	/* rte_fib_create: config == NULL */
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, NULL);
+	RTE_TEST_ASSERT(fib == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	/* socket_id < -1 is invalid */
+	fib = rte_fib_create(__func__, -2, &config);
+	RTE_TEST_ASSERT(fib == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	/* rte_fib_create: max_routes = 0 */
+	config.max_routes = 0;
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib == NULL,
+		"Call succeeded with invalid parameters\n");
+	config.max_routes = MAX_ROUTES;
+
+	config.type = RTE_FIB_TYPE_MAX;
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	config.type = RTE_FIB_DIR24_8;
+	config.dir24_8.num_tbl8 = 100000;
+
+	config.dir24_8.nh_sz = RTE_FIB_DIR24_8_8B + 1;
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib == NULL,
+		"Call succeeded with invalid parameters\n");
+	config.dir24_8.nh_sz = RTE_FIB_DIR24_8_8B;
+
+	config.dir24_8.num_tbl8 = 0;
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	return TEST_SUCCESS;
+}
+
+/*
+ * Create fib table then delete fib table 10 times
+ * Use a slightly different rules size each time
+ */
+int32_t
+test_multiple_create(void)
+{
+	struct rte_fib *fib = NULL;
+	struct rte_fib_conf config;
+	int32_t i;
+
+	config.default_nh = 0;
+	config.type = RTE_FIB_DUMMY;
+
+	for (i = 0; i < 5; i++) {
+		config.max_routes = MAX_ROUTES - i;
+		fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+		RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
+		rte_fib_free(fib);
+	}
+	/* Can not test free so return success */
+	return TEST_SUCCESS;
+}
+
+/*
+ * Call rte_fib_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_fib *fib = NULL;
+	struct rte_fib_conf config;
+
+	config.max_routes = MAX_ROUTES;
+	config.default_nh = 0;
+	config.type = RTE_FIB_DUMMY;
+
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
+
+	rte_fib_free(fib);
+	rte_fib_free(NULL);
+	return TEST_SUCCESS;
+}
+
+/*
+ * Check that rte_fib_add and rte_fib_delete fails gracefully
+ * for incorrect user input arguments
+ */
+int32_t
+test_add_del_invalid(void)
+{
+	struct rte_fib *fib = NULL;
+	struct rte_fib_conf config;
+	uint64_t nh = 100;
+	uint32_t ip = RTE_IPV4(0, 0, 0, 0);
+	int ret;
+	uint8_t depth = 24;
+
+	config.max_routes = MAX_ROUTES;
+	config.default_nh = 0;
+	config.type = RTE_FIB_DUMMY;
+
+	/* rte_fib_add: fib == NULL */
+	ret = rte_fib_add(NULL, ip, depth, nh);
+	RTE_TEST_ASSERT(ret < 0,
+		"Call succeeded with invalid parameters\n");
+
+	/* rte_fib_delete: fib == NULL */
+	ret = rte_fib_delete(NULL, ip, depth);
+	RTE_TEST_ASSERT(ret < 0,
+		"Call succeeded with invalid parameters\n");
+
+	/*Create valid fib to use in rest of test. */
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
+
+	/* rte_fib_add: depth > RTE_FIB_MAXDEPTH */
+	ret = rte_fib_add(fib, ip, RTE_FIB_MAXDEPTH + 1, nh);
+	RTE_TEST_ASSERT(ret < 0,
+		"Call succeeded with invalid parameters\n");
+
+	/* rte_fib_delete: depth > RTE_FIB_MAXDEPTH */
+	ret = rte_fib_delete(fib, ip, RTE_FIB_MAXDEPTH + 1);
+	RTE_TEST_ASSERT(ret < 0,
+		"Call succeeded with invalid parameters\n");
+
+	rte_fib_free(fib);
+
+	return TEST_SUCCESS;
+}
+
+/*
+ * Check that rte_fib_get_dp and rte_fib_get_rib fails gracefully
+ * for incorrect user input arguments
+ */
+int32_t
+test_get_invalid(void)
+{
+	void *p;
+
+	p = rte_fib_get_dp(NULL);
+	RTE_TEST_ASSERT(p == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	p = rte_fib_get_rib(NULL);
+	RTE_TEST_ASSERT(p == NULL,
+		"Call succeeded with invalid parameters\n");
+
+	return TEST_SUCCESS;
+}
+
+/*
+ * Add routes for one supernet with all possible depths and do lookup
+ * on each step
+ * After delete routes with doing lookup on each step
+ */
+static int
+lookup_and_check_asc(struct rte_fib *fib, uint32_t ip_arr[RTE_FIB_MAXDEPTH],
+	uint32_t ip_missing, uint64_t def_nh, uint32_t n)
+{
+	uint64_t nh_arr[RTE_FIB_MAXDEPTH];
+	int ret;
+	uint32_t i = 0;
+
+	ret = rte_fib_lookup_bulk(fib, ip_arr, nh_arr, RTE_FIB_MAXDEPTH);
+	RTE_TEST_ASSERT(ret == 0, "Failed to lookup\n");
+
+	for (; i <= RTE_FIB_MAXDEPTH - n; i++)
+		RTE_TEST_ASSERT(nh_arr[i] == n,
+			"Failed to get proper nexthop\n");
+
+	for (; i < RTE_FIB_MAXDEPTH; i++)
+		RTE_TEST_ASSERT(nh_arr[i] == --n,
+			"Failed to get proper nexthop\n");
+
+	ret = rte_fib_lookup_bulk(fib, &ip_missing, nh_arr, 1);
+	RTE_TEST_ASSERT((ret == 0) && (nh_arr[0] == def_nh),
+		"Failed to get proper nexthop\n");
+
+	return TEST_SUCCESS;
+}
+
+static int
+lookup_and_check_desc(struct rte_fib *fib, uint32_t ip_arr[RTE_FIB_MAXDEPTH],
+	uint32_t ip_missing, uint64_t def_nh, uint32_t n)
+{
+	uint64_t nh_arr[RTE_FIB_MAXDEPTH];
+	int ret;
+	uint32_t i = 0;
+
+	ret = rte_fib_lookup_bulk(fib, ip_arr, nh_arr, RTE_FIB_MAXDEPTH);
+	RTE_TEST_ASSERT(ret == 0, "Failed to lookup\n");
+
+	for (; i < n; i++)
+		RTE_TEST_ASSERT(nh_arr[i] == RTE_FIB_MAXDEPTH - i,
+			"Failed to get proper nexthop\n");
+
+	for (; i < RTE_FIB_MAXDEPTH; i++)
+		RTE_TEST_ASSERT(nh_arr[i] == def_nh,
+			"Failed to get proper nexthop\n");
+
+	ret = rte_fib_lookup_bulk(fib, &ip_missing, nh_arr, 1);
+	RTE_TEST_ASSERT((ret == 0) && (nh_arr[0] == def_nh),
+		"Failed to get proper nexthop\n");
+
+	return TEST_SUCCESS;
+}
+
+static int
+check_fib(struct rte_fib *fib)
+{
+	uint64_t def_nh = 100;
+	uint32_t ip_arr[RTE_FIB_MAXDEPTH];
+	uint32_t ip_add = RTE_IPV4(128, 0, 0, 0);
+	uint32_t i, ip_missing = RTE_IPV4(127, 255, 255, 255);
+	int ret;
+
+	for (i = 0; i < RTE_FIB_MAXDEPTH; i++)
+		ip_arr[i] = ip_add + (1ULL << i) - 1;
+
+	ret = lookup_and_check_desc(fib, ip_arr, ip_missing, def_nh, 0);
+	RTE_TEST_ASSERT(ret == TEST_SUCCESS, "Lookup and check fails\n");
+
+	for (i = 1; i <= RTE_FIB_MAXDEPTH; i++) {
+		ret = rte_fib_add(fib, ip_add, i, i);
+		RTE_TEST_ASSERT(ret == 0, "Failed to add a route\n");
+		ret = lookup_and_check_asc(fib, ip_arr, ip_missing,
+				def_nh, i);
+		RTE_TEST_ASSERT(ret == TEST_SUCCESS, "Lookup and check fails\n");
+	}
+
+	for (i = RTE_FIB_MAXDEPTH; i > 1; i--) {
+		ret = rte_fib_delete(fib, ip_add, i);
+		RTE_TEST_ASSERT(ret == 0, "Failed to delete a route\n");
+		ret = lookup_and_check_asc(fib, ip_arr, ip_missing,
+			def_nh, i - 1);
+
+		RTE_TEST_ASSERT(ret == TEST_SUCCESS, "Lookup and check fails\n");
+	}
+	ret = rte_fib_delete(fib, ip_add, i);
+	RTE_TEST_ASSERT(ret == 0, "Failed to delete a route\n");
+	ret = lookup_and_check_desc(fib, ip_arr, ip_missing, def_nh, 0);
+	RTE_TEST_ASSERT(ret == TEST_SUCCESS, "Lookup and check fails\n");
+
+	for (i = 0; i < RTE_FIB_MAXDEPTH; i++) {
+		ret = rte_fib_add(fib, ip_add, RTE_FIB_MAXDEPTH - i,
+			RTE_FIB_MAXDEPTH - i);
+		RTE_TEST_ASSERT(ret == 0, "Failed to add a route\n");
+		ret = lookup_and_check_desc(fib, ip_arr, ip_missing,
+			def_nh, i + 1);
+		RTE_TEST_ASSERT(ret == TEST_SUCCESS, "Lookup and check fails\n");
+	}
+
+	for (i = 1; i <= RTE_FIB_MAXDEPTH; i++) {
+		ret = rte_fib_delete(fib, ip_add, i);
+		RTE_TEST_ASSERT(ret == 0, "Failed to delete a route\n");
+		ret = lookup_and_check_desc(fib, ip_arr, ip_missing, def_nh,
+			RTE_FIB_MAXDEPTH - i);
+		RTE_TEST_ASSERT(ret == TEST_SUCCESS, "Lookup and check fails\n");
+	}
+
+	return TEST_SUCCESS;
+}
+
+int32_t
+test_lookup(void)
+{
+	struct rte_fib *fib = NULL;
+	struct rte_fib_conf config;
+	uint64_t def_nh = 100;
+	int ret;
+
+	config.max_routes = MAX_ROUTES;
+	config.default_nh = def_nh;
+	config.type = RTE_FIB_DUMMY;
+
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
+	ret = check_fib(fib);
+	RTE_TEST_ASSERT(ret == TEST_SUCCESS,
+		"Check_fib fails for DUMMY type\n");
+	rte_fib_free(fib);
+
+	config.type = RTE_FIB_DIR24_8;
+
+	config.dir24_8.nh_sz = RTE_FIB_DIR24_8_1B;
+	config.dir24_8.num_tbl8 = 127;
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
+	ret = check_fib(fib);
+	RTE_TEST_ASSERT(ret == TEST_SUCCESS,
+		"Check_fib fails for DIR24_8_1B type\n");
+	rte_fib_free(fib);
+
+	config.dir24_8.nh_sz = RTE_FIB_DIR24_8_2B;
+	config.dir24_8.num_tbl8 = 32767;
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
+	ret = check_fib(fib);
+	RTE_TEST_ASSERT(ret == TEST_SUCCESS,
+		"Check_fib fails for DIR24_8_2B type\n");
+	rte_fib_free(fib);
+
+	config.dir24_8.nh_sz = RTE_FIB_DIR24_8_4B;
+	config.dir24_8.num_tbl8 = 100000;
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
+	ret = check_fib(fib);
+	RTE_TEST_ASSERT(ret == TEST_SUCCESS,
+		"Check_fib fails for DIR24_8_4B type\n");
+	rte_fib_free(fib);
+
+	config.dir24_8.nh_sz = RTE_FIB_DIR24_8_8B;
+	config.dir24_8.num_tbl8 = 100000;
+	fib = rte_fib_create(__func__, SOCKET_ID_ANY, &config);
+	RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
+	ret = check_fib(fib);
+	RTE_TEST_ASSERT(ret == TEST_SUCCESS,
+		"Check_fib fails for DIR24_8_8B type\n");
+	rte_fib_free(fib);
+
+	return TEST_SUCCESS;
+}
+
+static struct unit_test_suite fib_tests = {
+	.suite_name = "fib 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_add_del_invalid),
+	TEST_CASE(test_get_invalid),
+	TEST_CASE(test_lookup),
+	TEST_CASES_END()
+	}
+};
+
+/*
+ * Do all unit tests.
+ */
+static int
+test_fib(void)
+{
+	return unit_test_suite_runner(&fib_tests);
+}
+
+REGISTER_TEST_COMMAND(fib_autotest, test_fib);