1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
8 #include <rte_cycles.h>
9 #include <rte_malloc.h>
10 #include <rte_mempool.h>
12 #include <rte_compressdev.h>
14 #include "test_compressdev_test_buffer.h"
17 #define DEFAULT_WINDOW_SIZE 15
18 #define DEFAULT_MEM_LEVEL 8
19 #define MAX_DEQD_RETRIES 10
20 #define DEQUEUE_WAIT_TIME 10000
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
27 #define COMPRESS_BUF_SIZE_RATIO 1.3
30 #define NUM_MAX_XFORMS 16
31 #define NUM_MAX_INFLIGHT_OPS 128
35 huffman_type_strings[] = {
36 [RTE_COMP_HUFFMAN_DEFAULT] = "PMD default",
37 [RTE_COMP_HUFFMAN_FIXED] = "Fixed",
38 [RTE_COMP_HUFFMAN_DYNAMIC] = "Dynamic"
52 struct comp_testsuite_params {
53 struct rte_mempool *mbuf_pool;
54 struct rte_mempool *op_pool;
55 struct rte_comp_xform *def_comp_xform;
56 struct rte_comp_xform *def_decomp_xform;
59 static struct comp_testsuite_params testsuite_params = { 0 };
62 testsuite_teardown(void)
64 struct comp_testsuite_params *ts_params = &testsuite_params;
66 rte_mempool_free(ts_params->mbuf_pool);
67 rte_mempool_free(ts_params->op_pool);
68 rte_free(ts_params->def_comp_xform);
69 rte_free(ts_params->def_decomp_xform);
75 struct comp_testsuite_params *ts_params = &testsuite_params;
78 if (rte_compressdev_count() == 0) {
79 RTE_LOG(ERR, USER1, "Need at least one compress device\n");
83 uint32_t max_buf_size = 0;
84 for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
85 max_buf_size = RTE_MAX(max_buf_size,
86 strlen(compress_test_bufs[i]) + 1);
88 max_buf_size *= COMPRESS_BUF_SIZE_RATIO;
90 * Buffers to be used in compression and decompression.
91 * Since decompressed data might be larger than
92 * compressed data (due to block header),
93 * buffers should be big enough for both cases.
95 ts_params->mbuf_pool = rte_pktmbuf_pool_create("mbuf_pool",
98 max_buf_size + RTE_PKTMBUF_HEADROOM,
100 if (ts_params->mbuf_pool == NULL) {
101 RTE_LOG(ERR, USER1, "Large mbuf pool could not be created\n");
105 ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
106 0, sizeof(struct priv_op_data),
108 if (ts_params->op_pool == NULL) {
109 RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
113 ts_params->def_comp_xform =
114 rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
115 if (ts_params->def_comp_xform == NULL) {
117 "Default compress xform could not be created\n");
120 ts_params->def_decomp_xform =
121 rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
122 if (ts_params->def_decomp_xform == NULL) {
124 "Default decompress xform could not be created\n");
128 /* Initializes default values for compress/decompress xforms */
129 ts_params->def_comp_xform->type = RTE_COMP_COMPRESS;
130 ts_params->def_comp_xform->compress.algo = RTE_COMP_ALGO_DEFLATE,
131 ts_params->def_comp_xform->compress.deflate.huffman =
132 RTE_COMP_HUFFMAN_DEFAULT;
133 ts_params->def_comp_xform->compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
134 ts_params->def_comp_xform->compress.chksum = RTE_COMP_CHECKSUM_NONE;
135 ts_params->def_comp_xform->compress.window_size = DEFAULT_WINDOW_SIZE;
137 ts_params->def_decomp_xform->type = RTE_COMP_DECOMPRESS;
138 ts_params->def_decomp_xform->decompress.algo = RTE_COMP_ALGO_DEFLATE,
139 ts_params->def_decomp_xform->decompress.chksum = RTE_COMP_CHECKSUM_NONE;
140 ts_params->def_decomp_xform->decompress.window_size = DEFAULT_WINDOW_SIZE;
145 testsuite_teardown();
151 generic_ut_setup(void)
153 /* Configure compressdev (one device, one queue pair) */
154 struct rte_compressdev_config config = {
155 .socket_id = rte_socket_id(),
157 .max_nb_priv_xforms = NUM_MAX_XFORMS,
161 if (rte_compressdev_configure(0, &config) < 0) {
162 RTE_LOG(ERR, USER1, "Device configuration failed\n");
166 if (rte_compressdev_queue_pair_setup(0, 0, NUM_MAX_INFLIGHT_OPS,
167 rte_socket_id()) < 0) {
168 RTE_LOG(ERR, USER1, "Queue pair setup failed\n");
172 if (rte_compressdev_start(0) < 0) {
173 RTE_LOG(ERR, USER1, "Device could not be started\n");
181 generic_ut_teardown(void)
183 rte_compressdev_stop(0);
184 if (rte_compressdev_close(0) < 0)
185 RTE_LOG(ERR, USER1, "Device could not be closed\n");
189 compare_buffers(const char *buffer1, uint32_t buffer1_len,
190 const char *buffer2, uint32_t buffer2_len)
192 if (buffer1_len != buffer2_len) {
193 RTE_LOG(ERR, USER1, "Buffer lengths are different\n");
197 if (memcmp(buffer1, buffer2, buffer1_len) != 0) {
198 RTE_LOG(ERR, USER1, "Buffers are different\n");
206 * Maps compressdev and Zlib flush flags
209 map_zlib_flush_flag(enum rte_comp_flush_flag flag)
212 case RTE_COMP_FLUSH_NONE:
214 case RTE_COMP_FLUSH_SYNC:
216 case RTE_COMP_FLUSH_FULL:
218 case RTE_COMP_FLUSH_FINAL:
221 * There should be only the values above,
222 * so this should never happen
230 compress_zlib(struct rte_comp_op *op,
231 const struct rte_comp_xform *xform, int mem_level)
235 int strategy, window_bits, comp_level;
238 /* initialize zlib stream */
239 stream.zalloc = Z_NULL;
240 stream.zfree = Z_NULL;
241 stream.opaque = Z_NULL;
243 if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED)
246 strategy = Z_DEFAULT_STRATEGY;
249 * Window bits is the base two logarithm of the window size (in bytes).
250 * When doing raw DEFLATE, this number will be negative.
252 window_bits = -(xform->compress.window_size);
254 comp_level = xform->compress.level;
256 if (comp_level != RTE_COMP_LEVEL_NONE)
257 ret = deflateInit2(&stream, comp_level, Z_DEFLATED,
258 window_bits, mem_level, strategy);
260 ret = deflateInit(&stream, Z_NO_COMPRESSION);
263 printf("Zlib deflate could not be initialized\n");
267 /* Assuming stateless operation */
268 stream.avail_in = op->src.length;
269 stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
270 stream.avail_out = op->m_dst->data_len;
271 stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
273 /* Stateless operation, all buffer will be compressed in one go */
274 zlib_flush = map_zlib_flush_flag(op->flush_flag);
275 ret = deflate(&stream, zlib_flush);
277 if (stream.avail_in != 0) {
278 RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
282 if (ret != Z_STREAM_END)
285 op->consumed = op->src.length - stream.avail_in;
286 op->produced = op->m_dst->data_len - stream.avail_out;
287 op->status = RTE_COMP_OP_STATUS_SUCCESS;
289 deflateReset(&stream);
299 decompress_zlib(struct rte_comp_op *op,
300 const struct rte_comp_xform *xform)
305 int ret = TEST_FAILED;
307 /* initialize zlib stream */
308 stream.zalloc = Z_NULL;
309 stream.zfree = Z_NULL;
310 stream.opaque = Z_NULL;
313 * Window bits is the base two logarithm of the window size (in bytes).
314 * When doing raw DEFLATE, this number will be negative.
316 window_bits = -(xform->decompress.window_size);
318 ret = inflateInit2(&stream, window_bits);
321 printf("Zlib deflate could not be initialized\n");
325 /* Assuming stateless operation */
326 stream.avail_in = op->src.length;
327 stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
328 stream.avail_out = op->m_dst->data_len;
329 stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
331 /* Stateless operation, all buffer will be compressed in one go */
332 zlib_flush = map_zlib_flush_flag(op->flush_flag);
333 ret = inflate(&stream, zlib_flush);
335 if (stream.avail_in != 0) {
336 RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
340 if (ret != Z_STREAM_END)
343 op->consumed = op->src.length - stream.avail_in;
344 op->produced = op->m_dst->data_len - stream.avail_out;
345 op->status = RTE_COMP_OP_STATUS_SUCCESS;
347 inflateReset(&stream);
357 * Compresses and decompresses buffer with compressdev API and Zlib API
360 test_deflate_comp_decomp(const char * const test_bufs[],
361 unsigned int num_bufs,
363 struct rte_comp_xform *compress_xforms[],
364 struct rte_comp_xform *decompress_xforms[],
365 unsigned int num_xforms,
366 enum rte_comp_op_type state,
367 enum zlib_direction zlib_dir)
369 struct comp_testsuite_params *ts_params = &testsuite_params;
372 struct rte_mbuf *uncomp_bufs[num_bufs];
373 struct rte_mbuf *comp_bufs[num_bufs];
374 struct rte_comp_op *ops[num_bufs];
375 struct rte_comp_op *ops_processed[num_bufs];
376 void *priv_xforms[num_bufs];
377 uint16_t num_enqd, num_deqd, num_total_deqd;
378 uint16_t num_priv_xforms = 0;
379 unsigned int deqd_retries = 0;
380 struct priv_op_data *priv_data;
383 const struct rte_compressdev_capabilities *capa =
384 rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
386 /* Initialize all arrays to NULL */
387 memset(uncomp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
388 memset(comp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
389 memset(ops, 0, sizeof(struct rte_comp_op *) * num_bufs);
390 memset(ops_processed, 0, sizeof(struct rte_comp_op *) * num_bufs);
391 memset(priv_xforms, 0, sizeof(void *) * num_bufs);
393 /* Prepare the source mbufs with the data */
394 ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
397 "Source mbufs could not be allocated "
398 "from the mempool\n");
402 for (i = 0; i < num_bufs; i++) {
403 data_ptr = rte_pktmbuf_append(uncomp_bufs[i],
404 strlen(test_bufs[i]) + 1);
405 snprintf(data_ptr, strlen(test_bufs[i]) + 1, "%s",
409 /* Prepare the destination mbufs */
410 ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, comp_bufs, num_bufs);
413 "Destination mbufs could not be allocated "
414 "from the mempool\n");
418 for (i = 0; i < num_bufs; i++)
419 rte_pktmbuf_append(comp_bufs[i],
420 strlen(test_bufs[i]) * COMPRESS_BUF_SIZE_RATIO);
422 /* Build the compression operations */
423 ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
426 "Compress operations could not be allocated "
427 "from the mempool\n");
431 for (i = 0; i < num_bufs; i++) {
432 ops[i]->m_src = uncomp_bufs[i];
433 ops[i]->m_dst = comp_bufs[i];
434 ops[i]->src.offset = 0;
435 ops[i]->src.length = rte_pktmbuf_pkt_len(uncomp_bufs[i]);
436 ops[i]->dst.offset = 0;
437 if (state == RTE_COMP_OP_STATELESS) {
438 ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
441 "Stateful operations are not supported "
442 "in these tests yet\n");
445 ops[i]->input_chksum = 0;
447 * Store original operation index in private data,
448 * since ordering does not have to be maintained,
449 * when dequeueing from compressdev, so a comparison
450 * at the end of the test can be done.
452 priv_data = (struct priv_op_data *) (ops[i] + 1);
453 priv_data->orig_idx = i;
456 /* Compress data (either with Zlib API or compressdev API */
457 if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
458 for (i = 0; i < num_bufs; i++) {
459 const struct rte_comp_xform *compress_xform =
460 compress_xforms[i % num_xforms];
461 ret = compress_zlib(ops[i], compress_xform,
466 ops_processed[i] = ops[i];
469 /* Create compress private xform data */
470 for (i = 0; i < num_xforms; i++) {
471 ret = rte_compressdev_private_xform_create(0,
472 (const struct rte_comp_xform *)compress_xforms[i],
476 "Compression private xform "
477 "could not be created\n");
483 if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
484 /* Attach shareable private xform data to ops */
485 for (i = 0; i < num_bufs; i++)
486 ops[i]->private_xform = priv_xforms[i % num_xforms];
488 /* Create rest of the private xforms for the other ops */
489 for (i = num_xforms; i < num_bufs; i++) {
490 ret = rte_compressdev_private_xform_create(0,
491 compress_xforms[i % num_xforms],
495 "Compression private xform "
496 "could not be created\n");
502 /* Attach non shareable private xform data to ops */
503 for (i = 0; i < num_bufs; i++)
504 ops[i]->private_xform = priv_xforms[i];
507 /* Enqueue and dequeue all operations */
508 num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
509 if (num_enqd < num_bufs) {
511 "The operations could not be enqueued\n");
518 * If retrying a dequeue call, wait for 10 ms to allow
519 * enough time to the driver to process the operations
521 if (deqd_retries != 0) {
523 * Avoid infinite loop if not all the
524 * operations get out of the device
526 if (deqd_retries == MAX_DEQD_RETRIES) {
528 "Not all operations could be "
532 usleep(DEQUEUE_WAIT_TIME);
534 num_deqd = rte_compressdev_dequeue_burst(0, 0,
535 &ops_processed[num_total_deqd], num_bufs);
536 num_total_deqd += num_deqd;
538 } while (num_total_deqd < num_enqd);
542 /* Free compress private xforms */
543 for (i = 0; i < num_priv_xforms; i++) {
544 rte_compressdev_private_xform_free(0, priv_xforms[i]);
545 priv_xforms[i] = NULL;
550 for (i = 0; i < num_bufs; i++) {
551 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
552 uint16_t xform_idx = priv_data->orig_idx % num_xforms;
553 const struct rte_comp_compress_xform *compress_xform =
554 &compress_xforms[xform_idx]->compress;
555 enum rte_comp_huffman huffman_type =
556 compress_xform->deflate.huffman;
557 RTE_LOG(DEBUG, USER1, "Buffer %u compressed from %u to %u bytes "
558 "(level = %d, huffman = %s)\n",
559 buf_idx[priv_data->orig_idx],
560 ops_processed[i]->consumed, ops_processed[i]->produced,
561 compress_xform->level,
562 huffman_type_strings[huffman_type]);
563 RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
564 (float)ops_processed[i]->produced /
565 ops_processed[i]->consumed * 100);
570 * Check operation status and free source mbufs (destination mbuf and
571 * compress operation information is needed for the decompression stage)
573 for (i = 0; i < num_bufs; i++) {
574 if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
576 "Some operations were not successful\n");
579 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
580 rte_pktmbuf_free(uncomp_bufs[priv_data->orig_idx]);
581 uncomp_bufs[priv_data->orig_idx] = NULL;
584 /* Allocate buffers for decompressed data */
585 ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
588 "Destination mbufs could not be allocated "
589 "from the mempool\n");
593 for (i = 0; i < num_bufs; i++) {
594 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
595 rte_pktmbuf_append(uncomp_bufs[i],
596 strlen(test_bufs[priv_data->orig_idx]) + 1);
599 /* Build the decompression operations */
600 ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
603 "Decompress operations could not be allocated "
604 "from the mempool\n");
608 /* Source buffer is the compressed data from the previous operations */
609 for (i = 0; i < num_bufs; i++) {
610 ops[i]->m_src = ops_processed[i]->m_dst;
611 ops[i]->m_dst = uncomp_bufs[i];
612 ops[i]->src.offset = 0;
614 * Set the length of the compressed data to the
615 * number of bytes that were produced in the previous stage
617 ops[i]->src.length = ops_processed[i]->produced;
618 ops[i]->dst.offset = 0;
619 if (state == RTE_COMP_OP_STATELESS) {
620 ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
623 "Stateful operations are not supported "
624 "in these tests yet\n");
627 ops[i]->input_chksum = 0;
629 * Copy private data from previous operations,
630 * to keep the pointer to the original buffer
632 memcpy(ops[i] + 1, ops_processed[i] + 1,
633 sizeof(struct priv_op_data));
637 * Free the previous compress operations,
638 * as it is not needed anymore
640 for (i = 0; i < num_bufs; i++) {
641 rte_comp_op_free(ops_processed[i]);
642 ops_processed[i] = NULL;
645 /* Decompress data (either with Zlib API or compressdev API */
646 if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
647 for (i = 0; i < num_bufs; i++) {
648 priv_data = (struct priv_op_data *)(ops[i] + 1);
649 uint16_t xform_idx = priv_data->orig_idx % num_xforms;
650 const struct rte_comp_xform *decompress_xform =
651 decompress_xforms[xform_idx];
653 ret = decompress_zlib(ops[i], decompress_xform);
657 ops_processed[i] = ops[i];
660 /* Create decompress private xform data */
661 for (i = 0; i < num_xforms; i++) {
662 ret = rte_compressdev_private_xform_create(0,
663 (const struct rte_comp_xform *)decompress_xforms[i],
667 "Decompression private xform "
668 "could not be created\n");
674 if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
675 /* Attach shareable private xform data to ops */
676 for (i = 0; i < num_bufs; i++) {
677 priv_data = (struct priv_op_data *)(ops[i] + 1);
678 uint16_t xform_idx = priv_data->orig_idx %
680 ops[i]->private_xform = priv_xforms[xform_idx];
683 /* Create rest of the private xforms for the other ops */
684 for (i = num_xforms; i < num_bufs; i++) {
685 ret = rte_compressdev_private_xform_create(0,
686 decompress_xforms[i % num_xforms],
690 "Decompression private xform "
691 "could not be created\n");
697 /* Attach non shareable private xform data to ops */
698 for (i = 0; i < num_bufs; i++) {
699 priv_data = (struct priv_op_data *) (ops[i] + 1);
700 uint16_t xform_idx = priv_data->orig_idx;
701 ops[i]->private_xform = priv_xforms[xform_idx];
705 /* Enqueue and dequeue all operations */
706 num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
707 if (num_enqd < num_bufs) {
709 "The operations could not be enqueued\n");
716 * If retrying a dequeue call, wait for 10 ms to allow
717 * enough time to the driver to process the operations
719 if (deqd_retries != 0) {
721 * Avoid infinite loop if not all the
722 * operations get out of the device
724 if (deqd_retries == MAX_DEQD_RETRIES) {
726 "Not all operations could be "
730 usleep(DEQUEUE_WAIT_TIME);
732 num_deqd = rte_compressdev_dequeue_burst(0, 0,
733 &ops_processed[num_total_deqd], num_bufs);
734 num_total_deqd += num_deqd;
736 } while (num_total_deqd < num_enqd);
741 for (i = 0; i < num_bufs; i++) {
742 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
743 RTE_LOG(DEBUG, USER1, "Buffer %u decompressed from %u to %u bytes\n",
744 buf_idx[priv_data->orig_idx],
745 ops_processed[i]->consumed, ops_processed[i]->produced);
750 * Check operation status and free source mbuf (destination mbuf and
751 * compress operation information is still needed)
753 for (i = 0; i < num_bufs; i++) {
754 if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
756 "Some operations were not successful\n");
759 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
760 rte_pktmbuf_free(comp_bufs[priv_data->orig_idx]);
761 comp_bufs[priv_data->orig_idx] = NULL;
765 * Compare the original stream with the decompressed stream
766 * (in size and the data)
768 for (i = 0; i < num_bufs; i++) {
769 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
770 const char *buf1 = test_bufs[priv_data->orig_idx];
771 const char *buf2 = rte_pktmbuf_mtod(ops_processed[i]->m_dst,
774 if (compare_buffers(buf1, strlen(buf1) + 1,
775 buf2, ops_processed[i]->produced) < 0)
783 for (i = 0; i < num_bufs; i++) {
784 rte_pktmbuf_free(uncomp_bufs[i]);
785 rte_pktmbuf_free(comp_bufs[i]);
786 rte_comp_op_free(ops[i]);
787 rte_comp_op_free(ops_processed[i]);
789 for (i = 0; i < num_priv_xforms; i++) {
790 if (priv_xforms[i] != NULL)
791 rte_compressdev_private_xform_free(0, priv_xforms[i]);
798 test_compressdev_deflate_stateless_fixed(void)
800 struct comp_testsuite_params *ts_params = &testsuite_params;
801 const char *test_buffer;
804 struct rte_comp_xform *compress_xform =
805 rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
807 if (compress_xform == NULL) {
809 "Compress xform could not be created\n");
814 memcpy(compress_xform, ts_params->def_comp_xform,
815 sizeof(struct rte_comp_xform));
816 compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
818 for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
819 test_buffer = compress_test_bufs[i];
821 /* Compress with compressdev, decompress with Zlib */
822 if (test_deflate_comp_decomp(&test_buffer, 1,
825 &ts_params->def_decomp_xform,
827 RTE_COMP_OP_STATELESS,
828 ZLIB_DECOMPRESS) < 0) {
833 /* Compress with Zlib, decompress with compressdev */
834 if (test_deflate_comp_decomp(&test_buffer, 1,
837 &ts_params->def_decomp_xform,
839 RTE_COMP_OP_STATELESS,
840 ZLIB_COMPRESS) < 0) {
849 rte_free(compress_xform);
854 test_compressdev_deflate_stateless_dynamic(void)
856 struct comp_testsuite_params *ts_params = &testsuite_params;
857 const char *test_buffer;
860 struct rte_comp_xform *compress_xform =
861 rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
863 if (compress_xform == NULL) {
865 "Compress xform could not be created\n");
870 memcpy(compress_xform, ts_params->def_comp_xform,
871 sizeof(struct rte_comp_xform));
872 compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
874 for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
875 test_buffer = compress_test_bufs[i];
877 /* Compress with compressdev, decompress with Zlib */
878 if (test_deflate_comp_decomp(&test_buffer, 1,
881 &ts_params->def_decomp_xform,
883 RTE_COMP_OP_STATELESS,
884 ZLIB_DECOMPRESS) < 0) {
889 /* Compress with Zlib, decompress with compressdev */
890 if (test_deflate_comp_decomp(&test_buffer, 1,
893 &ts_params->def_decomp_xform,
895 RTE_COMP_OP_STATELESS,
896 ZLIB_COMPRESS) < 0) {
905 rte_free(compress_xform);
910 test_compressdev_deflate_stateless_multi_op(void)
912 struct comp_testsuite_params *ts_params = &testsuite_params;
913 uint16_t num_bufs = RTE_DIM(compress_test_bufs);
914 uint16_t buf_idx[num_bufs];
917 for (i = 0; i < num_bufs; i++)
920 /* Compress with compressdev, decompress with Zlib */
921 if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
923 &ts_params->def_comp_xform,
924 &ts_params->def_decomp_xform,
926 RTE_COMP_OP_STATELESS,
927 ZLIB_DECOMPRESS) < 0)
930 /* Compress with Zlib, decompress with compressdev */
931 if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
933 &ts_params->def_comp_xform,
934 &ts_params->def_decomp_xform,
936 RTE_COMP_OP_STATELESS,
944 test_compressdev_deflate_stateless_multi_level(void)
946 struct comp_testsuite_params *ts_params = &testsuite_params;
947 const char *test_buffer;
951 struct rte_comp_xform *compress_xform =
952 rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
954 if (compress_xform == NULL) {
956 "Compress xform could not be created\n");
961 memcpy(compress_xform, ts_params->def_comp_xform,
962 sizeof(struct rte_comp_xform));
964 for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
965 test_buffer = compress_test_bufs[i];
966 for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
968 compress_xform->compress.level = level;
969 /* Compress with compressdev, decompress with Zlib */
970 if (test_deflate_comp_decomp(&test_buffer, 1,
973 &ts_params->def_decomp_xform,
975 RTE_COMP_OP_STATELESS,
976 ZLIB_DECOMPRESS) < 0) {
986 rte_free(compress_xform);
992 test_compressdev_deflate_stateless_multi_xform(void)
994 struct comp_testsuite_params *ts_params = &testsuite_params;
995 uint16_t num_bufs = NUM_XFORMS;
996 struct rte_comp_xform *compress_xforms[NUM_XFORMS] = {NULL};
997 struct rte_comp_xform *decompress_xforms[NUM_XFORMS] = {NULL};
998 const char *test_buffers[NUM_XFORMS];
1000 unsigned int level = RTE_COMP_LEVEL_MIN;
1001 uint16_t buf_idx[num_bufs];
1005 /* Create multiple xforms with various levels */
1006 for (i = 0; i < NUM_XFORMS; i++) {
1007 compress_xforms[i] = rte_malloc(NULL,
1008 sizeof(struct rte_comp_xform), 0);
1009 if (compress_xforms[i] == NULL) {
1011 "Compress xform could not be created\n");
1016 memcpy(compress_xforms[i], ts_params->def_comp_xform,
1017 sizeof(struct rte_comp_xform));
1018 compress_xforms[i]->compress.level = level;
1021 decompress_xforms[i] = rte_malloc(NULL,
1022 sizeof(struct rte_comp_xform), 0);
1023 if (decompress_xforms[i] == NULL) {
1025 "Decompress xform could not be created\n");
1030 memcpy(decompress_xforms[i], ts_params->def_decomp_xform,
1031 sizeof(struct rte_comp_xform));
1034 for (i = 0; i < NUM_XFORMS; i++) {
1036 /* Use the same buffer in all sessions */
1037 test_buffers[i] = compress_test_bufs[0];
1039 /* Compress with compressdev, decompress with Zlib */
1040 if (test_deflate_comp_decomp(test_buffers, num_bufs,
1045 RTE_COMP_OP_STATELESS,
1046 ZLIB_DECOMPRESS) < 0) {
1053 for (i = 0; i < NUM_XFORMS; i++) {
1054 rte_free(compress_xforms[i]);
1055 rte_free(decompress_xforms[i]);
1061 static struct unit_test_suite compressdev_testsuite = {
1062 .suite_name = "compressdev unit test suite",
1063 .setup = testsuite_setup,
1064 .teardown = testsuite_teardown,
1065 .unit_test_cases = {
1066 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1067 test_compressdev_deflate_stateless_fixed),
1068 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1069 test_compressdev_deflate_stateless_dynamic),
1070 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1071 test_compressdev_deflate_stateless_multi_op),
1072 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1073 test_compressdev_deflate_stateless_multi_level),
1074 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1075 test_compressdev_deflate_stateless_multi_xform),
1076 TEST_CASES_END() /**< NULL terminate unit test array */
1081 test_compressdev(void)
1083 return unit_test_suite_runner(&compressdev_testsuite);
1086 REGISTER_TEST_COMMAND(compressdev_autotest, test_compressdev);