diff mbox series

[v3,7/8] test/emudev: introduce functional test

Message ID 20210114062512.45462-8-chenbo.xia@intel.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers show
Series Introduce emudev library and iavf emudev driver | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Xia, Chenbo Jan. 14, 2021, 6:25 a.m. UTC
This patch introduces functional test for emudev. The
implementation of iavf emudev selftest is also added.

Signed-off-by: Miao Li <miao.li@intel.com>
Signed-off-by: Chenbo Xia <chenbo.xia@intel.com>
---
 app/test/meson.build                 |   5 +-
 app/test/test_emudev.c               |  29 +++++
 drivers/emu/iavf/iavf_emu.c          |   1 +
 drivers/emu/iavf/iavf_emu_internal.h |   1 +
 drivers/emu/iavf/iavf_emu_test.c     | 174 +++++++++++++++++++++++++++
 drivers/emu/iavf/meson.build         |   2 +-
 6 files changed, 210 insertions(+), 2 deletions(-)
 create mode 100644 app/test/test_emudev.c
 create mode 100644 drivers/emu/iavf/iavf_emu_test.c
diff mbox series

Patch

diff --git a/app/test/meson.build b/app/test/meson.build
index f5b15ac44c..b8b79bbc8b 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -139,6 +139,7 @@  test_sources = files('commands.c',
 	'test_trace_register.c',
 	'test_trace_perf.c',
 	'test_vfio_user.c',
+	'test_emudev.c',
 	'test_version.c',
 	'virtual_pmd.c'
 )
@@ -176,7 +177,8 @@  test_deps = ['acl',
 	'stack',
 	'vfio_user',
 	'telemetry',
-	'timer'
+	'timer',
+	'emudev'
 ]
 
 # Each test is marked with flag true/false
@@ -327,6 +329,7 @@  driver_test_names = [
         'eventdev_selftest_octeontx',
         'eventdev_selftest_sw',
         'rawdev_autotest',
+        'emudev_autotest',
 ]
 
 dump_test_names = [
diff --git a/app/test/test_emudev.c b/app/test/test_emudev.c
new file mode 100644
index 0000000000..0dfce162ed
--- /dev/null
+++ b/app/test/test_emudev.c
@@ -0,0 +1,29 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2020 Intel Corporation
+ */
+
+#include <rte_emudev.h>
+#include <rte_bus_vdev.h>
+
+#include "test.h"
+
+static int
+test_emudev_selftest_impl(const char *pmd, const char *opts)
+{
+	int ret = 0;
+
+	if (rte_emudev_get_dev_id(pmd) == -ENODEV)
+		ret = rte_vdev_init(pmd, opts);
+	if (ret)
+		return TEST_SKIPPED;
+
+	return rte_emudev_selftest(rte_emudev_get_dev_id(pmd));
+}
+
+static int
+test_emudev_selftest(void)
+{
+	return test_emudev_selftest_impl("emu_iavf", "sock=/tmp/sock1");
+}
+
+REGISTER_TEST_COMMAND(emudev_autotest, test_emudev_selftest);
diff --git a/drivers/emu/iavf/iavf_emu.c b/drivers/emu/iavf/iavf_emu.c
index cc56ec1c4b..8439677b65 100644
--- a/drivers/emu/iavf/iavf_emu.c
+++ b/drivers/emu/iavf/iavf_emu.c
@@ -258,4 +258,5 @@  struct rte_emudev_ops emu_iavf_ops = {
 	.subscribe_event = iavf_emu_subs_ev,
 	.unsubscribe_event = iavf_emu_unsubs_ev,
 	.get_attr = iavf_emu_get_attr,
+	.dev_selftest = iavf_emu_selftest,
 };
diff --git a/drivers/emu/iavf/iavf_emu_internal.h b/drivers/emu/iavf/iavf_emu_internal.h
index 10197c00ba..1ac7f96566 100644
--- a/drivers/emu/iavf/iavf_emu_internal.h
+++ b/drivers/emu/iavf/iavf_emu_internal.h
@@ -65,4 +65,5 @@  struct iavf_emudev {
 };
 
 void iavf_emu_uninit_device(struct iavf_emudev *dev);
+int iavf_emu_selftest(uint16_t dev_id);
 #endif
diff --git a/drivers/emu/iavf/iavf_emu_test.c b/drivers/emu/iavf/iavf_emu_test.c
new file mode 100644
index 0000000000..22450c1970
--- /dev/null
+++ b/drivers/emu/iavf/iavf_emu_test.c
@@ -0,0 +1,174 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2020 Intel Corporation
+ */
+
+#include <inttypes.h>
+
+#include <rte_common.h>
+#include <rte_malloc.h>
+#include <rte_memcpy.h>
+#include <rte_dev.h>
+#include <rte_emudev.h>
+#include <rte_bus_vdev.h>
+#include <rte_test.h>
+
+#include "iavf_emu_internal.h"
+
+#define TEST_DEV_NAME "emu_iavf"
+#define TEST_SUCCESS 0
+#define TEST_FAILED -1
+
+#define EMUDEV_TEST_RUN(setup, teardown, test) \
+	emudev_test_run(setup, teardown, test, #test)
+static uint16_t test_dev_id;
+static int total;
+static int passed;
+static int failed;
+static int unsupported;
+
+static int
+testsuite_setup(void)
+{
+	uint8_t count;
+	count = rte_emudev_count();
+	if (!count) {
+		EMU_IAVF_LOG(INFO, "No existing emu dev; "
+				  "Creating emu_iavf\n");
+		return rte_vdev_init(TEST_DEV_NAME, NULL);
+	}
+
+	return TEST_SUCCESS;
+}
+
+static void
+testsuite_teardown(void)
+{
+	rte_vdev_uninit(TEST_DEV_NAME);
+}
+
+static void
+emudev_test_run(int (*setup)(void), void (*teardown)(void),
+		int (*test)(void), const char *name)
+{
+	int ret = 0;
+
+	if (setup) {
+		ret = setup();
+		if (ret < 0) {
+			EMU_IAVF_LOG(INFO, "Error setting up test %s\n", name);
+			unsupported++;
+		}
+	}
+
+	if (test) {
+		ret = test();
+		if (ret < 0) {
+			failed++;
+			EMU_IAVF_LOG(INFO, "%s Failed\n", name);
+		} else {
+			passed++;
+			EMU_IAVF_LOG(INFO, "%s Passed\n", name);
+		}
+	}
+
+	if (teardown)
+		teardown();
+
+	total++;
+}
+
+static int
+test_emu_dev_count(void)
+{
+	uint8_t count;
+	count = rte_emudev_count();
+	RTE_TEST_ASSERT(count > 0, "Invalid emudev count %" PRIu8, count);
+	return TEST_SUCCESS;
+}
+
+static int
+test_emu_dev_get_dev_id(void)
+{
+	int ret;
+	ret = rte_emudev_get_dev_id("Invalid_emu_dev_device\n");
+	RTE_TEST_ASSERT_FAIL(ret, "Expected <0 for invalid dev name, ret=%d",
+			     ret);
+	return TEST_SUCCESS;
+}
+
+static int
+test_emu_dev_configure(void)
+{
+	int ret;
+	struct rte_emudev_info dev_conf;
+	struct rte_iavf_emu_config iavf_conf_set = {.qp_num = 1};
+	struct rte_iavf_emu_config iavf_conf_get = {0};
+
+	rte_emudev_stop(test_dev_id);
+
+	/* Check invalid configuration */
+	ret = rte_emudev_configure(test_dev_id, NULL);
+	RTE_TEST_ASSERT(ret == -EINVAL,
+			"Null configure; Expected -EINVAL, got %d", ret);
+
+	/* Valid configuration test */
+	dev_conf.dev_priv = (rte_emudev_obj_t)&iavf_conf_get;
+	ret = rte_emudev_get_dev_info(test_dev_id, &dev_conf);
+	RTE_TEST_ASSERT_SUCCESS(ret,
+				"Failed to obtain emudev configuration (%d)",
+				ret);
+	dev_conf.dev_priv = (rte_emudev_obj_t)&iavf_conf_set;
+	ret = rte_emudev_configure(test_dev_id, &dev_conf);
+	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to configure emudev (%d)", ret);
+
+	memset(&iavf_conf_get, 0, sizeof(iavf_conf_get));
+	dev_conf.dev_priv = (rte_emudev_obj_t)&iavf_conf_get;
+	ret = rte_emudev_get_dev_info(test_dev_id, &dev_conf);
+	RTE_TEST_ASSERT_SUCCESS(ret,
+				"Failed to obtain emudev configuration (%d)",
+				ret);
+
+	RTE_TEST_ASSERT_EQUAL(iavf_conf_set.qp_num,
+			      iavf_conf_get.qp_num,
+			      "Configuration test failed; num_queues (%d)(%d)",
+			      iavf_conf_set.qp_num,
+			      iavf_conf_get.qp_num);
+
+	return TEST_SUCCESS;
+}
+
+static int
+test_emu_dev_start_stop(void)
+{
+	int ret;
+	ret = rte_emudev_start(test_dev_id);
+	RTE_TEST_ASSERT_SUCCESS(ret, "Failed to start emudev (%d)", ret);
+
+	rte_emudev_stop(test_dev_id);
+
+	return TEST_SUCCESS;
+}
+
+int
+iavf_emu_selftest(uint16_t dev_id)
+{
+	test_dev_id = dev_id;
+	testsuite_setup();
+
+	EMUDEV_TEST_RUN(NULL, NULL, test_emu_dev_count);
+	EMUDEV_TEST_RUN(NULL, NULL, test_emu_dev_get_dev_id);
+	EMUDEV_TEST_RUN(NULL, NULL, test_emu_dev_configure);
+	EMUDEV_TEST_RUN(NULL, NULL, test_emu_dev_start_stop);
+
+	testsuite_teardown();
+
+	EMU_IAVF_LOG(INFO, "Total tests   : %d\n", total);
+	EMU_IAVF_LOG(INFO, "Passed        : %d\n", passed);
+	EMU_IAVF_LOG(INFO, "Failed        : %d\n", failed);
+	EMU_IAVF_LOG(INFO, "Not supported : %d\n", unsupported);
+
+	if (failed)
+		return -1;
+
+	return 0;
+}
diff --git a/drivers/emu/iavf/meson.build b/drivers/emu/iavf/meson.build
index 3cab2226b7..613783e407 100644
--- a/drivers/emu/iavf/meson.build
+++ b/drivers/emu/iavf/meson.build
@@ -10,7 +10,7 @@  endif
 ext_deps += librt
 
 sources = files('iavf_emu.c', 'iavf_vfio_user.c',
-	'iavf_emudev.c')
+	'iavf_emu_test.c', 'iavf_emudev.c')
 
 deps += ['bus_vdev', 'emudev', 'vfio_user', 'common_iavf']