eal: support strlcat function
[dpdk.git] / test / test / test_compressdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4 #include <string.h>
5 #include <zlib.h>
6 #include <math.h>
7
8 #include <rte_cycles.h>
9 #include <rte_malloc.h>
10 #include <rte_mempool.h>
11 #include <rte_mbuf.h>
12 #include <rte_compressdev.h>
13 #include <rte_string_fns.h>
14
15 #include "test_compressdev_test_buffer.h"
16 #include "test.h"
17
18 #define DIV_CEIL(a, b)  ((a) / (b) + ((a) % (b) != 0))
19
20 #define DEFAULT_WINDOW_SIZE 15
21 #define DEFAULT_MEM_LEVEL 8
22 #define MAX_DEQD_RETRIES 10
23 #define DEQUEUE_WAIT_TIME 10000
24
25 /*
26  * 30% extra size for compressed data compared to original data,
27  * in case data size cannot be reduced and it is actually bigger
28  * due to the compress block headers
29  */
30 #define COMPRESS_BUF_SIZE_RATIO 1.3
31 #define NUM_LARGE_MBUFS 16
32 #define SMALL_SEG_SIZE 256
33 #define MAX_SEGS 16
34 #define NUM_OPS 16
35 #define NUM_MAX_XFORMS 16
36 #define NUM_MAX_INFLIGHT_OPS 128
37 #define CACHE_SIZE 0
38
39 #define ZLIB_CRC_CHECKSUM_WINDOW_BITS 31
40 #define ZLIB_HEADER_SIZE 2
41 #define ZLIB_TRAILER_SIZE 4
42 #define GZIP_HEADER_SIZE 10
43 #define GZIP_TRAILER_SIZE 8
44
45 #define OUT_OF_SPACE_BUF 1
46
47 const char *
48 huffman_type_strings[] = {
49         [RTE_COMP_HUFFMAN_DEFAULT]      = "PMD default",
50         [RTE_COMP_HUFFMAN_FIXED]        = "Fixed",
51         [RTE_COMP_HUFFMAN_DYNAMIC]      = "Dynamic"
52 };
53
54 enum zlib_direction {
55         ZLIB_NONE,
56         ZLIB_COMPRESS,
57         ZLIB_DECOMPRESS,
58         ZLIB_ALL
59 };
60
61 enum varied_buff {
62         LB_BOTH = 0,    /* both input and output are linear*/
63         SGL_BOTH,       /* both input and output are chained */
64         SGL_TO_LB,      /* input buffer is chained */
65         LB_TO_SGL       /* output buffer is chained */
66 };
67
68 struct priv_op_data {
69         uint16_t orig_idx;
70 };
71
72 struct comp_testsuite_params {
73         struct rte_mempool *large_mbuf_pool;
74         struct rte_mempool *small_mbuf_pool;
75         struct rte_mempool *op_pool;
76         struct rte_comp_xform *def_comp_xform;
77         struct rte_comp_xform *def_decomp_xform;
78 };
79
80 struct interim_data_params {
81         const char * const *test_bufs;
82         unsigned int num_bufs;
83         uint16_t *buf_idx;
84         struct rte_comp_xform **compress_xforms;
85         struct rte_comp_xform **decompress_xforms;
86         unsigned int num_xforms;
87 };
88
89 struct test_data_params {
90         enum rte_comp_op_type state;
91         enum varied_buff buff_type;
92         enum zlib_direction zlib_dir;
93         unsigned int out_of_space;
94 };
95
96 static struct comp_testsuite_params testsuite_params = { 0 };
97
98 static void
99 testsuite_teardown(void)
100 {
101         struct comp_testsuite_params *ts_params = &testsuite_params;
102
103         if (rte_mempool_in_use_count(ts_params->large_mbuf_pool))
104                 RTE_LOG(ERR, USER1, "Large mbuf pool still has unfreed bufs\n");
105         if (rte_mempool_in_use_count(ts_params->small_mbuf_pool))
106                 RTE_LOG(ERR, USER1, "Small mbuf pool still has unfreed bufs\n");
107         if (rte_mempool_in_use_count(ts_params->op_pool))
108                 RTE_LOG(ERR, USER1, "op pool still has unfreed ops\n");
109
110         rte_mempool_free(ts_params->large_mbuf_pool);
111         rte_mempool_free(ts_params->small_mbuf_pool);
112         rte_mempool_free(ts_params->op_pool);
113         rte_free(ts_params->def_comp_xform);
114         rte_free(ts_params->def_decomp_xform);
115 }
116
117 static int
118 testsuite_setup(void)
119 {
120         struct comp_testsuite_params *ts_params = &testsuite_params;
121         uint32_t max_buf_size = 0;
122         unsigned int i;
123
124         if (rte_compressdev_count() == 0) {
125                 RTE_LOG(ERR, USER1, "Need at least one compress device\n");
126                 return TEST_FAILED;
127         }
128
129         RTE_LOG(NOTICE, USER1, "Running tests on device %s\n",
130                                 rte_compressdev_name_get(0));
131
132         for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
133                 max_buf_size = RTE_MAX(max_buf_size,
134                                 strlen(compress_test_bufs[i]) + 1);
135
136         /*
137          * Buffers to be used in compression and decompression.
138          * Since decompressed data might be larger than
139          * compressed data (due to block header),
140          * buffers should be big enough for both cases.
141          */
142         max_buf_size *= COMPRESS_BUF_SIZE_RATIO;
143         ts_params->large_mbuf_pool = rte_pktmbuf_pool_create("large_mbuf_pool",
144                         NUM_LARGE_MBUFS,
145                         CACHE_SIZE, 0,
146                         max_buf_size + RTE_PKTMBUF_HEADROOM,
147                         rte_socket_id());
148         if (ts_params->large_mbuf_pool == NULL) {
149                 RTE_LOG(ERR, USER1, "Large mbuf pool could not be created\n");
150                 return TEST_FAILED;
151         }
152
153         /* Create mempool with smaller buffers for SGL testing */
154         ts_params->small_mbuf_pool = rte_pktmbuf_pool_create("small_mbuf_pool",
155                         NUM_LARGE_MBUFS * MAX_SEGS,
156                         CACHE_SIZE, 0,
157                         SMALL_SEG_SIZE + RTE_PKTMBUF_HEADROOM,
158                         rte_socket_id());
159         if (ts_params->small_mbuf_pool == NULL) {
160                 RTE_LOG(ERR, USER1, "Small mbuf pool could not be created\n");
161                 goto exit;
162         }
163
164         ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
165                                 0, sizeof(struct priv_op_data),
166                                 rte_socket_id());
167         if (ts_params->op_pool == NULL) {
168                 RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
169                 goto exit;
170         }
171
172         ts_params->def_comp_xform =
173                         rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
174         if (ts_params->def_comp_xform == NULL) {
175                 RTE_LOG(ERR, USER1,
176                         "Default compress xform could not be created\n");
177                 goto exit;
178         }
179         ts_params->def_decomp_xform =
180                         rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
181         if (ts_params->def_decomp_xform == NULL) {
182                 RTE_LOG(ERR, USER1,
183                         "Default decompress xform could not be created\n");
184                 goto exit;
185         }
186
187         /* Initializes default values for compress/decompress xforms */
188         ts_params->def_comp_xform->type = RTE_COMP_COMPRESS;
189         ts_params->def_comp_xform->compress.algo = RTE_COMP_ALGO_DEFLATE,
190         ts_params->def_comp_xform->compress.deflate.huffman =
191                                                 RTE_COMP_HUFFMAN_DEFAULT;
192         ts_params->def_comp_xform->compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
193         ts_params->def_comp_xform->compress.chksum = RTE_COMP_CHECKSUM_NONE;
194         ts_params->def_comp_xform->compress.window_size = DEFAULT_WINDOW_SIZE;
195
196         ts_params->def_decomp_xform->type = RTE_COMP_DECOMPRESS;
197         ts_params->def_decomp_xform->decompress.algo = RTE_COMP_ALGO_DEFLATE,
198         ts_params->def_decomp_xform->decompress.chksum = RTE_COMP_CHECKSUM_NONE;
199         ts_params->def_decomp_xform->decompress.window_size = DEFAULT_WINDOW_SIZE;
200
201         return TEST_SUCCESS;
202
203 exit:
204         testsuite_teardown();
205
206         return TEST_FAILED;
207 }
208
209 static int
210 generic_ut_setup(void)
211 {
212         /* Configure compressdev (one device, one queue pair) */
213         struct rte_compressdev_config config = {
214                 .socket_id = rte_socket_id(),
215                 .nb_queue_pairs = 1,
216                 .max_nb_priv_xforms = NUM_MAX_XFORMS,
217                 .max_nb_streams = 0
218         };
219
220         if (rte_compressdev_configure(0, &config) < 0) {
221                 RTE_LOG(ERR, USER1, "Device configuration failed\n");
222                 return -1;
223         }
224
225         if (rte_compressdev_queue_pair_setup(0, 0, NUM_MAX_INFLIGHT_OPS,
226                         rte_socket_id()) < 0) {
227                 RTE_LOG(ERR, USER1, "Queue pair setup failed\n");
228                 return -1;
229         }
230
231         if (rte_compressdev_start(0) < 0) {
232                 RTE_LOG(ERR, USER1, "Device could not be started\n");
233                 return -1;
234         }
235
236         return 0;
237 }
238
239 static void
240 generic_ut_teardown(void)
241 {
242         rte_compressdev_stop(0);
243         if (rte_compressdev_close(0) < 0)
244                 RTE_LOG(ERR, USER1, "Device could not be closed\n");
245 }
246
247 static int
248 test_compressdev_invalid_configuration(void)
249 {
250         struct rte_compressdev_config invalid_config;
251         struct rte_compressdev_config valid_config = {
252                 .socket_id = rte_socket_id(),
253                 .nb_queue_pairs = 1,
254                 .max_nb_priv_xforms = NUM_MAX_XFORMS,
255                 .max_nb_streams = 0
256         };
257         struct rte_compressdev_info dev_info;
258
259         /* Invalid configuration with 0 queue pairs */
260         memcpy(&invalid_config, &valid_config,
261                         sizeof(struct rte_compressdev_config));
262         invalid_config.nb_queue_pairs = 0;
263
264         TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
265                         "Device configuration was successful "
266                         "with no queue pairs (invalid)\n");
267
268         /*
269          * Invalid configuration with too many queue pairs
270          * (if there is an actual maximum number of queue pairs)
271          */
272         rte_compressdev_info_get(0, &dev_info);
273         if (dev_info.max_nb_queue_pairs != 0) {
274                 memcpy(&invalid_config, &valid_config,
275                         sizeof(struct rte_compressdev_config));
276                 invalid_config.nb_queue_pairs = dev_info.max_nb_queue_pairs + 1;
277
278                 TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
279                                 "Device configuration was successful "
280                                 "with too many queue pairs (invalid)\n");
281         }
282
283         /* Invalid queue pair setup, with no number of queue pairs set */
284         TEST_ASSERT_FAIL(rte_compressdev_queue_pair_setup(0, 0,
285                                 NUM_MAX_INFLIGHT_OPS, rte_socket_id()),
286                         "Queue pair setup was successful "
287                         "with no queue pairs set (invalid)\n");
288
289         return TEST_SUCCESS;
290 }
291
292 static int
293 compare_buffers(const char *buffer1, uint32_t buffer1_len,
294                 const char *buffer2, uint32_t buffer2_len)
295 {
296         if (buffer1_len != buffer2_len) {
297                 RTE_LOG(ERR, USER1, "Buffer lengths are different\n");
298                 return -1;
299         }
300
301         if (memcmp(buffer1, buffer2, buffer1_len) != 0) {
302                 RTE_LOG(ERR, USER1, "Buffers are different\n");
303                 return -1;
304         }
305
306         return 0;
307 }
308
309 /*
310  * Maps compressdev and Zlib flush flags
311  */
312 static int
313 map_zlib_flush_flag(enum rte_comp_flush_flag flag)
314 {
315         switch (flag) {
316         case RTE_COMP_FLUSH_NONE:
317                 return Z_NO_FLUSH;
318         case RTE_COMP_FLUSH_SYNC:
319                 return Z_SYNC_FLUSH;
320         case RTE_COMP_FLUSH_FULL:
321                 return Z_FULL_FLUSH;
322         case RTE_COMP_FLUSH_FINAL:
323                 return Z_FINISH;
324         /*
325          * There should be only the values above,
326          * so this should never happen
327          */
328         default:
329                 return -1;
330         }
331 }
332
333 static int
334 compress_zlib(struct rte_comp_op *op,
335                 const struct rte_comp_xform *xform, int mem_level)
336 {
337         z_stream stream;
338         int zlib_flush;
339         int strategy, window_bits, comp_level;
340         int ret = TEST_FAILED;
341         uint8_t *single_src_buf = NULL;
342         uint8_t *single_dst_buf = NULL;
343
344         /* initialize zlib stream */
345         stream.zalloc = Z_NULL;
346         stream.zfree = Z_NULL;
347         stream.opaque = Z_NULL;
348
349         if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED)
350                 strategy = Z_FIXED;
351         else
352                 strategy = Z_DEFAULT_STRATEGY;
353
354         /*
355          * Window bits is the base two logarithm of the window size (in bytes).
356          * When doing raw DEFLATE, this number will be negative.
357          */
358         window_bits = -(xform->compress.window_size);
359         if (xform->compress.chksum == RTE_COMP_CHECKSUM_ADLER32)
360                 window_bits *= -1;
361         else if (xform->compress.chksum == RTE_COMP_CHECKSUM_CRC32)
362                 window_bits = ZLIB_CRC_CHECKSUM_WINDOW_BITS;
363
364         comp_level = xform->compress.level;
365
366         if (comp_level != RTE_COMP_LEVEL_NONE)
367                 ret = deflateInit2(&stream, comp_level, Z_DEFLATED,
368                         window_bits, mem_level, strategy);
369         else
370                 ret = deflateInit(&stream, Z_NO_COMPRESSION);
371
372         if (ret != Z_OK) {
373                 printf("Zlib deflate could not be initialized\n");
374                 goto exit;
375         }
376
377         /* Assuming stateless operation */
378         /* SGL Input */
379         if (op->m_src->nb_segs > 1) {
380                 single_src_buf = rte_malloc(NULL,
381                                 rte_pktmbuf_pkt_len(op->m_src), 0);
382                 if (single_src_buf == NULL) {
383                         RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
384                         goto exit;
385                 }
386
387                 if (rte_pktmbuf_read(op->m_src, op->src.offset,
388                                         rte_pktmbuf_pkt_len(op->m_src) -
389                                         op->src.offset,
390                                         single_src_buf) == NULL) {
391                         RTE_LOG(ERR, USER1,
392                                 "Buffer could not be read entirely\n");
393                         goto exit;
394                 }
395
396                 stream.avail_in = op->src.length;
397                 stream.next_in = single_src_buf;
398
399         } else {
400                 stream.avail_in = op->src.length;
401                 stream.next_in = rte_pktmbuf_mtod_offset(op->m_src, uint8_t *,
402                                 op->src.offset);
403         }
404         /* SGL output */
405         if (op->m_dst->nb_segs > 1) {
406
407                 single_dst_buf = rte_malloc(NULL,
408                                 rte_pktmbuf_pkt_len(op->m_dst), 0);
409                         if (single_dst_buf == NULL) {
410                                 RTE_LOG(ERR, USER1,
411                                         "Buffer could not be allocated\n");
412                         goto exit;
413                 }
414
415                 stream.avail_out = op->m_dst->pkt_len;
416                 stream.next_out = single_dst_buf;
417
418         } else {/* linear output */
419                 stream.avail_out = op->m_dst->data_len;
420                 stream.next_out = rte_pktmbuf_mtod_offset(op->m_dst, uint8_t *,
421                                 op->dst.offset);
422         }
423
424         /* Stateless operation, all buffer will be compressed in one go */
425         zlib_flush = map_zlib_flush_flag(op->flush_flag);
426         ret = deflate(&stream, zlib_flush);
427
428         if (stream.avail_in != 0) {
429                 RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
430                 goto exit;
431         }
432
433         if (ret != Z_STREAM_END)
434                 goto exit;
435
436         /* Copy data to destination SGL */
437         if (op->m_dst->nb_segs > 1) {
438                 uint32_t remaining_data = stream.total_out;
439                 uint8_t *src_data = single_dst_buf;
440                 struct rte_mbuf *dst_buf = op->m_dst;
441
442                 while (remaining_data > 0) {
443                         uint8_t *dst_data = rte_pktmbuf_mtod_offset(dst_buf,
444                                                 uint8_t *, op->dst.offset);
445                         /* Last segment */
446                         if (remaining_data < dst_buf->data_len) {
447                                 memcpy(dst_data, src_data, remaining_data);
448                                 remaining_data = 0;
449                         } else {
450                                 memcpy(dst_data, src_data, dst_buf->data_len);
451                                 remaining_data -= dst_buf->data_len;
452                                 src_data += dst_buf->data_len;
453                                 dst_buf = dst_buf->next;
454                         }
455                 }
456         }
457
458         op->consumed = stream.total_in;
459         if (xform->compress.chksum == RTE_COMP_CHECKSUM_ADLER32) {
460                 rte_pktmbuf_adj(op->m_dst, ZLIB_HEADER_SIZE);
461                 rte_pktmbuf_trim(op->m_dst, ZLIB_TRAILER_SIZE);
462                 op->produced = stream.total_out - (ZLIB_HEADER_SIZE +
463                                 ZLIB_TRAILER_SIZE);
464         } else if (xform->compress.chksum == RTE_COMP_CHECKSUM_CRC32) {
465                 rte_pktmbuf_adj(op->m_dst, GZIP_HEADER_SIZE);
466                 rte_pktmbuf_trim(op->m_dst, GZIP_TRAILER_SIZE);
467                 op->produced = stream.total_out - (GZIP_HEADER_SIZE +
468                                 GZIP_TRAILER_SIZE);
469         } else
470                 op->produced = stream.total_out;
471
472         op->status = RTE_COMP_OP_STATUS_SUCCESS;
473         op->output_chksum = stream.adler;
474
475         deflateReset(&stream);
476
477         ret = 0;
478 exit:
479         deflateEnd(&stream);
480         rte_free(single_src_buf);
481         rte_free(single_dst_buf);
482
483         return ret;
484 }
485
486 static int
487 decompress_zlib(struct rte_comp_op *op,
488                 const struct rte_comp_xform *xform)
489 {
490         z_stream stream;
491         int window_bits;
492         int zlib_flush;
493         int ret = TEST_FAILED;
494         uint8_t *single_src_buf = NULL;
495         uint8_t *single_dst_buf = NULL;
496
497         /* initialize zlib stream */
498         stream.zalloc = Z_NULL;
499         stream.zfree = Z_NULL;
500         stream.opaque = Z_NULL;
501
502         /*
503          * Window bits is the base two logarithm of the window size (in bytes).
504          * When doing raw DEFLATE, this number will be negative.
505          */
506         window_bits = -(xform->decompress.window_size);
507         ret = inflateInit2(&stream, window_bits);
508
509         if (ret != Z_OK) {
510                 printf("Zlib deflate could not be initialized\n");
511                 goto exit;
512         }
513
514         /* Assuming stateless operation */
515         /* SGL */
516         if (op->m_src->nb_segs > 1) {
517                 single_src_buf = rte_malloc(NULL,
518                                 rte_pktmbuf_pkt_len(op->m_src), 0);
519                 if (single_src_buf == NULL) {
520                         RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
521                         goto exit;
522                 }
523                 single_dst_buf = rte_malloc(NULL,
524                                 rte_pktmbuf_pkt_len(op->m_dst), 0);
525                 if (single_dst_buf == NULL) {
526                         RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
527                         goto exit;
528                 }
529                 if (rte_pktmbuf_read(op->m_src, 0,
530                                         rte_pktmbuf_pkt_len(op->m_src),
531                                         single_src_buf) == NULL) {
532                         RTE_LOG(ERR, USER1,
533                                 "Buffer could not be read entirely\n");
534                         goto exit;
535                 }
536
537                 stream.avail_in = op->src.length;
538                 stream.next_in = single_src_buf;
539                 stream.avail_out = rte_pktmbuf_pkt_len(op->m_dst);
540                 stream.next_out = single_dst_buf;
541
542         } else {
543                 stream.avail_in = op->src.length;
544                 stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
545                 stream.avail_out = op->m_dst->data_len;
546                 stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
547         }
548
549         /* Stateless operation, all buffer will be compressed in one go */
550         zlib_flush = map_zlib_flush_flag(op->flush_flag);
551         ret = inflate(&stream, zlib_flush);
552
553         if (stream.avail_in != 0) {
554                 RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
555                 goto exit;
556         }
557
558         if (ret != Z_STREAM_END)
559                 goto exit;
560
561         if (op->m_src->nb_segs > 1) {
562                 uint32_t remaining_data = stream.total_out;
563                 uint8_t *src_data = single_dst_buf;
564                 struct rte_mbuf *dst_buf = op->m_dst;
565
566                 while (remaining_data > 0) {
567                         uint8_t *dst_data = rte_pktmbuf_mtod(dst_buf,
568                                         uint8_t *);
569                         /* Last segment */
570                         if (remaining_data < dst_buf->data_len) {
571                                 memcpy(dst_data, src_data, remaining_data);
572                                 remaining_data = 0;
573                         } else {
574                                 memcpy(dst_data, src_data, dst_buf->data_len);
575                                 remaining_data -= dst_buf->data_len;
576                                 src_data += dst_buf->data_len;
577                                 dst_buf = dst_buf->next;
578                         }
579                 }
580         }
581
582         op->consumed = stream.total_in;
583         op->produced = stream.total_out;
584         op->status = RTE_COMP_OP_STATUS_SUCCESS;
585
586         inflateReset(&stream);
587
588         ret = 0;
589 exit:
590         inflateEnd(&stream);
591
592         return ret;
593 }
594
595 static int
596 prepare_sgl_bufs(const char *test_buf, struct rte_mbuf *head_buf,
597                 uint32_t total_data_size,
598                 struct rte_mempool *small_mbuf_pool,
599                 struct rte_mempool *large_mbuf_pool,
600                 uint8_t limit_segs_in_sgl)
601 {
602         uint32_t remaining_data = total_data_size;
603         uint16_t num_remaining_segs = DIV_CEIL(remaining_data, SMALL_SEG_SIZE);
604         struct rte_mempool *pool;
605         struct rte_mbuf *next_seg;
606         uint32_t data_size;
607         char *buf_ptr;
608         const char *data_ptr = test_buf;
609         uint16_t i;
610         int ret;
611
612         if (limit_segs_in_sgl != 0 && num_remaining_segs > limit_segs_in_sgl)
613                 num_remaining_segs = limit_segs_in_sgl - 1;
614
615         /*
616          * Allocate data in the first segment (header) and
617          * copy data if test buffer is provided
618          */
619         if (remaining_data < SMALL_SEG_SIZE)
620                 data_size = remaining_data;
621         else
622                 data_size = SMALL_SEG_SIZE;
623         buf_ptr = rte_pktmbuf_append(head_buf, data_size);
624         if (buf_ptr == NULL) {
625                 RTE_LOG(ERR, USER1,
626                         "Not enough space in the 1st buffer\n");
627                 return -1;
628         }
629
630         if (data_ptr != NULL) {
631                 /* Copy characters without NULL terminator */
632                 strncpy(buf_ptr, data_ptr, data_size);
633                 data_ptr += data_size;
634         }
635         remaining_data -= data_size;
636         num_remaining_segs--;
637
638         /*
639          * Allocate the rest of the segments,
640          * copy the rest of the data and chain the segments.
641          */
642         for (i = 0; i < num_remaining_segs; i++) {
643
644                 if (i == (num_remaining_segs - 1)) {
645                         /* last segment */
646                         if (remaining_data > SMALL_SEG_SIZE)
647                                 pool = large_mbuf_pool;
648                         else
649                                 pool = small_mbuf_pool;
650                         data_size = remaining_data;
651                 } else {
652                         data_size = SMALL_SEG_SIZE;
653                         pool = small_mbuf_pool;
654                 }
655
656                 next_seg = rte_pktmbuf_alloc(pool);
657                 if (next_seg == NULL) {
658                         RTE_LOG(ERR, USER1,
659                                 "New segment could not be allocated "
660                                 "from the mempool\n");
661                         return -1;
662                 }
663                 buf_ptr = rte_pktmbuf_append(next_seg, data_size);
664                 if (buf_ptr == NULL) {
665                         RTE_LOG(ERR, USER1,
666                                 "Not enough space in the buffer\n");
667                         rte_pktmbuf_free(next_seg);
668                         return -1;
669                 }
670                 if (data_ptr != NULL) {
671                         /* Copy characters without NULL terminator */
672                         strncpy(buf_ptr, data_ptr, data_size);
673                         data_ptr += data_size;
674                 }
675                 remaining_data -= data_size;
676
677                 ret = rte_pktmbuf_chain(head_buf, next_seg);
678                 if (ret != 0) {
679                         rte_pktmbuf_free(next_seg);
680                         RTE_LOG(ERR, USER1,
681                                 "Segment could not chained\n");
682                         return -1;
683                 }
684         }
685
686         return 0;
687 }
688
689 /*
690  * Compresses and decompresses buffer with compressdev API and Zlib API
691  */
692 static int
693 test_deflate_comp_decomp(const struct interim_data_params *int_data,
694                 const struct test_data_params *test_data)
695 {
696         struct comp_testsuite_params *ts_params = &testsuite_params;
697         const char * const *test_bufs = int_data->test_bufs;
698         unsigned int num_bufs = int_data->num_bufs;
699         uint16_t *buf_idx = int_data->buf_idx;
700         struct rte_comp_xform **compress_xforms = int_data->compress_xforms;
701         struct rte_comp_xform **decompress_xforms = int_data->decompress_xforms;
702         unsigned int num_xforms = int_data->num_xforms;
703         enum rte_comp_op_type state = test_data->state;
704         unsigned int buff_type = test_data->buff_type;
705         unsigned int out_of_space = test_data->out_of_space;
706         enum zlib_direction zlib_dir = test_data->zlib_dir;
707         int ret_status = -1;
708         int ret;
709         struct rte_mbuf *uncomp_bufs[num_bufs];
710         struct rte_mbuf *comp_bufs[num_bufs];
711         struct rte_comp_op *ops[num_bufs];
712         struct rte_comp_op *ops_processed[num_bufs];
713         void *priv_xforms[num_bufs];
714         uint16_t num_enqd, num_deqd, num_total_deqd;
715         uint16_t num_priv_xforms = 0;
716         unsigned int deqd_retries = 0;
717         struct priv_op_data *priv_data;
718         char *buf_ptr;
719         unsigned int i;
720         struct rte_mempool *buf_pool;
721         uint32_t data_size;
722         /* Compressing with CompressDev */
723         unsigned int oos_zlib_decompress =
724                         (zlib_dir == ZLIB_NONE || zlib_dir == ZLIB_DECOMPRESS);
725         /* Decompressing with CompressDev */
726         unsigned int oos_zlib_compress =
727                         (zlib_dir == ZLIB_NONE || zlib_dir == ZLIB_COMPRESS);
728         const struct rte_compressdev_capabilities *capa =
729                 rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
730         char *contig_buf = NULL;
731         uint64_t compress_checksum[num_bufs];
732
733         /* Initialize all arrays to NULL */
734         memset(uncomp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
735         memset(comp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
736         memset(ops, 0, sizeof(struct rte_comp_op *) * num_bufs);
737         memset(ops_processed, 0, sizeof(struct rte_comp_op *) * num_bufs);
738         memset(priv_xforms, 0, sizeof(void *) * num_bufs);
739
740         if (buff_type == SGL_BOTH)
741                 buf_pool = ts_params->small_mbuf_pool;
742         else
743                 buf_pool = ts_params->large_mbuf_pool;
744
745         /* Prepare the source mbufs with the data */
746         ret = rte_pktmbuf_alloc_bulk(buf_pool,
747                                 uncomp_bufs, num_bufs);
748         if (ret < 0) {
749                 RTE_LOG(ERR, USER1,
750                         "Source mbufs could not be allocated "
751                         "from the mempool\n");
752                 goto exit;
753         }
754
755         if (buff_type == SGL_BOTH || buff_type == SGL_TO_LB) {
756                 for (i = 0; i < num_bufs; i++) {
757                         data_size = strlen(test_bufs[i]) + 1;
758                         if (prepare_sgl_bufs(test_bufs[i], uncomp_bufs[i],
759                                         data_size,
760                                         ts_params->small_mbuf_pool,
761                                         ts_params->large_mbuf_pool,
762                                         MAX_SEGS) < 0)
763                                 goto exit;
764                 }
765         } else {
766                 for (i = 0; i < num_bufs; i++) {
767                         data_size = strlen(test_bufs[i]) + 1;
768                         buf_ptr = rte_pktmbuf_append(uncomp_bufs[i], data_size);
769                         snprintf(buf_ptr, data_size, "%s", test_bufs[i]);
770                 }
771         }
772
773         /* Prepare the destination mbufs */
774         ret = rte_pktmbuf_alloc_bulk(buf_pool, comp_bufs, num_bufs);
775         if (ret < 0) {
776                 RTE_LOG(ERR, USER1,
777                         "Destination mbufs could not be allocated "
778                         "from the mempool\n");
779                 goto exit;
780         }
781
782         if (buff_type == SGL_BOTH || buff_type == LB_TO_SGL) {
783                 for (i = 0; i < num_bufs; i++) {
784                         if (out_of_space == 1 && oos_zlib_decompress)
785                                 data_size = OUT_OF_SPACE_BUF;
786                         else
787                                 (data_size = strlen(test_bufs[i]) *
788                                         COMPRESS_BUF_SIZE_RATIO);
789
790                         if (prepare_sgl_bufs(NULL, comp_bufs[i],
791                                         data_size,
792                                         ts_params->small_mbuf_pool,
793                                         ts_params->large_mbuf_pool,
794                                         MAX_SEGS) < 0)
795                                 goto exit;
796                 }
797
798         } else {
799                 for (i = 0; i < num_bufs; i++) {
800                         if (out_of_space == 1 && oos_zlib_decompress)
801                                 data_size = OUT_OF_SPACE_BUF;
802                         else
803                                 (data_size = strlen(test_bufs[i]) *
804                                         COMPRESS_BUF_SIZE_RATIO);
805
806                         rte_pktmbuf_append(comp_bufs[i], data_size);
807                 }
808         }
809
810         /* Build the compression operations */
811         ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
812         if (ret < 0) {
813                 RTE_LOG(ERR, USER1,
814                         "Compress operations could not be allocated "
815                         "from the mempool\n");
816                 goto exit;
817         }
818
819
820         for (i = 0; i < num_bufs; i++) {
821                 ops[i]->m_src = uncomp_bufs[i];
822                 ops[i]->m_dst = comp_bufs[i];
823                 ops[i]->src.offset = 0;
824                 ops[i]->src.length = rte_pktmbuf_pkt_len(uncomp_bufs[i]);
825                 ops[i]->dst.offset = 0;
826                 if (state == RTE_COMP_OP_STATELESS) {
827                         ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
828                 } else {
829                         RTE_LOG(ERR, USER1,
830                                 "Stateful operations are not supported "
831                                 "in these tests yet\n");
832                         goto exit;
833                 }
834                 ops[i]->input_chksum = 0;
835                 /*
836                  * Store original operation index in private data,
837                  * since ordering does not have to be maintained,
838                  * when dequeueing from compressdev, so a comparison
839                  * at the end of the test can be done.
840                  */
841                 priv_data = (struct priv_op_data *) (ops[i] + 1);
842                 priv_data->orig_idx = i;
843         }
844
845         /* Compress data (either with Zlib API or compressdev API */
846         if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
847                 for (i = 0; i < num_bufs; i++) {
848                         const struct rte_comp_xform *compress_xform =
849                                 compress_xforms[i % num_xforms];
850                         ret = compress_zlib(ops[i], compress_xform,
851                                         DEFAULT_MEM_LEVEL);
852                         if (ret < 0)
853                                 goto exit;
854
855                         ops_processed[i] = ops[i];
856                 }
857         } else {
858                 /* Create compress private xform data */
859                 for (i = 0; i < num_xforms; i++) {
860                         ret = rte_compressdev_private_xform_create(0,
861                                 (const struct rte_comp_xform *)compress_xforms[i],
862                                 &priv_xforms[i]);
863                         if (ret < 0) {
864                                 RTE_LOG(ERR, USER1,
865                                         "Compression private xform "
866                                         "could not be created\n");
867                                 goto exit;
868                         }
869                         num_priv_xforms++;
870                 }
871
872                 if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
873                         /* Attach shareable private xform data to ops */
874                         for (i = 0; i < num_bufs; i++)
875                                 ops[i]->private_xform = priv_xforms[i % num_xforms];
876                 } else {
877                         /* Create rest of the private xforms for the other ops */
878                         for (i = num_xforms; i < num_bufs; i++) {
879                                 ret = rte_compressdev_private_xform_create(0,
880                                         compress_xforms[i % num_xforms],
881                                         &priv_xforms[i]);
882                                 if (ret < 0) {
883                                         RTE_LOG(ERR, USER1,
884                                                 "Compression private xform "
885                                                 "could not be created\n");
886                                         goto exit;
887                                 }
888                                 num_priv_xforms++;
889                         }
890
891                         /* Attach non shareable private xform data to ops */
892                         for (i = 0; i < num_bufs; i++)
893                                 ops[i]->private_xform = priv_xforms[i];
894                 }
895
896                 /* Enqueue and dequeue all operations */
897                 num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
898                 if (num_enqd < num_bufs) {
899                         RTE_LOG(ERR, USER1,
900                                 "The operations could not be enqueued\n");
901                         goto exit;
902                 }
903
904                 num_total_deqd = 0;
905                 do {
906                         /*
907                          * If retrying a dequeue call, wait for 10 ms to allow
908                          * enough time to the driver to process the operations
909                          */
910                         if (deqd_retries != 0) {
911                                 /*
912                                  * Avoid infinite loop if not all the
913                                  * operations get out of the device
914                                  */
915                                 if (deqd_retries == MAX_DEQD_RETRIES) {
916                                         RTE_LOG(ERR, USER1,
917                                                 "Not all operations could be "
918                                                 "dequeued\n");
919                                         goto exit;
920                                 }
921                                 usleep(DEQUEUE_WAIT_TIME);
922                         }
923                         num_deqd = rte_compressdev_dequeue_burst(0, 0,
924                                         &ops_processed[num_total_deqd], num_bufs);
925                         num_total_deqd += num_deqd;
926                         deqd_retries++;
927
928                 } while (num_total_deqd < num_enqd);
929
930                 deqd_retries = 0;
931
932                 /* Free compress private xforms */
933                 for (i = 0; i < num_priv_xforms; i++) {
934                         rte_compressdev_private_xform_free(0, priv_xforms[i]);
935                         priv_xforms[i] = NULL;
936                 }
937                 num_priv_xforms = 0;
938         }
939
940         for (i = 0; i < num_bufs; i++) {
941                 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
942                 uint16_t xform_idx = priv_data->orig_idx % num_xforms;
943                 const struct rte_comp_compress_xform *compress_xform =
944                                 &compress_xforms[xform_idx]->compress;
945                 enum rte_comp_huffman huffman_type =
946                         compress_xform->deflate.huffman;
947                 char engine[] = "zlib (directly, not PMD)";
948                 if (zlib_dir != ZLIB_COMPRESS || zlib_dir != ZLIB_ALL)
949                         strlcpy(engine, "PMD", sizeof(engine));
950
951                 RTE_LOG(DEBUG, USER1, "Buffer %u compressed by %s from %u to"
952                         " %u bytes (level = %d, huffman = %s)\n",
953                         buf_idx[priv_data->orig_idx], engine,
954                         ops_processed[i]->consumed, ops_processed[i]->produced,
955                         compress_xform->level,
956                         huffman_type_strings[huffman_type]);
957                 RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f\n",
958                         ops_processed[i]->consumed == 0 ? 0 :
959                         (float)ops_processed[i]->produced /
960                         ops_processed[i]->consumed * 100);
961                 if (compress_xform->chksum != RTE_COMP_CHECKSUM_NONE)
962                         compress_checksum[i] = ops_processed[i]->output_chksum;
963                 ops[i] = NULL;
964         }
965
966         /*
967          * Check operation status and free source mbufs (destination mbuf and
968          * compress operation information is needed for the decompression stage)
969          */
970         for (i = 0; i < num_bufs; i++) {
971                 if (out_of_space && oos_zlib_decompress) {
972                         if (ops_processed[i]->status !=
973                                         RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED) {
974                                 ret_status = -1;
975
976                                 RTE_LOG(ERR, USER1,
977                                         "Operation without expected out of "
978                                         "space status error\n");
979                                 goto exit;
980                         } else
981                                 continue;
982                 }
983
984                 if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
985                         RTE_LOG(ERR, USER1,
986                                 "Some operations were not successful\n");
987                         goto exit;
988                 }
989                 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
990                 rte_pktmbuf_free(uncomp_bufs[priv_data->orig_idx]);
991                 uncomp_bufs[priv_data->orig_idx] = NULL;
992         }
993
994         if (out_of_space && oos_zlib_decompress) {
995                 ret_status = 0;
996                 goto exit;
997         }
998
999         /* Allocate buffers for decompressed data */
1000         ret = rte_pktmbuf_alloc_bulk(buf_pool, uncomp_bufs, num_bufs);
1001         if (ret < 0) {
1002                 RTE_LOG(ERR, USER1,
1003                         "Destination mbufs could not be allocated "
1004                         "from the mempool\n");
1005                 goto exit;
1006         }
1007
1008         if (buff_type == SGL_BOTH || buff_type == LB_TO_SGL) {
1009                 for (i = 0; i < num_bufs; i++) {
1010                         priv_data = (struct priv_op_data *)
1011                                         (ops_processed[i] + 1);
1012                         if (out_of_space == 1 && oos_zlib_compress)
1013                                 data_size = OUT_OF_SPACE_BUF;
1014                         else
1015                                 data_size =
1016                                 strlen(test_bufs[priv_data->orig_idx]) + 1;
1017
1018                         if (prepare_sgl_bufs(NULL, uncomp_bufs[i],
1019                                         data_size,
1020                                         ts_params->small_mbuf_pool,
1021                                         ts_params->large_mbuf_pool,
1022                                         MAX_SEGS) < 0)
1023                                 goto exit;
1024                 }
1025
1026         } else {
1027                 for (i = 0; i < num_bufs; i++) {
1028                         priv_data = (struct priv_op_data *)
1029                                         (ops_processed[i] + 1);
1030                         if (out_of_space == 1 && oos_zlib_compress)
1031                                 data_size = OUT_OF_SPACE_BUF;
1032                         else
1033                                 data_size =
1034                                 strlen(test_bufs[priv_data->orig_idx]) + 1;
1035
1036                         rte_pktmbuf_append(uncomp_bufs[i], data_size);
1037                 }
1038         }
1039
1040         /* Build the decompression operations */
1041         ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
1042         if (ret < 0) {
1043                 RTE_LOG(ERR, USER1,
1044                         "Decompress operations could not be allocated "
1045                         "from the mempool\n");
1046                 goto exit;
1047         }
1048
1049         /* Source buffer is the compressed data from the previous operations */
1050         for (i = 0; i < num_bufs; i++) {
1051                 ops[i]->m_src = ops_processed[i]->m_dst;
1052                 ops[i]->m_dst = uncomp_bufs[i];
1053                 ops[i]->src.offset = 0;
1054                 /*
1055                  * Set the length of the compressed data to the
1056                  * number of bytes that were produced in the previous stage
1057                  */
1058                 ops[i]->src.length = ops_processed[i]->produced;
1059                 ops[i]->dst.offset = 0;
1060                 if (state == RTE_COMP_OP_STATELESS) {
1061                         ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
1062                 } else {
1063                         RTE_LOG(ERR, USER1,
1064                                 "Stateful operations are not supported "
1065                                 "in these tests yet\n");
1066                         goto exit;
1067                 }
1068                 ops[i]->input_chksum = 0;
1069                 /*
1070                  * Copy private data from previous operations,
1071                  * to keep the pointer to the original buffer
1072                  */
1073                 memcpy(ops[i] + 1, ops_processed[i] + 1,
1074                                 sizeof(struct priv_op_data));
1075         }
1076
1077         /*
1078          * Free the previous compress operations,
1079          * as they are not needed anymore
1080          */
1081         rte_comp_op_bulk_free(ops_processed, num_bufs);
1082
1083         /* Decompress data (either with Zlib API or compressdev API */
1084         if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
1085                 for (i = 0; i < num_bufs; i++) {
1086                         priv_data = (struct priv_op_data *)(ops[i] + 1);
1087                         uint16_t xform_idx = priv_data->orig_idx % num_xforms;
1088                         const struct rte_comp_xform *decompress_xform =
1089                                 decompress_xforms[xform_idx];
1090
1091                         ret = decompress_zlib(ops[i], decompress_xform);
1092                         if (ret < 0)
1093                                 goto exit;
1094
1095                         ops_processed[i] = ops[i];
1096                 }
1097         } else {
1098                 /* Create decompress private xform data */
1099                 for (i = 0; i < num_xforms; i++) {
1100                         ret = rte_compressdev_private_xform_create(0,
1101                                 (const struct rte_comp_xform *)decompress_xforms[i],
1102                                 &priv_xforms[i]);
1103                         if (ret < 0) {
1104                                 RTE_LOG(ERR, USER1,
1105                                         "Decompression private xform "
1106                                         "could not be created\n");
1107                                 goto exit;
1108                         }
1109                         num_priv_xforms++;
1110                 }
1111
1112                 if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
1113                         /* Attach shareable private xform data to ops */
1114                         for (i = 0; i < num_bufs; i++) {
1115                                 priv_data = (struct priv_op_data *)(ops[i] + 1);
1116                                 uint16_t xform_idx = priv_data->orig_idx %
1117                                                                 num_xforms;
1118                                 ops[i]->private_xform = priv_xforms[xform_idx];
1119                         }
1120                 } else {
1121                         /* Create rest of the private xforms for the other ops */
1122                         for (i = num_xforms; i < num_bufs; i++) {
1123                                 ret = rte_compressdev_private_xform_create(0,
1124                                         decompress_xforms[i % num_xforms],
1125                                         &priv_xforms[i]);
1126                                 if (ret < 0) {
1127                                         RTE_LOG(ERR, USER1,
1128                                                 "Decompression private xform "
1129                                                 "could not be created\n");
1130                                         goto exit;
1131                                 }
1132                                 num_priv_xforms++;
1133                         }
1134
1135                         /* Attach non shareable private xform data to ops */
1136                         for (i = 0; i < num_bufs; i++) {
1137                                 priv_data = (struct priv_op_data *)(ops[i] + 1);
1138                                 uint16_t xform_idx = priv_data->orig_idx;
1139                                 ops[i]->private_xform = priv_xforms[xform_idx];
1140                         }
1141                 }
1142
1143                 /* Enqueue and dequeue all operations */
1144                 num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
1145                 if (num_enqd < num_bufs) {
1146                         RTE_LOG(ERR, USER1,
1147                                 "The operations could not be enqueued\n");
1148                         goto exit;
1149                 }
1150
1151                 num_total_deqd = 0;
1152                 do {
1153                         /*
1154                          * If retrying a dequeue call, wait for 10 ms to allow
1155                          * enough time to the driver to process the operations
1156                          */
1157                         if (deqd_retries != 0) {
1158                                 /*
1159                                  * Avoid infinite loop if not all the
1160                                  * operations get out of the device
1161                                  */
1162                                 if (deqd_retries == MAX_DEQD_RETRIES) {
1163                                         RTE_LOG(ERR, USER1,
1164                                                 "Not all operations could be "
1165                                                 "dequeued\n");
1166                                         goto exit;
1167                                 }
1168                                 usleep(DEQUEUE_WAIT_TIME);
1169                         }
1170                         num_deqd = rte_compressdev_dequeue_burst(0, 0,
1171                                         &ops_processed[num_total_deqd], num_bufs);
1172                         num_total_deqd += num_deqd;
1173                         deqd_retries++;
1174                 } while (num_total_deqd < num_enqd);
1175
1176                 deqd_retries = 0;
1177         }
1178
1179         for (i = 0; i < num_bufs; i++) {
1180                 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
1181                 char engine[] = "zlib, (directly, no PMD)";
1182                 if (zlib_dir != ZLIB_DECOMPRESS || zlib_dir != ZLIB_ALL)
1183                         strlcpy(engine, "pmd", sizeof(engine));
1184                 RTE_LOG(DEBUG, USER1,
1185                         "Buffer %u decompressed by %s from %u to %u bytes\n",
1186                         buf_idx[priv_data->orig_idx], engine,
1187                         ops_processed[i]->consumed, ops_processed[i]->produced);
1188                 ops[i] = NULL;
1189         }
1190
1191         /*
1192          * Check operation status and free source mbuf (destination mbuf and
1193          * compress operation information is still needed)
1194          */
1195         for (i = 0; i < num_bufs; i++) {
1196                 if (out_of_space && oos_zlib_compress) {
1197                         if (ops_processed[i]->status !=
1198                                         RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED) {
1199                                 ret_status = -1;
1200
1201                                 RTE_LOG(ERR, USER1,
1202                                         "Operation without expected out of "
1203                                         "space status error\n");
1204                                 goto exit;
1205                         } else
1206                                 continue;
1207                 }
1208
1209                 if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
1210                         RTE_LOG(ERR, USER1,
1211                                 "Some operations were not successful\n");
1212                         goto exit;
1213                 }
1214                 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
1215                 rte_pktmbuf_free(comp_bufs[priv_data->orig_idx]);
1216                 comp_bufs[priv_data->orig_idx] = NULL;
1217         }
1218
1219         if (out_of_space && oos_zlib_compress) {
1220                 ret_status = 0;
1221                 goto exit;
1222         }
1223
1224         /*
1225          * Compare the original stream with the decompressed stream
1226          * (in size and the data)
1227          */
1228         for (i = 0; i < num_bufs; i++) {
1229                 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
1230                 const char *buf1 = test_bufs[priv_data->orig_idx];
1231                 const char *buf2;
1232                 contig_buf = rte_malloc(NULL, ops_processed[i]->produced, 0);
1233                 if (contig_buf == NULL) {
1234                         RTE_LOG(ERR, USER1, "Contiguous buffer could not "
1235                                         "be allocated\n");
1236                         goto exit;
1237                 }
1238
1239                 buf2 = rte_pktmbuf_read(ops_processed[i]->m_dst, 0,
1240                                 ops_processed[i]->produced, contig_buf);
1241                 if (compare_buffers(buf1, strlen(buf1) + 1,
1242                                 buf2, ops_processed[i]->produced) < 0)
1243                         goto exit;
1244
1245                 /* Test checksums */
1246                 if (compress_xforms[0]->compress.chksum !=
1247                                 RTE_COMP_CHECKSUM_NONE) {
1248                         if (ops_processed[i]->output_chksum !=
1249                                         compress_checksum[i]) {
1250                                 RTE_LOG(ERR, USER1, "The checksums differ\n"
1251                         "Compression Checksum: %" PRIu64 "\tDecompression "
1252                         "Checksum: %" PRIu64 "\n", compress_checksum[i],
1253                         ops_processed[i]->output_chksum);
1254                                 goto exit;
1255                         }
1256                 }
1257
1258                 rte_free(contig_buf);
1259                 contig_buf = NULL;
1260         }
1261
1262         ret_status = 0;
1263
1264 exit:
1265         /* Free resources */
1266         for (i = 0; i < num_bufs; i++) {
1267                 rte_pktmbuf_free(uncomp_bufs[i]);
1268                 rte_pktmbuf_free(comp_bufs[i]);
1269                 rte_comp_op_free(ops[i]);
1270                 rte_comp_op_free(ops_processed[i]);
1271         }
1272         for (i = 0; i < num_priv_xforms; i++) {
1273                 if (priv_xforms[i] != NULL)
1274                         rte_compressdev_private_xform_free(0, priv_xforms[i]);
1275         }
1276         rte_free(contig_buf);
1277
1278         return ret_status;
1279 }
1280
1281 static int
1282 test_compressdev_deflate_stateless_fixed(void)
1283 {
1284         struct comp_testsuite_params *ts_params = &testsuite_params;
1285         uint16_t i;
1286         int ret;
1287         const struct rte_compressdev_capabilities *capab;
1288
1289         capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
1290         TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
1291
1292         if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0)
1293                 return -ENOTSUP;
1294
1295         struct rte_comp_xform *compress_xform =
1296                         rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
1297
1298         if (compress_xform == NULL) {
1299                 RTE_LOG(ERR, USER1,
1300                         "Compress xform could not be created\n");
1301                 ret = TEST_FAILED;
1302                 goto exit;
1303         }
1304
1305         memcpy(compress_xform, ts_params->def_comp_xform,
1306                         sizeof(struct rte_comp_xform));
1307         compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
1308
1309         struct interim_data_params int_data = {
1310                 NULL,
1311                 1,
1312                 NULL,
1313                 &compress_xform,
1314                 &ts_params->def_decomp_xform,
1315                 1
1316         };
1317
1318         struct test_data_params test_data = {
1319                 RTE_COMP_OP_STATELESS,
1320                 LB_BOTH,
1321                 ZLIB_DECOMPRESS,
1322                 0
1323         };
1324
1325         for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
1326                 int_data.test_bufs = &compress_test_bufs[i];
1327                 int_data.buf_idx = &i;
1328
1329                 /* Compress with compressdev, decompress with Zlib */
1330                 test_data.zlib_dir = ZLIB_DECOMPRESS;
1331                 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1332                         ret = TEST_FAILED;
1333                         goto exit;
1334                 }
1335
1336                 /* Compress with Zlib, decompress with compressdev */
1337                 test_data.zlib_dir = ZLIB_COMPRESS;
1338                 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1339                         ret = TEST_FAILED;
1340                         goto exit;
1341                 }
1342         }
1343
1344         ret = TEST_SUCCESS;
1345
1346 exit:
1347         rte_free(compress_xform);
1348         return ret;
1349 }
1350
1351 static int
1352 test_compressdev_deflate_stateless_dynamic(void)
1353 {
1354         struct comp_testsuite_params *ts_params = &testsuite_params;
1355         uint16_t i;
1356         int ret;
1357         struct rte_comp_xform *compress_xform =
1358                         rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
1359
1360         const struct rte_compressdev_capabilities *capab;
1361
1362         capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
1363         TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
1364
1365         if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
1366                 return -ENOTSUP;
1367
1368         if (compress_xform == NULL) {
1369                 RTE_LOG(ERR, USER1,
1370                         "Compress xform could not be created\n");
1371                 ret = TEST_FAILED;
1372                 goto exit;
1373         }
1374
1375         memcpy(compress_xform, ts_params->def_comp_xform,
1376                         sizeof(struct rte_comp_xform));
1377         compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
1378
1379         struct interim_data_params int_data = {
1380                 NULL,
1381                 1,
1382                 NULL,
1383                 &compress_xform,
1384                 &ts_params->def_decomp_xform,
1385                 1
1386         };
1387
1388         struct test_data_params test_data = {
1389                 RTE_COMP_OP_STATELESS,
1390                 LB_BOTH,
1391                 ZLIB_DECOMPRESS,
1392                 0
1393         };
1394
1395         for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
1396                 int_data.test_bufs = &compress_test_bufs[i];
1397                 int_data.buf_idx = &i;
1398
1399                 /* Compress with compressdev, decompress with Zlib */
1400                 test_data.zlib_dir = ZLIB_DECOMPRESS;
1401                 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1402                         ret = TEST_FAILED;
1403                         goto exit;
1404                 }
1405
1406                 /* Compress with Zlib, decompress with compressdev */
1407                 test_data.zlib_dir = ZLIB_COMPRESS;
1408                 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1409                         ret = TEST_FAILED;
1410                         goto exit;
1411                 }
1412         }
1413
1414         ret = TEST_SUCCESS;
1415
1416 exit:
1417         rte_free(compress_xform);
1418         return ret;
1419 }
1420
1421 static int
1422 test_compressdev_deflate_stateless_multi_op(void)
1423 {
1424         struct comp_testsuite_params *ts_params = &testsuite_params;
1425         uint16_t num_bufs = RTE_DIM(compress_test_bufs);
1426         uint16_t buf_idx[num_bufs];
1427         uint16_t i;
1428
1429         for (i = 0; i < num_bufs; i++)
1430                 buf_idx[i] = i;
1431
1432         struct interim_data_params int_data = {
1433                 compress_test_bufs,
1434                 num_bufs,
1435                 buf_idx,
1436                 &ts_params->def_comp_xform,
1437                 &ts_params->def_decomp_xform,
1438                 1
1439         };
1440
1441         struct test_data_params test_data = {
1442                 RTE_COMP_OP_STATELESS,
1443                 LB_BOTH,
1444                 ZLIB_DECOMPRESS,
1445                 0
1446         };
1447
1448         /* Compress with compressdev, decompress with Zlib */
1449         test_data.zlib_dir = ZLIB_DECOMPRESS;
1450         if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
1451                 return TEST_FAILED;
1452
1453         /* Compress with Zlib, decompress with compressdev */
1454         test_data.zlib_dir = ZLIB_COMPRESS;
1455         if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
1456                 return TEST_FAILED;
1457
1458         return TEST_SUCCESS;
1459 }
1460
1461 static int
1462 test_compressdev_deflate_stateless_multi_level(void)
1463 {
1464         struct comp_testsuite_params *ts_params = &testsuite_params;
1465         unsigned int level;
1466         uint16_t i;
1467         int ret;
1468         struct rte_comp_xform *compress_xform =
1469                         rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
1470
1471         if (compress_xform == NULL) {
1472                 RTE_LOG(ERR, USER1,
1473                         "Compress xform could not be created\n");
1474                 ret = TEST_FAILED;
1475                 goto exit;
1476         }
1477
1478         memcpy(compress_xform, ts_params->def_comp_xform,
1479                         sizeof(struct rte_comp_xform));
1480
1481         struct interim_data_params int_data = {
1482                 NULL,
1483                 1,
1484                 NULL,
1485                 &compress_xform,
1486                 &ts_params->def_decomp_xform,
1487                 1
1488         };
1489
1490         struct test_data_params test_data = {
1491                 RTE_COMP_OP_STATELESS,
1492                 LB_BOTH,
1493                 ZLIB_DECOMPRESS,
1494                 0
1495         };
1496
1497         for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
1498                 int_data.test_bufs = &compress_test_bufs[i];
1499                 int_data.buf_idx = &i;
1500
1501                 for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
1502                                 level++) {
1503                         compress_xform->compress.level = level;
1504                         /* Compress with compressdev, decompress with Zlib */
1505                         test_data.zlib_dir = ZLIB_DECOMPRESS;
1506                         if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1507                                 ret = TEST_FAILED;
1508                                 goto exit;
1509                         }
1510                 }
1511         }
1512
1513         ret = TEST_SUCCESS;
1514
1515 exit:
1516         rte_free(compress_xform);
1517         return ret;
1518 }
1519
1520 #define NUM_XFORMS 3
1521 static int
1522 test_compressdev_deflate_stateless_multi_xform(void)
1523 {
1524         struct comp_testsuite_params *ts_params = &testsuite_params;
1525         uint16_t num_bufs = NUM_XFORMS;
1526         struct rte_comp_xform *compress_xforms[NUM_XFORMS] = {NULL};
1527         struct rte_comp_xform *decompress_xforms[NUM_XFORMS] = {NULL};
1528         const char *test_buffers[NUM_XFORMS];
1529         uint16_t i;
1530         unsigned int level = RTE_COMP_LEVEL_MIN;
1531         uint16_t buf_idx[num_bufs];
1532
1533         int ret;
1534
1535         /* Create multiple xforms with various levels */
1536         for (i = 0; i < NUM_XFORMS; i++) {
1537                 compress_xforms[i] = rte_malloc(NULL,
1538                                 sizeof(struct rte_comp_xform), 0);
1539                 if (compress_xforms[i] == NULL) {
1540                         RTE_LOG(ERR, USER1,
1541                                 "Compress xform could not be created\n");
1542                         ret = TEST_FAILED;
1543                         goto exit;
1544                 }
1545
1546                 memcpy(compress_xforms[i], ts_params->def_comp_xform,
1547                                 sizeof(struct rte_comp_xform));
1548                 compress_xforms[i]->compress.level = level;
1549                 level++;
1550
1551                 decompress_xforms[i] = rte_malloc(NULL,
1552                                 sizeof(struct rte_comp_xform), 0);
1553                 if (decompress_xforms[i] == NULL) {
1554                         RTE_LOG(ERR, USER1,
1555                                 "Decompress xform could not be created\n");
1556                         ret = TEST_FAILED;
1557                         goto exit;
1558                 }
1559
1560                 memcpy(decompress_xforms[i], ts_params->def_decomp_xform,
1561                                 sizeof(struct rte_comp_xform));
1562         }
1563
1564         for (i = 0; i < NUM_XFORMS; i++) {
1565                 buf_idx[i] = 0;
1566                 /* Use the same buffer in all sessions */
1567                 test_buffers[i] = compress_test_bufs[0];
1568         }
1569
1570         struct interim_data_params int_data = {
1571                 test_buffers,
1572                 num_bufs,
1573                 buf_idx,
1574                 compress_xforms,
1575                 decompress_xforms,
1576                 NUM_XFORMS
1577         };
1578
1579         struct test_data_params test_data = {
1580                 RTE_COMP_OP_STATELESS,
1581                 LB_BOTH,
1582                 ZLIB_DECOMPRESS,
1583                 0
1584         };
1585
1586         /* Compress with compressdev, decompress with Zlib */
1587         if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1588                 ret = TEST_FAILED;
1589                 goto exit;
1590         }
1591
1592         ret = TEST_SUCCESS;
1593 exit:
1594         for (i = 0; i < NUM_XFORMS; i++) {
1595                 rte_free(compress_xforms[i]);
1596                 rte_free(decompress_xforms[i]);
1597         }
1598
1599         return ret;
1600 }
1601
1602 static int
1603 test_compressdev_deflate_stateless_sgl(void)
1604 {
1605         struct comp_testsuite_params *ts_params = &testsuite_params;
1606         uint16_t i;
1607         const struct rte_compressdev_capabilities *capab;
1608
1609         capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
1610         TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
1611
1612         if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
1613                 return -ENOTSUP;
1614
1615         struct interim_data_params int_data = {
1616                 NULL,
1617                 1,
1618                 NULL,
1619                 &ts_params->def_comp_xform,
1620                 &ts_params->def_decomp_xform,
1621                 1
1622         };
1623
1624         struct test_data_params test_data = {
1625                 RTE_COMP_OP_STATELESS,
1626                 SGL_BOTH,
1627                 ZLIB_DECOMPRESS,
1628                 0
1629         };
1630
1631         for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
1632                 int_data.test_bufs = &compress_test_bufs[i];
1633                 int_data.buf_idx = &i;
1634
1635                 /* Compress with compressdev, decompress with Zlib */
1636                 test_data.zlib_dir = ZLIB_DECOMPRESS;
1637                 if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
1638                         return TEST_FAILED;
1639
1640                 /* Compress with Zlib, decompress with compressdev */
1641                 test_data.zlib_dir = ZLIB_COMPRESS;
1642                 if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
1643                         return TEST_FAILED;
1644
1645                 if (capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_LB_OUT) {
1646                         /* Compress with compressdev, decompress with Zlib */
1647                         test_data.zlib_dir = ZLIB_DECOMPRESS;
1648                         test_data.buff_type = SGL_TO_LB;
1649                         if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
1650                                 return TEST_FAILED;
1651
1652                         /* Compress with Zlib, decompress with compressdev */
1653                         test_data.zlib_dir = ZLIB_COMPRESS;
1654                         test_data.buff_type = SGL_TO_LB;
1655                         if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
1656                                 return TEST_FAILED;
1657                 }
1658
1659                 if (capab->comp_feature_flags & RTE_COMP_FF_OOP_LB_IN_SGL_OUT) {
1660                         /* Compress with compressdev, decompress with Zlib */
1661                         test_data.zlib_dir = ZLIB_DECOMPRESS;
1662                         test_data.buff_type = LB_TO_SGL;
1663                         if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
1664                                 return TEST_FAILED;
1665
1666                         /* Compress with Zlib, decompress with compressdev */
1667                         test_data.zlib_dir = ZLIB_COMPRESS;
1668                         test_data.buff_type = LB_TO_SGL;
1669                         if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
1670                                 return TEST_FAILED;
1671                 }
1672
1673
1674         }
1675
1676         return TEST_SUCCESS;
1677
1678 }
1679
1680 static int
1681 test_compressdev_deflate_stateless_checksum(void)
1682 {
1683         struct comp_testsuite_params *ts_params = &testsuite_params;
1684         uint16_t i;
1685         int ret;
1686         const struct rte_compressdev_capabilities *capab;
1687
1688         capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
1689         TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
1690
1691         /* Check if driver supports any checksum */
1692         if ((capab->comp_feature_flags & RTE_COMP_FF_CRC32_CHECKSUM) == 0 &&
1693                         (capab->comp_feature_flags &
1694                         RTE_COMP_FF_ADLER32_CHECKSUM) == 0 &&
1695                         (capab->comp_feature_flags &
1696                         RTE_COMP_FF_CRC32_ADLER32_CHECKSUM) == 0)
1697                 return -ENOTSUP;
1698
1699         struct rte_comp_xform *compress_xform =
1700                         rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
1701         if (compress_xform == NULL) {
1702                 RTE_LOG(ERR, USER1, "Compress xform could not be created\n");
1703                 ret = TEST_FAILED;
1704                 return ret;
1705         }
1706
1707         memcpy(compress_xform, ts_params->def_comp_xform,
1708                         sizeof(struct rte_comp_xform));
1709
1710         struct rte_comp_xform *decompress_xform =
1711                         rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
1712         if (decompress_xform == NULL) {
1713                 RTE_LOG(ERR, USER1, "Decompress xform could not be created\n");
1714                 rte_free(compress_xform);
1715                 ret = TEST_FAILED;
1716                 return ret;
1717         }
1718
1719         memcpy(decompress_xform, ts_params->def_decomp_xform,
1720                         sizeof(struct rte_comp_xform));
1721
1722         struct interim_data_params int_data = {
1723                 NULL,
1724                 1,
1725                 NULL,
1726                 &compress_xform,
1727                 &decompress_xform,
1728                 1
1729         };
1730
1731         struct test_data_params test_data = {
1732                 RTE_COMP_OP_STATELESS,
1733                 LB_BOTH,
1734                 ZLIB_DECOMPRESS,
1735                 0
1736         };
1737
1738         /* Check if driver supports crc32 checksum and test */
1739         if ((capab->comp_feature_flags & RTE_COMP_FF_CRC32_CHECKSUM)) {
1740                 compress_xform->compress.chksum = RTE_COMP_CHECKSUM_CRC32;
1741                 decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_CRC32;
1742
1743                 for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
1744                         /* Compress with compressdev, decompress with Zlib */
1745                         int_data.test_bufs = &compress_test_bufs[i];
1746                         int_data.buf_idx = &i;
1747
1748                         /* Generate zlib checksum and test against selected
1749                          * drivers decompression checksum
1750                          */
1751                         test_data.zlib_dir = ZLIB_COMPRESS;
1752                         if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1753                                 ret = TEST_FAILED;
1754                                 goto exit;
1755                         }
1756
1757                         /* Generate compression and decompression
1758                          * checksum of selected driver
1759                          */
1760                         test_data.zlib_dir = ZLIB_NONE;
1761                         if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1762                                 ret = TEST_FAILED;
1763                                 goto exit;
1764                         }
1765                 }
1766         }
1767
1768         /* Check if driver supports adler32 checksum and test */
1769         if ((capab->comp_feature_flags & RTE_COMP_FF_ADLER32_CHECKSUM)) {
1770                 compress_xform->compress.chksum = RTE_COMP_CHECKSUM_ADLER32;
1771                 decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_ADLER32;
1772
1773                 for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
1774                         int_data.test_bufs = &compress_test_bufs[i];
1775                         int_data.buf_idx = &i;
1776
1777                         /* Generate zlib checksum and test against selected
1778                          * drivers decompression checksum
1779                          */
1780                         test_data.zlib_dir = ZLIB_COMPRESS;
1781                         if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1782                                 ret = TEST_FAILED;
1783                                 goto exit;
1784                         }
1785                         /* Generate compression and decompression
1786                          * checksum of selected driver
1787                          */
1788                         test_data.zlib_dir = ZLIB_NONE;
1789                         if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1790                                 ret = TEST_FAILED;
1791                                 goto exit;
1792                         }
1793                 }
1794         }
1795
1796         /* Check if driver supports combined crc and adler checksum and test */
1797         if ((capab->comp_feature_flags & RTE_COMP_FF_CRC32_ADLER32_CHECKSUM)) {
1798                 compress_xform->compress.chksum =
1799                                 RTE_COMP_CHECKSUM_CRC32_ADLER32;
1800                 decompress_xform->decompress.chksum =
1801                                 RTE_COMP_CHECKSUM_CRC32_ADLER32;
1802
1803                 for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
1804                         int_data.test_bufs = &compress_test_bufs[i];
1805                         int_data.buf_idx = &i;
1806
1807                         /* Generate compression and decompression
1808                          * checksum of selected driver
1809                          */
1810                         test_data.zlib_dir = ZLIB_NONE;
1811                         if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1812                                 ret = TEST_FAILED;
1813                                 goto exit;
1814                         }
1815                 }
1816         }
1817
1818         ret = TEST_SUCCESS;
1819
1820 exit:
1821         rte_free(compress_xform);
1822         rte_free(decompress_xform);
1823         return ret;
1824 }
1825
1826 static int
1827 test_compressdev_out_of_space_buffer(void)
1828 {
1829         struct comp_testsuite_params *ts_params = &testsuite_params;
1830         int ret;
1831         uint16_t i;
1832         const struct rte_compressdev_capabilities *capab;
1833
1834         RTE_LOG(INFO, USER1, "This is a negative test errors are expected\n");
1835
1836         capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
1837         TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
1838
1839         if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0)
1840                 return -ENOTSUP;
1841
1842         struct rte_comp_xform *compress_xform =
1843                         rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
1844
1845         if (compress_xform == NULL) {
1846                 RTE_LOG(ERR, USER1,
1847                         "Compress xform could not be created\n");
1848                 ret = TEST_FAILED;
1849                 goto exit;
1850         }
1851
1852         struct interim_data_params int_data = {
1853                 &compress_test_bufs[0],
1854                 1,
1855                 &i,
1856                 &ts_params->def_comp_xform,
1857                 &ts_params->def_decomp_xform,
1858                 1
1859         };
1860
1861         struct test_data_params test_data = {
1862                 RTE_COMP_OP_STATELESS,
1863                 LB_BOTH,
1864                 ZLIB_DECOMPRESS,
1865                 1
1866         };
1867         /* Compress with compressdev, decompress with Zlib */
1868         test_data.zlib_dir = ZLIB_DECOMPRESS;
1869         if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1870                 ret = TEST_FAILED;
1871                 goto exit;
1872         }
1873
1874         /* Compress with Zlib, decompress with compressdev */
1875         test_data.zlib_dir = ZLIB_COMPRESS;
1876         if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1877                 ret = TEST_FAILED;
1878                 goto exit;
1879         }
1880
1881         if (capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
1882                 /* Compress with compressdev, decompress with Zlib */
1883                 test_data.zlib_dir = ZLIB_DECOMPRESS;
1884                 test_data.buff_type = SGL_BOTH;
1885                 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1886                         ret = TEST_FAILED;
1887                         goto exit;
1888                 }
1889
1890                 /* Compress with Zlib, decompress with compressdev */
1891                 test_data.zlib_dir = ZLIB_COMPRESS;
1892                 test_data.buff_type = SGL_BOTH;
1893                 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
1894                         ret = TEST_FAILED;
1895                         goto exit;
1896                 }
1897         }
1898
1899         ret  = TEST_SUCCESS;
1900
1901 exit:
1902         rte_free(compress_xform);
1903         return ret;
1904 }
1905
1906
1907 static struct unit_test_suite compressdev_testsuite  = {
1908         .suite_name = "compressdev unit test suite",
1909         .setup = testsuite_setup,
1910         .teardown = testsuite_teardown,
1911         .unit_test_cases = {
1912                 TEST_CASE_ST(NULL, NULL,
1913                         test_compressdev_invalid_configuration),
1914                 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1915                         test_compressdev_deflate_stateless_fixed),
1916                 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1917                         test_compressdev_deflate_stateless_dynamic),
1918                 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1919                         test_compressdev_deflate_stateless_multi_op),
1920                 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1921                         test_compressdev_deflate_stateless_multi_level),
1922                 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1923                         test_compressdev_deflate_stateless_multi_xform),
1924                 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1925                         test_compressdev_deflate_stateless_sgl),
1926                 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1927                         test_compressdev_deflate_stateless_checksum),
1928                 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1929                         test_compressdev_out_of_space_buffer),
1930                 TEST_CASES_END() /**< NULL terminate unit test array */
1931         }
1932 };
1933
1934 static int
1935 test_compressdev(void)
1936 {
1937         return unit_test_suite_runner(&compressdev_testsuite);
1938 }
1939
1940 REGISTER_TEST_COMMAND(compressdev_autotest, test_compressdev);