test/compress: add initial unit tests
[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
14 #include "test_compressdev_test_buffer.h"
15 #include "test.h"
16
17 #define DEFAULT_WINDOW_SIZE 15
18 #define DEFAULT_MEM_LEVEL 8
19 #define MAX_DEQD_RETRIES 10
20 #define DEQUEUE_WAIT_TIME 10000
21
22 /*
23  * 30% extra size for compressed data compared to original data,
24  * in case data size cannot be reduced and it is actually bigger
25  * due to the compress block headers
26  */
27 #define COMPRESS_BUF_SIZE_RATIO 1.3
28 #define NUM_MBUFS 16
29 #define NUM_OPS 16
30 #define NUM_MAX_XFORMS 1
31 #define NUM_MAX_INFLIGHT_OPS 128
32 #define CACHE_SIZE 0
33
34 const char *
35 huffman_type_strings[] = {
36         [RTE_COMP_HUFFMAN_DEFAULT]      = "PMD default",
37         [RTE_COMP_HUFFMAN_FIXED]        = "Fixed",
38         [RTE_COMP_HUFFMAN_DYNAMIC]      = "Dynamic"
39 };
40
41 enum zlib_direction {
42         ZLIB_NONE,
43         ZLIB_COMPRESS,
44         ZLIB_DECOMPRESS,
45         ZLIB_ALL
46 };
47
48 struct comp_testsuite_params {
49         struct rte_mempool *mbuf_pool;
50         struct rte_mempool *op_pool;
51         struct rte_comp_xform def_comp_xform;
52         struct rte_comp_xform def_decomp_xform;
53 };
54
55 static struct comp_testsuite_params testsuite_params = { 0 };
56
57 static void
58 testsuite_teardown(void)
59 {
60         struct comp_testsuite_params *ts_params = &testsuite_params;
61
62         rte_mempool_free(ts_params->mbuf_pool);
63         rte_mempool_free(ts_params->op_pool);
64 }
65
66 static int
67 testsuite_setup(void)
68 {
69         struct comp_testsuite_params *ts_params = &testsuite_params;
70         unsigned int i;
71
72         if (rte_compressdev_count() == 0) {
73                 RTE_LOG(ERR, USER1, "Need at least one compress device\n");
74                 return TEST_FAILED;
75         }
76
77         uint32_t max_buf_size = 0;
78         for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
79                 max_buf_size = RTE_MAX(max_buf_size,
80                                 strlen(compress_test_bufs[i]) + 1);
81
82         max_buf_size *= COMPRESS_BUF_SIZE_RATIO;
83         /*
84          * Buffers to be used in compression and decompression.
85          * Since decompressed data might be larger than
86          * compressed data (due to block header),
87          * buffers should be big enough for both cases.
88          */
89         ts_params->mbuf_pool = rte_pktmbuf_pool_create("mbuf_pool",
90                         NUM_MBUFS,
91                         CACHE_SIZE, 0,
92                         max_buf_size + RTE_PKTMBUF_HEADROOM,
93                         rte_socket_id());
94         if (ts_params->mbuf_pool == NULL) {
95                 RTE_LOG(ERR, USER1, "Large mbuf pool could not be created\n");
96                 return TEST_FAILED;
97         }
98
99         ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
100                                                 0, 0, rte_socket_id());
101         if (ts_params->op_pool == NULL) {
102                 RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
103                 goto exit;
104         }
105
106         /* Initializes default values for compress/decompress xforms */
107         ts_params->def_comp_xform.type = RTE_COMP_COMPRESS;
108         ts_params->def_comp_xform.compress.algo = RTE_COMP_ALGO_DEFLATE,
109         ts_params->def_comp_xform.compress.deflate.huffman =
110                                                 RTE_COMP_HUFFMAN_DEFAULT;
111         ts_params->def_comp_xform.compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
112         ts_params->def_comp_xform.compress.chksum = RTE_COMP_CHECKSUM_NONE;
113         ts_params->def_comp_xform.compress.window_size = DEFAULT_WINDOW_SIZE;
114
115         ts_params->def_decomp_xform.type = RTE_COMP_DECOMPRESS;
116         ts_params->def_decomp_xform.decompress.algo = RTE_COMP_ALGO_DEFLATE,
117         ts_params->def_decomp_xform.decompress.chksum = RTE_COMP_CHECKSUM_NONE;
118         ts_params->def_decomp_xform.decompress.window_size = DEFAULT_WINDOW_SIZE;
119
120         return TEST_SUCCESS;
121
122 exit:
123         testsuite_teardown();
124
125         return TEST_FAILED;
126 }
127
128 static int
129 generic_ut_setup(void)
130 {
131         /* Configure compressdev (one device, one queue pair) */
132         struct rte_compressdev_config config = {
133                 .socket_id = rte_socket_id(),
134                 .nb_queue_pairs = 1,
135                 .max_nb_priv_xforms = NUM_MAX_XFORMS,
136                 .max_nb_streams = 0
137         };
138
139         if (rte_compressdev_configure(0, &config) < 0) {
140                 RTE_LOG(ERR, USER1, "Device configuration failed\n");
141                 return -1;
142         }
143
144         if (rte_compressdev_queue_pair_setup(0, 0, NUM_MAX_INFLIGHT_OPS,
145                         rte_socket_id()) < 0) {
146                 RTE_LOG(ERR, USER1, "Queue pair setup failed\n");
147                 return -1;
148         }
149
150         if (rte_compressdev_start(0) < 0) {
151                 RTE_LOG(ERR, USER1, "Device could not be started\n");
152                 return -1;
153         }
154
155         return 0;
156 }
157
158 static void
159 generic_ut_teardown(void)
160 {
161         rte_compressdev_stop(0);
162         if (rte_compressdev_close(0) < 0)
163                 RTE_LOG(ERR, USER1, "Device could not be closed\n");
164 }
165
166 static int
167 compare_buffers(const char *buffer1, uint32_t buffer1_len,
168                 const char *buffer2, uint32_t buffer2_len)
169 {
170         if (buffer1_len != buffer2_len) {
171                 RTE_LOG(ERR, USER1, "Buffer lengths are different\n");
172                 return -1;
173         }
174
175         if (memcmp(buffer1, buffer2, buffer1_len) != 0) {
176                 RTE_LOG(ERR, USER1, "Buffers are different\n");
177                 return -1;
178         }
179
180         return 0;
181 }
182
183 /*
184  * Maps compressdev and Zlib flush flags
185  */
186 static int
187 map_zlib_flush_flag(enum rte_comp_flush_flag flag)
188 {
189         switch (flag) {
190         case RTE_COMP_FLUSH_NONE:
191                 return Z_NO_FLUSH;
192         case RTE_COMP_FLUSH_SYNC:
193                 return Z_SYNC_FLUSH;
194         case RTE_COMP_FLUSH_FULL:
195                 return Z_FULL_FLUSH;
196         case RTE_COMP_FLUSH_FINAL:
197                 return Z_FINISH;
198         /*
199          * There should be only the values above,
200          * so this should never happen
201          */
202         default:
203                 return -1;
204         }
205 }
206
207 static int
208 compress_zlib(struct rte_comp_op *op,
209                 const struct rte_comp_xform *xform, int mem_level)
210 {
211         z_stream stream;
212         int zlib_flush;
213         int strategy, window_bits, comp_level;
214         int ret = -1;
215
216         /* initialize zlib stream */
217         stream.zalloc = Z_NULL;
218         stream.zfree = Z_NULL;
219         stream.opaque = Z_NULL;
220
221         if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED)
222                 strategy = Z_FIXED;
223         else
224                 strategy = Z_DEFAULT_STRATEGY;
225
226         /*
227          * Window bits is the base two logarithm of the window size (in bytes).
228          * When doing raw DEFLATE, this number will be negative.
229          */
230         window_bits = -(xform->compress.window_size);
231
232         comp_level = xform->compress.level;
233
234         if (comp_level != RTE_COMP_LEVEL_NONE)
235                 ret = deflateInit2(&stream, comp_level, Z_DEFLATED,
236                         window_bits, mem_level, strategy);
237         else
238                 ret = deflateInit(&stream, Z_NO_COMPRESSION);
239
240         if (ret != Z_OK) {
241                 printf("Zlib deflate could not be initialized\n");
242                 goto exit;
243         }
244
245         /* Assuming stateless operation */
246         stream.avail_in = op->src.length;
247         stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
248         stream.avail_out = op->m_dst->data_len;
249         stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
250
251         /* Stateless operation, all buffer will be compressed in one go */
252         zlib_flush = map_zlib_flush_flag(op->flush_flag);
253         ret = deflate(&stream, zlib_flush);
254
255         if (stream.avail_in != 0) {
256                 RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
257                 goto exit;
258         }
259
260         if (ret != Z_STREAM_END)
261                 goto exit;
262
263         op->consumed = op->src.length - stream.avail_in;
264         op->produced = op->m_dst->data_len - stream.avail_out;
265         op->status = RTE_COMP_OP_STATUS_SUCCESS;
266
267         deflateReset(&stream);
268
269         ret = 0;
270 exit:
271         deflateEnd(&stream);
272
273         return ret;
274 }
275
276 static int
277 decompress_zlib(struct rte_comp_op *op,
278                 const struct rte_comp_xform *xform)
279 {
280         z_stream stream;
281         int window_bits;
282         int zlib_flush;
283         int ret = TEST_FAILED;
284
285         /* initialize zlib stream */
286         stream.zalloc = Z_NULL;
287         stream.zfree = Z_NULL;
288         stream.opaque = Z_NULL;
289
290         /*
291          * Window bits is the base two logarithm of the window size (in bytes).
292          * When doing raw DEFLATE, this number will be negative.
293          */
294         window_bits = -(xform->decompress.window_size);
295
296         ret = inflateInit2(&stream, window_bits);
297
298         if (ret != Z_OK) {
299                 printf("Zlib deflate could not be initialized\n");
300                 goto exit;
301         }
302
303         /* Assuming stateless operation */
304         stream.avail_in = op->src.length;
305         stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
306         stream.avail_out = op->m_dst->data_len;
307         stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
308
309         /* Stateless operation, all buffer will be compressed in one go */
310         zlib_flush = map_zlib_flush_flag(op->flush_flag);
311         ret = inflate(&stream, zlib_flush);
312
313         if (stream.avail_in != 0) {
314                 RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
315                 goto exit;
316         }
317
318         if (ret != Z_STREAM_END)
319                 goto exit;
320
321         op->consumed = op->src.length - stream.avail_in;
322         op->produced = op->m_dst->data_len - stream.avail_out;
323         op->status = RTE_COMP_OP_STATUS_SUCCESS;
324
325         inflateReset(&stream);
326
327         ret = 0;
328 exit:
329         inflateEnd(&stream);
330
331         return ret;
332 }
333
334 /*
335  * Compresses and decompresses buffer with compressdev API and Zlib API
336  */
337 static int
338 test_deflate_comp_decomp(const char *test_buffer,
339                 struct rte_comp_xform *compress_xform,
340                 struct rte_comp_xform *decompress_xform,
341                 enum rte_comp_op_type state,
342                 enum zlib_direction zlib_dir)
343 {
344         struct comp_testsuite_params *ts_params = &testsuite_params;
345         int ret_status = -1;
346         int ret;
347         struct rte_mbuf *comp_buf = NULL;
348         struct rte_mbuf *uncomp_buf = NULL;
349         struct rte_comp_op *op = NULL;
350         struct rte_comp_op *op_processed = NULL;
351         void *priv_xform = NULL;
352         uint16_t num_deqd;
353         unsigned int deqd_retries = 0;
354         char *data_ptr;
355
356         /* Prepare the source mbuf with the data */
357         uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
358         if (uncomp_buf == NULL) {
359                 RTE_LOG(ERR, USER1,
360                         "Source mbuf could not be allocated "
361                         "from the mempool\n");
362                 goto exit;
363         }
364
365         data_ptr = rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
366         snprintf(data_ptr, strlen(test_buffer) + 1, "%s", test_buffer);
367
368         /* Prepare the destination mbuf */
369         comp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
370         if (comp_buf == NULL) {
371                 RTE_LOG(ERR, USER1,
372                         "Destination mbuf could not be allocated "
373                         "from the mempool\n");
374                 goto exit;
375         }
376
377         rte_pktmbuf_append(comp_buf,
378                         strlen(test_buffer) * COMPRESS_BUF_SIZE_RATIO);
379
380         /* Build the compression operations */
381         op = rte_comp_op_alloc(ts_params->op_pool);
382         if (op == NULL) {
383                 RTE_LOG(ERR, USER1,
384                         "Compress operation could not be allocated "
385                         "from the mempool\n");
386                 goto exit;
387         }
388
389         op->m_src = uncomp_buf;
390         op->m_dst = comp_buf;
391         op->src.offset = 0;
392         op->src.length = rte_pktmbuf_pkt_len(uncomp_buf);
393         op->dst.offset = 0;
394         if (state == RTE_COMP_OP_STATELESS) {
395                 op->flush_flag = RTE_COMP_FLUSH_FINAL;
396         } else {
397                 RTE_LOG(ERR, USER1,
398                         "Stateful operations are not supported "
399                         "in these tests yet\n");
400                 goto exit;
401         }
402         op->input_chksum = 0;
403
404         /* Compress data (either with Zlib API or compressdev API */
405         if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
406                 ret = compress_zlib(op,
407                         (const struct rte_comp_xform *)&compress_xform,
408                         DEFAULT_MEM_LEVEL);
409                 if (ret < 0)
410                         goto exit;
411
412                 op_processed = op;
413         } else {
414                 /* Create compress xform private data */
415                 ret = rte_compressdev_private_xform_create(0,
416                         (const struct rte_comp_xform *)compress_xform,
417                         &priv_xform);
418                 if (ret < 0) {
419                         RTE_LOG(ERR, USER1,
420                                 "Compression private xform "
421                                 "could not be created\n");
422                         goto exit;
423                 }
424
425                 /* Attach xform private data to operation */
426                 op->private_xform = priv_xform;
427
428                 /* Enqueue and dequeue all operations */
429                 ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
430                 if (ret == 0) {
431                         RTE_LOG(ERR, USER1,
432                                 "The operation could not be enqueued\n");
433                         goto exit;
434                 }
435                 do {
436                         /*
437                          * If retrying a dequeue call, wait for 10 ms to allow
438                          * enough time to the driver to process the operations
439                          */
440                         if (deqd_retries != 0) {
441                                 /*
442                                  * Avoid infinite loop if not all the
443                                  * operations get out of the device
444                                  */
445                                 if (deqd_retries == MAX_DEQD_RETRIES) {
446                                         RTE_LOG(ERR, USER1,
447                                                 "Not all operations could be "
448                                                 "dequeued\n");
449                                         goto exit;
450                                 }
451                                 usleep(DEQUEUE_WAIT_TIME);
452                         }
453                         num_deqd = rte_compressdev_dequeue_burst(0, 0,
454                                         &op_processed, 1);
455
456                         deqd_retries++;
457                 } while (num_deqd < 1);
458
459                 deqd_retries = 0;
460
461                 /* Free compress private xform */
462                 rte_compressdev_private_xform_free(0, priv_xform);
463                 priv_xform = NULL;
464         }
465
466         enum rte_comp_huffman huffman_type =
467                 compress_xform->compress.deflate.huffman;
468         RTE_LOG(DEBUG, USER1, "Buffer compressed from %u to %u bytes "
469                         "(level = %u, huffman = %s)\n",
470                         op_processed->consumed, op_processed->produced,
471                         compress_xform->compress.level,
472                         huffman_type_strings[huffman_type]);
473         RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
474                         (float)op_processed->produced /
475                         op_processed->consumed * 100);
476         op = NULL;
477
478         /*
479          * Check operation status and free source mbuf (destination mbuf and
480          * compress operation information is needed for the decompression stage)
481          */
482         if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
483                 RTE_LOG(ERR, USER1,
484                         "Some operations were not successful\n");
485                 goto exit;
486         }
487         rte_pktmbuf_free(uncomp_buf);
488         uncomp_buf = NULL;
489
490         /* Allocate buffer for decompressed data */
491         uncomp_buf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
492         if (uncomp_buf == NULL) {
493                 RTE_LOG(ERR, USER1,
494                         "Destination mbuf could not be allocated "
495                         "from the mempool\n");
496                 goto exit;
497         }
498
499         rte_pktmbuf_append(uncomp_buf, strlen(test_buffer) + 1);
500
501         /* Build the decompression operations */
502         op = rte_comp_op_alloc(ts_params->op_pool);
503         if (op == NULL) {
504                 RTE_LOG(ERR, USER1,
505                         "Decompress operation could not be allocated "
506                         "from the mempool\n");
507                 goto exit;
508         }
509
510         /* Source buffer is the compressed data from the previous operation */
511         op->m_src = op_processed->m_dst;
512         op->m_dst = uncomp_buf;
513         op->src.offset = 0;
514         /*
515          * Set the length of the compressed data to the
516          * number of bytes that were produced in the previous stage
517          */
518         op->src.length = op_processed->produced;
519         op->dst.offset = 0;
520         if (state == RTE_COMP_OP_STATELESS) {
521                 op->flush_flag = RTE_COMP_FLUSH_FINAL;
522         } else {
523                 RTE_LOG(ERR, USER1,
524                         "Stateful operations are not supported "
525                         "in these tests yet\n");
526                 goto exit;
527         }
528         op->input_chksum = 0;
529
530         /*
531          * Free the previous compress operation,
532          * as it is not needed anymore
533          */
534         rte_comp_op_free(op_processed);
535         op_processed = NULL;
536
537         /* Decompress data (either with Zlib API or compressdev API */
538         if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
539                 ret = decompress_zlib(op,
540                         (const struct rte_comp_xform *)&decompress_xform);
541                 if (ret < 0)
542                         goto exit;
543
544                 op_processed = op;
545         } else {
546                 num_deqd = 0;
547                 /* Create decompress xform private data */
548                 ret = rte_compressdev_private_xform_create(0,
549                         (const struct rte_comp_xform *)decompress_xform,
550                         &priv_xform);
551                 if (ret < 0) {
552                         RTE_LOG(ERR, USER1,
553                                 "Decompression private xform "
554                                 "could not be created\n");
555                         goto exit;
556                 }
557
558                 /* Attach xform private data to operation */
559                 op->private_xform = priv_xform;
560
561                 /* Enqueue and dequeue all operations */
562                 ret = rte_compressdev_enqueue_burst(0, 0, &op, 1);
563                 if (ret == 0) {
564                         RTE_LOG(ERR, USER1,
565                                 "The operation could not be enqueued\n");
566                         goto exit;
567                 }
568                 do {
569                         /*
570                          * If retrying a dequeue call, wait for 10 ms to allow
571                          * enough time to the driver to process the operations
572                          */
573                         if (deqd_retries != 0) {
574                                 /*
575                                  * Avoid infinite loop if not all the
576                                  * operations get out of the device
577                                  */
578                                 if (deqd_retries == MAX_DEQD_RETRIES) {
579                                         RTE_LOG(ERR, USER1,
580                                                 "Not all operations could be "
581                                                 "dequeued\n");
582                                         goto exit;
583                                 }
584                                 usleep(DEQUEUE_WAIT_TIME);
585                         }
586                         num_deqd = rte_compressdev_dequeue_burst(0, 0,
587                                         &op_processed, 1);
588
589                         deqd_retries++;
590                 } while (num_deqd < 1);
591         }
592
593         RTE_LOG(DEBUG, USER1, "Buffer decompressed from %u to %u bytes\n",
594                         op_processed->consumed, op_processed->produced);
595         op = NULL;
596         /*
597          * Check operation status and free source mbuf (destination mbuf and
598          * compress operation information is still needed)
599          */
600         if (op_processed->status != RTE_COMP_OP_STATUS_SUCCESS) {
601                 RTE_LOG(ERR, USER1,
602                         "Some operations were not successful\n");
603                 goto exit;
604         }
605         rte_pktmbuf_free(comp_buf);
606         comp_buf = NULL;
607
608         /*
609          * Compare the original stream with the decompressed stream
610          * (in size and the data)
611          */
612         if (compare_buffers(test_buffer, strlen(test_buffer) + 1,
613                         rte_pktmbuf_mtod(op_processed->m_dst, const char *),
614                         op_processed->produced) < 0)
615                 goto exit;
616
617         ret_status = 0;
618
619 exit:
620         /* Free resources */
621         rte_pktmbuf_free(uncomp_buf);
622         rte_pktmbuf_free(comp_buf);
623         rte_comp_op_free(op);
624         rte_comp_op_free(op_processed);
625
626         if (priv_xform != NULL)
627                 rte_compressdev_private_xform_free(0, priv_xform);
628
629         return ret_status;
630 }
631
632 static int
633 test_compressdev_deflate_stateless_fixed(void)
634 {
635         struct comp_testsuite_params *ts_params = &testsuite_params;
636         const char *test_buffer;
637         uint16_t i;
638         struct rte_comp_xform compress_xform;
639
640         memcpy(&compress_xform, &ts_params->def_comp_xform,
641                         sizeof(struct rte_comp_xform));
642         compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
643
644         for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
645                 test_buffer = compress_test_bufs[i];
646
647                 /* Compress with compressdev, decompress with Zlib */
648                 if (test_deflate_comp_decomp(test_buffer,
649                                 &compress_xform,
650                                 &ts_params->def_decomp_xform,
651                                 RTE_COMP_OP_STATELESS,
652                                 ZLIB_DECOMPRESS) < 0)
653                         return TEST_FAILED;
654
655                 /* Compress with Zlib, decompress with compressdev */
656                 if (test_deflate_comp_decomp(test_buffer,
657                                 &compress_xform,
658                                 &ts_params->def_decomp_xform,
659                                 RTE_COMP_OP_STATELESS,
660                                 ZLIB_COMPRESS) < 0)
661                         return TEST_FAILED;
662         }
663
664         return TEST_SUCCESS;
665 }
666
667 static int
668 test_compressdev_deflate_stateless_dynamic(void)
669 {
670         struct comp_testsuite_params *ts_params = &testsuite_params;
671         const char *test_buffer;
672         uint16_t i;
673         struct rte_comp_xform compress_xform;
674
675         memcpy(&compress_xform, &ts_params->def_comp_xform,
676                         sizeof(struct rte_comp_xform));
677         compress_xform.compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
678
679         for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
680                 test_buffer = compress_test_bufs[i];
681
682                 /* Compress with compressdev, decompress with Zlib */
683                 if (test_deflate_comp_decomp(test_buffer,
684                                 &compress_xform,
685                                 &ts_params->def_decomp_xform,
686                                 RTE_COMP_OP_STATELESS,
687                                 ZLIB_DECOMPRESS) < 0)
688                         return TEST_FAILED;
689
690                 /* Compress with Zlib, decompress with compressdev */
691                 if (test_deflate_comp_decomp(test_buffer,
692                                 &compress_xform,
693                                 &ts_params->def_decomp_xform,
694                                 RTE_COMP_OP_STATELESS,
695                                 ZLIB_COMPRESS) < 0)
696                         return TEST_FAILED;
697         }
698
699         return TEST_SUCCESS;
700 }
701
702 static struct unit_test_suite compressdev_testsuite  = {
703         .suite_name = "compressdev unit test suite",
704         .setup = testsuite_setup,
705         .teardown = testsuite_teardown,
706         .unit_test_cases = {
707                 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
708                         test_compressdev_deflate_stateless_fixed),
709                 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
710                         test_compressdev_deflate_stateless_dynamic),
711                 TEST_CASES_END() /**< NULL terminate unit test array */
712         }
713 };
714
715 static int
716 test_compressdev(void)
717 {
718         return unit_test_suite_runner(&compressdev_testsuite);
719 }
720
721 REGISTER_TEST_COMMAND(compressdev_autotest, test_compressdev);