xref: /dpdk/app/test-bbdev/test_bbdev.c (revision d819c083)
1f714a188SAmr Mokhtar /* SPDX-License-Identifier: BSD-3-Clause
2f714a188SAmr Mokhtar  * Copyright(c) 2017 Intel Corporation
3f714a188SAmr Mokhtar  */
4f714a188SAmr Mokhtar 
5f714a188SAmr Mokhtar #include <rte_common.h>
6f714a188SAmr Mokhtar #include <rte_hexdump.h>
7f714a188SAmr Mokhtar #include <rte_mbuf.h>
8f714a188SAmr Mokhtar #include <rte_malloc.h>
9f714a188SAmr Mokhtar #include <rte_memcpy.h>
10f714a188SAmr Mokhtar #include <rte_cycles.h>
11f714a188SAmr Mokhtar 
12f714a188SAmr Mokhtar #include <rte_bus_vdev.h>
13f714a188SAmr Mokhtar 
14f714a188SAmr Mokhtar #include <rte_bbdev.h>
15f714a188SAmr Mokhtar #include <rte_bbdev_op.h>
16f714a188SAmr Mokhtar #include <rte_bbdev_pmd.h>
17f714a188SAmr Mokhtar 
18f714a188SAmr Mokhtar #include "main.h"
19f714a188SAmr Mokhtar 
20f714a188SAmr Mokhtar 
21f714a188SAmr Mokhtar #define BBDEV_NAME_NULL          ("bbdev_null")
22f714a188SAmr Mokhtar 
23f714a188SAmr Mokhtar struct bbdev_testsuite_params {
24f714a188SAmr Mokhtar 	struct rte_bbdev_queue_conf qconf;
25f714a188SAmr Mokhtar };
26f714a188SAmr Mokhtar 
27f714a188SAmr Mokhtar static struct bbdev_testsuite_params testsuite_params;
28f714a188SAmr Mokhtar 
29f714a188SAmr Mokhtar static uint8_t null_dev_id;
30f714a188SAmr Mokhtar 
31f714a188SAmr Mokhtar static int
testsuite_setup(void)32f714a188SAmr Mokhtar testsuite_setup(void)
33f714a188SAmr Mokhtar {
34f714a188SAmr Mokhtar 	uint8_t nb_devs;
35f714a188SAmr Mokhtar 	int ret;
36f714a188SAmr Mokhtar 	char buf[RTE_BBDEV_NAME_MAX_LEN];
37f714a188SAmr Mokhtar 
38f714a188SAmr Mokhtar 	/* Create test device */
39f714a188SAmr Mokhtar 	snprintf(buf, sizeof(buf), "%s_unittest", BBDEV_NAME_NULL);
40f714a188SAmr Mokhtar 	ret = rte_vdev_init(buf, NULL);
41f714a188SAmr Mokhtar 	TEST_ASSERT(ret == 0, "Failed to create instance of pmd: %s", buf);
42f714a188SAmr Mokhtar 
43f714a188SAmr Mokhtar 	nb_devs = rte_bbdev_count();
44f714a188SAmr Mokhtar 	TEST_ASSERT(nb_devs != 0, "No devices found");
45f714a188SAmr Mokhtar 
46f714a188SAmr Mokhtar 	/* Most recently created device is our device */
47f714a188SAmr Mokhtar 	null_dev_id = nb_devs - 1;
48f714a188SAmr Mokhtar 
49f714a188SAmr Mokhtar 	return TEST_SUCCESS;
50f714a188SAmr Mokhtar }
51f714a188SAmr Mokhtar 
52f714a188SAmr Mokhtar static void
testsuite_teardown(void)53f714a188SAmr Mokhtar testsuite_teardown(void)
54f714a188SAmr Mokhtar {
55f714a188SAmr Mokhtar 	char buf[RTE_BBDEV_NAME_MAX_LEN];
56f714a188SAmr Mokhtar 
57f714a188SAmr Mokhtar 	snprintf(buf, sizeof(buf), "%s_unittest", BBDEV_NAME_NULL);
58f714a188SAmr Mokhtar 	rte_vdev_uninit(buf);
59f714a188SAmr Mokhtar }
60f714a188SAmr Mokhtar 
61f714a188SAmr Mokhtar static int
ut_setup(void)62f714a188SAmr Mokhtar ut_setup(void)
63f714a188SAmr Mokhtar {
64f714a188SAmr Mokhtar 	struct bbdev_testsuite_params *ts_params = &testsuite_params;
65f714a188SAmr Mokhtar 	uint8_t num_queues;
66f714a188SAmr Mokhtar 
67f714a188SAmr Mokhtar 	/* Valid queue configuration */
68f714a188SAmr Mokhtar 	ts_params->qconf.priority = 0;
69f714a188SAmr Mokhtar 	ts_params->qconf.socket = SOCKET_ID_ANY;
70f714a188SAmr Mokhtar 	ts_params->qconf.deferred_start = 1;
71f714a188SAmr Mokhtar 
72f714a188SAmr Mokhtar 	num_queues = 1;
73f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_setup_queues(null_dev_id, num_queues,
74f714a188SAmr Mokhtar 			SOCKET_ID_ANY), "Failed to setup queues for bbdev %u",
75f714a188SAmr Mokhtar 			0);
76f714a188SAmr Mokhtar 
77f714a188SAmr Mokhtar 	/* Start the device */
78f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_start(null_dev_id),
79f714a188SAmr Mokhtar 			"Failed to start bbdev %u", 0);
80f714a188SAmr Mokhtar 
81f714a188SAmr Mokhtar 	return TEST_SUCCESS;
82f714a188SAmr Mokhtar }
83f714a188SAmr Mokhtar 
84f714a188SAmr Mokhtar static void
ut_teardown(void)85f714a188SAmr Mokhtar ut_teardown(void)
86f714a188SAmr Mokhtar {
87f714a188SAmr Mokhtar 	rte_bbdev_close(null_dev_id);
88f714a188SAmr Mokhtar }
89f714a188SAmr Mokhtar 
90f714a188SAmr Mokhtar static int
test_bbdev_configure_invalid_dev_id(void)91f714a188SAmr Mokhtar test_bbdev_configure_invalid_dev_id(void)
92f714a188SAmr Mokhtar {
93f714a188SAmr Mokhtar 	uint8_t dev_id;
94f714a188SAmr Mokhtar 	uint8_t num_queues;
95f714a188SAmr Mokhtar 
96f714a188SAmr Mokhtar 	num_queues = 1;
97f714a188SAmr Mokhtar 	for (dev_id = 0; dev_id < RTE_BBDEV_MAX_DEVS; dev_id++) {
98f714a188SAmr Mokhtar 		if (!rte_bbdev_is_valid(dev_id)) {
99f714a188SAmr Mokhtar 			TEST_ASSERT_FAIL(rte_bbdev_setup_queues(dev_id,
100f714a188SAmr Mokhtar 					num_queues, SOCKET_ID_ANY),
101f714a188SAmr Mokhtar 					"Failed test for rte_bbdev_setup_queues: "
102f714a188SAmr Mokhtar 					"invalid dev_num %u", dev_id);
103f714a188SAmr Mokhtar 			TEST_ASSERT(rte_bbdev_intr_enable(dev_id) == -ENODEV,
104f714a188SAmr Mokhtar 					"Failed test for rte_bbdev_intr_enable: "
105f714a188SAmr Mokhtar 					"invalid dev_num %u", dev_id);
106f714a188SAmr Mokhtar 			break;
107f714a188SAmr Mokhtar 		}
108f714a188SAmr Mokhtar 	}
109f714a188SAmr Mokhtar 
110f714a188SAmr Mokhtar 	return TEST_SUCCESS;
111f714a188SAmr Mokhtar }
112f714a188SAmr Mokhtar 
113f714a188SAmr Mokhtar static int
test_bbdev_configure_invalid_num_queues(void)114f714a188SAmr Mokhtar test_bbdev_configure_invalid_num_queues(void)
115f714a188SAmr Mokhtar {
116f714a188SAmr Mokhtar 	struct rte_bbdev_info info;
117f714a188SAmr Mokhtar 	uint8_t dev_id, num_devs;
118f714a188SAmr Mokhtar 	uint8_t num_queues;
119f714a188SAmr Mokhtar 	int return_value;
120f714a188SAmr Mokhtar 
121f714a188SAmr Mokhtar 	TEST_ASSERT((num_devs = rte_bbdev_count()) >= 1,
122f714a188SAmr Mokhtar 			"Need at least %d devices for test", 1);
123f714a188SAmr Mokhtar 
124f714a188SAmr Mokhtar 	/* valid num_queues values */
125f714a188SAmr Mokhtar 	num_queues = 8;
126f714a188SAmr Mokhtar 
127f714a188SAmr Mokhtar 	/* valid dev_id values */
128f714a188SAmr Mokhtar 	dev_id = null_dev_id;
129f714a188SAmr Mokhtar 
130f714a188SAmr Mokhtar 	/* Stop the device in case it's started so it can be configured */
131f714a188SAmr Mokhtar 	rte_bbdev_stop(dev_id);
132f714a188SAmr Mokhtar 
133f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_setup_queues(dev_id, 0, SOCKET_ID_ANY),
134f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_setup_queues: "
135f714a188SAmr Mokhtar 			"invalid num_queues %d", 0);
136f714a188SAmr Mokhtar 
137f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_setup_queues(dev_id, num_queues,
138f714a188SAmr Mokhtar 			SOCKET_ID_ANY),
139f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_setup_queues: "
140f714a188SAmr Mokhtar 			"invalid dev_num %u", dev_id);
141f714a188SAmr Mokhtar 
142f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(return_value = rte_bbdev_info_get(dev_id, NULL),
143f714a188SAmr Mokhtar 			 "Failed test for rte_bbdev_info_get: "
144f714a188SAmr Mokhtar 			 "returned value:%i", return_value);
145f714a188SAmr Mokhtar 
146f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(return_value = rte_bbdev_info_get(dev_id, &info),
147f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
148f714a188SAmr Mokhtar 			"invalid return value:%i", return_value);
149f714a188SAmr Mokhtar 
150f714a188SAmr Mokhtar 	TEST_ASSERT(info.num_queues == num_queues,
151f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
152f714a188SAmr Mokhtar 			"invalid num_queues:%u", info.num_queues);
153f714a188SAmr Mokhtar 
154f714a188SAmr Mokhtar 	num_queues = info.drv.max_num_queues;
155f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_setup_queues(dev_id, num_queues,
156f714a188SAmr Mokhtar 			SOCKET_ID_ANY),
157f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_setup_queues: "
158f714a188SAmr Mokhtar 			"invalid num_queues: %u", num_queues);
159f714a188SAmr Mokhtar 
160f714a188SAmr Mokhtar 	num_queues++;
161f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_setup_queues(dev_id, num_queues,
162f714a188SAmr Mokhtar 			SOCKET_ID_ANY),
163f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_setup_queues: "
164f714a188SAmr Mokhtar 			"invalid num_queues: %u", num_queues);
165f714a188SAmr Mokhtar 
166f714a188SAmr Mokhtar 	return TEST_SUCCESS;
167f714a188SAmr Mokhtar }
168f714a188SAmr Mokhtar 
169f714a188SAmr Mokhtar static int
test_bbdev_configure_stop_device(void)170f714a188SAmr Mokhtar test_bbdev_configure_stop_device(void)
171f714a188SAmr Mokhtar {
172f714a188SAmr Mokhtar 	struct rte_bbdev_info info;
173f714a188SAmr Mokhtar 	uint8_t dev_id;
174f714a188SAmr Mokhtar 	int return_value;
175f714a188SAmr Mokhtar 
176f714a188SAmr Mokhtar 	/* valid dev_id values */
177f714a188SAmr Mokhtar 	dev_id = null_dev_id;
178f714a188SAmr Mokhtar 
179f714a188SAmr Mokhtar 	/* Stop the device so it can be configured */
180f714a188SAmr Mokhtar 	rte_bbdev_stop(dev_id);
181f714a188SAmr Mokhtar 
182f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(return_value = rte_bbdev_info_get(dev_id, &info),
183f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
184f714a188SAmr Mokhtar 			"invalid return value from "
185f714a188SAmr Mokhtar 			"rte_bbdev_info_get function: %i", return_value);
186f714a188SAmr Mokhtar 
187f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(info.started, "Failed test for rte_bbdev_info_get: "
188f714a188SAmr Mokhtar 			"started value: %u", info.started);
189f714a188SAmr Mokhtar 
190f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_setup_queues(dev_id,
191f714a188SAmr Mokhtar 			info.drv.max_num_queues, SOCKET_ID_ANY),
192f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_setup_queues: "
193f714a188SAmr Mokhtar 			"device should be stopped, dev_id: %u", dev_id);
194f714a188SAmr Mokhtar 
195f714a188SAmr Mokhtar 	return_value = rte_bbdev_intr_enable(dev_id);
196f714a188SAmr Mokhtar 	TEST_ASSERT(return_value != -EBUSY,
197f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_intr_enable: device should be stopped, dev_id: %u",
198f714a188SAmr Mokhtar 			dev_id);
199f714a188SAmr Mokhtar 
200f714a188SAmr Mokhtar 	/* Start the device so it cannot be configured */
201f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_start(RTE_BBDEV_MAX_DEVS),
202f714a188SAmr Mokhtar 			"Failed to start bbdev %u", dev_id);
203f714a188SAmr Mokhtar 
204f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_start(dev_id),
205f714a188SAmr Mokhtar 			"Failed to start bbdev %u", dev_id);
206f714a188SAmr Mokhtar 
207f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(return_value = rte_bbdev_info_get(dev_id, &info),
208f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
209f714a188SAmr Mokhtar 			"invalid return value from "
210f714a188SAmr Mokhtar 			"rte_bbdev_info_get function: %i", return_value);
211f714a188SAmr Mokhtar 
212f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(info.started, "Failed test for rte_bbdev_info_get: "
213f714a188SAmr Mokhtar 			"started value: %u", info.started);
214f714a188SAmr Mokhtar 
215f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_setup_queues(dev_id,
216f714a188SAmr Mokhtar 			info.drv.max_num_queues, SOCKET_ID_ANY),
217f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_setup_queues: "
218f714a188SAmr Mokhtar 			"device should be started, dev_id: %u", dev_id);
219f714a188SAmr Mokhtar 
220f714a188SAmr Mokhtar 	return_value = rte_bbdev_intr_enable(dev_id);
221f714a188SAmr Mokhtar 	TEST_ASSERT(return_value == -EBUSY,
222f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_intr_enable: device should be started, dev_id: %u",
223f714a188SAmr Mokhtar 			dev_id);
224f714a188SAmr Mokhtar 
225f714a188SAmr Mokhtar 	/* Stop again the device so it can be once again configured */
226f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_stop(RTE_BBDEV_MAX_DEVS),
227f714a188SAmr Mokhtar 			"Failed to start bbdev %u", dev_id);
228f714a188SAmr Mokhtar 
229f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stop(dev_id), "Failed to stop bbdev %u",
230f714a188SAmr Mokhtar 			dev_id);
231f714a188SAmr Mokhtar 
232f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(return_value = rte_bbdev_info_get(dev_id, &info),
233f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
234f714a188SAmr Mokhtar 			"invalid return value from "
235f714a188SAmr Mokhtar 			"rte_bbdev_info_get function: %i", return_value);
236f714a188SAmr Mokhtar 
237f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(info.started, "Failed test for rte_bbdev_info_get: "
238f714a188SAmr Mokhtar 			"started value: %u", info.started);
239f714a188SAmr Mokhtar 
240f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_setup_queues(dev_id,
241f714a188SAmr Mokhtar 			info.drv.max_num_queues, SOCKET_ID_ANY),
242f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_setup_queues: "
243f714a188SAmr Mokhtar 			"device should be stopped, dev_id: %u", dev_id);
244f714a188SAmr Mokhtar 
245f714a188SAmr Mokhtar 	return_value = rte_bbdev_intr_enable(dev_id);
246f714a188SAmr Mokhtar 	TEST_ASSERT(return_value != -EBUSY,
247f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_intr_enable: device should be stopped, dev_id: %u",
248f714a188SAmr Mokhtar 			dev_id);
249f714a188SAmr Mokhtar 
250f714a188SAmr Mokhtar 	return TEST_SUCCESS;
251f714a188SAmr Mokhtar }
252f714a188SAmr Mokhtar 
253f714a188SAmr Mokhtar static int
test_bbdev_configure_stop_queue(void)254f714a188SAmr Mokhtar test_bbdev_configure_stop_queue(void)
255f714a188SAmr Mokhtar {
256f714a188SAmr Mokhtar 	struct bbdev_testsuite_params *ts_params = &testsuite_params;
257f714a188SAmr Mokhtar 	struct rte_bbdev_info info;
258f714a188SAmr Mokhtar 	struct rte_bbdev_queue_info qinfo;
259f714a188SAmr Mokhtar 	uint8_t dev_id;
260f714a188SAmr Mokhtar 	uint16_t queue_id;
261f714a188SAmr Mokhtar 	int return_value;
262f714a188SAmr Mokhtar 
263f714a188SAmr Mokhtar 	/* Valid dev_id values */
264f714a188SAmr Mokhtar 	dev_id = null_dev_id;
265f714a188SAmr Mokhtar 
266f714a188SAmr Mokhtar 	/* Valid queue_id values */
267f714a188SAmr Mokhtar 	queue_id = 0;
268f714a188SAmr Mokhtar 
269f714a188SAmr Mokhtar 	rte_bbdev_stop(dev_id);
270f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(return_value = rte_bbdev_info_get(dev_id, &info),
271f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
272f714a188SAmr Mokhtar 			"invalid return value:%i", return_value);
273f714a188SAmr Mokhtar 
274f714a188SAmr Mokhtar 	/* Valid queue configuration */
275f714a188SAmr Mokhtar 	ts_params->qconf.queue_size = info.drv.queue_size_lim;
27658a695c6SKamil Chalupnik 	ts_params->qconf.priority = info.drv.max_ul_queue_priority;
277f714a188SAmr Mokhtar 
278f714a188SAmr Mokhtar 	/* Device - started; queue - started */
279f714a188SAmr Mokhtar 	rte_bbdev_start(dev_id);
280f714a188SAmr Mokhtar 
281f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_configure(dev_id, queue_id,
282f714a188SAmr Mokhtar 			&ts_params->qconf),
283f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_configure: "
284f714a188SAmr Mokhtar 			"queue:%u on device:%u should be stopped",
285f714a188SAmr Mokhtar 			 queue_id, dev_id);
286f714a188SAmr Mokhtar 
287f714a188SAmr Mokhtar 	/* Device - stopped; queue - started */
288f714a188SAmr Mokhtar 	rte_bbdev_stop(dev_id);
289f714a188SAmr Mokhtar 
290f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_configure(dev_id, queue_id,
291f714a188SAmr Mokhtar 			&ts_params->qconf),
292f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_configure: "
293f714a188SAmr Mokhtar 			"queue:%u on device:%u should be stopped",
294f714a188SAmr Mokhtar 			 queue_id, dev_id);
295f714a188SAmr Mokhtar 
296f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_stop(RTE_BBDEV_MAX_DEVS, queue_id),
297f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_stop "
298f714a188SAmr Mokhtar 			"invalid dev_id ");
299f714a188SAmr Mokhtar 
300f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_stop(dev_id, RTE_MAX_QUEUES_PER_PORT),
301f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_stop "
302f714a188SAmr Mokhtar 			"invalid queue_id ");
303f714a188SAmr Mokhtar 
304f714a188SAmr Mokhtar 	/* Device - stopped; queue - stopped */
305f714a188SAmr Mokhtar 	rte_bbdev_queue_stop(dev_id, queue_id);
306f714a188SAmr Mokhtar 
307f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_configure(dev_id, queue_id,
308f714a188SAmr Mokhtar 			&ts_params->qconf),
309f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_configure: "
310f714a188SAmr Mokhtar 			"queue:%u on device:%u should be stopped", queue_id,
311f714a188SAmr Mokhtar 			dev_id);
312f714a188SAmr Mokhtar 
313f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(return_value = rte_bbdev_queue_info_get(dev_id,
314f714a188SAmr Mokhtar 			queue_id, &qinfo),
315f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
316f714a188SAmr Mokhtar 			"invalid return value from "
317f714a188SAmr Mokhtar 			"rte_bbdev_queue_info_get function: %i", return_value);
318f714a188SAmr Mokhtar 
319f714a188SAmr Mokhtar 	TEST_ASSERT(qinfo.conf.socket == ts_params->qconf.socket,
320f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_info_get: "
321f714a188SAmr Mokhtar 			"invalid queue_size:%u", qinfo.conf.socket);
322f714a188SAmr Mokhtar 
323f714a188SAmr Mokhtar 	TEST_ASSERT(qinfo.conf.queue_size == ts_params->qconf.queue_size,
324f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_info_get: "
325f714a188SAmr Mokhtar 			"invalid queue_size:%u", qinfo.conf.queue_size);
326f714a188SAmr Mokhtar 
327f714a188SAmr Mokhtar 	TEST_ASSERT(qinfo.conf.priority == ts_params->qconf.priority,
328f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_info_get: "
329f714a188SAmr Mokhtar 			"invalid queue_size:%u", qinfo.conf.priority);
330f714a188SAmr Mokhtar 
331f714a188SAmr Mokhtar 	TEST_ASSERT(qinfo.conf.deferred_start ==
332f714a188SAmr Mokhtar 			ts_params->qconf.deferred_start,
333f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_info_get: "
334f714a188SAmr Mokhtar 			"invalid queue_size:%u", qinfo.conf.deferred_start);
335f714a188SAmr Mokhtar 
336f714a188SAmr Mokhtar 	/* Device - started; queue - stopped */
337f714a188SAmr Mokhtar 	rte_bbdev_start(dev_id);
338f714a188SAmr Mokhtar 	rte_bbdev_queue_stop(dev_id, queue_id);
339f714a188SAmr Mokhtar 
340f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_configure(dev_id, queue_id,
341f714a188SAmr Mokhtar 			&ts_params->qconf),
342f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_configure: "
343f714a188SAmr Mokhtar 			"queue:%u on device:%u should be stopped", queue_id,
344f714a188SAmr Mokhtar 			dev_id);
345f714a188SAmr Mokhtar 
346f714a188SAmr Mokhtar 	rte_bbdev_stop(dev_id);
347f714a188SAmr Mokhtar 
348f714a188SAmr Mokhtar 	/* After rte_bbdev_start(dev_id):
349f714a188SAmr Mokhtar 	 * - queue should be still stopped if deferred_start ==
350f714a188SAmr Mokhtar 	 */
351f714a188SAmr Mokhtar 	rte_bbdev_start(dev_id);
352f714a188SAmr Mokhtar 
353f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(return_value = rte_bbdev_queue_info_get(dev_id,
354f714a188SAmr Mokhtar 			queue_id, &qinfo),
355f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
356f714a188SAmr Mokhtar 			"invalid return value from "
357f714a188SAmr Mokhtar 			"rte_bbdev_queue_info_get function: %i", return_value);
358f714a188SAmr Mokhtar 
359f714a188SAmr Mokhtar 	TEST_ASSERT(qinfo.started == 0,
360f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_info_get: "
361f714a188SAmr Mokhtar 			"invalid value for qinfo.started:%u", qinfo.started);
362f714a188SAmr Mokhtar 
363f714a188SAmr Mokhtar 	rte_bbdev_stop(dev_id);
364f714a188SAmr Mokhtar 
365f714a188SAmr Mokhtar 	/* After rte_bbdev_start(dev_id):
366f714a188SAmr Mokhtar 	 * - queue should be started if deferred_start ==
367f714a188SAmr Mokhtar 	 */
368f714a188SAmr Mokhtar 	ts_params->qconf.deferred_start = 0;
369f714a188SAmr Mokhtar 	rte_bbdev_queue_configure(dev_id, queue_id, &ts_params->qconf);
370f714a188SAmr Mokhtar 	rte_bbdev_start(dev_id);
371f714a188SAmr Mokhtar 
372f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(return_value = rte_bbdev_queue_info_get(dev_id,
373f714a188SAmr Mokhtar 			queue_id, &qinfo),
374f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
375f714a188SAmr Mokhtar 			"invalid return value from "
376f714a188SAmr Mokhtar 			"rte_bbdev_queue_info_get function: %i", return_value);
377f714a188SAmr Mokhtar 
378f714a188SAmr Mokhtar 	TEST_ASSERT(qinfo.started == 1,
379f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_info_get: "
380f714a188SAmr Mokhtar 			"invalid value for qinfo.started:%u", qinfo.started);
381f714a188SAmr Mokhtar 
382f714a188SAmr Mokhtar 	return TEST_SUCCESS;
383f714a188SAmr Mokhtar }
384f714a188SAmr Mokhtar 
385f714a188SAmr Mokhtar static int
test_bbdev_configure_invalid_queue_configure(void)386f714a188SAmr Mokhtar test_bbdev_configure_invalid_queue_configure(void)
387f714a188SAmr Mokhtar {
388f714a188SAmr Mokhtar 	struct bbdev_testsuite_params *ts_params = &testsuite_params;
389f714a188SAmr Mokhtar 	int return_value;
390f714a188SAmr Mokhtar 	struct rte_bbdev_info info;
391f714a188SAmr Mokhtar 	uint8_t dev_id;
392f714a188SAmr Mokhtar 	uint16_t queue_id;
393f714a188SAmr Mokhtar 
394f714a188SAmr Mokhtar 	/* Valid dev_id values */
395f714a188SAmr Mokhtar 	dev_id = null_dev_id;
396f714a188SAmr Mokhtar 
397f714a188SAmr Mokhtar 	/* Valid queue_id values */
398f714a188SAmr Mokhtar 	queue_id = 0;
399f714a188SAmr Mokhtar 
400f714a188SAmr Mokhtar 	rte_bbdev_stop(dev_id);
401f714a188SAmr Mokhtar 
402f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(return_value = rte_bbdev_info_get(dev_id, &info),
403f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
404f714a188SAmr Mokhtar 			"invalid return value:%i", return_value);
405f714a188SAmr Mokhtar 
406f714a188SAmr Mokhtar 	rte_bbdev_queue_stop(dev_id, queue_id);
407f714a188SAmr Mokhtar 
408f714a188SAmr Mokhtar 	ts_params->qconf.queue_size = info.drv.queue_size_lim + 1;
409f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_configure(dev_id, queue_id,
410f714a188SAmr Mokhtar 			&ts_params->qconf),
411f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_configure: "
412f714a188SAmr Mokhtar 			"invalid value qconf.queue_size: %u",
413f714a188SAmr Mokhtar 			ts_params->qconf.queue_size);
414f714a188SAmr Mokhtar 
415f714a188SAmr Mokhtar 	ts_params->qconf.queue_size = info.drv.queue_size_lim;
41658a695c6SKamil Chalupnik 	ts_params->qconf.priority = info.drv.max_ul_queue_priority;
417f714a188SAmr Mokhtar 	queue_id = info.num_queues;
418f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_configure(dev_id, queue_id,
419f714a188SAmr Mokhtar 			&ts_params->qconf),
420f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_configure: "
421f714a188SAmr Mokhtar 			"invalid value queue_id: %u", queue_id);
422f714a188SAmr Mokhtar 
423f714a188SAmr Mokhtar 	queue_id = 0;
424f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_configure(dev_id, queue_id, NULL),
425f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_configure: "
426f714a188SAmr Mokhtar 			"NULL qconf structure ");
427f714a188SAmr Mokhtar 
428f714a188SAmr Mokhtar 	ts_params->qconf.socket = RTE_MAX_NUMA_NODES;
429f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_configure(dev_id, queue_id,
430f714a188SAmr Mokhtar 			&ts_params->qconf),
431f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_configure: "
432f714a188SAmr Mokhtar 			"invalid socket number ");
433f714a188SAmr Mokhtar 
434f714a188SAmr Mokhtar 	ts_params->qconf.socket = SOCKET_ID_ANY;
435f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_configure(dev_id, queue_id,
436f714a188SAmr Mokhtar 			&ts_params->qconf),
437f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_configure: "
438f714a188SAmr Mokhtar 			"invalid value qconf.queue_size: %u",
439f714a188SAmr Mokhtar 			ts_params->qconf.queue_size);
440f714a188SAmr Mokhtar 
441f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_configure(RTE_BBDEV_MAX_DEVS, queue_id,
442f714a188SAmr Mokhtar 			&ts_params->qconf),
443f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_configure: "
444f714a188SAmr Mokhtar 			"invalid dev_id");
445f714a188SAmr Mokhtar 
446f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_configure(dev_id, queue_id, NULL),
447f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_queue_configure: "
448f714a188SAmr Mokhtar 			"invalid value qconf.queue_size: %u",
449f714a188SAmr Mokhtar 			ts_params->qconf.queue_size);
450f714a188SAmr Mokhtar 
451f714a188SAmr Mokhtar 	return TEST_SUCCESS;
452f714a188SAmr Mokhtar }
453f714a188SAmr Mokhtar 
454f714a188SAmr Mokhtar static int
test_bbdev_op_pool(void)455f714a188SAmr Mokhtar test_bbdev_op_pool(void)
456f714a188SAmr Mokhtar {
457f714a188SAmr Mokhtar 	struct rte_mempool *mp;
458f714a188SAmr Mokhtar 
459f714a188SAmr Mokhtar 	unsigned int dec_size = sizeof(struct rte_bbdev_dec_op);
460f714a188SAmr Mokhtar 	unsigned int enc_size = sizeof(struct rte_bbdev_enc_op);
461f714a188SAmr Mokhtar 
462f714a188SAmr Mokhtar 	const char *pool_dec = "Test_DEC";
463f714a188SAmr Mokhtar 	const char *pool_enc = "Test_ENC";
464f714a188SAmr Mokhtar 
465f714a188SAmr Mokhtar 	/* Valid pool configuration */
466f714a188SAmr Mokhtar 	uint32_t size = 256;
467f714a188SAmr Mokhtar 	uint32_t cache_size = 128;
468f714a188SAmr Mokhtar 
469f714a188SAmr Mokhtar 	TEST_ASSERT(rte_bbdev_op_pool_create(NULL,
470f714a188SAmr Mokhtar 			RTE_BBDEV_OP_TURBO_DEC, size, cache_size, 0) == NULL,
471f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_pool_create: "
472f714a188SAmr Mokhtar 			"NULL name parameter");
473f714a188SAmr Mokhtar 
474f714a188SAmr Mokhtar 	TEST_ASSERT((mp = rte_bbdev_op_pool_create(pool_dec,
475f714a188SAmr Mokhtar 			RTE_BBDEV_OP_TURBO_DEC, size, cache_size, 0)) != NULL,
476f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_pool_create: "
477f714a188SAmr Mokhtar 			"returned value is empty");
478f714a188SAmr Mokhtar 
479f714a188SAmr Mokhtar 	TEST_ASSERT(mp->size == size,
480f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_pool_create: "
481f714a188SAmr Mokhtar 			"invalid size of the mempool, mp->size: %u", mp->size);
482f714a188SAmr Mokhtar 
483f714a188SAmr Mokhtar 	TEST_ASSERT(mp->cache_size == cache_size,
484f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_pool_create: "
485f714a188SAmr Mokhtar 			"invalid size of the mempool, mp->size: %u",
486f714a188SAmr Mokhtar 			mp->cache_size);
487f714a188SAmr Mokhtar 
488f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(strcmp(mp->name, pool_dec),
489f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_pool_create: "
490f714a188SAmr Mokhtar 			"invalid name of mempool, mp->name: %s", mp->name);
491f714a188SAmr Mokhtar 
492f714a188SAmr Mokhtar 	TEST_ASSERT(mp->elt_size == dec_size,
493f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_pool_create: "
494f714a188SAmr Mokhtar 			"invalid element size for RTE_BBDEV_OP_TURBO_DEC, "
495f714a188SAmr Mokhtar 			"mp->elt_size: %u", mp->elt_size);
496f714a188SAmr Mokhtar 
497f714a188SAmr Mokhtar 	rte_mempool_free(mp);
498f714a188SAmr Mokhtar 
499f714a188SAmr Mokhtar 	TEST_ASSERT((mp = rte_bbdev_op_pool_create(pool_enc,
500f714a188SAmr Mokhtar 			RTE_BBDEV_OP_TURBO_ENC, size, cache_size, 0)) != NULL,
501f714a188SAmr Mokhtar 			 "Failed test for rte_bbdev_op_pool_create: "
502f714a188SAmr Mokhtar 			"returned value is empty");
503f714a188SAmr Mokhtar 
504f714a188SAmr Mokhtar 	TEST_ASSERT(mp->elt_size == enc_size,
505f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_pool_create: "
506f714a188SAmr Mokhtar 			"invalid element size for RTE_BBDEV_OP_TURBO_ENC, "
507f714a188SAmr Mokhtar 			"mp->elt_size: %u", mp->elt_size);
508f714a188SAmr Mokhtar 
509f714a188SAmr Mokhtar 	rte_mempool_free(mp);
510f714a188SAmr Mokhtar 
511f714a188SAmr Mokhtar 	TEST_ASSERT((mp = rte_bbdev_op_pool_create("Test_NONE",
512f714a188SAmr Mokhtar 			RTE_BBDEV_OP_NONE, size, cache_size, 0)) != NULL,
513f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_pool_create: "
514f714a188SAmr Mokhtar 			"returned value is empty for RTE_BBDEV_OP_NONE");
515f714a188SAmr Mokhtar 
516f714a188SAmr Mokhtar 	TEST_ASSERT(mp->elt_size == (enc_size > dec_size ? enc_size : dec_size),
517f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_pool_create: "
518f714a188SAmr Mokhtar 			"invalid  size for RTE_BBDEV_OP_NONE, mp->elt_size: %u",
519f714a188SAmr Mokhtar 			mp->elt_size);
520f714a188SAmr Mokhtar 
521f714a188SAmr Mokhtar 	rte_mempool_free(mp);
522f714a188SAmr Mokhtar 
523f714a188SAmr Mokhtar 	TEST_ASSERT((mp = rte_bbdev_op_pool_create("Test_INV",
524f714a188SAmr Mokhtar 			RTE_BBDEV_OP_TYPE_COUNT, size, cache_size, 0)) == NULL,
525f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_pool_create: "
526f714a188SAmr Mokhtar 			"returned value is not NULL for invalid type");
527f714a188SAmr Mokhtar 
528f714a188SAmr Mokhtar 	/* Invalid pool configuration */
529f714a188SAmr Mokhtar 	size = 128;
530f714a188SAmr Mokhtar 	cache_size = 256;
531f714a188SAmr Mokhtar 
532f714a188SAmr Mokhtar 	TEST_ASSERT((mp = rte_bbdev_op_pool_create("Test_InvSize",
533f714a188SAmr Mokhtar 			RTE_BBDEV_OP_NONE, size, cache_size, 0)) == NULL,
534f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_pool_create: "
535f714a188SAmr Mokhtar 			"returned value should be empty "
536f714a188SAmr Mokhtar 			"because size of per-lcore local cache "
537f714a188SAmr Mokhtar 			"is greater than size of the mempool.");
538f714a188SAmr Mokhtar 
539f714a188SAmr Mokhtar 	return TEST_SUCCESS;
540f714a188SAmr Mokhtar }
541f714a188SAmr Mokhtar 
542f714a188SAmr Mokhtar /**
543f714a188SAmr Mokhtar  *  Create pool of OP types RTE_BBDEV_OP_NONE, RTE_BBDEV_OP_TURBO_DEC and
544f714a188SAmr Mokhtar  *  RTE_BBDEV_OP_TURBO_ENC and check that only ops of that type can be
545f714a188SAmr Mokhtar  *  allocated
546f714a188SAmr Mokhtar  */
547f714a188SAmr Mokhtar static int
test_bbdev_op_type(void)548f714a188SAmr Mokhtar test_bbdev_op_type(void)
549f714a188SAmr Mokhtar {
550f714a188SAmr Mokhtar 	struct rte_mempool *mp_dec;
551f714a188SAmr Mokhtar 
552f714a188SAmr Mokhtar 	const unsigned int OPS_COUNT = 32;
553f714a188SAmr Mokhtar 	struct rte_bbdev_dec_op *dec_ops_arr[OPS_COUNT];
554f714a188SAmr Mokhtar 	struct rte_bbdev_enc_op *enc_ops_arr[OPS_COUNT];
555f714a188SAmr Mokhtar 
556f714a188SAmr Mokhtar 	const char *pool_dec = "Test_op_dec";
557f714a188SAmr Mokhtar 
558f714a188SAmr Mokhtar 	/* Valid pool configuration */
559f714a188SAmr Mokhtar 	uint32_t num_elements = 256;
560f714a188SAmr Mokhtar 	uint32_t cache_size = 128;
561f714a188SAmr Mokhtar 
562f714a188SAmr Mokhtar 	/* mempool type : RTE_BBDEV_OP_TURBO_DEC */
563f714a188SAmr Mokhtar 	mp_dec = rte_bbdev_op_pool_create(pool_dec,
564f714a188SAmr Mokhtar 			RTE_BBDEV_OP_TURBO_DEC, num_elements, cache_size, 0);
565f714a188SAmr Mokhtar 	TEST_ASSERT(mp_dec != NULL, "Failed to create %s mempool", pool_dec);
566f714a188SAmr Mokhtar 
567f714a188SAmr Mokhtar 	TEST_ASSERT(rte_bbdev_dec_op_alloc_bulk(mp_dec, dec_ops_arr, 1) == 0,
568f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_alloc_bulk TURBO_DEC: "
569f714a188SAmr Mokhtar 			"OPs type: RTE_BBDEV_OP_TURBO_DEC");
570f714a188SAmr Mokhtar 
571f714a188SAmr Mokhtar 	TEST_ASSERT(rte_bbdev_enc_op_alloc_bulk(mp_dec, enc_ops_arr, 1) != 0,
572f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_op_alloc_bulk TURBO_DEC: "
573f714a188SAmr Mokhtar 			"OPs type: RTE_BBDEV_OP_TURBO_ENC");
574f714a188SAmr Mokhtar 
575f714a188SAmr Mokhtar 	rte_mempool_free(mp_dec);
576f714a188SAmr Mokhtar 
577f714a188SAmr Mokhtar 	return TEST_SUCCESS;
578f714a188SAmr Mokhtar }
579f714a188SAmr Mokhtar 
580f714a188SAmr Mokhtar static int
test_bbdev_op_pool_size(void)581f714a188SAmr Mokhtar test_bbdev_op_pool_size(void)
582f714a188SAmr Mokhtar {
583f714a188SAmr Mokhtar 	struct rte_mempool *mp_none;
584f714a188SAmr Mokhtar 
585f714a188SAmr Mokhtar 	const unsigned int OPS_COUNT = 128;
586f714a188SAmr Mokhtar 	struct rte_bbdev_enc_op *ops_enc_arr[OPS_COUNT];
587f714a188SAmr Mokhtar 	struct rte_bbdev_enc_op *ops_ext_arr[OPS_COUNT];
588f714a188SAmr Mokhtar 	struct rte_bbdev_enc_op *ops_ext2_arr[OPS_COUNT];
589f714a188SAmr Mokhtar 
590f714a188SAmr Mokhtar 	const char *pool_none = "Test_pool_size";
591f714a188SAmr Mokhtar 
592f714a188SAmr Mokhtar 	/* Valid pool configuration */
593f714a188SAmr Mokhtar 	uint32_t num_elements = 256;
594f714a188SAmr Mokhtar 	uint32_t cache_size = 0;
595f714a188SAmr Mokhtar 
596f714a188SAmr Mokhtar 	/* Create mempool type : RTE_BBDEV_OP_TURBO_ENC, size : 256 */
597f714a188SAmr Mokhtar 	mp_none = rte_bbdev_op_pool_create(pool_none, RTE_BBDEV_OP_TURBO_ENC,
598f714a188SAmr Mokhtar 			num_elements, cache_size, 0);
599f714a188SAmr Mokhtar 	TEST_ASSERT(mp_none != NULL, "Failed to create %s mempool", pool_none);
600f714a188SAmr Mokhtar 
601f714a188SAmr Mokhtar 	/* Add 128 RTE_BBDEV_OP_TURBO_ENC ops */
602f714a188SAmr Mokhtar 	rte_bbdev_enc_op_alloc_bulk(mp_none, ops_enc_arr, OPS_COUNT);
603f714a188SAmr Mokhtar 
604f714a188SAmr Mokhtar 	/* Add 128 RTE_BBDEV_OP_TURBO_ENC ops */
605f714a188SAmr Mokhtar 	TEST_ASSERT(rte_bbdev_enc_op_alloc_bulk(mp_none, ops_ext_arr,
606f714a188SAmr Mokhtar 			OPS_COUNT) == 0,
607f714a188SAmr Mokhtar 			"Failed test for allocating bbdev ops: "
608f714a188SAmr Mokhtar 			"Mempool size: 256, Free : 128, Attempted to add: 128");
609f714a188SAmr Mokhtar 
610f714a188SAmr Mokhtar 	/* Try adding 128 more RTE_BBDEV_OP_TURBO_ENC ops, this should fail */
611f714a188SAmr Mokhtar 	TEST_ASSERT(rte_bbdev_enc_op_alloc_bulk(mp_none, ops_ext2_arr,
612f714a188SAmr Mokhtar 			OPS_COUNT) != 0,
613f714a188SAmr Mokhtar 			"Failed test for allocating bbdev ops: "
614f714a188SAmr Mokhtar 			"Mempool size: 256, Free : 0, Attempted to add: 128");
615f714a188SAmr Mokhtar 
616f714a188SAmr Mokhtar 	/* Free-up 128 RTE_BBDEV_OP_TURBO_ENC ops */
617f714a188SAmr Mokhtar 	rte_bbdev_enc_op_free_bulk(ops_enc_arr, OPS_COUNT);
618f714a188SAmr Mokhtar 
619f714a188SAmr Mokhtar 	/* Try adding 128 RTE_BBDEV_OP_TURBO_DEC ops, this should succeed */
620f714a188SAmr Mokhtar 	/* Cache size > 0 causes reallocation of ops size > 127 fail */
621f714a188SAmr Mokhtar 	TEST_ASSERT(rte_bbdev_enc_op_alloc_bulk(mp_none, ops_ext2_arr,
622f714a188SAmr Mokhtar 			OPS_COUNT) == 0,
623f714a188SAmr Mokhtar 			"Failed test for allocating ops after mempool freed:  "
624f714a188SAmr Mokhtar 			"Mempool size: 256, Free : 128, Attempted to add: 128");
625f714a188SAmr Mokhtar 
626f714a188SAmr Mokhtar 	rte_mempool_free(mp_none);
627f714a188SAmr Mokhtar 
628f714a188SAmr Mokhtar 	return TEST_SUCCESS;
629f714a188SAmr Mokhtar }
630f714a188SAmr Mokhtar 
631f714a188SAmr Mokhtar static int
test_bbdev_count(void)632f714a188SAmr Mokhtar test_bbdev_count(void)
633f714a188SAmr Mokhtar {
634f714a188SAmr Mokhtar 	uint8_t num_devs, num_valid_devs = 0;
635f714a188SAmr Mokhtar 
636f714a188SAmr Mokhtar 	for (num_devs = 0; num_devs < RTE_BBDEV_MAX_DEVS; num_devs++) {
637f714a188SAmr Mokhtar 		if (rte_bbdev_is_valid(num_devs))
638f714a188SAmr Mokhtar 			num_valid_devs++;
639f714a188SAmr Mokhtar 	}
640f714a188SAmr Mokhtar 
641f714a188SAmr Mokhtar 	num_devs = rte_bbdev_count();
642f714a188SAmr Mokhtar 	TEST_ASSERT(num_valid_devs == num_devs,
643f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_is_valid: "
644f714a188SAmr Mokhtar 			"invalid num_devs %u ", num_devs);
645f714a188SAmr Mokhtar 
646f714a188SAmr Mokhtar 	return TEST_SUCCESS;
647f714a188SAmr Mokhtar }
648f714a188SAmr Mokhtar 
649f714a188SAmr Mokhtar static int
test_bbdev_stats(void)650f714a188SAmr Mokhtar test_bbdev_stats(void)
651f714a188SAmr Mokhtar {
652f714a188SAmr Mokhtar 	uint8_t dev_id = null_dev_id;
653f714a188SAmr Mokhtar 	uint16_t queue_id = 0;
654f714a188SAmr Mokhtar 	struct rte_bbdev_dec_op *dec_ops[4096] = { 0 };
655f714a188SAmr Mokhtar 	struct rte_bbdev_dec_op *dec_proc_ops[4096] = { 0 };
656f714a188SAmr Mokhtar 	struct rte_bbdev_enc_op *enc_ops[4096] = { 0 };
657f714a188SAmr Mokhtar 	struct rte_bbdev_enc_op *enc_proc_ops[4096] = { 0 };
658f714a188SAmr Mokhtar 	uint16_t num_ops = 236;
659f714a188SAmr Mokhtar 	struct rte_bbdev_stats stats;
660f714a188SAmr Mokhtar 	struct bbdev_testsuite_params *ts_params = &testsuite_params;
661f714a188SAmr Mokhtar 
662f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_stop(dev_id, queue_id),
663f714a188SAmr Mokhtar 			"Failed to stop queue %u on device %u ", queue_id,
664f714a188SAmr Mokhtar 			dev_id);
665f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stop(dev_id),
666f714a188SAmr Mokhtar 			"Failed to stop bbdev %u ", dev_id);
667f714a188SAmr Mokhtar 
668f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_configure(dev_id, queue_id,
669f714a188SAmr Mokhtar 			&ts_params->qconf),
670f714a188SAmr Mokhtar 			"Failed to configure queue %u on device %u ",
671f714a188SAmr Mokhtar 			queue_id, dev_id);
672f714a188SAmr Mokhtar 
673f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_start(dev_id),
674f714a188SAmr Mokhtar 			"Failed to start bbdev %u ", dev_id);
675f714a188SAmr Mokhtar 
676f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_start(dev_id, queue_id),
677f714a188SAmr Mokhtar 			"Failed to start queue %u on device %u ", queue_id,
678f714a188SAmr Mokhtar 			dev_id);
679f714a188SAmr Mokhtar 
680f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_start(dev_id, queue_id),
681f714a188SAmr Mokhtar 			"Failed to start queue %u on device %u ", queue_id,
682f714a188SAmr Mokhtar 			dev_id);
683f714a188SAmr Mokhtar 
684f714a188SAmr Mokhtar 	/* Tests after enqueue operation */
685f714a188SAmr Mokhtar 	rte_bbdev_enqueue_enc_ops(dev_id, queue_id, enc_ops, num_ops);
686f714a188SAmr Mokhtar 	rte_bbdev_enqueue_dec_ops(dev_id, queue_id, dec_ops, num_ops);
687f714a188SAmr Mokhtar 
688f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_stats_get(RTE_BBDEV_MAX_DEVS, &stats),
689f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_get on device %u ",
690f714a188SAmr Mokhtar 			dev_id);
691f714a188SAmr Mokhtar 
692f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_stats_get(dev_id, NULL),
693f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_get on device %u ",
694f714a188SAmr Mokhtar 			dev_id);
695f714a188SAmr Mokhtar 
696f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stats_get(dev_id, &stats),
697f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_get on device %u ",
698f714a188SAmr Mokhtar 			dev_id);
699f714a188SAmr Mokhtar 
700f714a188SAmr Mokhtar 	TEST_ASSERT(stats.enqueued_count == 2 * num_ops,
701f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_enqueue_ops: "
702f714a188SAmr Mokhtar 			"invalid enqueued_count %" PRIu64 " ",
703f714a188SAmr Mokhtar 			stats.enqueued_count);
704f714a188SAmr Mokhtar 
705f714a188SAmr Mokhtar 	TEST_ASSERT(stats.dequeued_count == 0,
706f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_reset: "
707f714a188SAmr Mokhtar 			"invalid dequeued_count %" PRIu64 " ",
708f714a188SAmr Mokhtar 			stats.dequeued_count);
709f714a188SAmr Mokhtar 
710f714a188SAmr Mokhtar 	/* Tests after dequeue operation */
711f714a188SAmr Mokhtar 	rte_bbdev_dequeue_enc_ops(dev_id, queue_id, enc_proc_ops, num_ops);
712f714a188SAmr Mokhtar 	rte_bbdev_dequeue_dec_ops(dev_id, queue_id, dec_proc_ops, num_ops);
713f714a188SAmr Mokhtar 
714f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stats_get(dev_id, &stats),
715f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_get on device %u ",
716f714a188SAmr Mokhtar 			dev_id);
717f714a188SAmr Mokhtar 
718f714a188SAmr Mokhtar 	TEST_ASSERT(stats.dequeued_count == 2 * num_ops,
719f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_dequeue_ops: "
720f714a188SAmr Mokhtar 			"invalid enqueued_count %" PRIu64 " ",
721f714a188SAmr Mokhtar 			stats.dequeued_count);
722f714a188SAmr Mokhtar 
723f714a188SAmr Mokhtar 	TEST_ASSERT(stats.enqueue_err_count == 0,
724f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_reset: "
725f714a188SAmr Mokhtar 			"invalid enqueue_err_count %" PRIu64 " ",
726f714a188SAmr Mokhtar 			stats.enqueue_err_count);
727f714a188SAmr Mokhtar 
728f714a188SAmr Mokhtar 	TEST_ASSERT(stats.dequeue_err_count == 0,
729f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_reset: "
730f714a188SAmr Mokhtar 			"invalid dequeue_err_count %" PRIu64 " ",
731f714a188SAmr Mokhtar 			stats.dequeue_err_count);
732f714a188SAmr Mokhtar 
733f714a188SAmr Mokhtar 	/* Tests after reset operation */
734f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_stats_reset(RTE_BBDEV_MAX_DEVS),
735f714a188SAmr Mokhtar 			"Failed to reset statistic for device %u ", dev_id);
736f714a188SAmr Mokhtar 
737f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stats_reset(dev_id),
738f714a188SAmr Mokhtar 			"Failed to reset statistic for device %u ", dev_id);
739f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stats_get(dev_id, &stats),
740f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_get on device %u ",
741f714a188SAmr Mokhtar 			dev_id);
742f714a188SAmr Mokhtar 
743f714a188SAmr Mokhtar 	TEST_ASSERT(stats.enqueued_count == 0,
744f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_reset: "
745f714a188SAmr Mokhtar 			"invalid enqueued_count %" PRIu64 " ",
746f714a188SAmr Mokhtar 			stats.enqueued_count);
747f714a188SAmr Mokhtar 
748f714a188SAmr Mokhtar 	TEST_ASSERT(stats.dequeued_count == 0,
749f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_reset: "
750f714a188SAmr Mokhtar 			"invalid dequeued_count %" PRIu64 " ",
751f714a188SAmr Mokhtar 			stats.dequeued_count);
752f714a188SAmr Mokhtar 
753f714a188SAmr Mokhtar 	TEST_ASSERT(stats.enqueue_err_count == 0,
754f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_reset: "
755f714a188SAmr Mokhtar 			"invalid enqueue_err_count %" PRIu64 " ",
756f714a188SAmr Mokhtar 			stats.enqueue_err_count);
757f714a188SAmr Mokhtar 
758f714a188SAmr Mokhtar 	TEST_ASSERT(stats.dequeue_err_count == 0,
759f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_reset: "
760f714a188SAmr Mokhtar 			"invalid dequeue_err_count %" PRIu64 " ",
761f714a188SAmr Mokhtar 			stats.dequeue_err_count);
762f714a188SAmr Mokhtar 
763f714a188SAmr Mokhtar 	return TEST_SUCCESS;
764f714a188SAmr Mokhtar }
765f714a188SAmr Mokhtar 
766f714a188SAmr Mokhtar static int
test_bbdev_driver_init(void)767f714a188SAmr Mokhtar test_bbdev_driver_init(void)
768f714a188SAmr Mokhtar {
769f714a188SAmr Mokhtar 	struct rte_bbdev *dev1, *dev2;
770f714a188SAmr Mokhtar 	const char *name = "dev_name";
771*d819c083SNicolas Chautru 	char name_tmp[32];
772f714a188SAmr Mokhtar 	int num_devs, num_devs_tmp;
773f714a188SAmr Mokhtar 
774f714a188SAmr Mokhtar 	dev1 = rte_bbdev_allocate(NULL);
775f714a188SAmr Mokhtar 	TEST_ASSERT(dev1 == NULL,
776f714a188SAmr Mokhtar 			"Failed initialize bbdev driver with NULL name");
777f714a188SAmr Mokhtar 
778f714a188SAmr Mokhtar 	dev1 = rte_bbdev_allocate(name);
779f714a188SAmr Mokhtar 	TEST_ASSERT(dev1 != NULL, "Failed to initialize bbdev driver");
780f714a188SAmr Mokhtar 
781f714a188SAmr Mokhtar 	dev2 = rte_bbdev_allocate(name);
782f714a188SAmr Mokhtar 	TEST_ASSERT(dev2 == NULL,
783f714a188SAmr Mokhtar 			"Failed to initialize bbdev driver: "
784f714a188SAmr Mokhtar 			"driver with the same name has been initialized before");
785f714a188SAmr Mokhtar 
786f714a188SAmr Mokhtar 	num_devs = rte_bbdev_count() - 1;
787f714a188SAmr Mokhtar 	num_devs_tmp = num_devs;
788f714a188SAmr Mokhtar 
789f714a188SAmr Mokhtar 	/* Initialize the maximum amount of devices */
790f714a188SAmr Mokhtar 	do {
791*d819c083SNicolas Chautru 		sprintf(name_tmp, "%s%i", "name_", num_devs);
792f714a188SAmr Mokhtar 		dev2 = rte_bbdev_allocate(name_tmp);
793f714a188SAmr Mokhtar 		TEST_ASSERT(dev2 != NULL,
794f714a188SAmr Mokhtar 				"Failed to initialize bbdev driver");
795f714a188SAmr Mokhtar 		++num_devs;
796f714a188SAmr Mokhtar 	} while (num_devs < (RTE_BBDEV_MAX_DEVS - 1));
797f714a188SAmr Mokhtar 
798*d819c083SNicolas Chautru 	sprintf(name_tmp, "%s%i", "name_", num_devs);
799f714a188SAmr Mokhtar 	dev2 = rte_bbdev_allocate(name_tmp);
800f714a188SAmr Mokhtar 	TEST_ASSERT(dev2 == NULL, "Failed to initialize bbdev driver number %d "
801f714a188SAmr Mokhtar 			"more drivers than RTE_BBDEV_MAX_DEVS: %d ", num_devs,
802f714a188SAmr Mokhtar 			RTE_BBDEV_MAX_DEVS);
803f714a188SAmr Mokhtar 
804f714a188SAmr Mokhtar 	num_devs--;
805f714a188SAmr Mokhtar 
806f714a188SAmr Mokhtar 	while (num_devs >= num_devs_tmp) {
807*d819c083SNicolas Chautru 		sprintf(name_tmp, "%s%i", "name_", num_devs);
808f714a188SAmr Mokhtar 		dev2 = rte_bbdev_get_named_dev(name_tmp);
809f714a188SAmr Mokhtar 		TEST_ASSERT_SUCCESS(rte_bbdev_release(dev2),
810f714a188SAmr Mokhtar 				"Failed to uninitialize bbdev driver %s ",
811f714a188SAmr Mokhtar 				name_tmp);
812f714a188SAmr Mokhtar 		num_devs--;
813f714a188SAmr Mokhtar 	}
814f714a188SAmr Mokhtar 
815f714a188SAmr Mokhtar 	TEST_ASSERT(dev1->data->dev_id < RTE_BBDEV_MAX_DEVS,
816f714a188SAmr Mokhtar 			"Failed test rte_bbdev_allocate: "
817f714a188SAmr Mokhtar 			"invalid dev_id %" PRIu8 ", max number of devices %d ",
818f714a188SAmr Mokhtar 			dev1->data->dev_id, RTE_BBDEV_MAX_DEVS);
819f714a188SAmr Mokhtar 
820f714a188SAmr Mokhtar 	TEST_ASSERT(dev1->state == RTE_BBDEV_INITIALIZED,
821f714a188SAmr Mokhtar 			"Failed test rte_bbdev_allocate: "
822f714a188SAmr Mokhtar 			"invalid state %d (0 - RTE_BBDEV_UNUSED, 1 - RTE_BBDEV_INITIALIZED",
823f714a188SAmr Mokhtar 			dev1->state);
824f714a188SAmr Mokhtar 
825f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_release(NULL),
826f714a188SAmr Mokhtar 			"Failed to uninitialize bbdev driver with NULL bbdev");
827f714a188SAmr Mokhtar 
828*d819c083SNicolas Chautru 	sprintf(name_tmp, "%s", "invalid_name");
829f714a188SAmr Mokhtar 	dev2 = rte_bbdev_get_named_dev(name_tmp);
830f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_release(dev2),
831f714a188SAmr Mokhtar 			"Failed to uninitialize bbdev driver with invalid name");
832f714a188SAmr Mokhtar 
833f714a188SAmr Mokhtar 	dev2 = rte_bbdev_get_named_dev(name);
834f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_release(dev2),
835f714a188SAmr Mokhtar 			"Failed to uninitialize bbdev driver: %s ", name);
836f714a188SAmr Mokhtar 
837f714a188SAmr Mokhtar 	return TEST_SUCCESS;
838f714a188SAmr Mokhtar }
839f714a188SAmr Mokhtar 
840f714a188SAmr Mokhtar static void
event_callback(uint16_t dev_id,enum rte_bbdev_event_type type,void * param,void * ret_param)841f714a188SAmr Mokhtar event_callback(uint16_t dev_id, enum rte_bbdev_event_type type, void *param,
842f714a188SAmr Mokhtar 		void *ret_param)
843f714a188SAmr Mokhtar {
844f714a188SAmr Mokhtar 	RTE_SET_USED(dev_id);
845f714a188SAmr Mokhtar 	RTE_SET_USED(ret_param);
846f714a188SAmr Mokhtar 
847f714a188SAmr Mokhtar 	if (param == NULL)
848f714a188SAmr Mokhtar 		return;
849f714a188SAmr Mokhtar 
850f714a188SAmr Mokhtar 	if (type == RTE_BBDEV_EVENT_UNKNOWN ||
851f714a188SAmr Mokhtar 			type == RTE_BBDEV_EVENT_ERROR ||
852f714a188SAmr Mokhtar 			type == RTE_BBDEV_EVENT_MAX)
853f714a188SAmr Mokhtar 		*(int *)param = type;
854f714a188SAmr Mokhtar }
855f714a188SAmr Mokhtar 
856f714a188SAmr Mokhtar static int
test_bbdev_callback(void)857f714a188SAmr Mokhtar test_bbdev_callback(void)
858f714a188SAmr Mokhtar {
859f714a188SAmr Mokhtar 	struct rte_bbdev *dev1, *dev2;
860f714a188SAmr Mokhtar 	const char *name = "dev_name1";
861f714a188SAmr Mokhtar 	const char *name2 = "dev_name2";
862f714a188SAmr Mokhtar 	int event_status;
863f714a188SAmr Mokhtar 	uint8_t invalid_dev_id = RTE_BBDEV_MAX_DEVS;
864f714a188SAmr Mokhtar 	enum rte_bbdev_event_type invalid_event_type = RTE_BBDEV_EVENT_MAX;
865f714a188SAmr Mokhtar 	uint8_t dev_id;
866f714a188SAmr Mokhtar 
867f714a188SAmr Mokhtar 	dev1 = rte_bbdev_allocate(name);
868f714a188SAmr Mokhtar 	TEST_ASSERT(dev1 != NULL, "Failed to initialize bbdev driver");
869f714a188SAmr Mokhtar 
870f714a188SAmr Mokhtar 	/*
871f714a188SAmr Mokhtar 	 * RTE_BBDEV_EVENT_UNKNOWN - unregistered
872f714a188SAmr Mokhtar 	 * RTE_BBDEV_EVENT_ERROR - unregistered
873f714a188SAmr Mokhtar 	 */
874f714a188SAmr Mokhtar 	event_status = -1;
875f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_UNKNOWN, NULL);
876f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_ERROR, NULL);
877f714a188SAmr Mokhtar 	TEST_ASSERT(event_status == -1,
878f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process: "
879f714a188SAmr Mokhtar 			"events were not registered ");
880f714a188SAmr Mokhtar 
881f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_callback_register(dev1->data->dev_id,
882f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_MAX, event_callback, NULL),
883f714a188SAmr Mokhtar 			"Failed to callback register for RTE_BBDEV_EVENT_MAX ");
884f714a188SAmr Mokhtar 
885f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_callback_unregister(dev1->data->dev_id,
886f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_MAX, event_callback, NULL),
887f714a188SAmr Mokhtar 			"Failed to unregister RTE_BBDEV_EVENT_MAX ");
888f714a188SAmr Mokhtar 
889f714a188SAmr Mokhtar 	/*
890f714a188SAmr Mokhtar 	 * RTE_BBDEV_EVENT_UNKNOWN - registered
891f714a188SAmr Mokhtar 	 * RTE_BBDEV_EVENT_ERROR - unregistered
892f714a188SAmr Mokhtar 	 */
893f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_callback_register(dev1->data->dev_id,
894f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_UNKNOWN, event_callback, &event_status),
895f714a188SAmr Mokhtar 			"Failed to callback rgstr for RTE_BBDEV_EVENT_UNKNOWN");
896f714a188SAmr Mokhtar 
897f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_UNKNOWN, NULL);
898f287b797SKamil Chalupnik 	TEST_ASSERT(event_status == (int) RTE_BBDEV_EVENT_UNKNOWN,
899f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process "
900f714a188SAmr Mokhtar 			"for RTE_BBDEV_EVENT_UNKNOWN ");
901f714a188SAmr Mokhtar 
902f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_ERROR, NULL);
903f287b797SKamil Chalupnik 	TEST_ASSERT(event_status == (int) RTE_BBDEV_EVENT_UNKNOWN,
904f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process: "
905f714a188SAmr Mokhtar 			"event RTE_BBDEV_EVENT_ERROR was not registered ");
906f714a188SAmr Mokhtar 
907f714a188SAmr Mokhtar 	/*
908f714a188SAmr Mokhtar 	 * RTE_BBDEV_EVENT_UNKNOWN - registered
909f714a188SAmr Mokhtar 	 * RTE_BBDEV_EVENT_ERROR - registered
910f714a188SAmr Mokhtar 	 */
911f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_callback_register(dev1->data->dev_id,
912f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_ERROR, event_callback, &event_status),
913f714a188SAmr Mokhtar 			"Failed to callback rgstr for RTE_BBDEV_EVENT_ERROR ");
914f714a188SAmr Mokhtar 
915f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_callback_register(dev1->data->dev_id,
916f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_ERROR, event_callback, &event_status),
917f714a188SAmr Mokhtar 			"Failed to callback register for RTE_BBDEV_EVENT_ERROR"
918f714a188SAmr Mokhtar 			"(re-registration) ");
919f714a188SAmr Mokhtar 
920f714a188SAmr Mokhtar 	event_status = -1;
921f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_UNKNOWN, NULL);
922f287b797SKamil Chalupnik 	TEST_ASSERT(event_status == (int) RTE_BBDEV_EVENT_UNKNOWN,
923f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process "
924f714a188SAmr Mokhtar 			"for RTE_BBDEV_EVENT_UNKNOWN ");
925f714a188SAmr Mokhtar 
926f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_ERROR, NULL);
927f287b797SKamil Chalupnik 	TEST_ASSERT(event_status == (int) RTE_BBDEV_EVENT_ERROR,
928f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process "
929f714a188SAmr Mokhtar 			"for RTE_BBDEV_EVENT_ERROR ");
930f714a188SAmr Mokhtar 
931f714a188SAmr Mokhtar 	/*
932f714a188SAmr Mokhtar 	 * RTE_BBDEV_EVENT_UNKNOWN - registered
933f714a188SAmr Mokhtar 	 * RTE_BBDEV_EVENT_ERROR - unregistered
934f714a188SAmr Mokhtar 	 */
935f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_callback_unregister(dev1->data->dev_id,
936f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_ERROR, event_callback, &event_status),
937f714a188SAmr Mokhtar 			"Failed to unregister RTE_BBDEV_EVENT_ERROR ");
938f714a188SAmr Mokhtar 
939f714a188SAmr Mokhtar 	event_status = -1;
940f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_UNKNOWN, NULL);
941f287b797SKamil Chalupnik 	TEST_ASSERT(event_status == (int) RTE_BBDEV_EVENT_UNKNOWN,
942f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process "
943f714a188SAmr Mokhtar 			"for RTE_BBDEV_EVENT_UNKNOWN ");
944f714a188SAmr Mokhtar 
945f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_ERROR, NULL);
946f287b797SKamil Chalupnik 	TEST_ASSERT(event_status == (int) RTE_BBDEV_EVENT_UNKNOWN,
947f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process: "
948f714a188SAmr Mokhtar 			"event RTE_BBDEV_EVENT_ERROR was unregistered ");
949f714a188SAmr Mokhtar 
950f714a188SAmr Mokhtar 	/* rte_bbdev_callback_register with invalid inputs */
951f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_callback_register(invalid_dev_id,
952f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_ERROR, event_callback, &event_status),
953f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_callback_register "
954f714a188SAmr Mokhtar 			"for invalid_dev_id ");
955f714a188SAmr Mokhtar 
956f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_callback_register(dev1->data->dev_id,
957f714a188SAmr Mokhtar 			invalid_event_type, event_callback, &event_status),
958f714a188SAmr Mokhtar 			"Failed to callback register for invalid event type ");
959f714a188SAmr Mokhtar 
960f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_callback_register(dev1->data->dev_id,
961f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_ERROR, NULL, &event_status),
962f714a188SAmr Mokhtar 			"Failed to callback register - no callback function ");
963f714a188SAmr Mokhtar 
964f714a188SAmr Mokhtar 	/* The impact of devices on each other */
965f714a188SAmr Mokhtar 	dev2 = rte_bbdev_allocate(name2);
966f714a188SAmr Mokhtar 	TEST_ASSERT(dev2 != NULL,
967f714a188SAmr Mokhtar 			"Failed to initialize bbdev driver");
968f714a188SAmr Mokhtar 
969f714a188SAmr Mokhtar 	/*
970f714a188SAmr Mokhtar 	 * dev2:
971f714a188SAmr Mokhtar 	 * RTE_BBDEV_EVENT_UNKNOWN - unregistered
972f714a188SAmr Mokhtar 	 * RTE_BBDEV_EVENT_ERROR - unregistered
973f714a188SAmr Mokhtar 	 */
974f714a188SAmr Mokhtar 	event_status = -1;
975f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev2, RTE_BBDEV_EVENT_UNKNOWN, NULL);
976f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev2, RTE_BBDEV_EVENT_ERROR, NULL);
977f714a188SAmr Mokhtar 	TEST_ASSERT(event_status == -1,
978f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process: "
979f714a188SAmr Mokhtar 			"events were not registered ");
980f714a188SAmr Mokhtar 
981f714a188SAmr Mokhtar 	/*
982f714a188SAmr Mokhtar 	 * dev1: RTE_BBDEV_EVENT_ERROR - unregistered
983f714a188SAmr Mokhtar 	 * dev2: RTE_BBDEV_EVENT_ERROR - registered
984f714a188SAmr Mokhtar 	 */
985f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_callback_register(dev2->data->dev_id,
986f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_ERROR, event_callback, &event_status),
987f714a188SAmr Mokhtar 			"Failed to callback rgstr for RTE_BBDEV_EVENT_ERROR");
988f714a188SAmr Mokhtar 
989f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_ERROR, NULL);
990f714a188SAmr Mokhtar 	TEST_ASSERT(event_status == -1,
991f714a188SAmr Mokhtar 		"Failed test for rte_bbdev_pmd_callback_process in dev1 "
992f714a188SAmr Mokhtar 		"for RTE_BBDEV_EVENT_ERROR ");
993f714a188SAmr Mokhtar 
994f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev2, RTE_BBDEV_EVENT_ERROR, NULL);
995f287b797SKamil Chalupnik 	TEST_ASSERT(event_status == (int) RTE_BBDEV_EVENT_ERROR,
996f714a188SAmr Mokhtar 		"Failed test for rte_bbdev_pmd_callback_process in dev2 "
997f714a188SAmr Mokhtar 		"for RTE_BBDEV_EVENT_ERROR ");
998f714a188SAmr Mokhtar 
999f714a188SAmr Mokhtar 	/*
1000f714a188SAmr Mokhtar 	 * dev1: RTE_BBDEV_EVENT_UNKNOWN - registered
1001f714a188SAmr Mokhtar 	 * dev2: RTE_BBDEV_EVENT_UNKNOWN - unregistered
1002f714a188SAmr Mokhtar 	 */
1003f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_callback_register(dev2->data->dev_id,
1004f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_UNKNOWN, event_callback, &event_status),
1005f714a188SAmr Mokhtar 			"Failed to callback register for RTE_BBDEV_EVENT_UNKNOWN "
1006f714a188SAmr Mokhtar 			"in dev 2 ");
1007f714a188SAmr Mokhtar 
1008f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev2, RTE_BBDEV_EVENT_UNKNOWN, NULL);
1009f287b797SKamil Chalupnik 	TEST_ASSERT(event_status == (int) RTE_BBDEV_EVENT_UNKNOWN,
1010f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process in dev2"
1011f714a188SAmr Mokhtar 			" for RTE_BBDEV_EVENT_UNKNOWN ");
1012f714a188SAmr Mokhtar 
1013f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_callback_unregister(dev2->data->dev_id,
1014f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_UNKNOWN, event_callback, &event_status),
1015f714a188SAmr Mokhtar 			"Failed to unregister RTE_BBDEV_EVENT_UNKNOWN ");
1016f714a188SAmr Mokhtar 
1017f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_callback_unregister(dev2->data->dev_id,
1018f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_UNKNOWN, event_callback, &event_status),
1019f714a188SAmr Mokhtar 			"Failed to unregister RTE_BBDEV_EVENT_UNKNOWN : "
1020f714a188SAmr Mokhtar 			"unregister function called once again ");
1021f714a188SAmr Mokhtar 
1022f714a188SAmr Mokhtar 	event_status = -1;
1023f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev2, RTE_BBDEV_EVENT_UNKNOWN, NULL);
1024f714a188SAmr Mokhtar 	TEST_ASSERT(event_status == -1,
1025f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process in dev2"
1026f714a188SAmr Mokhtar 		" for RTE_BBDEV_EVENT_UNKNOWN ");
1027f714a188SAmr Mokhtar 
1028f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_UNKNOWN, NULL);
1029f287b797SKamil Chalupnik 	TEST_ASSERT(event_status == (int) RTE_BBDEV_EVENT_UNKNOWN,
1030f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process in dev2 "
1031f714a188SAmr Mokhtar 			"for RTE_BBDEV_EVENT_UNKNOWN ");
1032f714a188SAmr Mokhtar 
1033f714a188SAmr Mokhtar 	/* rte_bbdev_pmd_callback_process with invalid inputs */
1034f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(NULL, RTE_BBDEV_EVENT_UNKNOWN, NULL);
1035f714a188SAmr Mokhtar 
1036f714a188SAmr Mokhtar 	event_status = -1;
1037f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, invalid_event_type, NULL);
1038f714a188SAmr Mokhtar 	TEST_ASSERT(event_status == -1,
1039f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process: "
1040f714a188SAmr Mokhtar 			"for invalid event type ");
1041f714a188SAmr Mokhtar 
1042f714a188SAmr Mokhtar 	/* rte_dev_callback_unregister with invalid inputs */
1043f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_callback_unregister(invalid_dev_id,
1044f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_UNKNOWN, event_callback, &event_status),
1045f714a188SAmr Mokhtar 			"Failed test for rte_dev_callback_unregister "
1046f714a188SAmr Mokhtar 			"for invalid_dev_id ");
1047f714a188SAmr Mokhtar 
1048f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_callback_unregister(dev1->data->dev_id,
1049f714a188SAmr Mokhtar 			invalid_event_type, event_callback, &event_status),
1050f714a188SAmr Mokhtar 			"Failed rte_dev_callback_unregister "
1051f714a188SAmr Mokhtar 			"for invalid event type ");
1052f714a188SAmr Mokhtar 
1053f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_callback_unregister(dev1->data->dev_id,
1054f714a188SAmr Mokhtar 			invalid_event_type, NULL, &event_status),
1055f714a188SAmr Mokhtar 			"Failed rte_dev_callback_unregister "
1056f714a188SAmr Mokhtar 			"when no callback function ");
1057f714a188SAmr Mokhtar 
1058f714a188SAmr Mokhtar 	dev_id = dev1->data->dev_id;
1059f714a188SAmr Mokhtar 
1060f714a188SAmr Mokhtar 	rte_bbdev_release(dev1);
1061f714a188SAmr Mokhtar 	rte_bbdev_release(dev2);
1062f714a188SAmr Mokhtar 
1063f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_callback_register(dev_id,
1064f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_ERROR, event_callback, &event_status),
1065f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_callback_register: "
1066f714a188SAmr Mokhtar 			"function called after rte_bbdev_driver_uninit .");
1067f714a188SAmr Mokhtar 
1068f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_callback_unregister(dev_id,
1069f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_ERROR, event_callback, &event_status),
1070f714a188SAmr Mokhtar 			"Failed test for rte_dev_callback_unregister: "
1071f714a188SAmr Mokhtar 			"function called after rte_bbdev_driver_uninit. ");
1072f714a188SAmr Mokhtar 
1073f714a188SAmr Mokhtar 	event_status = -1;
1074f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_UNKNOWN, NULL);
1075f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev1, RTE_BBDEV_EVENT_ERROR, NULL);
1076f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev2, RTE_BBDEV_EVENT_UNKNOWN, NULL);
1077f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev2, RTE_BBDEV_EVENT_ERROR, NULL);
1078f714a188SAmr Mokhtar 	TEST_ASSERT(event_status == -1,
1079f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_pmd_callback_process: "
1080f714a188SAmr Mokhtar 			"callback function was called after rte_bbdev_driver_uninit");
1081f714a188SAmr Mokhtar 
1082f714a188SAmr Mokhtar 	return TEST_SUCCESS;
1083f714a188SAmr Mokhtar }
1084f714a188SAmr Mokhtar 
1085f714a188SAmr Mokhtar static int
test_bbdev_invalid_driver(void)1086f714a188SAmr Mokhtar test_bbdev_invalid_driver(void)
1087f714a188SAmr Mokhtar {
1088f714a188SAmr Mokhtar 	struct rte_bbdev dev1, *dev2;
1089f714a188SAmr Mokhtar 	uint8_t dev_id = null_dev_id;
1090f714a188SAmr Mokhtar 	uint16_t queue_id = 0;
1091f714a188SAmr Mokhtar 	struct rte_bbdev_stats stats;
1092f714a188SAmr Mokhtar 	struct bbdev_testsuite_params *ts_params = &testsuite_params;
1093f714a188SAmr Mokhtar 	struct rte_bbdev_queue_info qinfo;
1094f714a188SAmr Mokhtar 	struct rte_bbdev_ops dev_ops_tmp;
1095f714a188SAmr Mokhtar 
1096f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stop(dev_id), "Failed to stop bbdev %u ",
1097f714a188SAmr Mokhtar 			dev_id);
1098f714a188SAmr Mokhtar 
1099f714a188SAmr Mokhtar 	dev1 = rte_bbdev_devices[dev_id];
1100f714a188SAmr Mokhtar 	dev2 = &rte_bbdev_devices[dev_id];
1101f714a188SAmr Mokhtar 
1102f714a188SAmr Mokhtar 	/* Tests for rte_bbdev_setup_queues */
1103f714a188SAmr Mokhtar 	dev2->dev_ops = NULL;
1104f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_setup_queues(dev_id, 1, SOCKET_ID_ANY),
1105f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_setup_queues: "
1106f714a188SAmr Mokhtar 			"NULL dev_ops structure ");
1107f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1108f714a188SAmr Mokhtar 
1109f714a188SAmr Mokhtar 	dev_ops_tmp = *dev2->dev_ops;
1110f714a188SAmr Mokhtar 	dev_ops_tmp.info_get = NULL;
1111f714a188SAmr Mokhtar 	dev2->dev_ops = &dev_ops_tmp;
1112f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_setup_queues(dev_id, 1, SOCKET_ID_ANY),
1113f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_setup_queues: "
1114f714a188SAmr Mokhtar 			"NULL info_get ");
1115f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1116f714a188SAmr Mokhtar 
1117f714a188SAmr Mokhtar 	dev_ops_tmp = *dev2->dev_ops;
1118f714a188SAmr Mokhtar 	dev_ops_tmp.queue_release = NULL;
1119f714a188SAmr Mokhtar 	dev2->dev_ops = &dev_ops_tmp;
1120f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_setup_queues(dev_id, 1, SOCKET_ID_ANY),
1121f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_setup_queues: "
1122f714a188SAmr Mokhtar 			"NULL queue_release ");
1123f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1124f714a188SAmr Mokhtar 
1125f714a188SAmr Mokhtar 	dev2->data->socket_id = SOCKET_ID_ANY;
1126f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_setup_queues(dev_id, 1,
1127f714a188SAmr Mokhtar 			SOCKET_ID_ANY), "Failed to configure bbdev %u", dev_id);
1128f714a188SAmr Mokhtar 
1129f714a188SAmr Mokhtar 	/* Test for rte_bbdev_queue_configure */
1130f714a188SAmr Mokhtar 	dev2->dev_ops = NULL;
1131f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_configure(dev_id, queue_id,
1132f714a188SAmr Mokhtar 			&ts_params->qconf),
1133f714a188SAmr Mokhtar 			"Failed to configure queue %u on device %u "
1134f714a188SAmr Mokhtar 			"with NULL dev_ops structure ", queue_id, dev_id);
1135f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1136f714a188SAmr Mokhtar 
1137f714a188SAmr Mokhtar 	dev_ops_tmp = *dev2->dev_ops;
1138f714a188SAmr Mokhtar 	dev_ops_tmp.queue_setup = NULL;
1139f714a188SAmr Mokhtar 	dev2->dev_ops = &dev_ops_tmp;
1140f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_configure(dev_id, queue_id,
1141f714a188SAmr Mokhtar 			&ts_params->qconf),
1142f714a188SAmr Mokhtar 			"Failed to configure queue %u on device %u "
1143f714a188SAmr Mokhtar 			"with NULL queue_setup ", queue_id, dev_id);
1144f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1145f714a188SAmr Mokhtar 
1146f714a188SAmr Mokhtar 	dev_ops_tmp = *dev2->dev_ops;
1147f714a188SAmr Mokhtar 	dev_ops_tmp.info_get = NULL;
1148f714a188SAmr Mokhtar 	dev2->dev_ops = &dev_ops_tmp;
1149f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_configure(dev_id, queue_id,
1150f714a188SAmr Mokhtar 			&ts_params->qconf),
1151f714a188SAmr Mokhtar 			"Failed to configure queue %u on device %u "
1152f714a188SAmr Mokhtar 			"with NULL info_get ", queue_id, dev_id);
1153f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1154f714a188SAmr Mokhtar 
1155f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_configure(RTE_BBDEV_MAX_DEVS,
1156f714a188SAmr Mokhtar 			queue_id, &ts_params->qconf),
1157f714a188SAmr Mokhtar 			"Failed to configure queue %u on device %u ",
1158f714a188SAmr Mokhtar 			queue_id, dev_id);
1159f714a188SAmr Mokhtar 
1160f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_configure(dev_id, queue_id,
1161f714a188SAmr Mokhtar 			&ts_params->qconf),
1162f714a188SAmr Mokhtar 			"Failed to configure queue %u on device %u ",
1163f714a188SAmr Mokhtar 			queue_id, dev_id);
1164f714a188SAmr Mokhtar 
1165f714a188SAmr Mokhtar 	/* Test for rte_bbdev_queue_info_get */
1166f714a188SAmr Mokhtar 	dev2->dev_ops = NULL;
1167f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_info_get(dev_id, queue_id, &qinfo),
1168f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
1169f714a188SAmr Mokhtar 			"NULL dev_ops structure  ");
1170f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1171f714a188SAmr Mokhtar 
1172f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_info_get(RTE_BBDEV_MAX_DEVS,
1173f714a188SAmr Mokhtar 			queue_id, &qinfo),
1174f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
1175f714a188SAmr Mokhtar 			"invalid dev_id ");
1176f714a188SAmr Mokhtar 
1177f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_info_get(dev_id,
1178f714a188SAmr Mokhtar 			RTE_MAX_QUEUES_PER_PORT, &qinfo),
1179f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
1180f714a188SAmr Mokhtar 			"invalid queue_id ");
1181f714a188SAmr Mokhtar 
1182f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_info_get(dev_id, queue_id, NULL),
1183f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_info_get: "
1184f714a188SAmr Mokhtar 			"invalid dev_info ");
1185f714a188SAmr Mokhtar 
1186f714a188SAmr Mokhtar 	/* Test for rte_bbdev_start */
1187f714a188SAmr Mokhtar 	dev2->dev_ops = NULL;
1188f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_start(dev_id),
1189f714a188SAmr Mokhtar 			"Failed to start bbdev %u "
1190f714a188SAmr Mokhtar 			"with NULL dev_ops structure ", dev_id);
1191f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1192f714a188SAmr Mokhtar 
1193f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_start(dev_id),
1194f714a188SAmr Mokhtar 			"Failed to start bbdev %u ", dev_id);
1195f714a188SAmr Mokhtar 
1196f714a188SAmr Mokhtar 	/* Test for rte_bbdev_queue_start */
1197f714a188SAmr Mokhtar 	dev2->dev_ops = NULL;
1198f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_start(dev_id, queue_id),
1199f714a188SAmr Mokhtar 			"Failed to start queue %u on device %u: "
1200f714a188SAmr Mokhtar 			"NULL dev_ops structure", queue_id, dev_id);
1201f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1202f714a188SAmr Mokhtar 
1203f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_start(dev_id, queue_id),
1204f714a188SAmr Mokhtar 			"Failed to start queue %u on device %u ", queue_id,
1205f714a188SAmr Mokhtar 			dev_id);
1206f714a188SAmr Mokhtar 
1207f714a188SAmr Mokhtar 	/* Tests for rte_bbdev_stats_get */
1208f714a188SAmr Mokhtar 	dev2->dev_ops = NULL;
1209f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_stats_get(dev_id, &stats),
1210f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_get on device %u ",
1211f714a188SAmr Mokhtar 			dev_id);
1212f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1213f714a188SAmr Mokhtar 
1214f714a188SAmr Mokhtar 	dev_ops_tmp = *dev2->dev_ops;
1215f714a188SAmr Mokhtar 	dev_ops_tmp.stats_reset = NULL;
1216f714a188SAmr Mokhtar 	dev2->dev_ops = &dev_ops_tmp;
1217f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stats_get(dev_id, &stats),
1218f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_get: "
1219f714a188SAmr Mokhtar 			"NULL stats_get ");
1220f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1221f714a188SAmr Mokhtar 
1222f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stats_get(dev_id, &stats),
1223f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_get on device %u ",
1224f714a188SAmr Mokhtar 			dev_id);
1225f714a188SAmr Mokhtar 
1226f714a188SAmr Mokhtar 	/*
1227f714a188SAmr Mokhtar 	 * Tests for:
1228f714a188SAmr Mokhtar 	 * rte_bbdev_callback_register,
1229f714a188SAmr Mokhtar 	 * rte_bbdev_pmd_callback_process,
1230f714a188SAmr Mokhtar 	 * rte_dev_callback_unregister
1231f714a188SAmr Mokhtar 	 */
1232f714a188SAmr Mokhtar 	dev2->dev_ops = NULL;
1233f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_callback_register(dev_id,
1234f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_UNKNOWN, event_callback, NULL),
1235f714a188SAmr Mokhtar 			"Failed to callback rgstr for RTE_BBDEV_EVENT_UNKNOWN");
1236f714a188SAmr Mokhtar 	rte_bbdev_pmd_callback_process(dev2, RTE_BBDEV_EVENT_UNKNOWN, NULL);
1237f714a188SAmr Mokhtar 
1238f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_callback_unregister(dev_id,
1239f714a188SAmr Mokhtar 			RTE_BBDEV_EVENT_UNKNOWN, event_callback, NULL),
1240f714a188SAmr Mokhtar 			"Failed to unregister RTE_BBDEV_EVENT_ERROR ");
1241f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1242f714a188SAmr Mokhtar 
1243f714a188SAmr Mokhtar 	/* Tests for rte_bbdev_stats_reset */
1244f714a188SAmr Mokhtar 	dev2->dev_ops = NULL;
1245f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_stats_reset(dev_id),
1246f714a188SAmr Mokhtar 			"Failed to reset statistic for device %u ", dev_id);
1247f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1248f714a188SAmr Mokhtar 
1249f714a188SAmr Mokhtar 	dev_ops_tmp = *dev2->dev_ops;
1250f714a188SAmr Mokhtar 	dev_ops_tmp.stats_reset = NULL;
1251f714a188SAmr Mokhtar 	dev2->dev_ops = &dev_ops_tmp;
1252f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stats_reset(dev_id),
1253f714a188SAmr Mokhtar 			"Failed test for rte_bbdev_stats_reset: "
1254f714a188SAmr Mokhtar 			"NULL stats_reset ");
1255f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1256f714a188SAmr Mokhtar 
1257f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stats_reset(dev_id),
1258f714a188SAmr Mokhtar 			"Failed to reset statistic for device %u ", dev_id);
1259f714a188SAmr Mokhtar 
1260f714a188SAmr Mokhtar 	/* Tests for rte_bbdev_queue_stop */
1261f714a188SAmr Mokhtar 	dev2->dev_ops = NULL;
1262f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_queue_stop(dev_id, queue_id),
1263f714a188SAmr Mokhtar 			"Failed to stop queue %u on device %u: "
1264f714a188SAmr Mokhtar 			"NULL dev_ops structure", queue_id, dev_id);
1265f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1266f714a188SAmr Mokhtar 
1267f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_queue_stop(dev_id, queue_id),
1268f714a188SAmr Mokhtar 			"Failed to stop queue %u on device %u ", queue_id,
1269f714a188SAmr Mokhtar 			dev_id);
1270f714a188SAmr Mokhtar 
1271f714a188SAmr Mokhtar 	/* Tests for rte_bbdev_stop */
1272f714a188SAmr Mokhtar 	dev2->dev_ops = NULL;
1273f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_stop(dev_id),
1274f714a188SAmr Mokhtar 			"Failed to stop bbdev %u with NULL dev_ops structure ",
1275f714a188SAmr Mokhtar 			dev_id);
1276f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1277f714a188SAmr Mokhtar 
1278f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_stop(dev_id),
1279f714a188SAmr Mokhtar 			"Failed to stop bbdev %u ", dev_id);
1280f714a188SAmr Mokhtar 
1281f714a188SAmr Mokhtar 	/* Tests for rte_bbdev_close */
1282f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_close(RTE_BBDEV_MAX_DEVS),
1283f714a188SAmr Mokhtar 			"Failed to close bbdev with invalid dev_id");
1284f714a188SAmr Mokhtar 
1285f714a188SAmr Mokhtar 	dev2->dev_ops = NULL;
1286f714a188SAmr Mokhtar 	TEST_ASSERT_FAIL(rte_bbdev_close(dev_id),
1287f714a188SAmr Mokhtar 			"Failed to close bbdev %u with NULL dev_ops structure ",
1288f714a188SAmr Mokhtar 			dev_id);
1289f714a188SAmr Mokhtar 	dev2->dev_ops = dev1.dev_ops;
1290f714a188SAmr Mokhtar 
1291f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_close(dev_id),
1292f714a188SAmr Mokhtar 			"Failed to close bbdev %u ", dev_id);
1293f714a188SAmr Mokhtar 
1294f714a188SAmr Mokhtar 	return TEST_SUCCESS;
1295f714a188SAmr Mokhtar }
1296f714a188SAmr Mokhtar 
1297f714a188SAmr Mokhtar static int
test_bbdev_get_named_dev(void)1298f714a188SAmr Mokhtar test_bbdev_get_named_dev(void)
1299f714a188SAmr Mokhtar {
1300f714a188SAmr Mokhtar 	struct rte_bbdev *dev, *dev_tmp;
1301f714a188SAmr Mokhtar 	const char *name = "name";
1302f714a188SAmr Mokhtar 
1303f714a188SAmr Mokhtar 	dev = rte_bbdev_allocate(name);
1304f714a188SAmr Mokhtar 	TEST_ASSERT(dev != NULL, "Failed to initialize bbdev driver");
1305f714a188SAmr Mokhtar 
1306f714a188SAmr Mokhtar 	dev_tmp = rte_bbdev_get_named_dev(NULL);
1307f714a188SAmr Mokhtar 	TEST_ASSERT(dev_tmp == NULL, "Failed test for rte_bbdev_get_named_dev: "
1308f714a188SAmr Mokhtar 			"function called with NULL parameter");
1309f714a188SAmr Mokhtar 
1310f714a188SAmr Mokhtar 	dev_tmp = rte_bbdev_get_named_dev(name);
1311f714a188SAmr Mokhtar 
1312f714a188SAmr Mokhtar 	TEST_ASSERT(dev == dev_tmp, "Failed test for rte_bbdev_get_named_dev: "
1313f714a188SAmr Mokhtar 			"wrong device was returned ");
1314f714a188SAmr Mokhtar 
1315f714a188SAmr Mokhtar 	TEST_ASSERT_SUCCESS(rte_bbdev_release(dev),
1316f714a188SAmr Mokhtar 			"Failed to uninitialize bbdev driver %s ", name);
1317f714a188SAmr Mokhtar 
1318f714a188SAmr Mokhtar 	return TEST_SUCCESS;
1319f714a188SAmr Mokhtar }
1320f714a188SAmr Mokhtar 
1321f714a188SAmr Mokhtar static struct unit_test_suite bbdev_null_testsuite = {
1322f714a188SAmr Mokhtar 	.suite_name = "BBDEV NULL Unit Test Suite",
1323f714a188SAmr Mokhtar 	.setup = testsuite_setup,
1324f714a188SAmr Mokhtar 	.teardown = testsuite_teardown,
1325f714a188SAmr Mokhtar 	.unit_test_cases = {
1326f714a188SAmr Mokhtar 
1327f714a188SAmr Mokhtar 		TEST_CASE(test_bbdev_configure_invalid_dev_id),
1328f714a188SAmr Mokhtar 
1329f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1330f714a188SAmr Mokhtar 				test_bbdev_configure_invalid_num_queues),
1331f714a188SAmr Mokhtar 
1332f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1333f714a188SAmr Mokhtar 				test_bbdev_configure_stop_device),
1334f714a188SAmr Mokhtar 
1335f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1336f714a188SAmr Mokhtar 				test_bbdev_configure_stop_queue),
1337f714a188SAmr Mokhtar 
1338f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1339f714a188SAmr Mokhtar 				test_bbdev_configure_invalid_queue_configure),
1340f714a188SAmr Mokhtar 
1341f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1342f714a188SAmr Mokhtar 				test_bbdev_op_pool),
1343f714a188SAmr Mokhtar 
1344f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1345f714a188SAmr Mokhtar 				test_bbdev_op_type),
1346f714a188SAmr Mokhtar 
1347f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1348f714a188SAmr Mokhtar 				test_bbdev_op_pool_size),
1349f714a188SAmr Mokhtar 
1350f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1351f714a188SAmr Mokhtar 				test_bbdev_stats),
1352f714a188SAmr Mokhtar 
1353f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1354f714a188SAmr Mokhtar 				test_bbdev_driver_init),
1355f714a188SAmr Mokhtar 
1356f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1357f714a188SAmr Mokhtar 				test_bbdev_callback),
1358f714a188SAmr Mokhtar 
1359f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1360f714a188SAmr Mokhtar 				test_bbdev_invalid_driver),
1361f714a188SAmr Mokhtar 
1362f714a188SAmr Mokhtar 		TEST_CASE_ST(ut_setup, ut_teardown,
1363f714a188SAmr Mokhtar 				test_bbdev_get_named_dev),
1364f714a188SAmr Mokhtar 
1365f714a188SAmr Mokhtar 		TEST_CASE(test_bbdev_count),
1366f714a188SAmr Mokhtar 
1367f714a188SAmr Mokhtar 		TEST_CASES_END() /**< NULL terminate unit test array */
1368f714a188SAmr Mokhtar 	}
1369f714a188SAmr Mokhtar };
1370f714a188SAmr Mokhtar 
1371f714a188SAmr Mokhtar REGISTER_TEST_COMMAND(unittest, bbdev_null_testsuite);
1372