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 test_compressdev_invalid_configuration(void)
191 struct rte_compressdev_config invalid_config;
192 struct rte_compressdev_config valid_config = {
193 .socket_id = rte_socket_id(),
195 .max_nb_priv_xforms = NUM_MAX_XFORMS,
198 struct rte_compressdev_info dev_info;
200 /* Invalid configuration with 0 queue pairs */
201 memcpy(&invalid_config, &valid_config,
202 sizeof(struct rte_compressdev_config));
203 invalid_config.nb_queue_pairs = 0;
205 TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
206 "Device configuration was successful "
207 "with no queue pairs (invalid)\n");
210 * Invalid configuration with too many queue pairs
211 * (if there is an actual maximum number of queue pairs)
213 rte_compressdev_info_get(0, &dev_info);
214 if (dev_info.max_nb_queue_pairs != 0) {
215 memcpy(&invalid_config, &valid_config,
216 sizeof(struct rte_compressdev_config));
217 invalid_config.nb_queue_pairs = dev_info.max_nb_queue_pairs + 1;
219 TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
220 "Device configuration was successful "
221 "with too many queue pairs (invalid)\n");
224 /* Invalid queue pair setup, with no number of queue pairs set */
225 TEST_ASSERT_FAIL(rte_compressdev_queue_pair_setup(0, 0,
226 NUM_MAX_INFLIGHT_OPS, rte_socket_id()),
227 "Queue pair setup was successful "
228 "with no queue pairs set (invalid)\n");
234 compare_buffers(const char *buffer1, uint32_t buffer1_len,
235 const char *buffer2, uint32_t buffer2_len)
237 if (buffer1_len != buffer2_len) {
238 RTE_LOG(ERR, USER1, "Buffer lengths are different\n");
242 if (memcmp(buffer1, buffer2, buffer1_len) != 0) {
243 RTE_LOG(ERR, USER1, "Buffers are different\n");
251 * Maps compressdev and Zlib flush flags
254 map_zlib_flush_flag(enum rte_comp_flush_flag flag)
257 case RTE_COMP_FLUSH_NONE:
259 case RTE_COMP_FLUSH_SYNC:
261 case RTE_COMP_FLUSH_FULL:
263 case RTE_COMP_FLUSH_FINAL:
266 * There should be only the values above,
267 * so this should never happen
275 compress_zlib(struct rte_comp_op *op,
276 const struct rte_comp_xform *xform, int mem_level)
280 int strategy, window_bits, comp_level;
283 /* initialize zlib stream */
284 stream.zalloc = Z_NULL;
285 stream.zfree = Z_NULL;
286 stream.opaque = Z_NULL;
288 if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED)
291 strategy = Z_DEFAULT_STRATEGY;
294 * Window bits is the base two logarithm of the window size (in bytes).
295 * When doing raw DEFLATE, this number will be negative.
297 window_bits = -(xform->compress.window_size);
299 comp_level = xform->compress.level;
301 if (comp_level != RTE_COMP_LEVEL_NONE)
302 ret = deflateInit2(&stream, comp_level, Z_DEFLATED,
303 window_bits, mem_level, strategy);
305 ret = deflateInit(&stream, Z_NO_COMPRESSION);
308 printf("Zlib deflate could not be initialized\n");
312 /* Assuming stateless operation */
313 stream.avail_in = op->src.length;
314 stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
315 stream.avail_out = op->m_dst->data_len;
316 stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
318 /* Stateless operation, all buffer will be compressed in one go */
319 zlib_flush = map_zlib_flush_flag(op->flush_flag);
320 ret = deflate(&stream, zlib_flush);
322 if (stream.avail_in != 0) {
323 RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
327 if (ret != Z_STREAM_END)
330 op->consumed = op->src.length - stream.avail_in;
331 op->produced = op->m_dst->data_len - stream.avail_out;
332 op->status = RTE_COMP_OP_STATUS_SUCCESS;
334 deflateReset(&stream);
344 decompress_zlib(struct rte_comp_op *op,
345 const struct rte_comp_xform *xform)
350 int ret = TEST_FAILED;
352 /* initialize zlib stream */
353 stream.zalloc = Z_NULL;
354 stream.zfree = Z_NULL;
355 stream.opaque = Z_NULL;
358 * Window bits is the base two logarithm of the window size (in bytes).
359 * When doing raw DEFLATE, this number will be negative.
361 window_bits = -(xform->decompress.window_size);
363 ret = inflateInit2(&stream, window_bits);
366 printf("Zlib deflate could not be initialized\n");
370 /* Assuming stateless operation */
371 stream.avail_in = op->src.length;
372 stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
373 stream.avail_out = op->m_dst->data_len;
374 stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
376 /* Stateless operation, all buffer will be compressed in one go */
377 zlib_flush = map_zlib_flush_flag(op->flush_flag);
378 ret = inflate(&stream, zlib_flush);
380 if (stream.avail_in != 0) {
381 RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
385 if (ret != Z_STREAM_END)
388 op->consumed = op->src.length - stream.avail_in;
389 op->produced = op->m_dst->data_len - stream.avail_out;
390 op->status = RTE_COMP_OP_STATUS_SUCCESS;
392 inflateReset(&stream);
402 * Compresses and decompresses buffer with compressdev API and Zlib API
405 test_deflate_comp_decomp(const char * const test_bufs[],
406 unsigned int num_bufs,
408 struct rte_comp_xform *compress_xforms[],
409 struct rte_comp_xform *decompress_xforms[],
410 unsigned int num_xforms,
411 enum rte_comp_op_type state,
412 enum zlib_direction zlib_dir)
414 struct comp_testsuite_params *ts_params = &testsuite_params;
417 struct rte_mbuf *uncomp_bufs[num_bufs];
418 struct rte_mbuf *comp_bufs[num_bufs];
419 struct rte_comp_op *ops[num_bufs];
420 struct rte_comp_op *ops_processed[num_bufs];
421 void *priv_xforms[num_bufs];
422 uint16_t num_enqd, num_deqd, num_total_deqd;
423 uint16_t num_priv_xforms = 0;
424 unsigned int deqd_retries = 0;
425 struct priv_op_data *priv_data;
428 const struct rte_compressdev_capabilities *capa =
429 rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
431 /* Initialize all arrays to NULL */
432 memset(uncomp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
433 memset(comp_bufs, 0, sizeof(struct rte_mbuf *) * num_bufs);
434 memset(ops, 0, sizeof(struct rte_comp_op *) * num_bufs);
435 memset(ops_processed, 0, sizeof(struct rte_comp_op *) * num_bufs);
436 memset(priv_xforms, 0, sizeof(void *) * num_bufs);
438 /* Prepare the source mbufs with the data */
439 ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
442 "Source mbufs could not be allocated "
443 "from the mempool\n");
447 for (i = 0; i < num_bufs; i++) {
448 data_ptr = rte_pktmbuf_append(uncomp_bufs[i],
449 strlen(test_bufs[i]) + 1);
450 snprintf(data_ptr, strlen(test_bufs[i]) + 1, "%s",
454 /* Prepare the destination mbufs */
455 ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, comp_bufs, num_bufs);
458 "Destination mbufs could not be allocated "
459 "from the mempool\n");
463 for (i = 0; i < num_bufs; i++)
464 rte_pktmbuf_append(comp_bufs[i],
465 strlen(test_bufs[i]) * COMPRESS_BUF_SIZE_RATIO);
467 /* Build the compression operations */
468 ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
471 "Compress operations could not be allocated "
472 "from the mempool\n");
476 for (i = 0; i < num_bufs; i++) {
477 ops[i]->m_src = uncomp_bufs[i];
478 ops[i]->m_dst = comp_bufs[i];
479 ops[i]->src.offset = 0;
480 ops[i]->src.length = rte_pktmbuf_pkt_len(uncomp_bufs[i]);
481 ops[i]->dst.offset = 0;
482 if (state == RTE_COMP_OP_STATELESS) {
483 ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
486 "Stateful operations are not supported "
487 "in these tests yet\n");
490 ops[i]->input_chksum = 0;
492 * Store original operation index in private data,
493 * since ordering does not have to be maintained,
494 * when dequeueing from compressdev, so a comparison
495 * at the end of the test can be done.
497 priv_data = (struct priv_op_data *) (ops[i] + 1);
498 priv_data->orig_idx = i;
501 /* Compress data (either with Zlib API or compressdev API */
502 if (zlib_dir == ZLIB_COMPRESS || zlib_dir == ZLIB_ALL) {
503 for (i = 0; i < num_bufs; i++) {
504 const struct rte_comp_xform *compress_xform =
505 compress_xforms[i % num_xforms];
506 ret = compress_zlib(ops[i], compress_xform,
511 ops_processed[i] = ops[i];
514 /* Create compress private xform data */
515 for (i = 0; i < num_xforms; i++) {
516 ret = rte_compressdev_private_xform_create(0,
517 (const struct rte_comp_xform *)compress_xforms[i],
521 "Compression private xform "
522 "could not be created\n");
528 if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
529 /* Attach shareable private xform data to ops */
530 for (i = 0; i < num_bufs; i++)
531 ops[i]->private_xform = priv_xforms[i % num_xforms];
533 /* Create rest of the private xforms for the other ops */
534 for (i = num_xforms; i < num_bufs; i++) {
535 ret = rte_compressdev_private_xform_create(0,
536 compress_xforms[i % num_xforms],
540 "Compression private xform "
541 "could not be created\n");
547 /* Attach non shareable private xform data to ops */
548 for (i = 0; i < num_bufs; i++)
549 ops[i]->private_xform = priv_xforms[i];
552 /* Enqueue and dequeue all operations */
553 num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
554 if (num_enqd < num_bufs) {
556 "The operations could not be enqueued\n");
563 * If retrying a dequeue call, wait for 10 ms to allow
564 * enough time to the driver to process the operations
566 if (deqd_retries != 0) {
568 * Avoid infinite loop if not all the
569 * operations get out of the device
571 if (deqd_retries == MAX_DEQD_RETRIES) {
573 "Not all operations could be "
577 usleep(DEQUEUE_WAIT_TIME);
579 num_deqd = rte_compressdev_dequeue_burst(0, 0,
580 &ops_processed[num_total_deqd], num_bufs);
581 num_total_deqd += num_deqd;
583 } while (num_total_deqd < num_enqd);
587 /* Free compress private xforms */
588 for (i = 0; i < num_priv_xforms; i++) {
589 rte_compressdev_private_xform_free(0, priv_xforms[i]);
590 priv_xforms[i] = NULL;
595 for (i = 0; i < num_bufs; i++) {
596 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
597 uint16_t xform_idx = priv_data->orig_idx % num_xforms;
598 const struct rte_comp_compress_xform *compress_xform =
599 &compress_xforms[xform_idx]->compress;
600 enum rte_comp_huffman huffman_type =
601 compress_xform->deflate.huffman;
602 RTE_LOG(DEBUG, USER1, "Buffer %u compressed from %u to %u bytes "
603 "(level = %d, huffman = %s)\n",
604 buf_idx[priv_data->orig_idx],
605 ops_processed[i]->consumed, ops_processed[i]->produced,
606 compress_xform->level,
607 huffman_type_strings[huffman_type]);
608 RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f",
609 (float)ops_processed[i]->produced /
610 ops_processed[i]->consumed * 100);
615 * Check operation status and free source mbufs (destination mbuf and
616 * compress operation information is needed for the decompression stage)
618 for (i = 0; i < num_bufs; i++) {
619 if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
621 "Some operations were not successful\n");
624 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
625 rte_pktmbuf_free(uncomp_bufs[priv_data->orig_idx]);
626 uncomp_bufs[priv_data->orig_idx] = NULL;
629 /* Allocate buffers for decompressed data */
630 ret = rte_pktmbuf_alloc_bulk(ts_params->mbuf_pool, uncomp_bufs, num_bufs);
633 "Destination mbufs could not be allocated "
634 "from the mempool\n");
638 for (i = 0; i < num_bufs; i++) {
639 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
640 rte_pktmbuf_append(uncomp_bufs[i],
641 strlen(test_bufs[priv_data->orig_idx]) + 1);
644 /* Build the decompression operations */
645 ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
648 "Decompress operations could not be allocated "
649 "from the mempool\n");
653 /* Source buffer is the compressed data from the previous operations */
654 for (i = 0; i < num_bufs; i++) {
655 ops[i]->m_src = ops_processed[i]->m_dst;
656 ops[i]->m_dst = uncomp_bufs[i];
657 ops[i]->src.offset = 0;
659 * Set the length of the compressed data to the
660 * number of bytes that were produced in the previous stage
662 ops[i]->src.length = ops_processed[i]->produced;
663 ops[i]->dst.offset = 0;
664 if (state == RTE_COMP_OP_STATELESS) {
665 ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
668 "Stateful operations are not supported "
669 "in these tests yet\n");
672 ops[i]->input_chksum = 0;
674 * Copy private data from previous operations,
675 * to keep the pointer to the original buffer
677 memcpy(ops[i] + 1, ops_processed[i] + 1,
678 sizeof(struct priv_op_data));
682 * Free the previous compress operations,
683 * as it is not needed anymore
685 for (i = 0; i < num_bufs; i++) {
686 rte_comp_op_free(ops_processed[i]);
687 ops_processed[i] = NULL;
690 /* Decompress data (either with Zlib API or compressdev API */
691 if (zlib_dir == ZLIB_DECOMPRESS || zlib_dir == ZLIB_ALL) {
692 for (i = 0; i < num_bufs; i++) {
693 priv_data = (struct priv_op_data *)(ops[i] + 1);
694 uint16_t xform_idx = priv_data->orig_idx % num_xforms;
695 const struct rte_comp_xform *decompress_xform =
696 decompress_xforms[xform_idx];
698 ret = decompress_zlib(ops[i], decompress_xform);
702 ops_processed[i] = ops[i];
705 /* Create decompress private xform data */
706 for (i = 0; i < num_xforms; i++) {
707 ret = rte_compressdev_private_xform_create(0,
708 (const struct rte_comp_xform *)decompress_xforms[i],
712 "Decompression private xform "
713 "could not be created\n");
719 if (capa->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
720 /* Attach shareable private xform data to ops */
721 for (i = 0; i < num_bufs; i++) {
722 priv_data = (struct priv_op_data *)(ops[i] + 1);
723 uint16_t xform_idx = priv_data->orig_idx %
725 ops[i]->private_xform = priv_xforms[xform_idx];
728 /* Create rest of the private xforms for the other ops */
729 for (i = num_xforms; i < num_bufs; i++) {
730 ret = rte_compressdev_private_xform_create(0,
731 decompress_xforms[i % num_xforms],
735 "Decompression private xform "
736 "could not be created\n");
742 /* Attach non shareable private xform data to ops */
743 for (i = 0; i < num_bufs; i++) {
744 priv_data = (struct priv_op_data *)(ops[i] + 1);
745 uint16_t xform_idx = priv_data->orig_idx;
746 ops[i]->private_xform = priv_xforms[xform_idx];
750 /* Enqueue and dequeue all operations */
751 num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
752 if (num_enqd < num_bufs) {
754 "The operations could not be enqueued\n");
761 * If retrying a dequeue call, wait for 10 ms to allow
762 * enough time to the driver to process the operations
764 if (deqd_retries != 0) {
766 * Avoid infinite loop if not all the
767 * operations get out of the device
769 if (deqd_retries == MAX_DEQD_RETRIES) {
771 "Not all operations could be "
775 usleep(DEQUEUE_WAIT_TIME);
777 num_deqd = rte_compressdev_dequeue_burst(0, 0,
778 &ops_processed[num_total_deqd], num_bufs);
779 num_total_deqd += num_deqd;
781 } while (num_total_deqd < num_enqd);
786 for (i = 0; i < num_bufs; i++) {
787 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
788 RTE_LOG(DEBUG, USER1, "Buffer %u decompressed from %u to %u bytes\n",
789 buf_idx[priv_data->orig_idx],
790 ops_processed[i]->consumed, ops_processed[i]->produced);
795 * Check operation status and free source mbuf (destination mbuf and
796 * compress operation information is still needed)
798 for (i = 0; i < num_bufs; i++) {
799 if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
801 "Some operations were not successful\n");
804 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
805 rte_pktmbuf_free(comp_bufs[priv_data->orig_idx]);
806 comp_bufs[priv_data->orig_idx] = NULL;
810 * Compare the original stream with the decompressed stream
811 * (in size and the data)
813 for (i = 0; i < num_bufs; i++) {
814 priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
815 const char *buf1 = test_bufs[priv_data->orig_idx];
816 const char *buf2 = rte_pktmbuf_mtod(ops_processed[i]->m_dst,
819 if (compare_buffers(buf1, strlen(buf1) + 1,
820 buf2, ops_processed[i]->produced) < 0)
828 for (i = 0; i < num_bufs; i++) {
829 rte_pktmbuf_free(uncomp_bufs[i]);
830 rte_pktmbuf_free(comp_bufs[i]);
831 rte_comp_op_free(ops[i]);
832 rte_comp_op_free(ops_processed[i]);
834 for (i = 0; i < num_priv_xforms; i++) {
835 if (priv_xforms[i] != NULL)
836 rte_compressdev_private_xform_free(0, priv_xforms[i]);
843 test_compressdev_deflate_stateless_fixed(void)
845 struct comp_testsuite_params *ts_params = &testsuite_params;
846 const char *test_buffer;
849 const struct rte_compressdev_capabilities *capab;
851 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
852 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
854 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0)
857 struct rte_comp_xform *compress_xform =
858 rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
860 if (compress_xform == NULL) {
862 "Compress xform could not be created\n");
867 memcpy(compress_xform, ts_params->def_comp_xform,
868 sizeof(struct rte_comp_xform));
869 compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
871 for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
872 test_buffer = compress_test_bufs[i];
874 /* Compress with compressdev, decompress with Zlib */
875 if (test_deflate_comp_decomp(&test_buffer, 1,
878 &ts_params->def_decomp_xform,
880 RTE_COMP_OP_STATELESS,
881 ZLIB_DECOMPRESS) < 0) {
886 /* Compress with Zlib, decompress with compressdev */
887 if (test_deflate_comp_decomp(&test_buffer, 1,
890 &ts_params->def_decomp_xform,
892 RTE_COMP_OP_STATELESS,
893 ZLIB_COMPRESS) < 0) {
902 rte_free(compress_xform);
907 test_compressdev_deflate_stateless_dynamic(void)
909 struct comp_testsuite_params *ts_params = &testsuite_params;
910 const char *test_buffer;
913 struct rte_comp_xform *compress_xform =
914 rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
916 const struct rte_compressdev_capabilities *capab;
918 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
919 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
921 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
924 if (compress_xform == NULL) {
926 "Compress xform could not be created\n");
931 memcpy(compress_xform, ts_params->def_comp_xform,
932 sizeof(struct rte_comp_xform));
933 compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
935 for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
936 test_buffer = compress_test_bufs[i];
938 /* Compress with compressdev, decompress with Zlib */
939 if (test_deflate_comp_decomp(&test_buffer, 1,
942 &ts_params->def_decomp_xform,
944 RTE_COMP_OP_STATELESS,
945 ZLIB_DECOMPRESS) < 0) {
950 /* Compress with Zlib, decompress with compressdev */
951 if (test_deflate_comp_decomp(&test_buffer, 1,
954 &ts_params->def_decomp_xform,
956 RTE_COMP_OP_STATELESS,
957 ZLIB_COMPRESS) < 0) {
966 rte_free(compress_xform);
971 test_compressdev_deflate_stateless_multi_op(void)
973 struct comp_testsuite_params *ts_params = &testsuite_params;
974 uint16_t num_bufs = RTE_DIM(compress_test_bufs);
975 uint16_t buf_idx[num_bufs];
978 for (i = 0; i < num_bufs; i++)
981 /* Compress with compressdev, decompress with Zlib */
982 if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
984 &ts_params->def_comp_xform,
985 &ts_params->def_decomp_xform,
987 RTE_COMP_OP_STATELESS,
988 ZLIB_DECOMPRESS) < 0)
991 /* Compress with Zlib, decompress with compressdev */
992 if (test_deflate_comp_decomp(compress_test_bufs, num_bufs,
994 &ts_params->def_comp_xform,
995 &ts_params->def_decomp_xform,
997 RTE_COMP_OP_STATELESS,
1001 return TEST_SUCCESS;
1005 test_compressdev_deflate_stateless_multi_level(void)
1007 struct comp_testsuite_params *ts_params = &testsuite_params;
1008 const char *test_buffer;
1012 struct rte_comp_xform *compress_xform =
1013 rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
1015 if (compress_xform == NULL) {
1017 "Compress xform could not be created\n");
1022 memcpy(compress_xform, ts_params->def_comp_xform,
1023 sizeof(struct rte_comp_xform));
1025 for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
1026 test_buffer = compress_test_bufs[i];
1027 for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
1029 compress_xform->compress.level = level;
1030 /* Compress with compressdev, decompress with Zlib */
1031 if (test_deflate_comp_decomp(&test_buffer, 1,
1034 &ts_params->def_decomp_xform,
1036 RTE_COMP_OP_STATELESS,
1037 ZLIB_DECOMPRESS) < 0) {
1047 rte_free(compress_xform);
1051 #define NUM_XFORMS 3
1053 test_compressdev_deflate_stateless_multi_xform(void)
1055 struct comp_testsuite_params *ts_params = &testsuite_params;
1056 uint16_t num_bufs = NUM_XFORMS;
1057 struct rte_comp_xform *compress_xforms[NUM_XFORMS] = {NULL};
1058 struct rte_comp_xform *decompress_xforms[NUM_XFORMS] = {NULL};
1059 const char *test_buffers[NUM_XFORMS];
1061 unsigned int level = RTE_COMP_LEVEL_MIN;
1062 uint16_t buf_idx[num_bufs];
1066 /* Create multiple xforms with various levels */
1067 for (i = 0; i < NUM_XFORMS; i++) {
1068 compress_xforms[i] = rte_malloc(NULL,
1069 sizeof(struct rte_comp_xform), 0);
1070 if (compress_xforms[i] == NULL) {
1072 "Compress xform could not be created\n");
1077 memcpy(compress_xforms[i], ts_params->def_comp_xform,
1078 sizeof(struct rte_comp_xform));
1079 compress_xforms[i]->compress.level = level;
1082 decompress_xforms[i] = rte_malloc(NULL,
1083 sizeof(struct rte_comp_xform), 0);
1084 if (decompress_xforms[i] == NULL) {
1086 "Decompress xform could not be created\n");
1091 memcpy(decompress_xforms[i], ts_params->def_decomp_xform,
1092 sizeof(struct rte_comp_xform));
1095 for (i = 0; i < NUM_XFORMS; i++) {
1097 /* Use the same buffer in all sessions */
1098 test_buffers[i] = compress_test_bufs[0];
1100 /* Compress with compressdev, decompress with Zlib */
1101 if (test_deflate_comp_decomp(test_buffers, num_bufs,
1106 RTE_COMP_OP_STATELESS,
1107 ZLIB_DECOMPRESS) < 0) {
1114 for (i = 0; i < NUM_XFORMS; i++) {
1115 rte_free(compress_xforms[i]);
1116 rte_free(decompress_xforms[i]);
1122 static struct unit_test_suite compressdev_testsuite = {
1123 .suite_name = "compressdev unit test suite",
1124 .setup = testsuite_setup,
1125 .teardown = testsuite_teardown,
1126 .unit_test_cases = {
1127 TEST_CASE_ST(NULL, NULL,
1128 test_compressdev_invalid_configuration),
1129 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1130 test_compressdev_deflate_stateless_fixed),
1131 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1132 test_compressdev_deflate_stateless_dynamic),
1133 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1134 test_compressdev_deflate_stateless_multi_op),
1135 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1136 test_compressdev_deflate_stateless_multi_level),
1137 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
1138 test_compressdev_deflate_stateless_multi_xform),
1139 TEST_CASES_END() /**< NULL terminate unit test array */
1144 test_compressdev(void)
1146 return unit_test_suite_runner(&compressdev_testsuite);
1149 REGISTER_TEST_COMMAND(compressdev_autotest, test_compressdev);