DPDK patches and discussions
 help / color / mirror / Atom feed
From: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>
To: pbhagavatula@caviumnetworks.com
Cc: dev@dpdk.org, jerin.jacob@caviumnetworks.com,
	nipun.gupta@nxp.com, hemant.agrawal@nxp.com,
	nikhil.rao@intel.com
Subject: [dpdk-dev] [RFC PATCH v4 4/4] test: add event timer adapter auto-test
Date: Tue, 28 Nov 2017 11:40:08 -0600	[thread overview]
Message-ID: <1511890808-6072-5-git-send-email-erik.g.carrillo@intel.com> (raw)
In-Reply-To: <1511890808-6072-1-git-send-email-erik.g.carrillo@intel.com>

This commit adds enough test infrastructure to exercise the
allocation/deallocation routines of the event timer adapter library
minimally.

Signed-off-by: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>
---
 test/test/Makefile                   |   1 +
 test/test/test_event_timer_adapter.c | 249 +++++++++++++++++++++++++++++++++++
 2 files changed, 250 insertions(+)
 create mode 100644 test/test/test_event_timer_adapter.c

diff --git a/test/test/Makefile b/test/test/Makefile
index bb54c98..9448aef 100644
--- a/test/test/Makefile
+++ b/test/test/Makefile
@@ -210,6 +210,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_EVENTDEV),y)
 SRCS-y += test_eventdev.c
 SRCS-y += test_event_ring.c
 SRCS-y += test_event_eth_rx_adapter.c
+SRCS-y += test_event_timer_adapter.c
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_SW_EVENTDEV) += test_eventdev_sw.c
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_OCTEONTX_SSOVF) += test_eventdev_octeontx.c
 endif
diff --git a/test/test/test_event_timer_adapter.c b/test/test/test_event_timer_adapter.c
new file mode 100644
index 0000000..d0ea066
--- /dev/null
+++ b/test/test/test_event_timer_adapter.c
@@ -0,0 +1,249 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+#include <rte_eventdev.h>
+#include <rte_dev.h>
+#include <rte_bus_vdev.h>
+#include <rte_event_timer_adapter.h>
+#include <rte_mempool.h>
+#include <rte_errno.h>
+#include <rte_service_component.h>
+
+#include "test.h"
+
+/* Example from RFC */
+#define NB_TEST_EVENT_TIMERS 40000
+
+static int evdev;
+//struct rte_event_timer_adapter *g_adapter;
+struct rte_event_timer *g_evtimer;
+struct rte_mempool *g_event_timer_pool;
+
+static inline void
+devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
+			struct rte_event_dev_info *info)
+{
+	memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
+	dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
+	/* Leave a port for the adapter to allocate */
+	dev_conf->nb_event_ports = info->max_event_ports - 1;
+	dev_conf->nb_event_queues = info->max_event_queues;
+	dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
+	dev_conf->nb_event_port_dequeue_depth =
+			info->max_event_port_dequeue_depth;
+	dev_conf->nb_event_port_enqueue_depth =
+			info->max_event_port_enqueue_depth;
+	dev_conf->nb_event_port_enqueue_depth =
+			info->max_event_port_enqueue_depth;
+	dev_conf->nb_events_limit =
+			info->max_num_events;
+}
+
+static int
+configure_event_dev(void)
+{
+	struct rte_event_dev_config devconf;
+	int ret;
+	const char *eventdev_name = "event_sw0";
+	struct rte_event_dev_info info;
+	int i;
+
+	evdev = rte_event_dev_get_dev_id(eventdev_name);
+	if (evdev < 0) {
+		if (rte_vdev_init(eventdev_name, NULL) < 0) {
+			printf("Error creating eventdev\n");
+			return TEST_FAILED;
+		}
+		evdev = rte_event_dev_get_dev_id(eventdev_name);
+		if (evdev < 0) {
+			printf("Error finding newly created eventdev\n");
+			return TEST_FAILED;
+		}
+	}
+
+	ret = rte_event_dev_info_get(evdev, &info);
+	TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
+
+	devconf_set_default_sane_values(&devconf, &info);
+
+	ret = rte_event_dev_configure(evdev, &devconf);
+	TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
+
+	/* Map the event_sw0 service to a service core */
+	ret = rte_service_start_with_defaults();
+	TEST_ASSERT_SUCCESS(ret, "Failed to start sw_evdev service");
+
+	/* Set up event queues */
+	uint32_t queue_count;
+	TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(evdev,
+			    RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
+			    "Queue count get failed");
+
+	for (i = 0; i < (int)queue_count; i++) {
+		ret = rte_event_queue_setup(evdev, i, NULL);
+		TEST_ASSERT_SUCCESS(ret, "Failed to setup queue=%d", i);
+	}
+
+	/* Set up event ports */
+	uint32_t port_count;
+	TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(evdev,
+			    RTE_EVENT_DEV_ATTR_PORT_COUNT,
+			    &port_count), "Port count get failed");
+
+	for (i = 0; i < (int)port_count; i++) {
+		ret = rte_event_port_setup(evdev, i, NULL);
+		TEST_ASSERT_SUCCESS(ret, "Failed to setup port=%d", i);
+		/* Link each queues to all ports */
+		ret = rte_event_port_link(evdev, i, NULL, NULL, 0);
+		TEST_ASSERT(ret >= 0, "Failed to link all queues port=%d", i);
+	}
+
+	/* Start the event device */
+	ret = rte_event_dev_start(evdev);
+	TEST_ASSERT_SUCCESS(ret, "Failed to start device");
+
+	return TEST_SUCCESS;
+}
+
+static int
+testsuite_setup(void)
+{
+	int ret;
+
+	/* Setup and start event device. */
+	ret = configure_event_dev();
+	if (ret) {
+		printf("Failed to configure event dev\n");
+		return TEST_FAILED;
+	}
+
+	/* Create a mempool of event timers. */
+	g_event_timer_pool = rte_mempool_create("event_timer_mempool",
+						NB_TEST_EVENT_TIMERS,
+						sizeof(struct rte_event_timer),
+						0,
+						0,
+						NULL,
+						NULL,
+						NULL,
+						NULL,
+						rte_socket_id(),
+						0);
+	if (g_event_timer_pool == NULL) {
+		/* Failed to create event timer mempool. */
+		printf("Failed to configure event timer mempool: %s\n",
+		       rte_strerror(rte_errno));
+		return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+static void
+testsuite_teardown(void)
+{
+	/* TODO: tear down adapter and evdev */
+
+	rte_mempool_free(g_event_timer_pool);
+}
+
+#define NSECPERSEC 1E9  // No of ns for 1 sec
+
+static int
+adapter_create_free(void)
+{
+	int ret;
+	int adapter_id = 0;
+	struct rte_event_timer_adapter *adapter;
+
+	struct rte_event_timer_adapter_conf conf = {
+		.event_dev_id = evdev,
+		.timer_adapter_id = adapter_id,
+		.clk_src = RTE_EVENT_TIMER_ADAPTER_CPU_CLK,
+		.timer_tick_ns = NSECPERSEC / 10,  // 100 milliseconds
+		.max_tmo_ns = 180 * NSECPERSEC,  // 2 minutes
+		.nb_timers = NB_TEST_EVENT_TIMERS,
+		.flags = 0,
+	};
+
+	adapter = rte_event_timer_adapter_create(&conf);
+	if (adapter == NULL) {
+		printf("Failed to create adapter\n");
+		return TEST_FAILED;
+	}
+
+	/* Move to separate tests later; just verify plugin connections for
+	 * now
+	 */
+
+	struct rte_event_timer_adapter_info adapter_info;
+	ret = rte_event_timer_adapter_get_info(adapter, &adapter_info);
+	if (ret < 0)
+		return TEST_FAILED;
+
+	ret = rte_event_timer_adapter_start(adapter);
+	if (ret < 0)
+		return TEST_FAILED;
+
+	ret = rte_event_timer_adapter_stop(adapter);
+	if (ret < 0)
+		return TEST_FAILED;
+
+	ret = rte_event_timer_adapter_free(adapter);
+	if (ret) {
+		printf("Failed to free adapter\n");
+		return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+static struct unit_test_suite adapter_tests  = {
+	.suite_name = "event timer adapter test suite",
+	.setup = testsuite_setup,
+	.teardown = testsuite_teardown,
+	.unit_test_cases = {
+		TEST_CASE(adapter_create_free),
+		TEST_CASES_END() /**< NULL terminate unit test array */
+	}
+};
+
+static int
+test_event_timer_adapter_common(void)
+{
+	return unit_test_suite_runner(&adapter_tests);
+}
+
+REGISTER_TEST_COMMAND(event_timer_adapter_autotest,
+		      test_event_timer_adapter_common);
-- 
2.6.4

      parent reply	other threads:[~2017-11-28 17:41 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-17 16:11 [dpdk-dev] [RFC PATCH 0/1] eventtimer: introduce event timer wheel Jerin Jacob
2017-08-17 16:11 ` [dpdk-dev] [RFC PATCH 1/1] " Jerin Jacob
2017-08-23 22:57 ` [dpdk-dev] [RFC PATCH 0/1] " Carrillo, Erik G
2017-08-25 10:25   ` Jerin Jacob
2017-08-29 15:02     ` Thomas Monjalon
2017-08-29 15:41       ` Jerin Jacob
2017-08-29 15:48         ` Thomas Monjalon
2017-08-29 16:07           ` Jerin Jacob
2017-09-22 15:17 ` [dpdk-dev] [RFC PATCH v2 0/1] eventtimer: introduce event timer adapter Erik Gabriel Carrillo
2017-09-22 15:17   ` [dpdk-dev] [RFC PATCH v2 1/1] " Erik Gabriel Carrillo
2017-10-03 14:37   ` [dpdk-dev] [RFC PATCH v2 0/1] " Jerin Jacob
2017-10-09 20:30     ` Carrillo, Erik G
2017-10-16 12:04       ` Pavan Nikhilesh Bhagavatula
2017-10-16 12:37         ` Pavan Nikhilesh Bhagavatula
2017-10-18 21:48           ` Carrillo, Erik G
2017-10-26 15:45             ` Pavan Nikhilesh Bhagavatula
2017-11-20 22:35   ` [dpdk-dev] [RFC PATCH v3 " Erik Gabriel Carrillo
2017-11-20 22:35     ` [dpdk-dev] [RFC PATCH v3 1/1] " Erik Gabriel Carrillo
2017-11-23  4:37       ` Pavan Nikhilesh Bhagavatula
2017-11-27 14:47         ` Carrillo, Erik G
2017-11-28 17:40     ` [dpdk-dev] [RFC PATCH v4 0/4] " Erik Gabriel Carrillo
2017-11-28 17:40       ` [dpdk-dev] [RFC PATCH v4 1/4] " Erik Gabriel Carrillo
2017-11-29 10:29         ` Pavan Nikhilesh Bhagavatula
2017-11-28 17:40       ` [dpdk-dev] [RFC PATCH v4 2/4] eventtimer: add common code Erik Gabriel Carrillo
2017-11-29  5:19         ` Pavan Nikhilesh Bhagavatula
2017-11-30 20:59           ` Carrillo, Erik G
2017-12-01  5:13             ` Pavan Nikhilesh Bhagavatula
2017-12-01 20:19               ` Carrillo, Erik G
2017-11-28 17:40       ` [dpdk-dev] [RFC PATCH v4 3/4] eventtimer: add default software implementation stub Erik Gabriel Carrillo
2017-11-29 10:34         ` Pavan Nikhilesh Bhagavatula
2017-11-30 23:56           ` Carrillo, Erik G
2017-12-01  5:15             ` Pavan Nikhilesh Bhagavatula
2017-11-28 17:40       ` Erik Gabriel Carrillo [this message]

Reply instructions:

You may reply publicly 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=1511890808-6072-5-git-send-email-erik.g.carrillo@intel.com \
    --to=erik.g.carrillo@intel.com \
    --cc=dev@dpdk.org \
    --cc=hemant.agrawal@nxp.com \
    --cc=jerin.jacob@caviumnetworks.com \
    --cc=nikhil.rao@intel.com \
    --cc=nipun.gupta@nxp.com \
    --cc=pbhagavatula@caviumnetworks.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).