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 35889A04B5; Sat, 19 Dec 2020 07:45:41 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 09846CBDC; Sat, 19 Dec 2020 07:43:35 +0100 (CET) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 55B8ACBA9 for ; Sat, 19 Dec 2020 07:43:33 +0100 (CET) IronPort-SDR: 18fBoKVNLtJ1F5VogLh54X232Y6nEMyAeTRLPI5qwO7+OixaXB31PglGQu2S3ODGlivfWE2iR5 6jbHdZypJmeg== X-IronPort-AV: E=McAfee;i="6000,8403,9839"; a="163285200" X-IronPort-AV: E=Sophos;i="5.78,432,1599548400"; d="scan'208";a="163285200" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2020 22:43:32 -0800 IronPort-SDR: jgG0HKoa+xYrWlG3ug/0XhFjjo1EkZvqGWjav+79Bso1puTGTWqxDtkp4Ex/X4MSDw51tK+Rg/ 3hHkAcXu8oxg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,432,1599548400"; d="scan'208";a="454449638" Received: from npg-dpdk-virtio-xiachenbo-nw.sh.intel.com ([10.67.119.123]) by fmsmga001.fm.intel.com with ESMTP; 18 Dec 2020 22:43:30 -0800 From: Chenbo Xia To: dev@dpdk.org, thomas@monjalon.net, david.marchand@redhat.com Cc: stephen@networkplumber.org, cunming.liang@intel.com, xiuchun.lu@intel.com, miao.li@intel.com, jingjing.wu@intel.com Date: Sat, 19 Dec 2020 14:28:05 +0800 Message-Id: <20201219062806.56477-8-chenbo.xia@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201219062806.56477-1-chenbo.xia@intel.com> References: <20201218074736.93999-1-chenbo.xia@intel.com> <20201219062806.56477-1-chenbo.xia@intel.com> Subject: [dpdk-dev] [PATCH v2 7/8] test/emudev: introduce functional test 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" This patch introduces functional test for emudev. The implementation of iavf emudev selftest is also added. Signed-off-by: Miao Li Signed-off-by: Chenbo Xia --- 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 --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 +#include + +#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 9ad371ca98..88bf2bdf94 100644 --- a/drivers/emu/iavf/iavf_emu.c +++ b/drivers/emu/iavf/iavf_emu.c @@ -246,4 +246,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..ad19134724 --- /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 + +#include +#include +#include +#include +#include +#include +#include + +#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'] -- 2.17.1