1473c88f9SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2473c88f9SBruce Richardson * Copyright 2017 NXP
3473c88f9SBruce Richardson */
4473c88f9SBruce Richardson
5473c88f9SBruce Richardson #include <rte_common.h>
6473c88f9SBruce Richardson #include <rte_mbuf.h>
7473c88f9SBruce Richardson #include <rte_malloc.h>
8473c88f9SBruce Richardson #include <rte_memcpy.h>
9473c88f9SBruce Richardson #include <rte_dev.h>
10473c88f9SBruce Richardson #include <rte_rawdev.h>
11473c88f9SBruce Richardson #include <rte_bus_vdev.h>
12473c88f9SBruce Richardson #include <rte_test.h>
13473c88f9SBruce Richardson
14473c88f9SBruce Richardson /* Using relative path as skeleton_rawdev is not part of exported headers */
15473c88f9SBruce Richardson #include "skeleton_rawdev.h"
16473c88f9SBruce Richardson
17473c88f9SBruce Richardson #define TEST_DEV_NAME "rawdev_skeleton"
18473c88f9SBruce Richardson
19473c88f9SBruce Richardson #define SKELDEV_LOGS(level, fmt, args...) \
20473c88f9SBruce Richardson rte_log(RTE_LOG_ ## level, skeleton_pmd_logtype, fmt "\n", \
21473c88f9SBruce Richardson ##args)
22473c88f9SBruce Richardson
23473c88f9SBruce Richardson #define SKELDEV_TEST_INFO(fmt, args...) \
24473c88f9SBruce Richardson SKELDEV_LOGS(INFO, fmt, ## args)
25473c88f9SBruce Richardson #define SKELDEV_TEST_DEBUG(fmt, args...) \
26473c88f9SBruce Richardson SKELDEV_LOGS(DEBUG, fmt, ## args)
27473c88f9SBruce Richardson
28473c88f9SBruce Richardson #define SKELDEV_TEST_RUN(setup, teardown, test) \
29473c88f9SBruce Richardson skeldev_test_run(setup, teardown, test, #test)
30473c88f9SBruce Richardson
31473c88f9SBruce Richardson #define TEST_SUCCESS 0
32473c88f9SBruce Richardson #define TEST_FAILED -1
33473c88f9SBruce Richardson
34473c88f9SBruce Richardson static int total;
35473c88f9SBruce Richardson static int passed;
36473c88f9SBruce Richardson static int failed;
37473c88f9SBruce Richardson static int unsupported;
38473c88f9SBruce Richardson
39473c88f9SBruce Richardson static uint16_t test_dev_id;
40473c88f9SBruce Richardson
41473c88f9SBruce Richardson static int
testsuite_setup(void)42473c88f9SBruce Richardson testsuite_setup(void)
43473c88f9SBruce Richardson {
44473c88f9SBruce Richardson uint8_t count;
4522b5c63eSLukasz Wojciechowski
4622b5c63eSLukasz Wojciechowski total = 0;
4722b5c63eSLukasz Wojciechowski passed = 0;
4822b5c63eSLukasz Wojciechowski failed = 0;
4922b5c63eSLukasz Wojciechowski unsupported = 0;
5022b5c63eSLukasz Wojciechowski
51473c88f9SBruce Richardson count = rte_rawdev_count();
52473c88f9SBruce Richardson if (!count) {
53473c88f9SBruce Richardson SKELDEV_TEST_INFO("\tNo existing rawdev; "
54473c88f9SBruce Richardson "Creating 'skeldev_rawdev'");
55473c88f9SBruce Richardson return rte_vdev_init(TEST_DEV_NAME, NULL);
56473c88f9SBruce Richardson }
57473c88f9SBruce Richardson
58473c88f9SBruce Richardson return TEST_SUCCESS;
59473c88f9SBruce Richardson }
60473c88f9SBruce Richardson
61473c88f9SBruce Richardson static void local_teardown(void);
62473c88f9SBruce Richardson
63473c88f9SBruce Richardson static void
testsuite_teardown(void)64473c88f9SBruce Richardson testsuite_teardown(void)
65473c88f9SBruce Richardson {
66473c88f9SBruce Richardson local_teardown();
67473c88f9SBruce Richardson }
68473c88f9SBruce Richardson
69473c88f9SBruce Richardson static void
local_teardown(void)70473c88f9SBruce Richardson local_teardown(void)
71473c88f9SBruce Richardson {
72473c88f9SBruce Richardson rte_vdev_uninit(TEST_DEV_NAME);
73473c88f9SBruce Richardson }
74473c88f9SBruce Richardson
75473c88f9SBruce Richardson static int
test_rawdev_count(void)76473c88f9SBruce Richardson test_rawdev_count(void)
77473c88f9SBruce Richardson {
78473c88f9SBruce Richardson uint8_t count;
79473c88f9SBruce Richardson count = rte_rawdev_count();
80473c88f9SBruce Richardson RTE_TEST_ASSERT(count > 0, "Invalid rawdev count %" PRIu8, count);
81473c88f9SBruce Richardson return TEST_SUCCESS;
82473c88f9SBruce Richardson }
83473c88f9SBruce Richardson
84473c88f9SBruce Richardson static int
test_rawdev_get_dev_id(void)85473c88f9SBruce Richardson test_rawdev_get_dev_id(void)
86473c88f9SBruce Richardson {
87473c88f9SBruce Richardson int ret;
88473c88f9SBruce Richardson ret = rte_rawdev_get_dev_id("invalid_rawdev_device");
89473c88f9SBruce Richardson RTE_TEST_ASSERT_FAIL(ret, "Expected <0 for invalid dev name ret=%d",
90473c88f9SBruce Richardson ret);
91473c88f9SBruce Richardson return TEST_SUCCESS;
92473c88f9SBruce Richardson }
93473c88f9SBruce Richardson
94473c88f9SBruce Richardson static int
test_rawdev_socket_id(void)95473c88f9SBruce Richardson test_rawdev_socket_id(void)
96473c88f9SBruce Richardson {
97473c88f9SBruce Richardson int socket_id;
98473c88f9SBruce Richardson socket_id = rte_rawdev_socket_id(test_dev_id);
99473c88f9SBruce Richardson RTE_TEST_ASSERT(socket_id != -EINVAL,
100473c88f9SBruce Richardson "Failed to get socket_id %d", socket_id);
101473c88f9SBruce Richardson socket_id = rte_rawdev_socket_id(RTE_RAWDEV_MAX_DEVS);
102473c88f9SBruce Richardson RTE_TEST_ASSERT(socket_id == -EINVAL,
103473c88f9SBruce Richardson "Expected -EINVAL %d", socket_id);
104473c88f9SBruce Richardson
105473c88f9SBruce Richardson return TEST_SUCCESS;
106473c88f9SBruce Richardson }
107473c88f9SBruce Richardson
108473c88f9SBruce Richardson static int
test_rawdev_info_get(void)109473c88f9SBruce Richardson test_rawdev_info_get(void)
110473c88f9SBruce Richardson {
111473c88f9SBruce Richardson int ret;
112473c88f9SBruce Richardson struct rte_rawdev_info rdev_info = {0};
113473c88f9SBruce Richardson struct skeleton_rawdev_conf skel_conf = {0};
114473c88f9SBruce Richardson
11510b71caeSBruce Richardson ret = rte_rawdev_info_get(test_dev_id, NULL, 0);
116473c88f9SBruce Richardson RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
117473c88f9SBruce Richardson
118473c88f9SBruce Richardson rdev_info.dev_private = &skel_conf;
119473c88f9SBruce Richardson
12010b71caeSBruce Richardson ret = rte_rawdev_info_get(test_dev_id, &rdev_info, sizeof(skel_conf));
121473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get raw dev info");
122473c88f9SBruce Richardson
123473c88f9SBruce Richardson return TEST_SUCCESS;
124473c88f9SBruce Richardson }
125473c88f9SBruce Richardson
126473c88f9SBruce Richardson static int
test_rawdev_configure(void)127473c88f9SBruce Richardson test_rawdev_configure(void)
128473c88f9SBruce Richardson {
129473c88f9SBruce Richardson int ret;
130473c88f9SBruce Richardson struct rte_rawdev_info rdev_info = {0};
131473c88f9SBruce Richardson struct skeleton_rawdev_conf rdev_conf_set = {0};
132473c88f9SBruce Richardson struct skeleton_rawdev_conf rdev_conf_get = {0};
133473c88f9SBruce Richardson
134473c88f9SBruce Richardson /* Check invalid configuration */
1358db9dce7SBruce Richardson ret = rte_rawdev_configure(test_dev_id, NULL, 0);
136473c88f9SBruce Richardson RTE_TEST_ASSERT(ret == -EINVAL,
137473c88f9SBruce Richardson "Null configure; Expected -EINVAL, got %d", ret);
138473c88f9SBruce Richardson
139473c88f9SBruce Richardson /* Valid configuration test */
140473c88f9SBruce Richardson rdev_conf_set.num_queues = 1;
141473c88f9SBruce Richardson rdev_conf_set.capabilities = SKELETON_CAPA_FW_LOAD |
142473c88f9SBruce Richardson SKELETON_CAPA_FW_RESET;
143473c88f9SBruce Richardson
144473c88f9SBruce Richardson rdev_info.dev_private = &rdev_conf_set;
145473c88f9SBruce Richardson ret = rte_rawdev_configure(test_dev_id,
1468db9dce7SBruce Richardson (rte_rawdev_obj_t)&rdev_info,
1478db9dce7SBruce Richardson sizeof(rdev_conf_set));
148473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret, "Failed to configure rawdev (%d)", ret);
149473c88f9SBruce Richardson
150473c88f9SBruce Richardson rdev_info.dev_private = &rdev_conf_get;
151473c88f9SBruce Richardson ret = rte_rawdev_info_get(test_dev_id,
15210b71caeSBruce Richardson (rte_rawdev_obj_t)&rdev_info,
15310b71caeSBruce Richardson sizeof(rdev_conf_get));
154473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret,
155473c88f9SBruce Richardson "Failed to obtain rawdev configuration (%d)",
156473c88f9SBruce Richardson ret);
157473c88f9SBruce Richardson
158473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(rdev_conf_set.num_queues,
159473c88f9SBruce Richardson rdev_conf_get.num_queues,
160473c88f9SBruce Richardson "Configuration test failed; num_queues (%d)(%d)",
161473c88f9SBruce Richardson rdev_conf_set.num_queues,
162473c88f9SBruce Richardson rdev_conf_get.num_queues);
163473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(rdev_conf_set.capabilities,
164473c88f9SBruce Richardson rdev_conf_get.capabilities,
165473c88f9SBruce Richardson "Configuration test failed; capabilities");
166473c88f9SBruce Richardson
167473c88f9SBruce Richardson return TEST_SUCCESS;
168473c88f9SBruce Richardson }
169473c88f9SBruce Richardson
170473c88f9SBruce Richardson static int
test_rawdev_queue_default_conf_get(void)171473c88f9SBruce Richardson test_rawdev_queue_default_conf_get(void)
172473c88f9SBruce Richardson {
173473c88f9SBruce Richardson int ret, i;
174473c88f9SBruce Richardson struct rte_rawdev_info rdev_info = {0};
175473c88f9SBruce Richardson struct skeleton_rawdev_conf rdev_conf_get = {0};
176473c88f9SBruce Richardson struct skeleton_rawdev_queue q = {0};
177473c88f9SBruce Richardson
178473c88f9SBruce Richardson /* Get the current configuration */
179473c88f9SBruce Richardson rdev_info.dev_private = &rdev_conf_get;
180473c88f9SBruce Richardson ret = rte_rawdev_info_get(test_dev_id,
18110b71caeSBruce Richardson (rte_rawdev_obj_t)&rdev_info,
18210b71caeSBruce Richardson sizeof(rdev_conf_get));
183473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain rawdev configuration (%d)",
184473c88f9SBruce Richardson ret);
185473c88f9SBruce Richardson
186473c88f9SBruce Richardson /* call to test_rawdev_configure would have set the num_queues = 1 */
187473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(!(rdev_conf_get.num_queues > 0),
188473c88f9SBruce Richardson "Invalid number of queues (%d). Expected 1",
189473c88f9SBruce Richardson rdev_conf_get.num_queues);
190473c88f9SBruce Richardson /* All queues by default should have state = DETACH and
191473c88f9SBruce Richardson * depth = DEF_DEPTH
192473c88f9SBruce Richardson */
193473c88f9SBruce Richardson for (i = 0; i < rdev_conf_get.num_queues; i++) {
194f574ed81SBruce Richardson rte_rawdev_queue_conf_get(test_dev_id, i, &q, sizeof(q));
195473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(q.depth, SKELETON_QUEUE_DEF_DEPTH,
196473c88f9SBruce Richardson "Invalid default depth of queue (%d)",
197473c88f9SBruce Richardson q.depth);
198473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(q.state, SKELETON_QUEUE_DETACH,
199473c88f9SBruce Richardson "Invalid default state of queue (%d)",
200473c88f9SBruce Richardson q.state);
201473c88f9SBruce Richardson }
202473c88f9SBruce Richardson
203473c88f9SBruce Richardson return TEST_SUCCESS;
204473c88f9SBruce Richardson }
205473c88f9SBruce Richardson
206473c88f9SBruce Richardson static int
test_rawdev_queue_count(void)207473c88f9SBruce Richardson test_rawdev_queue_count(void)
208473c88f9SBruce Richardson {
209473c88f9SBruce Richardson unsigned int q_count;
210473c88f9SBruce Richardson
211473c88f9SBruce Richardson /* Get the current configuration */
212473c88f9SBruce Richardson q_count = rte_rawdev_queue_count(test_dev_id);
213473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(q_count, 1, "Invalid queue count (%d)", q_count);
214473c88f9SBruce Richardson
215473c88f9SBruce Richardson return TEST_SUCCESS;
216473c88f9SBruce Richardson }
217473c88f9SBruce Richardson
218473c88f9SBruce Richardson static int
test_rawdev_queue_setup(void)219473c88f9SBruce Richardson test_rawdev_queue_setup(void)
220473c88f9SBruce Richardson {
221473c88f9SBruce Richardson int ret;
222473c88f9SBruce Richardson struct rte_rawdev_info rdev_info = {0};
223473c88f9SBruce Richardson struct skeleton_rawdev_conf rdev_conf_get = {0};
224473c88f9SBruce Richardson struct skeleton_rawdev_queue qset = {0};
225473c88f9SBruce Richardson struct skeleton_rawdev_queue qget = {0};
226473c88f9SBruce Richardson
227473c88f9SBruce Richardson /* Get the current configuration */
228473c88f9SBruce Richardson rdev_info.dev_private = &rdev_conf_get;
229473c88f9SBruce Richardson ret = rte_rawdev_info_get(test_dev_id,
23010b71caeSBruce Richardson (rte_rawdev_obj_t)&rdev_info,
23110b71caeSBruce Richardson sizeof(rdev_conf_get));
232473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret,
233473c88f9SBruce Richardson "Failed to obtain rawdev configuration (%d)",
234473c88f9SBruce Richardson ret);
235473c88f9SBruce Richardson
236473c88f9SBruce Richardson /* call to test_rawdev_configure would have set the num_queues = 1 */
237473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(!(rdev_conf_get.num_queues > 0),
238473c88f9SBruce Richardson "Invalid number of queues (%d). Expected 1",
239473c88f9SBruce Richardson rdev_conf_get.num_queues);
240473c88f9SBruce Richardson
241473c88f9SBruce Richardson /* Modify the queue depth for Queue 0 and attach it */
242473c88f9SBruce Richardson qset.depth = 15;
243473c88f9SBruce Richardson qset.state = SKELETON_QUEUE_ATTACH;
244f574ed81SBruce Richardson ret = rte_rawdev_queue_setup(test_dev_id, 0, &qset, sizeof(qset));
245473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup queue (%d)", ret);
246473c88f9SBruce Richardson
247473c88f9SBruce Richardson /* Now, fetching the queue 0 should show depth as 15 */
248f574ed81SBruce Richardson ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget, sizeof(qget));
249473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret);
250473c88f9SBruce Richardson
251473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(qset.depth, qget.depth,
252473c88f9SBruce Richardson "Failed to set queue depth: Need(%d), has(%d)",
253473c88f9SBruce Richardson qset.depth, qget.depth);
254473c88f9SBruce Richardson
255473c88f9SBruce Richardson return TEST_SUCCESS;
256473c88f9SBruce Richardson }
257473c88f9SBruce Richardson
258473c88f9SBruce Richardson /* After executing test_rawdev_queue_setup, queue_id=0 would have depth as 15.
259473c88f9SBruce Richardson * Releasing should set it back to default. state would set to DETACH
260473c88f9SBruce Richardson */
261473c88f9SBruce Richardson static int
test_rawdev_queue_release(void)262473c88f9SBruce Richardson test_rawdev_queue_release(void)
263473c88f9SBruce Richardson {
264473c88f9SBruce Richardson int ret;
265473c88f9SBruce Richardson struct skeleton_rawdev_queue qget = {0};
266473c88f9SBruce Richardson
267473c88f9SBruce Richardson /* Now, fetching the queue 0 should show depth as 100 */
268473c88f9SBruce Richardson ret = rte_rawdev_queue_release(test_dev_id, 0);
269473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret, "Failed to release queue 0; (%d)", ret);
270473c88f9SBruce Richardson
271473c88f9SBruce Richardson /* Now, fetching the queue 0 should show depth as default */
272f574ed81SBruce Richardson ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget, sizeof(qget));
273473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret);
274473c88f9SBruce Richardson
275473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(qget.depth, SKELETON_QUEUE_DEF_DEPTH,
276473c88f9SBruce Richardson "Release of Queue 0 failed; (depth)");
277473c88f9SBruce Richardson
278473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(qget.state, SKELETON_QUEUE_DETACH,
279473c88f9SBruce Richardson "Release of Queue 0 failed; (state)");
280473c88f9SBruce Richardson
281473c88f9SBruce Richardson return TEST_SUCCESS;
282473c88f9SBruce Richardson }
283473c88f9SBruce Richardson
284473c88f9SBruce Richardson static int
test_rawdev_attr_set_get(void)285473c88f9SBruce Richardson test_rawdev_attr_set_get(void)
286473c88f9SBruce Richardson {
287473c88f9SBruce Richardson int ret;
288473c88f9SBruce Richardson int *dummy_value, set_value;
289473c88f9SBruce Richardson uint64_t ret_value;
290473c88f9SBruce Richardson
291473c88f9SBruce Richardson /* Set an attribute and fetch it */
292473c88f9SBruce Richardson ret = rte_rawdev_set_attr(test_dev_id, "Test1", 100);
293473c88f9SBruce Richardson RTE_TEST_ASSERT(!ret, "Unable to set an attribute (Test1)");
294473c88f9SBruce Richardson
295473c88f9SBruce Richardson dummy_value = &set_value;
296473c88f9SBruce Richardson *dummy_value = 200;
297473c88f9SBruce Richardson ret = rte_rawdev_set_attr(test_dev_id, "Test2", (uintptr_t)dummy_value);
298*b9701282SMin Hu (Connor) RTE_TEST_ASSERT(!ret, "Unable to set an attribute (Test2)");
299473c88f9SBruce Richardson
300473c88f9SBruce Richardson /* Check if attributes have been set */
301473c88f9SBruce Richardson ret = rte_rawdev_get_attr(test_dev_id, "Test1", &ret_value);
302473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(ret_value, 100,
303473c88f9SBruce Richardson "Attribute (Test1) not set correctly (%" PRIu64 ")",
304473c88f9SBruce Richardson ret_value);
305473c88f9SBruce Richardson
306473c88f9SBruce Richardson ret_value = 0;
307473c88f9SBruce Richardson ret = rte_rawdev_get_attr(test_dev_id, "Test2", &ret_value);
308473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(*((int *)(uintptr_t)ret_value), set_value,
309473c88f9SBruce Richardson "Attribute (Test2) not set correctly (%" PRIu64 ")",
310473c88f9SBruce Richardson ret_value);
311473c88f9SBruce Richardson
312473c88f9SBruce Richardson return TEST_SUCCESS;
313473c88f9SBruce Richardson }
314473c88f9SBruce Richardson
315473c88f9SBruce Richardson static int
test_rawdev_start_stop(void)316473c88f9SBruce Richardson test_rawdev_start_stop(void)
317473c88f9SBruce Richardson {
318473c88f9SBruce Richardson int ret;
319473c88f9SBruce Richardson struct rte_rawdev_info rdev_info = {0};
320473c88f9SBruce Richardson struct skeleton_rawdev_conf rdev_conf_get = {0};
321473c88f9SBruce Richardson char *dummy_firmware = NULL;
322473c88f9SBruce Richardson
323473c88f9SBruce Richardson /* Get the current configuration */
324473c88f9SBruce Richardson rdev_info.dev_private = &rdev_conf_get;
325473c88f9SBruce Richardson
326473c88f9SBruce Richardson /* Load a firmware using a dummy address area */
327473c88f9SBruce Richardson dummy_firmware = rte_zmalloc("RAWDEV SKELETON", sizeof(int) * 10, 0);
328473c88f9SBruce Richardson RTE_TEST_ASSERT(dummy_firmware != NULL,
329473c88f9SBruce Richardson "Failed to create firmware memory backing");
330473c88f9SBruce Richardson
331473c88f9SBruce Richardson ret = rte_rawdev_firmware_load(test_dev_id, dummy_firmware);
332473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret, "Firmware loading failed (%d)", ret);
333473c88f9SBruce Richardson
334473c88f9SBruce Richardson /* Skeleton doesn't do anything with the firmware area - that is dummy
335473c88f9SBruce Richardson * and can be removed.
336473c88f9SBruce Richardson */
337473c88f9SBruce Richardson rte_free(dummy_firmware);
338473c88f9SBruce Richardson dummy_firmware = NULL;
339473c88f9SBruce Richardson
340473c88f9SBruce Richardson rte_rawdev_start(test_dev_id);
34110b71caeSBruce Richardson ret = rte_rawdev_info_get(test_dev_id, (rte_rawdev_obj_t)&rdev_info,
34210b71caeSBruce Richardson sizeof(rdev_conf_get));
343473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret,
344473c88f9SBruce Richardson "Failed to obtain rawdev configuration (%d)",
345473c88f9SBruce Richardson ret);
346473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(rdev_conf_get.device_state, SKELETON_DEV_RUNNING,
347473c88f9SBruce Richardson "Device start failed. State is (%d)",
348473c88f9SBruce Richardson rdev_conf_get.device_state);
349473c88f9SBruce Richardson
350473c88f9SBruce Richardson rte_rawdev_stop(test_dev_id);
35110b71caeSBruce Richardson ret = rte_rawdev_info_get(test_dev_id, (rte_rawdev_obj_t)&rdev_info,
35210b71caeSBruce Richardson sizeof(rdev_conf_get));
353473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret,
354473c88f9SBruce Richardson "Failed to obtain rawdev configuration (%d)",
355473c88f9SBruce Richardson ret);
356473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL(rdev_conf_get.device_state, SKELETON_DEV_STOPPED,
357473c88f9SBruce Richardson "Device stop failed. State is (%d)",
358473c88f9SBruce Richardson rdev_conf_get.device_state);
359473c88f9SBruce Richardson
360473c88f9SBruce Richardson /* Unloading the firmware once device is stopped */
361473c88f9SBruce Richardson ret = rte_rawdev_firmware_unload(test_dev_id);
362473c88f9SBruce Richardson RTE_TEST_ASSERT_SUCCESS(ret, "Failed to unload firmware (%d)", ret);
363473c88f9SBruce Richardson
364473c88f9SBruce Richardson return TEST_SUCCESS;
365473c88f9SBruce Richardson }
366473c88f9SBruce Richardson
367473c88f9SBruce Richardson static int
test_rawdev_enqdeq(void)368473c88f9SBruce Richardson test_rawdev_enqdeq(void)
369473c88f9SBruce Richardson {
370473c88f9SBruce Richardson int ret;
371473c88f9SBruce Richardson unsigned int count = 1;
372473c88f9SBruce Richardson uint16_t queue_id = 0;
373473c88f9SBruce Richardson struct rte_rawdev_buf buffers[1];
374473c88f9SBruce Richardson struct rte_rawdev_buf *deq_buffers = NULL;
375473c88f9SBruce Richardson
376473c88f9SBruce Richardson buffers[0].buf_addr = malloc(strlen(TEST_DEV_NAME) + 3);
377473c88f9SBruce Richardson if (!buffers[0].buf_addr)
378473c88f9SBruce Richardson goto cleanup;
379473c88f9SBruce Richardson snprintf(buffers[0].buf_addr, strlen(TEST_DEV_NAME) + 2, "%s%d",
380473c88f9SBruce Richardson TEST_DEV_NAME, 0);
381473c88f9SBruce Richardson
382473c88f9SBruce Richardson ret = rte_rawdev_enqueue_buffers(test_dev_id,
383473c88f9SBruce Richardson (struct rte_rawdev_buf **)&buffers,
384473c88f9SBruce Richardson count, &queue_id);
385473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count,
386473c88f9SBruce Richardson "Unable to enqueue buffers");
387473c88f9SBruce Richardson
388473c88f9SBruce Richardson deq_buffers = malloc(sizeof(struct rte_rawdev_buf) * count);
389473c88f9SBruce Richardson if (!deq_buffers)
390473c88f9SBruce Richardson goto cleanup;
391473c88f9SBruce Richardson
392473c88f9SBruce Richardson ret = rte_rawdev_dequeue_buffers(test_dev_id,
393473c88f9SBruce Richardson (struct rte_rawdev_buf **)&deq_buffers,
394473c88f9SBruce Richardson count, &queue_id);
395473c88f9SBruce Richardson RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count,
396473c88f9SBruce Richardson "Unable to dequeue buffers");
397473c88f9SBruce Richardson
398473c88f9SBruce Richardson free(deq_buffers);
399473c88f9SBruce Richardson
400473c88f9SBruce Richardson return TEST_SUCCESS;
401473c88f9SBruce Richardson cleanup:
402473c88f9SBruce Richardson free(buffers[0].buf_addr);
403473c88f9SBruce Richardson
404473c88f9SBruce Richardson return TEST_FAILED;
405473c88f9SBruce Richardson }
406473c88f9SBruce Richardson
skeldev_test_run(int (* setup)(void),void (* teardown)(void),int (* test)(void),const char * name)407473c88f9SBruce Richardson static void skeldev_test_run(int (*setup)(void),
408473c88f9SBruce Richardson void (*teardown)(void),
409473c88f9SBruce Richardson int (*test)(void),
410473c88f9SBruce Richardson const char *name)
411473c88f9SBruce Richardson {
412473c88f9SBruce Richardson int ret = 0;
413473c88f9SBruce Richardson
414473c88f9SBruce Richardson if (setup) {
415473c88f9SBruce Richardson ret = setup();
416473c88f9SBruce Richardson if (ret < 0) {
417473c88f9SBruce Richardson SKELDEV_TEST_INFO("Error setting up test %s", name);
418473c88f9SBruce Richardson unsupported++;
419473c88f9SBruce Richardson }
420473c88f9SBruce Richardson }
421473c88f9SBruce Richardson
422473c88f9SBruce Richardson if (test) {
423473c88f9SBruce Richardson ret = test();
424473c88f9SBruce Richardson if (ret < 0) {
425473c88f9SBruce Richardson failed++;
426473c88f9SBruce Richardson SKELDEV_TEST_INFO("%s Failed", name);
427473c88f9SBruce Richardson } else {
428473c88f9SBruce Richardson passed++;
429473c88f9SBruce Richardson SKELDEV_TEST_DEBUG("%s Passed", name);
430473c88f9SBruce Richardson }
431473c88f9SBruce Richardson }
432473c88f9SBruce Richardson
433473c88f9SBruce Richardson if (teardown)
434473c88f9SBruce Richardson teardown();
435473c88f9SBruce Richardson
436473c88f9SBruce Richardson total++;
437473c88f9SBruce Richardson }
438473c88f9SBruce Richardson
439473c88f9SBruce Richardson int
test_rawdev_skeldev(uint16_t dev_id)440473c88f9SBruce Richardson test_rawdev_skeldev(uint16_t dev_id)
441473c88f9SBruce Richardson {
442473c88f9SBruce Richardson test_dev_id = dev_id;
443473c88f9SBruce Richardson testsuite_setup();
444473c88f9SBruce Richardson
445473c88f9SBruce Richardson SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_count);
446473c88f9SBruce Richardson SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_get_dev_id);
447473c88f9SBruce Richardson SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_socket_id);
448473c88f9SBruce Richardson SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_info_get);
449473c88f9SBruce Richardson SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_configure);
450473c88f9SBruce Richardson SKELDEV_TEST_RUN(test_rawdev_configure, NULL,
451473c88f9SBruce Richardson test_rawdev_queue_default_conf_get);
452473c88f9SBruce Richardson SKELDEV_TEST_RUN(test_rawdev_configure, NULL, test_rawdev_queue_setup);
453473c88f9SBruce Richardson SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_queue_count);
454473c88f9SBruce Richardson SKELDEV_TEST_RUN(test_rawdev_queue_setup, NULL,
455473c88f9SBruce Richardson test_rawdev_queue_release);
456473c88f9SBruce Richardson SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_attr_set_get);
457473c88f9SBruce Richardson SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_start_stop);
458473c88f9SBruce Richardson SKELDEV_TEST_RUN(test_rawdev_queue_setup, NULL, test_rawdev_enqdeq);
459473c88f9SBruce Richardson
460473c88f9SBruce Richardson testsuite_teardown();
461473c88f9SBruce Richardson
462473c88f9SBruce Richardson SKELDEV_TEST_INFO("Total tests : %d", total);
463473c88f9SBruce Richardson SKELDEV_TEST_INFO("Passed : %d", passed);
464473c88f9SBruce Richardson SKELDEV_TEST_INFO("Failed : %d", failed);
465473c88f9SBruce Richardson SKELDEV_TEST_INFO("Not supported : %d", unsupported);
466473c88f9SBruce Richardson
467473c88f9SBruce Richardson if (failed)
468473c88f9SBruce Richardson return -1;
469473c88f9SBruce Richardson
470473c88f9SBruce Richardson return 0;
471473c88f9SBruce Richardson };
472