Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018 - 2019 Intel Corporation
3 : : */
4 : : #include <string.h>
5 : : #include <zlib.h>
6 : : #include <math.h>
7 : : #include <stdlib.h>
8 : : #include <unistd.h>
9 : : #include <stdio.h>
10 : :
11 : : #include <rte_cycles.h>
12 : : #include <rte_malloc.h>
13 : : #include <rte_mempool.h>
14 : : #include <rte_mbuf.h>
15 : : #include <rte_compressdev.h>
16 : : #include <rte_string_fns.h>
17 : :
18 : : #include "test_compressdev_test_buffer.h"
19 : : #include "test.h"
20 : :
21 : : #define DIV_CEIL(a, b) ((a) / (b) + ((a) % (b) != 0))
22 : :
23 : : #define DEFAULT_WINDOW_SIZE 15
24 : : #define DEFAULT_MEM_LEVEL 8
25 : : #define MAX_DEQD_RETRIES 10
26 : : #define DEQUEUE_WAIT_TIME 10000
27 : :
28 : : /*
29 : : * 30% extra size for compressed data compared to original data,
30 : : * in case data size cannot be reduced and it is actually bigger
31 : : * due to the compress block headers
32 : : */
33 : : #define COMPRESS_BUF_SIZE_RATIO 1.3
34 : : #define COMPRESS_BUF_SIZE_RATIO_DISABLED 1.0
35 : : #define COMPRESS_BUF_SIZE_RATIO_OVERFLOW 0.2
36 : : #define NUM_LARGE_MBUFS 16
37 : : #define SMALL_SEG_SIZE 256
38 : : #define MAX_SEGS 16
39 : : #define NUM_OPS 16
40 : : #define NUM_MAX_XFORMS 16
41 : : #define NUM_MAX_INFLIGHT_OPS 128
42 : : #define CACHE_SIZE 0
43 : :
44 : : #define ZLIB_CRC_CHECKSUM_WINDOW_BITS 31
45 : : #define ZLIB_HEADER_SIZE 2
46 : : #define ZLIB_TRAILER_SIZE 4
47 : : #define GZIP_HEADER_SIZE 10
48 : : #define GZIP_TRAILER_SIZE 8
49 : :
50 : : #define OUT_OF_SPACE_BUF 1
51 : :
52 : : #define MAX_MBUF_SEGMENT_SIZE 65535
53 : : #define MAX_DATA_MBUF_SIZE (MAX_MBUF_SEGMENT_SIZE - RTE_PKTMBUF_HEADROOM)
54 : : #define NUM_BIG_MBUFS (512 + 1)
55 : : #define BIG_DATA_TEST_SIZE (MAX_DATA_MBUF_SIZE * 2)
56 : :
57 : : /* constants for "im buffer" tests start here */
58 : :
59 : : /* number of mbufs lower than number of inflight ops */
60 : : #define IM_BUF_NUM_MBUFS 3
61 : : /* above threshold (QAT_FALLBACK_THLD) and below max mbuf size */
62 : : #define IM_BUF_DATA_TEST_SIZE_LB 59600
63 : : /* data size smaller than the queue capacity */
64 : : #define IM_BUF_DATA_TEST_SIZE_SGL (MAX_DATA_MBUF_SIZE * IM_BUF_NUM_MBUFS)
65 : : /* number of mbufs bigger than number of inflight ops */
66 : : #define IM_BUF_NUM_MBUFS_OVER (NUM_MAX_INFLIGHT_OPS + 1)
67 : : /* data size bigger than the queue capacity */
68 : : #define IM_BUF_DATA_TEST_SIZE_OVER (MAX_DATA_MBUF_SIZE * IM_BUF_NUM_MBUFS_OVER)
69 : : /* number of mid-size mbufs */
70 : : #define IM_BUF_NUM_MBUFS_MID ((NUM_MAX_INFLIGHT_OPS / 3) + 1)
71 : : /* capacity of mid-size mbufs */
72 : : #define IM_BUF_DATA_TEST_SIZE_MID (MAX_DATA_MBUF_SIZE * IM_BUF_NUM_MBUFS_MID)
73 : :
74 : :
75 : : const char *
76 : : huffman_type_strings[] = {
77 : : [RTE_COMP_HUFFMAN_DEFAULT] = "PMD default",
78 : : [RTE_COMP_HUFFMAN_FIXED] = "Fixed",
79 : : [RTE_COMP_HUFFMAN_DYNAMIC] = "Dynamic"
80 : : };
81 : :
82 : : enum zlib_direction {
83 : : ZLIB_NONE,
84 : : ZLIB_COMPRESS,
85 : : ZLIB_DECOMPRESS,
86 : : ZLIB_ALL
87 : : };
88 : :
89 : : enum varied_buff {
90 : : LB_BOTH = 0, /* both input and output are linear*/
91 : : SGL_BOTH, /* both input and output are chained */
92 : : SGL_TO_LB, /* input buffer is chained */
93 : : LB_TO_SGL /* output buffer is chained */
94 : : };
95 : :
96 : : enum overflow_test {
97 : : OVERFLOW_DISABLED,
98 : : OVERFLOW_ENABLED
99 : : };
100 : :
101 : : enum ratio_switch {
102 : : RATIO_DISABLED,
103 : : RATIO_ENABLED
104 : : };
105 : :
106 : : enum operation_type {
107 : : OPERATION_COMPRESSION,
108 : : OPERATION_DECOMPRESSION
109 : : };
110 : :
111 : : struct priv_op_data {
112 : : uint16_t orig_idx;
113 : : };
114 : :
115 : : struct comp_testsuite_params {
116 : : struct rte_mempool *large_mbuf_pool;
117 : : struct rte_mempool *small_mbuf_pool;
118 : : struct rte_mempool *big_mbuf_pool;
119 : : struct rte_mempool *op_pool;
120 : : struct rte_comp_xform *def_comp_xform;
121 : : struct rte_comp_xform *def_decomp_xform;
122 : : };
123 : :
124 : : struct interim_data_params {
125 : : const char * const *test_bufs;
126 : : unsigned int num_bufs;
127 : : uint16_t *buf_idx;
128 : : struct rte_comp_xform **compress_xforms;
129 : : struct rte_comp_xform **decompress_xforms;
130 : : unsigned int num_xforms;
131 : : };
132 : :
133 : : struct test_data_params {
134 : : enum rte_comp_op_type compress_state;
135 : : enum rte_comp_op_type decompress_state;
136 : : enum varied_buff buff_type;
137 : : enum zlib_direction zlib_dir;
138 : : unsigned int out_of_space;
139 : : unsigned int big_data;
140 : : /* stateful decompression specific parameters */
141 : : unsigned int decompress_output_block_size;
142 : : unsigned int decompress_steps_max;
143 : : /* external mbufs specific parameters */
144 : : unsigned int use_external_mbufs;
145 : : unsigned int inbuf_data_size;
146 : : const struct rte_memzone *inbuf_memzone;
147 : : const struct rte_memzone *compbuf_memzone;
148 : : const struct rte_memzone *uncompbuf_memzone;
149 : : /* overflow test activation */
150 : : enum overflow_test overflow;
151 : : enum ratio_switch ratio;
152 : : };
153 : :
154 : : struct test_private_arrays {
155 : : struct rte_mbuf **uncomp_bufs;
156 : : struct rte_mbuf **comp_bufs;
157 : : struct rte_comp_op **ops;
158 : : struct rte_comp_op **ops_processed;
159 : : void **priv_xforms;
160 : : uint64_t *compress_checksum;
161 : : uint32_t *compressed_data_size;
162 : : void **stream;
163 : : char **all_decomp_data;
164 : : unsigned int *decomp_produced_data_size;
165 : : uint16_t num_priv_xforms;
166 : : };
167 : :
168 : : static struct comp_testsuite_params testsuite_params = { 0 };
169 : :
170 : :
171 : : static void
172 : 0 : testsuite_teardown(void)
173 : : {
174 : : struct comp_testsuite_params *ts_params = &testsuite_params;
175 : :
176 [ # # ]: 0 : if (rte_mempool_in_use_count(ts_params->large_mbuf_pool))
177 : 0 : RTE_LOG(ERR, USER1, "Large mbuf pool still has unfreed bufs\n");
178 [ # # ]: 0 : if (rte_mempool_in_use_count(ts_params->small_mbuf_pool))
179 : 0 : RTE_LOG(ERR, USER1, "Small mbuf pool still has unfreed bufs\n");
180 [ # # ]: 0 : if (rte_mempool_in_use_count(ts_params->big_mbuf_pool))
181 : 0 : RTE_LOG(ERR, USER1, "Big mbuf pool still has unfreed bufs\n");
182 [ # # ]: 0 : if (rte_mempool_in_use_count(ts_params->op_pool))
183 : 0 : RTE_LOG(ERR, USER1, "op pool still has unfreed ops\n");
184 : :
185 : 0 : rte_mempool_free(ts_params->large_mbuf_pool);
186 : 0 : rte_mempool_free(ts_params->small_mbuf_pool);
187 : 0 : rte_mempool_free(ts_params->big_mbuf_pool);
188 : 0 : rte_mempool_free(ts_params->op_pool);
189 : 0 : rte_free(ts_params->def_comp_xform);
190 : 0 : rte_free(ts_params->def_decomp_xform);
191 : 0 : }
192 : :
193 : : static int
194 : 1 : testsuite_setup(void)
195 : : {
196 : : struct comp_testsuite_params *ts_params = &testsuite_params;
197 : : uint32_t max_buf_size = 0;
198 : : unsigned int i;
199 : :
200 [ + - ]: 1 : if (rte_compressdev_count() == 0) {
201 : 1 : RTE_LOG(WARNING, USER1, "Need at least one compress device\n");
202 : 1 : return TEST_SKIPPED;
203 : : }
204 : :
205 : 0 : RTE_LOG(NOTICE, USER1, "Running tests on device %s\n",
206 : : rte_compressdev_name_get(0));
207 : :
208 [ # # ]: 0 : for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
209 : 0 : max_buf_size = RTE_MAX(max_buf_size,
210 : : strlen(compress_test_bufs[i]) + 1);
211 : :
212 : : /*
213 : : * Buffers to be used in compression and decompression.
214 : : * Since decompressed data might be larger than
215 : : * compressed data (due to block header),
216 : : * buffers should be big enough for both cases.
217 : : */
218 : 0 : max_buf_size *= COMPRESS_BUF_SIZE_RATIO;
219 : 0 : ts_params->large_mbuf_pool = rte_pktmbuf_pool_create("large_mbuf_pool",
220 : : NUM_LARGE_MBUFS,
221 : : CACHE_SIZE, 0,
222 : 0 : max_buf_size + RTE_PKTMBUF_HEADROOM,
223 : 0 : rte_socket_id());
224 [ # # ]: 0 : if (ts_params->large_mbuf_pool == NULL) {
225 : 0 : RTE_LOG(ERR, USER1, "Large mbuf pool could not be created\n");
226 : 0 : return TEST_FAILED;
227 : : }
228 : :
229 : : /* Create mempool with smaller buffers for SGL testing */
230 : 0 : ts_params->small_mbuf_pool = rte_pktmbuf_pool_create("small_mbuf_pool",
231 : : NUM_LARGE_MBUFS * MAX_SEGS,
232 : : CACHE_SIZE, 0,
233 : : SMALL_SEG_SIZE + RTE_PKTMBUF_HEADROOM,
234 : 0 : rte_socket_id());
235 [ # # ]: 0 : if (ts_params->small_mbuf_pool == NULL) {
236 : 0 : RTE_LOG(ERR, USER1, "Small mbuf pool could not be created\n");
237 : 0 : goto exit;
238 : : }
239 : :
240 : : /* Create mempool with big buffers for SGL testing */
241 : 0 : ts_params->big_mbuf_pool = rte_pktmbuf_pool_create("big_mbuf_pool",
242 : : NUM_BIG_MBUFS + 1,
243 : : CACHE_SIZE, 0,
244 : : MAX_MBUF_SEGMENT_SIZE,
245 : 0 : rte_socket_id());
246 [ # # ]: 0 : if (ts_params->big_mbuf_pool == NULL) {
247 : 0 : RTE_LOG(ERR, USER1, "Big mbuf pool could not be created\n");
248 : 0 : goto exit;
249 : : }
250 : :
251 : 0 : ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
252 : : 0, sizeof(struct priv_op_data),
253 : 0 : rte_socket_id());
254 [ # # ]: 0 : if (ts_params->op_pool == NULL) {
255 : 0 : RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
256 : 0 : goto exit;
257 : : }
258 : :
259 : 0 : ts_params->def_comp_xform =
260 : 0 : rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
261 [ # # ]: 0 : if (ts_params->def_comp_xform == NULL) {
262 : 0 : RTE_LOG(ERR, USER1,
263 : : "Default compress xform could not be created\n");
264 : 0 : goto exit;
265 : : }
266 : 0 : ts_params->def_decomp_xform =
267 : 0 : rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
268 [ # # ]: 0 : if (ts_params->def_decomp_xform == NULL) {
269 : 0 : RTE_LOG(ERR, USER1,
270 : : "Default decompress xform could not be created\n");
271 : 0 : goto exit;
272 : : }
273 : :
274 : : /* Initializes default values for compress/decompress xforms */
275 : 0 : ts_params->def_comp_xform->type = RTE_COMP_COMPRESS;
276 : 0 : ts_params->def_comp_xform->compress.algo = RTE_COMP_ALGO_DEFLATE,
277 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
278 : : RTE_COMP_HUFFMAN_DEFAULT;
279 : 0 : ts_params->def_comp_xform->compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
280 : 0 : ts_params->def_comp_xform->compress.chksum = RTE_COMP_CHECKSUM_NONE;
281 : 0 : ts_params->def_comp_xform->compress.window_size = DEFAULT_WINDOW_SIZE;
282 : :
283 : 0 : ts_params->def_decomp_xform->type = RTE_COMP_DECOMPRESS;
284 : 0 : ts_params->def_decomp_xform->decompress.algo = RTE_COMP_ALGO_DEFLATE,
285 : 0 : ts_params->def_decomp_xform->decompress.chksum = RTE_COMP_CHECKSUM_NONE;
286 : 0 : ts_params->def_decomp_xform->decompress.window_size = DEFAULT_WINDOW_SIZE;
287 : :
288 : 0 : return TEST_SUCCESS;
289 : :
290 : 0 : exit:
291 : 0 : testsuite_teardown();
292 : :
293 : 0 : return TEST_FAILED;
294 : : }
295 : :
296 : : static int
297 : 0 : generic_ut_setup(void)
298 : : {
299 : : /* Configure compressdev (one device, one queue pair) */
300 : 0 : struct rte_compressdev_config config = {
301 : 0 : .socket_id = rte_socket_id(),
302 : : .nb_queue_pairs = 1,
303 : : .max_nb_priv_xforms = NUM_MAX_XFORMS,
304 : : .max_nb_streams = 1
305 : : };
306 : :
307 [ # # ]: 0 : if (rte_compressdev_configure(0, &config) < 0) {
308 : 0 : RTE_LOG(ERR, USER1, "Device configuration failed\n");
309 : 0 : return -1;
310 : : }
311 : :
312 [ # # ]: 0 : if (rte_compressdev_queue_pair_setup(0, 0, NUM_MAX_INFLIGHT_OPS,
313 : 0 : rte_socket_id()) < 0) {
314 : 0 : RTE_LOG(ERR, USER1, "Queue pair setup failed\n");
315 : 0 : return -1;
316 : : }
317 : :
318 [ # # ]: 0 : if (rte_compressdev_start(0) < 0) {
319 : 0 : RTE_LOG(ERR, USER1, "Device could not be started\n");
320 : 0 : return -1;
321 : : }
322 : :
323 : : return 0;
324 : : }
325 : :
326 : : static void
327 : 0 : generic_ut_teardown(void)
328 : : {
329 : 0 : rte_compressdev_stop(0);
330 [ # # ]: 0 : if (rte_compressdev_close(0) < 0)
331 : 0 : RTE_LOG(ERR, USER1, "Device could not be closed\n");
332 : 0 : }
333 : :
334 : : static int
335 : 0 : test_compressdev_invalid_configuration(void)
336 : : {
337 : : struct rte_compressdev_config invalid_config;
338 : : struct rte_compressdev_config valid_config = {
339 : 0 : .socket_id = rte_socket_id(),
340 : : .nb_queue_pairs = 1,
341 : : .max_nb_priv_xforms = NUM_MAX_XFORMS,
342 : : .max_nb_streams = 1
343 : : };
344 : : struct rte_compressdev_info dev_info;
345 : :
346 : 0 : RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
347 : :
348 : : /* Invalid configuration with 0 queue pairs */
349 : 0 : invalid_config = valid_config;
350 : 0 : invalid_config.nb_queue_pairs = 0;
351 : :
352 [ # # ]: 0 : TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
353 : : "Device configuration was successful "
354 : : "with no queue pairs (invalid)\n");
355 : :
356 : : /*
357 : : * Invalid configuration with too many queue pairs
358 : : * (if there is an actual maximum number of queue pairs)
359 : : */
360 : 0 : rte_compressdev_info_get(0, &dev_info);
361 [ # # ]: 0 : if (dev_info.max_nb_queue_pairs != 0) {
362 : 0 : invalid_config = valid_config;
363 : 0 : invalid_config.nb_queue_pairs = dev_info.max_nb_queue_pairs + 1;
364 : :
365 [ # # ]: 0 : TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
366 : : "Device configuration was successful "
367 : : "with too many queue pairs (invalid)\n");
368 : : }
369 : :
370 : : /* Invalid queue pair setup, with no number of queue pairs set */
371 [ # # ]: 0 : TEST_ASSERT_FAIL(rte_compressdev_queue_pair_setup(0, 0,
372 : : NUM_MAX_INFLIGHT_OPS, rte_socket_id()),
373 : : "Queue pair setup was successful "
374 : : "with no queue pairs set (invalid)\n");
375 : :
376 : : return TEST_SUCCESS;
377 : : }
378 : :
379 : : static int
380 : 0 : compare_buffers(const char *buffer1, uint32_t buffer1_len,
381 : : const char *buffer2, uint32_t buffer2_len)
382 : : {
383 [ # # ]: 0 : if (buffer1_len != buffer2_len) {
384 : 0 : RTE_LOG(ERR, USER1, "Buffer lengths are different\n");
385 : 0 : return -1;
386 : : }
387 : :
388 [ # # ]: 0 : if (memcmp(buffer1, buffer2, buffer1_len) != 0) {
389 : 0 : RTE_LOG(ERR, USER1, "Buffers are different\n");
390 : 0 : return -1;
391 : : }
392 : :
393 : : return 0;
394 : : }
395 : :
396 : : /*
397 : : * Maps compressdev and Zlib flush flags
398 : : */
399 : : static int
400 : : map_zlib_flush_flag(enum rte_comp_flush_flag flag)
401 : : {
402 : : switch (flag) {
403 : : case RTE_COMP_FLUSH_NONE:
404 : : return Z_NO_FLUSH;
405 : : case RTE_COMP_FLUSH_SYNC:
406 : : return Z_SYNC_FLUSH;
407 : : case RTE_COMP_FLUSH_FULL:
408 : : return Z_FULL_FLUSH;
409 : : case RTE_COMP_FLUSH_FINAL:
410 : : return Z_FINISH;
411 : : /*
412 : : * There should be only the values above,
413 : : * so this should never happen
414 : : */
415 : : default:
416 : : return -1;
417 : : }
418 : : }
419 : :
420 : : static int
421 : 0 : compress_zlib(struct rte_comp_op *op,
422 : : const struct rte_comp_xform *xform, int mem_level)
423 : : {
424 : : z_stream stream;
425 : : int zlib_flush;
426 : : int strategy, window_bits, comp_level;
427 : : int ret = TEST_FAILED;
428 : : uint8_t *single_src_buf = NULL;
429 : : uint8_t *single_dst_buf = NULL;
430 : :
431 : : /* initialize zlib stream */
432 : 0 : stream.zalloc = Z_NULL;
433 : 0 : stream.zfree = Z_NULL;
434 : 0 : stream.opaque = Z_NULL;
435 : :
436 [ # # ]: 0 : if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED)
437 : : strategy = Z_FIXED;
438 : : else
439 : : strategy = Z_DEFAULT_STRATEGY;
440 : :
441 : : /*
442 : : * Window bits is the base two logarithm of the window size (in bytes).
443 : : * When doing raw DEFLATE, this number will be negative.
444 : : */
445 : 0 : window_bits = -(xform->compress.window_size);
446 [ # # ]: 0 : if (xform->compress.chksum == RTE_COMP_CHECKSUM_ADLER32)
447 : : window_bits *= -1;
448 [ # # ]: 0 : else if (xform->compress.chksum == RTE_COMP_CHECKSUM_CRC32)
449 : : window_bits = ZLIB_CRC_CHECKSUM_WINDOW_BITS;
450 : :
451 : 0 : comp_level = xform->compress.level;
452 : :
453 [ # # ]: 0 : if (comp_level != RTE_COMP_LEVEL_NONE)
454 : 0 : ret = deflateInit2(&stream, comp_level, Z_DEFLATED,
455 : : window_bits, mem_level, strategy);
456 : : else
457 : 0 : ret = deflateInit(&stream, Z_NO_COMPRESSION);
458 : :
459 [ # # ]: 0 : if (ret != Z_OK) {
460 : : printf("Zlib deflate could not be initialized\n");
461 : 0 : goto exit;
462 : : }
463 : :
464 : : /* Assuming stateless operation */
465 : : /* SGL Input */
466 [ # # ]: 0 : if (op->m_src->nb_segs > 1) {
467 : 0 : single_src_buf = rte_malloc(NULL,
468 : 0 : rte_pktmbuf_pkt_len(op->m_src), 0);
469 [ # # ]: 0 : if (single_src_buf == NULL) {
470 : 0 : RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
471 : 0 : goto exit;
472 : : }
473 : :
474 [ # # ]: 0 : if (rte_pktmbuf_read(op->m_src, op->src.offset,
475 : 0 : rte_pktmbuf_pkt_len(op->m_src) -
476 [ # # ]: 0 : op->src.offset,
477 : : single_src_buf) == NULL) {
478 : 0 : RTE_LOG(ERR, USER1,
479 : : "Buffer could not be read entirely\n");
480 : 0 : goto exit;
481 : : }
482 : :
483 : 0 : stream.avail_in = op->src.length;
484 : 0 : stream.next_in = single_src_buf;
485 : :
486 : : } else {
487 : 0 : stream.avail_in = op->src.length;
488 : 0 : stream.next_in = rte_pktmbuf_mtod_offset(op->m_src, uint8_t *,
489 : : op->src.offset);
490 : : }
491 : : /* SGL output */
492 [ # # ]: 0 : if (op->m_dst->nb_segs > 1) {
493 : :
494 : 0 : single_dst_buf = rte_malloc(NULL,
495 : 0 : rte_pktmbuf_pkt_len(op->m_dst), 0);
496 [ # # ]: 0 : if (single_dst_buf == NULL) {
497 : 0 : RTE_LOG(ERR, USER1,
498 : : "Buffer could not be allocated\n");
499 : 0 : goto exit;
500 : : }
501 : :
502 : 0 : stream.avail_out = op->m_dst->pkt_len;
503 : 0 : stream.next_out = single_dst_buf;
504 : :
505 : : } else {/* linear output */
506 : 0 : stream.avail_out = op->m_dst->data_len;
507 : 0 : stream.next_out = rte_pktmbuf_mtod_offset(op->m_dst, uint8_t *,
508 : : op->dst.offset);
509 : : }
510 : :
511 : : /* Stateless operation, all buffer will be compressed in one go */
512 [ # # ]: 0 : zlib_flush = map_zlib_flush_flag(op->flush_flag);
513 : 0 : ret = deflate(&stream, zlib_flush);
514 : :
515 [ # # ]: 0 : if (stream.avail_in != 0) {
516 : 0 : RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
517 : 0 : goto exit;
518 : : }
519 : :
520 [ # # ]: 0 : if (ret != Z_STREAM_END)
521 : 0 : goto exit;
522 : :
523 : : /* Copy data to destination SGL */
524 [ # # ]: 0 : if (op->m_dst->nb_segs > 1) {
525 : 0 : uint32_t remaining_data = stream.total_out;
526 : : uint8_t *src_data = single_dst_buf;
527 : : struct rte_mbuf *dst_buf = op->m_dst;
528 : :
529 [ # # ]: 0 : while (remaining_data > 0) {
530 : 0 : uint8_t *dst_data = rte_pktmbuf_mtod_offset(dst_buf,
531 : : uint8_t *, op->dst.offset);
532 : : /* Last segment */
533 [ # # ]: 0 : if (remaining_data < dst_buf->data_len) {
534 : 0 : memcpy(dst_data, src_data, remaining_data);
535 : : remaining_data = 0;
536 : : } else {
537 : 0 : memcpy(dst_data, src_data, dst_buf->data_len);
538 : 0 : remaining_data -= dst_buf->data_len;
539 : 0 : src_data += dst_buf->data_len;
540 : 0 : dst_buf = dst_buf->next;
541 : : }
542 : : }
543 : : }
544 : :
545 : 0 : op->consumed = stream.total_in;
546 [ # # ]: 0 : if (xform->compress.chksum == RTE_COMP_CHECKSUM_ADLER32) {
547 [ # # ]: 0 : rte_pktmbuf_adj(op->m_dst, ZLIB_HEADER_SIZE);
548 : 0 : rte_pktmbuf_trim(op->m_dst, ZLIB_TRAILER_SIZE);
549 : 0 : op->produced = stream.total_out - (ZLIB_HEADER_SIZE +
550 : : ZLIB_TRAILER_SIZE);
551 [ # # ]: 0 : } else if (xform->compress.chksum == RTE_COMP_CHECKSUM_CRC32) {
552 [ # # ]: 0 : rte_pktmbuf_adj(op->m_dst, GZIP_HEADER_SIZE);
553 : 0 : rte_pktmbuf_trim(op->m_dst, GZIP_TRAILER_SIZE);
554 : 0 : op->produced = stream.total_out - (GZIP_HEADER_SIZE +
555 : : GZIP_TRAILER_SIZE);
556 : : } else
557 : 0 : op->produced = stream.total_out;
558 : :
559 : 0 : op->status = RTE_COMP_OP_STATUS_SUCCESS;
560 : 0 : op->output_chksum = stream.adler;
561 : :
562 : 0 : deflateReset(&stream);
563 : :
564 : : ret = 0;
565 : 0 : exit:
566 : 0 : deflateEnd(&stream);
567 : 0 : rte_free(single_src_buf);
568 : 0 : rte_free(single_dst_buf);
569 : :
570 : 0 : return ret;
571 : : }
572 : :
573 : : static int
574 : 0 : decompress_zlib(struct rte_comp_op *op,
575 : : const struct rte_comp_xform *xform)
576 : : {
577 : : z_stream stream;
578 : : int window_bits;
579 : : int zlib_flush;
580 : : int ret = TEST_FAILED;
581 : : uint8_t *single_src_buf = NULL;
582 : : uint8_t *single_dst_buf = NULL;
583 : :
584 : : /* initialize zlib stream */
585 : 0 : stream.zalloc = Z_NULL;
586 : 0 : stream.zfree = Z_NULL;
587 : 0 : stream.opaque = Z_NULL;
588 : :
589 : : /*
590 : : * Window bits is the base two logarithm of the window size (in bytes).
591 : : * When doing raw DEFLATE, this number will be negative.
592 : : */
593 : 0 : window_bits = -(xform->decompress.window_size);
594 : 0 : ret = inflateInit2(&stream, window_bits);
595 : :
596 [ # # ]: 0 : if (ret != Z_OK) {
597 : : printf("Zlib deflate could not be initialized\n");
598 : 0 : goto exit;
599 : : }
600 : :
601 : : /* Assuming stateless operation */
602 : : /* SGL */
603 [ # # ]: 0 : if (op->m_src->nb_segs > 1) {
604 : 0 : single_src_buf = rte_malloc(NULL,
605 : 0 : rte_pktmbuf_pkt_len(op->m_src), 0);
606 [ # # ]: 0 : if (single_src_buf == NULL) {
607 : 0 : RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
608 : 0 : goto exit;
609 : : }
610 : 0 : single_dst_buf = rte_malloc(NULL,
611 : 0 : rte_pktmbuf_pkt_len(op->m_dst), 0);
612 [ # # ]: 0 : if (single_dst_buf == NULL) {
613 : 0 : RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
614 : 0 : goto exit;
615 : : }
616 [ # # ]: 0 : if (rte_pktmbuf_read(op->m_src, 0,
617 [ # # ]: 0 : rte_pktmbuf_pkt_len(op->m_src),
618 : : single_src_buf) == NULL) {
619 : 0 : RTE_LOG(ERR, USER1,
620 : : "Buffer could not be read entirely\n");
621 : 0 : goto exit;
622 : : }
623 : :
624 : 0 : stream.avail_in = op->src.length;
625 : 0 : stream.next_in = single_src_buf;
626 : 0 : stream.avail_out = rte_pktmbuf_pkt_len(op->m_dst);
627 : 0 : stream.next_out = single_dst_buf;
628 : :
629 : : } else {
630 : 0 : stream.avail_in = op->src.length;
631 : 0 : stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
632 : 0 : stream.avail_out = op->m_dst->data_len;
633 : 0 : stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
634 : : }
635 : :
636 : : /* Stateless operation, all buffer will be compressed in one go */
637 [ # # ]: 0 : zlib_flush = map_zlib_flush_flag(op->flush_flag);
638 : 0 : ret = inflate(&stream, zlib_flush);
639 : :
640 [ # # ]: 0 : if (stream.avail_in != 0) {
641 : 0 : RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
642 : 0 : goto exit;
643 : : }
644 : :
645 [ # # ]: 0 : if (ret != Z_STREAM_END)
646 : 0 : goto exit;
647 : :
648 [ # # ]: 0 : if (op->m_src->nb_segs > 1) {
649 : 0 : uint32_t remaining_data = stream.total_out;
650 : : uint8_t *src_data = single_dst_buf;
651 : 0 : struct rte_mbuf *dst_buf = op->m_dst;
652 : :
653 [ # # ]: 0 : while (remaining_data > 0) {
654 : 0 : uint8_t *dst_data = rte_pktmbuf_mtod(dst_buf,
655 : : uint8_t *);
656 : : /* Last segment */
657 [ # # ]: 0 : if (remaining_data < dst_buf->data_len) {
658 : 0 : memcpy(dst_data, src_data, remaining_data);
659 : : remaining_data = 0;
660 : : } else {
661 : 0 : memcpy(dst_data, src_data, dst_buf->data_len);
662 : 0 : remaining_data -= dst_buf->data_len;
663 : 0 : src_data += dst_buf->data_len;
664 : 0 : dst_buf = dst_buf->next;
665 : : }
666 : : }
667 : : }
668 : :
669 : 0 : op->consumed = stream.total_in;
670 : 0 : op->produced = stream.total_out;
671 : 0 : op->status = RTE_COMP_OP_STATUS_SUCCESS;
672 : :
673 : 0 : inflateReset(&stream);
674 : :
675 : : ret = 0;
676 : 0 : exit:
677 : 0 : inflateEnd(&stream);
678 : :
679 : 0 : return ret;
680 : : }
681 : :
682 : : static int
683 : 0 : prepare_sgl_bufs(const char *test_buf, struct rte_mbuf *head_buf,
684 : : uint32_t total_data_size,
685 : : struct rte_mempool *small_mbuf_pool,
686 : : struct rte_mempool *large_mbuf_pool,
687 : : uint8_t limit_segs_in_sgl,
688 : : uint16_t seg_size)
689 : : {
690 : : uint32_t remaining_data = total_data_size;
691 : 0 : uint16_t num_remaining_segs = DIV_CEIL(remaining_data, seg_size);
692 : : struct rte_mempool *pool;
693 : : struct rte_mbuf *next_seg;
694 : : uint32_t data_size;
695 : : char *buf_ptr;
696 : : const char *data_ptr = test_buf;
697 : : uint16_t i;
698 : : int ret;
699 : :
700 [ # # # # ]: 0 : if (limit_segs_in_sgl != 0 && num_remaining_segs > limit_segs_in_sgl)
701 : 0 : num_remaining_segs = limit_segs_in_sgl - 1;
702 : :
703 : : /*
704 : : * Allocate data in the first segment (header) and
705 : : * copy data if test buffer is provided
706 : : */
707 : : if (remaining_data < seg_size)
708 : : data_size = remaining_data;
709 : : else
710 : : data_size = seg_size;
711 : :
712 : 0 : buf_ptr = rte_pktmbuf_append(head_buf, data_size);
713 [ # # ]: 0 : if (buf_ptr == NULL) {
714 : 0 : RTE_LOG(ERR, USER1,
715 : : "Not enough space in the 1st buffer\n");
716 : 0 : return -1;
717 : : }
718 : :
719 [ # # ]: 0 : if (data_ptr != NULL) {
720 : : /* Copy characters without NULL terminator */
721 : 0 : memcpy(buf_ptr, data_ptr, data_size);
722 : 0 : data_ptr += data_size;
723 : : }
724 : 0 : remaining_data -= data_size;
725 : 0 : num_remaining_segs--;
726 : :
727 : : /*
728 : : * Allocate the rest of the segments,
729 : : * copy the rest of the data and chain the segments.
730 : : */
731 [ # # ]: 0 : for (i = 0; i < num_remaining_segs; i++) {
732 : :
733 [ # # ]: 0 : if (i == (num_remaining_segs - 1)) {
734 : : /* last segment */
735 [ # # ]: 0 : if (remaining_data > seg_size)
736 : : pool = large_mbuf_pool;
737 : : else
738 : : pool = small_mbuf_pool;
739 : : data_size = remaining_data;
740 : : } else {
741 : : data_size = seg_size;
742 : : pool = small_mbuf_pool;
743 : : }
744 : :
745 : 0 : next_seg = rte_pktmbuf_alloc(pool);
746 [ # # ]: 0 : if (next_seg == NULL) {
747 : 0 : RTE_LOG(ERR, USER1,
748 : : "New segment could not be allocated "
749 : : "from the mempool\n");
750 : 0 : return -1;
751 : : }
752 : 0 : buf_ptr = rte_pktmbuf_append(next_seg, data_size);
753 [ # # ]: 0 : if (buf_ptr == NULL) {
754 : 0 : RTE_LOG(ERR, USER1,
755 : : "Not enough space in the buffer\n");
756 : 0 : rte_pktmbuf_free(next_seg);
757 : 0 : return -1;
758 : : }
759 [ # # ]: 0 : if (data_ptr != NULL) {
760 : : /* Copy characters without NULL terminator */
761 : 0 : memcpy(buf_ptr, data_ptr, data_size);
762 : 0 : data_ptr += data_size;
763 : : }
764 [ # # ]: 0 : remaining_data -= data_size;
765 : :
766 : : ret = rte_pktmbuf_chain(head_buf, next_seg);
767 : : if (ret != 0) {
768 : 0 : rte_pktmbuf_free(next_seg);
769 : 0 : RTE_LOG(ERR, USER1,
770 : : "Segment could not chained\n");
771 : 0 : return -1;
772 : : }
773 : : }
774 : :
775 : : return 0;
776 : : }
777 : :
778 : : static void
779 : 0 : extbuf_free_callback(void *addr __rte_unused, void *opaque __rte_unused)
780 : : {
781 : 0 : }
782 : :
783 : : static int
784 : 0 : test_run_enqueue_dequeue(struct rte_comp_op **ops,
785 : : struct rte_comp_op **ops_processed,
786 : : unsigned int num_bufs)
787 : : {
788 : : uint16_t num_enqd, num_deqd, num_total_deqd;
789 : : unsigned int deqd_retries = 0;
790 : : int res = 0;
791 : :
792 : : /* Enqueue and dequeue all operations */
793 : 0 : num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
794 [ # # ]: 0 : if (num_enqd < num_bufs) {
795 : 0 : RTE_LOG(ERR, USER1,
796 : : "Some operations could not be enqueued\n");
797 : : res = -1;
798 : : }
799 : :
800 : : /* dequeue ops even on error (same number of ops as was enqueued) */
801 : :
802 : : num_total_deqd = 0;
803 [ # # ]: 0 : while (num_total_deqd < num_enqd) {
804 : : /*
805 : : * If retrying a dequeue call, wait for 10 ms to allow
806 : : * enough time to the driver to process the operations
807 : : */
808 [ # # ]: 0 : if (deqd_retries != 0) {
809 : : /*
810 : : * Avoid infinite loop if not all the
811 : : * operations get out of the device
812 : : */
813 [ # # ]: 0 : if (deqd_retries == MAX_DEQD_RETRIES) {
814 : 0 : RTE_LOG(ERR, USER1,
815 : : "Not all operations could be dequeued\n");
816 : : res = -1;
817 : 0 : break;
818 : : }
819 : 0 : usleep(DEQUEUE_WAIT_TIME);
820 : : }
821 : 0 : num_deqd = rte_compressdev_dequeue_burst(0, 0,
822 : 0 : &ops_processed[num_total_deqd], num_bufs);
823 : 0 : num_total_deqd += num_deqd;
824 : 0 : deqd_retries++;
825 : :
826 : : }
827 : :
828 : 0 : return res;
829 : : }
830 : :
831 : : /**
832 : : * Arrays initialization. Input buffers preparation for compression.
833 : : *
834 : : * API that initializes all the private arrays to NULL
835 : : * and allocates input buffers to perform compression operations.
836 : : *
837 : : * @param int_data
838 : : * Interim data containing session/transformation objects.
839 : : * @param test_data
840 : : * The test parameters set by users (command line parameters).
841 : : * @param test_priv_data
842 : : * A container used for aggregation all the private test arrays.
843 : : * @return
844 : : * - 0: On success.
845 : : * - -1: On error.
846 : : */
847 : : static int
848 : 0 : test_setup_com_bufs(const struct interim_data_params *int_data,
849 : : const struct test_data_params *test_data,
850 : : const struct test_private_arrays *test_priv_data)
851 : : {
852 : : /* local variables: */
853 : : unsigned int i;
854 : : uint32_t data_size;
855 : : char *buf_ptr;
856 : : int ret;
857 : 0 : char **all_decomp_data = test_priv_data->all_decomp_data;
858 : :
859 : : struct comp_testsuite_params *ts_params = &testsuite_params;
860 : :
861 : : /* from int_data: */
862 : 0 : const char * const *test_bufs = int_data->test_bufs;
863 : 0 : unsigned int num_bufs = int_data->num_bufs;
864 : :
865 : : /* from test_data: */
866 : 0 : unsigned int buff_type = test_data->buff_type;
867 : 0 : unsigned int big_data = test_data->big_data;
868 : :
869 : : /* from test_priv_data: */
870 : 0 : struct rte_mbuf **uncomp_bufs = test_priv_data->uncomp_bufs;
871 : : struct rte_mempool *buf_pool;
872 : :
873 : : static struct rte_mbuf_ext_shared_info inbuf_info;
874 : :
875 [ # # ]: 0 : size_t array_size = sizeof(void *) * num_bufs;
876 : :
877 : : /* Initialize all arrays to NULL */
878 : : memset(test_priv_data->uncomp_bufs, 0, array_size);
879 : 0 : memset(test_priv_data->comp_bufs, 0, array_size);
880 : 0 : memset(test_priv_data->ops, 0, array_size);
881 : 0 : memset(test_priv_data->ops_processed, 0, array_size);
882 : 0 : memset(test_priv_data->priv_xforms, 0, array_size);
883 : 0 : memset(test_priv_data->compressed_data_size,
884 : : 0, sizeof(uint32_t) * num_bufs);
885 : :
886 [ # # ]: 0 : if (test_data->decompress_state == RTE_COMP_OP_STATEFUL) {
887 : 0 : data_size = strlen(test_bufs[0]) + 1;
888 : 0 : *all_decomp_data = rte_malloc(NULL, data_size,
889 : : RTE_CACHE_LINE_SIZE);
890 : : }
891 : :
892 [ # # ]: 0 : if (big_data)
893 : 0 : buf_pool = ts_params->big_mbuf_pool;
894 [ # # ]: 0 : else if (buff_type == SGL_BOTH)
895 : 0 : buf_pool = ts_params->small_mbuf_pool;
896 : : else
897 : 0 : buf_pool = ts_params->large_mbuf_pool;
898 : :
899 : : /* for compression uncomp_bufs is used as a source buffer */
900 : : /* allocation from buf_pool (mempool type) */
901 : 0 : ret = rte_pktmbuf_alloc_bulk(buf_pool,
902 : : uncomp_bufs, num_bufs);
903 [ # # ]: 0 : if (ret < 0) {
904 : 0 : RTE_LOG(ERR, USER1,
905 : : "Source mbufs could not be allocated "
906 : : "from the mempool\n");
907 : 0 : return -1;
908 : : }
909 : :
910 [ # # ]: 0 : if (test_data->use_external_mbufs) {
911 : 0 : inbuf_info.free_cb = extbuf_free_callback;
912 : 0 : inbuf_info.fcb_opaque = NULL;
913 : : rte_mbuf_ext_refcnt_set(&inbuf_info, 1);
914 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
915 : 0 : rte_pktmbuf_attach_extbuf(uncomp_bufs[i],
916 : 0 : test_data->inbuf_memzone->addr,
917 : 0 : test_data->inbuf_memzone->iova,
918 : 0 : test_data->inbuf_data_size,
919 : : &inbuf_info);
920 : 0 : buf_ptr = rte_pktmbuf_append(uncomp_bufs[i],
921 : 0 : test_data->inbuf_data_size);
922 [ # # ]: 0 : if (buf_ptr == NULL) {
923 : 0 : RTE_LOG(ERR, USER1,
924 : : "Append extra bytes to the source mbuf failed\n");
925 : 0 : return -1;
926 : : }
927 : : }
928 [ # # ]: 0 : } else if (buff_type == SGL_BOTH || buff_type == SGL_TO_LB) {
929 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
930 : 0 : data_size = strlen(test_bufs[i]) + 1;
931 [ # # # # : 0 : if (prepare_sgl_bufs(test_bufs[i], uncomp_bufs[i],
# # # # #
# ]
932 : : data_size,
933 : : big_data ? buf_pool : ts_params->small_mbuf_pool,
934 : : big_data ? buf_pool : ts_params->large_mbuf_pool,
935 : : big_data ? 0 : MAX_SEGS,
936 : : big_data ? MAX_DATA_MBUF_SIZE : SMALL_SEG_SIZE) < 0)
937 : : return -1;
938 : : }
939 : : } else {
940 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
941 : 0 : data_size = strlen(test_bufs[i]) + 1;
942 : :
943 : 0 : buf_ptr = rte_pktmbuf_append(uncomp_bufs[i], data_size);
944 [ # # ]: 0 : if (buf_ptr == NULL) {
945 : 0 : RTE_LOG(ERR, USER1,
946 : : "Append extra bytes to the source mbuf failed\n");
947 : 0 : return -1;
948 : : }
949 : 0 : strlcpy(buf_ptr, test_bufs[i], data_size);
950 : : }
951 : : }
952 : :
953 : : return 0;
954 : : }
955 : :
956 : : /**
957 : : * Data size calculation (for both compression and decompression).
958 : : *
959 : : * Calculate size of anticipated output buffer required for both
960 : : * compression and decompression operations based on input int_data.
961 : : *
962 : : * @param op_type
963 : : * Operation type: compress or decompress
964 : : * @param out_of_space_and_zlib
965 : : * Boolean value to switch into "out of space" buffer if set.
966 : : * To test "out-of-space" data size, zlib_decompress must be set as well.
967 : : * @param test_priv_data
968 : : * A container used for aggregation all the private test arrays.
969 : : * @param int_data
970 : : * Interim data containing session/transformation objects.
971 : : * @param test_data
972 : : * The test parameters set by users (command line parameters).
973 : : * @param i
974 : : * current buffer index
975 : : * @return
976 : : * data size
977 : : */
978 : : static inline uint32_t
979 : 0 : test_mbufs_calculate_data_size(
980 : : enum operation_type op_type,
981 : : unsigned int out_of_space_and_zlib,
982 : : const struct test_private_arrays *test_priv_data,
983 : : const struct interim_data_params *int_data,
984 : : const struct test_data_params *test_data,
985 : : unsigned int i)
986 : : {
987 : : /* local variables: */
988 : : uint32_t data_size;
989 : : struct priv_op_data *priv_data;
990 : : float ratio_val;
991 : 0 : enum ratio_switch ratio = test_data->ratio;
992 : :
993 : : uint8_t not_zlib_compr; /* true if zlib isn't current compression dev */
994 : 0 : enum overflow_test overflow = test_data->overflow;
995 : :
996 : : /* from test_priv_data: */
997 : 0 : struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
998 : :
999 : : /* from int_data: */
1000 : 0 : const char * const *test_bufs = int_data->test_bufs;
1001 : :
1002 [ # # ]: 0 : if (out_of_space_and_zlib)
1003 : : data_size = OUT_OF_SPACE_BUF;
1004 : : else {
1005 [ # # ]: 0 : if (op_type == OPERATION_COMPRESSION) {
1006 : 0 : not_zlib_compr = (test_data->zlib_dir == ZLIB_DECOMPRESS
1007 : 0 : || test_data->zlib_dir == ZLIB_NONE);
1008 : :
1009 : : ratio_val = (ratio == RATIO_ENABLED) ?
1010 [ # # ]: 0 : COMPRESS_BUF_SIZE_RATIO :
1011 : : COMPRESS_BUF_SIZE_RATIO_DISABLED;
1012 : :
1013 : 0 : ratio_val = (not_zlib_compr &&
1014 : 0 : (overflow == OVERFLOW_ENABLED)) ?
1015 [ # # ]: 0 : COMPRESS_BUF_SIZE_RATIO_OVERFLOW :
1016 : : ratio_val;
1017 : :
1018 : 0 : data_size = strlen(test_bufs[i]) * ratio_val;
1019 : : } else {
1020 : : priv_data = (struct priv_op_data *)
1021 : 0 : (ops_processed[i] + 1);
1022 : 0 : data_size = strlen(test_bufs[priv_data->orig_idx]) + 1;
1023 : : }
1024 : : }
1025 : :
1026 : 0 : return data_size;
1027 : : }
1028 : :
1029 : :
1030 : : /**
1031 : : * Memory buffers preparation (for both compression and decompression).
1032 : : *
1033 : : * Function allocates output buffers to perform compression
1034 : : * or decompression operations depending on value of op_type.
1035 : : *
1036 : : * @param op_type
1037 : : * Operation type: compress or decompress
1038 : : * @param out_of_space_and_zlib
1039 : : * Boolean value to switch into "out of space" buffer if set.
1040 : : * To test "out-of-space" data size, zlib_decompress must be set as well.
1041 : : * @param test_priv_data
1042 : : * A container used for aggregation all the private test arrays.
1043 : : * @param int_data
1044 : : * Interim data containing session/transformation objects.
1045 : : * @param test_data
1046 : : * The test parameters set by users (command line parameters).
1047 : : * @param current_extbuf_info,
1048 : : * The structure containing all the information related to external mbufs
1049 : : * @return
1050 : : * - 0: On success.
1051 : : * - -1: On error.
1052 : : */
1053 : : static int
1054 : 0 : test_setup_output_bufs(
1055 : : enum operation_type op_type,
1056 : : unsigned int out_of_space_and_zlib,
1057 : : const struct test_private_arrays *test_priv_data,
1058 : : const struct interim_data_params *int_data,
1059 : : const struct test_data_params *test_data,
1060 : : struct rte_mbuf_ext_shared_info *current_extbuf_info)
1061 : : {
1062 : : /* local variables: */
1063 : : unsigned int i;
1064 : : uint32_t data_size;
1065 : : int ret;
1066 : : char *buf_ptr;
1067 : :
1068 : : /* from test_priv_data: */
1069 : : struct rte_mbuf **current_bufs;
1070 : :
1071 : : /* from int_data: */
1072 : 0 : unsigned int num_bufs = int_data->num_bufs;
1073 : :
1074 : : /* from test_data: */
1075 : 0 : unsigned int buff_type = test_data->buff_type;
1076 : 0 : unsigned int big_data = test_data->big_data;
1077 : : const struct rte_memzone *current_memzone;
1078 : :
1079 : : struct comp_testsuite_params *ts_params = &testsuite_params;
1080 : : struct rte_mempool *buf_pool;
1081 : :
1082 [ # # ]: 0 : if (big_data)
1083 : 0 : buf_pool = ts_params->big_mbuf_pool;
1084 [ # # ]: 0 : else if (buff_type == SGL_BOTH)
1085 : 0 : buf_pool = ts_params->small_mbuf_pool;
1086 : : else
1087 : 0 : buf_pool = ts_params->large_mbuf_pool;
1088 : :
1089 [ # # ]: 0 : if (op_type == OPERATION_COMPRESSION)
1090 : 0 : current_bufs = test_priv_data->comp_bufs;
1091 : : else
1092 : 0 : current_bufs = test_priv_data->uncomp_bufs;
1093 : :
1094 : : /* the mbufs allocation*/
1095 : 0 : ret = rte_pktmbuf_alloc_bulk(buf_pool, current_bufs, num_bufs);
1096 [ # # ]: 0 : if (ret < 0) {
1097 : 0 : RTE_LOG(ERR, USER1,
1098 : : "Destination mbufs could not be allocated "
1099 : : "from the mempool\n");
1100 : 0 : return -1;
1101 : : }
1102 : :
1103 [ # # ]: 0 : if (test_data->use_external_mbufs) {
1104 : 0 : current_extbuf_info->free_cb = extbuf_free_callback;
1105 [ # # ]: 0 : current_extbuf_info->fcb_opaque = NULL;
1106 : : rte_mbuf_ext_refcnt_set(current_extbuf_info, 1);
1107 [ # # ]: 0 : if (op_type == OPERATION_COMPRESSION)
1108 : 0 : current_memzone = test_data->compbuf_memzone;
1109 : : else
1110 : 0 : current_memzone = test_data->uncompbuf_memzone;
1111 : :
1112 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1113 : 0 : rte_pktmbuf_attach_extbuf(current_bufs[i],
1114 : 0 : current_memzone->addr,
1115 : 0 : current_memzone->iova,
1116 : 0 : current_memzone->len,
1117 : : current_extbuf_info);
1118 : 0 : rte_pktmbuf_append(current_bufs[i],
1119 : 0 : current_memzone->len);
1120 : : }
1121 : : } else {
1122 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1123 : :
1124 : 0 : enum rte_comp_huffman comp_huffman =
1125 : 0 : ts_params->def_comp_xform->compress.deflate.huffman;
1126 : :
1127 : : /* data size calculation */
1128 : 0 : data_size = test_mbufs_calculate_data_size(
1129 : : op_type,
1130 : : out_of_space_and_zlib,
1131 : : test_priv_data,
1132 : : int_data,
1133 : : test_data,
1134 : : i);
1135 : :
1136 [ # # ]: 0 : if (comp_huffman != RTE_COMP_HUFFMAN_DYNAMIC) {
1137 [ # # ]: 0 : if (op_type == OPERATION_DECOMPRESSION)
1138 : 0 : data_size *= COMPRESS_BUF_SIZE_RATIO;
1139 : : }
1140 : :
1141 : : /* data allocation */
1142 [ # # ]: 0 : if (buff_type == SGL_BOTH || buff_type == LB_TO_SGL) {
1143 [ # # # # : 0 : ret = prepare_sgl_bufs(NULL, current_bufs[i],
# # # # ]
1144 : : data_size,
1145 : : big_data ? buf_pool :
1146 : : ts_params->small_mbuf_pool,
1147 : : big_data ? buf_pool :
1148 : : ts_params->large_mbuf_pool,
1149 : : big_data ? 0 : MAX_SEGS,
1150 : : big_data ? MAX_DATA_MBUF_SIZE :
1151 : : SMALL_SEG_SIZE);
1152 [ # # ]: 0 : if (ret < 0)
1153 : : return -1;
1154 : : } else {
1155 : 0 : buf_ptr = rte_pktmbuf_append(current_bufs[i],
1156 : : data_size);
1157 [ # # ]: 0 : if (buf_ptr == NULL) {
1158 : 0 : RTE_LOG(ERR, USER1,
1159 : : "Append extra bytes to the destination mbuf failed\n");
1160 : 0 : return -1;
1161 : : }
1162 : : }
1163 : : }
1164 : : }
1165 : :
1166 : : return 0;
1167 : : }
1168 : :
1169 : : /**
1170 : : * The main compression function.
1171 : : *
1172 : : * Function performs compression operation.
1173 : : * Operation(s) configuration, depending on CLI parameters.
1174 : : * Operation(s) processing.
1175 : : *
1176 : : * @param int_data
1177 : : * Interim data containing session/transformation objects.
1178 : : * @param test_data
1179 : : * The test parameters set by users (command line parameters).
1180 : : * @param test_priv_data
1181 : : * A container used for aggregation all the private test arrays.
1182 : : * @return
1183 : : * - 0: On success.
1184 : : * - -1: On error.
1185 : : */
1186 : : static int
1187 : 0 : test_deflate_comp_run(const struct interim_data_params *int_data,
1188 : : const struct test_data_params *test_data,
1189 : : const struct test_private_arrays *test_priv_data)
1190 : : {
1191 : : /* local variables: */
1192 : : struct priv_op_data *priv_data;
1193 : : unsigned int i;
1194 : : uint16_t num_priv_xforms = 0;
1195 : : int ret;
1196 : : int ret_status = 0;
1197 : : char *buf_ptr;
1198 : :
1199 : : struct comp_testsuite_params *ts_params = &testsuite_params;
1200 : :
1201 : : /* from test_data: */
1202 : 0 : enum rte_comp_op_type operation_type = test_data->compress_state;
1203 : : unsigned int zlib_compress =
1204 : 0 : (test_data->zlib_dir == ZLIB_ALL ||
1205 : : test_data->zlib_dir == ZLIB_COMPRESS);
1206 : :
1207 : : /* from int_data: */
1208 : 0 : struct rte_comp_xform **compress_xforms = int_data->compress_xforms;
1209 : 0 : unsigned int num_xforms = int_data->num_xforms;
1210 : 0 : unsigned int num_bufs = int_data->num_bufs;
1211 : :
1212 : : /* from test_priv_data: */
1213 : 0 : struct rte_mbuf **comp_bufs = test_priv_data->comp_bufs;
1214 : 0 : struct rte_mbuf **uncomp_bufs = test_priv_data->uncomp_bufs;
1215 : 0 : struct rte_comp_op **ops = test_priv_data->ops;
1216 : 0 : struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
1217 : 0 : void **priv_xforms = test_priv_data->priv_xforms;
1218 : :
1219 : : const struct rte_compressdev_capabilities *capa =
1220 : 0 : rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
1221 : :
1222 : : /* Build the compression operations */
1223 : 0 : ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
1224 [ # # ]: 0 : if (ret < 0) {
1225 : 0 : RTE_LOG(ERR, USER1,
1226 : : "Compress operations could not be allocated "
1227 : : "from the mempool\n");
1228 : : ret_status = -1;
1229 : 0 : goto exit;
1230 : : }
1231 : :
1232 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1233 : 0 : ops[i]->m_src = uncomp_bufs[i];
1234 : 0 : ops[i]->m_dst = comp_bufs[i];
1235 : 0 : ops[i]->src.offset = 0;
1236 : 0 : ops[i]->src.length = rte_pktmbuf_pkt_len(uncomp_bufs[i]);
1237 : 0 : ops[i]->dst.offset = 0;
1238 : :
1239 : 0 : RTE_LOG(DEBUG, USER1,
1240 : : "Uncompressed buffer length = %u compressed buffer length = %u",
1241 : : rte_pktmbuf_pkt_len(uncomp_bufs[i]),
1242 : : rte_pktmbuf_pkt_len(comp_bufs[i]));
1243 : :
1244 [ # # ]: 0 : if (operation_type == RTE_COMP_OP_STATELESS) {
1245 : 0 : ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
1246 : : } else {
1247 : 0 : RTE_LOG(ERR, USER1,
1248 : : "Compression: stateful operations are not "
1249 : : "supported in these tests yet\n");
1250 : : ret_status = -1;
1251 : 0 : goto exit;
1252 : : }
1253 : 0 : ops[i]->input_chksum = 0;
1254 : : /*
1255 : : * Store original operation index in private data,
1256 : : * since ordering does not have to be maintained,
1257 : : * when dequeuing from compressdev, so a comparison
1258 : : * at the end of the test can be done.
1259 : : */
1260 : 0 : priv_data = (struct priv_op_data *) (ops[i] + 1);
1261 : 0 : priv_data->orig_idx = i;
1262 : : }
1263 : :
1264 : : /* Compress data (either with Zlib API or compressdev API */
1265 [ # # ]: 0 : if (zlib_compress) {
1266 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1267 : 0 : const struct rte_comp_xform *compress_xform =
1268 : 0 : compress_xforms[i % num_xforms];
1269 : 0 : ret = compress_zlib(ops[i], compress_xform,
1270 : : DEFAULT_MEM_LEVEL);
1271 [ # # ]: 0 : if (ret < 0) {
1272 : : ret_status = -1;
1273 : 0 : goto exit;
1274 : : }
1275 : :
1276 : 0 : ops_processed[i] = ops[i];
1277 : : }
1278 : : } else {
1279 : : /* Create compress private xform data */
1280 [ # # ]: 0 : for (i = 0; i < num_xforms; i++) {
1281 : 0 : ret = rte_compressdev_private_xform_create(0,
1282 : : (const struct rte_comp_xform *)
1283 : 0 : compress_xforms[i],
1284 : 0 : &priv_xforms[i]);
1285 [ # # ]: 0 : if (ret < 0) {
1286 : 0 : RTE_LOG(ERR, USER1,
1287 : : "Compression private xform "
1288 : : "could not be created\n");
1289 : : ret_status = -1;
1290 : 0 : goto exit;
1291 : : }
1292 : 0 : num_priv_xforms++;
1293 : : }
1294 [ # # ]: 0 : if (capa->comp_feature_flags &
1295 : : RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
1296 : : /* Attach shareable private xform data to ops */
1297 [ # # ]: 0 : for (i = 0; i < num_bufs; i++)
1298 : 0 : ops[i]->private_xform =
1299 : 0 : priv_xforms[i % num_xforms];
1300 : : } else {
1301 : : /* Create rest of the private xforms for the other ops */
1302 [ # # ]: 0 : for (i = num_xforms; i < num_bufs; i++) {
1303 : 0 : ret = rte_compressdev_private_xform_create(0,
1304 : 0 : compress_xforms[i % num_xforms],
1305 : 0 : &priv_xforms[i]);
1306 [ # # ]: 0 : if (ret < 0) {
1307 : 0 : RTE_LOG(ERR, USER1,
1308 : : "Compression private xform "
1309 : : "could not be created\n");
1310 : : ret_status = -1;
1311 : 0 : goto exit;
1312 : : }
1313 : 0 : num_priv_xforms++;
1314 : : }
1315 : : /* Attach non shareable private xform data to ops */
1316 [ # # ]: 0 : for (i = 0; i < num_bufs; i++)
1317 : 0 : ops[i]->private_xform = priv_xforms[i];
1318 : : }
1319 : :
1320 : 0 : recovery_lb:
1321 : 0 : ret = test_run_enqueue_dequeue(ops, ops_processed, num_bufs);
1322 [ # # ]: 0 : if (ret < 0) {
1323 : 0 : RTE_LOG(ERR, USER1,
1324 : : "Compression: enqueue/dequeue operation failed\n");
1325 : : ret_status = -1;
1326 : 0 : goto exit;
1327 : : }
1328 : :
1329 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1330 : 0 : test_priv_data->compressed_data_size[i] +=
1331 : 0 : ops_processed[i]->produced;
1332 : :
1333 [ # # ]: 0 : if (ops_processed[i]->status ==
1334 : : RTE_COMP_OP_STATUS_OUT_OF_SPACE_RECOVERABLE) {
1335 : :
1336 : 0 : ops[i]->status =
1337 : : RTE_COMP_OP_STATUS_NOT_PROCESSED;
1338 : 0 : ops[i]->src.offset +=
1339 : 0 : ops_processed[i]->consumed;
1340 : 0 : ops[i]->src.length -=
1341 : 0 : ops_processed[i]->consumed;
1342 : 0 : ops[i]->dst.offset +=
1343 : 0 : ops_processed[i]->produced;
1344 : :
1345 : 0 : buf_ptr = rte_pktmbuf_append(
1346 : 0 : ops[i]->m_dst,
1347 : 0 : ops_processed[i]->produced);
1348 : :
1349 [ # # ]: 0 : if (buf_ptr == NULL) {
1350 : 0 : RTE_LOG(ERR, USER1,
1351 : : "Data recovery: append extra bytes to the current mbuf failed\n");
1352 : : ret_status = -1;
1353 : 0 : goto exit;
1354 : : }
1355 : 0 : goto recovery_lb;
1356 : : }
1357 : : }
1358 : : }
1359 : :
1360 : 0 : exit:
1361 : : /* Free resources */
1362 : : if (ret_status < 0)
1363 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1364 : 0 : rte_comp_op_free(ops[i]);
1365 : 0 : ops[i] = NULL;
1366 : 0 : ops_processed[i] = NULL;
1367 : : }
1368 : :
1369 : : /* Free compress private xforms */
1370 [ # # ]: 0 : for (i = 0; i < num_priv_xforms; i++) {
1371 [ # # ]: 0 : if (priv_xforms[i] != NULL) {
1372 : 0 : rte_compressdev_private_xform_free(0, priv_xforms[i]);
1373 : 0 : priv_xforms[i] = NULL;
1374 : : }
1375 : : }
1376 : :
1377 : 0 : return ret_status;
1378 : : }
1379 : :
1380 : : /**
1381 : : * Prints out the test report. Memory freeing.
1382 : : *
1383 : : * Called after successful compression.
1384 : : * Operation(s) status validation and decompression buffers freeing.
1385 : :
1386 : : * -1 returned if function fail.
1387 : : *
1388 : : * @param int_data
1389 : : * Interim data containing session/transformation objects.
1390 : : * @param test_data
1391 : : * The test parameters set by users (command line parameters).
1392 : : * @param test_priv_data
1393 : : * A container used for aggregation all the private test arrays.
1394 : : * @return
1395 : : * - 2: Some operation is not supported
1396 : : * - 1: Decompression should be skipped
1397 : : * - 0: On success.
1398 : : * - -1: On error.
1399 : : */
1400 : : static int
1401 : 0 : test_deflate_comp_finalize(const struct interim_data_params *int_data,
1402 : : const struct test_data_params *test_data,
1403 : : const struct test_private_arrays *test_priv_data)
1404 : : {
1405 : : /* local variables: */
1406 : : unsigned int i;
1407 : : struct priv_op_data *priv_data;
1408 : :
1409 : : /* from int_data: */
1410 : 0 : unsigned int num_xforms = int_data->num_xforms;
1411 : 0 : struct rte_comp_xform **compress_xforms = int_data->compress_xforms;
1412 : 0 : unsigned int num_bufs = int_data->num_bufs;
1413 : :
1414 : : /* from test_priv_data: */
1415 : 0 : struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
1416 : 0 : uint64_t *compress_checksum = test_priv_data->compress_checksum;
1417 : 0 : struct rte_mbuf **uncomp_bufs = test_priv_data->uncomp_bufs;
1418 : 0 : struct rte_comp_op **ops = test_priv_data->ops;
1419 : :
1420 : : /* from test_data: */
1421 : 0 : unsigned int out_of_space = test_data->out_of_space;
1422 : : unsigned int zlib_compress =
1423 : 0 : (test_data->zlib_dir == ZLIB_ALL ||
1424 : : test_data->zlib_dir == ZLIB_COMPRESS);
1425 : : unsigned int zlib_decompress =
1426 : 0 : (test_data->zlib_dir == ZLIB_ALL ||
1427 : : test_data->zlib_dir == ZLIB_DECOMPRESS);
1428 : :
1429 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1430 : 0 : priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
1431 : 0 : uint16_t xform_idx = priv_data->orig_idx % num_xforms;
1432 : : const struct rte_comp_compress_xform *compress_xform =
1433 : 0 : &compress_xforms[xform_idx]->compress;
1434 : 0 : enum rte_comp_huffman huffman_type =
1435 : : compress_xform->deflate.huffman;
1436 : 0 : char engine[] = "zlib (directly, not PMD)";
1437 [ # # ]: 0 : if (zlib_decompress)
1438 : : strlcpy(engine, "PMD", sizeof(engine));
1439 : :
1440 : 0 : RTE_LOG(DEBUG, USER1, "Buffer %u compressed by %s from %u to"
1441 : : " %u bytes (level = %d, huffman = %s)\n",
1442 : : i, engine,
1443 : : ops_processed[i]->consumed, ops_processed[i]->produced,
1444 : : compress_xform->level,
1445 : : huffman_type_strings[huffman_type]);
1446 [ # # ]: 0 : RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f\n",
1447 : : ops_processed[i]->consumed == 0 ? 0 :
1448 : : (float)ops_processed[i]->produced /
1449 : : ops_processed[i]->consumed * 100);
1450 [ # # ]: 0 : if (compress_xform->chksum != RTE_COMP_CHECKSUM_NONE)
1451 : 0 : compress_checksum[i] = ops_processed[i]->output_chksum;
1452 : 0 : ops[i] = NULL;
1453 : : }
1454 : :
1455 : : /*
1456 : : * Check operation status and free source mbufs (destination mbuf and
1457 : : * compress operation information is needed for the decompression stage)
1458 : : */
1459 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1460 [ # # ]: 0 : if (out_of_space && !zlib_compress) {
1461 [ # # ]: 0 : if (ops_processed[i]->status !=
1462 : : RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED) {
1463 : 0 : RTE_LOG(ERR, USER1,
1464 : : "Operation without expected out of "
1465 : : "space status error\n");
1466 : 0 : return -1;
1467 : : } else
1468 : 0 : continue;
1469 : : }
1470 : :
1471 [ # # ]: 0 : if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
1472 [ # # ]: 0 : if (test_data->overflow == OVERFLOW_ENABLED) {
1473 [ # # ]: 0 : if (ops_processed[i]->status ==
1474 : : RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED) {
1475 : 0 : RTE_LOG(INFO, USER1,
1476 : : "Out-of-space-recoverable functionality"
1477 : : " is not supported on this device\n");
1478 : 0 : return 2;
1479 : : }
1480 : : }
1481 : :
1482 : 0 : RTE_LOG(ERR, USER1,
1483 : : "Comp: Some operations were not successful\n");
1484 : 0 : return -1;
1485 : : }
1486 : : priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
1487 : 0 : rte_pktmbuf_free(uncomp_bufs[priv_data->orig_idx]);
1488 : 0 : uncomp_bufs[priv_data->orig_idx] = NULL;
1489 : : }
1490 : :
1491 [ # # ]: 0 : if (out_of_space && !zlib_compress)
1492 : 0 : return 1;
1493 : :
1494 : : return 0;
1495 : : }
1496 : :
1497 : : /**
1498 : : * The main decompression function.
1499 : : *
1500 : : * Function performs decompression operation.
1501 : : * Operation(s) configuration, depending on CLI parameters.
1502 : : * Operation(s) processing.
1503 : : *
1504 : : * @param int_data
1505 : : * Interim data containing session/transformation objects.
1506 : : * @param test_data
1507 : : * The test parameters set by users (command line parameters).
1508 : : * @param test_priv_data
1509 : : * A container used for aggregation all the private test arrays.
1510 : : * @return
1511 : : * - 0: On success.
1512 : : * - -1: On error.
1513 : : */
1514 : : static int
1515 : 0 : test_deflate_decomp_run(const struct interim_data_params *int_data,
1516 : : const struct test_data_params *test_data,
1517 : : struct test_private_arrays *test_priv_data)
1518 : : {
1519 : :
1520 : : /* local variables: */
1521 : : struct priv_op_data *priv_data;
1522 : : unsigned int i;
1523 : : uint16_t num_priv_xforms = 0;
1524 : : int ret;
1525 : : int ret_status = 0;
1526 : :
1527 : : struct comp_testsuite_params *ts_params = &testsuite_params;
1528 : :
1529 : : /* from test_data: */
1530 : 0 : enum rte_comp_op_type operation_type = test_data->decompress_state;
1531 : : unsigned int zlib_decompress =
1532 : 0 : (test_data->zlib_dir == ZLIB_ALL ||
1533 : : test_data->zlib_dir == ZLIB_DECOMPRESS);
1534 : :
1535 : : /* from int_data: */
1536 : 0 : struct rte_comp_xform **decompress_xforms = int_data->decompress_xforms;
1537 : 0 : unsigned int num_xforms = int_data->num_xforms;
1538 : 0 : unsigned int num_bufs = int_data->num_bufs;
1539 : :
1540 : : /* from test_priv_data: */
1541 : 0 : struct rte_mbuf **uncomp_bufs = test_priv_data->uncomp_bufs;
1542 : 0 : struct rte_mbuf **comp_bufs = test_priv_data->comp_bufs;
1543 : 0 : struct rte_comp_op **ops = test_priv_data->ops;
1544 : 0 : struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
1545 : 0 : void **priv_xforms = test_priv_data->priv_xforms;
1546 : 0 : uint32_t *compressed_data_size = test_priv_data->compressed_data_size;
1547 : 0 : void **stream = test_priv_data->stream;
1548 : :
1549 : : const struct rte_compressdev_capabilities *capa =
1550 : 0 : rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
1551 : :
1552 : 0 : ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
1553 [ # # ]: 0 : if (ret < 0) {
1554 : 0 : RTE_LOG(ERR, USER1,
1555 : : "Decompress operations could not be allocated "
1556 : : "from the mempool\n");
1557 : : ret_status = -1;
1558 : 0 : goto exit;
1559 : : }
1560 : :
1561 : : /* Source buffer is the compressed data from the previous operations */
1562 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1563 : 0 : ops[i]->m_src = comp_bufs[i];
1564 : 0 : ops[i]->m_dst = uncomp_bufs[i];
1565 : 0 : ops[i]->src.offset = 0;
1566 : : /*
1567 : : * Set the length of the compressed data to the
1568 : : * number of bytes that were produced in the previous stage
1569 : : */
1570 : :
1571 [ # # ]: 0 : if (compressed_data_size[i])
1572 : 0 : ops[i]->src.length = compressed_data_size[i];
1573 : : else
1574 : 0 : ops[i]->src.length = ops_processed[i]->produced;
1575 : :
1576 : 0 : ops[i]->dst.offset = 0;
1577 : :
1578 [ # # ]: 0 : if (operation_type == RTE_COMP_OP_STATELESS) {
1579 : 0 : ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
1580 : 0 : ops[i]->op_type = RTE_COMP_OP_STATELESS;
1581 [ # # ]: 0 : } else if (!zlib_decompress) {
1582 : 0 : ops[i]->flush_flag = RTE_COMP_FLUSH_SYNC;
1583 : 0 : ops[i]->op_type = RTE_COMP_OP_STATEFUL;
1584 : : } else {
1585 : 0 : RTE_LOG(ERR, USER1,
1586 : : "Decompression: stateful operations are"
1587 : : " not supported in these tests yet\n");
1588 : : ret_status = -1;
1589 : 0 : goto exit;
1590 : : }
1591 : 0 : ops[i]->input_chksum = 0;
1592 : : /*
1593 : : * Copy private data from previous operations,
1594 : : * to keep the pointer to the original buffer
1595 : : */
1596 : 0 : memcpy(ops[i] + 1, ops_processed[i] + 1,
1597 : : sizeof(struct priv_op_data));
1598 : : }
1599 : :
1600 : : /*
1601 : : * Free the previous compress operations,
1602 : : * as they are not needed anymore
1603 : : */
1604 : 0 : rte_comp_op_bulk_free(ops_processed, num_bufs);
1605 : :
1606 : : /* Decompress data (either with Zlib API or compressdev API */
1607 [ # # ]: 0 : if (zlib_decompress) {
1608 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1609 : 0 : priv_data = (struct priv_op_data *)(ops[i] + 1);
1610 : 0 : uint16_t xform_idx = priv_data->orig_idx % num_xforms;
1611 : 0 : const struct rte_comp_xform *decompress_xform =
1612 : 0 : decompress_xforms[xform_idx];
1613 : :
1614 : 0 : ret = decompress_zlib(ops[i], decompress_xform);
1615 [ # # ]: 0 : if (ret < 0) {
1616 : : ret_status = -1;
1617 : 0 : goto exit;
1618 : : }
1619 : :
1620 : 0 : ops_processed[i] = ops[i];
1621 : : }
1622 : : } else {
1623 [ # # ]: 0 : if (operation_type == RTE_COMP_OP_STATELESS) {
1624 : : /* Create decompress private xform data */
1625 [ # # ]: 0 : for (i = 0; i < num_xforms; i++) {
1626 : 0 : ret = rte_compressdev_private_xform_create(0,
1627 : : (const struct rte_comp_xform *)
1628 : 0 : decompress_xforms[i],
1629 : 0 : &priv_xforms[i]);
1630 [ # # ]: 0 : if (ret < 0) {
1631 : 0 : RTE_LOG(ERR, USER1,
1632 : : "Decompression private xform "
1633 : : "could not be created\n");
1634 : : ret_status = -1;
1635 : 0 : goto exit;
1636 : : }
1637 : 0 : num_priv_xforms++;
1638 : : }
1639 : :
1640 [ # # ]: 0 : if (capa->comp_feature_flags &
1641 : : RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
1642 : : /* Attach shareable private xform data to ops */
1643 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1644 : : priv_data = (struct priv_op_data *)
1645 : 0 : (ops[i] + 1);
1646 : : uint16_t xform_idx =
1647 : 0 : priv_data->orig_idx % num_xforms;
1648 : 0 : ops[i]->private_xform =
1649 : 0 : priv_xforms[xform_idx];
1650 : : }
1651 : : } else {
1652 : : /* Create rest of the private xforms */
1653 : : /* for the other ops */
1654 [ # # ]: 0 : for (i = num_xforms; i < num_bufs; i++) {
1655 : : ret =
1656 : 0 : rte_compressdev_private_xform_create(0,
1657 : 0 : decompress_xforms[i % num_xforms],
1658 : 0 : &priv_xforms[i]);
1659 [ # # ]: 0 : if (ret < 0) {
1660 : 0 : RTE_LOG(ERR, USER1,
1661 : : "Decompression private xform"
1662 : : " could not be created\n");
1663 : : ret_status = -1;
1664 : 0 : goto exit;
1665 : : }
1666 : 0 : num_priv_xforms++;
1667 : : }
1668 : :
1669 : : /* Attach non shareable private xform data */
1670 : : /* to ops */
1671 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1672 : : priv_data = (struct priv_op_data *)
1673 : 0 : (ops[i] + 1);
1674 : 0 : uint16_t xform_idx =
1675 : : priv_data->orig_idx;
1676 : 0 : ops[i]->private_xform =
1677 : 0 : priv_xforms[xform_idx];
1678 : : }
1679 : : }
1680 : : } else {
1681 : : /* Create a stream object for stateful decompression */
1682 : 0 : ret = rte_compressdev_stream_create(0,
1683 : : decompress_xforms[0], stream);
1684 [ # # ]: 0 : if (ret < 0) {
1685 : 0 : RTE_LOG(ERR, USER1,
1686 : : "Decompression stream could not be created, error %d\n",
1687 : : ret);
1688 : : ret_status = -1;
1689 : 0 : goto exit;
1690 : : }
1691 : : /* Attach stream to ops */
1692 [ # # ]: 0 : for (i = 0; i < num_bufs; i++)
1693 : 0 : ops[i]->stream = *stream;
1694 : : }
1695 : :
1696 : 0 : test_priv_data->num_priv_xforms = num_priv_xforms;
1697 : : }
1698 : :
1699 : 0 : exit:
1700 : 0 : return ret_status;
1701 : : }
1702 : :
1703 : : /**
1704 : : * Prints out the test report. Memory freeing.
1705 : : *
1706 : : * Called after successful decompression.
1707 : : * Operation(s) status validation and compression buffers freeing.
1708 : :
1709 : : * -1 returned if function fail.
1710 : : *
1711 : : * @param int_data
1712 : : * Interim data containing session/transformation objects.
1713 : : * @param test_data
1714 : : * The test parameters set by users (command line parameters).
1715 : : * @param test_priv_data
1716 : : * A container used for aggregation all the private test arrays.
1717 : : * @return
1718 : : * - 2: Next step must be executed by the caller (stateful decompression only)
1719 : : * - 1: On success (caller should stop and exit)
1720 : : * - 0: On success.
1721 : : * - -1: On error.
1722 : : */
1723 : : static int
1724 : 0 : test_deflate_decomp_finalize(const struct interim_data_params *int_data,
1725 : : const struct test_data_params *test_data,
1726 : : const struct test_private_arrays *test_priv_data)
1727 : : {
1728 : : /* local variables: */
1729 : : unsigned int i;
1730 : : struct priv_op_data *priv_data;
1731 : : static unsigned int step;
1732 : :
1733 : : /* from int_data: */
1734 : 0 : unsigned int num_bufs = int_data->num_bufs;
1735 : 0 : const char * const *test_bufs = int_data->test_bufs;
1736 : 0 : struct rte_comp_xform **compress_xforms = int_data->compress_xforms;
1737 : :
1738 : : /* from test_priv_data: */
1739 : 0 : struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
1740 : 0 : struct rte_mbuf **comp_bufs = test_priv_data->comp_bufs;
1741 : 0 : struct rte_comp_op **ops = test_priv_data->ops;
1742 : 0 : uint64_t *compress_checksum = test_priv_data->compress_checksum;
1743 : 0 : unsigned int *decomp_produced_data_size =
1744 : : test_priv_data->decomp_produced_data_size;
1745 : 0 : char **all_decomp_data = test_priv_data->all_decomp_data;
1746 : :
1747 : : /* from test_data: */
1748 : 0 : unsigned int out_of_space = test_data->out_of_space;
1749 : 0 : enum rte_comp_op_type operation_type = test_data->decompress_state;
1750 : :
1751 : : unsigned int zlib_compress =
1752 : 0 : (test_data->zlib_dir == ZLIB_ALL ||
1753 : : test_data->zlib_dir == ZLIB_COMPRESS);
1754 : : unsigned int zlib_decompress =
1755 : 0 : (test_data->zlib_dir == ZLIB_ALL ||
1756 : : test_data->zlib_dir == ZLIB_DECOMPRESS);
1757 : :
1758 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1759 : 0 : priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
1760 : 0 : char engine[] = "zlib, (directly, no PMD)";
1761 [ # # ]: 0 : if (zlib_compress)
1762 : : strlcpy(engine, "pmd", sizeof(engine));
1763 : 0 : RTE_LOG(DEBUG, USER1,
1764 : : "Buffer %u decompressed by %s from %u to %u bytes\n",
1765 : : i, engine,
1766 : : ops_processed[i]->consumed, ops_processed[i]->produced);
1767 : 0 : ops[i] = NULL;
1768 : : }
1769 : :
1770 : : /*
1771 : : * Check operation status and free source mbuf (destination mbuf and
1772 : : * compress operation information is still needed)
1773 : : */
1774 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1775 [ # # ]: 0 : if (out_of_space && !zlib_decompress) {
1776 [ # # ]: 0 : if (ops_processed[i]->status !=
1777 : : RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED) {
1778 : :
1779 : 0 : RTE_LOG(ERR, USER1,
1780 : : "Operation without expected out of "
1781 : : "space status error\n");
1782 : 0 : return -1;
1783 : : } else
1784 : 0 : continue;
1785 : : }
1786 : :
1787 [ # # ]: 0 : if (operation_type == RTE_COMP_OP_STATEFUL
1788 : 0 : && (ops_processed[i]->status ==
1789 : : RTE_COMP_OP_STATUS_OUT_OF_SPACE_RECOVERABLE
1790 [ # # ]: 0 : || ops_processed[i]->status ==
1791 : : RTE_COMP_OP_STATUS_SUCCESS)) {
1792 : :
1793 : 0 : RTE_LOG(DEBUG, USER1,
1794 : : ".............RECOVERABLE\n");
1795 : :
1796 : : /* collect the output into all_decomp_data */
1797 : 0 : const void *ptr = rte_pktmbuf_read(
1798 : 0 : ops_processed[i]->m_dst,
1799 : : ops_processed[i]->dst.offset,
1800 : 0 : ops_processed[i]->produced,
1801 : 0 : *all_decomp_data +
1802 [ # # ]: 0 : *decomp_produced_data_size);
1803 : 0 : if (ptr != *all_decomp_data +
1804 [ # # ]: 0 : *decomp_produced_data_size)
1805 : 0 : rte_memcpy(*all_decomp_data +
1806 : : *decomp_produced_data_size,
1807 [ # # ]: 0 : ptr, ops_processed[i]->produced);
1808 : :
1809 : 0 : *decomp_produced_data_size +=
1810 : 0 : ops_processed[i]->produced;
1811 : 0 : if (ops_processed[i]->src.length >
1812 [ # # ]: 0 : ops_processed[i]->consumed) {
1813 [ # # ]: 0 : if (ops_processed[i]->status ==
1814 : : RTE_COMP_OP_STATUS_SUCCESS) {
1815 : 0 : RTE_LOG(ERR, USER1,
1816 : : "Operation finished too early\n");
1817 : 0 : return -1;
1818 : : }
1819 : 0 : step++;
1820 [ # # ]: 0 : if (step >= test_data->decompress_steps_max) {
1821 : 0 : RTE_LOG(ERR, USER1,
1822 : : "Operation exceeded maximum steps\n");
1823 : 0 : return -1;
1824 : : }
1825 : 0 : ops[i] = ops_processed[i];
1826 : 0 : ops[i]->status =
1827 : : RTE_COMP_OP_STATUS_NOT_PROCESSED;
1828 : 0 : ops[i]->src.offset +=
1829 : 0 : ops_processed[i]->consumed;
1830 : 0 : ops[i]->src.length -=
1831 : 0 : ops_processed[i]->consumed;
1832 : : /* repeat the operation */
1833 : 0 : return 2;
1834 : : } else {
1835 : : /* Compare the original stream with the */
1836 : : /* decompressed stream (in size and the data) */
1837 : : priv_data = (struct priv_op_data *)
1838 : : (ops_processed[i] + 1);
1839 : 0 : const char *buf1 =
1840 : 0 : test_bufs[priv_data->orig_idx];
1841 : 0 : const char *buf2 = *all_decomp_data;
1842 : :
1843 [ # # ]: 0 : if (compare_buffers(buf1, strlen(buf1) + 1,
1844 : : buf2, *decomp_produced_data_size) < 0)
1845 : : return -1;
1846 : : /* Test checksums */
1847 [ # # ]: 0 : if (compress_xforms[0]->compress.chksum
1848 : : != RTE_COMP_CHECKSUM_NONE) {
1849 : 0 : if (ops_processed[i]->output_chksum
1850 [ # # ]: 0 : != compress_checksum[i]) {
1851 : 0 : RTE_LOG(ERR, USER1,
1852 : : "The checksums differ\n"
1853 : : "Compression Checksum: %" PRIu64 "\tDecompression "
1854 : : "Checksum: %" PRIu64 "\n", compress_checksum[i],
1855 : : ops_processed[i]->output_chksum);
1856 : 0 : return -1;
1857 : : }
1858 : : }
1859 : : }
1860 [ # # ]: 0 : } else if (ops_processed[i]->status !=
1861 : : RTE_COMP_OP_STATUS_SUCCESS) {
1862 : 0 : RTE_LOG(ERR, USER1,
1863 : : "Decomp: Some operations were not successful, status = %u\n",
1864 : : ops_processed[i]->status);
1865 : 0 : return -1;
1866 : : }
1867 : 0 : priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
1868 : 0 : rte_pktmbuf_free(comp_bufs[priv_data->orig_idx]);
1869 : 0 : comp_bufs[priv_data->orig_idx] = NULL;
1870 : : }
1871 : :
1872 [ # # ]: 0 : if (out_of_space && !zlib_decompress)
1873 : 0 : return 1;
1874 : :
1875 : : return 0;
1876 : : }
1877 : :
1878 : : /**
1879 : : * Validation of the output (compression/decompression) data.
1880 : : *
1881 : : * The function compares the source stream with the output stream,
1882 : : * after decompression, to check if compression/decompression
1883 : : * was correct.
1884 : : * -1 returned if function fail.
1885 : : *
1886 : : * @param int_data
1887 : : * Interim data containing session/transformation objects.
1888 : : * @param test_data
1889 : : * The test parameters set by users (command line parameters).
1890 : : * @param test_priv_data
1891 : : * A container used for aggregation all the private test arrays.
1892 : : * @return
1893 : : * - 0: On success.
1894 : : * - -1: On error.
1895 : : */
1896 : : static int
1897 : 0 : test_results_validation(const struct interim_data_params *int_data,
1898 : : const struct test_data_params *test_data,
1899 : : const struct test_private_arrays *test_priv_data)
1900 : : {
1901 : : /* local variables: */
1902 : : unsigned int i;
1903 : : struct priv_op_data *priv_data;
1904 : : const char *buf1;
1905 : : const char *buf2;
1906 : : char *contig_buf = NULL;
1907 : : uint32_t data_size;
1908 : :
1909 : : /* from int_data: */
1910 : 0 : struct rte_comp_xform **compress_xforms = int_data->compress_xforms;
1911 : 0 : unsigned int num_bufs = int_data->num_bufs;
1912 : 0 : const char * const *test_bufs = int_data->test_bufs;
1913 : :
1914 : : /* from test_priv_data: */
1915 : 0 : uint64_t *compress_checksum = test_priv_data->compress_checksum;
1916 : 0 : struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
1917 : :
1918 : : /*
1919 : : * Compare the original stream with the decompressed stream
1920 : : * (in size and the data)
1921 : : */
1922 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
1923 : 0 : priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
1924 : 0 : buf1 = test_data->use_external_mbufs ?
1925 [ # # ]: 0 : test_data->inbuf_memzone->addr :
1926 : 0 : test_bufs[priv_data->orig_idx];
1927 [ # # ]: 0 : data_size = test_data->use_external_mbufs ?
1928 : : test_data->inbuf_data_size :
1929 : 0 : strlen(buf1) + 1;
1930 : :
1931 : 0 : contig_buf = rte_malloc(NULL, ops_processed[i]->produced, 0);
1932 [ # # ]: 0 : if (contig_buf == NULL) {
1933 : 0 : RTE_LOG(ERR, USER1, "Contiguous buffer could not "
1934 : : "be allocated\n");
1935 : 0 : goto exit;
1936 : : }
1937 : :
1938 : 0 : buf2 = rte_pktmbuf_read(ops_processed[i]->m_dst, 0,
1939 [ # # ]: 0 : ops_processed[i]->produced, contig_buf);
1940 [ # # ]: 0 : if (compare_buffers(buf1, data_size,
1941 : 0 : buf2, ops_processed[i]->produced) < 0)
1942 : 0 : goto exit;
1943 : :
1944 : : /* Test checksums */
1945 [ # # ]: 0 : if (compress_xforms[0]->compress.chksum !=
1946 : : RTE_COMP_CHECKSUM_NONE) {
1947 : 0 : if (ops_processed[i]->output_chksum !=
1948 [ # # ]: 0 : compress_checksum[i]) {
1949 : 0 : RTE_LOG(ERR, USER1, "The checksums differ\n"
1950 : : "Compression Checksum: %" PRIu64 "\tDecompression "
1951 : : "Checksum: %" PRIu64 "\n", compress_checksum[i],
1952 : : ops_processed[i]->output_chksum);
1953 : 0 : goto exit;
1954 : : }
1955 : : }
1956 : :
1957 : 0 : rte_free(contig_buf);
1958 : : contig_buf = NULL;
1959 : : }
1960 : : return 0;
1961 : :
1962 : 0 : exit:
1963 : 0 : rte_free(contig_buf);
1964 : 0 : return -1;
1965 : : }
1966 : :
1967 : : /**
1968 : : * Compresses and decompresses input stream with compressdev API and Zlib API
1969 : : *
1970 : : * Basic test function. Common for all the functional tests.
1971 : : * -1 returned if function fail.
1972 : : *
1973 : : * @param int_data
1974 : : * Interim data containing session/transformation objects.
1975 : : * @param test_data
1976 : : * The test parameters set by users (command line parameters).
1977 : : * @return
1978 : : * - 1: Some operation not supported
1979 : : * - 0: On success.
1980 : : * - -1: On error.
1981 : : */
1982 : :
1983 : : static int
1984 : 0 : test_deflate_comp_decomp(const struct interim_data_params *int_data,
1985 : : const struct test_data_params *test_data)
1986 : 0 : {
1987 : 0 : unsigned int num_bufs = int_data->num_bufs;
1988 : 0 : unsigned int out_of_space = test_data->out_of_space;
1989 : :
1990 : 0 : void *stream = NULL;
1991 : 0 : char *all_decomp_data = NULL;
1992 : 0 : unsigned int decomp_produced_data_size = 0;
1993 : :
1994 : : int ret_status = -1;
1995 : : int ret;
1996 : 0 : struct rte_mbuf *uncomp_bufs[num_bufs];
1997 : 0 : struct rte_mbuf *comp_bufs[num_bufs];
1998 : 0 : struct rte_comp_op *ops[num_bufs];
1999 : 0 : struct rte_comp_op *ops_processed[num_bufs];
2000 : 0 : void *priv_xforms[num_bufs];
2001 : : unsigned int i;
2002 : :
2003 : 0 : uint64_t compress_checksum[num_bufs];
2004 : 0 : uint32_t compressed_data_size[num_bufs];
2005 : : char *contig_buf = NULL;
2006 : :
2007 : : struct rte_mbuf_ext_shared_info compbuf_info;
2008 : : struct rte_mbuf_ext_shared_info decompbuf_info;
2009 : :
2010 : : const struct rte_compressdev_capabilities *capa;
2011 : :
2012 : : /* Compressing with CompressDev */
2013 : : unsigned int zlib_compress =
2014 : 0 : (test_data->zlib_dir == ZLIB_ALL ||
2015 : : test_data->zlib_dir == ZLIB_COMPRESS);
2016 : : unsigned int zlib_decompress =
2017 : 0 : (test_data->zlib_dir == ZLIB_ALL ||
2018 : : test_data->zlib_dir == ZLIB_DECOMPRESS);
2019 : :
2020 : : struct test_private_arrays test_priv_data;
2021 : :
2022 : 0 : test_priv_data.uncomp_bufs = uncomp_bufs;
2023 : 0 : test_priv_data.comp_bufs = comp_bufs;
2024 : 0 : test_priv_data.ops = ops;
2025 : 0 : test_priv_data.ops_processed = ops_processed;
2026 : 0 : test_priv_data.priv_xforms = priv_xforms;
2027 : 0 : test_priv_data.compress_checksum = compress_checksum;
2028 : 0 : test_priv_data.compressed_data_size = compressed_data_size;
2029 : :
2030 : 0 : test_priv_data.stream = &stream;
2031 : 0 : test_priv_data.all_decomp_data = &all_decomp_data;
2032 : 0 : test_priv_data.decomp_produced_data_size = &decomp_produced_data_size;
2033 : :
2034 : 0 : test_priv_data.num_priv_xforms = 0; /* it's used for decompression only */
2035 : :
2036 : 0 : capa = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
2037 [ # # ]: 0 : if (capa == NULL) {
2038 : 0 : RTE_LOG(ERR, USER1,
2039 : : "Compress device does not support DEFLATE\n");
2040 : 0 : return -1;
2041 : : }
2042 : :
2043 : : /* Prepare the source mbufs with the data */
2044 : 0 : ret = test_setup_com_bufs(int_data, test_data, &test_priv_data);
2045 [ # # ]: 0 : if (ret < 0) {
2046 : : ret_status = -1;
2047 : 0 : goto exit;
2048 : : }
2049 : :
2050 : 0 : RTE_LOG(DEBUG, USER1, "<<< COMPRESSION >>>\n");
2051 : :
2052 : : /* COMPRESSION */
2053 : :
2054 : : /* Prepare output (destination) mbufs for compressed data */
2055 : 0 : ret = test_setup_output_bufs(
2056 : : OPERATION_COMPRESSION,
2057 : 0 : out_of_space == 1 && !zlib_compress,
2058 : : &test_priv_data,
2059 : : int_data,
2060 : : test_data,
2061 : : &compbuf_info);
2062 [ # # ]: 0 : if (ret < 0) {
2063 : : ret_status = -1;
2064 : 0 : goto exit;
2065 : : }
2066 : :
2067 : : /* Run compression */
2068 : 0 : ret = test_deflate_comp_run(int_data, test_data, &test_priv_data);
2069 [ # # ]: 0 : if (ret < 0) {
2070 : : ret_status = -1;
2071 : 0 : goto exit;
2072 : : }
2073 : :
2074 : 0 : ret = test_deflate_comp_finalize(int_data, test_data, &test_priv_data);
2075 [ # # ]: 0 : if (ret < 0) {
2076 : : ret_status = -1;
2077 : 0 : goto exit;
2078 [ # # ]: 0 : } else if (ret == 1) {
2079 : : ret_status = 0;
2080 : 0 : goto exit;
2081 [ # # ]: 0 : } else if (ret == 2) {
2082 : : ret_status = 1; /* some operation not supported */
2083 : 0 : goto exit;
2084 : : }
2085 : :
2086 : : /* DECOMPRESSION */
2087 : :
2088 : 0 : RTE_LOG(DEBUG, USER1, "<<< DECOMPRESSION >>>\n");
2089 : :
2090 : : /* Prepare output (destination) mbufs for decompressed data */
2091 : 0 : ret = test_setup_output_bufs(
2092 : : OPERATION_DECOMPRESSION,
2093 : 0 : out_of_space == 1 && !zlib_decompress,
2094 : : &test_priv_data,
2095 : : int_data,
2096 : : test_data,
2097 : : &decompbuf_info);
2098 [ # # ]: 0 : if (ret < 0) {
2099 : : ret_status = -1;
2100 : 0 : goto exit;
2101 : : }
2102 : :
2103 : : /* Run decompression */
2104 : 0 : ret = test_deflate_decomp_run(int_data, test_data, &test_priv_data);
2105 [ # # ]: 0 : if (ret < 0) {
2106 : : ret_status = -1;
2107 : 0 : goto exit;
2108 : : }
2109 : :
2110 [ # # ]: 0 : if (!zlib_decompress) {
2111 : 0 : next_step: /* next step for stateful decompression only */
2112 : 0 : ret = test_run_enqueue_dequeue(ops, ops_processed, num_bufs);
2113 [ # # ]: 0 : if (ret < 0) {
2114 : : ret_status = -1;
2115 : 0 : RTE_LOG(ERR, USER1,
2116 : : "Decompression: enqueue/dequeue operation failed\n");
2117 : : }
2118 : : }
2119 : :
2120 : 0 : ret = test_deflate_decomp_finalize(int_data, test_data, &test_priv_data);
2121 [ # # ]: 0 : if (ret < 0) {
2122 : : ret_status = -1;
2123 : 0 : goto exit;
2124 [ # # ]: 0 : } else if (ret == 1) {
2125 : : ret_status = 0;
2126 : 0 : goto exit;
2127 [ # # ]: 0 : } else if (ret == 2) {
2128 : 0 : goto next_step;
2129 : : }
2130 : :
2131 : : /* FINAL PROCESSING */
2132 : :
2133 : 0 : ret = test_results_validation(int_data, test_data, &test_priv_data);
2134 [ # # ]: 0 : if (ret < 0) {
2135 : : ret_status = -1;
2136 : 0 : goto exit;
2137 : : }
2138 : : ret_status = 0;
2139 : :
2140 : 0 : exit:
2141 : : /* Free resources */
2142 : :
2143 [ # # ]: 0 : if (stream != NULL)
2144 : 0 : rte_compressdev_stream_free(0, stream);
2145 : 0 : rte_free(all_decomp_data);
2146 : :
2147 : : /* Free compress private xforms */
2148 [ # # ]: 0 : for (i = 0; i < test_priv_data.num_priv_xforms; i++) {
2149 [ # # ]: 0 : if (priv_xforms[i] != NULL) {
2150 : 0 : rte_compressdev_private_xform_free(0, priv_xforms[i]);
2151 : 0 : priv_xforms[i] = NULL;
2152 : : }
2153 : : }
2154 [ # # ]: 0 : for (i = 0; i < num_bufs; i++) {
2155 : 0 : rte_pktmbuf_free(uncomp_bufs[i]);
2156 : 0 : rte_pktmbuf_free(comp_bufs[i]);
2157 : 0 : rte_comp_op_free(ops[i]);
2158 : 0 : rte_comp_op_free(ops_processed[i]);
2159 : : }
2160 : 0 : rte_free(contig_buf);
2161 : :
2162 : 0 : return ret_status;
2163 : : }
2164 : :
2165 : : static int
2166 : 0 : test_compressdev_deflate_stateless_fixed(void)
2167 : : {
2168 : : struct comp_testsuite_params *ts_params = &testsuite_params;
2169 : : uint16_t i;
2170 : : int ret;
2171 : : const struct rte_compressdev_capabilities *capab;
2172 : :
2173 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
2174 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
2175 : :
2176 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0)
2177 : : return -ENOTSUP;
2178 : :
2179 : 0 : struct rte_comp_xform *compress_xform =
2180 : 0 : rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
2181 : :
2182 [ # # ]: 0 : if (compress_xform == NULL) {
2183 : 0 : RTE_LOG(ERR, USER1,
2184 : : "Compress xform could not be created\n");
2185 : : ret = TEST_FAILED;
2186 : 0 : goto exit;
2187 : : }
2188 : :
2189 : 0 : *compress_xform = *ts_params->def_comp_xform;
2190 : 0 : compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
2191 : :
2192 : 0 : struct interim_data_params int_data = {
2193 : : NULL,
2194 : : 1,
2195 : : NULL,
2196 : : &compress_xform,
2197 : : &ts_params->def_decomp_xform,
2198 : : 1
2199 : : };
2200 : :
2201 : 0 : struct test_data_params test_data = {
2202 : : .compress_state = RTE_COMP_OP_STATELESS,
2203 : : .decompress_state = RTE_COMP_OP_STATELESS,
2204 : : .buff_type = LB_BOTH,
2205 : : .zlib_dir = ZLIB_DECOMPRESS,
2206 : : .out_of_space = 0,
2207 : : .big_data = 0,
2208 : : .overflow = OVERFLOW_DISABLED,
2209 : : .ratio = RATIO_ENABLED
2210 : : };
2211 : :
2212 [ # # ]: 0 : for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
2213 : 0 : int_data.test_bufs = &compress_test_bufs[i];
2214 : 0 : int_data.buf_idx = &i;
2215 : :
2216 : : /* Compress with compressdev, decompress with Zlib */
2217 : 0 : test_data.zlib_dir = ZLIB_DECOMPRESS;
2218 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2219 [ # # ]: 0 : if (ret < 0)
2220 : 0 : goto exit;
2221 : :
2222 : : /* Compress with Zlib, decompress with compressdev */
2223 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
2224 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2225 [ # # ]: 0 : if (ret < 0)
2226 : 0 : goto exit;
2227 : : }
2228 : :
2229 : : ret = TEST_SUCCESS;
2230 : :
2231 : 0 : exit:
2232 : 0 : rte_free(compress_xform);
2233 : 0 : return ret;
2234 : : }
2235 : :
2236 : : static int
2237 : 0 : test_compressdev_deflate_stateless_dynamic(void)
2238 : : {
2239 : : struct comp_testsuite_params *ts_params = &testsuite_params;
2240 : : uint16_t i;
2241 : : int ret;
2242 : 0 : struct rte_comp_xform *compress_xform =
2243 : 0 : rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
2244 : :
2245 : : const struct rte_compressdev_capabilities *capab;
2246 : :
2247 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
2248 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
2249 : :
2250 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
2251 : : return -ENOTSUP;
2252 : :
2253 [ # # ]: 0 : if (compress_xform == NULL) {
2254 : 0 : RTE_LOG(ERR, USER1,
2255 : : "Compress xform could not be created\n");
2256 : : ret = TEST_FAILED;
2257 : 0 : goto exit;
2258 : : }
2259 : :
2260 : 0 : *compress_xform = *ts_params->def_comp_xform;
2261 : 0 : compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
2262 : :
2263 : 0 : struct interim_data_params int_data = {
2264 : : NULL,
2265 : : 1,
2266 : : NULL,
2267 : : &compress_xform,
2268 : : &ts_params->def_decomp_xform,
2269 : : 1
2270 : : };
2271 : :
2272 : 0 : struct test_data_params test_data = {
2273 : : .compress_state = RTE_COMP_OP_STATELESS,
2274 : : .decompress_state = RTE_COMP_OP_STATELESS,
2275 : : .buff_type = LB_BOTH,
2276 : : .zlib_dir = ZLIB_DECOMPRESS,
2277 : : .out_of_space = 0,
2278 : : .big_data = 0,
2279 : : .overflow = OVERFLOW_DISABLED,
2280 : : .ratio = RATIO_ENABLED
2281 : : };
2282 : :
2283 [ # # ]: 0 : for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
2284 : 0 : int_data.test_bufs = &compress_test_bufs[i];
2285 : 0 : int_data.buf_idx = &i;
2286 : :
2287 : : /* Compress with compressdev, decompress with Zlib */
2288 : 0 : test_data.zlib_dir = ZLIB_DECOMPRESS;
2289 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2290 [ # # ]: 0 : if (ret < 0)
2291 : 0 : goto exit;
2292 : :
2293 : : /* Compress with Zlib, decompress with compressdev */
2294 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
2295 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2296 [ # # ]: 0 : if (ret < 0)
2297 : 0 : goto exit;
2298 : : }
2299 : :
2300 : : ret = TEST_SUCCESS;
2301 : :
2302 : 0 : exit:
2303 : 0 : rte_free(compress_xform);
2304 : 0 : return ret;
2305 : : }
2306 : :
2307 : : static int
2308 : 0 : test_compressdev_deflate_stateless_multi_op(void)
2309 : 0 : {
2310 : : struct comp_testsuite_params *ts_params = &testsuite_params;
2311 : : uint16_t num_bufs = RTE_DIM(compress_test_bufs);
2312 : : uint16_t buf_idx[num_bufs];
2313 : : uint16_t i;
2314 : : int ret;
2315 : :
2316 [ # # ]: 0 : for (i = 0; i < num_bufs; i++)
2317 : 0 : buf_idx[i] = i;
2318 : :
2319 : 0 : struct interim_data_params int_data = {
2320 : : compress_test_bufs,
2321 : : num_bufs,
2322 : : buf_idx,
2323 : : &ts_params->def_comp_xform,
2324 : : &ts_params->def_decomp_xform,
2325 : : 1
2326 : : };
2327 : :
2328 : 0 : struct test_data_params test_data = {
2329 : : .compress_state = RTE_COMP_OP_STATELESS,
2330 : : .decompress_state = RTE_COMP_OP_STATELESS,
2331 : : .buff_type = LB_BOTH,
2332 : : .zlib_dir = ZLIB_DECOMPRESS,
2333 : : .out_of_space = 0,
2334 : : .big_data = 0,
2335 : : .overflow = OVERFLOW_DISABLED,
2336 : : .ratio = RATIO_ENABLED
2337 : : };
2338 : :
2339 : : /* Compress with compressdev, decompress with Zlib */
2340 : : test_data.zlib_dir = ZLIB_DECOMPRESS;
2341 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2342 [ # # ]: 0 : if (ret < 0)
2343 : : return ret;
2344 : :
2345 : : /* Compress with Zlib, decompress with compressdev */
2346 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
2347 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2348 : : if (ret < 0)
2349 : : return ret;
2350 : :
2351 : : return TEST_SUCCESS;
2352 : : }
2353 : :
2354 : : static int
2355 : 0 : test_compressdev_deflate_stateless_multi_level(void)
2356 : : {
2357 : : struct comp_testsuite_params *ts_params = &testsuite_params;
2358 : : unsigned int level;
2359 : : uint16_t i;
2360 : : int ret;
2361 : 0 : struct rte_comp_xform *compress_xform =
2362 : 0 : rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
2363 : :
2364 [ # # ]: 0 : if (compress_xform == NULL) {
2365 : 0 : RTE_LOG(ERR, USER1,
2366 : : "Compress xform could not be created\n");
2367 : : ret = TEST_FAILED;
2368 : 0 : goto exit;
2369 : : }
2370 : :
2371 : 0 : *compress_xform = *ts_params->def_comp_xform;
2372 : :
2373 : 0 : struct interim_data_params int_data = {
2374 : : NULL,
2375 : : 1,
2376 : : NULL,
2377 : : &compress_xform,
2378 : : &ts_params->def_decomp_xform,
2379 : : 1
2380 : : };
2381 : :
2382 : 0 : struct test_data_params test_data = {
2383 : : .compress_state = RTE_COMP_OP_STATELESS,
2384 : : .decompress_state = RTE_COMP_OP_STATELESS,
2385 : : .buff_type = LB_BOTH,
2386 : : .zlib_dir = ZLIB_DECOMPRESS,
2387 : : .out_of_space = 0,
2388 : : .big_data = 0,
2389 : : .overflow = OVERFLOW_DISABLED,
2390 : : .ratio = RATIO_ENABLED
2391 : : };
2392 : :
2393 [ # # ]: 0 : for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
2394 : 0 : int_data.test_bufs = &compress_test_bufs[i];
2395 : 0 : int_data.buf_idx = &i;
2396 : :
2397 [ # # ]: 0 : for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
2398 : 0 : level++) {
2399 : 0 : compress_xform->compress.level = level;
2400 : : /* Compress with compressdev, decompress with Zlib */
2401 : 0 : test_data.zlib_dir = ZLIB_DECOMPRESS;
2402 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2403 [ # # ]: 0 : if (ret < 0)
2404 : 0 : goto exit;
2405 : : }
2406 : : }
2407 : :
2408 : : ret = TEST_SUCCESS;
2409 : :
2410 : 0 : exit:
2411 : 0 : rte_free(compress_xform);
2412 : 0 : return ret;
2413 : : }
2414 : :
2415 : : #define NUM_XFORMS 3
2416 : : static int
2417 : 0 : test_compressdev_deflate_stateless_multi_xform(void)
2418 : 0 : {
2419 : : struct comp_testsuite_params *ts_params = &testsuite_params;
2420 : : uint16_t num_bufs = NUM_XFORMS;
2421 : 0 : struct rte_comp_xform *compress_xforms[NUM_XFORMS] = {NULL};
2422 : 0 : struct rte_comp_xform *decompress_xforms[NUM_XFORMS] = {NULL};
2423 : : const char *test_buffers[NUM_XFORMS];
2424 : : uint16_t i;
2425 : : unsigned int level = RTE_COMP_LEVEL_MIN;
2426 : : uint16_t buf_idx[num_bufs];
2427 : : int ret;
2428 : :
2429 : : /* Create multiple xforms with various levels */
2430 [ # # ]: 0 : for (i = 0; i < NUM_XFORMS; i++) {
2431 : 0 : compress_xforms[i] = rte_malloc(NULL,
2432 : : sizeof(struct rte_comp_xform), 0);
2433 [ # # ]: 0 : if (compress_xforms[i] == NULL) {
2434 : 0 : RTE_LOG(ERR, USER1,
2435 : : "Compress xform could not be created\n");
2436 : : ret = TEST_FAILED;
2437 : 0 : goto exit;
2438 : : }
2439 : :
2440 : 0 : *compress_xforms[i] = *ts_params->def_comp_xform;
2441 : 0 : compress_xforms[i]->compress.level = level;
2442 : 0 : level++;
2443 : :
2444 : 0 : decompress_xforms[i] = rte_malloc(NULL,
2445 : : sizeof(struct rte_comp_xform), 0);
2446 [ # # ]: 0 : if (decompress_xforms[i] == NULL) {
2447 : 0 : RTE_LOG(ERR, USER1,
2448 : : "Decompress xform could not be created\n");
2449 : : ret = TEST_FAILED;
2450 : 0 : goto exit;
2451 : : }
2452 : :
2453 : 0 : *decompress_xforms[i] = *ts_params->def_decomp_xform;
2454 : : }
2455 : :
2456 [ # # ]: 0 : for (i = 0; i < NUM_XFORMS; i++) {
2457 : 0 : buf_idx[i] = 0;
2458 : : /* Use the same buffer in all sessions */
2459 : 0 : test_buffers[i] = compress_test_bufs[0];
2460 : : }
2461 : :
2462 : 0 : struct interim_data_params int_data = {
2463 : : test_buffers,
2464 : : num_bufs,
2465 : : buf_idx,
2466 : : compress_xforms,
2467 : : decompress_xforms,
2468 : : NUM_XFORMS
2469 : : };
2470 : :
2471 : 0 : struct test_data_params test_data = {
2472 : : .compress_state = RTE_COMP_OP_STATELESS,
2473 : : .decompress_state = RTE_COMP_OP_STATELESS,
2474 : : .buff_type = LB_BOTH,
2475 : : .zlib_dir = ZLIB_DECOMPRESS,
2476 : : .out_of_space = 0,
2477 : : .big_data = 0,
2478 : : .overflow = OVERFLOW_DISABLED,
2479 : : .ratio = RATIO_ENABLED
2480 : : };
2481 : :
2482 : : /* Compress with compressdev, decompress with Zlib */
2483 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2484 : : if (ret < 0)
2485 : : goto exit;
2486 : :
2487 : : ret = TEST_SUCCESS;
2488 : :
2489 : 0 : exit:
2490 [ # # ]: 0 : for (i = 0; i < NUM_XFORMS; i++) {
2491 : 0 : rte_free(compress_xforms[i]);
2492 : 0 : rte_free(decompress_xforms[i]);
2493 : : }
2494 : :
2495 : 0 : return ret;
2496 : : }
2497 : :
2498 : : static int
2499 : 0 : test_compressdev_deflate_stateless_sgl(void)
2500 : : {
2501 : : struct comp_testsuite_params *ts_params = &testsuite_params;
2502 : : uint16_t i;
2503 : : int ret;
2504 : : const struct rte_compressdev_capabilities *capab;
2505 : :
2506 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
2507 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
2508 : :
2509 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
2510 : : return -ENOTSUP;
2511 : :
2512 : 0 : struct interim_data_params int_data = {
2513 : : NULL,
2514 : : 1,
2515 : : NULL,
2516 : : &ts_params->def_comp_xform,
2517 : : &ts_params->def_decomp_xform,
2518 : : 1
2519 : : };
2520 : :
2521 : 0 : struct test_data_params test_data = {
2522 : : .compress_state = RTE_COMP_OP_STATELESS,
2523 : : .decompress_state = RTE_COMP_OP_STATELESS,
2524 : : .buff_type = SGL_BOTH,
2525 : : .zlib_dir = ZLIB_DECOMPRESS,
2526 : : .out_of_space = 0,
2527 : : .big_data = 0,
2528 : : .overflow = OVERFLOW_DISABLED,
2529 : : .ratio = RATIO_ENABLED
2530 : : };
2531 : :
2532 [ # # ]: 0 : for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
2533 : 0 : int_data.test_bufs = &compress_test_bufs[i];
2534 : 0 : int_data.buf_idx = &i;
2535 : :
2536 : : /* Compress with compressdev, decompress with Zlib */
2537 : 0 : test_data.zlib_dir = ZLIB_DECOMPRESS;
2538 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2539 [ # # ]: 0 : if (ret < 0)
2540 : 0 : return ret;
2541 : :
2542 : : /* Compress with Zlib, decompress with compressdev */
2543 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
2544 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2545 [ # # ]: 0 : if (ret < 0)
2546 : 0 : return ret;
2547 : :
2548 [ # # ]: 0 : if (capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_LB_OUT) {
2549 : : /* Compress with compressdev, decompress with Zlib */
2550 : 0 : test_data.zlib_dir = ZLIB_DECOMPRESS;
2551 : 0 : test_data.buff_type = SGL_TO_LB;
2552 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2553 [ # # ]: 0 : if (ret < 0)
2554 : 0 : return ret;
2555 : :
2556 : : /* Compress with Zlib, decompress with compressdev */
2557 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
2558 : 0 : test_data.buff_type = SGL_TO_LB;
2559 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2560 [ # # ]: 0 : if (ret < 0)
2561 : 0 : return ret;
2562 : : }
2563 : :
2564 [ # # ]: 0 : if (capab->comp_feature_flags & RTE_COMP_FF_OOP_LB_IN_SGL_OUT) {
2565 : : /* Compress with compressdev, decompress with Zlib */
2566 : 0 : test_data.zlib_dir = ZLIB_DECOMPRESS;
2567 : 0 : test_data.buff_type = LB_TO_SGL;
2568 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2569 [ # # ]: 0 : if (ret < 0)
2570 : 0 : return ret;
2571 : :
2572 : : /* Compress with Zlib, decompress with compressdev */
2573 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
2574 : 0 : test_data.buff_type = LB_TO_SGL;
2575 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2576 [ # # ]: 0 : if (ret < 0)
2577 : 0 : return ret;
2578 : : }
2579 : : }
2580 : :
2581 : : return TEST_SUCCESS;
2582 : : }
2583 : :
2584 : : static int
2585 : 0 : test_compressdev_deflate_stateless_checksum(void)
2586 : : {
2587 : : struct comp_testsuite_params *ts_params = &testsuite_params;
2588 : : uint16_t i;
2589 : : int ret;
2590 : : const struct rte_compressdev_capabilities *capab;
2591 : :
2592 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
2593 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
2594 : :
2595 : : /* Check if driver supports any checksum */
2596 : 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_CRC32_CHECKSUM) == 0 &&
2597 : : (capab->comp_feature_flags &
2598 [ # # ]: 0 : RTE_COMP_FF_ADLER32_CHECKSUM) == 0 &&
2599 : : (capab->comp_feature_flags &
2600 : : RTE_COMP_FF_CRC32_ADLER32_CHECKSUM) == 0)
2601 : : return -ENOTSUP;
2602 : :
2603 : 0 : struct rte_comp_xform *compress_xform =
2604 : 0 : rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
2605 [ # # ]: 0 : if (compress_xform == NULL) {
2606 : 0 : RTE_LOG(ERR, USER1, "Compress xform could not be created\n");
2607 : 0 : return TEST_FAILED;
2608 : : }
2609 : :
2610 : 0 : *compress_xform = *ts_params->def_comp_xform;
2611 : :
2612 : 0 : struct rte_comp_xform *decompress_xform =
2613 : 0 : rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
2614 [ # # ]: 0 : if (decompress_xform == NULL) {
2615 : 0 : RTE_LOG(ERR, USER1, "Decompress xform could not be created\n");
2616 : 0 : rte_free(compress_xform);
2617 : 0 : return TEST_FAILED;
2618 : : }
2619 : :
2620 : 0 : *decompress_xform = *ts_params->def_decomp_xform;
2621 : :
2622 : 0 : struct interim_data_params int_data = {
2623 : : NULL,
2624 : : 1,
2625 : : NULL,
2626 : : &compress_xform,
2627 : : &decompress_xform,
2628 : : 1
2629 : : };
2630 : :
2631 : 0 : struct test_data_params test_data = {
2632 : : .compress_state = RTE_COMP_OP_STATELESS,
2633 : : .decompress_state = RTE_COMP_OP_STATELESS,
2634 : : .buff_type = LB_BOTH,
2635 : : .zlib_dir = ZLIB_DECOMPRESS,
2636 : : .out_of_space = 0,
2637 : : .big_data = 0,
2638 : : .overflow = OVERFLOW_DISABLED,
2639 : : .ratio = RATIO_ENABLED
2640 : : };
2641 : :
2642 : : /* Check if driver supports crc32 checksum and test */
2643 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_CRC32_CHECKSUM)) {
2644 : 0 : compress_xform->compress.chksum = RTE_COMP_CHECKSUM_CRC32;
2645 : 0 : decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_CRC32;
2646 : :
2647 [ # # ]: 0 : for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
2648 : : /* Compress with compressdev, decompress with Zlib */
2649 : 0 : int_data.test_bufs = &compress_test_bufs[i];
2650 : 0 : int_data.buf_idx = &i;
2651 : :
2652 : : /* Generate zlib checksum and test against selected
2653 : : * drivers decompression checksum
2654 : : */
2655 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
2656 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2657 [ # # ]: 0 : if (ret < 0)
2658 : 0 : goto exit;
2659 : :
2660 : : /* Generate compression and decompression
2661 : : * checksum of selected driver
2662 : : */
2663 : 0 : test_data.zlib_dir = ZLIB_NONE;
2664 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2665 [ # # ]: 0 : if (ret < 0)
2666 : 0 : goto exit;
2667 : : }
2668 : : }
2669 : :
2670 : : /* Check if driver supports adler32 checksum and test */
2671 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_ADLER32_CHECKSUM)) {
2672 : 0 : compress_xform->compress.chksum = RTE_COMP_CHECKSUM_ADLER32;
2673 : 0 : decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_ADLER32;
2674 : :
2675 [ # # ]: 0 : for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
2676 : 0 : int_data.test_bufs = &compress_test_bufs[i];
2677 : 0 : int_data.buf_idx = &i;
2678 : :
2679 : : /* Generate zlib checksum and test against selected
2680 : : * drivers decompression checksum
2681 : : */
2682 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
2683 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2684 [ # # ]: 0 : if (ret < 0)
2685 : 0 : goto exit;
2686 : : /* Generate compression and decompression
2687 : : * checksum of selected driver
2688 : : */
2689 : 0 : test_data.zlib_dir = ZLIB_NONE;
2690 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2691 [ # # ]: 0 : if (ret < 0)
2692 : 0 : goto exit;
2693 : : }
2694 : : }
2695 : :
2696 : : /* Check if driver supports combined crc and adler checksum and test */
2697 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_CRC32_ADLER32_CHECKSUM)) {
2698 : 0 : compress_xform->compress.chksum =
2699 : : RTE_COMP_CHECKSUM_CRC32_ADLER32;
2700 : 0 : decompress_xform->decompress.chksum =
2701 : : RTE_COMP_CHECKSUM_CRC32_ADLER32;
2702 : :
2703 [ # # ]: 0 : for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
2704 : 0 : int_data.test_bufs = &compress_test_bufs[i];
2705 : 0 : int_data.buf_idx = &i;
2706 : :
2707 : : /* Generate compression and decompression
2708 : : * checksum of selected driver
2709 : : */
2710 : 0 : test_data.zlib_dir = ZLIB_NONE;
2711 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2712 [ # # ]: 0 : if (ret < 0)
2713 : 0 : goto exit;
2714 : : }
2715 : : }
2716 : :
2717 : : ret = TEST_SUCCESS;
2718 : :
2719 : 0 : exit:
2720 : 0 : rte_free(compress_xform);
2721 : 0 : rte_free(decompress_xform);
2722 : 0 : return ret;
2723 : : }
2724 : :
2725 : : static int
2726 : 0 : test_compressdev_out_of_space_buffer(void)
2727 : : {
2728 : : struct comp_testsuite_params *ts_params = &testsuite_params;
2729 : : int ret;
2730 : : uint16_t i;
2731 : : const struct rte_compressdev_capabilities *capab;
2732 : :
2733 : 0 : RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
2734 : :
2735 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
2736 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
2737 : :
2738 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0)
2739 : : return -ENOTSUP;
2740 : :
2741 : 0 : struct interim_data_params int_data = {
2742 : : &compress_test_bufs[0],
2743 : : 1,
2744 : : &i,
2745 : : &ts_params->def_comp_xform,
2746 : : &ts_params->def_decomp_xform,
2747 : : 1
2748 : : };
2749 : :
2750 : 0 : struct test_data_params test_data = {
2751 : : .compress_state = RTE_COMP_OP_STATELESS,
2752 : : .decompress_state = RTE_COMP_OP_STATELESS,
2753 : : .buff_type = LB_BOTH,
2754 : : .zlib_dir = ZLIB_DECOMPRESS,
2755 : : .out_of_space = 1, /* run out-of-space test */
2756 : : .big_data = 0,
2757 : : .overflow = OVERFLOW_DISABLED,
2758 : : .ratio = RATIO_ENABLED
2759 : : };
2760 : : /* Compress with compressdev, decompress with Zlib */
2761 : : test_data.zlib_dir = ZLIB_DECOMPRESS;
2762 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2763 [ # # ]: 0 : if (ret < 0)
2764 : 0 : goto exit;
2765 : :
2766 : : /* Compress with Zlib, decompress with compressdev */
2767 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
2768 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2769 [ # # ]: 0 : if (ret < 0)
2770 : 0 : goto exit;
2771 : :
2772 [ # # ]: 0 : if (capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
2773 : : /* Compress with compressdev, decompress with Zlib */
2774 : 0 : test_data.zlib_dir = ZLIB_DECOMPRESS;
2775 : 0 : test_data.buff_type = SGL_BOTH;
2776 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2777 [ # # ]: 0 : if (ret < 0)
2778 : 0 : goto exit;
2779 : :
2780 : : /* Compress with Zlib, decompress with compressdev */
2781 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
2782 : 0 : test_data.buff_type = SGL_BOTH;
2783 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2784 : : if (ret < 0)
2785 : : goto exit;
2786 : : }
2787 : :
2788 : : ret = TEST_SUCCESS;
2789 : :
2790 : : exit:
2791 : : return ret;
2792 : : }
2793 : :
2794 : : static int
2795 : 0 : test_compressdev_deflate_stateless_dynamic_big(void)
2796 : : {
2797 : : struct comp_testsuite_params *ts_params = &testsuite_params;
2798 : 0 : uint16_t i = 0;
2799 : : int ret;
2800 : : unsigned int j;
2801 : : const struct rte_compressdev_capabilities *capab;
2802 : 0 : char *test_buffer = NULL;
2803 : :
2804 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
2805 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
2806 : :
2807 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
2808 : : return -ENOTSUP;
2809 : :
2810 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
2811 : : return -ENOTSUP;
2812 : :
2813 : 0 : test_buffer = rte_malloc(NULL, BIG_DATA_TEST_SIZE, 0);
2814 [ # # ]: 0 : if (test_buffer == NULL) {
2815 : 0 : RTE_LOG(ERR, USER1,
2816 : : "Can't allocate buffer for big-data\n");
2817 : 0 : return TEST_FAILED;
2818 : : }
2819 : :
2820 : 0 : struct interim_data_params int_data = {
2821 : : (const char * const *)&test_buffer,
2822 : : 1,
2823 : : &i,
2824 : : &ts_params->def_comp_xform,
2825 : : &ts_params->def_decomp_xform,
2826 : : 1
2827 : : };
2828 : :
2829 : 0 : struct test_data_params test_data = {
2830 : : .compress_state = RTE_COMP_OP_STATELESS,
2831 : : .decompress_state = RTE_COMP_OP_STATELESS,
2832 : : .buff_type = SGL_BOTH,
2833 : : .zlib_dir = ZLIB_DECOMPRESS,
2834 : : .out_of_space = 0,
2835 : : .big_data = 1,
2836 : : .overflow = OVERFLOW_DISABLED,
2837 : : .ratio = RATIO_DISABLED
2838 : : };
2839 : :
2840 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
2841 : : RTE_COMP_HUFFMAN_DYNAMIC;
2842 : :
2843 : : /* fill the buffer with data based on rand. data */
2844 : 0 : srand(BIG_DATA_TEST_SIZE);
2845 [ # # ]: 0 : for (j = 0; j < BIG_DATA_TEST_SIZE - 1; ++j)
2846 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
2847 : 0 : test_buffer[BIG_DATA_TEST_SIZE - 1] = 0;
2848 : :
2849 : : /* Compress with compressdev, decompress with Zlib */
2850 : 0 : test_data.zlib_dir = ZLIB_DECOMPRESS;
2851 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2852 [ # # ]: 0 : if (ret < 0)
2853 : 0 : goto exit;
2854 : :
2855 : : /* Compress with Zlib, decompress with compressdev */
2856 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
2857 : 0 : ret = test_deflate_comp_decomp(&int_data, &test_data);
2858 : : if (ret < 0)
2859 : : goto exit;
2860 : :
2861 : : ret = TEST_SUCCESS;
2862 : :
2863 : 0 : exit:
2864 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
2865 : : RTE_COMP_HUFFMAN_DEFAULT;
2866 : 0 : rte_free(test_buffer);
2867 : 0 : return ret;
2868 : : }
2869 : :
2870 : : static int
2871 : 0 : test_compressdev_deflate_stateful_decomp(void)
2872 : : {
2873 : : struct comp_testsuite_params *ts_params = &testsuite_params;
2874 : : int ret;
2875 : : uint16_t i;
2876 : : const struct rte_compressdev_capabilities *capab;
2877 : :
2878 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
2879 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
2880 : :
2881 [ # # ]: 0 : if (!(capab->comp_feature_flags & RTE_COMP_FF_STATEFUL_DECOMPRESSION))
2882 : : return -ENOTSUP;
2883 : :
2884 : 0 : struct interim_data_params int_data = {
2885 : : &compress_test_bufs[0],
2886 : : 1,
2887 : : &i,
2888 : : &ts_params->def_comp_xform,
2889 : : &ts_params->def_decomp_xform,
2890 : : 1
2891 : : };
2892 : :
2893 : 0 : struct test_data_params test_data = {
2894 : : .compress_state = RTE_COMP_OP_STATELESS,
2895 : : .decompress_state = RTE_COMP_OP_STATEFUL,
2896 : : .buff_type = LB_BOTH,
2897 : : .zlib_dir = ZLIB_COMPRESS,
2898 : : .out_of_space = 0,
2899 : : .big_data = 0,
2900 : : .decompress_output_block_size = 2000,
2901 : : .decompress_steps_max = 4,
2902 : : .overflow = OVERFLOW_DISABLED,
2903 : : .ratio = RATIO_ENABLED
2904 : : };
2905 : :
2906 : : /* Compress with Zlib, decompress with compressdev */
2907 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
2908 : : ret = TEST_FAILED;
2909 : 0 : goto exit;
2910 : : }
2911 : :
2912 [ # # ]: 0 : if (capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
2913 : : /* Now test with SGL buffers */
2914 : 0 : test_data.buff_type = SGL_BOTH;
2915 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
2916 : : ret = TEST_FAILED;
2917 : 0 : goto exit;
2918 : : }
2919 : : }
2920 : :
2921 : : ret = TEST_SUCCESS;
2922 : :
2923 : : exit:
2924 : : return ret;
2925 : : }
2926 : :
2927 : : static int
2928 : 0 : test_compressdev_deflate_stateful_decomp_checksum(void)
2929 : : {
2930 : : struct comp_testsuite_params *ts_params = &testsuite_params;
2931 : : int ret;
2932 : : uint16_t i;
2933 : : const struct rte_compressdev_capabilities *capab;
2934 : :
2935 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
2936 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
2937 : :
2938 [ # # ]: 0 : if (!(capab->comp_feature_flags & RTE_COMP_FF_STATEFUL_DECOMPRESSION))
2939 : : return -ENOTSUP;
2940 : :
2941 : : /* Check if driver supports any checksum */
2942 [ # # ]: 0 : if (!(capab->comp_feature_flags &
2943 : : (RTE_COMP_FF_CRC32_CHECKSUM | RTE_COMP_FF_ADLER32_CHECKSUM |
2944 : : RTE_COMP_FF_CRC32_ADLER32_CHECKSUM)))
2945 : : return -ENOTSUP;
2946 : :
2947 : 0 : struct rte_comp_xform *compress_xform =
2948 : 0 : rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
2949 [ # # ]: 0 : if (compress_xform == NULL) {
2950 : 0 : RTE_LOG(ERR, USER1, "Compress xform could not be created\n");
2951 : 0 : return TEST_FAILED;
2952 : : }
2953 : :
2954 : 0 : *compress_xform = *ts_params->def_comp_xform;
2955 : :
2956 : 0 : struct rte_comp_xform *decompress_xform =
2957 : 0 : rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
2958 [ # # ]: 0 : if (decompress_xform == NULL) {
2959 : 0 : RTE_LOG(ERR, USER1, "Decompress xform could not be created\n");
2960 : 0 : rte_free(compress_xform);
2961 : 0 : return TEST_FAILED;
2962 : : }
2963 : :
2964 : 0 : *decompress_xform = *ts_params->def_decomp_xform;
2965 : :
2966 : 0 : struct interim_data_params int_data = {
2967 : : &compress_test_bufs[0],
2968 : : 1,
2969 : : &i,
2970 : : &compress_xform,
2971 : : &decompress_xform,
2972 : : 1
2973 : : };
2974 : :
2975 : 0 : struct test_data_params test_data = {
2976 : : .compress_state = RTE_COMP_OP_STATELESS,
2977 : : .decompress_state = RTE_COMP_OP_STATEFUL,
2978 : : .buff_type = LB_BOTH,
2979 : : .zlib_dir = ZLIB_COMPRESS,
2980 : : .out_of_space = 0,
2981 : : .big_data = 0,
2982 : : .decompress_output_block_size = 2000,
2983 : : .decompress_steps_max = 4,
2984 : : .overflow = OVERFLOW_DISABLED,
2985 : : .ratio = RATIO_ENABLED
2986 : : };
2987 : :
2988 : : /* Check if driver supports crc32 checksum and test */
2989 [ # # ]: 0 : if (capab->comp_feature_flags & RTE_COMP_FF_CRC32_CHECKSUM) {
2990 : 0 : compress_xform->compress.chksum = RTE_COMP_CHECKSUM_CRC32;
2991 : 0 : decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_CRC32;
2992 : : /* Compress with Zlib, decompress with compressdev */
2993 : : test_data.buff_type = LB_BOTH;
2994 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
2995 : : ret = TEST_FAILED;
2996 : 0 : goto exit;
2997 : : }
2998 [ # # ]: 0 : if (capab->comp_feature_flags &
2999 : : RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
3000 : : /* Now test with SGL buffers */
3001 : 0 : test_data.buff_type = SGL_BOTH;
3002 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data,
3003 : : &test_data) < 0) {
3004 : : ret = TEST_FAILED;
3005 : 0 : goto exit;
3006 : : }
3007 : : }
3008 : : }
3009 : :
3010 : : /* Check if driver supports adler32 checksum and test */
3011 [ # # ]: 0 : if (capab->comp_feature_flags & RTE_COMP_FF_ADLER32_CHECKSUM) {
3012 : 0 : compress_xform->compress.chksum = RTE_COMP_CHECKSUM_ADLER32;
3013 : 0 : decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_ADLER32;
3014 : : /* Compress with Zlib, decompress with compressdev */
3015 : 0 : test_data.buff_type = LB_BOTH;
3016 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3017 : : ret = TEST_FAILED;
3018 : 0 : goto exit;
3019 : : }
3020 [ # # ]: 0 : if (capab->comp_feature_flags &
3021 : : RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
3022 : : /* Now test with SGL buffers */
3023 : 0 : test_data.buff_type = SGL_BOTH;
3024 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data,
3025 : : &test_data) < 0) {
3026 : : ret = TEST_FAILED;
3027 : 0 : goto exit;
3028 : : }
3029 : : }
3030 : : }
3031 : :
3032 : : /* Check if driver supports combined crc and adler checksum and test */
3033 [ # # ]: 0 : if (capab->comp_feature_flags & RTE_COMP_FF_CRC32_ADLER32_CHECKSUM) {
3034 : 0 : compress_xform->compress.chksum =
3035 : : RTE_COMP_CHECKSUM_CRC32_ADLER32;
3036 : 0 : decompress_xform->decompress.chksum =
3037 : : RTE_COMP_CHECKSUM_CRC32_ADLER32;
3038 : : /* Zlib doesn't support combined checksum */
3039 : 0 : test_data.zlib_dir = ZLIB_NONE;
3040 : : /* Compress stateless, decompress stateful with compressdev */
3041 : 0 : test_data.buff_type = LB_BOTH;
3042 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3043 : : ret = TEST_FAILED;
3044 : 0 : goto exit;
3045 : : }
3046 [ # # ]: 0 : if (capab->comp_feature_flags &
3047 : : RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
3048 : : /* Now test with SGL buffers */
3049 : 0 : test_data.buff_type = SGL_BOTH;
3050 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data,
3051 : : &test_data) < 0) {
3052 : : ret = TEST_FAILED;
3053 : 0 : goto exit;
3054 : : }
3055 : : }
3056 : : }
3057 : :
3058 : : ret = TEST_SUCCESS;
3059 : :
3060 : 0 : exit:
3061 : 0 : rte_free(compress_xform);
3062 : 0 : rte_free(decompress_xform);
3063 : 0 : return ret;
3064 : : }
3065 : :
3066 : : static const struct rte_memzone *
3067 : 0 : make_memzone(const char *name, size_t size)
3068 : : {
3069 : 0 : unsigned int socket_id = rte_socket_id();
3070 : : char mz_name[RTE_MEMZONE_NAMESIZE];
3071 : : const struct rte_memzone *memzone;
3072 : :
3073 : : snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "%s_%u", name, socket_id);
3074 : 0 : memzone = rte_memzone_lookup(mz_name);
3075 [ # # # # ]: 0 : if (memzone != NULL && memzone->len != size) {
3076 : 0 : rte_memzone_free(memzone);
3077 : : memzone = NULL;
3078 : : }
3079 [ # # ]: 0 : if (memzone == NULL) {
3080 : 0 : memzone = rte_memzone_reserve_aligned(mz_name, size, socket_id,
3081 : : RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE);
3082 [ # # ]: 0 : if (memzone == NULL)
3083 : 0 : RTE_LOG(ERR, USER1, "Can't allocate memory zone %s",
3084 : : mz_name);
3085 : : }
3086 : 0 : return memzone;
3087 : : }
3088 : :
3089 : : static int
3090 : 0 : test_compressdev_external_mbufs(void)
3091 : : {
3092 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3093 : : size_t data_len = 0;
3094 : : uint16_t i;
3095 : : int ret = TEST_FAILED;
3096 : :
3097 [ # # ]: 0 : for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
3098 : 0 : data_len = RTE_MAX(data_len, strlen(compress_test_bufs[i]) + 1);
3099 : :
3100 : 0 : struct interim_data_params int_data = {
3101 : : NULL,
3102 : : 1,
3103 : : NULL,
3104 : : &ts_params->def_comp_xform,
3105 : : &ts_params->def_decomp_xform,
3106 : : 1
3107 : : };
3108 : :
3109 : 0 : struct test_data_params test_data = {
3110 : : .compress_state = RTE_COMP_OP_STATELESS,
3111 : : .decompress_state = RTE_COMP_OP_STATELESS,
3112 : : .buff_type = LB_BOTH,
3113 : : .zlib_dir = ZLIB_DECOMPRESS,
3114 : : .out_of_space = 0,
3115 : : .big_data = 0,
3116 : : .use_external_mbufs = 1,
3117 : : .inbuf_data_size = data_len,
3118 : 0 : .inbuf_memzone = make_memzone("inbuf", data_len),
3119 : 0 : .compbuf_memzone = make_memzone("compbuf", data_len *
3120 : : COMPRESS_BUF_SIZE_RATIO),
3121 : 0 : .uncompbuf_memzone = make_memzone("decompbuf", data_len),
3122 : : .overflow = OVERFLOW_DISABLED
3123 : : };
3124 : :
3125 [ # # ]: 0 : for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
3126 : : /* prepare input data */
3127 : 0 : data_len = strlen(compress_test_bufs[i]) + 1;
3128 [ # # ]: 0 : rte_memcpy(test_data.inbuf_memzone->addr, compress_test_bufs[i],
3129 : : data_len);
3130 : 0 : test_data.inbuf_data_size = data_len;
3131 : 0 : int_data.buf_idx = &i;
3132 : :
3133 : : /* Compress with compressdev, decompress with Zlib */
3134 : 0 : test_data.zlib_dir = ZLIB_DECOMPRESS;
3135 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
3136 : 0 : goto exit;
3137 : :
3138 : : /* Compress with Zlib, decompress with compressdev */
3139 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
3140 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
3141 : 0 : goto exit;
3142 : : }
3143 : :
3144 : : ret = TEST_SUCCESS;
3145 : :
3146 : 0 : exit:
3147 : 0 : rte_memzone_free(test_data.inbuf_memzone);
3148 : 0 : rte_memzone_free(test_data.compbuf_memzone);
3149 : 0 : rte_memzone_free(test_data.uncompbuf_memzone);
3150 : 0 : return ret;
3151 : : }
3152 : :
3153 : : static int
3154 : 0 : test_compressdev_deflate_stateless_fixed_oos_recoverable(void)
3155 : : {
3156 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3157 : : uint16_t i;
3158 : : int ret;
3159 : : int comp_result;
3160 : : const struct rte_compressdev_capabilities *capab;
3161 : :
3162 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3163 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3164 : :
3165 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0)
3166 : : return -ENOTSUP;
3167 : :
3168 : 0 : struct rte_comp_xform *compress_xform =
3169 : 0 : rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
3170 : :
3171 [ # # ]: 0 : if (compress_xform == NULL) {
3172 : 0 : RTE_LOG(ERR, USER1,
3173 : : "Compress xform could not be created\n");
3174 : : ret = TEST_FAILED;
3175 : 0 : goto exit;
3176 : : }
3177 : :
3178 : 0 : *compress_xform = *ts_params->def_comp_xform;
3179 : 0 : compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
3180 : :
3181 : 0 : struct interim_data_params int_data = {
3182 : : NULL,
3183 : : 1,
3184 : : NULL,
3185 : : &compress_xform,
3186 : : &ts_params->def_decomp_xform,
3187 : : 1
3188 : : };
3189 : :
3190 : 0 : struct test_data_params test_data = {
3191 : : .compress_state = RTE_COMP_OP_STATELESS,
3192 : : .decompress_state = RTE_COMP_OP_STATELESS,
3193 : : .buff_type = LB_BOTH,
3194 : : .zlib_dir = ZLIB_DECOMPRESS,
3195 : : .out_of_space = 0,
3196 : : .big_data = 0,
3197 : : .overflow = OVERFLOW_ENABLED,
3198 : : .ratio = RATIO_ENABLED
3199 : : };
3200 : :
3201 [ # # ]: 0 : for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
3202 : 0 : int_data.test_bufs = &compress_test_bufs[i];
3203 : 0 : int_data.buf_idx = &i;
3204 : :
3205 : : /* Compress with compressdev, decompress with Zlib */
3206 : 0 : test_data.zlib_dir = ZLIB_DECOMPRESS;
3207 : 0 : comp_result = test_deflate_comp_decomp(&int_data, &test_data);
3208 [ # # ]: 0 : if (comp_result < 0) {
3209 : : ret = TEST_FAILED;
3210 : 0 : goto exit;
3211 [ # # ]: 0 : } else if (comp_result > 0) {
3212 : : ret = -ENOTSUP;
3213 : 0 : goto exit;
3214 : : }
3215 : :
3216 : : /* Compress with Zlib, decompress with compressdev */
3217 : 0 : test_data.zlib_dir = ZLIB_COMPRESS;
3218 : 0 : comp_result = test_deflate_comp_decomp(&int_data, &test_data);
3219 [ # # ]: 0 : if (comp_result < 0) {
3220 : : ret = TEST_FAILED;
3221 : 0 : goto exit;
3222 [ # # ]: 0 : } else if (comp_result > 0) {
3223 : : ret = -ENOTSUP;
3224 : 0 : goto exit;
3225 : : }
3226 : : }
3227 : :
3228 : : ret = TEST_SUCCESS;
3229 : :
3230 : 0 : exit:
3231 : 0 : rte_free(compress_xform);
3232 : 0 : return ret;
3233 : : }
3234 : :
3235 : : static int
3236 : 0 : test_compressdev_deflate_im_buffers_LB_1op(void)
3237 : : {
3238 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3239 : 0 : uint16_t i = 0;
3240 : : int ret = TEST_SUCCESS;
3241 : : int j;
3242 : : const struct rte_compressdev_capabilities *capab;
3243 : 0 : char *test_buffer = NULL;
3244 : :
3245 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3246 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3247 : :
3248 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3249 : : return -ENOTSUP;
3250 : :
3251 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3252 : : return -ENOTSUP;
3253 : :
3254 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
3255 [ # # ]: 0 : if (test_buffer == NULL) {
3256 : 0 : RTE_LOG(ERR, USER1,
3257 : : "Can't allocate buffer for 'im buffer' test\n");
3258 : 0 : return TEST_FAILED;
3259 : : }
3260 : :
3261 : 0 : struct interim_data_params int_data = {
3262 : : (const char * const *)&test_buffer,
3263 : : 1,
3264 : : &i,
3265 : : &ts_params->def_comp_xform,
3266 : : &ts_params->def_decomp_xform,
3267 : : 1
3268 : : };
3269 : :
3270 : 0 : struct test_data_params test_data = {
3271 : : .compress_state = RTE_COMP_OP_STATELESS,
3272 : : .decompress_state = RTE_COMP_OP_STATELESS,
3273 : : /* must be LB to SGL,
3274 : : * input LB buffer reaches its maximum,
3275 : : * if ratio 1.3 than another mbuf must be
3276 : : * created and attached
3277 : : */
3278 : : .buff_type = LB_BOTH,
3279 : : .zlib_dir = ZLIB_NONE,
3280 : : .out_of_space = 0,
3281 : : .big_data = 1,
3282 : : .overflow = OVERFLOW_DISABLED,
3283 : : .ratio = RATIO_DISABLED
3284 : : };
3285 : :
3286 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3287 : : RTE_COMP_HUFFMAN_DYNAMIC;
3288 : :
3289 : : /* fill the buffer with data based on rand. data */
3290 : 0 : srand(IM_BUF_DATA_TEST_SIZE_LB);
3291 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
3292 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3293 : :
3294 : : /* Compress with compressdev, decompress with compressdev */
3295 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3296 : : ret = TEST_FAILED;
3297 : 0 : goto end;
3298 : : }
3299 : :
3300 : 0 : end:
3301 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3302 : : RTE_COMP_HUFFMAN_DEFAULT;
3303 : 0 : rte_free(test_buffer);
3304 : 0 : return ret;
3305 : : }
3306 : :
3307 : : static int
3308 : 0 : test_compressdev_deflate_im_buffers_LB_2ops_first(void)
3309 : : {
3310 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3311 : 0 : uint16_t i = 0;
3312 : : int ret = TEST_SUCCESS;
3313 : : int j;
3314 : : const struct rte_compressdev_capabilities *capab;
3315 : : char *test_buffer = NULL;
3316 : : const char *test_buffers[2];
3317 : :
3318 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3319 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3320 : :
3321 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3322 : : return -ENOTSUP;
3323 : :
3324 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3325 : : return -ENOTSUP;
3326 : :
3327 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
3328 [ # # ]: 0 : if (test_buffer == NULL) {
3329 : 0 : RTE_LOG(ERR, USER1,
3330 : : "Can't allocate buffer for 'im buffer' test\n");
3331 : 0 : return TEST_FAILED;
3332 : : }
3333 : :
3334 : 0 : test_buffers[0] = test_buffer;
3335 : 0 : test_buffers[1] = compress_test_bufs[0];
3336 : :
3337 : 0 : struct interim_data_params int_data = {
3338 : : (const char * const *)test_buffers,
3339 : : 2,
3340 : : &i,
3341 : : &ts_params->def_comp_xform,
3342 : : &ts_params->def_decomp_xform,
3343 : : 1
3344 : : };
3345 : :
3346 : 0 : struct test_data_params test_data = {
3347 : : .compress_state = RTE_COMP_OP_STATELESS,
3348 : : .decompress_state = RTE_COMP_OP_STATELESS,
3349 : : .buff_type = LB_BOTH,
3350 : : .zlib_dir = ZLIB_NONE,
3351 : : .out_of_space = 0,
3352 : : .big_data = 1,
3353 : : .overflow = OVERFLOW_DISABLED,
3354 : : .ratio = RATIO_DISABLED
3355 : : };
3356 : :
3357 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3358 : : RTE_COMP_HUFFMAN_DYNAMIC;
3359 : :
3360 : : /* fill the buffer with data based on rand. data */
3361 : 0 : srand(IM_BUF_DATA_TEST_SIZE_LB);
3362 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
3363 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3364 : :
3365 : : /* Compress with compressdev, decompress with compressdev */
3366 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3367 : : ret = TEST_FAILED;
3368 : 0 : goto end;
3369 : : }
3370 : :
3371 : 0 : end:
3372 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3373 : : RTE_COMP_HUFFMAN_DEFAULT;
3374 : 0 : rte_free(test_buffer);
3375 : 0 : return ret;
3376 : : }
3377 : :
3378 : : static int
3379 : 0 : test_compressdev_deflate_im_buffers_LB_2ops_second(void)
3380 : : {
3381 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3382 : 0 : uint16_t i = 0;
3383 : : int ret = TEST_SUCCESS;
3384 : : int j;
3385 : : const struct rte_compressdev_capabilities *capab;
3386 : : char *test_buffer = NULL;
3387 : : const char *test_buffers[2];
3388 : :
3389 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3390 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3391 : :
3392 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3393 : : return -ENOTSUP;
3394 : :
3395 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3396 : : return -ENOTSUP;
3397 : :
3398 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
3399 [ # # ]: 0 : if (test_buffer == NULL) {
3400 : 0 : RTE_LOG(ERR, USER1,
3401 : : "Can't allocate buffer for 'im buffer' test\n");
3402 : 0 : return TEST_FAILED;
3403 : : }
3404 : :
3405 : 0 : test_buffers[0] = compress_test_bufs[0];
3406 : 0 : test_buffers[1] = test_buffer;
3407 : :
3408 : 0 : struct interim_data_params int_data = {
3409 : : (const char * const *)test_buffers,
3410 : : 2,
3411 : : &i,
3412 : : &ts_params->def_comp_xform,
3413 : : &ts_params->def_decomp_xform,
3414 : : 1
3415 : : };
3416 : :
3417 : 0 : struct test_data_params test_data = {
3418 : : .compress_state = RTE_COMP_OP_STATELESS,
3419 : : .decompress_state = RTE_COMP_OP_STATELESS,
3420 : : .buff_type = LB_BOTH,
3421 : : .zlib_dir = ZLIB_NONE,
3422 : : .out_of_space = 0,
3423 : : .big_data = 1,
3424 : : .overflow = OVERFLOW_DISABLED,
3425 : : .ratio = RATIO_DISABLED
3426 : : };
3427 : :
3428 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3429 : : RTE_COMP_HUFFMAN_DYNAMIC;
3430 : :
3431 : : /* fill the buffer with data based on rand. data */
3432 : 0 : srand(IM_BUF_DATA_TEST_SIZE_LB);
3433 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
3434 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3435 : :
3436 : : /* Compress with compressdev, decompress with compressdev */
3437 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3438 : : ret = TEST_FAILED;
3439 : 0 : goto end;
3440 : : }
3441 : :
3442 : 0 : end:
3443 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3444 : : RTE_COMP_HUFFMAN_DEFAULT;
3445 : 0 : rte_free(test_buffer);
3446 : 0 : return ret;
3447 : : }
3448 : :
3449 : : static int
3450 : 0 : test_compressdev_deflate_im_buffers_LB_3ops(void)
3451 : : {
3452 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3453 : 0 : uint16_t i = 0;
3454 : : int ret = TEST_SUCCESS;
3455 : : int j;
3456 : : const struct rte_compressdev_capabilities *capab;
3457 : : char *test_buffer = NULL;
3458 : : const char *test_buffers[3];
3459 : :
3460 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3461 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3462 : :
3463 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3464 : : return -ENOTSUP;
3465 : :
3466 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3467 : : return -ENOTSUP;
3468 : :
3469 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
3470 [ # # ]: 0 : if (test_buffer == NULL) {
3471 : 0 : RTE_LOG(ERR, USER1,
3472 : : "Can't allocate buffer for 'im buffer' test\n");
3473 : 0 : return TEST_FAILED;
3474 : : }
3475 : :
3476 : 0 : test_buffers[0] = compress_test_bufs[0];
3477 : 0 : test_buffers[1] = test_buffer;
3478 : 0 : test_buffers[2] = compress_test_bufs[1];
3479 : :
3480 : 0 : struct interim_data_params int_data = {
3481 : : (const char * const *)test_buffers,
3482 : : 3,
3483 : : &i,
3484 : : &ts_params->def_comp_xform,
3485 : : &ts_params->def_decomp_xform,
3486 : : 1
3487 : : };
3488 : :
3489 : 0 : struct test_data_params test_data = {
3490 : : .compress_state = RTE_COMP_OP_STATELESS,
3491 : : .decompress_state = RTE_COMP_OP_STATELESS,
3492 : : .buff_type = LB_BOTH,
3493 : : .zlib_dir = ZLIB_NONE,
3494 : : .out_of_space = 0,
3495 : : .big_data = 1,
3496 : : .overflow = OVERFLOW_DISABLED,
3497 : : .ratio = RATIO_DISABLED
3498 : : };
3499 : :
3500 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3501 : : RTE_COMP_HUFFMAN_DYNAMIC;
3502 : :
3503 : : /* fill the buffer with data based on rand. data */
3504 : 0 : srand(IM_BUF_DATA_TEST_SIZE_LB);
3505 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
3506 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3507 : :
3508 : : /* Compress with compressdev, decompress with compressdev */
3509 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3510 : : ret = TEST_FAILED;
3511 : 0 : goto end;
3512 : : }
3513 : :
3514 : 0 : end:
3515 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3516 : : RTE_COMP_HUFFMAN_DEFAULT;
3517 : 0 : rte_free(test_buffer);
3518 : 0 : return ret;
3519 : : }
3520 : :
3521 : : static int
3522 : 0 : test_compressdev_deflate_im_buffers_LB_4ops(void)
3523 : : {
3524 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3525 : 0 : uint16_t i = 0;
3526 : : int ret = TEST_SUCCESS;
3527 : : int j;
3528 : : const struct rte_compressdev_capabilities *capab;
3529 : : char *test_buffer = NULL;
3530 : : const char *test_buffers[4];
3531 : :
3532 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3533 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3534 : :
3535 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3536 : : return -ENOTSUP;
3537 : :
3538 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3539 : : return -ENOTSUP;
3540 : :
3541 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
3542 [ # # ]: 0 : if (test_buffer == NULL) {
3543 : 0 : RTE_LOG(ERR, USER1,
3544 : : "Can't allocate buffer for 'im buffer' test\n");
3545 : 0 : return TEST_FAILED;
3546 : : }
3547 : :
3548 : 0 : test_buffers[0] = compress_test_bufs[0];
3549 : 0 : test_buffers[1] = test_buffer;
3550 : 0 : test_buffers[2] = compress_test_bufs[1];
3551 : 0 : test_buffers[3] = test_buffer;
3552 : :
3553 : 0 : struct interim_data_params int_data = {
3554 : : (const char * const *)test_buffers,
3555 : : 4,
3556 : : &i,
3557 : : &ts_params->def_comp_xform,
3558 : : &ts_params->def_decomp_xform,
3559 : : 1
3560 : : };
3561 : :
3562 : 0 : struct test_data_params test_data = {
3563 : : .compress_state = RTE_COMP_OP_STATELESS,
3564 : : .decompress_state = RTE_COMP_OP_STATELESS,
3565 : : .buff_type = LB_BOTH,
3566 : : .zlib_dir = ZLIB_NONE,
3567 : : .out_of_space = 0,
3568 : : .big_data = 1,
3569 : : .overflow = OVERFLOW_DISABLED,
3570 : : .ratio = RATIO_DISABLED
3571 : : };
3572 : :
3573 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3574 : : RTE_COMP_HUFFMAN_DYNAMIC;
3575 : :
3576 : : /* fill the buffer with data based on rand. data */
3577 : 0 : srand(IM_BUF_DATA_TEST_SIZE_LB);
3578 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
3579 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3580 : :
3581 : : /* Compress with compressdev, decompress with compressdev */
3582 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3583 : : ret = TEST_FAILED;
3584 : 0 : goto end;
3585 : : }
3586 : :
3587 : 0 : end:
3588 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3589 : : RTE_COMP_HUFFMAN_DEFAULT;
3590 : 0 : rte_free(test_buffer);
3591 : 0 : return ret;
3592 : : }
3593 : :
3594 : :
3595 : : static int
3596 : 0 : test_compressdev_deflate_im_buffers_SGL_1op(void)
3597 : : {
3598 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3599 : 0 : uint16_t i = 0;
3600 : : int ret = TEST_SUCCESS;
3601 : : int j;
3602 : : const struct rte_compressdev_capabilities *capab;
3603 : 0 : char *test_buffer = NULL;
3604 : :
3605 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3606 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3607 : :
3608 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3609 : : return -ENOTSUP;
3610 : :
3611 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3612 : : return -ENOTSUP;
3613 : :
3614 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
3615 [ # # ]: 0 : if (test_buffer == NULL) {
3616 : 0 : RTE_LOG(ERR, USER1,
3617 : : "Can't allocate buffer for big-data\n");
3618 : 0 : return TEST_FAILED;
3619 : : }
3620 : :
3621 : 0 : struct interim_data_params int_data = {
3622 : : (const char * const *)&test_buffer,
3623 : : 1,
3624 : : &i,
3625 : : &ts_params->def_comp_xform,
3626 : : &ts_params->def_decomp_xform,
3627 : : 1
3628 : : };
3629 : :
3630 : 0 : struct test_data_params test_data = {
3631 : : .compress_state = RTE_COMP_OP_STATELESS,
3632 : : .decompress_state = RTE_COMP_OP_STATELESS,
3633 : : .buff_type = SGL_BOTH,
3634 : : .zlib_dir = ZLIB_NONE,
3635 : : .out_of_space = 0,
3636 : : .big_data = 1,
3637 : : .overflow = OVERFLOW_DISABLED,
3638 : : .ratio = RATIO_DISABLED
3639 : : };
3640 : :
3641 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3642 : : RTE_COMP_HUFFMAN_DYNAMIC;
3643 : :
3644 : : /* fill the buffer with data based on rand. data */
3645 : 0 : srand(IM_BUF_DATA_TEST_SIZE_SGL);
3646 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
3647 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3648 : :
3649 : : /* Compress with compressdev, decompress with compressdev */
3650 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3651 : : ret = TEST_FAILED;
3652 : 0 : goto end;
3653 : : }
3654 : :
3655 : 0 : end:
3656 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3657 : : RTE_COMP_HUFFMAN_DEFAULT;
3658 : 0 : rte_free(test_buffer);
3659 : 0 : return ret;
3660 : : }
3661 : :
3662 : : static int
3663 : 0 : test_compressdev_deflate_im_buffers_SGL_2ops_first(void)
3664 : : {
3665 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3666 : 0 : uint16_t i = 0;
3667 : : int ret = TEST_SUCCESS;
3668 : : int j;
3669 : : const struct rte_compressdev_capabilities *capab;
3670 : : char *test_buffer = NULL;
3671 : : const char *test_buffers[2];
3672 : :
3673 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3674 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3675 : :
3676 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3677 : : return -ENOTSUP;
3678 : :
3679 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3680 : : return -ENOTSUP;
3681 : :
3682 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
3683 [ # # ]: 0 : if (test_buffer == NULL) {
3684 : 0 : RTE_LOG(ERR, USER1,
3685 : : "Can't allocate buffer for big-data\n");
3686 : 0 : return TEST_FAILED;
3687 : : }
3688 : :
3689 : 0 : test_buffers[0] = test_buffer;
3690 : 0 : test_buffers[1] = compress_test_bufs[0];
3691 : :
3692 : 0 : struct interim_data_params int_data = {
3693 : : (const char * const *)test_buffers,
3694 : : 2,
3695 : : &i,
3696 : : &ts_params->def_comp_xform,
3697 : : &ts_params->def_decomp_xform,
3698 : : 1
3699 : : };
3700 : :
3701 : 0 : struct test_data_params test_data = {
3702 : : .compress_state = RTE_COMP_OP_STATELESS,
3703 : : .decompress_state = RTE_COMP_OP_STATELESS,
3704 : : .buff_type = SGL_BOTH,
3705 : : .zlib_dir = ZLIB_NONE,
3706 : : .out_of_space = 0,
3707 : : .big_data = 1,
3708 : : .overflow = OVERFLOW_DISABLED,
3709 : : .ratio = RATIO_DISABLED
3710 : : };
3711 : :
3712 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3713 : : RTE_COMP_HUFFMAN_DYNAMIC;
3714 : :
3715 : : /* fill the buffer with data based on rand. data */
3716 : 0 : srand(IM_BUF_DATA_TEST_SIZE_SGL);
3717 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
3718 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3719 : :
3720 : : /* Compress with compressdev, decompress with compressdev */
3721 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3722 : : ret = TEST_FAILED;
3723 : 0 : goto end;
3724 : : }
3725 : :
3726 : 0 : end:
3727 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3728 : : RTE_COMP_HUFFMAN_DEFAULT;
3729 : 0 : rte_free(test_buffer);
3730 : 0 : return ret;
3731 : : }
3732 : :
3733 : : static int
3734 : 0 : test_compressdev_deflate_im_buffers_SGL_2ops_second(void)
3735 : : {
3736 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3737 : 0 : uint16_t i = 0;
3738 : : int ret = TEST_SUCCESS;
3739 : : int j;
3740 : : const struct rte_compressdev_capabilities *capab;
3741 : : char *test_buffer = NULL;
3742 : : const char *test_buffers[2];
3743 : :
3744 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3745 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3746 : :
3747 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3748 : : return -ENOTSUP;
3749 : :
3750 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3751 : : return -ENOTSUP;
3752 : :
3753 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
3754 [ # # ]: 0 : if (test_buffer == NULL) {
3755 : 0 : RTE_LOG(ERR, USER1,
3756 : : "Can't allocate buffer for big-data\n");
3757 : 0 : return TEST_FAILED;
3758 : : }
3759 : :
3760 : 0 : test_buffers[0] = compress_test_bufs[0];
3761 : 0 : test_buffers[1] = test_buffer;
3762 : :
3763 : 0 : struct interim_data_params int_data = {
3764 : : (const char * const *)test_buffers,
3765 : : 2,
3766 : : &i,
3767 : : &ts_params->def_comp_xform,
3768 : : &ts_params->def_decomp_xform,
3769 : : 1
3770 : : };
3771 : :
3772 : 0 : struct test_data_params test_data = {
3773 : : .compress_state = RTE_COMP_OP_STATELESS,
3774 : : .decompress_state = RTE_COMP_OP_STATELESS,
3775 : : .buff_type = SGL_BOTH,
3776 : : .zlib_dir = ZLIB_NONE,
3777 : : .out_of_space = 0,
3778 : : .big_data = 1,
3779 : : .overflow = OVERFLOW_DISABLED,
3780 : : .ratio = RATIO_DISABLED
3781 : : };
3782 : :
3783 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3784 : : RTE_COMP_HUFFMAN_DYNAMIC;
3785 : :
3786 : : /* fill the buffer with data based on rand. data */
3787 : 0 : srand(IM_BUF_DATA_TEST_SIZE_SGL);
3788 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
3789 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3790 : :
3791 : : /* Compress with compressdev, decompress with compressdev */
3792 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3793 : : ret = TEST_FAILED;
3794 : 0 : goto end;
3795 : : }
3796 : :
3797 : 0 : end:
3798 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3799 : : RTE_COMP_HUFFMAN_DEFAULT;
3800 : 0 : rte_free(test_buffer);
3801 : 0 : return ret;
3802 : : }
3803 : :
3804 : : static int
3805 : 0 : test_compressdev_deflate_im_buffers_SGL_3ops(void)
3806 : : {
3807 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3808 : 0 : uint16_t i = 0;
3809 : : int ret = TEST_SUCCESS;
3810 : : int j;
3811 : : const struct rte_compressdev_capabilities *capab;
3812 : : char *test_buffer = NULL;
3813 : : const char *test_buffers[3];
3814 : :
3815 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3816 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3817 : :
3818 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3819 : : return -ENOTSUP;
3820 : :
3821 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3822 : : return -ENOTSUP;
3823 : :
3824 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
3825 [ # # ]: 0 : if (test_buffer == NULL) {
3826 : 0 : RTE_LOG(ERR, USER1,
3827 : : "Can't allocate buffer for big-data\n");
3828 : 0 : return TEST_FAILED;
3829 : : }
3830 : :
3831 : 0 : test_buffers[0] = compress_test_bufs[0];
3832 : 0 : test_buffers[1] = test_buffer;
3833 : 0 : test_buffers[2] = compress_test_bufs[1];
3834 : :
3835 : 0 : struct interim_data_params int_data = {
3836 : : (const char * const *)test_buffers,
3837 : : 3,
3838 : : &i,
3839 : : &ts_params->def_comp_xform,
3840 : : &ts_params->def_decomp_xform,
3841 : : 1
3842 : : };
3843 : :
3844 : 0 : struct test_data_params test_data = {
3845 : : .compress_state = RTE_COMP_OP_STATELESS,
3846 : : .decompress_state = RTE_COMP_OP_STATELESS,
3847 : : .buff_type = SGL_BOTH,
3848 : : .zlib_dir = ZLIB_NONE,
3849 : : .out_of_space = 0,
3850 : : .big_data = 1,
3851 : : .overflow = OVERFLOW_DISABLED,
3852 : : .ratio = RATIO_DISABLED
3853 : : };
3854 : :
3855 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3856 : : RTE_COMP_HUFFMAN_DYNAMIC;
3857 : :
3858 : : /* fill the buffer with data based on rand. data */
3859 : 0 : srand(IM_BUF_DATA_TEST_SIZE_SGL);
3860 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
3861 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3862 : :
3863 : : /* Compress with compressdev, decompress with compressdev */
3864 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3865 : : ret = TEST_FAILED;
3866 : 0 : goto end;
3867 : : }
3868 : :
3869 : 0 : end:
3870 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3871 : : RTE_COMP_HUFFMAN_DEFAULT;
3872 : 0 : rte_free(test_buffer);
3873 : 0 : return ret;
3874 : : }
3875 : :
3876 : :
3877 : : static int
3878 : 0 : test_compressdev_deflate_im_buffers_SGL_4ops(void)
3879 : : {
3880 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3881 : 0 : uint16_t i = 0;
3882 : : int ret = TEST_SUCCESS;
3883 : : int j;
3884 : : const struct rte_compressdev_capabilities *capab;
3885 : : char *test_buffer = NULL;
3886 : : const char *test_buffers[4];
3887 : :
3888 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3889 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3890 : :
3891 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3892 : : return -ENOTSUP;
3893 : :
3894 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3895 : : return -ENOTSUP;
3896 : :
3897 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
3898 [ # # ]: 0 : if (test_buffer == NULL) {
3899 : 0 : RTE_LOG(ERR, USER1,
3900 : : "Can't allocate buffer for big-data\n");
3901 : 0 : return TEST_FAILED;
3902 : : }
3903 : :
3904 : 0 : test_buffers[0] = compress_test_bufs[0];
3905 : 0 : test_buffers[1] = test_buffer;
3906 : 0 : test_buffers[2] = compress_test_bufs[1];
3907 : 0 : test_buffers[3] = test_buffer;
3908 : :
3909 : 0 : struct interim_data_params int_data = {
3910 : : (const char * const *)test_buffers,
3911 : : 4,
3912 : : &i,
3913 : : &ts_params->def_comp_xform,
3914 : : &ts_params->def_decomp_xform,
3915 : : 1
3916 : : };
3917 : :
3918 : 0 : struct test_data_params test_data = {
3919 : : .compress_state = RTE_COMP_OP_STATELESS,
3920 : : .decompress_state = RTE_COMP_OP_STATELESS,
3921 : : .buff_type = SGL_BOTH,
3922 : : .zlib_dir = ZLIB_NONE,
3923 : : .out_of_space = 0,
3924 : : .big_data = 1,
3925 : : .overflow = OVERFLOW_DISABLED,
3926 : : .ratio = RATIO_DISABLED
3927 : : };
3928 : :
3929 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3930 : : RTE_COMP_HUFFMAN_DYNAMIC;
3931 : :
3932 : : /* fill the buffer with data based on rand. data */
3933 : 0 : srand(IM_BUF_DATA_TEST_SIZE_SGL);
3934 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
3935 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3936 : :
3937 : : /* Compress with compressdev, decompress with compressdev */
3938 [ # # ]: 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3939 : : ret = TEST_FAILED;
3940 : 0 : goto end;
3941 : : }
3942 : :
3943 : 0 : end:
3944 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3945 : : RTE_COMP_HUFFMAN_DEFAULT;
3946 : 0 : rte_free(test_buffer);
3947 : 0 : return ret;
3948 : : }
3949 : :
3950 : : static int
3951 : 0 : test_compressdev_deflate_im_buffers_SGL_over_1op(void)
3952 : : {
3953 : : struct comp_testsuite_params *ts_params = &testsuite_params;
3954 : 0 : uint16_t i = 0;
3955 : : int ret = TEST_SUCCESS;
3956 : : int j;
3957 : : const struct rte_compressdev_capabilities *capab;
3958 : 0 : char *test_buffer = NULL;
3959 : :
3960 : 0 : RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
3961 : :
3962 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3963 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3964 : :
3965 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3966 : : return -ENOTSUP;
3967 : :
3968 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3969 : : return -ENOTSUP;
3970 : :
3971 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_OVER, 0);
3972 [ # # ]: 0 : if (test_buffer == NULL) {
3973 : 0 : RTE_LOG(ERR, USER1,
3974 : : "Can't allocate buffer for big-data\n");
3975 : 0 : return TEST_FAILED;
3976 : : }
3977 : :
3978 : 0 : struct interim_data_params int_data = {
3979 : : (const char * const *)&test_buffer,
3980 : : 1,
3981 : : &i,
3982 : : &ts_params->def_comp_xform,
3983 : : &ts_params->def_decomp_xform,
3984 : : 1
3985 : : };
3986 : :
3987 : 0 : struct test_data_params test_data = {
3988 : : .compress_state = RTE_COMP_OP_STATELESS,
3989 : : .decompress_state = RTE_COMP_OP_STATELESS,
3990 : : .buff_type = SGL_BOTH,
3991 : : .zlib_dir = ZLIB_NONE,
3992 : : .out_of_space = 0,
3993 : : .big_data = 1,
3994 : : .overflow = OVERFLOW_DISABLED,
3995 : : .ratio = RATIO_DISABLED
3996 : : };
3997 : :
3998 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
3999 : : RTE_COMP_HUFFMAN_DYNAMIC;
4000 : :
4001 : : /* fill the buffer with data based on rand. data */
4002 : 0 : srand(IM_BUF_DATA_TEST_SIZE_OVER);
4003 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_OVER - 1; ++j)
4004 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
4005 : :
4006 : : /* Compress with compressdev, decompress with compressdev */
4007 : 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
4008 : : ret = TEST_SUCCESS;
4009 : : goto end;
4010 : : }
4011 : :
4012 : : end:
4013 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
4014 : : RTE_COMP_HUFFMAN_DEFAULT;
4015 : 0 : rte_free(test_buffer);
4016 : :
4017 : 0 : return ret;
4018 : : }
4019 : :
4020 : :
4021 : : static int
4022 : 0 : test_compressdev_deflate_im_buffers_SGL_over_2ops_first(void)
4023 : : {
4024 : : struct comp_testsuite_params *ts_params = &testsuite_params;
4025 : 0 : uint16_t i = 0;
4026 : : int ret = TEST_SUCCESS;
4027 : : int j;
4028 : : const struct rte_compressdev_capabilities *capab;
4029 : : char *test_buffer = NULL;
4030 : : const char *test_buffers[2];
4031 : :
4032 : 0 : RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
4033 : :
4034 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
4035 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
4036 : :
4037 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
4038 : : return -ENOTSUP;
4039 : :
4040 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
4041 : : return -ENOTSUP;
4042 : :
4043 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_OVER, 0);
4044 [ # # ]: 0 : if (test_buffer == NULL) {
4045 : 0 : RTE_LOG(ERR, USER1,
4046 : : "Can't allocate buffer for big-data\n");
4047 : 0 : return TEST_FAILED;
4048 : : }
4049 : :
4050 : 0 : test_buffers[0] = test_buffer;
4051 : 0 : test_buffers[1] = compress_test_bufs[0];
4052 : :
4053 : 0 : struct interim_data_params int_data = {
4054 : : (const char * const *)test_buffers,
4055 : : 2,
4056 : : &i,
4057 : : &ts_params->def_comp_xform,
4058 : : &ts_params->def_decomp_xform,
4059 : : 1
4060 : : };
4061 : :
4062 : 0 : struct test_data_params test_data = {
4063 : : .compress_state = RTE_COMP_OP_STATELESS,
4064 : : .decompress_state = RTE_COMP_OP_STATELESS,
4065 : : .buff_type = SGL_BOTH,
4066 : : .zlib_dir = ZLIB_NONE,
4067 : : .out_of_space = 0,
4068 : : .big_data = 1,
4069 : : .overflow = OVERFLOW_DISABLED,
4070 : : .ratio = RATIO_DISABLED
4071 : : };
4072 : :
4073 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
4074 : : RTE_COMP_HUFFMAN_DYNAMIC;
4075 : :
4076 : : /* fill the buffer with data based on rand. data */
4077 : 0 : srand(IM_BUF_DATA_TEST_SIZE_OVER);
4078 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_OVER - 1; ++j)
4079 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
4080 : :
4081 : : /* Compress with compressdev, decompress with compressdev */
4082 : 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
4083 : : ret = TEST_SUCCESS;
4084 : : goto end;
4085 : : }
4086 : :
4087 : : end:
4088 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
4089 : : RTE_COMP_HUFFMAN_DEFAULT;
4090 : 0 : rte_free(test_buffer);
4091 : 0 : return ret;
4092 : : }
4093 : :
4094 : : static int
4095 : 0 : test_compressdev_deflate_im_buffers_SGL_over_2ops_second(void)
4096 : : {
4097 : : struct comp_testsuite_params *ts_params = &testsuite_params;
4098 : 0 : uint16_t i = 0;
4099 : : int ret = TEST_SUCCESS;
4100 : : int j;
4101 : : const struct rte_compressdev_capabilities *capab;
4102 : : char *test_buffer = NULL;
4103 : : const char *test_buffers[2];
4104 : :
4105 : 0 : RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
4106 : :
4107 : 0 : capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
4108 [ # # ]: 0 : TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
4109 : :
4110 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
4111 : : return -ENOTSUP;
4112 : :
4113 [ # # ]: 0 : if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
4114 : : return -ENOTSUP;
4115 : :
4116 : 0 : test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_OVER, 0);
4117 [ # # ]: 0 : if (test_buffer == NULL) {
4118 : 0 : RTE_LOG(ERR, USER1,
4119 : : "Can't allocate buffer for big-data\n");
4120 : 0 : return TEST_FAILED;
4121 : : }
4122 : :
4123 : 0 : test_buffers[0] = compress_test_bufs[0];
4124 : 0 : test_buffers[1] = test_buffer;
4125 : :
4126 : 0 : struct interim_data_params int_data = {
4127 : : (const char * const *)test_buffers,
4128 : : 2,
4129 : : &i,
4130 : : &ts_params->def_comp_xform,
4131 : : &ts_params->def_decomp_xform,
4132 : : 1
4133 : : };
4134 : :
4135 : 0 : struct test_data_params test_data = {
4136 : : .compress_state = RTE_COMP_OP_STATELESS,
4137 : : .decompress_state = RTE_COMP_OP_STATELESS,
4138 : : .buff_type = SGL_BOTH,
4139 : : .zlib_dir = ZLIB_NONE,
4140 : : .out_of_space = 0,
4141 : : .big_data = 1,
4142 : : .overflow = OVERFLOW_DISABLED,
4143 : : .ratio = RATIO_DISABLED
4144 : : };
4145 : :
4146 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
4147 : : RTE_COMP_HUFFMAN_DYNAMIC;
4148 : :
4149 : : /* fill the buffer with data based on rand. data */
4150 : 0 : srand(IM_BUF_DATA_TEST_SIZE_OVER);
4151 [ # # ]: 0 : for (j = 0; j < IM_BUF_DATA_TEST_SIZE_OVER - 1; ++j)
4152 : 0 : test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
4153 : :
4154 : : /* Compress with compressdev, decompress with compressdev */
4155 : 0 : if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
4156 : : ret = TEST_SUCCESS;
4157 : : goto end;
4158 : : }
4159 : :
4160 : : end:
4161 : 0 : ts_params->def_comp_xform->compress.deflate.huffman =
4162 : : RTE_COMP_HUFFMAN_DEFAULT;
4163 : 0 : rte_free(test_buffer);
4164 : 0 : return ret;
4165 : : }
4166 : :
4167 : : static struct unit_test_suite compressdev_testsuite = {
4168 : : .suite_name = "compressdev unit test suite",
4169 : : .setup = testsuite_setup,
4170 : : .teardown = testsuite_teardown,
4171 : : .unit_test_cases = {
4172 : : TEST_CASE_ST(NULL, NULL,
4173 : : test_compressdev_invalid_configuration),
4174 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4175 : : test_compressdev_deflate_stateless_fixed),
4176 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4177 : : test_compressdev_deflate_stateless_dynamic),
4178 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4179 : : test_compressdev_deflate_stateless_dynamic_big),
4180 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4181 : : test_compressdev_deflate_stateless_multi_op),
4182 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4183 : : test_compressdev_deflate_stateless_multi_level),
4184 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4185 : : test_compressdev_deflate_stateless_multi_xform),
4186 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4187 : : test_compressdev_deflate_stateless_sgl),
4188 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4189 : : test_compressdev_deflate_stateless_checksum),
4190 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4191 : : test_compressdev_out_of_space_buffer),
4192 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4193 : : test_compressdev_deflate_stateful_decomp),
4194 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4195 : : test_compressdev_deflate_stateful_decomp_checksum),
4196 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4197 : : test_compressdev_external_mbufs),
4198 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4199 : : test_compressdev_deflate_stateless_fixed_oos_recoverable),
4200 : :
4201 : : /* Positive test cases for IM buffer handling verification */
4202 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4203 : : test_compressdev_deflate_im_buffers_LB_1op),
4204 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4205 : : test_compressdev_deflate_im_buffers_LB_2ops_first),
4206 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4207 : : test_compressdev_deflate_im_buffers_LB_2ops_second),
4208 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4209 : : test_compressdev_deflate_im_buffers_LB_3ops),
4210 : :
4211 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4212 : : test_compressdev_deflate_im_buffers_LB_4ops),
4213 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4214 : : test_compressdev_deflate_im_buffers_SGL_1op),
4215 : :
4216 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4217 : : test_compressdev_deflate_im_buffers_SGL_2ops_first),
4218 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4219 : : test_compressdev_deflate_im_buffers_SGL_2ops_second),
4220 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4221 : : test_compressdev_deflate_im_buffers_SGL_3ops),
4222 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4223 : : test_compressdev_deflate_im_buffers_SGL_4ops),
4224 : :
4225 : : /* Negative test cases for IM buffer handling verification */
4226 : :
4227 : : /* For this test huge mempool is necessary.
4228 : : * It tests one case:
4229 : : * only one op containing big amount of data, so that
4230 : : * number of requested descriptors higher than number
4231 : : * of available descriptors (128)
4232 : : */
4233 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4234 : : test_compressdev_deflate_im_buffers_SGL_over_1op),
4235 : :
4236 : : /* For this test huge mempool is necessary.
4237 : : * 2 ops. First op contains big amount of data:
4238 : : * number of requested descriptors higher than number
4239 : : * of available descriptors (128), the second op is
4240 : : * relatively small. In this case both ops are rejected
4241 : : */
4242 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4243 : : test_compressdev_deflate_im_buffers_SGL_over_2ops_first),
4244 : :
4245 : : TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4246 : : test_compressdev_deflate_im_buffers_SGL_over_2ops_second),
4247 : :
4248 : : TEST_CASES_END() /**< NULL terminate unit test array */
4249 : : }
4250 : : };
4251 : :
4252 : : static int
4253 : 1 : test_compressdev(void)
4254 : : {
4255 : 1 : return unit_test_suite_runner(&compressdev_testsuite);
4256 : : }
4257 : :
4258 : 254 : REGISTER_FAST_TEST(compressdev_autotest, false, true, test_compressdev);
|