Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2021 HiSilicon Limited
3 : : */
4 : :
5 : : #include <string.h>
6 : :
7 : : #include <rte_cycles.h>
8 : : #include <rte_malloc.h>
9 : : #include <rte_test.h>
10 : : #include <rte_dmadev.h>
11 : :
12 : : extern int test_dma_api(uint16_t dev_id);
13 : :
14 : : #define DMA_TEST_API_RUN(test) \
15 : : testsuite_run_test(test, #test)
16 : :
17 : : #define TEST_MEMCPY_SIZE 1024
18 : : #define TEST_WAIT_US_VAL 50000
19 : :
20 : : #define TEST_SUCCESS 0
21 : : #define TEST_FAILED -1
22 : :
23 : : static int16_t test_dev_id;
24 : : static int16_t invalid_dev_id;
25 : :
26 : : static char *src;
27 : : static char *dst;
28 : :
29 : : static int total;
30 : : static int passed;
31 : : static int failed;
32 : :
33 : : static int
34 : 0 : testsuite_setup(int16_t dev_id)
35 : : {
36 : 0 : test_dev_id = dev_id;
37 : 0 : invalid_dev_id = -1;
38 : :
39 : 0 : src = rte_malloc("dmadev_test_src", TEST_MEMCPY_SIZE, 0);
40 [ # # ]: 0 : if (src == NULL)
41 : : return -ENOMEM;
42 : 0 : dst = rte_malloc("dmadev_test_dst", TEST_MEMCPY_SIZE, 0);
43 [ # # ]: 0 : if (dst == NULL) {
44 : 0 : rte_free(src);
45 : 0 : src = NULL;
46 : 0 : return -ENOMEM;
47 : : }
48 : :
49 : 0 : total = 0;
50 : 0 : passed = 0;
51 : 0 : failed = 0;
52 : :
53 : : /* Set dmadev log level to critical to suppress unnecessary output
54 : : * during API tests.
55 : : */
56 : 0 : rte_log_set_level_pattern("lib.dmadev", RTE_LOG_CRIT);
57 : :
58 : 0 : return 0;
59 : : }
60 : :
61 : : static void
62 : 0 : testsuite_teardown(void)
63 : : {
64 : 0 : rte_free(src);
65 : 0 : src = NULL;
66 : 0 : rte_free(dst);
67 : 0 : dst = NULL;
68 : : /* Ensure the dmadev is stopped. */
69 : 0 : rte_dma_stop(test_dev_id);
70 : :
71 : 0 : rte_log_set_level_pattern("lib.dmadev", RTE_LOG_INFO);
72 : 0 : }
73 : :
74 : : static void
75 : 0 : testsuite_run_test(int (*test)(void), const char *name)
76 : : {
77 : : int ret = 0;
78 : :
79 [ # # ]: 0 : if (test) {
80 : 0 : ret = test();
81 [ # # ]: 0 : if (ret < 0) {
82 : 0 : failed++;
83 : : printf("%s Failed\n", name);
84 : : } else {
85 : 0 : passed++;
86 : : printf("%s Passed\n", name);
87 : : }
88 : : }
89 : :
90 : 0 : total++;
91 : 0 : }
92 : :
93 : : static int
94 : 0 : test_dma_get_dev_id_by_name(void)
95 : : {
96 : 0 : int ret = rte_dma_get_dev_id_by_name("invalid_dmadev_device");
97 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
98 : : return TEST_SUCCESS;
99 : : }
100 : :
101 : : static int
102 : 0 : test_dma_is_valid_dev(void)
103 : : {
104 : : int ret;
105 : 0 : ret = rte_dma_is_valid(invalid_dev_id);
106 [ # # ]: 0 : RTE_TEST_ASSERT(ret == false, "Expected false for invalid dev id");
107 : 0 : ret = rte_dma_is_valid(test_dev_id);
108 [ # # ]: 0 : RTE_TEST_ASSERT(ret == true, "Expected true for valid dev id");
109 : : return TEST_SUCCESS;
110 : : }
111 : :
112 : : static int
113 : 0 : test_dma_count(void)
114 : : {
115 : 0 : uint16_t count = rte_dma_count_avail();
116 [ # # ]: 0 : RTE_TEST_ASSERT(count > 0, "Invalid dmadev count %u", count);
117 : : return TEST_SUCCESS;
118 : : }
119 : :
120 : : static int
121 : 0 : test_dma_info_get(void)
122 : : {
123 : 0 : struct rte_dma_info info = { 0 };
124 : : int ret;
125 : :
126 : 0 : ret = rte_dma_info_get(invalid_dev_id, &info);
127 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
128 : 0 : ret = rte_dma_info_get(test_dev_id, NULL);
129 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
130 : 0 : ret = rte_dma_info_get(test_dev_id, &info);
131 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain device info");
132 : :
133 : : return TEST_SUCCESS;
134 : : }
135 : :
136 : : static int
137 : 0 : test_dma_configure(void)
138 : : {
139 : 0 : struct rte_dma_conf conf = { 0 };
140 : 0 : struct rte_dma_info info = { 0 };
141 : : int ret;
142 : :
143 : : /* Check for invalid parameters */
144 : 0 : ret = rte_dma_configure(invalid_dev_id, &conf);
145 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
146 : 0 : ret = rte_dma_configure(test_dev_id, NULL);
147 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
148 : :
149 : : /* Check for nb_vchans == 0 */
150 : : memset(&conf, 0, sizeof(conf));
151 : 0 : ret = rte_dma_configure(test_dev_id, &conf);
152 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
153 : :
154 : : /* Check for conf.nb_vchans > info.max_vchans */
155 : 0 : ret = rte_dma_info_get(test_dev_id, &info);
156 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain device info");
157 : : memset(&conf, 0, sizeof(conf));
158 : 0 : conf.nb_vchans = info.max_vchans + 1;
159 : 0 : ret = rte_dma_configure(test_dev_id, &conf);
160 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
161 : :
162 : : /* Check enable silent mode */
163 : : memset(&conf, 0, sizeof(conf));
164 : 0 : conf.nb_vchans = info.max_vchans;
165 : 0 : conf.enable_silent = true;
166 : 0 : ret = rte_dma_configure(test_dev_id, &conf);
167 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
168 : :
169 : : /* Configure success */
170 : : memset(&conf, 0, sizeof(conf));
171 : 0 : conf.nb_vchans = info.max_vchans;
172 : 0 : ret = rte_dma_configure(test_dev_id, &conf);
173 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to configure dmadev, %d", ret);
174 : :
175 : : /* Check configure success */
176 : 0 : ret = rte_dma_info_get(test_dev_id, &info);
177 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain device info");
178 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(conf.nb_vchans, info.nb_vchans,
179 : : "Configure nb_vchans not match");
180 : :
181 : : return TEST_SUCCESS;
182 : : }
183 : :
184 : : static int
185 : 0 : check_direction(void)
186 : : {
187 : : struct rte_dma_vchan_conf vchan_conf;
188 : : int ret;
189 : :
190 : : /* Check for direction */
191 : : memset(&vchan_conf, 0, sizeof(vchan_conf));
192 : 0 : vchan_conf.direction = RTE_DMA_DIR_DEV_TO_DEV + 1;
193 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
194 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
195 : 0 : vchan_conf.direction = RTE_DMA_DIR_MEM_TO_MEM - 1;
196 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
197 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
198 : :
199 : : /* Check for direction and dev_capa combination */
200 : : memset(&vchan_conf, 0, sizeof(vchan_conf));
201 : 0 : vchan_conf.direction = RTE_DMA_DIR_MEM_TO_DEV;
202 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
203 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
204 : 0 : vchan_conf.direction = RTE_DMA_DIR_DEV_TO_MEM;
205 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
206 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
207 : 0 : vchan_conf.direction = RTE_DMA_DIR_DEV_TO_DEV;
208 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
209 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
210 : :
211 : : return 0;
212 : : }
213 : :
214 : : static int
215 : 0 : check_port_type(struct rte_dma_info *dev_info)
216 : : {
217 : : struct rte_dma_vchan_conf vchan_conf;
218 : : int ret;
219 : :
220 : : /* Check src port type validation */
221 : : memset(&vchan_conf, 0, sizeof(vchan_conf));
222 : : vchan_conf.direction = RTE_DMA_DIR_MEM_TO_MEM;
223 : 0 : vchan_conf.nb_desc = dev_info->min_desc;
224 : 0 : vchan_conf.src_port.port_type = RTE_DMA_PORT_PCIE;
225 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
226 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
227 : :
228 : : /* Check dst port type validation */
229 : : memset(&vchan_conf, 0, sizeof(vchan_conf));
230 : : vchan_conf.direction = RTE_DMA_DIR_MEM_TO_MEM;
231 : 0 : vchan_conf.nb_desc = dev_info->min_desc;
232 : 0 : vchan_conf.dst_port.port_type = RTE_DMA_PORT_PCIE;
233 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
234 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
235 : :
236 : : return 0;
237 : : }
238 : :
239 : : static int
240 : 0 : test_dma_vchan_setup(void)
241 : : {
242 : 0 : struct rte_dma_vchan_conf vchan_conf = { 0 };
243 : 0 : struct rte_dma_conf dev_conf = { 0 };
244 : 0 : struct rte_dma_info dev_info = { 0 };
245 : : int ret;
246 : :
247 : : /* Check for invalid parameters */
248 : 0 : ret = rte_dma_vchan_setup(invalid_dev_id, 0, &vchan_conf);
249 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
250 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, NULL);
251 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
252 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
253 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
254 : :
255 : : /* Make sure configure success */
256 : 0 : ret = rte_dma_info_get(test_dev_id, &dev_info);
257 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain device info");
258 : 0 : dev_conf.nb_vchans = dev_info.max_vchans;
259 : 0 : ret = rte_dma_configure(test_dev_id, &dev_conf);
260 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to configure dmadev, %d", ret);
261 : :
262 : : /* Check for invalid vchan */
263 : 0 : ret = rte_dma_vchan_setup(test_dev_id, dev_conf.nb_vchans, &vchan_conf);
264 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
265 : :
266 : : /* Check for direction */
267 : 0 : ret = check_direction();
268 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to check direction");
269 : :
270 : : /* Check for nb_desc validation */
271 : : memset(&vchan_conf, 0, sizeof(vchan_conf));
272 : : vchan_conf.direction = RTE_DMA_DIR_MEM_TO_MEM;
273 : 0 : vchan_conf.nb_desc = dev_info.min_desc - 1;
274 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
275 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
276 : 0 : vchan_conf.nb_desc = dev_info.max_desc + 1;
277 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
278 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
279 : :
280 : : /* Check port type */
281 : 0 : ret = check_port_type(&dev_info);
282 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to check port type");
283 : :
284 : : /* Check vchan setup success */
285 : : memset(&vchan_conf, 0, sizeof(vchan_conf));
286 : : vchan_conf.direction = RTE_DMA_DIR_MEM_TO_MEM;
287 : 0 : vchan_conf.nb_desc = dev_info.min_desc;
288 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
289 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup vchan, %d", ret);
290 : :
291 : : return TEST_SUCCESS;
292 : : }
293 : :
294 : : static int
295 : 0 : setup_one_vchan(void)
296 : : {
297 : 0 : struct rte_dma_vchan_conf vchan_conf = { 0 };
298 : 0 : struct rte_dma_info dev_info = { 0 };
299 : 0 : struct rte_dma_conf dev_conf = { 0 };
300 : : int ret;
301 : :
302 : 0 : ret = rte_dma_info_get(test_dev_id, &dev_info);
303 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain device info, %d", ret);
304 : 0 : dev_conf.nb_vchans = dev_info.max_vchans;
305 : 0 : ret = rte_dma_configure(test_dev_id, &dev_conf);
306 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to configure, %d", ret);
307 : 0 : vchan_conf.direction = RTE_DMA_DIR_MEM_TO_MEM;
308 : 0 : vchan_conf.nb_desc = dev_info.min_desc;
309 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
310 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup vchan, %d", ret);
311 : :
312 : : return TEST_SUCCESS;
313 : : }
314 : :
315 : : static int
316 : 0 : test_dma_start_stop(void)
317 : : {
318 : 0 : struct rte_dma_vchan_conf vchan_conf = { 0 };
319 : 0 : struct rte_dma_conf dev_conf = { 0 };
320 : : int ret;
321 : :
322 : : /* Check for invalid parameters */
323 : 0 : ret = rte_dma_start(invalid_dev_id);
324 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
325 : 0 : ret = rte_dma_stop(invalid_dev_id);
326 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
327 : :
328 : : /* Setup one vchan for later test */
329 : 0 : ret = setup_one_vchan();
330 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup one vchan, %d", ret);
331 : :
332 : 0 : ret = rte_dma_start(test_dev_id);
333 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to start, %d", ret);
334 : :
335 : : /* Check reconfigure and vchan setup when device started */
336 : 0 : ret = rte_dma_configure(test_dev_id, &dev_conf);
337 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EBUSY, "Failed to configure, %d", ret);
338 : 0 : ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf);
339 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EBUSY, "Failed to setup vchan, %d", ret);
340 : :
341 : 0 : ret = rte_dma_stop(test_dev_id);
342 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to stop, %d", ret);
343 : :
344 : : return TEST_SUCCESS;
345 : : }
346 : :
347 : : static int
348 : 0 : test_dma_stats(void)
349 : : {
350 : 0 : struct rte_dma_info dev_info = { 0 };
351 : 0 : struct rte_dma_stats stats = { 0 };
352 : : int ret;
353 : :
354 : : /* Check for invalid parameters */
355 : 0 : ret = rte_dma_stats_get(invalid_dev_id, 0, &stats);
356 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
357 : 0 : ret = rte_dma_stats_get(invalid_dev_id, 0, NULL);
358 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
359 : 0 : ret = rte_dma_stats_reset(invalid_dev_id, 0);
360 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
361 : :
362 : : /* Setup one vchan for later test */
363 : 0 : ret = setup_one_vchan();
364 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup one vchan, %d", ret);
365 : :
366 : : /* Check for invalid vchan */
367 : 0 : ret = rte_dma_info_get(test_dev_id, &dev_info);
368 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain device info, %d", ret);
369 : 0 : ret = rte_dma_stats_get(test_dev_id, dev_info.max_vchans, &stats);
370 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
371 : 0 : ret = rte_dma_stats_reset(test_dev_id, dev_info.max_vchans);
372 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
373 : :
374 : : /* Check for valid vchan */
375 : 0 : ret = rte_dma_stats_get(test_dev_id, 0, &stats);
376 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get stats, %d", ret);
377 : 0 : ret = rte_dma_stats_get(test_dev_id, RTE_DMA_ALL_VCHAN, &stats);
378 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get all stats, %d", ret);
379 : 0 : ret = rte_dma_stats_reset(test_dev_id, 0);
380 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to reset stats, %d", ret);
381 : 0 : ret = rte_dma_stats_reset(test_dev_id, RTE_DMA_ALL_VCHAN);
382 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to reset all stats, %d", ret);
383 : :
384 : : return TEST_SUCCESS;
385 : : }
386 : :
387 : : static int
388 : 0 : test_dma_dump(void)
389 : : {
390 : : int ret;
391 : :
392 : : /* Check for invalid parameters */
393 : 0 : ret = rte_dma_dump(invalid_dev_id, stderr);
394 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Excepted -EINVAL, %d", ret);
395 : 0 : ret = rte_dma_dump(test_dev_id, NULL);
396 [ # # ]: 0 : RTE_TEST_ASSERT(ret == -EINVAL, "Excepted -EINVAL, %d", ret);
397 : :
398 : : return TEST_SUCCESS;
399 : : }
400 : :
401 : : static void
402 : 0 : setup_memory(void)
403 : : {
404 : : int i;
405 : :
406 [ # # ]: 0 : for (i = 0; i < TEST_MEMCPY_SIZE; i++)
407 : 0 : src[i] = (char)i;
408 : 0 : memset(dst, 0, TEST_MEMCPY_SIZE);
409 : 0 : }
410 : :
411 : : static int
412 : 0 : verify_memory(void)
413 : : {
414 : : int i;
415 : :
416 [ # # ]: 0 : for (i = 0; i < TEST_MEMCPY_SIZE; i++) {
417 [ # # ]: 0 : if (src[i] == dst[i])
418 : : continue;
419 : 0 : RTE_TEST_ASSERT_EQUAL(src[i], dst[i],
420 : : "Failed to copy memory, %d %d", src[i], dst[i]);
421 : : }
422 : :
423 : : return 0;
424 : : }
425 : :
426 : : static int
427 : 0 : test_dma_completed(void)
428 : : {
429 : 0 : uint16_t last_idx = 1;
430 : 0 : bool has_error = true;
431 : : uint16_t cpl_ret;
432 : : int ret;
433 : :
434 : : /* Setup one vchan for later test */
435 : 0 : ret = setup_one_vchan();
436 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup one vchan, %d", ret);
437 : :
438 : 0 : ret = rte_dma_start(test_dev_id);
439 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to start, %d", ret);
440 : :
441 : 0 : setup_memory();
442 : :
443 : : /* Check enqueue without submit */
444 : 0 : ret = rte_dma_copy(test_dev_id, 0, (rte_iova_t)src, (rte_iova_t)dst,
445 : : TEST_MEMCPY_SIZE, 0);
446 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(ret, 0, "Failed to enqueue copy, %d", ret);
447 : 0 : rte_delay_us_sleep(TEST_WAIT_US_VAL);
448 : 0 : cpl_ret = rte_dma_completed(test_dev_id, 0, 1, &last_idx, &has_error);
449 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(cpl_ret, 0, "Failed to get completed");
450 : :
451 : : /* Check add submit */
452 : 0 : ret = rte_dma_submit(test_dev_id, 0);
453 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to submit, %d", ret);
454 : 0 : rte_delay_us_sleep(TEST_WAIT_US_VAL);
455 : 0 : cpl_ret = rte_dma_completed(test_dev_id, 0, 1, &last_idx, &has_error);
456 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(cpl_ret, 1, "Failed to get completed");
457 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(last_idx, 0, "Last idx should be zero, %u",
458 : : last_idx);
459 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(has_error, false, "Should have no error");
460 : 0 : ret = verify_memory();
461 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to verify memory");
462 : :
463 : 0 : setup_memory();
464 : :
465 : : /* Check for enqueue with submit */
466 : 0 : ret = rte_dma_copy(test_dev_id, 0, (rte_iova_t)src, (rte_iova_t)dst,
467 : : TEST_MEMCPY_SIZE, RTE_DMA_OP_FLAG_SUBMIT);
468 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(ret, 1, "Failed to enqueue copy, %d", ret);
469 : 0 : rte_delay_us_sleep(TEST_WAIT_US_VAL);
470 : 0 : cpl_ret = rte_dma_completed(test_dev_id, 0, 1, &last_idx, &has_error);
471 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(cpl_ret, 1, "Failed to get completed");
472 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(last_idx, 1, "Last idx should be 1, %u",
473 : : last_idx);
474 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(has_error, false, "Should have no error");
475 : 0 : ret = verify_memory();
476 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to verify memory");
477 : :
478 : : /* Stop dmadev to make sure dmadev to a known state */
479 : 0 : ret = rte_dma_stop(test_dev_id);
480 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to stop, %d", ret);
481 : :
482 : : return TEST_SUCCESS;
483 : : }
484 : :
485 : : static int
486 : 0 : test_dma_completed_status(void)
487 : : {
488 : 0 : enum rte_dma_status_code status[1] = { 1 };
489 : 0 : uint16_t last_idx = 1;
490 : : uint16_t cpl_ret, i;
491 : : int ret;
492 : :
493 : : /* Setup one vchan for later test */
494 : 0 : ret = setup_one_vchan();
495 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup one vchan, %d", ret);
496 : :
497 : 0 : ret = rte_dma_start(test_dev_id);
498 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to start, %d", ret);
499 : :
500 : : /* Check for enqueue with submit */
501 : 0 : ret = rte_dma_copy(test_dev_id, 0, (rte_iova_t)src, (rte_iova_t)dst,
502 : : TEST_MEMCPY_SIZE, RTE_DMA_OP_FLAG_SUBMIT);
503 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(ret, 0, "Failed to enqueue copy, %d", ret);
504 : 0 : rte_delay_us_sleep(TEST_WAIT_US_VAL);
505 : 0 : cpl_ret = rte_dma_completed_status(test_dev_id, 0, 1, &last_idx,
506 : : status);
507 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(cpl_ret, 1, "Failed to completed status");
508 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(last_idx, 0, "Last idx should be zero, %u",
509 : : last_idx);
510 [ # # ]: 0 : for (i = 0; i < RTE_DIM(status); i++)
511 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(status[i], 0,
512 : : "Failed to completed status, %d", status[i]);
513 : :
514 : : /* Check do completed status again */
515 : 0 : cpl_ret = rte_dma_completed_status(test_dev_id, 0, 1, &last_idx,
516 : : status);
517 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(cpl_ret, 0, "Failed to completed status");
518 : :
519 : : /* Check for enqueue with submit again */
520 : 0 : ret = rte_dma_copy(test_dev_id, 0, (rte_iova_t)src, (rte_iova_t)dst,
521 : : TEST_MEMCPY_SIZE, RTE_DMA_OP_FLAG_SUBMIT);
522 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(ret, 1, "Failed to enqueue copy, %d", ret);
523 : 0 : rte_delay_us_sleep(TEST_WAIT_US_VAL);
524 : 0 : cpl_ret = rte_dma_completed_status(test_dev_id, 0, 1, &last_idx,
525 : : status);
526 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(cpl_ret, 1, "Failed to completed status");
527 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(last_idx, 1, "Last idx should be 1, %u",
528 : : last_idx);
529 [ # # ]: 0 : for (i = 0; i < RTE_DIM(status); i++)
530 [ # # ]: 0 : RTE_TEST_ASSERT_EQUAL(status[i], 0,
531 : : "Failed to completed status, %d", status[i]);
532 : :
533 : : /* Stop dmadev to make sure dmadev to a known state */
534 : 0 : ret = rte_dma_stop(test_dev_id);
535 [ # # ]: 0 : RTE_TEST_ASSERT_SUCCESS(ret, "Failed to stop, %d", ret);
536 : :
537 : : return TEST_SUCCESS;
538 : : }
539 : :
540 : : int
541 : 0 : test_dma_api(uint16_t dev_id)
542 : : {
543 : 0 : int ret = testsuite_setup(dev_id);
544 [ # # ]: 0 : if (ret) {
545 : : printf("testsuite setup fail!\n");
546 : 0 : return -1;
547 : : }
548 : :
549 : : /* If the testcase exit successfully, ensure that the test dmadev exist
550 : : * and the dmadev is in the stopped state.
551 : : */
552 : 0 : DMA_TEST_API_RUN(test_dma_get_dev_id_by_name);
553 : 0 : DMA_TEST_API_RUN(test_dma_is_valid_dev);
554 : 0 : DMA_TEST_API_RUN(test_dma_count);
555 : 0 : DMA_TEST_API_RUN(test_dma_info_get);
556 : 0 : DMA_TEST_API_RUN(test_dma_configure);
557 : 0 : DMA_TEST_API_RUN(test_dma_vchan_setup);
558 : 0 : DMA_TEST_API_RUN(test_dma_start_stop);
559 : 0 : DMA_TEST_API_RUN(test_dma_stats);
560 : 0 : DMA_TEST_API_RUN(test_dma_dump);
561 : 0 : DMA_TEST_API_RUN(test_dma_completed);
562 : 0 : DMA_TEST_API_RUN(test_dma_completed_status);
563 : :
564 : 0 : testsuite_teardown();
565 : :
566 : 0 : printf("Total tests : %d\n", total);
567 : 0 : printf("Passed : %d\n", passed);
568 : 0 : printf("Failed : %d\n", failed);
569 : :
570 [ # # ]: 0 : if (failed)
571 : 0 : return -1;
572 : :
573 : : return 0;
574 : : };
|