xref: /dpdk/app/test/test_event_timer_adapter.c (revision 3c60274c)
1a9de470cSBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2a9de470cSBruce Richardson  * Copyright(c) 2017 Cavium, Inc
3a9de470cSBruce Richardson  * Copyright(c) 2017-2018 Intel Corporation.
4a9de470cSBruce Richardson  */
5a9de470cSBruce Richardson 
6*3c60274cSJie Zhou #include "test.h"
7*3c60274cSJie Zhou 
841f27795SPavan Nikhilesh #include <math.h>
941f27795SPavan Nikhilesh 
10a9de470cSBruce Richardson #include <rte_common.h>
11a9de470cSBruce Richardson #include <rte_cycles.h>
12a9de470cSBruce Richardson #include <rte_debug.h>
13a9de470cSBruce Richardson #include <rte_eal.h>
14a9de470cSBruce Richardson #include <rte_ethdev.h>
15*3c60274cSJie Zhou 
16*3c60274cSJie Zhou #ifdef RTE_EXEC_ENV_WINDOWS
17*3c60274cSJie Zhou static int
test_event_timer_adapter_func(void)18*3c60274cSJie Zhou test_event_timer_adapter_func(void)
19*3c60274cSJie Zhou {
20*3c60274cSJie Zhou 	printf("event_timer_adapter not supported on Windows, skipping test\n");
21*3c60274cSJie Zhou 	return TEST_SKIPPED;
22*3c60274cSJie Zhou }
23*3c60274cSJie Zhou 
24*3c60274cSJie Zhou #else
25*3c60274cSJie Zhou 
26a9de470cSBruce Richardson #include <rte_eventdev.h>
27a9de470cSBruce Richardson #include <rte_event_timer_adapter.h>
28a9de470cSBruce Richardson #include <rte_mempool.h>
29a9de470cSBruce Richardson #include <rte_launch.h>
30a9de470cSBruce Richardson #include <rte_lcore.h>
31a9de470cSBruce Richardson #include <rte_per_lcore.h>
32a9de470cSBruce Richardson #include <rte_random.h>
33a9de470cSBruce Richardson #include <rte_bus_vdev.h>
34a9de470cSBruce Richardson #include <rte_service.h>
35a9de470cSBruce Richardson #include <stdbool.h>
36a9de470cSBruce Richardson 
37a9de470cSBruce Richardson /* 4K timers corresponds to sw evdev max inflight events */
38a9de470cSBruce Richardson #define MAX_TIMERS  (4 * 1024)
39a9de470cSBruce Richardson #define BKT_TCK_NSEC
40a9de470cSBruce Richardson 
41a9de470cSBruce Richardson #define NSECPERSEC 1E9
42a9de470cSBruce Richardson #define BATCH_SIZE 16
43a9de470cSBruce Richardson /* Both the app lcore and adapter ports are linked to this queue */
44a9de470cSBruce Richardson #define TEST_QUEUE_ID 0
45a9de470cSBruce Richardson /* Port the application dequeues from */
46a9de470cSBruce Richardson #define TEST_PORT_ID 0
47a9de470cSBruce Richardson #define TEST_ADAPTER_ID 0
48a9de470cSBruce Richardson 
49a9de470cSBruce Richardson /* Handle log statements in same manner as test macros */
50a9de470cSBruce Richardson #define LOG_DBG(...)	RTE_LOG(DEBUG, EAL, __VA_ARGS__)
51a9de470cSBruce Richardson 
52a9de470cSBruce Richardson static int evdev;
53a9de470cSBruce Richardson static struct rte_event_timer_adapter *timdev;
54a9de470cSBruce Richardson static struct rte_mempool *eventdev_test_mempool;
55a9de470cSBruce Richardson static struct rte_ring *timer_producer_ring;
56a9de470cSBruce Richardson static uint64_t global_bkt_tck_ns;
572385a7f5SPavan Nikhilesh static uint64_t global_info_bkt_tck_ns;
58a9de470cSBruce Richardson static volatile uint8_t arm_done;
59a9de470cSBruce Richardson 
602385a7f5SPavan Nikhilesh #define CALC_TICKS(tks)					\
6141f27795SPavan Nikhilesh 	ceil((double)(tks * global_bkt_tck_ns) / global_info_bkt_tck_ns)
622385a7f5SPavan Nikhilesh 
632385a7f5SPavan Nikhilesh 
64a9de470cSBruce Richardson static bool using_services;
65a9de470cSBruce Richardson static uint32_t test_lcore1;
66a9de470cSBruce Richardson static uint32_t test_lcore2;
67a9de470cSBruce Richardson static uint32_t test_lcore3;
68a9de470cSBruce Richardson static uint32_t sw_evdev_slcore;
69a9de470cSBruce Richardson static uint32_t sw_adptr_slcore;
70a9de470cSBruce Richardson 
71a9de470cSBruce Richardson static inline void
devconf_set_default_sane_values(struct rte_event_dev_config * dev_conf,struct rte_event_dev_info * info)72a9de470cSBruce Richardson devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
73a9de470cSBruce Richardson 		struct rte_event_dev_info *info)
74a9de470cSBruce Richardson {
75a9de470cSBruce Richardson 	memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
76a9de470cSBruce Richardson 	dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
77a9de470cSBruce Richardson 	dev_conf->nb_event_ports = 1;
78a9de470cSBruce Richardson 	dev_conf->nb_event_queues = 1;
79a9de470cSBruce Richardson 	dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
80a9de470cSBruce Richardson 	dev_conf->nb_event_port_dequeue_depth =
81a9de470cSBruce Richardson 		info->max_event_port_dequeue_depth;
82a9de470cSBruce Richardson 	dev_conf->nb_event_port_enqueue_depth =
83a9de470cSBruce Richardson 		info->max_event_port_enqueue_depth;
84a9de470cSBruce Richardson 	dev_conf->nb_event_port_enqueue_depth =
85a9de470cSBruce Richardson 		info->max_event_port_enqueue_depth;
86a9de470cSBruce Richardson 	dev_conf->nb_events_limit =
87a9de470cSBruce Richardson 		info->max_num_events;
88a9de470cSBruce Richardson }
89a9de470cSBruce Richardson 
90a9de470cSBruce Richardson static inline int
eventdev_setup(void)91a9de470cSBruce Richardson eventdev_setup(void)
92a9de470cSBruce Richardson {
93a9de470cSBruce Richardson 	int ret;
94a9de470cSBruce Richardson 	struct rte_event_dev_config dev_conf;
95a9de470cSBruce Richardson 	struct rte_event_dev_info info;
96a9de470cSBruce Richardson 	uint32_t service_id;
97a9de470cSBruce Richardson 
98a9de470cSBruce Richardson 	ret = rte_event_dev_info_get(evdev, &info);
99a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
1002385a7f5SPavan Nikhilesh 	TEST_ASSERT(info.max_num_events < 0 ||
1012385a7f5SPavan Nikhilesh 			info.max_num_events >= (int32_t)MAX_TIMERS,
102a9de470cSBruce Richardson 			"ERROR max_num_events=%d < max_events=%d",
103a9de470cSBruce Richardson 			info.max_num_events, MAX_TIMERS);
104a9de470cSBruce Richardson 
105a9de470cSBruce Richardson 	devconf_set_default_sane_values(&dev_conf, &info);
106a9de470cSBruce Richardson 	ret = rte_event_dev_configure(evdev, &dev_conf);
107a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
108a9de470cSBruce Richardson 
109a9de470cSBruce Richardson 	ret = rte_event_queue_setup(evdev, 0, NULL);
110a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(ret, "Failed to setup queue=%d", 0);
111a9de470cSBruce Richardson 
112a9de470cSBruce Richardson 	/* Configure event port */
113a9de470cSBruce Richardson 	ret = rte_event_port_setup(evdev, 0, NULL);
114a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(ret, "Failed to setup port=%d", 0);
115a9de470cSBruce Richardson 	ret = rte_event_port_link(evdev, 0, NULL, NULL, 0);
116a9de470cSBruce Richardson 	TEST_ASSERT(ret >= 0, "Failed to link all queues port=%d", 0);
117a9de470cSBruce Richardson 
118a9de470cSBruce Richardson 	/* If this is a software event device, map and start its service */
119a9de470cSBruce Richardson 	if (rte_event_dev_service_id_get(evdev, &service_id) == 0) {
120a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_service_lcore_add(sw_evdev_slcore),
121a9de470cSBruce Richardson 				"Failed to add service core");
122a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_service_lcore_start(
123a9de470cSBruce Richardson 				sw_evdev_slcore),
124a9de470cSBruce Richardson 				"Failed to start service core");
125a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_service_map_lcore_set(
126a9de470cSBruce Richardson 				service_id, sw_evdev_slcore, 1),
127a9de470cSBruce Richardson 				"Failed to map evdev service");
128a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_service_runstate_set(
129a9de470cSBruce Richardson 				service_id, 1),
130a9de470cSBruce Richardson 				"Failed to start evdev service");
131a9de470cSBruce Richardson 	}
132a9de470cSBruce Richardson 
133a9de470cSBruce Richardson 	ret = rte_event_dev_start(evdev);
134a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(ret, "Failed to start device");
135a9de470cSBruce Richardson 
136a9de470cSBruce Richardson 	return TEST_SUCCESS;
137a9de470cSBruce Richardson }
138a9de470cSBruce Richardson 
139a9de470cSBruce Richardson static int
testsuite_setup(void)140a9de470cSBruce Richardson testsuite_setup(void)
141a9de470cSBruce Richardson {
142a9de470cSBruce Richardson 	/* Some of the multithreaded tests require 3 other lcores to run */
143a9de470cSBruce Richardson 	unsigned int required_lcore_count = 4;
144a9de470cSBruce Richardson 	uint32_t service_id;
145a9de470cSBruce Richardson 
146a9de470cSBruce Richardson 	/* To make it easier to map services later if needed, just reset
147a9de470cSBruce Richardson 	 * service core state.
148a9de470cSBruce Richardson 	 */
149a9de470cSBruce Richardson 	(void) rte_service_lcore_reset_all();
150a9de470cSBruce Richardson 
151a9de470cSBruce Richardson 	if (!rte_event_dev_count()) {
152a9de470cSBruce Richardson 		/* If there is no hardware eventdev, or no software vdev was
153a9de470cSBruce Richardson 		 * specified on the command line, create an instance of
154a9de470cSBruce Richardson 		 * event_sw.
155a9de470cSBruce Richardson 		 */
156a9de470cSBruce Richardson 		LOG_DBG("Failed to find a valid event device... testing with"
157a9de470cSBruce Richardson 			" event_sw device\n");
158a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_vdev_init("event_sw0", NULL),
159a9de470cSBruce Richardson 					"Error creating eventdev");
160a9de470cSBruce Richardson 		evdev = rte_event_dev_get_dev_id("event_sw0");
161a9de470cSBruce Richardson 	}
162a9de470cSBruce Richardson 
163a9de470cSBruce Richardson 	if (rte_event_dev_service_id_get(evdev, &service_id) == 0) {
164a9de470cSBruce Richardson 		/* A software event device will use a software event timer
165a9de470cSBruce Richardson 		 * adapter as well. 2 more cores required to convert to
166a9de470cSBruce Richardson 		 * service cores.
167a9de470cSBruce Richardson 		 */
168a9de470cSBruce Richardson 		required_lcore_count += 2;
169a9de470cSBruce Richardson 		using_services = true;
170a9de470cSBruce Richardson 	}
171a9de470cSBruce Richardson 
172a9de470cSBruce Richardson 	if (rte_lcore_count() < required_lcore_count) {
173e0f4a0edSDavid Marchand 		printf("Not enough cores for event_timer_adapter_test, expecting at least %u\n",
174e0f4a0edSDavid Marchand 		       required_lcore_count);
175e0f4a0edSDavid Marchand 		return TEST_SKIPPED;
176a9de470cSBruce Richardson 	}
177a9de470cSBruce Richardson 
178a9de470cSBruce Richardson 	/* Assign lcores for various tasks */
179a9de470cSBruce Richardson 	test_lcore1 = rte_get_next_lcore(-1, 1, 0);
180a9de470cSBruce Richardson 	test_lcore2 = rte_get_next_lcore(test_lcore1, 1, 0);
181a9de470cSBruce Richardson 	test_lcore3 = rte_get_next_lcore(test_lcore2, 1, 0);
182a9de470cSBruce Richardson 	if (using_services) {
183a9de470cSBruce Richardson 		sw_evdev_slcore = rte_get_next_lcore(test_lcore3, 1, 0);
184a9de470cSBruce Richardson 		sw_adptr_slcore = rte_get_next_lcore(sw_evdev_slcore, 1, 0);
185a9de470cSBruce Richardson 	}
186a9de470cSBruce Richardson 
187a9de470cSBruce Richardson 	return eventdev_setup();
188a9de470cSBruce Richardson }
189a9de470cSBruce Richardson 
190a9de470cSBruce Richardson static void
testsuite_teardown(void)191a9de470cSBruce Richardson testsuite_teardown(void)
192a9de470cSBruce Richardson {
193a9de470cSBruce Richardson 	rte_event_dev_stop(evdev);
194a9de470cSBruce Richardson 	rte_event_dev_close(evdev);
195a9de470cSBruce Richardson }
196a9de470cSBruce Richardson 
197a9de470cSBruce Richardson static int
setup_adapter_service(struct rte_event_timer_adapter * adptr)198a9de470cSBruce Richardson setup_adapter_service(struct rte_event_timer_adapter *adptr)
199a9de470cSBruce Richardson {
200a9de470cSBruce Richardson 	uint32_t adapter_service_id;
201a9de470cSBruce Richardson 	int ret;
202a9de470cSBruce Richardson 
203a9de470cSBruce Richardson 	/* retrieve service ids */
204a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_service_id_get(adptr,
205a9de470cSBruce Richardson 			&adapter_service_id), "Failed to get event timer "
206a9de470cSBruce Richardson 			"adapter service id");
207a9de470cSBruce Richardson 	/* add a service core and start it */
208a9de470cSBruce Richardson 	ret = rte_service_lcore_add(sw_adptr_slcore);
209a9de470cSBruce Richardson 	TEST_ASSERT(ret == 0 || ret == -EALREADY,
210a9de470cSBruce Richardson 			"Failed to add service core");
211a9de470cSBruce Richardson 	ret = rte_service_lcore_start(sw_adptr_slcore);
212a9de470cSBruce Richardson 	TEST_ASSERT(ret == 0 || ret == -EALREADY,
213a9de470cSBruce Richardson 			"Failed to start service core");
214a9de470cSBruce Richardson 
215a9de470cSBruce Richardson 	/* map services to it */
216a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_service_map_lcore_set(adapter_service_id,
217a9de470cSBruce Richardson 			sw_adptr_slcore, 1),
218a9de470cSBruce Richardson 			"Failed to map adapter service");
219a9de470cSBruce Richardson 
220a9de470cSBruce Richardson 	/* set services to running */
221a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_service_runstate_set(adapter_service_id, 1),
222a9de470cSBruce Richardson 			"Failed to start event timer adapter service");
223a9de470cSBruce Richardson 
224a9de470cSBruce Richardson 	return TEST_SUCCESS;
225a9de470cSBruce Richardson }
226a9de470cSBruce Richardson 
227a9de470cSBruce Richardson static int
test_port_conf_cb(uint16_t id,uint8_t event_dev_id,uint8_t * event_port_id,void * conf_arg)228a9de470cSBruce Richardson test_port_conf_cb(uint16_t id, uint8_t event_dev_id, uint8_t *event_port_id,
229a9de470cSBruce Richardson 		  void *conf_arg)
230a9de470cSBruce Richardson {
231a9de470cSBruce Richardson 	struct rte_event_dev_config dev_conf;
232a9de470cSBruce Richardson 	struct rte_event_dev_info info;
233a9de470cSBruce Richardson 	struct rte_event_port_conf *port_conf, def_port_conf = {0};
234a9de470cSBruce Richardson 	uint32_t started;
235a9de470cSBruce Richardson 	static int port_allocated;
236a9de470cSBruce Richardson 	static uint8_t port_id;
237a9de470cSBruce Richardson 	int ret;
238a9de470cSBruce Richardson 
239a9de470cSBruce Richardson 	if (port_allocated) {
240a9de470cSBruce Richardson 		*event_port_id = port_id;
241a9de470cSBruce Richardson 		return 0;
242a9de470cSBruce Richardson 	}
243a9de470cSBruce Richardson 
244a9de470cSBruce Richardson 	RTE_SET_USED(id);
245a9de470cSBruce Richardson 
246a9de470cSBruce Richardson 	ret = rte_event_dev_attr_get(event_dev_id, RTE_EVENT_DEV_ATTR_STARTED,
247a9de470cSBruce Richardson 				     &started);
248a9de470cSBruce Richardson 	if (ret < 0)
249a9de470cSBruce Richardson 		return ret;
250a9de470cSBruce Richardson 
251a9de470cSBruce Richardson 	if (started)
252a9de470cSBruce Richardson 		rte_event_dev_stop(event_dev_id);
253a9de470cSBruce Richardson 
254a9de470cSBruce Richardson 	ret = rte_event_dev_info_get(evdev, &info);
255a9de470cSBruce Richardson 	if (ret < 0)
256a9de470cSBruce Richardson 		return ret;
257a9de470cSBruce Richardson 
258a9de470cSBruce Richardson 	devconf_set_default_sane_values(&dev_conf, &info);
259a9de470cSBruce Richardson 
260a9de470cSBruce Richardson 	port_id = dev_conf.nb_event_ports;
261a9de470cSBruce Richardson 	dev_conf.nb_event_ports++;
262a9de470cSBruce Richardson 
263a9de470cSBruce Richardson 	ret = rte_event_dev_configure(event_dev_id, &dev_conf);
264a9de470cSBruce Richardson 	if (ret < 0) {
265a9de470cSBruce Richardson 		if (started)
266a9de470cSBruce Richardson 			rte_event_dev_start(event_dev_id);
267a9de470cSBruce Richardson 		return ret;
268a9de470cSBruce Richardson 	}
269a9de470cSBruce Richardson 
270a9de470cSBruce Richardson 	if (conf_arg != NULL)
271a9de470cSBruce Richardson 		port_conf = conf_arg;
272a9de470cSBruce Richardson 	else {
273a9de470cSBruce Richardson 		port_conf = &def_port_conf;
274a9de470cSBruce Richardson 		ret = rte_event_port_default_conf_get(event_dev_id, port_id,
275a9de470cSBruce Richardson 						      port_conf);
276a9de470cSBruce Richardson 		if (ret < 0)
277a9de470cSBruce Richardson 			return ret;
278a9de470cSBruce Richardson 	}
279a9de470cSBruce Richardson 
280a9de470cSBruce Richardson 	ret = rte_event_port_setup(event_dev_id, port_id, port_conf);
281a9de470cSBruce Richardson 	if (ret < 0)
282a9de470cSBruce Richardson 		return ret;
283a9de470cSBruce Richardson 
284a9de470cSBruce Richardson 	*event_port_id = port_id;
285a9de470cSBruce Richardson 
286a9de470cSBruce Richardson 	if (started)
287a9de470cSBruce Richardson 		rte_event_dev_start(event_dev_id);
288a9de470cSBruce Richardson 
289a9de470cSBruce Richardson 	/* Reuse this port number next time this is called */
290a9de470cSBruce Richardson 	port_allocated = 1;
291a9de470cSBruce Richardson 
292a9de470cSBruce Richardson 	return 0;
293a9de470cSBruce Richardson }
294a9de470cSBruce Richardson 
295a9de470cSBruce Richardson static int
_timdev_setup(uint64_t max_tmo_ns,uint64_t bkt_tck_ns,uint64_t flags)2967d761b07SShijith Thotton _timdev_setup(uint64_t max_tmo_ns, uint64_t bkt_tck_ns, uint64_t flags)
297a9de470cSBruce Richardson {
2982385a7f5SPavan Nikhilesh 	struct rte_event_timer_adapter_info info;
299a9de470cSBruce Richardson 	struct rte_event_timer_adapter_conf config = {
300a9de470cSBruce Richardson 		.event_dev_id = evdev,
301a9de470cSBruce Richardson 		.timer_adapter_id = TEST_ADAPTER_ID,
302a9de470cSBruce Richardson 		.timer_tick_ns = bkt_tck_ns,
303a9de470cSBruce Richardson 		.max_tmo_ns = max_tmo_ns,
304a9de470cSBruce Richardson 		.nb_timers = MAX_TIMERS * 10,
3057d761b07SShijith Thotton 		.flags = flags,
306a9de470cSBruce Richardson 	};
307a9de470cSBruce Richardson 	uint32_t caps = 0;
308a9de470cSBruce Richardson 	const char *pool_name = "timdev_test_pool";
309a9de470cSBruce Richardson 
310a9de470cSBruce Richardson 	global_bkt_tck_ns = bkt_tck_ns;
311a9de470cSBruce Richardson 
312a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_caps_get(evdev, &caps),
313a9de470cSBruce Richardson 				"failed to get adapter capabilities");
3147d761b07SShijith Thotton 
3157d761b07SShijith Thotton 	if (flags & RTE_EVENT_TIMER_ADAPTER_F_PERIODIC &&
3165d28b660SShijith Thotton 	    !(caps & RTE_EVENT_TIMER_ADAPTER_CAP_PERIODIC))
3175d28b660SShijith Thotton 		return -ENOTSUP;
3187d761b07SShijith Thotton 
319a9de470cSBruce Richardson 	if (!(caps & RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT)) {
320a9de470cSBruce Richardson 		timdev = rte_event_timer_adapter_create_ext(&config,
321a9de470cSBruce Richardson 							    test_port_conf_cb,
322a9de470cSBruce Richardson 							    NULL);
323a9de470cSBruce Richardson 		setup_adapter_service(timdev);
324a9de470cSBruce Richardson 		using_services = true;
325a9de470cSBruce Richardson 	} else
326a9de470cSBruce Richardson 		timdev = rte_event_timer_adapter_create(&config);
327a9de470cSBruce Richardson 
328a9de470cSBruce Richardson 	TEST_ASSERT_NOT_NULL(timdev,
329a9de470cSBruce Richardson 			"failed to create event timer ring");
330a9de470cSBruce Richardson 
331a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_event_timer_adapter_start(timdev), 0,
332a9de470cSBruce Richardson 			"failed to Start event timer adapter");
333a9de470cSBruce Richardson 
334a9de470cSBruce Richardson 	/* Create event timer mempool */
335a9de470cSBruce Richardson 	eventdev_test_mempool = rte_mempool_create(pool_name,
336a9de470cSBruce Richardson 			MAX_TIMERS * 2,
337a9de470cSBruce Richardson 			sizeof(struct rte_event_timer), /* element size*/
338a9de470cSBruce Richardson 			0, /* cache size*/
339a9de470cSBruce Richardson 			0, NULL, NULL, NULL, NULL,
340a9de470cSBruce Richardson 			rte_socket_id(), 0);
341a9de470cSBruce Richardson 	if (!eventdev_test_mempool) {
342a9de470cSBruce Richardson 		printf("ERROR creating mempool\n");
343a9de470cSBruce Richardson 		return TEST_FAILED;
344a9de470cSBruce Richardson 	}
345a9de470cSBruce Richardson 
3462385a7f5SPavan Nikhilesh 	rte_event_timer_adapter_get_info(timdev, &info);
3472385a7f5SPavan Nikhilesh 
3482385a7f5SPavan Nikhilesh 	global_info_bkt_tck_ns = info.min_resolution_ns;
3492385a7f5SPavan Nikhilesh 
350a9de470cSBruce Richardson 	return TEST_SUCCESS;
351a9de470cSBruce Richardson }
352a9de470cSBruce Richardson 
353a9de470cSBruce Richardson static int
timdev_setup_usec(void)354a9de470cSBruce Richardson timdev_setup_usec(void)
355a9de470cSBruce Richardson {
3567d761b07SShijith Thotton 	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
3577d761b07SShijith Thotton 
358a9de470cSBruce Richardson 	return using_services ?
359a9de470cSBruce Richardson 		/* Max timeout is 10,000us and bucket interval is 100us */
3607d761b07SShijith Thotton 		_timdev_setup(1E7, 1E5, flags) :
361a9de470cSBruce Richardson 		/* Max timeout is 100us and bucket interval is 1us */
3627d761b07SShijith Thotton 		_timdev_setup(1E5, 1E3, flags);
363a9de470cSBruce Richardson }
364a9de470cSBruce Richardson 
365a9de470cSBruce Richardson static int
timdev_setup_usec_multicore(void)366a9de470cSBruce Richardson timdev_setup_usec_multicore(void)
367a9de470cSBruce Richardson {
3687d761b07SShijith Thotton 	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
3697d761b07SShijith Thotton 
370a9de470cSBruce Richardson 	return using_services ?
371a9de470cSBruce Richardson 		/* Max timeout is 10,000us and bucket interval is 100us */
3727d761b07SShijith Thotton 		_timdev_setup(1E7, 1E5, flags) :
373a9de470cSBruce Richardson 		/* Max timeout is 100us and bucket interval is 1us */
3747d761b07SShijith Thotton 		_timdev_setup(1E5, 1E3, flags);
375a9de470cSBruce Richardson }
376a9de470cSBruce Richardson 
377a9de470cSBruce Richardson static int
timdev_setup_msec(void)378a9de470cSBruce Richardson timdev_setup_msec(void)
379a9de470cSBruce Richardson {
3807d761b07SShijith Thotton 	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
3817d761b07SShijith Thotton 
3827d761b07SShijith Thotton 	/* Max timeout is 3 mins, and bucket interval is 100 ms */
3837d761b07SShijith Thotton 	return _timdev_setup(180 * NSECPERSEC, NSECPERSEC / 10, flags);
3847d761b07SShijith Thotton }
3857d761b07SShijith Thotton 
3867d761b07SShijith Thotton static int
timdev_setup_msec_periodic(void)3877d761b07SShijith Thotton timdev_setup_msec_periodic(void)
3887d761b07SShijith Thotton {
3897d761b07SShijith Thotton 	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES |
3907d761b07SShijith Thotton 			 RTE_EVENT_TIMER_ADAPTER_F_PERIODIC;
3917d761b07SShijith Thotton 
3927d761b07SShijith Thotton 	/* Periodic mode with 100 ms resolution */
3937d761b07SShijith Thotton 	return _timdev_setup(0, NSECPERSEC / 10, flags);
394a9de470cSBruce Richardson }
395a9de470cSBruce Richardson 
396a9de470cSBruce Richardson static int
timdev_setup_sec(void)397a9de470cSBruce Richardson timdev_setup_sec(void)
398a9de470cSBruce Richardson {
3997d761b07SShijith Thotton 	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
4007d761b07SShijith Thotton 
401a9de470cSBruce Richardson 	/* Max timeout is 100sec and bucket interval is 1sec */
4027d761b07SShijith Thotton 	return _timdev_setup(1E11, 1E9, flags);
4037d761b07SShijith Thotton }
4047d761b07SShijith Thotton 
4057d761b07SShijith Thotton static int
timdev_setup_sec_periodic(void)4067d761b07SShijith Thotton timdev_setup_sec_periodic(void)
4077d761b07SShijith Thotton {
4087d761b07SShijith Thotton 	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES |
4097d761b07SShijith Thotton 			 RTE_EVENT_TIMER_ADAPTER_F_PERIODIC;
4107d761b07SShijith Thotton 
4117d761b07SShijith Thotton 	/* Periodic mode with 1 sec resolution */
4127d761b07SShijith Thotton 	return _timdev_setup(0, NSECPERSEC, flags);
413a9de470cSBruce Richardson }
414a9de470cSBruce Richardson 
415a9de470cSBruce Richardson static int
timdev_setup_sec_multicore(void)416a9de470cSBruce Richardson timdev_setup_sec_multicore(void)
417a9de470cSBruce Richardson {
4187d761b07SShijith Thotton 	uint64_t flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES;
4197d761b07SShijith Thotton 
420a9de470cSBruce Richardson 	/* Max timeout is 100sec and bucket interval is 1sec */
4217d761b07SShijith Thotton 	return _timdev_setup(1E11, 1E9, flags);
422a9de470cSBruce Richardson }
423a9de470cSBruce Richardson 
424a9de470cSBruce Richardson static void
timdev_teardown(void)425a9de470cSBruce Richardson timdev_teardown(void)
426a9de470cSBruce Richardson {
427a9de470cSBruce Richardson 	rte_event_timer_adapter_stop(timdev);
428a9de470cSBruce Richardson 	rte_event_timer_adapter_free(timdev);
429a9de470cSBruce Richardson 
430a9de470cSBruce Richardson 	rte_mempool_free(eventdev_test_mempool);
431a9de470cSBruce Richardson }
432a9de470cSBruce Richardson 
433a9de470cSBruce Richardson static inline int
test_timer_state(void)434a9de470cSBruce Richardson test_timer_state(void)
435a9de470cSBruce Richardson {
436a9de470cSBruce Richardson 	struct rte_event_timer *ev_tim;
437a9de470cSBruce Richardson 	struct rte_event ev;
438a9de470cSBruce Richardson 	const struct rte_event_timer tim = {
439a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
440a9de470cSBruce Richardson 		.ev.queue_id = 0,
441a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
442a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
443a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
444a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
445a9de470cSBruce Richardson 	};
446a9de470cSBruce Richardson 
4472385a7f5SPavan Nikhilesh 
448a9de470cSBruce Richardson 	rte_mempool_get(eventdev_test_mempool, (void **)&ev_tim);
449a9de470cSBruce Richardson 	*ev_tim = tim;
450a9de470cSBruce Richardson 	ev_tim->ev.event_ptr = ev_tim;
4512385a7f5SPavan Nikhilesh 	ev_tim->timeout_ticks = CALC_TICKS(120);
452a9de470cSBruce Richardson 
453a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim, 1), 0,
454a9de470cSBruce Richardson 			"Armed timer exceeding max_timeout.");
455a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ev_tim->state, RTE_EVENT_TIMER_ERROR_TOOLATE,
456a9de470cSBruce Richardson 			"Improper timer state set expected %d returned %d",
457a9de470cSBruce Richardson 			RTE_EVENT_TIMER_ERROR_TOOLATE, ev_tim->state);
458a9de470cSBruce Richardson 
459a9de470cSBruce Richardson 	ev_tim->state = RTE_EVENT_TIMER_NOT_ARMED;
4602385a7f5SPavan Nikhilesh 	ev_tim->timeout_ticks = CALC_TICKS(10);
461a9de470cSBruce Richardson 
462a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim, 1), 1,
463a9de470cSBruce Richardson 			"Failed to arm timer with proper timeout.");
464a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ev_tim->state, RTE_EVENT_TIMER_ARMED,
465a9de470cSBruce Richardson 			"Improper timer state set expected %d returned %d",
466a9de470cSBruce Richardson 			RTE_EVENT_TIMER_ARMED, ev_tim->state);
467a9de470cSBruce Richardson 
468a9de470cSBruce Richardson 	if (!using_services)
469a9de470cSBruce Richardson 		rte_delay_us(20);
470a9de470cSBruce Richardson 	else
471a9de470cSBruce Richardson 		rte_delay_us(1000 + 200);
472a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_event_dequeue_burst(evdev, 0, &ev, 1, 0), 1,
473a9de470cSBruce Richardson 			"Armed timer failed to trigger.");
474a9de470cSBruce Richardson 
475a9de470cSBruce Richardson 	ev_tim->state = RTE_EVENT_TIMER_NOT_ARMED;
4762385a7f5SPavan Nikhilesh 	ev_tim->timeout_ticks = CALC_TICKS(90);
477a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim, 1), 1,
478a9de470cSBruce Richardson 			"Failed to arm timer with proper timeout.");
479a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_event_timer_cancel_burst(timdev, &ev_tim, 1),
480a9de470cSBruce Richardson 			1, "Failed to cancel armed timer");
481a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ev_tim->state, RTE_EVENT_TIMER_CANCELED,
482a9de470cSBruce Richardson 			"Improper timer state set expected %d returned %d",
483a9de470cSBruce Richardson 			RTE_EVENT_TIMER_CANCELED, ev_tim->state);
484a9de470cSBruce Richardson 
485a9de470cSBruce Richardson 	rte_mempool_put(eventdev_test_mempool, (void *)ev_tim);
486a9de470cSBruce Richardson 
487a9de470cSBruce Richardson 	return TEST_SUCCESS;
488a9de470cSBruce Richardson }
489a9de470cSBruce Richardson 
490a9de470cSBruce Richardson static inline int
_arm_timers(uint64_t timeout_tcks,uint64_t timers)491a9de470cSBruce Richardson _arm_timers(uint64_t timeout_tcks, uint64_t timers)
492a9de470cSBruce Richardson {
493a9de470cSBruce Richardson 	uint64_t i;
494a9de470cSBruce Richardson 	struct rte_event_timer *ev_tim;
495a9de470cSBruce Richardson 	const struct rte_event_timer tim = {
496a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
497a9de470cSBruce Richardson 		.ev.queue_id = 0,
498a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
499a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
500a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
501a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
5022385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(timeout_tcks),
503a9de470cSBruce Richardson 	};
504a9de470cSBruce Richardson 
505a9de470cSBruce Richardson 	for (i = 0; i < timers; i++) {
506a9de470cSBruce Richardson 
507a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_mempool_get(eventdev_test_mempool,
508a9de470cSBruce Richardson 					(void **)&ev_tim),
509a9de470cSBruce Richardson 				"mempool alloc failed");
510a9de470cSBruce Richardson 		*ev_tim = tim;
511a9de470cSBruce Richardson 		ev_tim->ev.event_ptr = ev_tim;
512a9de470cSBruce Richardson 
513a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim,
514a9de470cSBruce Richardson 					1), 1, "Failed to arm timer %d",
515a9de470cSBruce Richardson 				rte_errno);
516a9de470cSBruce Richardson 	}
517a9de470cSBruce Richardson 
518a9de470cSBruce Richardson 	return TEST_SUCCESS;
519a9de470cSBruce Richardson }
520a9de470cSBruce Richardson 
521a9de470cSBruce Richardson static inline int
_wait_timer_triggers(uint64_t wait_sec,uint64_t arm_count,uint64_t cancel_count)522a9de470cSBruce Richardson _wait_timer_triggers(uint64_t wait_sec, uint64_t arm_count,
523a9de470cSBruce Richardson 		uint64_t cancel_count)
524a9de470cSBruce Richardson {
525a9de470cSBruce Richardson 	uint8_t valid_event;
526a9de470cSBruce Richardson 	uint64_t events = 0;
527a9de470cSBruce Richardson 	uint64_t wait_start, max_wait;
528a9de470cSBruce Richardson 	struct rte_event ev;
529a9de470cSBruce Richardson 
530a9de470cSBruce Richardson 	max_wait = rte_get_timer_hz() * wait_sec;
531a9de470cSBruce Richardson 	wait_start = rte_get_timer_cycles();
532a9de470cSBruce Richardson 	while (1) {
533a9de470cSBruce Richardson 		if (rte_get_timer_cycles() - wait_start > max_wait) {
534a9de470cSBruce Richardson 			if (events + cancel_count != arm_count)
535a9de470cSBruce Richardson 				TEST_ASSERT_SUCCESS(max_wait,
536a9de470cSBruce Richardson 					"Max time limit for timers exceeded.");
537a9de470cSBruce Richardson 			break;
538a9de470cSBruce Richardson 		}
539a9de470cSBruce Richardson 
540a9de470cSBruce Richardson 		valid_event = rte_event_dequeue_burst(evdev, 0, &ev, 1, 0);
541a9de470cSBruce Richardson 		if (!valid_event)
542a9de470cSBruce Richardson 			continue;
543a9de470cSBruce Richardson 
544a9de470cSBruce Richardson 		rte_mempool_put(eventdev_test_mempool, ev.event_ptr);
545a9de470cSBruce Richardson 		events++;
546a9de470cSBruce Richardson 	}
547a9de470cSBruce Richardson 
548a9de470cSBruce Richardson 	return TEST_SUCCESS;
549a9de470cSBruce Richardson }
550a9de470cSBruce Richardson 
551a9de470cSBruce Richardson static inline int
test_timer_arm(void)552a9de470cSBruce Richardson test_timer_arm(void)
553a9de470cSBruce Richardson {
554a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_arm_timers(20, MAX_TIMERS),
555a9de470cSBruce Richardson 			"Failed to arm timers");
556a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_wait_timer_triggers(10, MAX_TIMERS, 0),
557a9de470cSBruce Richardson 			"Timer triggered count doesn't match arm count");
558a9de470cSBruce Richardson 	return TEST_SUCCESS;
559a9de470cSBruce Richardson }
560a9de470cSBruce Richardson 
5617d761b07SShijith Thotton static inline int
test_timer_arm_periodic(void)5627d761b07SShijith Thotton test_timer_arm_periodic(void)
5637d761b07SShijith Thotton {
5647d761b07SShijith Thotton 	TEST_ASSERT_SUCCESS(_arm_timers(1, MAX_TIMERS),
5657d761b07SShijith Thotton 			    "Failed to arm timers");
5667d761b07SShijith Thotton 	/* With a resolution of 100ms and wait time of 1sec,
5677d761b07SShijith Thotton 	 * there will be 10 * MAX_TIMERS periodic timer triggers.
5687d761b07SShijith Thotton 	 */
5697d761b07SShijith Thotton 	TEST_ASSERT_SUCCESS(_wait_timer_triggers(1, 10 * MAX_TIMERS, 0),
5707d761b07SShijith Thotton 			    "Timer triggered count doesn't match arm count");
5717d761b07SShijith Thotton 	return TEST_SUCCESS;
5727d761b07SShijith Thotton }
5737d761b07SShijith Thotton 
574a9de470cSBruce Richardson static int
_arm_wrapper(void * arg)575a9de470cSBruce Richardson _arm_wrapper(void *arg)
576a9de470cSBruce Richardson {
577a9de470cSBruce Richardson 	RTE_SET_USED(arg);
578a9de470cSBruce Richardson 
579a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_arm_timers(20, MAX_TIMERS),
580a9de470cSBruce Richardson 			"Failed to arm timers");
581a9de470cSBruce Richardson 
582a9de470cSBruce Richardson 	return TEST_SUCCESS;
583a9de470cSBruce Richardson }
584a9de470cSBruce Richardson 
585a9de470cSBruce Richardson static inline int
test_timer_arm_multicore(void)586a9de470cSBruce Richardson test_timer_arm_multicore(void)
587a9de470cSBruce Richardson {
588a9de470cSBruce Richardson 
589a9de470cSBruce Richardson 	uint32_t lcore_1 = rte_get_next_lcore(-1, 1, 0);
590a9de470cSBruce Richardson 	uint32_t lcore_2 = rte_get_next_lcore(lcore_1, 1, 0);
591a9de470cSBruce Richardson 
592a9de470cSBruce Richardson 	rte_eal_remote_launch(_arm_wrapper, NULL, lcore_1);
593a9de470cSBruce Richardson 	rte_eal_remote_launch(_arm_wrapper, NULL, lcore_2);
594a9de470cSBruce Richardson 
595a9de470cSBruce Richardson 	rte_eal_mp_wait_lcore();
596a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_wait_timer_triggers(10, MAX_TIMERS * 2, 0),
597a9de470cSBruce Richardson 			"Timer triggered count doesn't match arm count");
598a9de470cSBruce Richardson 
599a9de470cSBruce Richardson 	return TEST_SUCCESS;
600a9de470cSBruce Richardson }
601a9de470cSBruce Richardson 
602a9de470cSBruce Richardson #define MAX_BURST 16
603a9de470cSBruce Richardson static inline int
_arm_timers_burst(uint64_t timeout_tcks,uint64_t timers)604a9de470cSBruce Richardson _arm_timers_burst(uint64_t timeout_tcks, uint64_t timers)
605a9de470cSBruce Richardson {
606a9de470cSBruce Richardson 	uint64_t i;
607a9de470cSBruce Richardson 	int j;
608a9de470cSBruce Richardson 	struct rte_event_timer *ev_tim[MAX_BURST];
609a9de470cSBruce Richardson 	const struct rte_event_timer tim = {
610a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
611a9de470cSBruce Richardson 		.ev.queue_id = 0,
612a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
613a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
614a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
615a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
6162385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(timeout_tcks),
617a9de470cSBruce Richardson 	};
618a9de470cSBruce Richardson 
619a9de470cSBruce Richardson 	for (i = 0; i < timers / MAX_BURST; i++) {
620a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_mempool_get_bulk(
621a9de470cSBruce Richardson 				eventdev_test_mempool,
622a9de470cSBruce Richardson 				(void **)ev_tim, MAX_BURST),
623a9de470cSBruce Richardson 				"mempool alloc failed");
624a9de470cSBruce Richardson 
625a9de470cSBruce Richardson 		for (j = 0; j < MAX_BURST; j++) {
626a9de470cSBruce Richardson 			*ev_tim[j] = tim;
627a9de470cSBruce Richardson 			ev_tim[j]->ev.event_ptr = ev_tim[j];
628a9de470cSBruce Richardson 		}
629a9de470cSBruce Richardson 
630a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(rte_event_timer_arm_tmo_tick_burst(timdev,
631a9de470cSBruce Richardson 				ev_tim, tim.timeout_ticks, MAX_BURST),
632a9de470cSBruce Richardson 				MAX_BURST, "Failed to arm timer %d", rte_errno);
633a9de470cSBruce Richardson 	}
634a9de470cSBruce Richardson 
635a9de470cSBruce Richardson 	return TEST_SUCCESS;
636a9de470cSBruce Richardson }
637a9de470cSBruce Richardson 
638a9de470cSBruce Richardson static inline int
test_timer_arm_burst(void)639a9de470cSBruce Richardson test_timer_arm_burst(void)
640a9de470cSBruce Richardson {
641a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_arm_timers_burst(20, MAX_TIMERS),
642a9de470cSBruce Richardson 			"Failed to arm timers");
643a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_wait_timer_triggers(10, MAX_TIMERS, 0),
644a9de470cSBruce Richardson 			"Timer triggered count doesn't match arm count");
645a9de470cSBruce Richardson 
646a9de470cSBruce Richardson 	return TEST_SUCCESS;
647a9de470cSBruce Richardson }
648a9de470cSBruce Richardson 
6497d761b07SShijith Thotton static inline int
test_timer_arm_burst_periodic(void)6507d761b07SShijith Thotton test_timer_arm_burst_periodic(void)
6517d761b07SShijith Thotton {
6527d761b07SShijith Thotton 	TEST_ASSERT_SUCCESS(_arm_timers_burst(1, MAX_TIMERS),
6537d761b07SShijith Thotton 			    "Failed to arm timers");
6547d761b07SShijith Thotton 	/* With a resolution of 100ms and wait time of 1sec,
6557d761b07SShijith Thotton 	 * there will be 10 * MAX_TIMERS periodic timer triggers.
6567d761b07SShijith Thotton 	 */
6577d761b07SShijith Thotton 	TEST_ASSERT_SUCCESS(_wait_timer_triggers(1, 10 * MAX_TIMERS, 0),
6587d761b07SShijith Thotton 			    "Timer triggered count doesn't match arm count");
6597d761b07SShijith Thotton 
6607d761b07SShijith Thotton 	return TEST_SUCCESS;
6617d761b07SShijith Thotton }
6627d761b07SShijith Thotton 
663a9de470cSBruce Richardson static int
_arm_wrapper_burst(void * arg)664a9de470cSBruce Richardson _arm_wrapper_burst(void *arg)
665a9de470cSBruce Richardson {
666a9de470cSBruce Richardson 	RTE_SET_USED(arg);
667a9de470cSBruce Richardson 
668a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_arm_timers_burst(20, MAX_TIMERS),
669a9de470cSBruce Richardson 			"Failed to arm timers");
670a9de470cSBruce Richardson 
671a9de470cSBruce Richardson 	return TEST_SUCCESS;
672a9de470cSBruce Richardson }
673a9de470cSBruce Richardson 
674a9de470cSBruce Richardson static inline int
test_timer_arm_burst_multicore(void)675a9de470cSBruce Richardson test_timer_arm_burst_multicore(void)
676a9de470cSBruce Richardson {
677a9de470cSBruce Richardson 	rte_eal_remote_launch(_arm_wrapper_burst, NULL, test_lcore1);
678a9de470cSBruce Richardson 	rte_eal_remote_launch(_arm_wrapper_burst, NULL, test_lcore2);
679a9de470cSBruce Richardson 
680a9de470cSBruce Richardson 	rte_eal_mp_wait_lcore();
681a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_wait_timer_triggers(10, MAX_TIMERS * 2, 0),
682a9de470cSBruce Richardson 			"Timer triggered count doesn't match arm count");
683a9de470cSBruce Richardson 
684a9de470cSBruce Richardson 	return TEST_SUCCESS;
685a9de470cSBruce Richardson }
686a9de470cSBruce Richardson 
687a9de470cSBruce Richardson static inline int
test_timer_cancel_periodic(void)6887d761b07SShijith Thotton test_timer_cancel_periodic(void)
6897d761b07SShijith Thotton {
6907d761b07SShijith Thotton 	uint64_t i;
6917d761b07SShijith Thotton 	struct rte_event_timer *ev_tim;
6927d761b07SShijith Thotton 	const struct rte_event_timer tim = {
6937d761b07SShijith Thotton 		.ev.op = RTE_EVENT_OP_NEW,
6947d761b07SShijith Thotton 		.ev.queue_id = 0,
6957d761b07SShijith Thotton 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
6967d761b07SShijith Thotton 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
6977d761b07SShijith Thotton 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
6987d761b07SShijith Thotton 		.state = RTE_EVENT_TIMER_NOT_ARMED,
6997d761b07SShijith Thotton 		.timeout_ticks = CALC_TICKS(1),
7007d761b07SShijith Thotton 	};
7017d761b07SShijith Thotton 
7027d761b07SShijith Thotton 	for (i = 0; i < MAX_TIMERS; i++) {
7037d761b07SShijith Thotton 		TEST_ASSERT_SUCCESS(rte_mempool_get(eventdev_test_mempool,
7047d761b07SShijith Thotton 					(void **)&ev_tim),
7057d761b07SShijith Thotton 				"mempool alloc failed");
7067d761b07SShijith Thotton 		*ev_tim = tim;
7077d761b07SShijith Thotton 		ev_tim->ev.event_ptr = ev_tim;
7087d761b07SShijith Thotton 
7097d761b07SShijith Thotton 		TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim,
7107d761b07SShijith Thotton 					1), 1, "Failed to arm timer %d",
7117d761b07SShijith Thotton 				rte_errno);
7127d761b07SShijith Thotton 
7137d761b07SShijith Thotton 		rte_delay_us(100 + (i % 5000));
7147d761b07SShijith Thotton 
7157d761b07SShijith Thotton 		TEST_ASSERT_EQUAL(rte_event_timer_cancel_burst(timdev,
7167d761b07SShijith Thotton 					&ev_tim, 1), 1,
7177d761b07SShijith Thotton 				"Failed to cancel event timer %d", rte_errno);
7187d761b07SShijith Thotton 		rte_mempool_put(eventdev_test_mempool, ev_tim);
7197d761b07SShijith Thotton 	}
7207d761b07SShijith Thotton 
7217d761b07SShijith Thotton 
7227d761b07SShijith Thotton 	TEST_ASSERT_SUCCESS(_wait_timer_triggers(30, MAX_TIMERS,
7237d761b07SShijith Thotton 				MAX_TIMERS),
7247d761b07SShijith Thotton 		"Timer triggered count doesn't match arm, cancel count");
7257d761b07SShijith Thotton 
7267d761b07SShijith Thotton 	return TEST_SUCCESS;
7277d761b07SShijith Thotton }
7287d761b07SShijith Thotton 
7297d761b07SShijith Thotton static inline int
test_timer_cancel(void)730a9de470cSBruce Richardson test_timer_cancel(void)
731a9de470cSBruce Richardson {
732a9de470cSBruce Richardson 	uint64_t i;
733a9de470cSBruce Richardson 	struct rte_event_timer *ev_tim;
734a9de470cSBruce Richardson 	const struct rte_event_timer tim = {
735a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
736a9de470cSBruce Richardson 		.ev.queue_id = 0,
737a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
738a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
739a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
740a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
7412385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(20),
742a9de470cSBruce Richardson 	};
743a9de470cSBruce Richardson 
744a9de470cSBruce Richardson 	for (i = 0; i < MAX_TIMERS; i++) {
745a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_mempool_get(eventdev_test_mempool,
746a9de470cSBruce Richardson 					(void **)&ev_tim),
747a9de470cSBruce Richardson 				"mempool alloc failed");
748a9de470cSBruce Richardson 		*ev_tim = tim;
749a9de470cSBruce Richardson 		ev_tim->ev.event_ptr = ev_tim;
750a9de470cSBruce Richardson 
751a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim,
752a9de470cSBruce Richardson 					1), 1, "Failed to arm timer %d",
753a9de470cSBruce Richardson 				rte_errno);
754a9de470cSBruce Richardson 
755a9de470cSBruce Richardson 		rte_delay_us(100 + (i % 5000));
756a9de470cSBruce Richardson 
757a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(rte_event_timer_cancel_burst(timdev,
758a9de470cSBruce Richardson 					&ev_tim, 1), 1,
759a9de470cSBruce Richardson 				"Failed to cancel event timer %d", rte_errno);
760a9de470cSBruce Richardson 		rte_mempool_put(eventdev_test_mempool, ev_tim);
761a9de470cSBruce Richardson 	}
762a9de470cSBruce Richardson 
763a9de470cSBruce Richardson 
764a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_wait_timer_triggers(30, MAX_TIMERS,
765a9de470cSBruce Richardson 				MAX_TIMERS),
766a9de470cSBruce Richardson 		"Timer triggered count doesn't match arm, cancel count");
767a9de470cSBruce Richardson 
768a9de470cSBruce Richardson 	return TEST_SUCCESS;
769a9de470cSBruce Richardson }
770a9de470cSBruce Richardson 
771a9de470cSBruce Richardson static int
_cancel_producer(uint64_t timeout_tcks,uint64_t timers)772a9de470cSBruce Richardson _cancel_producer(uint64_t timeout_tcks, uint64_t timers)
773a9de470cSBruce Richardson {
774a9de470cSBruce Richardson 	uint64_t i;
775a9de470cSBruce Richardson 	struct rte_event_timer *ev_tim;
776a9de470cSBruce Richardson 	const struct rte_event_timer tim = {
777a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
778a9de470cSBruce Richardson 		.ev.queue_id = 0,
779a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
780a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
781a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
782a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
7832385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(timeout_tcks),
784a9de470cSBruce Richardson 	};
785a9de470cSBruce Richardson 
786a9de470cSBruce Richardson 	for (i = 0; i < timers; i++) {
787a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_mempool_get(eventdev_test_mempool,
788a9de470cSBruce Richardson 					(void **)&ev_tim),
789a9de470cSBruce Richardson 				"mempool alloc failed");
790a9de470cSBruce Richardson 
791a9de470cSBruce Richardson 		*ev_tim = tim;
792a9de470cSBruce Richardson 		ev_tim->ev.event_ptr = ev_tim;
793a9de470cSBruce Richardson 
794a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim,
795a9de470cSBruce Richardson 					1), 1, "Failed to arm timer %d",
796a9de470cSBruce Richardson 				rte_errno);
797a9de470cSBruce Richardson 
798a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ev_tim->state, RTE_EVENT_TIMER_ARMED,
799a9de470cSBruce Richardson 				  "Failed to arm event timer");
800a9de470cSBruce Richardson 
801a9de470cSBruce Richardson 		while (rte_ring_enqueue(timer_producer_ring, ev_tim) != 0)
802a9de470cSBruce Richardson 			;
803a9de470cSBruce Richardson 	}
804a9de470cSBruce Richardson 
805a9de470cSBruce Richardson 	return TEST_SUCCESS;
806a9de470cSBruce Richardson }
807a9de470cSBruce Richardson 
808a9de470cSBruce Richardson static int
_cancel_producer_burst(uint64_t timeout_tcks,uint64_t timers)809a9de470cSBruce Richardson _cancel_producer_burst(uint64_t timeout_tcks, uint64_t timers)
810a9de470cSBruce Richardson {
811a9de470cSBruce Richardson 
812a9de470cSBruce Richardson 	uint64_t i;
813a9de470cSBruce Richardson 	int j, ret;
814a9de470cSBruce Richardson 	struct rte_event_timer *ev_tim[MAX_BURST];
815a9de470cSBruce Richardson 	const struct rte_event_timer tim = {
816a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
817a9de470cSBruce Richardson 		.ev.queue_id = 0,
818a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
819a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
820a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
821a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
8222385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(timeout_tcks),
823a9de470cSBruce Richardson 	};
824a9de470cSBruce Richardson 	int arm_count = 0;
825a9de470cSBruce Richardson 
826a9de470cSBruce Richardson 	for (i = 0; i < timers / MAX_BURST; i++) {
827a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_mempool_get_bulk(
828a9de470cSBruce Richardson 				eventdev_test_mempool,
829a9de470cSBruce Richardson 				(void **)ev_tim, MAX_BURST),
830a9de470cSBruce Richardson 				"mempool alloc failed");
831a9de470cSBruce Richardson 
832a9de470cSBruce Richardson 		for (j = 0; j < MAX_BURST; j++) {
833a9de470cSBruce Richardson 			*ev_tim[j] = tim;
834a9de470cSBruce Richardson 			ev_tim[j]->ev.event_ptr = ev_tim[j];
835a9de470cSBruce Richardson 		}
836a9de470cSBruce Richardson 
837a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(rte_event_timer_arm_tmo_tick_burst(timdev,
838a9de470cSBruce Richardson 				ev_tim, tim.timeout_ticks, MAX_BURST),
839a9de470cSBruce Richardson 				MAX_BURST, "Failed to arm timer %d", rte_errno);
840a9de470cSBruce Richardson 
841a9de470cSBruce Richardson 		for (j = 0; j < MAX_BURST; j++)
842a9de470cSBruce Richardson 			TEST_ASSERT_EQUAL(ev_tim[j]->state,
843a9de470cSBruce Richardson 					  RTE_EVENT_TIMER_ARMED,
844a9de470cSBruce Richardson 					  "Event timer not armed, state = %d",
845a9de470cSBruce Richardson 					  ev_tim[j]->state);
846a9de470cSBruce Richardson 
847a9de470cSBruce Richardson 		ret = rte_ring_enqueue_bulk(timer_producer_ring,
848a9de470cSBruce Richardson 				(void **)ev_tim, MAX_BURST, NULL);
849a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ret, MAX_BURST,
850a9de470cSBruce Richardson 				"Failed to enqueue event timers to ring");
851a9de470cSBruce Richardson 		arm_count += ret;
852a9de470cSBruce Richardson 	}
853a9de470cSBruce Richardson 
854a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(arm_count, MAX_TIMERS,
855a9de470cSBruce Richardson 			  "Failed to arm expected number of event timers");
856a9de470cSBruce Richardson 
857a9de470cSBruce Richardson 	return TEST_SUCCESS;
858a9de470cSBruce Richardson }
859a9de470cSBruce Richardson 
860a9de470cSBruce Richardson static int
_cancel_producer_wrapper(void * args)861a9de470cSBruce Richardson _cancel_producer_wrapper(void *args)
862a9de470cSBruce Richardson {
863a9de470cSBruce Richardson 	RTE_SET_USED(args);
864a9de470cSBruce Richardson 
865a9de470cSBruce Richardson 	return _cancel_producer(20, MAX_TIMERS);
866a9de470cSBruce Richardson }
867a9de470cSBruce Richardson 
868a9de470cSBruce Richardson static int
_cancel_producer_burst_wrapper(void * args)869a9de470cSBruce Richardson _cancel_producer_burst_wrapper(void *args)
870a9de470cSBruce Richardson {
871a9de470cSBruce Richardson 	RTE_SET_USED(args);
872a9de470cSBruce Richardson 
873a9de470cSBruce Richardson 	return _cancel_producer_burst(100, MAX_TIMERS);
874a9de470cSBruce Richardson }
875a9de470cSBruce Richardson 
876a9de470cSBruce Richardson static int
_cancel_thread(void * args)877a9de470cSBruce Richardson _cancel_thread(void *args)
878a9de470cSBruce Richardson {
879a9de470cSBruce Richardson 	RTE_SET_USED(args);
880a9de470cSBruce Richardson 	struct rte_event_timer *ev_tim = NULL;
881a9de470cSBruce Richardson 	uint64_t cancel_count = 0;
882a9de470cSBruce Richardson 	uint16_t ret;
883a9de470cSBruce Richardson 
884a9de470cSBruce Richardson 	while (!arm_done || rte_ring_count(timer_producer_ring) > 0) {
885a9de470cSBruce Richardson 		if (rte_ring_dequeue(timer_producer_ring, (void **)&ev_tim))
886a9de470cSBruce Richardson 			continue;
887a9de470cSBruce Richardson 
888a9de470cSBruce Richardson 		ret = rte_event_timer_cancel_burst(timdev, &ev_tim, 1);
889a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(ret, 1, "Failed to cancel timer");
890a9de470cSBruce Richardson 		rte_mempool_put(eventdev_test_mempool, (void *)ev_tim);
891a9de470cSBruce Richardson 		cancel_count++;
892a9de470cSBruce Richardson 	}
893a9de470cSBruce Richardson 
894a9de470cSBruce Richardson 	return TEST_SUCCESS;
895a9de470cSBruce Richardson }
896a9de470cSBruce Richardson 
897a9de470cSBruce Richardson static int
_cancel_burst_thread(void * args)898a9de470cSBruce Richardson _cancel_burst_thread(void *args)
899a9de470cSBruce Richardson {
900a9de470cSBruce Richardson 	RTE_SET_USED(args);
901a9de470cSBruce Richardson 
902a9de470cSBruce Richardson 	int ret, i, n;
903a9de470cSBruce Richardson 	struct rte_event_timer *ev_tim[MAX_BURST];
904a9de470cSBruce Richardson 	uint64_t cancel_count = 0;
905a9de470cSBruce Richardson 	uint64_t dequeue_count = 0;
906a9de470cSBruce Richardson 
907a9de470cSBruce Richardson 	while (!arm_done || rte_ring_count(timer_producer_ring) > 0) {
908a9de470cSBruce Richardson 		n = rte_ring_dequeue_burst(timer_producer_ring,
909a9de470cSBruce Richardson 				(void **)ev_tim, MAX_BURST, NULL);
910a9de470cSBruce Richardson 		if (!n)
911a9de470cSBruce Richardson 			continue;
912a9de470cSBruce Richardson 
913a9de470cSBruce Richardson 		dequeue_count += n;
914a9de470cSBruce Richardson 
915a9de470cSBruce Richardson 		for (i = 0; i < n; i++)
916a9de470cSBruce Richardson 			TEST_ASSERT_EQUAL(ev_tim[i]->state,
917a9de470cSBruce Richardson 					  RTE_EVENT_TIMER_ARMED,
918a9de470cSBruce Richardson 					  "Event timer not armed, state = %d",
919a9de470cSBruce Richardson 					  ev_tim[i]->state);
920a9de470cSBruce Richardson 
921a9de470cSBruce Richardson 		ret = rte_event_timer_cancel_burst(timdev, ev_tim, n);
922a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(n, ret, "Failed to cancel complete burst of "
923a9de470cSBruce Richardson 				  "event timers");
924a9de470cSBruce Richardson 		rte_mempool_put_bulk(eventdev_test_mempool, (void **)ev_tim,
925a9de470cSBruce Richardson 				RTE_MIN(ret, MAX_BURST));
926a9de470cSBruce Richardson 
927a9de470cSBruce Richardson 		cancel_count += ret;
928a9de470cSBruce Richardson 	}
929a9de470cSBruce Richardson 
930a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(cancel_count, MAX_TIMERS,
931a9de470cSBruce Richardson 			  "Failed to cancel expected number of timers: "
932a9de470cSBruce Richardson 			  "expected = %d, cancel_count = %"PRIu64", "
933a9de470cSBruce Richardson 			  "dequeue_count = %"PRIu64"\n", MAX_TIMERS,
934a9de470cSBruce Richardson 			  cancel_count, dequeue_count);
935a9de470cSBruce Richardson 
936a9de470cSBruce Richardson 	return TEST_SUCCESS;
937a9de470cSBruce Richardson }
938a9de470cSBruce Richardson 
939a9de470cSBruce Richardson static inline int
test_timer_cancel_multicore(void)940a9de470cSBruce Richardson test_timer_cancel_multicore(void)
941a9de470cSBruce Richardson {
942a9de470cSBruce Richardson 	arm_done = 0;
943a9de470cSBruce Richardson 	timer_producer_ring = rte_ring_create("timer_cancel_queue",
944a9de470cSBruce Richardson 			MAX_TIMERS * 2, rte_socket_id(), 0);
945a9de470cSBruce Richardson 	TEST_ASSERT_NOT_NULL(timer_producer_ring,
946a9de470cSBruce Richardson 			"Unable to reserve memory for ring");
947a9de470cSBruce Richardson 
948a9de470cSBruce Richardson 	rte_eal_remote_launch(_cancel_thread, NULL, test_lcore3);
949a9de470cSBruce Richardson 	rte_eal_remote_launch(_cancel_producer_wrapper, NULL, test_lcore1);
950a9de470cSBruce Richardson 	rte_eal_remote_launch(_cancel_producer_wrapper, NULL, test_lcore2);
951a9de470cSBruce Richardson 
952a9de470cSBruce Richardson 	rte_eal_wait_lcore(test_lcore1);
953a9de470cSBruce Richardson 	rte_eal_wait_lcore(test_lcore2);
954a9de470cSBruce Richardson 	arm_done = 1;
955a9de470cSBruce Richardson 	rte_eal_wait_lcore(test_lcore3);
956a9de470cSBruce Richardson 	rte_ring_free(timer_producer_ring);
957a9de470cSBruce Richardson 
958a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_wait_timer_triggers(30, MAX_TIMERS * 2,
959a9de470cSBruce Richardson 			MAX_TIMERS * 2),
960a9de470cSBruce Richardson 			"Timer triggered count doesn't match arm count");
961a9de470cSBruce Richardson 
962a9de470cSBruce Richardson 	return TEST_SUCCESS;
963a9de470cSBruce Richardson }
964a9de470cSBruce Richardson 
965a9de470cSBruce Richardson static inline int
test_timer_cancel_burst_multicore(void)966a9de470cSBruce Richardson test_timer_cancel_burst_multicore(void)
967a9de470cSBruce Richardson {
968a9de470cSBruce Richardson 	arm_done = 0;
969a9de470cSBruce Richardson 	timer_producer_ring = rte_ring_create("timer_cancel_queue",
970a9de470cSBruce Richardson 			MAX_TIMERS * 2, rte_socket_id(), 0);
971a9de470cSBruce Richardson 	TEST_ASSERT_NOT_NULL(timer_producer_ring,
972a9de470cSBruce Richardson 			"Unable to reserve memory for ring");
973a9de470cSBruce Richardson 
974a9de470cSBruce Richardson 	rte_eal_remote_launch(_cancel_burst_thread, NULL, test_lcore2);
975a9de470cSBruce Richardson 	rte_eal_remote_launch(_cancel_producer_burst_wrapper, NULL,
976a9de470cSBruce Richardson 			test_lcore1);
977a9de470cSBruce Richardson 
978a9de470cSBruce Richardson 	rte_eal_wait_lcore(test_lcore1);
979a9de470cSBruce Richardson 	arm_done = 1;
980a9de470cSBruce Richardson 	rte_eal_wait_lcore(test_lcore2);
981a9de470cSBruce Richardson 	rte_ring_free(timer_producer_ring);
982a9de470cSBruce Richardson 
983a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_wait_timer_triggers(30, MAX_TIMERS,
984a9de470cSBruce Richardson 			MAX_TIMERS),
985a9de470cSBruce Richardson 			"Timer triggered count doesn't match arm count");
986a9de470cSBruce Richardson 
987a9de470cSBruce Richardson 	return TEST_SUCCESS;
988a9de470cSBruce Richardson }
989a9de470cSBruce Richardson 
990a9de470cSBruce Richardson static inline int
test_timer_cancel_random(void)991a9de470cSBruce Richardson test_timer_cancel_random(void)
992a9de470cSBruce Richardson {
993a9de470cSBruce Richardson 	uint64_t i;
994a9de470cSBruce Richardson 	uint64_t events_canceled = 0;
995a9de470cSBruce Richardson 	struct rte_event_timer *ev_tim;
996a9de470cSBruce Richardson 	const struct rte_event_timer tim = {
997a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
998a9de470cSBruce Richardson 		.ev.queue_id = 0,
999a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
1000a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1001a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
1002a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
10032385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(20),
1004a9de470cSBruce Richardson 	};
1005a9de470cSBruce Richardson 
1006a9de470cSBruce Richardson 	for (i = 0; i < MAX_TIMERS; i++) {
1007a9de470cSBruce Richardson 
1008a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_mempool_get(eventdev_test_mempool,
1009a9de470cSBruce Richardson 					(void **)&ev_tim),
1010a9de470cSBruce Richardson 				"mempool alloc failed");
1011a9de470cSBruce Richardson 		*ev_tim = tim;
1012a9de470cSBruce Richardson 		ev_tim->ev.event_ptr = ev_tim;
1013a9de470cSBruce Richardson 
1014a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(rte_event_timer_arm_burst(timdev, &ev_tim,
1015a9de470cSBruce Richardson 					1), 1, "Failed to arm timer %d",
1016a9de470cSBruce Richardson 				rte_errno);
1017a9de470cSBruce Richardson 
1018a9de470cSBruce Richardson 		if (rte_rand() & 1) {
1019a9de470cSBruce Richardson 			rte_delay_us(100 + (i % 5000));
1020a9de470cSBruce Richardson 			TEST_ASSERT_EQUAL(rte_event_timer_cancel_burst(
1021a9de470cSBruce Richardson 						timdev,
1022a9de470cSBruce Richardson 						&ev_tim, 1), 1,
1023a9de470cSBruce Richardson 				"Failed to cancel event timer %d", rte_errno);
1024a9de470cSBruce Richardson 			rte_mempool_put(eventdev_test_mempool, ev_tim);
1025a9de470cSBruce Richardson 			events_canceled++;
1026a9de470cSBruce Richardson 		}
1027a9de470cSBruce Richardson 	}
1028a9de470cSBruce Richardson 
1029a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(_wait_timer_triggers(30, MAX_TIMERS,
1030a9de470cSBruce Richardson 				events_canceled),
1031a9de470cSBruce Richardson 		       "Timer triggered count doesn't match arm, cancel count");
1032a9de470cSBruce Richardson 
1033a9de470cSBruce Richardson 	return TEST_SUCCESS;
1034a9de470cSBruce Richardson }
1035a9de470cSBruce Richardson 
1036a9de470cSBruce Richardson /* Check that the adapter can be created correctly */
1037a9de470cSBruce Richardson static int
adapter_create(void)1038a9de470cSBruce Richardson adapter_create(void)
1039a9de470cSBruce Richardson {
1040a9de470cSBruce Richardson 	int adapter_id = 0;
1041a9de470cSBruce Richardson 	struct rte_event_timer_adapter *adapter, *adapter2;
1042a9de470cSBruce Richardson 
1043a9de470cSBruce Richardson 	struct rte_event_timer_adapter_conf conf = {
1044a9de470cSBruce Richardson 		.event_dev_id = evdev + 1,  // invalid event dev id
1045a9de470cSBruce Richardson 		.timer_adapter_id = adapter_id,
1046a9de470cSBruce Richardson 		.clk_src = RTE_EVENT_TIMER_ADAPTER_CPU_CLK,
1047a9de470cSBruce Richardson 		.timer_tick_ns = NSECPERSEC / 10,
1048a9de470cSBruce Richardson 		.max_tmo_ns = 180 * NSECPERSEC,
1049a9de470cSBruce Richardson 		.nb_timers = MAX_TIMERS,
10502385a7f5SPavan Nikhilesh 		.flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES,
1051a9de470cSBruce Richardson 	};
1052a9de470cSBruce Richardson 	uint32_t caps = 0;
1053a9de470cSBruce Richardson 
1054a9de470cSBruce Richardson 	/* Test invalid conf */
1055a9de470cSBruce Richardson 	adapter = rte_event_timer_adapter_create(&conf);
1056a9de470cSBruce Richardson 	TEST_ASSERT_NULL(adapter, "Created adapter with invalid "
1057a9de470cSBruce Richardson 			"event device id");
1058a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Incorrect errno value for "
1059a9de470cSBruce Richardson 			"invalid event device id");
1060a9de470cSBruce Richardson 
1061a9de470cSBruce Richardson 	/* Test valid conf */
1062a9de470cSBruce Richardson 	conf.event_dev_id = evdev;
1063a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_caps_get(evdev, &caps),
1064a9de470cSBruce Richardson 			"failed to get adapter capabilities");
1065a9de470cSBruce Richardson 	if (!(caps & RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT))
1066a9de470cSBruce Richardson 		adapter = rte_event_timer_adapter_create_ext(&conf,
1067a9de470cSBruce Richardson 				test_port_conf_cb,
1068a9de470cSBruce Richardson 				NULL);
1069a9de470cSBruce Richardson 	else
1070a9de470cSBruce Richardson 		adapter = rte_event_timer_adapter_create(&conf);
1071a9de470cSBruce Richardson 	TEST_ASSERT_NOT_NULL(adapter, "Failed to create adapter with valid "
1072a9de470cSBruce Richardson 			"configuration");
1073a9de470cSBruce Richardson 
1074a9de470cSBruce Richardson 	/* Test existing id */
1075a9de470cSBruce Richardson 	adapter2 = rte_event_timer_adapter_create(&conf);
1076a9de470cSBruce Richardson 	TEST_ASSERT_NULL(adapter2, "Created adapter with in-use id");
1077a9de470cSBruce Richardson 	TEST_ASSERT(rte_errno == EEXIST, "Incorrect errno value for existing "
1078a9de470cSBruce Richardson 			"id");
1079a9de470cSBruce Richardson 
1080a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_free(adapter),
1081a9de470cSBruce Richardson 			"Failed to free adapter");
1082a9de470cSBruce Richardson 
1083a9de470cSBruce Richardson 	return TEST_SUCCESS;
1084a9de470cSBruce Richardson }
1085a9de470cSBruce Richardson 
1086a9de470cSBruce Richardson 
1087a9de470cSBruce Richardson /* Test that adapter can be freed correctly. */
1088a9de470cSBruce Richardson static int
adapter_free(void)1089a9de470cSBruce Richardson adapter_free(void)
1090a9de470cSBruce Richardson {
1091a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_stop(timdev),
1092a9de470cSBruce Richardson 			"Failed to stop adapter");
1093a9de470cSBruce Richardson 
1094a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_free(timdev),
1095a9de470cSBruce Richardson 			"Failed to free valid adapter");
1096a9de470cSBruce Richardson 
1097a9de470cSBruce Richardson 	/* Test free of already freed adapter */
1098a9de470cSBruce Richardson 	TEST_ASSERT_FAIL(rte_event_timer_adapter_free(timdev),
1099a9de470cSBruce Richardson 			"Freed adapter that was already freed");
1100a9de470cSBruce Richardson 
1101a9de470cSBruce Richardson 	/* Test free of null adapter */
1102a9de470cSBruce Richardson 	timdev = NULL;
1103a9de470cSBruce Richardson 	TEST_ASSERT_FAIL(rte_event_timer_adapter_free(timdev),
1104a9de470cSBruce Richardson 			"Freed null adapter");
1105a9de470cSBruce Richardson 
1106a9de470cSBruce Richardson 	rte_mempool_free(eventdev_test_mempool);
1107a9de470cSBruce Richardson 
1108a9de470cSBruce Richardson 	return TEST_SUCCESS;
1109a9de470cSBruce Richardson }
1110a9de470cSBruce Richardson 
1111a9de470cSBruce Richardson /* Test that adapter info can be retrieved and is correct. */
1112a9de470cSBruce Richardson static int
adapter_get_info(void)1113a9de470cSBruce Richardson adapter_get_info(void)
1114a9de470cSBruce Richardson {
1115a9de470cSBruce Richardson 	struct rte_event_timer_adapter_info info;
1116a9de470cSBruce Richardson 
1117a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_get_info(timdev, &info),
1118a9de470cSBruce Richardson 			"Failed to get adapter info");
1119a9de470cSBruce Richardson 
1120a9de470cSBruce Richardson 	if (using_services)
1121a9de470cSBruce Richardson 		TEST_ASSERT_EQUAL(info.event_dev_port_id, 1,
1122a9de470cSBruce Richardson 				"Expected port id = 1, got port id = %d",
1123a9de470cSBruce Richardson 				info.event_dev_port_id);
1124a9de470cSBruce Richardson 
1125a9de470cSBruce Richardson 	return TEST_SUCCESS;
1126a9de470cSBruce Richardson }
1127a9de470cSBruce Richardson 
1128a9de470cSBruce Richardson /* Test adapter lookup via adapter ID. */
1129a9de470cSBruce Richardson static int
adapter_lookup(void)1130a9de470cSBruce Richardson adapter_lookup(void)
1131a9de470cSBruce Richardson {
1132a9de470cSBruce Richardson 	struct rte_event_timer_adapter *adapter;
1133a9de470cSBruce Richardson 
1134a9de470cSBruce Richardson 	adapter = rte_event_timer_adapter_lookup(TEST_ADAPTER_ID);
1135a9de470cSBruce Richardson 	TEST_ASSERT_NOT_NULL(adapter, "Failed to lookup adapter");
1136a9de470cSBruce Richardson 
1137a9de470cSBruce Richardson 	return TEST_SUCCESS;
1138a9de470cSBruce Richardson }
1139a9de470cSBruce Richardson 
1140a9de470cSBruce Richardson static int
adapter_start(void)1141a9de470cSBruce Richardson adapter_start(void)
1142a9de470cSBruce Richardson {
11437d761b07SShijith Thotton 	TEST_ASSERT_SUCCESS(_timdev_setup(180 * NSECPERSEC, NSECPERSEC / 10,
11447d761b07SShijith Thotton 					  RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES),
1145a9de470cSBruce Richardson 			    "Failed to start adapter");
1146d69d0858SPavan Nikhilesh 	TEST_ASSERT_EQUAL(rte_event_timer_adapter_start(timdev), -EALREADY,
1147d69d0858SPavan Nikhilesh 			"Timer adapter started without call to stop.");
1148a9de470cSBruce Richardson 
1149a9de470cSBruce Richardson 	return TEST_SUCCESS;
1150a9de470cSBruce Richardson }
1151a9de470cSBruce Richardson 
1152a9de470cSBruce Richardson /* Test that adapter stops correctly. */
1153a9de470cSBruce Richardson static int
adapter_stop(void)1154a9de470cSBruce Richardson adapter_stop(void)
1155a9de470cSBruce Richardson {
1156a9de470cSBruce Richardson 	struct rte_event_timer_adapter *l_adapter = NULL;
1157a9de470cSBruce Richardson 
1158a9de470cSBruce Richardson 	/* Test adapter stop */
1159a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_stop(timdev),
1160a9de470cSBruce Richardson 			"Failed to stop event adapter");
1161a9de470cSBruce Richardson 
1162a9de470cSBruce Richardson 	TEST_ASSERT_FAIL(rte_event_timer_adapter_stop(l_adapter),
1163a9de470cSBruce Richardson 			"Erroneously stopped null event adapter");
1164a9de470cSBruce Richardson 
1165a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_free(timdev),
1166a9de470cSBruce Richardson 			"Failed to free adapter");
1167a9de470cSBruce Richardson 
1168a9de470cSBruce Richardson 	rte_mempool_free(eventdev_test_mempool);
1169a9de470cSBruce Richardson 
1170a9de470cSBruce Richardson 	return TEST_SUCCESS;
1171a9de470cSBruce Richardson }
1172a9de470cSBruce Richardson 
1173a9de470cSBruce Richardson /* Test increment and reset of ev_enq_count stat */
1174a9de470cSBruce Richardson static int
stat_inc_reset_ev_enq(void)1175a9de470cSBruce Richardson stat_inc_reset_ev_enq(void)
1176a9de470cSBruce Richardson {
1177a9de470cSBruce Richardson 	int ret, i, n;
1178a9de470cSBruce Richardson 	int num_evtims = MAX_TIMERS;
1179a9de470cSBruce Richardson 	struct rte_event_timer *evtims[num_evtims];
1180a9de470cSBruce Richardson 	struct rte_event evs[BATCH_SIZE];
1181a9de470cSBruce Richardson 	struct rte_event_timer_adapter_stats stats;
1182a9de470cSBruce Richardson 	const struct rte_event_timer init_tim = {
1183a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
1184a9de470cSBruce Richardson 		.ev.queue_id = TEST_QUEUE_ID,
1185a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
1186a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1187a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
1188a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
11892385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(5), // expire in .5 sec
1190a9de470cSBruce Richardson 	};
1191a9de470cSBruce Richardson 
1192a9de470cSBruce Richardson 	ret = rte_mempool_get_bulk(eventdev_test_mempool, (void **)evtims,
1193a9de470cSBruce Richardson 				   num_evtims);
1194a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "Failed to get array of timer objs: ret = %d",
1195a9de470cSBruce Richardson 			  ret);
1196a9de470cSBruce Richardson 
1197a9de470cSBruce Richardson 	for (i = 0; i < num_evtims; i++) {
1198a9de470cSBruce Richardson 		*evtims[i] = init_tim;
1199a9de470cSBruce Richardson 		evtims[i]->ev.event_ptr = evtims[i];
1200a9de470cSBruce Richardson 	}
1201a9de470cSBruce Richardson 
1202a9de470cSBruce Richardson 	ret = rte_event_timer_adapter_stats_get(timdev, &stats);
1203a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "Failed to get stats");
1204a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL((int)stats.ev_enq_count, 0, "Stats not clear at "
1205a9de470cSBruce Richardson 			  "startup");
1206a9de470cSBruce Richardson 
1207a9de470cSBruce Richardson 	/* Test with the max value for the adapter */
1208a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(timdev, evtims, num_evtims);
1209a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, num_evtims,
1210a9de470cSBruce Richardson 			  "Failed to arm all event timers: attempted = %d, "
1211a9de470cSBruce Richardson 			  "succeeded = %d, rte_errno = %s",
1212a9de470cSBruce Richardson 			  num_evtims, ret, rte_strerror(rte_errno));
1213a9de470cSBruce Richardson 
1214a9de470cSBruce Richardson 	rte_delay_ms(1000);
1215a9de470cSBruce Richardson 
1216a9de470cSBruce Richardson #define MAX_TRIES num_evtims
1217a9de470cSBruce Richardson 	int sum = 0;
1218a9de470cSBruce Richardson 	int tries = 0;
1219a9de470cSBruce Richardson 	bool done = false;
1220a9de470cSBruce Richardson 	while (!done) {
1221a9de470cSBruce Richardson 		sum += rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs,
1222a9de470cSBruce Richardson 					       RTE_DIM(evs), 10);
1223a9de470cSBruce Richardson 		if (sum >= num_evtims || ++tries >= MAX_TRIES)
1224a9de470cSBruce Richardson 			done = true;
1225a9de470cSBruce Richardson 
1226a9de470cSBruce Richardson 		rte_delay_ms(10);
1227a9de470cSBruce Richardson 	}
1228a9de470cSBruce Richardson 
1229a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(sum, num_evtims, "Expected %d timer expiry events, "
1230a9de470cSBruce Richardson 			  "got %d", num_evtims, sum);
1231a9de470cSBruce Richardson 
1232a9de470cSBruce Richardson 	TEST_ASSERT(tries < MAX_TRIES, "Exceeded max tries");
1233a9de470cSBruce Richardson 
1234a9de470cSBruce Richardson 	rte_delay_ms(100);
1235a9de470cSBruce Richardson 
1236a9de470cSBruce Richardson 	/* Make sure the eventdev is still empty */
1237a9de470cSBruce Richardson 	n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs),
1238a9de470cSBruce Richardson 				      10);
1239a9de470cSBruce Richardson 
1240a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(n, 0, "Dequeued unexpected number of timer expiry "
1241a9de470cSBruce Richardson 			  "events from event device");
1242a9de470cSBruce Richardson 
1243a9de470cSBruce Richardson 	/* Check stats again */
1244a9de470cSBruce Richardson 	ret = rte_event_timer_adapter_stats_get(timdev, &stats);
1245a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "Failed to get stats");
1246a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL((int)stats.ev_enq_count, num_evtims,
1247a9de470cSBruce Richardson 			  "Expected enqueue stat = %d; got %d", num_evtims,
1248a9de470cSBruce Richardson 			  (int)stats.ev_enq_count);
1249a9de470cSBruce Richardson 
1250a9de470cSBruce Richardson 	/* Reset and check again */
1251a9de470cSBruce Richardson 	ret = rte_event_timer_adapter_stats_reset(timdev);
1252a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "Failed to reset stats");
1253a9de470cSBruce Richardson 
1254a9de470cSBruce Richardson 	ret = rte_event_timer_adapter_stats_get(timdev, &stats);
1255a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "Failed to get stats");
1256a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL((int)stats.ev_enq_count, 0,
1257a9de470cSBruce Richardson 			  "Expected enqueue stat = %d; got %d", 0,
1258a9de470cSBruce Richardson 			  (int)stats.ev_enq_count);
1259a9de470cSBruce Richardson 
1260a9de470cSBruce Richardson 	rte_mempool_put_bulk(eventdev_test_mempool, (void **)evtims,
1261a9de470cSBruce Richardson 			     num_evtims);
1262a9de470cSBruce Richardson 
1263a9de470cSBruce Richardson 	return TEST_SUCCESS;
1264a9de470cSBruce Richardson }
1265a9de470cSBruce Richardson 
1266a9de470cSBruce Richardson /* Test various cases in arming timers */
1267a9de470cSBruce Richardson static int
event_timer_arm(void)1268a9de470cSBruce Richardson event_timer_arm(void)
1269a9de470cSBruce Richardson {
1270a9de470cSBruce Richardson 	uint16_t n;
1271a9de470cSBruce Richardson 	int ret;
1272a9de470cSBruce Richardson 	struct rte_event_timer_adapter *adapter = timdev;
1273a9de470cSBruce Richardson 	struct rte_event_timer *evtim = NULL;
1274a9de470cSBruce Richardson 	struct rte_event evs[BATCH_SIZE];
1275a9de470cSBruce Richardson 	const struct rte_event_timer init_tim = {
1276a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
1277a9de470cSBruce Richardson 		.ev.queue_id = TEST_QUEUE_ID,
1278a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
1279a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1280a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
1281a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
12822385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(5), // expire in .5 sec
1283a9de470cSBruce Richardson 	};
1284a9de470cSBruce Richardson 
1285a9de470cSBruce Richardson 	rte_mempool_get(eventdev_test_mempool, (void **)&evtim);
1286a9de470cSBruce Richardson 	if (evtim == NULL) {
1287a9de470cSBruce Richardson 		/* Failed to get an event timer object */
1288a9de470cSBruce Richardson 		return TEST_FAILED;
1289a9de470cSBruce Richardson 	}
1290a9de470cSBruce Richardson 
1291a9de470cSBruce Richardson 	/* Set up a timer */
1292a9de470cSBruce Richardson 	*evtim = init_tim;
1293a9de470cSBruce Richardson 	evtim->ev.event_ptr = evtim;
1294a9de470cSBruce Richardson 
1295a9de470cSBruce Richardson 	/* Test single timer arm succeeds */
1296a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(adapter, &evtim, 1);
1297a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 1, "Failed to arm event timer: %s\n",
1298a9de470cSBruce Richardson 			  rte_strerror(rte_errno));
1299a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(evtim->state, RTE_EVENT_TIMER_ARMED, "Event timer "
1300a9de470cSBruce Richardson 			  "in incorrect state");
1301a9de470cSBruce Richardson 
1302a9de470cSBruce Richardson 	/* Test arm of armed timer fails */
1303a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(adapter, &evtim, 1);
1304a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "expected return value from "
1305a9de470cSBruce Richardson 			  "rte_event_timer_arm_burst: 0, got: %d", ret);
1306a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_errno, EALREADY, "Unexpected rte_errno value "
1307a9de470cSBruce Richardson 			  "after arming already armed timer");
1308a9de470cSBruce Richardson 
1309a9de470cSBruce Richardson 	/* Let timer expire */
1310a9de470cSBruce Richardson 	rte_delay_ms(1000);
1311a9de470cSBruce Richardson 
1312a9de470cSBruce Richardson 	n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0);
1313a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(n, 1, "Failed to dequeue expected number of expiry "
1314a9de470cSBruce Richardson 			  "events from event device");
1315a9de470cSBruce Richardson 
1316a9de470cSBruce Richardson 	rte_mempool_put(eventdev_test_mempool, evtim);
1317a9de470cSBruce Richardson 
1318a9de470cSBruce Richardson 	return TEST_SUCCESS;
1319a9de470cSBruce Richardson }
1320a9de470cSBruce Richardson 
1321a9de470cSBruce Richardson /* This test checks that repeated references to the same event timer in the
1322a9de470cSBruce Richardson  * arm request work as expected; only the first one through should succeed.
1323a9de470cSBruce Richardson  */
1324a9de470cSBruce Richardson static int
event_timer_arm_double(void)1325a9de470cSBruce Richardson event_timer_arm_double(void)
1326a9de470cSBruce Richardson {
1327a9de470cSBruce Richardson 	uint16_t n;
1328a9de470cSBruce Richardson 	int ret;
1329a9de470cSBruce Richardson 	struct rte_event_timer_adapter *adapter = timdev;
1330a9de470cSBruce Richardson 	struct rte_event_timer *evtim = NULL;
1331a9de470cSBruce Richardson 	struct rte_event evs[BATCH_SIZE];
1332a9de470cSBruce Richardson 	const struct rte_event_timer init_tim = {
1333a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
1334a9de470cSBruce Richardson 		.ev.queue_id = TEST_QUEUE_ID,
1335a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
1336a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1337a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
1338a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
13392385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(5), // expire in .5 sec
1340a9de470cSBruce Richardson 	};
1341a9de470cSBruce Richardson 
1342a9de470cSBruce Richardson 	rte_mempool_get(eventdev_test_mempool, (void **)&evtim);
1343a9de470cSBruce Richardson 	if (evtim == NULL) {
1344a9de470cSBruce Richardson 		/* Failed to get an event timer object */
1345a9de470cSBruce Richardson 		return TEST_FAILED;
1346a9de470cSBruce Richardson 	}
1347a9de470cSBruce Richardson 
1348a9de470cSBruce Richardson 	/* Set up a timer */
1349a9de470cSBruce Richardson 	*evtim = init_tim;
1350a9de470cSBruce Richardson 	evtim->ev.event_ptr = evtim;
1351a9de470cSBruce Richardson 
1352a9de470cSBruce Richardson 	struct rte_event_timer *evtim_arr[] = {evtim, evtim};
1353a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(adapter, evtim_arr, RTE_DIM(evtim_arr));
1354a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 1, "Unexpected return value from "
1355a9de470cSBruce Richardson 			  "rte_event_timer_arm_burst");
1356a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_errno, EALREADY, "Unexpected rte_errno value "
1357a9de470cSBruce Richardson 			  "after double-arm");
1358a9de470cSBruce Richardson 
1359a9de470cSBruce Richardson 	/* Let timer expire */
1360a9de470cSBruce Richardson 	rte_delay_ms(600);
1361a9de470cSBruce Richardson 
1362a9de470cSBruce Richardson 	n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0);
1363a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(n, 1, "Dequeued incorrect number of expiry events - "
1364a9de470cSBruce Richardson 			  "expected: 1, actual: %d", n);
1365a9de470cSBruce Richardson 
1366a9de470cSBruce Richardson 	rte_mempool_put(eventdev_test_mempool, evtim);
1367a9de470cSBruce Richardson 
1368a9de470cSBruce Richardson 	return TEST_SUCCESS;
1369a9de470cSBruce Richardson }
1370a9de470cSBruce Richardson 
1371a9de470cSBruce Richardson /* Test the timer expiry event is generated at the expected time.  */
1372a9de470cSBruce Richardson static int
event_timer_arm_expiry(void)1373a9de470cSBruce Richardson event_timer_arm_expiry(void)
1374a9de470cSBruce Richardson {
1375a9de470cSBruce Richardson 	uint16_t n;
1376a9de470cSBruce Richardson 	int ret;
1377a9de470cSBruce Richardson 	struct rte_event_timer_adapter *adapter = timdev;
1378a9de470cSBruce Richardson 	struct rte_event_timer *evtim = NULL;
1379a9de470cSBruce Richardson 	struct rte_event_timer *evtim2 = NULL;
1380a9de470cSBruce Richardson 	struct rte_event evs[BATCH_SIZE];
1381a9de470cSBruce Richardson 	const struct rte_event_timer init_tim = {
1382a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
1383a9de470cSBruce Richardson 		.ev.queue_id = TEST_QUEUE_ID,
1384a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
1385a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1386a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
1387a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
1388a9de470cSBruce Richardson 	};
1389a9de470cSBruce Richardson 
1390a9de470cSBruce Richardson 	rte_mempool_get(eventdev_test_mempool, (void **)&evtim);
1391a9de470cSBruce Richardson 	if (evtim == NULL) {
1392a9de470cSBruce Richardson 		/* Failed to get an event timer object */
1393a9de470cSBruce Richardson 		return TEST_FAILED;
1394a9de470cSBruce Richardson 	}
1395a9de470cSBruce Richardson 
1396a9de470cSBruce Richardson 	/* Set up an event timer */
1397a9de470cSBruce Richardson 	*evtim = init_tim;
13982385a7f5SPavan Nikhilesh 	evtim->timeout_ticks = CALC_TICKS(30),	// expire in 3 secs
1399a9de470cSBruce Richardson 	evtim->ev.event_ptr = evtim;
1400a9de470cSBruce Richardson 
1401a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(adapter, &evtim, 1);
1402a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 1, "Failed to arm event timer: %s",
1403a9de470cSBruce Richardson 			  rte_strerror(rte_errno));
1404a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(evtim->state, RTE_EVENT_TIMER_ARMED, "Event "
1405a9de470cSBruce Richardson 			  "timer in incorrect state");
1406a9de470cSBruce Richardson 
1407a9de470cSBruce Richardson 	rte_delay_ms(2999);
1408a9de470cSBruce Richardson 
1409a9de470cSBruce Richardson 	n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0);
1410a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(n, 0, "Dequeued unexpected timer expiry event");
1411a9de470cSBruce Richardson 
1412a9de470cSBruce Richardson 	/* Delay 100 ms to account for the adapter tick window - should let us
1413a9de470cSBruce Richardson 	 * dequeue one event
1414a9de470cSBruce Richardson 	 */
1415a9de470cSBruce Richardson 	rte_delay_ms(100);
1416a9de470cSBruce Richardson 
1417a9de470cSBruce Richardson 	n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0);
1418a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(n, 1, "Dequeued incorrect number (%d) of timer "
1419a9de470cSBruce Richardson 			  "expiry events", n);
1420a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(evs[0].event_type, RTE_EVENT_TYPE_TIMER,
1421a9de470cSBruce Richardson 			  "Dequeued unexpected type of event");
1422a9de470cSBruce Richardson 
1423a9de470cSBruce Richardson 	/* Check that we recover the original event timer and then free it */
1424a9de470cSBruce Richardson 	evtim2 = evs[0].event_ptr;
1425a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(evtim, evtim2,
1426a9de470cSBruce Richardson 			  "Failed to recover pointer to original event timer");
1427a9de470cSBruce Richardson 	rte_mempool_put(eventdev_test_mempool, evtim2);
1428a9de470cSBruce Richardson 
1429a9de470cSBruce Richardson 	return TEST_SUCCESS;
1430a9de470cSBruce Richardson }
1431a9de470cSBruce Richardson 
1432a9de470cSBruce Richardson /* Check that rearming a timer works as expected. */
1433a9de470cSBruce Richardson static int
event_timer_arm_rearm(void)1434a9de470cSBruce Richardson event_timer_arm_rearm(void)
1435a9de470cSBruce Richardson {
1436a9de470cSBruce Richardson 	uint16_t n;
1437a9de470cSBruce Richardson 	int ret;
1438a9de470cSBruce Richardson 	struct rte_event_timer *evtim = NULL;
1439a9de470cSBruce Richardson 	struct rte_event_timer *evtim2 = NULL;
1440a9de470cSBruce Richardson 	struct rte_event evs[BATCH_SIZE];
1441a9de470cSBruce Richardson 	const struct rte_event_timer init_tim = {
1442a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
1443a9de470cSBruce Richardson 		.ev.queue_id = TEST_QUEUE_ID,
1444a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
1445a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1446a9de470cSBruce Richardson 		.ev.event_type = RTE_EVENT_TYPE_TIMER,
1447a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
1448a9de470cSBruce Richardson 	};
1449a9de470cSBruce Richardson 
1450a9de470cSBruce Richardson 	rte_mempool_get(eventdev_test_mempool, (void **)&evtim);
1451a9de470cSBruce Richardson 	if (evtim == NULL) {
1452a9de470cSBruce Richardson 		/* Failed to get an event timer object */
1453a9de470cSBruce Richardson 		return TEST_FAILED;
1454a9de470cSBruce Richardson 	}
1455a9de470cSBruce Richardson 
1456a9de470cSBruce Richardson 	/* Set up a timer */
1457a9de470cSBruce Richardson 	*evtim = init_tim;
14582385a7f5SPavan Nikhilesh 	evtim->timeout_ticks = CALC_TICKS(1);  // expire in 0.1 sec
1459a9de470cSBruce Richardson 	evtim->ev.event_ptr = evtim;
1460a9de470cSBruce Richardson 
1461a9de470cSBruce Richardson 	/* Arm it */
1462a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(timdev, &evtim, 1);
1463a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 1, "Failed to arm event timer: %s\n",
1464a9de470cSBruce Richardson 			  rte_strerror(rte_errno));
1465a9de470cSBruce Richardson 
1466a9de470cSBruce Richardson 	/* Add 100ms to account for the adapter tick window */
1467a9de470cSBruce Richardson 	rte_delay_ms(100 + 100);
1468a9de470cSBruce Richardson 
1469a9de470cSBruce Richardson 	n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0);
1470a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(n, 1, "Failed to dequeue expected number of expiry "
1471a9de470cSBruce Richardson 			  "events from event device");
1472a9de470cSBruce Richardson 
1473a9de470cSBruce Richardson 	/* Recover the timer through the event that was dequeued. */
1474a9de470cSBruce Richardson 	evtim2 = evs[0].event_ptr;
1475a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(evtim, evtim2,
1476a9de470cSBruce Richardson 			  "Failed to recover pointer to original event timer");
1477a9de470cSBruce Richardson 
1478a9de470cSBruce Richardson 	/* Need to reset state in case implementation can't do it */
1479a9de470cSBruce Richardson 	evtim2->state = RTE_EVENT_TIMER_NOT_ARMED;
1480a9de470cSBruce Richardson 
1481a9de470cSBruce Richardson 	/* Rearm it */
1482a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(timdev, &evtim2, 1);
1483a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 1, "Failed to arm event timer: %s\n",
1484a9de470cSBruce Richardson 			  rte_strerror(rte_errno));
1485a9de470cSBruce Richardson 
1486a9de470cSBruce Richardson 	/* Add 100ms to account for the adapter tick window */
1487a9de470cSBruce Richardson 	rte_delay_ms(100 + 100);
1488a9de470cSBruce Richardson 
1489a9de470cSBruce Richardson 	n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0);
1490a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(n, 1, "Failed to dequeue expected number of expiry "
1491a9de470cSBruce Richardson 			  "events from event device");
1492a9de470cSBruce Richardson 
1493a9de470cSBruce Richardson 	/* Free it */
1494a9de470cSBruce Richardson 	evtim2 = evs[0].event_ptr;
1495a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(evtim, evtim2,
1496a9de470cSBruce Richardson 			  "Failed to recover pointer to original event timer");
1497a9de470cSBruce Richardson 	rte_mempool_put(eventdev_test_mempool, evtim2);
1498a9de470cSBruce Richardson 
1499a9de470cSBruce Richardson 	return TEST_SUCCESS;
1500a9de470cSBruce Richardson }
1501a9de470cSBruce Richardson 
1502a9de470cSBruce Richardson /* Check that the adapter handles the max specified number of timers as
1503a9de470cSBruce Richardson  * expected.
1504a9de470cSBruce Richardson  */
1505a9de470cSBruce Richardson static int
event_timer_arm_max(void)1506a9de470cSBruce Richardson event_timer_arm_max(void)
1507a9de470cSBruce Richardson {
1508a9de470cSBruce Richardson 	int ret, i, n;
1509a9de470cSBruce Richardson 	int num_evtims = MAX_TIMERS;
1510a9de470cSBruce Richardson 	struct rte_event_timer *evtims[num_evtims];
1511a9de470cSBruce Richardson 	struct rte_event evs[BATCH_SIZE];
1512a9de470cSBruce Richardson 	const struct rte_event_timer init_tim = {
1513a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
1514a9de470cSBruce Richardson 		.ev.queue_id = TEST_QUEUE_ID,
1515a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
1516a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1517a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
1518a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
15192385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(5), // expire in .5 sec
1520a9de470cSBruce Richardson 	};
1521a9de470cSBruce Richardson 
1522a9de470cSBruce Richardson 	ret = rte_mempool_get_bulk(eventdev_test_mempool, (void **)evtims,
1523a9de470cSBruce Richardson 				   num_evtims);
1524a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "Failed to get array of timer objs: ret = %d",
1525a9de470cSBruce Richardson 			  ret);
1526a9de470cSBruce Richardson 
1527a9de470cSBruce Richardson 	for (i = 0; i < num_evtims; i++) {
1528a9de470cSBruce Richardson 		*evtims[i] = init_tim;
1529a9de470cSBruce Richardson 		evtims[i]->ev.event_ptr = evtims[i];
1530a9de470cSBruce Richardson 	}
1531a9de470cSBruce Richardson 
1532a9de470cSBruce Richardson 	/* Test with the max value for the adapter */
1533a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(timdev, evtims, num_evtims);
1534a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, num_evtims,
1535a9de470cSBruce Richardson 			  "Failed to arm all event timers: attempted = %d, "
1536a9de470cSBruce Richardson 			  "succeeded = %d, rte_errno = %s",
1537a9de470cSBruce Richardson 			  num_evtims, ret, rte_strerror(rte_errno));
1538a9de470cSBruce Richardson 
1539a9de470cSBruce Richardson 	rte_delay_ms(1000);
1540a9de470cSBruce Richardson 
1541a9de470cSBruce Richardson #define MAX_TRIES num_evtims
1542a9de470cSBruce Richardson 	int sum = 0;
1543a9de470cSBruce Richardson 	int tries = 0;
1544a9de470cSBruce Richardson 	bool done = false;
1545a9de470cSBruce Richardson 	while (!done) {
1546a9de470cSBruce Richardson 		sum += rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs,
1547a9de470cSBruce Richardson 					       RTE_DIM(evs), 10);
1548a9de470cSBruce Richardson 		if (sum >= num_evtims || ++tries >= MAX_TRIES)
1549a9de470cSBruce Richardson 			done = true;
1550a9de470cSBruce Richardson 
1551a9de470cSBruce Richardson 		rte_delay_ms(10);
1552a9de470cSBruce Richardson 	}
1553a9de470cSBruce Richardson 
1554a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(sum, num_evtims, "Expected %d timer expiry events, "
1555a9de470cSBruce Richardson 			  "got %d", num_evtims, sum);
1556a9de470cSBruce Richardson 
1557a9de470cSBruce Richardson 	TEST_ASSERT(tries < MAX_TRIES, "Exceeded max tries");
1558a9de470cSBruce Richardson 
1559a9de470cSBruce Richardson 	rte_delay_ms(100);
1560a9de470cSBruce Richardson 
1561a9de470cSBruce Richardson 	/* Make sure the eventdev is still empty */
1562a9de470cSBruce Richardson 	n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs),
1563a9de470cSBruce Richardson 				    10);
1564a9de470cSBruce Richardson 
1565a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(n, 0, "Dequeued unexpected number of timer expiry "
1566a9de470cSBruce Richardson 			  "events from event device");
1567a9de470cSBruce Richardson 
1568a9de470cSBruce Richardson 	rte_mempool_put_bulk(eventdev_test_mempool, (void **)evtims,
1569a9de470cSBruce Richardson 			     num_evtims);
1570a9de470cSBruce Richardson 
1571a9de470cSBruce Richardson 	return TEST_SUCCESS;
1572a9de470cSBruce Richardson }
1573a9de470cSBruce Richardson 
1574a9de470cSBruce Richardson /* Check that creating an event timer with incorrect event sched type fails. */
1575a9de470cSBruce Richardson static int
event_timer_arm_invalid_sched_type(void)1576a9de470cSBruce Richardson event_timer_arm_invalid_sched_type(void)
1577a9de470cSBruce Richardson {
1578a9de470cSBruce Richardson 	int ret;
1579a9de470cSBruce Richardson 	struct rte_event_timer *evtim = NULL;
1580a9de470cSBruce Richardson 	const struct rte_event_timer init_tim = {
1581a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
1582a9de470cSBruce Richardson 		.ev.queue_id = TEST_QUEUE_ID,
1583a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
1584a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1585a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
1586a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
15872385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(5), // expire in .5 sec
1588a9de470cSBruce Richardson 	};
1589a9de470cSBruce Richardson 
1590a9de470cSBruce Richardson 	if (!using_services)
1591a9de470cSBruce Richardson 		return -ENOTSUP;
1592a9de470cSBruce Richardson 
1593a9de470cSBruce Richardson 	rte_mempool_get(eventdev_test_mempool, (void **)&evtim);
1594a9de470cSBruce Richardson 	if (evtim == NULL) {
1595a9de470cSBruce Richardson 		/* Failed to get an event timer object */
1596a9de470cSBruce Richardson 		return TEST_FAILED;
1597a9de470cSBruce Richardson 	}
1598a9de470cSBruce Richardson 
1599a9de470cSBruce Richardson 	*evtim = init_tim;
1600a9de470cSBruce Richardson 	evtim->ev.event_ptr = evtim;
1601a9de470cSBruce Richardson 	evtim->ev.sched_type = RTE_SCHED_TYPE_PARALLEL; // bad sched type
1602a9de470cSBruce Richardson 
1603a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(timdev, &evtim, 1);
1604a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "Expected to fail timer arm with invalid "
1605a9de470cSBruce Richardson 			  "sched type, but didn't");
1606a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Unexpected rte_errno value after"
1607a9de470cSBruce Richardson 			  " arm fail with invalid queue");
1608a9de470cSBruce Richardson 
1609a9de470cSBruce Richardson 	rte_mempool_put(eventdev_test_mempool, &evtim);
1610a9de470cSBruce Richardson 
1611a9de470cSBruce Richardson 	return TEST_SUCCESS;
1612a9de470cSBruce Richardson }
1613a9de470cSBruce Richardson 
1614a9de470cSBruce Richardson /* Check that creating an event timer with a timeout value that is too small or
1615a9de470cSBruce Richardson  * too big fails.
1616a9de470cSBruce Richardson  */
1617a9de470cSBruce Richardson static int
event_timer_arm_invalid_timeout(void)1618a9de470cSBruce Richardson event_timer_arm_invalid_timeout(void)
1619a9de470cSBruce Richardson {
1620a9de470cSBruce Richardson 	int ret;
1621a9de470cSBruce Richardson 	struct rte_event_timer *evtim = NULL;
1622a9de470cSBruce Richardson 	const struct rte_event_timer init_tim = {
1623a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
1624a9de470cSBruce Richardson 		.ev.queue_id = TEST_QUEUE_ID,
1625a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
1626a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1627a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
1628a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
16292385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(5), // expire in .5 sec
1630a9de470cSBruce Richardson 	};
1631a9de470cSBruce Richardson 
1632a9de470cSBruce Richardson 	rte_mempool_get(eventdev_test_mempool, (void **)&evtim);
1633a9de470cSBruce Richardson 	if (evtim == NULL) {
1634a9de470cSBruce Richardson 		/* Failed to get an event timer object */
1635a9de470cSBruce Richardson 		return TEST_FAILED;
1636a9de470cSBruce Richardson 	}
1637a9de470cSBruce Richardson 
1638a9de470cSBruce Richardson 	*evtim = init_tim;
1639a9de470cSBruce Richardson 	evtim->ev.event_ptr = evtim;
1640a9de470cSBruce Richardson 	evtim->timeout_ticks = 0;  // timeout too small
1641a9de470cSBruce Richardson 
1642a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(timdev, &evtim, 1);
1643a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "Expected to fail timer arm with invalid "
1644a9de470cSBruce Richardson 			  "timeout, but didn't");
1645a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Unexpected rte_errno value after"
1646a9de470cSBruce Richardson 			  " arm fail with invalid timeout");
1647a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(evtim->state, RTE_EVENT_TIMER_ERROR_TOOEARLY,
1648a9de470cSBruce Richardson 			  "Unexpected event timer state");
1649a9de470cSBruce Richardson 
1650a9de470cSBruce Richardson 	*evtim = init_tim;
1651a9de470cSBruce Richardson 	evtim->ev.event_ptr = evtim;
16522385a7f5SPavan Nikhilesh 	evtim->timeout_ticks = CALC_TICKS(1801);  // timeout too big
1653a9de470cSBruce Richardson 
1654a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(timdev, &evtim, 1);
1655a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "Expected to fail timer arm with invalid "
1656a9de470cSBruce Richardson 			  "timeout, but didn't");
1657a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Unexpected rte_errno value after"
1658a9de470cSBruce Richardson 			  " arm fail with invalid timeout");
1659a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(evtim->state, RTE_EVENT_TIMER_ERROR_TOOLATE,
1660a9de470cSBruce Richardson 			  "Unexpected event timer state");
1661a9de470cSBruce Richardson 
1662a9de470cSBruce Richardson 	rte_mempool_put(eventdev_test_mempool, evtim);
1663a9de470cSBruce Richardson 
1664a9de470cSBruce Richardson 	return TEST_SUCCESS;
1665a9de470cSBruce Richardson }
1666a9de470cSBruce Richardson 
1667a9de470cSBruce Richardson static int
event_timer_cancel(void)1668a9de470cSBruce Richardson event_timer_cancel(void)
1669a9de470cSBruce Richardson {
1670a9de470cSBruce Richardson 	uint16_t n;
1671a9de470cSBruce Richardson 	int ret;
1672a9de470cSBruce Richardson 	struct rte_event_timer_adapter *adapter = timdev;
1673a9de470cSBruce Richardson 	struct rte_event_timer *evtim = NULL;
1674a9de470cSBruce Richardson 	struct rte_event evs[BATCH_SIZE];
1675a9de470cSBruce Richardson 	const struct rte_event_timer init_tim = {
1676a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
1677a9de470cSBruce Richardson 		.ev.queue_id = TEST_QUEUE_ID,
1678a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
1679a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1680a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
1681a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
1682a9de470cSBruce Richardson 	};
1683a9de470cSBruce Richardson 
1684a9de470cSBruce Richardson 	rte_mempool_get(eventdev_test_mempool, (void **)&evtim);
1685a9de470cSBruce Richardson 	if (evtim == NULL) {
1686a9de470cSBruce Richardson 		/* Failed to get an event timer object */
1687a9de470cSBruce Richardson 		return TEST_FAILED;
1688a9de470cSBruce Richardson 	}
1689a9de470cSBruce Richardson 
1690a9de470cSBruce Richardson 	/* Check that cancelling an uninited timer fails */
1691a9de470cSBruce Richardson 	ret = rte_event_timer_cancel_burst(adapter, &evtim, 1);
1692a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "Succeeded unexpectedly in canceling "
1693a9de470cSBruce Richardson 			  "uninited timer");
1694a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Unexpected rte_errno value after "
1695a9de470cSBruce Richardson 			  "cancelling uninited timer");
1696a9de470cSBruce Richardson 
1697a9de470cSBruce Richardson 	/* Set up a timer */
1698a9de470cSBruce Richardson 	*evtim = init_tim;
1699a9de470cSBruce Richardson 	evtim->ev.event_ptr = evtim;
17002385a7f5SPavan Nikhilesh 	evtim->timeout_ticks = CALC_TICKS(30);  // expire in 3 sec
1701a9de470cSBruce Richardson 
1702a9de470cSBruce Richardson 	/* Check that cancelling an inited but unarmed timer fails */
1703a9de470cSBruce Richardson 	ret = rte_event_timer_cancel_burst(adapter, &evtim, 1);
1704a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 0, "Succeeded unexpectedly in canceling "
1705a9de470cSBruce Richardson 			  "unarmed timer");
1706a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Unexpected rte_errno value after "
1707a9de470cSBruce Richardson 			  "cancelling unarmed timer");
1708a9de470cSBruce Richardson 
1709a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(adapter, &evtim, 1);
1710a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 1, "Failed to arm event timer: %s\n",
1711a9de470cSBruce Richardson 			  rte_strerror(rte_errno));
1712a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(evtim->state, RTE_EVENT_TIMER_ARMED,
1713a9de470cSBruce Richardson 			  "evtim in incorrect state");
1714a9de470cSBruce Richardson 
1715a9de470cSBruce Richardson 	/* Delay 1 sec */
1716a9de470cSBruce Richardson 	rte_delay_ms(1000);
1717a9de470cSBruce Richardson 
1718a9de470cSBruce Richardson 	ret = rte_event_timer_cancel_burst(adapter, &evtim, 1);
1719a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 1, "Failed to cancel event_timer: %s\n",
1720a9de470cSBruce Richardson 			  rte_strerror(rte_errno));
1721a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(evtim->state, RTE_EVENT_TIMER_CANCELED,
1722a9de470cSBruce Richardson 			  "evtim in incorrect state");
1723a9de470cSBruce Richardson 
1724a9de470cSBruce Richardson 	rte_delay_ms(3000);
1725a9de470cSBruce Richardson 
1726a9de470cSBruce Richardson 	/* Make sure that no expiry event was generated */
1727a9de470cSBruce Richardson 	n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0);
1728a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(n, 0, "Dequeued unexpected timer expiry event\n");
1729a9de470cSBruce Richardson 
1730a9de470cSBruce Richardson 	rte_mempool_put(eventdev_test_mempool, evtim);
1731a9de470cSBruce Richardson 
1732a9de470cSBruce Richardson 	return TEST_SUCCESS;
1733a9de470cSBruce Richardson }
1734a9de470cSBruce Richardson 
1735a9de470cSBruce Richardson static int
event_timer_cancel_double(void)1736a9de470cSBruce Richardson event_timer_cancel_double(void)
1737a9de470cSBruce Richardson {
1738a9de470cSBruce Richardson 	uint16_t n;
1739a9de470cSBruce Richardson 	int ret;
1740a9de470cSBruce Richardson 	struct rte_event_timer_adapter *adapter = timdev;
1741a9de470cSBruce Richardson 	struct rte_event_timer *evtim = NULL;
1742a9de470cSBruce Richardson 	struct rte_event evs[BATCH_SIZE];
1743a9de470cSBruce Richardson 	const struct rte_event_timer init_tim = {
1744a9de470cSBruce Richardson 		.ev.op = RTE_EVENT_OP_NEW,
1745a9de470cSBruce Richardson 		.ev.queue_id = TEST_QUEUE_ID,
1746a9de470cSBruce Richardson 		.ev.sched_type = RTE_SCHED_TYPE_ATOMIC,
1747a9de470cSBruce Richardson 		.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1748a9de470cSBruce Richardson 		.ev.event_type =  RTE_EVENT_TYPE_TIMER,
1749a9de470cSBruce Richardson 		.state = RTE_EVENT_TIMER_NOT_ARMED,
17502385a7f5SPavan Nikhilesh 		.timeout_ticks = CALC_TICKS(5), // expire in .5 sec
1751a9de470cSBruce Richardson 	};
1752a9de470cSBruce Richardson 
1753a9de470cSBruce Richardson 	rte_mempool_get(eventdev_test_mempool, (void **)&evtim);
1754a9de470cSBruce Richardson 	if (evtim == NULL) {
1755a9de470cSBruce Richardson 		/* Failed to get an event timer object */
1756a9de470cSBruce Richardson 		return TEST_FAILED;
1757a9de470cSBruce Richardson 	}
1758a9de470cSBruce Richardson 
1759a9de470cSBruce Richardson 	/* Set up a timer */
1760a9de470cSBruce Richardson 	*evtim = init_tim;
1761a9de470cSBruce Richardson 	evtim->ev.event_ptr = evtim;
17622385a7f5SPavan Nikhilesh 	evtim->timeout_ticks = CALC_TICKS(30);  // expire in 3 sec
1763a9de470cSBruce Richardson 
1764a9de470cSBruce Richardson 	ret = rte_event_timer_arm_burst(adapter, &evtim, 1);
1765a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 1, "Failed to arm event timer: %s\n",
1766a9de470cSBruce Richardson 			  rte_strerror(rte_errno));
1767a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(evtim->state, RTE_EVENT_TIMER_ARMED,
1768a9de470cSBruce Richardson 			  "timer in unexpected state");
1769a9de470cSBruce Richardson 
1770a9de470cSBruce Richardson 	/* Now, test that referencing the same timer twice in the same call
1771a9de470cSBruce Richardson 	 * fails
1772a9de470cSBruce Richardson 	 */
1773a9de470cSBruce Richardson 	struct rte_event_timer *evtim_arr[] = {evtim, evtim};
1774a9de470cSBruce Richardson 	ret = rte_event_timer_cancel_burst(adapter, evtim_arr,
1775a9de470cSBruce Richardson 					   RTE_DIM(evtim_arr));
1776a9de470cSBruce Richardson 
1777a9de470cSBruce Richardson 	/* Two requests to cancel same timer, only one should succeed */
1778a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(ret, 1, "Succeeded unexpectedly in canceling timer "
1779a9de470cSBruce Richardson 			  "twice");
1780a9de470cSBruce Richardson 
1781a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(rte_errno, EALREADY, "Unexpected rte_errno value "
1782a9de470cSBruce Richardson 			  "after double-cancel: rte_errno = %d", rte_errno);
1783a9de470cSBruce Richardson 
1784a9de470cSBruce Richardson 	rte_delay_ms(3000);
1785a9de470cSBruce Richardson 
1786a9de470cSBruce Richardson 	/* Still make sure that no expiry event was generated */
1787a9de470cSBruce Richardson 	n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0);
1788a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(n, 0, "Dequeued unexpected timer expiry event\n");
1789a9de470cSBruce Richardson 
1790a9de470cSBruce Richardson 	rte_mempool_put(eventdev_test_mempool, evtim);
1791a9de470cSBruce Richardson 
1792a9de470cSBruce Richardson 	return TEST_SUCCESS;
1793a9de470cSBruce Richardson }
1794a9de470cSBruce Richardson 
1795a9de470cSBruce Richardson /* Check that event timer adapter tick resolution works as expected by testing
1796a9de470cSBruce Richardson  * the number of adapter ticks that occur within a particular time interval.
1797a9de470cSBruce Richardson  */
1798a9de470cSBruce Richardson static int
adapter_tick_resolution(void)1799a9de470cSBruce Richardson adapter_tick_resolution(void)
1800a9de470cSBruce Richardson {
1801a9de470cSBruce Richardson 	struct rte_event_timer_adapter_stats stats;
1802a9de470cSBruce Richardson 	uint64_t adapter_tick_count;
1803a9de470cSBruce Richardson 
1804a9de470cSBruce Richardson 	/* Only run this test in the software driver case */
1805a9de470cSBruce Richardson 	if (!using_services)
1806a9de470cSBruce Richardson 		return -ENOTSUP;
1807a9de470cSBruce Richardson 
1808a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_stats_reset(timdev),
1809a9de470cSBruce Richardson 				"Failed to reset stats");
1810a9de470cSBruce Richardson 
1811a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_stats_get(timdev,
1812a9de470cSBruce Richardson 			&stats), "Failed to get adapter stats");
1813a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(stats.adapter_tick_count, 0, "Adapter tick count "
1814a9de470cSBruce Richardson 			"not zeroed out");
1815a9de470cSBruce Richardson 
1816a9de470cSBruce Richardson 	/* Delay 1 second; should let at least 10 ticks occur with the default
1817a9de470cSBruce Richardson 	 * adapter configuration used by this test.
1818a9de470cSBruce Richardson 	 */
1819a9de470cSBruce Richardson 	rte_delay_ms(1000);
1820a9de470cSBruce Richardson 
1821a9de470cSBruce Richardson 	TEST_ASSERT_SUCCESS(rte_event_timer_adapter_stats_get(timdev,
1822a9de470cSBruce Richardson 			&stats), "Failed to get adapter stats");
1823a9de470cSBruce Richardson 
1824a9de470cSBruce Richardson 	adapter_tick_count = stats.adapter_tick_count;
1825a9de470cSBruce Richardson 	TEST_ASSERT(adapter_tick_count >= 10 && adapter_tick_count <= 12,
1826a9de470cSBruce Richardson 			"Expected 10-12 adapter ticks, got %"PRIu64"\n",
1827a9de470cSBruce Richardson 			adapter_tick_count);
1828a9de470cSBruce Richardson 
1829a9de470cSBruce Richardson 	return TEST_SUCCESS;
1830a9de470cSBruce Richardson }
1831a9de470cSBruce Richardson 
1832a9de470cSBruce Richardson static int
adapter_create_max(void)1833a9de470cSBruce Richardson adapter_create_max(void)
1834a9de470cSBruce Richardson {
1835a9de470cSBruce Richardson 	int i;
1836a9de470cSBruce Richardson 	uint32_t svc_start_count, svc_end_count;
1837a9de470cSBruce Richardson 	struct rte_event_timer_adapter *adapters[
1838a9de470cSBruce Richardson 					RTE_EVENT_TIMER_ADAPTER_NUM_MAX + 1];
1839a9de470cSBruce Richardson 
1840a9de470cSBruce Richardson 	struct rte_event_timer_adapter_conf conf = {
1841a9de470cSBruce Richardson 		.event_dev_id = evdev,
1842a9de470cSBruce Richardson 		// timer_adapter_id set in loop
1843a9de470cSBruce Richardson 		.clk_src = RTE_EVENT_TIMER_ADAPTER_CPU_CLK,
1844a9de470cSBruce Richardson 		.timer_tick_ns = NSECPERSEC / 10,
1845a9de470cSBruce Richardson 		.max_tmo_ns = 180 * NSECPERSEC,
1846a9de470cSBruce Richardson 		.nb_timers = MAX_TIMERS,
18472385a7f5SPavan Nikhilesh 		.flags = RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES,
1848a9de470cSBruce Richardson 	};
1849a9de470cSBruce Richardson 
1850a9de470cSBruce Richardson 	if (!using_services)
1851a9de470cSBruce Richardson 		return -ENOTSUP;
1852a9de470cSBruce Richardson 
1853a9de470cSBruce Richardson 	svc_start_count = rte_service_get_count();
1854a9de470cSBruce Richardson 
1855a9de470cSBruce Richardson 	/* This test expects that there are sufficient service IDs available
1856a9de470cSBruce Richardson 	 * to be allocated. I.e., RTE_EVENT_TIMER_ADAPTER_NUM_MAX may need to
1857a9de470cSBruce Richardson 	 * be less than RTE_SERVICE_NUM_MAX if anything else uses a service
1858a9de470cSBruce Richardson 	 * (the SW event device, for example).
1859a9de470cSBruce Richardson 	 */
1860a9de470cSBruce Richardson 	for (i = 0; i < RTE_EVENT_TIMER_ADAPTER_NUM_MAX; i++) {
1861a9de470cSBruce Richardson 		conf.timer_adapter_id = i;
1862a9de470cSBruce Richardson 		adapters[i] = rte_event_timer_adapter_create_ext(&conf,
1863a9de470cSBruce Richardson 				test_port_conf_cb, NULL);
1864a9de470cSBruce Richardson 		TEST_ASSERT_NOT_NULL(adapters[i], "Failed to create adapter "
1865a9de470cSBruce Richardson 				"%d", i);
1866a9de470cSBruce Richardson 	}
1867a9de470cSBruce Richardson 
1868a9de470cSBruce Richardson 	conf.timer_adapter_id = i;
1869a9de470cSBruce Richardson 	adapters[i] = rte_event_timer_adapter_create(&conf);
1870a9de470cSBruce Richardson 	TEST_ASSERT_NULL(adapters[i], "Created too many adapters");
1871a9de470cSBruce Richardson 
1872a9de470cSBruce Richardson 	/* Check that at least RTE_EVENT_TIMER_ADAPTER_NUM_MAX services
1873a9de470cSBruce Richardson 	 * have been created
1874a9de470cSBruce Richardson 	 */
1875a9de470cSBruce Richardson 	svc_end_count = rte_service_get_count();
1876a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(svc_end_count - svc_start_count,
1877a9de470cSBruce Richardson 			RTE_EVENT_TIMER_ADAPTER_NUM_MAX,
1878a9de470cSBruce Richardson 			"Failed to create expected number of services");
1879a9de470cSBruce Richardson 
1880a9de470cSBruce Richardson 	for (i = 0; i < RTE_EVENT_TIMER_ADAPTER_NUM_MAX; i++)
1881a9de470cSBruce Richardson 		TEST_ASSERT_SUCCESS(rte_event_timer_adapter_free(adapters[i]),
1882a9de470cSBruce Richardson 				"Failed to free adapter %d", i);
1883a9de470cSBruce Richardson 
1884a9de470cSBruce Richardson 	/* Check that service count is back to where it was at start */
1885a9de470cSBruce Richardson 	svc_end_count = rte_service_get_count();
1886a9de470cSBruce Richardson 	TEST_ASSERT_EQUAL(svc_start_count, svc_end_count, "Failed to release "
1887a9de470cSBruce Richardson 			  "correct number of services");
1888a9de470cSBruce Richardson 
1889a9de470cSBruce Richardson 	return TEST_SUCCESS;
1890a9de470cSBruce Richardson }
1891a9de470cSBruce Richardson 
1892a9de470cSBruce Richardson static struct unit_test_suite event_timer_adptr_functional_testsuite  = {
1893a9de470cSBruce Richardson 	.suite_name = "event timer functional test suite",
1894a9de470cSBruce Richardson 	.setup = testsuite_setup,
1895a9de470cSBruce Richardson 	.teardown = testsuite_teardown,
1896a9de470cSBruce Richardson 	.unit_test_cases = {
1897a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_usec, timdev_teardown,
1898a9de470cSBruce Richardson 				test_timer_state),
1899a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_usec, timdev_teardown,
1900a9de470cSBruce Richardson 				test_timer_arm),
19017d761b07SShijith Thotton 		TEST_CASE_ST(timdev_setup_msec_periodic, timdev_teardown,
19027d761b07SShijith Thotton 				test_timer_arm_periodic),
1903a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_usec, timdev_teardown,
1904a9de470cSBruce Richardson 				test_timer_arm_burst),
19057d761b07SShijith Thotton 		TEST_CASE_ST(timdev_setup_msec_periodic, timdev_teardown,
19067d761b07SShijith Thotton 				test_timer_arm_burst_periodic),
1907a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_sec, timdev_teardown,
1908a9de470cSBruce Richardson 				test_timer_cancel),
19097d761b07SShijith Thotton 		TEST_CASE_ST(timdev_setup_sec_periodic, timdev_teardown,
19107d761b07SShijith Thotton 				test_timer_cancel_periodic),
1911a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_sec, timdev_teardown,
1912a9de470cSBruce Richardson 				test_timer_cancel_random),
1913a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_usec_multicore, timdev_teardown,
1914a9de470cSBruce Richardson 				test_timer_arm_multicore),
1915a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_usec_multicore, timdev_teardown,
1916a9de470cSBruce Richardson 				test_timer_arm_burst_multicore),
1917a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_sec_multicore, timdev_teardown,
1918a9de470cSBruce Richardson 				test_timer_cancel_multicore),
1919a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_sec_multicore, timdev_teardown,
1920a9de470cSBruce Richardson 				test_timer_cancel_burst_multicore),
1921a9de470cSBruce Richardson 		TEST_CASE(adapter_create),
1922a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, NULL, adapter_free),
1923a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1924a9de470cSBruce Richardson 				adapter_get_info),
1925a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1926a9de470cSBruce Richardson 				adapter_lookup),
1927a9de470cSBruce Richardson 		TEST_CASE_ST(NULL, timdev_teardown,
1928a9de470cSBruce Richardson 				adapter_start),
1929a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, NULL,
1930a9de470cSBruce Richardson 				adapter_stop),
1931a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1932a9de470cSBruce Richardson 				stat_inc_reset_ev_enq),
1933a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1934a9de470cSBruce Richardson 			     event_timer_arm),
1935a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1936a9de470cSBruce Richardson 			     event_timer_arm_double),
1937a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1938a9de470cSBruce Richardson 			     event_timer_arm_expiry),
1939a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1940a9de470cSBruce Richardson 				event_timer_arm_rearm),
1941a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1942a9de470cSBruce Richardson 				event_timer_arm_max),
1943a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1944a9de470cSBruce Richardson 				event_timer_arm_invalid_sched_type),
1945a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1946a9de470cSBruce Richardson 				event_timer_arm_invalid_timeout),
1947a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1948a9de470cSBruce Richardson 				event_timer_cancel),
1949a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1950a9de470cSBruce Richardson 				event_timer_cancel_double),
1951a9de470cSBruce Richardson 		TEST_CASE_ST(timdev_setup_msec, timdev_teardown,
1952a9de470cSBruce Richardson 				adapter_tick_resolution),
1953a9de470cSBruce Richardson 		TEST_CASE(adapter_create_max),
1954a9de470cSBruce Richardson 		TEST_CASES_END() /**< NULL terminate unit test array */
1955a9de470cSBruce Richardson 	}
1956a9de470cSBruce Richardson };
1957a9de470cSBruce Richardson 
1958a9de470cSBruce Richardson static int
test_event_timer_adapter_func(void)1959a9de470cSBruce Richardson test_event_timer_adapter_func(void)
1960a9de470cSBruce Richardson {
1961a9de470cSBruce Richardson 	return unit_test_suite_runner(&event_timer_adptr_functional_testsuite);
1962a9de470cSBruce Richardson }
1963a9de470cSBruce Richardson 
1964*3c60274cSJie Zhou #endif /* !RTE_EXEC_ENV_WINDOWS */
1965*3c60274cSJie Zhou 
1966a9de470cSBruce Richardson REGISTER_TEST_COMMAND(event_timer_adapter_test, test_event_timer_adapter_func);
1967