From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 21527A0A02; Thu, 14 Jan 2021 07:31:20 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7FFE5140E5B; Thu, 14 Jan 2021 07:30:29 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id E4109140E4B for ; Thu, 14 Jan 2021 07:30:27 +0100 (CET) IronPort-SDR: aQMao5l8foWFmzz8jpAkuoe+zCaONKjiekWetaD1+442PkSUmim1+dSF17B29TGTEFXEhlAiBS EGA42+dwjvpg== X-IronPort-AV: E=McAfee;i="6000,8403,9863"; a="178407175" X-IronPort-AV: E=Sophos;i="5.79,346,1602572400"; d="scan'208";a="178407175" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2021 22:30:27 -0800 IronPort-SDR: cMQFuKq9FY31H5aLSCqaK4ReWLYrYqvFTw0K3qCkR98VmXUqlWcashJVIc7hj9SHmj8ZCdJ+G5 H9fR2Hj5tHVw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,346,1602572400"; d="scan'208";a="400799484" Received: from npg-dpdk-virtio-xiachenbo-nw.sh.intel.com ([10.67.119.123]) by fmsmga002.fm.intel.com with ESMTP; 13 Jan 2021 22:30:25 -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, beilei.xing@intel.com Date: Thu, 14 Jan 2021 14:25:11 +0800 Message-Id: <20210114062512.45462-8-chenbo.xia@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210114062512.45462-1-chenbo.xia@intel.com> References: <20201219062806.56477-1-chenbo.xia@intel.com> <20210114062512.45462-1-chenbo.xia@intel.com> Subject: [dpdk-dev] [PATCH v3 7/8] test/emudev: introduce functional test X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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 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 + +#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