14418919fSjohnjiang /* SPDX-License-Identifier: BSD-3-Clause
24418919fSjohnjiang * Copyright(c) 2018 - 2019 Intel Corporation
34418919fSjohnjiang */
44418919fSjohnjiang #include <string.h>
54418919fSjohnjiang #include <zlib.h>
64418919fSjohnjiang #include <math.h>
74418919fSjohnjiang #include <stdlib.h>
84418919fSjohnjiang #include <unistd.h>
9*2d9fd380Sjfb8856606 #include <stdio.h>
104418919fSjohnjiang
114418919fSjohnjiang #include <rte_cycles.h>
124418919fSjohnjiang #include <rte_malloc.h>
134418919fSjohnjiang #include <rte_mempool.h>
144418919fSjohnjiang #include <rte_mbuf.h>
154418919fSjohnjiang #include <rte_compressdev.h>
164418919fSjohnjiang #include <rte_string_fns.h>
174418919fSjohnjiang
184418919fSjohnjiang #include "test_compressdev_test_buffer.h"
194418919fSjohnjiang #include "test.h"
204418919fSjohnjiang
214418919fSjohnjiang #define DIV_CEIL(a, b) ((a) / (b) + ((a) % (b) != 0))
224418919fSjohnjiang
234418919fSjohnjiang #define DEFAULT_WINDOW_SIZE 15
244418919fSjohnjiang #define DEFAULT_MEM_LEVEL 8
254418919fSjohnjiang #define MAX_DEQD_RETRIES 10
264418919fSjohnjiang #define DEQUEUE_WAIT_TIME 10000
274418919fSjohnjiang
284418919fSjohnjiang /*
294418919fSjohnjiang * 30% extra size for compressed data compared to original data,
304418919fSjohnjiang * in case data size cannot be reduced and it is actually bigger
314418919fSjohnjiang * due to the compress block headers
324418919fSjohnjiang */
334418919fSjohnjiang #define COMPRESS_BUF_SIZE_RATIO 1.3
34*2d9fd380Sjfb8856606 #define COMPRESS_BUF_SIZE_RATIO_DISABLED 1.0
354418919fSjohnjiang #define COMPRESS_BUF_SIZE_RATIO_OVERFLOW 0.2
364418919fSjohnjiang #define NUM_LARGE_MBUFS 16
374418919fSjohnjiang #define SMALL_SEG_SIZE 256
384418919fSjohnjiang #define MAX_SEGS 16
394418919fSjohnjiang #define NUM_OPS 16
404418919fSjohnjiang #define NUM_MAX_XFORMS 16
414418919fSjohnjiang #define NUM_MAX_INFLIGHT_OPS 128
424418919fSjohnjiang #define CACHE_SIZE 0
434418919fSjohnjiang
444418919fSjohnjiang #define ZLIB_CRC_CHECKSUM_WINDOW_BITS 31
454418919fSjohnjiang #define ZLIB_HEADER_SIZE 2
464418919fSjohnjiang #define ZLIB_TRAILER_SIZE 4
474418919fSjohnjiang #define GZIP_HEADER_SIZE 10
484418919fSjohnjiang #define GZIP_TRAILER_SIZE 8
494418919fSjohnjiang
504418919fSjohnjiang #define OUT_OF_SPACE_BUF 1
514418919fSjohnjiang
524418919fSjohnjiang #define MAX_MBUF_SEGMENT_SIZE 65535
534418919fSjohnjiang #define MAX_DATA_MBUF_SIZE (MAX_MBUF_SEGMENT_SIZE - RTE_PKTMBUF_HEADROOM)
54*2d9fd380Sjfb8856606 #define NUM_BIG_MBUFS (512 + 1)
55*2d9fd380Sjfb8856606 #define BIG_DATA_TEST_SIZE (MAX_DATA_MBUF_SIZE * 2)
56*2d9fd380Sjfb8856606
57*2d9fd380Sjfb8856606 /* constants for "im buffer" tests start here */
58*2d9fd380Sjfb8856606
59*2d9fd380Sjfb8856606 /* number of mbufs lower than number of inflight ops */
60*2d9fd380Sjfb8856606 #define IM_BUF_NUM_MBUFS 3
61*2d9fd380Sjfb8856606 /* above threshold (QAT_FALLBACK_THLD) and below max mbuf size */
62*2d9fd380Sjfb8856606 #define IM_BUF_DATA_TEST_SIZE_LB 59600
63*2d9fd380Sjfb8856606 /* data size smaller than the queue capacity */
64*2d9fd380Sjfb8856606 #define IM_BUF_DATA_TEST_SIZE_SGL (MAX_DATA_MBUF_SIZE * IM_BUF_NUM_MBUFS)
65*2d9fd380Sjfb8856606 /* number of mbufs bigger than number of inflight ops */
66*2d9fd380Sjfb8856606 #define IM_BUF_NUM_MBUFS_OVER (NUM_MAX_INFLIGHT_OPS + 1)
67*2d9fd380Sjfb8856606 /* data size bigger than the queue capacity */
68*2d9fd380Sjfb8856606 #define IM_BUF_DATA_TEST_SIZE_OVER (MAX_DATA_MBUF_SIZE * IM_BUF_NUM_MBUFS_OVER)
69*2d9fd380Sjfb8856606 /* number of mid-size mbufs */
70*2d9fd380Sjfb8856606 #define IM_BUF_NUM_MBUFS_MID ((NUM_MAX_INFLIGHT_OPS / 3) + 1)
71*2d9fd380Sjfb8856606 /* capacity of mid-size mbufs */
72*2d9fd380Sjfb8856606 #define IM_BUF_DATA_TEST_SIZE_MID (MAX_DATA_MBUF_SIZE * IM_BUF_NUM_MBUFS_MID)
73*2d9fd380Sjfb8856606
744418919fSjohnjiang
754418919fSjohnjiang const char *
764418919fSjohnjiang huffman_type_strings[] = {
774418919fSjohnjiang [RTE_COMP_HUFFMAN_DEFAULT] = "PMD default",
784418919fSjohnjiang [RTE_COMP_HUFFMAN_FIXED] = "Fixed",
794418919fSjohnjiang [RTE_COMP_HUFFMAN_DYNAMIC] = "Dynamic"
804418919fSjohnjiang };
814418919fSjohnjiang
824418919fSjohnjiang enum zlib_direction {
834418919fSjohnjiang ZLIB_NONE,
844418919fSjohnjiang ZLIB_COMPRESS,
854418919fSjohnjiang ZLIB_DECOMPRESS,
864418919fSjohnjiang ZLIB_ALL
874418919fSjohnjiang };
884418919fSjohnjiang
894418919fSjohnjiang enum varied_buff {
904418919fSjohnjiang LB_BOTH = 0, /* both input and output are linear*/
914418919fSjohnjiang SGL_BOTH, /* both input and output are chained */
924418919fSjohnjiang SGL_TO_LB, /* input buffer is chained */
934418919fSjohnjiang LB_TO_SGL /* output buffer is chained */
944418919fSjohnjiang };
954418919fSjohnjiang
964418919fSjohnjiang enum overflow_test {
974418919fSjohnjiang OVERFLOW_DISABLED,
984418919fSjohnjiang OVERFLOW_ENABLED
994418919fSjohnjiang };
1004418919fSjohnjiang
101*2d9fd380Sjfb8856606 enum ratio_switch {
102*2d9fd380Sjfb8856606 RATIO_DISABLED,
103*2d9fd380Sjfb8856606 RATIO_ENABLED
104*2d9fd380Sjfb8856606 };
105*2d9fd380Sjfb8856606
1064418919fSjohnjiang enum operation_type {
1074418919fSjohnjiang OPERATION_COMPRESSION,
1084418919fSjohnjiang OPERATION_DECOMPRESSION
1094418919fSjohnjiang };
1104418919fSjohnjiang
1114418919fSjohnjiang struct priv_op_data {
1124418919fSjohnjiang uint16_t orig_idx;
1134418919fSjohnjiang };
1144418919fSjohnjiang
1154418919fSjohnjiang struct comp_testsuite_params {
1164418919fSjohnjiang struct rte_mempool *large_mbuf_pool;
1174418919fSjohnjiang struct rte_mempool *small_mbuf_pool;
1184418919fSjohnjiang struct rte_mempool *big_mbuf_pool;
1194418919fSjohnjiang struct rte_mempool *op_pool;
1204418919fSjohnjiang struct rte_comp_xform *def_comp_xform;
1214418919fSjohnjiang struct rte_comp_xform *def_decomp_xform;
1224418919fSjohnjiang };
1234418919fSjohnjiang
1244418919fSjohnjiang struct interim_data_params {
1254418919fSjohnjiang const char * const *test_bufs;
1264418919fSjohnjiang unsigned int num_bufs;
1274418919fSjohnjiang uint16_t *buf_idx;
1284418919fSjohnjiang struct rte_comp_xform **compress_xforms;
1294418919fSjohnjiang struct rte_comp_xform **decompress_xforms;
1304418919fSjohnjiang unsigned int num_xforms;
1314418919fSjohnjiang };
1324418919fSjohnjiang
1334418919fSjohnjiang struct test_data_params {
1344418919fSjohnjiang enum rte_comp_op_type compress_state;
1354418919fSjohnjiang enum rte_comp_op_type decompress_state;
1364418919fSjohnjiang enum varied_buff buff_type;
1374418919fSjohnjiang enum zlib_direction zlib_dir;
1384418919fSjohnjiang unsigned int out_of_space;
1394418919fSjohnjiang unsigned int big_data;
1404418919fSjohnjiang /* stateful decompression specific parameters */
1414418919fSjohnjiang unsigned int decompress_output_block_size;
1424418919fSjohnjiang unsigned int decompress_steps_max;
1434418919fSjohnjiang /* external mbufs specific parameters */
1444418919fSjohnjiang unsigned int use_external_mbufs;
1454418919fSjohnjiang unsigned int inbuf_data_size;
1464418919fSjohnjiang const struct rte_memzone *inbuf_memzone;
1474418919fSjohnjiang const struct rte_memzone *compbuf_memzone;
1484418919fSjohnjiang const struct rte_memzone *uncompbuf_memzone;
1494418919fSjohnjiang /* overflow test activation */
1504418919fSjohnjiang enum overflow_test overflow;
151*2d9fd380Sjfb8856606 enum ratio_switch ratio;
1524418919fSjohnjiang };
1534418919fSjohnjiang
1544418919fSjohnjiang struct test_private_arrays {
1554418919fSjohnjiang struct rte_mbuf **uncomp_bufs;
1564418919fSjohnjiang struct rte_mbuf **comp_bufs;
1574418919fSjohnjiang struct rte_comp_op **ops;
1584418919fSjohnjiang struct rte_comp_op **ops_processed;
1594418919fSjohnjiang void **priv_xforms;
1604418919fSjohnjiang uint64_t *compress_checksum;
1614418919fSjohnjiang uint32_t *compressed_data_size;
1624418919fSjohnjiang void **stream;
1634418919fSjohnjiang char **all_decomp_data;
1644418919fSjohnjiang unsigned int *decomp_produced_data_size;
1654418919fSjohnjiang uint16_t num_priv_xforms;
1664418919fSjohnjiang };
1674418919fSjohnjiang
1684418919fSjohnjiang static struct comp_testsuite_params testsuite_params = { 0 };
1694418919fSjohnjiang
170*2d9fd380Sjfb8856606
1714418919fSjohnjiang static void
testsuite_teardown(void)1724418919fSjohnjiang testsuite_teardown(void)
1734418919fSjohnjiang {
1744418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
1754418919fSjohnjiang
1764418919fSjohnjiang if (rte_mempool_in_use_count(ts_params->large_mbuf_pool))
1774418919fSjohnjiang RTE_LOG(ERR, USER1, "Large mbuf pool still has unfreed bufs\n");
1784418919fSjohnjiang if (rte_mempool_in_use_count(ts_params->small_mbuf_pool))
1794418919fSjohnjiang RTE_LOG(ERR, USER1, "Small mbuf pool still has unfreed bufs\n");
1804418919fSjohnjiang if (rte_mempool_in_use_count(ts_params->big_mbuf_pool))
1814418919fSjohnjiang RTE_LOG(ERR, USER1, "Big mbuf pool still has unfreed bufs\n");
1824418919fSjohnjiang if (rte_mempool_in_use_count(ts_params->op_pool))
1834418919fSjohnjiang RTE_LOG(ERR, USER1, "op pool still has unfreed ops\n");
1844418919fSjohnjiang
1854418919fSjohnjiang rte_mempool_free(ts_params->large_mbuf_pool);
1864418919fSjohnjiang rte_mempool_free(ts_params->small_mbuf_pool);
1874418919fSjohnjiang rte_mempool_free(ts_params->big_mbuf_pool);
1884418919fSjohnjiang rte_mempool_free(ts_params->op_pool);
1894418919fSjohnjiang rte_free(ts_params->def_comp_xform);
1904418919fSjohnjiang rte_free(ts_params->def_decomp_xform);
1914418919fSjohnjiang }
1924418919fSjohnjiang
1934418919fSjohnjiang static int
testsuite_setup(void)1944418919fSjohnjiang testsuite_setup(void)
1954418919fSjohnjiang {
1964418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
1974418919fSjohnjiang uint32_t max_buf_size = 0;
1984418919fSjohnjiang unsigned int i;
1994418919fSjohnjiang
2004418919fSjohnjiang if (rte_compressdev_count() == 0) {
2014418919fSjohnjiang RTE_LOG(WARNING, USER1, "Need at least one compress device\n");
2024418919fSjohnjiang return TEST_SKIPPED;
2034418919fSjohnjiang }
2044418919fSjohnjiang
2054418919fSjohnjiang RTE_LOG(NOTICE, USER1, "Running tests on device %s\n",
2064418919fSjohnjiang rte_compressdev_name_get(0));
2074418919fSjohnjiang
2084418919fSjohnjiang for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
2094418919fSjohnjiang max_buf_size = RTE_MAX(max_buf_size,
2104418919fSjohnjiang strlen(compress_test_bufs[i]) + 1);
2114418919fSjohnjiang
2124418919fSjohnjiang /*
2134418919fSjohnjiang * Buffers to be used in compression and decompression.
2144418919fSjohnjiang * Since decompressed data might be larger than
2154418919fSjohnjiang * compressed data (due to block header),
2164418919fSjohnjiang * buffers should be big enough for both cases.
2174418919fSjohnjiang */
2184418919fSjohnjiang max_buf_size *= COMPRESS_BUF_SIZE_RATIO;
2194418919fSjohnjiang ts_params->large_mbuf_pool = rte_pktmbuf_pool_create("large_mbuf_pool",
2204418919fSjohnjiang NUM_LARGE_MBUFS,
2214418919fSjohnjiang CACHE_SIZE, 0,
2224418919fSjohnjiang max_buf_size + RTE_PKTMBUF_HEADROOM,
2234418919fSjohnjiang rte_socket_id());
2244418919fSjohnjiang if (ts_params->large_mbuf_pool == NULL) {
2254418919fSjohnjiang RTE_LOG(ERR, USER1, "Large mbuf pool could not be created\n");
2264418919fSjohnjiang return TEST_FAILED;
2274418919fSjohnjiang }
2284418919fSjohnjiang
2294418919fSjohnjiang /* Create mempool with smaller buffers for SGL testing */
2304418919fSjohnjiang ts_params->small_mbuf_pool = rte_pktmbuf_pool_create("small_mbuf_pool",
2314418919fSjohnjiang NUM_LARGE_MBUFS * MAX_SEGS,
2324418919fSjohnjiang CACHE_SIZE, 0,
2334418919fSjohnjiang SMALL_SEG_SIZE + RTE_PKTMBUF_HEADROOM,
2344418919fSjohnjiang rte_socket_id());
2354418919fSjohnjiang if (ts_params->small_mbuf_pool == NULL) {
2364418919fSjohnjiang RTE_LOG(ERR, USER1, "Small mbuf pool could not be created\n");
2374418919fSjohnjiang goto exit;
2384418919fSjohnjiang }
2394418919fSjohnjiang
2404418919fSjohnjiang /* Create mempool with big buffers for SGL testing */
2414418919fSjohnjiang ts_params->big_mbuf_pool = rte_pktmbuf_pool_create("big_mbuf_pool",
2424418919fSjohnjiang NUM_BIG_MBUFS + 1,
2434418919fSjohnjiang CACHE_SIZE, 0,
2444418919fSjohnjiang MAX_MBUF_SEGMENT_SIZE,
2454418919fSjohnjiang rte_socket_id());
2464418919fSjohnjiang if (ts_params->big_mbuf_pool == NULL) {
2474418919fSjohnjiang RTE_LOG(ERR, USER1, "Big mbuf pool could not be created\n");
2484418919fSjohnjiang goto exit;
2494418919fSjohnjiang }
2504418919fSjohnjiang
2514418919fSjohnjiang ts_params->op_pool = rte_comp_op_pool_create("op_pool", NUM_OPS,
2524418919fSjohnjiang 0, sizeof(struct priv_op_data),
2534418919fSjohnjiang rte_socket_id());
2544418919fSjohnjiang if (ts_params->op_pool == NULL) {
2554418919fSjohnjiang RTE_LOG(ERR, USER1, "Operation pool could not be created\n");
2564418919fSjohnjiang goto exit;
2574418919fSjohnjiang }
2584418919fSjohnjiang
2594418919fSjohnjiang ts_params->def_comp_xform =
2604418919fSjohnjiang rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
2614418919fSjohnjiang if (ts_params->def_comp_xform == NULL) {
2624418919fSjohnjiang RTE_LOG(ERR, USER1,
2634418919fSjohnjiang "Default compress xform could not be created\n");
2644418919fSjohnjiang goto exit;
2654418919fSjohnjiang }
2664418919fSjohnjiang ts_params->def_decomp_xform =
2674418919fSjohnjiang rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
2684418919fSjohnjiang if (ts_params->def_decomp_xform == NULL) {
2694418919fSjohnjiang RTE_LOG(ERR, USER1,
2704418919fSjohnjiang "Default decompress xform could not be created\n");
2714418919fSjohnjiang goto exit;
2724418919fSjohnjiang }
2734418919fSjohnjiang
2744418919fSjohnjiang /* Initializes default values for compress/decompress xforms */
2754418919fSjohnjiang ts_params->def_comp_xform->type = RTE_COMP_COMPRESS;
2764418919fSjohnjiang ts_params->def_comp_xform->compress.algo = RTE_COMP_ALGO_DEFLATE,
2774418919fSjohnjiang ts_params->def_comp_xform->compress.deflate.huffman =
2784418919fSjohnjiang RTE_COMP_HUFFMAN_DEFAULT;
2794418919fSjohnjiang ts_params->def_comp_xform->compress.level = RTE_COMP_LEVEL_PMD_DEFAULT;
2804418919fSjohnjiang ts_params->def_comp_xform->compress.chksum = RTE_COMP_CHECKSUM_NONE;
2814418919fSjohnjiang ts_params->def_comp_xform->compress.window_size = DEFAULT_WINDOW_SIZE;
2824418919fSjohnjiang
2834418919fSjohnjiang ts_params->def_decomp_xform->type = RTE_COMP_DECOMPRESS;
2844418919fSjohnjiang ts_params->def_decomp_xform->decompress.algo = RTE_COMP_ALGO_DEFLATE,
2854418919fSjohnjiang ts_params->def_decomp_xform->decompress.chksum = RTE_COMP_CHECKSUM_NONE;
2864418919fSjohnjiang ts_params->def_decomp_xform->decompress.window_size = DEFAULT_WINDOW_SIZE;
2874418919fSjohnjiang
2884418919fSjohnjiang return TEST_SUCCESS;
2894418919fSjohnjiang
2904418919fSjohnjiang exit:
2914418919fSjohnjiang testsuite_teardown();
2924418919fSjohnjiang
2934418919fSjohnjiang return TEST_FAILED;
2944418919fSjohnjiang }
2954418919fSjohnjiang
2964418919fSjohnjiang static int
generic_ut_setup(void)2974418919fSjohnjiang generic_ut_setup(void)
2984418919fSjohnjiang {
2994418919fSjohnjiang /* Configure compressdev (one device, one queue pair) */
3004418919fSjohnjiang struct rte_compressdev_config config = {
3014418919fSjohnjiang .socket_id = rte_socket_id(),
3024418919fSjohnjiang .nb_queue_pairs = 1,
3034418919fSjohnjiang .max_nb_priv_xforms = NUM_MAX_XFORMS,
3044418919fSjohnjiang .max_nb_streams = 1
3054418919fSjohnjiang };
3064418919fSjohnjiang
3074418919fSjohnjiang if (rte_compressdev_configure(0, &config) < 0) {
3084418919fSjohnjiang RTE_LOG(ERR, USER1, "Device configuration failed\n");
3094418919fSjohnjiang return -1;
3104418919fSjohnjiang }
3114418919fSjohnjiang
3124418919fSjohnjiang if (rte_compressdev_queue_pair_setup(0, 0, NUM_MAX_INFLIGHT_OPS,
3134418919fSjohnjiang rte_socket_id()) < 0) {
3144418919fSjohnjiang RTE_LOG(ERR, USER1, "Queue pair setup failed\n");
3154418919fSjohnjiang return -1;
3164418919fSjohnjiang }
3174418919fSjohnjiang
3184418919fSjohnjiang if (rte_compressdev_start(0) < 0) {
3194418919fSjohnjiang RTE_LOG(ERR, USER1, "Device could not be started\n");
3204418919fSjohnjiang return -1;
3214418919fSjohnjiang }
3224418919fSjohnjiang
3234418919fSjohnjiang return 0;
3244418919fSjohnjiang }
3254418919fSjohnjiang
3264418919fSjohnjiang static void
generic_ut_teardown(void)3274418919fSjohnjiang generic_ut_teardown(void)
3284418919fSjohnjiang {
3294418919fSjohnjiang rte_compressdev_stop(0);
3304418919fSjohnjiang if (rte_compressdev_close(0) < 0)
3314418919fSjohnjiang RTE_LOG(ERR, USER1, "Device could not be closed\n");
3324418919fSjohnjiang }
3334418919fSjohnjiang
3344418919fSjohnjiang static int
test_compressdev_invalid_configuration(void)3354418919fSjohnjiang test_compressdev_invalid_configuration(void)
3364418919fSjohnjiang {
3374418919fSjohnjiang struct rte_compressdev_config invalid_config;
3384418919fSjohnjiang struct rte_compressdev_config valid_config = {
3394418919fSjohnjiang .socket_id = rte_socket_id(),
3404418919fSjohnjiang .nb_queue_pairs = 1,
3414418919fSjohnjiang .max_nb_priv_xforms = NUM_MAX_XFORMS,
3424418919fSjohnjiang .max_nb_streams = 1
3434418919fSjohnjiang };
3444418919fSjohnjiang struct rte_compressdev_info dev_info;
3454418919fSjohnjiang
346*2d9fd380Sjfb8856606 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
347*2d9fd380Sjfb8856606
3484418919fSjohnjiang /* Invalid configuration with 0 queue pairs */
3494418919fSjohnjiang memcpy(&invalid_config, &valid_config,
3504418919fSjohnjiang sizeof(struct rte_compressdev_config));
3514418919fSjohnjiang invalid_config.nb_queue_pairs = 0;
3524418919fSjohnjiang
3534418919fSjohnjiang TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
3544418919fSjohnjiang "Device configuration was successful "
3554418919fSjohnjiang "with no queue pairs (invalid)\n");
3564418919fSjohnjiang
3574418919fSjohnjiang /*
3584418919fSjohnjiang * Invalid configuration with too many queue pairs
3594418919fSjohnjiang * (if there is an actual maximum number of queue pairs)
3604418919fSjohnjiang */
3614418919fSjohnjiang rte_compressdev_info_get(0, &dev_info);
3624418919fSjohnjiang if (dev_info.max_nb_queue_pairs != 0) {
3634418919fSjohnjiang memcpy(&invalid_config, &valid_config,
3644418919fSjohnjiang sizeof(struct rte_compressdev_config));
3654418919fSjohnjiang invalid_config.nb_queue_pairs = dev_info.max_nb_queue_pairs + 1;
3664418919fSjohnjiang
3674418919fSjohnjiang TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
3684418919fSjohnjiang "Device configuration was successful "
3694418919fSjohnjiang "with too many queue pairs (invalid)\n");
3704418919fSjohnjiang }
3714418919fSjohnjiang
3724418919fSjohnjiang /* Invalid queue pair setup, with no number of queue pairs set */
3734418919fSjohnjiang TEST_ASSERT_FAIL(rte_compressdev_queue_pair_setup(0, 0,
3744418919fSjohnjiang NUM_MAX_INFLIGHT_OPS, rte_socket_id()),
3754418919fSjohnjiang "Queue pair setup was successful "
3764418919fSjohnjiang "with no queue pairs set (invalid)\n");
3774418919fSjohnjiang
3784418919fSjohnjiang return TEST_SUCCESS;
3794418919fSjohnjiang }
3804418919fSjohnjiang
3814418919fSjohnjiang static int
compare_buffers(const char * buffer1,uint32_t buffer1_len,const char * buffer2,uint32_t buffer2_len)3824418919fSjohnjiang compare_buffers(const char *buffer1, uint32_t buffer1_len,
3834418919fSjohnjiang const char *buffer2, uint32_t buffer2_len)
3844418919fSjohnjiang {
3854418919fSjohnjiang if (buffer1_len != buffer2_len) {
3864418919fSjohnjiang RTE_LOG(ERR, USER1, "Buffer lengths are different\n");
3874418919fSjohnjiang return -1;
3884418919fSjohnjiang }
3894418919fSjohnjiang
3904418919fSjohnjiang if (memcmp(buffer1, buffer2, buffer1_len) != 0) {
3914418919fSjohnjiang RTE_LOG(ERR, USER1, "Buffers are different\n");
3924418919fSjohnjiang return -1;
3934418919fSjohnjiang }
3944418919fSjohnjiang
3954418919fSjohnjiang return 0;
3964418919fSjohnjiang }
3974418919fSjohnjiang
3984418919fSjohnjiang /*
3994418919fSjohnjiang * Maps compressdev and Zlib flush flags
4004418919fSjohnjiang */
4014418919fSjohnjiang static int
map_zlib_flush_flag(enum rte_comp_flush_flag flag)4024418919fSjohnjiang map_zlib_flush_flag(enum rte_comp_flush_flag flag)
4034418919fSjohnjiang {
4044418919fSjohnjiang switch (flag) {
4054418919fSjohnjiang case RTE_COMP_FLUSH_NONE:
4064418919fSjohnjiang return Z_NO_FLUSH;
4074418919fSjohnjiang case RTE_COMP_FLUSH_SYNC:
4084418919fSjohnjiang return Z_SYNC_FLUSH;
4094418919fSjohnjiang case RTE_COMP_FLUSH_FULL:
4104418919fSjohnjiang return Z_FULL_FLUSH;
4114418919fSjohnjiang case RTE_COMP_FLUSH_FINAL:
4124418919fSjohnjiang return Z_FINISH;
4134418919fSjohnjiang /*
4144418919fSjohnjiang * There should be only the values above,
4154418919fSjohnjiang * so this should never happen
4164418919fSjohnjiang */
4174418919fSjohnjiang default:
4184418919fSjohnjiang return -1;
4194418919fSjohnjiang }
4204418919fSjohnjiang }
4214418919fSjohnjiang
4224418919fSjohnjiang static int
compress_zlib(struct rte_comp_op * op,const struct rte_comp_xform * xform,int mem_level)4234418919fSjohnjiang compress_zlib(struct rte_comp_op *op,
4244418919fSjohnjiang const struct rte_comp_xform *xform, int mem_level)
4254418919fSjohnjiang {
4264418919fSjohnjiang z_stream stream;
4274418919fSjohnjiang int zlib_flush;
4284418919fSjohnjiang int strategy, window_bits, comp_level;
4294418919fSjohnjiang int ret = TEST_FAILED;
4304418919fSjohnjiang uint8_t *single_src_buf = NULL;
4314418919fSjohnjiang uint8_t *single_dst_buf = NULL;
4324418919fSjohnjiang
4334418919fSjohnjiang /* initialize zlib stream */
4344418919fSjohnjiang stream.zalloc = Z_NULL;
4354418919fSjohnjiang stream.zfree = Z_NULL;
4364418919fSjohnjiang stream.opaque = Z_NULL;
4374418919fSjohnjiang
4384418919fSjohnjiang if (xform->compress.deflate.huffman == RTE_COMP_HUFFMAN_FIXED)
4394418919fSjohnjiang strategy = Z_FIXED;
4404418919fSjohnjiang else
4414418919fSjohnjiang strategy = Z_DEFAULT_STRATEGY;
4424418919fSjohnjiang
4434418919fSjohnjiang /*
4444418919fSjohnjiang * Window bits is the base two logarithm of the window size (in bytes).
4454418919fSjohnjiang * When doing raw DEFLATE, this number will be negative.
4464418919fSjohnjiang */
4474418919fSjohnjiang window_bits = -(xform->compress.window_size);
4484418919fSjohnjiang if (xform->compress.chksum == RTE_COMP_CHECKSUM_ADLER32)
4494418919fSjohnjiang window_bits *= -1;
4504418919fSjohnjiang else if (xform->compress.chksum == RTE_COMP_CHECKSUM_CRC32)
4514418919fSjohnjiang window_bits = ZLIB_CRC_CHECKSUM_WINDOW_BITS;
4524418919fSjohnjiang
4534418919fSjohnjiang comp_level = xform->compress.level;
4544418919fSjohnjiang
4554418919fSjohnjiang if (comp_level != RTE_COMP_LEVEL_NONE)
4564418919fSjohnjiang ret = deflateInit2(&stream, comp_level, Z_DEFLATED,
4574418919fSjohnjiang window_bits, mem_level, strategy);
4584418919fSjohnjiang else
4594418919fSjohnjiang ret = deflateInit(&stream, Z_NO_COMPRESSION);
4604418919fSjohnjiang
4614418919fSjohnjiang if (ret != Z_OK) {
4624418919fSjohnjiang printf("Zlib deflate could not be initialized\n");
4634418919fSjohnjiang goto exit;
4644418919fSjohnjiang }
4654418919fSjohnjiang
4664418919fSjohnjiang /* Assuming stateless operation */
4674418919fSjohnjiang /* SGL Input */
4684418919fSjohnjiang if (op->m_src->nb_segs > 1) {
4694418919fSjohnjiang single_src_buf = rte_malloc(NULL,
4704418919fSjohnjiang rte_pktmbuf_pkt_len(op->m_src), 0);
4714418919fSjohnjiang if (single_src_buf == NULL) {
4724418919fSjohnjiang RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
4734418919fSjohnjiang goto exit;
4744418919fSjohnjiang }
4754418919fSjohnjiang
4764418919fSjohnjiang if (rte_pktmbuf_read(op->m_src, op->src.offset,
4774418919fSjohnjiang rte_pktmbuf_pkt_len(op->m_src) -
4784418919fSjohnjiang op->src.offset,
4794418919fSjohnjiang single_src_buf) == NULL) {
4804418919fSjohnjiang RTE_LOG(ERR, USER1,
4814418919fSjohnjiang "Buffer could not be read entirely\n");
4824418919fSjohnjiang goto exit;
4834418919fSjohnjiang }
4844418919fSjohnjiang
4854418919fSjohnjiang stream.avail_in = op->src.length;
4864418919fSjohnjiang stream.next_in = single_src_buf;
4874418919fSjohnjiang
4884418919fSjohnjiang } else {
4894418919fSjohnjiang stream.avail_in = op->src.length;
4904418919fSjohnjiang stream.next_in = rte_pktmbuf_mtod_offset(op->m_src, uint8_t *,
4914418919fSjohnjiang op->src.offset);
4924418919fSjohnjiang }
4934418919fSjohnjiang /* SGL output */
4944418919fSjohnjiang if (op->m_dst->nb_segs > 1) {
4954418919fSjohnjiang
4964418919fSjohnjiang single_dst_buf = rte_malloc(NULL,
4974418919fSjohnjiang rte_pktmbuf_pkt_len(op->m_dst), 0);
4984418919fSjohnjiang if (single_dst_buf == NULL) {
4994418919fSjohnjiang RTE_LOG(ERR, USER1,
5004418919fSjohnjiang "Buffer could not be allocated\n");
5014418919fSjohnjiang goto exit;
5024418919fSjohnjiang }
5034418919fSjohnjiang
5044418919fSjohnjiang stream.avail_out = op->m_dst->pkt_len;
5054418919fSjohnjiang stream.next_out = single_dst_buf;
5064418919fSjohnjiang
5074418919fSjohnjiang } else {/* linear output */
5084418919fSjohnjiang stream.avail_out = op->m_dst->data_len;
5094418919fSjohnjiang stream.next_out = rte_pktmbuf_mtod_offset(op->m_dst, uint8_t *,
5104418919fSjohnjiang op->dst.offset);
5114418919fSjohnjiang }
5124418919fSjohnjiang
5134418919fSjohnjiang /* Stateless operation, all buffer will be compressed in one go */
5144418919fSjohnjiang zlib_flush = map_zlib_flush_flag(op->flush_flag);
5154418919fSjohnjiang ret = deflate(&stream, zlib_flush);
5164418919fSjohnjiang
5174418919fSjohnjiang if (stream.avail_in != 0) {
5184418919fSjohnjiang RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
5194418919fSjohnjiang goto exit;
5204418919fSjohnjiang }
5214418919fSjohnjiang
5224418919fSjohnjiang if (ret != Z_STREAM_END)
5234418919fSjohnjiang goto exit;
5244418919fSjohnjiang
5254418919fSjohnjiang /* Copy data to destination SGL */
5264418919fSjohnjiang if (op->m_dst->nb_segs > 1) {
5274418919fSjohnjiang uint32_t remaining_data = stream.total_out;
5284418919fSjohnjiang uint8_t *src_data = single_dst_buf;
5294418919fSjohnjiang struct rte_mbuf *dst_buf = op->m_dst;
5304418919fSjohnjiang
5314418919fSjohnjiang while (remaining_data > 0) {
5324418919fSjohnjiang uint8_t *dst_data = rte_pktmbuf_mtod_offset(dst_buf,
5334418919fSjohnjiang uint8_t *, op->dst.offset);
5344418919fSjohnjiang /* Last segment */
5354418919fSjohnjiang if (remaining_data < dst_buf->data_len) {
5364418919fSjohnjiang memcpy(dst_data, src_data, remaining_data);
5374418919fSjohnjiang remaining_data = 0;
5384418919fSjohnjiang } else {
5394418919fSjohnjiang memcpy(dst_data, src_data, dst_buf->data_len);
5404418919fSjohnjiang remaining_data -= dst_buf->data_len;
5414418919fSjohnjiang src_data += dst_buf->data_len;
5424418919fSjohnjiang dst_buf = dst_buf->next;
5434418919fSjohnjiang }
5444418919fSjohnjiang }
5454418919fSjohnjiang }
5464418919fSjohnjiang
5474418919fSjohnjiang op->consumed = stream.total_in;
5484418919fSjohnjiang if (xform->compress.chksum == RTE_COMP_CHECKSUM_ADLER32) {
5494418919fSjohnjiang rte_pktmbuf_adj(op->m_dst, ZLIB_HEADER_SIZE);
5504418919fSjohnjiang rte_pktmbuf_trim(op->m_dst, ZLIB_TRAILER_SIZE);
5514418919fSjohnjiang op->produced = stream.total_out - (ZLIB_HEADER_SIZE +
5524418919fSjohnjiang ZLIB_TRAILER_SIZE);
5534418919fSjohnjiang } else if (xform->compress.chksum == RTE_COMP_CHECKSUM_CRC32) {
5544418919fSjohnjiang rte_pktmbuf_adj(op->m_dst, GZIP_HEADER_SIZE);
5554418919fSjohnjiang rte_pktmbuf_trim(op->m_dst, GZIP_TRAILER_SIZE);
5564418919fSjohnjiang op->produced = stream.total_out - (GZIP_HEADER_SIZE +
5574418919fSjohnjiang GZIP_TRAILER_SIZE);
5584418919fSjohnjiang } else
5594418919fSjohnjiang op->produced = stream.total_out;
5604418919fSjohnjiang
5614418919fSjohnjiang op->status = RTE_COMP_OP_STATUS_SUCCESS;
5624418919fSjohnjiang op->output_chksum = stream.adler;
5634418919fSjohnjiang
5644418919fSjohnjiang deflateReset(&stream);
5654418919fSjohnjiang
5664418919fSjohnjiang ret = 0;
5674418919fSjohnjiang exit:
5684418919fSjohnjiang deflateEnd(&stream);
5694418919fSjohnjiang rte_free(single_src_buf);
5704418919fSjohnjiang rte_free(single_dst_buf);
5714418919fSjohnjiang
5724418919fSjohnjiang return ret;
5734418919fSjohnjiang }
5744418919fSjohnjiang
5754418919fSjohnjiang static int
decompress_zlib(struct rte_comp_op * op,const struct rte_comp_xform * xform)5764418919fSjohnjiang decompress_zlib(struct rte_comp_op *op,
5774418919fSjohnjiang const struct rte_comp_xform *xform)
5784418919fSjohnjiang {
5794418919fSjohnjiang z_stream stream;
5804418919fSjohnjiang int window_bits;
5814418919fSjohnjiang int zlib_flush;
5824418919fSjohnjiang int ret = TEST_FAILED;
5834418919fSjohnjiang uint8_t *single_src_buf = NULL;
5844418919fSjohnjiang uint8_t *single_dst_buf = NULL;
5854418919fSjohnjiang
5864418919fSjohnjiang /* initialize zlib stream */
5874418919fSjohnjiang stream.zalloc = Z_NULL;
5884418919fSjohnjiang stream.zfree = Z_NULL;
5894418919fSjohnjiang stream.opaque = Z_NULL;
5904418919fSjohnjiang
5914418919fSjohnjiang /*
5924418919fSjohnjiang * Window bits is the base two logarithm of the window size (in bytes).
5934418919fSjohnjiang * When doing raw DEFLATE, this number will be negative.
5944418919fSjohnjiang */
5954418919fSjohnjiang window_bits = -(xform->decompress.window_size);
5964418919fSjohnjiang ret = inflateInit2(&stream, window_bits);
5974418919fSjohnjiang
5984418919fSjohnjiang if (ret != Z_OK) {
5994418919fSjohnjiang printf("Zlib deflate could not be initialized\n");
6004418919fSjohnjiang goto exit;
6014418919fSjohnjiang }
6024418919fSjohnjiang
6034418919fSjohnjiang /* Assuming stateless operation */
6044418919fSjohnjiang /* SGL */
6054418919fSjohnjiang if (op->m_src->nb_segs > 1) {
6064418919fSjohnjiang single_src_buf = rte_malloc(NULL,
6074418919fSjohnjiang rte_pktmbuf_pkt_len(op->m_src), 0);
6084418919fSjohnjiang if (single_src_buf == NULL) {
6094418919fSjohnjiang RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
6104418919fSjohnjiang goto exit;
6114418919fSjohnjiang }
6124418919fSjohnjiang single_dst_buf = rte_malloc(NULL,
6134418919fSjohnjiang rte_pktmbuf_pkt_len(op->m_dst), 0);
6144418919fSjohnjiang if (single_dst_buf == NULL) {
6154418919fSjohnjiang RTE_LOG(ERR, USER1, "Buffer could not be allocated\n");
6164418919fSjohnjiang goto exit;
6174418919fSjohnjiang }
6184418919fSjohnjiang if (rte_pktmbuf_read(op->m_src, 0,
6194418919fSjohnjiang rte_pktmbuf_pkt_len(op->m_src),
6204418919fSjohnjiang single_src_buf) == NULL) {
6214418919fSjohnjiang RTE_LOG(ERR, USER1,
6224418919fSjohnjiang "Buffer could not be read entirely\n");
6234418919fSjohnjiang goto exit;
6244418919fSjohnjiang }
6254418919fSjohnjiang
6264418919fSjohnjiang stream.avail_in = op->src.length;
6274418919fSjohnjiang stream.next_in = single_src_buf;
6284418919fSjohnjiang stream.avail_out = rte_pktmbuf_pkt_len(op->m_dst);
6294418919fSjohnjiang stream.next_out = single_dst_buf;
6304418919fSjohnjiang
6314418919fSjohnjiang } else {
6324418919fSjohnjiang stream.avail_in = op->src.length;
6334418919fSjohnjiang stream.next_in = rte_pktmbuf_mtod(op->m_src, uint8_t *);
6344418919fSjohnjiang stream.avail_out = op->m_dst->data_len;
6354418919fSjohnjiang stream.next_out = rte_pktmbuf_mtod(op->m_dst, uint8_t *);
6364418919fSjohnjiang }
6374418919fSjohnjiang
6384418919fSjohnjiang /* Stateless operation, all buffer will be compressed in one go */
6394418919fSjohnjiang zlib_flush = map_zlib_flush_flag(op->flush_flag);
6404418919fSjohnjiang ret = inflate(&stream, zlib_flush);
6414418919fSjohnjiang
6424418919fSjohnjiang if (stream.avail_in != 0) {
6434418919fSjohnjiang RTE_LOG(ERR, USER1, "Buffer could not be read entirely\n");
6444418919fSjohnjiang goto exit;
6454418919fSjohnjiang }
6464418919fSjohnjiang
6474418919fSjohnjiang if (ret != Z_STREAM_END)
6484418919fSjohnjiang goto exit;
6494418919fSjohnjiang
6504418919fSjohnjiang if (op->m_src->nb_segs > 1) {
6514418919fSjohnjiang uint32_t remaining_data = stream.total_out;
6524418919fSjohnjiang uint8_t *src_data = single_dst_buf;
6534418919fSjohnjiang struct rte_mbuf *dst_buf = op->m_dst;
6544418919fSjohnjiang
6554418919fSjohnjiang while (remaining_data > 0) {
6564418919fSjohnjiang uint8_t *dst_data = rte_pktmbuf_mtod(dst_buf,
6574418919fSjohnjiang uint8_t *);
6584418919fSjohnjiang /* Last segment */
6594418919fSjohnjiang if (remaining_data < dst_buf->data_len) {
6604418919fSjohnjiang memcpy(dst_data, src_data, remaining_data);
6614418919fSjohnjiang remaining_data = 0;
6624418919fSjohnjiang } else {
6634418919fSjohnjiang memcpy(dst_data, src_data, dst_buf->data_len);
6644418919fSjohnjiang remaining_data -= dst_buf->data_len;
6654418919fSjohnjiang src_data += dst_buf->data_len;
6664418919fSjohnjiang dst_buf = dst_buf->next;
6674418919fSjohnjiang }
6684418919fSjohnjiang }
6694418919fSjohnjiang }
6704418919fSjohnjiang
6714418919fSjohnjiang op->consumed = stream.total_in;
6724418919fSjohnjiang op->produced = stream.total_out;
6734418919fSjohnjiang op->status = RTE_COMP_OP_STATUS_SUCCESS;
6744418919fSjohnjiang
6754418919fSjohnjiang inflateReset(&stream);
6764418919fSjohnjiang
6774418919fSjohnjiang ret = 0;
6784418919fSjohnjiang exit:
6794418919fSjohnjiang inflateEnd(&stream);
6804418919fSjohnjiang
6814418919fSjohnjiang return ret;
6824418919fSjohnjiang }
6834418919fSjohnjiang
6844418919fSjohnjiang static int
prepare_sgl_bufs(const char * test_buf,struct rte_mbuf * head_buf,uint32_t total_data_size,struct rte_mempool * small_mbuf_pool,struct rte_mempool * large_mbuf_pool,uint8_t limit_segs_in_sgl,uint16_t seg_size)6854418919fSjohnjiang prepare_sgl_bufs(const char *test_buf, struct rte_mbuf *head_buf,
6864418919fSjohnjiang uint32_t total_data_size,
6874418919fSjohnjiang struct rte_mempool *small_mbuf_pool,
6884418919fSjohnjiang struct rte_mempool *large_mbuf_pool,
6894418919fSjohnjiang uint8_t limit_segs_in_sgl,
6904418919fSjohnjiang uint16_t seg_size)
6914418919fSjohnjiang {
6924418919fSjohnjiang uint32_t remaining_data = total_data_size;
6934418919fSjohnjiang uint16_t num_remaining_segs = DIV_CEIL(remaining_data, seg_size);
6944418919fSjohnjiang struct rte_mempool *pool;
6954418919fSjohnjiang struct rte_mbuf *next_seg;
6964418919fSjohnjiang uint32_t data_size;
6974418919fSjohnjiang char *buf_ptr;
6984418919fSjohnjiang const char *data_ptr = test_buf;
6994418919fSjohnjiang uint16_t i;
7004418919fSjohnjiang int ret;
7014418919fSjohnjiang
7024418919fSjohnjiang if (limit_segs_in_sgl != 0 && num_remaining_segs > limit_segs_in_sgl)
7034418919fSjohnjiang num_remaining_segs = limit_segs_in_sgl - 1;
7044418919fSjohnjiang
7054418919fSjohnjiang /*
7064418919fSjohnjiang * Allocate data in the first segment (header) and
7074418919fSjohnjiang * copy data if test buffer is provided
7084418919fSjohnjiang */
7094418919fSjohnjiang if (remaining_data < seg_size)
7104418919fSjohnjiang data_size = remaining_data;
7114418919fSjohnjiang else
7124418919fSjohnjiang data_size = seg_size;
7134418919fSjohnjiang
7144418919fSjohnjiang buf_ptr = rte_pktmbuf_append(head_buf, data_size);
7154418919fSjohnjiang if (buf_ptr == NULL) {
7164418919fSjohnjiang RTE_LOG(ERR, USER1,
7174418919fSjohnjiang "Not enough space in the 1st buffer\n");
7184418919fSjohnjiang return -1;
7194418919fSjohnjiang }
7204418919fSjohnjiang
7214418919fSjohnjiang if (data_ptr != NULL) {
7224418919fSjohnjiang /* Copy characters without NULL terminator */
723*2d9fd380Sjfb8856606 memcpy(buf_ptr, data_ptr, data_size);
7244418919fSjohnjiang data_ptr += data_size;
7254418919fSjohnjiang }
7264418919fSjohnjiang remaining_data -= data_size;
7274418919fSjohnjiang num_remaining_segs--;
7284418919fSjohnjiang
7294418919fSjohnjiang /*
7304418919fSjohnjiang * Allocate the rest of the segments,
7314418919fSjohnjiang * copy the rest of the data and chain the segments.
7324418919fSjohnjiang */
7334418919fSjohnjiang for (i = 0; i < num_remaining_segs; i++) {
7344418919fSjohnjiang
7354418919fSjohnjiang if (i == (num_remaining_segs - 1)) {
7364418919fSjohnjiang /* last segment */
7374418919fSjohnjiang if (remaining_data > seg_size)
7384418919fSjohnjiang pool = large_mbuf_pool;
7394418919fSjohnjiang else
7404418919fSjohnjiang pool = small_mbuf_pool;
7414418919fSjohnjiang data_size = remaining_data;
7424418919fSjohnjiang } else {
7434418919fSjohnjiang data_size = seg_size;
7444418919fSjohnjiang pool = small_mbuf_pool;
7454418919fSjohnjiang }
7464418919fSjohnjiang
7474418919fSjohnjiang next_seg = rte_pktmbuf_alloc(pool);
7484418919fSjohnjiang if (next_seg == NULL) {
7494418919fSjohnjiang RTE_LOG(ERR, USER1,
7504418919fSjohnjiang "New segment could not be allocated "
7514418919fSjohnjiang "from the mempool\n");
7524418919fSjohnjiang return -1;
7534418919fSjohnjiang }
7544418919fSjohnjiang buf_ptr = rte_pktmbuf_append(next_seg, data_size);
7554418919fSjohnjiang if (buf_ptr == NULL) {
7564418919fSjohnjiang RTE_LOG(ERR, USER1,
7574418919fSjohnjiang "Not enough space in the buffer\n");
7584418919fSjohnjiang rte_pktmbuf_free(next_seg);
7594418919fSjohnjiang return -1;
7604418919fSjohnjiang }
7614418919fSjohnjiang if (data_ptr != NULL) {
7624418919fSjohnjiang /* Copy characters without NULL terminator */
763*2d9fd380Sjfb8856606 memcpy(buf_ptr, data_ptr, data_size);
7644418919fSjohnjiang data_ptr += data_size;
7654418919fSjohnjiang }
7664418919fSjohnjiang remaining_data -= data_size;
7674418919fSjohnjiang
7684418919fSjohnjiang ret = rte_pktmbuf_chain(head_buf, next_seg);
7694418919fSjohnjiang if (ret != 0) {
7704418919fSjohnjiang rte_pktmbuf_free(next_seg);
7714418919fSjohnjiang RTE_LOG(ERR, USER1,
7724418919fSjohnjiang "Segment could not chained\n");
7734418919fSjohnjiang return -1;
7744418919fSjohnjiang }
7754418919fSjohnjiang }
7764418919fSjohnjiang
7774418919fSjohnjiang return 0;
7784418919fSjohnjiang }
7794418919fSjohnjiang
7804418919fSjohnjiang static void
extbuf_free_callback(void * addr __rte_unused,void * opaque __rte_unused)7814418919fSjohnjiang extbuf_free_callback(void *addr __rte_unused, void *opaque __rte_unused)
7824418919fSjohnjiang {
7834418919fSjohnjiang }
7844418919fSjohnjiang
7854418919fSjohnjiang static int
test_run_enqueue_dequeue(struct rte_comp_op ** ops,struct rte_comp_op ** ops_processed,unsigned int num_bufs)7864418919fSjohnjiang test_run_enqueue_dequeue(struct rte_comp_op **ops,
7874418919fSjohnjiang struct rte_comp_op **ops_processed,
7884418919fSjohnjiang unsigned int num_bufs)
7894418919fSjohnjiang {
7904418919fSjohnjiang uint16_t num_enqd, num_deqd, num_total_deqd;
7914418919fSjohnjiang unsigned int deqd_retries = 0;
792*2d9fd380Sjfb8856606 int res = 0;
7934418919fSjohnjiang
7944418919fSjohnjiang /* Enqueue and dequeue all operations */
7954418919fSjohnjiang num_enqd = rte_compressdev_enqueue_burst(0, 0, ops, num_bufs);
7964418919fSjohnjiang if (num_enqd < num_bufs) {
7974418919fSjohnjiang RTE_LOG(ERR, USER1,
7984418919fSjohnjiang "Some operations could not be enqueued\n");
799*2d9fd380Sjfb8856606 res = -1;
8004418919fSjohnjiang }
8014418919fSjohnjiang
802*2d9fd380Sjfb8856606 /* dequeue ops even on error (same number of ops as was enqueued) */
803*2d9fd380Sjfb8856606
8044418919fSjohnjiang num_total_deqd = 0;
805*2d9fd380Sjfb8856606 while (num_total_deqd < num_enqd) {
8064418919fSjohnjiang /*
8074418919fSjohnjiang * If retrying a dequeue call, wait for 10 ms to allow
8084418919fSjohnjiang * enough time to the driver to process the operations
8094418919fSjohnjiang */
8104418919fSjohnjiang if (deqd_retries != 0) {
8114418919fSjohnjiang /*
8124418919fSjohnjiang * Avoid infinite loop if not all the
8134418919fSjohnjiang * operations get out of the device
8144418919fSjohnjiang */
8154418919fSjohnjiang if (deqd_retries == MAX_DEQD_RETRIES) {
8164418919fSjohnjiang RTE_LOG(ERR, USER1,
8174418919fSjohnjiang "Not all operations could be dequeued\n");
818*2d9fd380Sjfb8856606 res = -1;
819*2d9fd380Sjfb8856606 break;
8204418919fSjohnjiang }
8214418919fSjohnjiang usleep(DEQUEUE_WAIT_TIME);
8224418919fSjohnjiang }
8234418919fSjohnjiang num_deqd = rte_compressdev_dequeue_burst(0, 0,
8244418919fSjohnjiang &ops_processed[num_total_deqd], num_bufs);
8254418919fSjohnjiang num_total_deqd += num_deqd;
8264418919fSjohnjiang deqd_retries++;
8274418919fSjohnjiang
828*2d9fd380Sjfb8856606 }
8294418919fSjohnjiang
830*2d9fd380Sjfb8856606 return res;
8314418919fSjohnjiang }
8324418919fSjohnjiang
8334418919fSjohnjiang /**
8344418919fSjohnjiang * Arrays initialization. Input buffers preparation for compression.
8354418919fSjohnjiang *
8364418919fSjohnjiang * API that initializes all the private arrays to NULL
8374418919fSjohnjiang * and allocates input buffers to perform compression operations.
8384418919fSjohnjiang *
8394418919fSjohnjiang * @param int_data
8404418919fSjohnjiang * Interim data containing session/transformation objects.
8414418919fSjohnjiang * @param test_data
8424418919fSjohnjiang * The test parameters set by users (command line parameters).
8434418919fSjohnjiang * @param test_priv_data
8444418919fSjohnjiang * A container used for aggregation all the private test arrays.
8454418919fSjohnjiang * @return
8464418919fSjohnjiang * - 0: On success.
8474418919fSjohnjiang * - -1: On error.
8484418919fSjohnjiang */
8494418919fSjohnjiang static int
test_setup_com_bufs(const struct interim_data_params * int_data,const struct test_data_params * test_data,const struct test_private_arrays * test_priv_data)8504418919fSjohnjiang test_setup_com_bufs(const struct interim_data_params *int_data,
8514418919fSjohnjiang const struct test_data_params *test_data,
8524418919fSjohnjiang const struct test_private_arrays *test_priv_data)
8534418919fSjohnjiang {
8544418919fSjohnjiang /* local variables: */
8554418919fSjohnjiang unsigned int i;
8564418919fSjohnjiang uint32_t data_size;
8574418919fSjohnjiang char *buf_ptr;
8584418919fSjohnjiang int ret;
8594418919fSjohnjiang char **all_decomp_data = test_priv_data->all_decomp_data;
8604418919fSjohnjiang
8614418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
8624418919fSjohnjiang
8634418919fSjohnjiang /* from int_data: */
8644418919fSjohnjiang const char * const *test_bufs = int_data->test_bufs;
8654418919fSjohnjiang unsigned int num_bufs = int_data->num_bufs;
8664418919fSjohnjiang
8674418919fSjohnjiang /* from test_data: */
8684418919fSjohnjiang unsigned int buff_type = test_data->buff_type;
8694418919fSjohnjiang unsigned int big_data = test_data->big_data;
8704418919fSjohnjiang
8714418919fSjohnjiang /* from test_priv_data: */
8724418919fSjohnjiang struct rte_mbuf **uncomp_bufs = test_priv_data->uncomp_bufs;
8734418919fSjohnjiang struct rte_mempool *buf_pool;
8744418919fSjohnjiang
8754418919fSjohnjiang static struct rte_mbuf_ext_shared_info inbuf_info;
8764418919fSjohnjiang
8774418919fSjohnjiang size_t array_size = sizeof(void *) * num_bufs;
8784418919fSjohnjiang
8794418919fSjohnjiang /* Initialize all arrays to NULL */
8804418919fSjohnjiang memset(test_priv_data->uncomp_bufs, 0, array_size);
8814418919fSjohnjiang memset(test_priv_data->comp_bufs, 0, array_size);
8824418919fSjohnjiang memset(test_priv_data->ops, 0, array_size);
8834418919fSjohnjiang memset(test_priv_data->ops_processed, 0, array_size);
8844418919fSjohnjiang memset(test_priv_data->priv_xforms, 0, array_size);
8854418919fSjohnjiang memset(test_priv_data->compressed_data_size,
8864418919fSjohnjiang 0, sizeof(uint32_t) * num_bufs);
8874418919fSjohnjiang
8884418919fSjohnjiang if (test_data->decompress_state == RTE_COMP_OP_STATEFUL) {
8894418919fSjohnjiang data_size = strlen(test_bufs[0]) + 1;
8904418919fSjohnjiang *all_decomp_data = rte_malloc(NULL, data_size,
8914418919fSjohnjiang RTE_CACHE_LINE_SIZE);
8924418919fSjohnjiang }
8934418919fSjohnjiang
8944418919fSjohnjiang if (big_data)
8954418919fSjohnjiang buf_pool = ts_params->big_mbuf_pool;
8964418919fSjohnjiang else if (buff_type == SGL_BOTH)
8974418919fSjohnjiang buf_pool = ts_params->small_mbuf_pool;
8984418919fSjohnjiang else
8994418919fSjohnjiang buf_pool = ts_params->large_mbuf_pool;
9004418919fSjohnjiang
9014418919fSjohnjiang /* for compression uncomp_bufs is used as a source buffer */
9024418919fSjohnjiang /* allocation from buf_pool (mempool type) */
9034418919fSjohnjiang ret = rte_pktmbuf_alloc_bulk(buf_pool,
9044418919fSjohnjiang uncomp_bufs, num_bufs);
9054418919fSjohnjiang if (ret < 0) {
9064418919fSjohnjiang RTE_LOG(ERR, USER1,
9074418919fSjohnjiang "Source mbufs could not be allocated "
9084418919fSjohnjiang "from the mempool\n");
9094418919fSjohnjiang return -1;
9104418919fSjohnjiang }
9114418919fSjohnjiang
9124418919fSjohnjiang if (test_data->use_external_mbufs) {
9134418919fSjohnjiang inbuf_info.free_cb = extbuf_free_callback;
9144418919fSjohnjiang inbuf_info.fcb_opaque = NULL;
9154418919fSjohnjiang rte_mbuf_ext_refcnt_set(&inbuf_info, 1);
9164418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
9174418919fSjohnjiang rte_pktmbuf_attach_extbuf(uncomp_bufs[i],
9184418919fSjohnjiang test_data->inbuf_memzone->addr,
9194418919fSjohnjiang test_data->inbuf_memzone->iova,
9204418919fSjohnjiang test_data->inbuf_data_size,
9214418919fSjohnjiang &inbuf_info);
9224418919fSjohnjiang buf_ptr = rte_pktmbuf_append(uncomp_bufs[i],
9234418919fSjohnjiang test_data->inbuf_data_size);
9244418919fSjohnjiang if (buf_ptr == NULL) {
9254418919fSjohnjiang RTE_LOG(ERR, USER1,
9264418919fSjohnjiang "Append extra bytes to the source mbuf failed\n");
9274418919fSjohnjiang return -1;
9284418919fSjohnjiang }
9294418919fSjohnjiang }
9304418919fSjohnjiang } else if (buff_type == SGL_BOTH || buff_type == SGL_TO_LB) {
9314418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
9324418919fSjohnjiang data_size = strlen(test_bufs[i]) + 1;
9334418919fSjohnjiang if (prepare_sgl_bufs(test_bufs[i], uncomp_bufs[i],
9344418919fSjohnjiang data_size,
9354418919fSjohnjiang big_data ? buf_pool : ts_params->small_mbuf_pool,
9364418919fSjohnjiang big_data ? buf_pool : ts_params->large_mbuf_pool,
9374418919fSjohnjiang big_data ? 0 : MAX_SEGS,
9384418919fSjohnjiang big_data ? MAX_DATA_MBUF_SIZE : SMALL_SEG_SIZE) < 0)
9394418919fSjohnjiang return -1;
9404418919fSjohnjiang }
9414418919fSjohnjiang } else {
9424418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
9434418919fSjohnjiang data_size = strlen(test_bufs[i]) + 1;
9444418919fSjohnjiang
9454418919fSjohnjiang buf_ptr = rte_pktmbuf_append(uncomp_bufs[i], data_size);
9464418919fSjohnjiang if (buf_ptr == NULL) {
9474418919fSjohnjiang RTE_LOG(ERR, USER1,
9484418919fSjohnjiang "Append extra bytes to the source mbuf failed\n");
9494418919fSjohnjiang return -1;
9504418919fSjohnjiang }
9514418919fSjohnjiang strlcpy(buf_ptr, test_bufs[i], data_size);
9524418919fSjohnjiang }
9534418919fSjohnjiang }
9544418919fSjohnjiang
9554418919fSjohnjiang return 0;
9564418919fSjohnjiang }
9574418919fSjohnjiang
9584418919fSjohnjiang /**
9594418919fSjohnjiang * Data size calculation (for both compression and decompression).
9604418919fSjohnjiang *
9614418919fSjohnjiang * Calculate size of anticipated output buffer required for both
9624418919fSjohnjiang * compression and decompression operations based on input int_data.
9634418919fSjohnjiang *
9644418919fSjohnjiang * @param op_type
9654418919fSjohnjiang * Operation type: compress or decompress
9664418919fSjohnjiang * @param out_of_space_and_zlib
9674418919fSjohnjiang * Boolean value to switch into "out of space" buffer if set.
9684418919fSjohnjiang * To test "out-of-space" data size, zlib_decompress must be set as well.
9694418919fSjohnjiang * @param test_priv_data
9704418919fSjohnjiang * A container used for aggregation all the private test arrays.
9714418919fSjohnjiang * @param int_data
9724418919fSjohnjiang * Interim data containing session/transformation objects.
9734418919fSjohnjiang * @param test_data
9744418919fSjohnjiang * The test parameters set by users (command line parameters).
9754418919fSjohnjiang * @param i
9764418919fSjohnjiang * current buffer index
9774418919fSjohnjiang * @return
9784418919fSjohnjiang * data size
9794418919fSjohnjiang */
9804418919fSjohnjiang static inline uint32_t
test_mbufs_calculate_data_size(enum operation_type op_type,unsigned int out_of_space_and_zlib,const struct test_private_arrays * test_priv_data,const struct interim_data_params * int_data,const struct test_data_params * test_data,unsigned int i)9814418919fSjohnjiang test_mbufs_calculate_data_size(
9824418919fSjohnjiang enum operation_type op_type,
9834418919fSjohnjiang unsigned int out_of_space_and_zlib,
9844418919fSjohnjiang const struct test_private_arrays *test_priv_data,
9854418919fSjohnjiang const struct interim_data_params *int_data,
9864418919fSjohnjiang const struct test_data_params *test_data,
9874418919fSjohnjiang unsigned int i)
9884418919fSjohnjiang {
9894418919fSjohnjiang /* local variables: */
9904418919fSjohnjiang uint32_t data_size;
9914418919fSjohnjiang struct priv_op_data *priv_data;
992*2d9fd380Sjfb8856606 float ratio_val;
993*2d9fd380Sjfb8856606 enum ratio_switch ratio = test_data->ratio;
994*2d9fd380Sjfb8856606
9954418919fSjohnjiang uint8_t not_zlib_compr; /* true if zlib isn't current compression dev */
9964418919fSjohnjiang enum overflow_test overflow = test_data->overflow;
9974418919fSjohnjiang
9984418919fSjohnjiang /* from test_priv_data: */
9994418919fSjohnjiang struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
10004418919fSjohnjiang
10014418919fSjohnjiang /* from int_data: */
10024418919fSjohnjiang const char * const *test_bufs = int_data->test_bufs;
10034418919fSjohnjiang
10044418919fSjohnjiang if (out_of_space_and_zlib)
10054418919fSjohnjiang data_size = OUT_OF_SPACE_BUF;
10064418919fSjohnjiang else {
10074418919fSjohnjiang if (op_type == OPERATION_COMPRESSION) {
10084418919fSjohnjiang not_zlib_compr = (test_data->zlib_dir == ZLIB_DECOMPRESS
10094418919fSjohnjiang || test_data->zlib_dir == ZLIB_NONE);
10104418919fSjohnjiang
1011*2d9fd380Sjfb8856606 ratio_val = (ratio == RATIO_ENABLED) ?
1012*2d9fd380Sjfb8856606 COMPRESS_BUF_SIZE_RATIO :
1013*2d9fd380Sjfb8856606 COMPRESS_BUF_SIZE_RATIO_DISABLED;
1014*2d9fd380Sjfb8856606
1015*2d9fd380Sjfb8856606 ratio_val = (not_zlib_compr &&
10164418919fSjohnjiang (overflow == OVERFLOW_ENABLED)) ?
10174418919fSjohnjiang COMPRESS_BUF_SIZE_RATIO_OVERFLOW :
1018*2d9fd380Sjfb8856606 ratio_val;
10194418919fSjohnjiang
1020*2d9fd380Sjfb8856606 data_size = strlen(test_bufs[i]) * ratio_val;
10214418919fSjohnjiang } else {
10224418919fSjohnjiang priv_data = (struct priv_op_data *)
10234418919fSjohnjiang (ops_processed[i] + 1);
10244418919fSjohnjiang data_size = strlen(test_bufs[priv_data->orig_idx]) + 1;
10254418919fSjohnjiang }
10264418919fSjohnjiang }
10274418919fSjohnjiang
10284418919fSjohnjiang return data_size;
10294418919fSjohnjiang }
10304418919fSjohnjiang
10314418919fSjohnjiang
10324418919fSjohnjiang /**
10334418919fSjohnjiang * Memory buffers preparation (for both compression and decompression).
10344418919fSjohnjiang *
10354418919fSjohnjiang * Function allocates output buffers to perform compression
10364418919fSjohnjiang * or decompression operations depending on value of op_type.
10374418919fSjohnjiang *
10384418919fSjohnjiang * @param op_type
10394418919fSjohnjiang * Operation type: compress or decompress
10404418919fSjohnjiang * @param out_of_space_and_zlib
10414418919fSjohnjiang * Boolean value to switch into "out of space" buffer if set.
10424418919fSjohnjiang * To test "out-of-space" data size, zlib_decompress must be set as well.
10434418919fSjohnjiang * @param test_priv_data
10444418919fSjohnjiang * A container used for aggregation all the private test arrays.
10454418919fSjohnjiang * @param int_data
10464418919fSjohnjiang * Interim data containing session/transformation objects.
10474418919fSjohnjiang * @param test_data
10484418919fSjohnjiang * The test parameters set by users (command line parameters).
10494418919fSjohnjiang * @param current_extbuf_info,
10504418919fSjohnjiang * The structure containing all the information related to external mbufs
10514418919fSjohnjiang * @return
10524418919fSjohnjiang * - 0: On success.
10534418919fSjohnjiang * - -1: On error.
10544418919fSjohnjiang */
10554418919fSjohnjiang static int
test_setup_output_bufs(enum operation_type op_type,unsigned int out_of_space_and_zlib,const struct test_private_arrays * test_priv_data,const struct interim_data_params * int_data,const struct test_data_params * test_data,struct rte_mbuf_ext_shared_info * current_extbuf_info)10564418919fSjohnjiang test_setup_output_bufs(
10574418919fSjohnjiang enum operation_type op_type,
10584418919fSjohnjiang unsigned int out_of_space_and_zlib,
10594418919fSjohnjiang const struct test_private_arrays *test_priv_data,
10604418919fSjohnjiang const struct interim_data_params *int_data,
10614418919fSjohnjiang const struct test_data_params *test_data,
10624418919fSjohnjiang struct rte_mbuf_ext_shared_info *current_extbuf_info)
10634418919fSjohnjiang {
10644418919fSjohnjiang /* local variables: */
10654418919fSjohnjiang unsigned int i;
10664418919fSjohnjiang uint32_t data_size;
10674418919fSjohnjiang int ret;
10684418919fSjohnjiang char *buf_ptr;
10694418919fSjohnjiang
10704418919fSjohnjiang /* from test_priv_data: */
10714418919fSjohnjiang struct rte_mbuf **current_bufs;
10724418919fSjohnjiang
10734418919fSjohnjiang /* from int_data: */
10744418919fSjohnjiang unsigned int num_bufs = int_data->num_bufs;
10754418919fSjohnjiang
10764418919fSjohnjiang /* from test_data: */
10774418919fSjohnjiang unsigned int buff_type = test_data->buff_type;
10784418919fSjohnjiang unsigned int big_data = test_data->big_data;
10794418919fSjohnjiang const struct rte_memzone *current_memzone;
10804418919fSjohnjiang
10814418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
10824418919fSjohnjiang struct rte_mempool *buf_pool;
10834418919fSjohnjiang
10844418919fSjohnjiang if (big_data)
10854418919fSjohnjiang buf_pool = ts_params->big_mbuf_pool;
10864418919fSjohnjiang else if (buff_type == SGL_BOTH)
10874418919fSjohnjiang buf_pool = ts_params->small_mbuf_pool;
10884418919fSjohnjiang else
10894418919fSjohnjiang buf_pool = ts_params->large_mbuf_pool;
10904418919fSjohnjiang
10914418919fSjohnjiang if (op_type == OPERATION_COMPRESSION)
10924418919fSjohnjiang current_bufs = test_priv_data->comp_bufs;
10934418919fSjohnjiang else
10944418919fSjohnjiang current_bufs = test_priv_data->uncomp_bufs;
10954418919fSjohnjiang
10964418919fSjohnjiang /* the mbufs allocation*/
10974418919fSjohnjiang ret = rte_pktmbuf_alloc_bulk(buf_pool, current_bufs, num_bufs);
10984418919fSjohnjiang if (ret < 0) {
10994418919fSjohnjiang RTE_LOG(ERR, USER1,
11004418919fSjohnjiang "Destination mbufs could not be allocated "
11014418919fSjohnjiang "from the mempool\n");
11024418919fSjohnjiang return -1;
11034418919fSjohnjiang }
11044418919fSjohnjiang
11054418919fSjohnjiang if (test_data->use_external_mbufs) {
11064418919fSjohnjiang current_extbuf_info->free_cb = extbuf_free_callback;
11074418919fSjohnjiang current_extbuf_info->fcb_opaque = NULL;
11084418919fSjohnjiang rte_mbuf_ext_refcnt_set(current_extbuf_info, 1);
11094418919fSjohnjiang if (op_type == OPERATION_COMPRESSION)
11104418919fSjohnjiang current_memzone = test_data->compbuf_memzone;
11114418919fSjohnjiang else
11124418919fSjohnjiang current_memzone = test_data->uncompbuf_memzone;
11134418919fSjohnjiang
11144418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
11154418919fSjohnjiang rte_pktmbuf_attach_extbuf(current_bufs[i],
11164418919fSjohnjiang current_memzone->addr,
11174418919fSjohnjiang current_memzone->iova,
11184418919fSjohnjiang current_memzone->len,
11194418919fSjohnjiang current_extbuf_info);
11204418919fSjohnjiang rte_pktmbuf_append(current_bufs[i],
11214418919fSjohnjiang current_memzone->len);
11224418919fSjohnjiang }
11234418919fSjohnjiang } else {
11244418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
11254418919fSjohnjiang
1126*2d9fd380Sjfb8856606 enum rte_comp_huffman comp_huffman =
1127*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman;
1128*2d9fd380Sjfb8856606
11294418919fSjohnjiang /* data size calculation */
11304418919fSjohnjiang data_size = test_mbufs_calculate_data_size(
11314418919fSjohnjiang op_type,
11324418919fSjohnjiang out_of_space_and_zlib,
11334418919fSjohnjiang test_priv_data,
11344418919fSjohnjiang int_data,
11354418919fSjohnjiang test_data,
11364418919fSjohnjiang i);
11374418919fSjohnjiang
1138*2d9fd380Sjfb8856606 if (comp_huffman != RTE_COMP_HUFFMAN_DYNAMIC) {
1139*2d9fd380Sjfb8856606 if (op_type == OPERATION_DECOMPRESSION)
1140*2d9fd380Sjfb8856606 data_size *= COMPRESS_BUF_SIZE_RATIO;
1141*2d9fd380Sjfb8856606 }
1142*2d9fd380Sjfb8856606
11434418919fSjohnjiang /* data allocation */
11444418919fSjohnjiang if (buff_type == SGL_BOTH || buff_type == LB_TO_SGL) {
11454418919fSjohnjiang ret = prepare_sgl_bufs(NULL, current_bufs[i],
11464418919fSjohnjiang data_size,
11474418919fSjohnjiang big_data ? buf_pool :
11484418919fSjohnjiang ts_params->small_mbuf_pool,
11494418919fSjohnjiang big_data ? buf_pool :
11504418919fSjohnjiang ts_params->large_mbuf_pool,
11514418919fSjohnjiang big_data ? 0 : MAX_SEGS,
11524418919fSjohnjiang big_data ? MAX_DATA_MBUF_SIZE :
11534418919fSjohnjiang SMALL_SEG_SIZE);
11544418919fSjohnjiang if (ret < 0)
11554418919fSjohnjiang return -1;
11564418919fSjohnjiang } else {
11574418919fSjohnjiang buf_ptr = rte_pktmbuf_append(current_bufs[i],
11584418919fSjohnjiang data_size);
11594418919fSjohnjiang if (buf_ptr == NULL) {
11604418919fSjohnjiang RTE_LOG(ERR, USER1,
11614418919fSjohnjiang "Append extra bytes to the destination mbuf failed\n");
11624418919fSjohnjiang return -1;
11634418919fSjohnjiang }
11644418919fSjohnjiang }
11654418919fSjohnjiang }
11664418919fSjohnjiang }
11674418919fSjohnjiang
11684418919fSjohnjiang return 0;
11694418919fSjohnjiang }
11704418919fSjohnjiang
11714418919fSjohnjiang /**
11724418919fSjohnjiang * The main compression function.
11734418919fSjohnjiang *
11744418919fSjohnjiang * Function performs compression operation.
11754418919fSjohnjiang * Operation(s) configuration, depending on CLI parameters.
11764418919fSjohnjiang * Operation(s) processing.
11774418919fSjohnjiang *
11784418919fSjohnjiang * @param int_data
11794418919fSjohnjiang * Interim data containing session/transformation objects.
11804418919fSjohnjiang * @param test_data
11814418919fSjohnjiang * The test parameters set by users (command line parameters).
11824418919fSjohnjiang * @param test_priv_data
11834418919fSjohnjiang * A container used for aggregation all the private test arrays.
11844418919fSjohnjiang * @return
11854418919fSjohnjiang * - 0: On success.
11864418919fSjohnjiang * - -1: On error.
11874418919fSjohnjiang */
11884418919fSjohnjiang static int
test_deflate_comp_run(const struct interim_data_params * int_data,const struct test_data_params * test_data,const struct test_private_arrays * test_priv_data)11894418919fSjohnjiang test_deflate_comp_run(const struct interim_data_params *int_data,
11904418919fSjohnjiang const struct test_data_params *test_data,
11914418919fSjohnjiang const struct test_private_arrays *test_priv_data)
11924418919fSjohnjiang {
11934418919fSjohnjiang /* local variables: */
11944418919fSjohnjiang struct priv_op_data *priv_data;
11954418919fSjohnjiang unsigned int i;
11964418919fSjohnjiang uint16_t num_priv_xforms = 0;
11974418919fSjohnjiang int ret;
11984418919fSjohnjiang int ret_status = 0;
11994418919fSjohnjiang char *buf_ptr;
12004418919fSjohnjiang
12014418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
12024418919fSjohnjiang
12034418919fSjohnjiang /* from test_data: */
12044418919fSjohnjiang enum rte_comp_op_type operation_type = test_data->compress_state;
12054418919fSjohnjiang unsigned int zlib_compress =
12064418919fSjohnjiang (test_data->zlib_dir == ZLIB_ALL ||
12074418919fSjohnjiang test_data->zlib_dir == ZLIB_COMPRESS);
12084418919fSjohnjiang
12094418919fSjohnjiang /* from int_data: */
12104418919fSjohnjiang struct rte_comp_xform **compress_xforms = int_data->compress_xforms;
12114418919fSjohnjiang unsigned int num_xforms = int_data->num_xforms;
12124418919fSjohnjiang unsigned int num_bufs = int_data->num_bufs;
12134418919fSjohnjiang
12144418919fSjohnjiang /* from test_priv_data: */
12154418919fSjohnjiang struct rte_mbuf **comp_bufs = test_priv_data->comp_bufs;
12164418919fSjohnjiang struct rte_mbuf **uncomp_bufs = test_priv_data->uncomp_bufs;
12174418919fSjohnjiang struct rte_comp_op **ops = test_priv_data->ops;
12184418919fSjohnjiang struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
12194418919fSjohnjiang void **priv_xforms = test_priv_data->priv_xforms;
12204418919fSjohnjiang
12214418919fSjohnjiang const struct rte_compressdev_capabilities *capa =
12224418919fSjohnjiang rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
12234418919fSjohnjiang
12244418919fSjohnjiang /* Build the compression operations */
12254418919fSjohnjiang ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
12264418919fSjohnjiang if (ret < 0) {
12274418919fSjohnjiang RTE_LOG(ERR, USER1,
12284418919fSjohnjiang "Compress operations could not be allocated "
12294418919fSjohnjiang "from the mempool\n");
12304418919fSjohnjiang ret_status = -1;
12314418919fSjohnjiang goto exit;
12324418919fSjohnjiang }
12334418919fSjohnjiang
12344418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
12354418919fSjohnjiang ops[i]->m_src = uncomp_bufs[i];
12364418919fSjohnjiang ops[i]->m_dst = comp_bufs[i];
12374418919fSjohnjiang ops[i]->src.offset = 0;
12384418919fSjohnjiang ops[i]->src.length = rte_pktmbuf_pkt_len(uncomp_bufs[i]);
12394418919fSjohnjiang ops[i]->dst.offset = 0;
12404418919fSjohnjiang
1241*2d9fd380Sjfb8856606 RTE_LOG(DEBUG, USER1,
1242*2d9fd380Sjfb8856606 "Uncompressed buffer length = %u compressed buffer length = %u",
1243*2d9fd380Sjfb8856606 rte_pktmbuf_pkt_len(uncomp_bufs[i]),
1244*2d9fd380Sjfb8856606 rte_pktmbuf_pkt_len(comp_bufs[i]));
1245*2d9fd380Sjfb8856606
12464418919fSjohnjiang if (operation_type == RTE_COMP_OP_STATELESS) {
12474418919fSjohnjiang ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
12484418919fSjohnjiang } else {
12494418919fSjohnjiang RTE_LOG(ERR, USER1,
12504418919fSjohnjiang "Compression: stateful operations are not "
12514418919fSjohnjiang "supported in these tests yet\n");
12524418919fSjohnjiang ret_status = -1;
12534418919fSjohnjiang goto exit;
12544418919fSjohnjiang }
12554418919fSjohnjiang ops[i]->input_chksum = 0;
12564418919fSjohnjiang /*
12574418919fSjohnjiang * Store original operation index in private data,
12584418919fSjohnjiang * since ordering does not have to be maintained,
12594418919fSjohnjiang * when dequeueing from compressdev, so a comparison
12604418919fSjohnjiang * at the end of the test can be done.
12614418919fSjohnjiang */
12624418919fSjohnjiang priv_data = (struct priv_op_data *) (ops[i] + 1);
12634418919fSjohnjiang priv_data->orig_idx = i;
12644418919fSjohnjiang }
12654418919fSjohnjiang
12664418919fSjohnjiang /* Compress data (either with Zlib API or compressdev API */
12674418919fSjohnjiang if (zlib_compress) {
12684418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
12694418919fSjohnjiang const struct rte_comp_xform *compress_xform =
12704418919fSjohnjiang compress_xforms[i % num_xforms];
12714418919fSjohnjiang ret = compress_zlib(ops[i], compress_xform,
12724418919fSjohnjiang DEFAULT_MEM_LEVEL);
12734418919fSjohnjiang if (ret < 0) {
12744418919fSjohnjiang ret_status = -1;
12754418919fSjohnjiang goto exit;
12764418919fSjohnjiang }
12774418919fSjohnjiang
12784418919fSjohnjiang ops_processed[i] = ops[i];
12794418919fSjohnjiang }
12804418919fSjohnjiang } else {
12814418919fSjohnjiang /* Create compress private xform data */
12824418919fSjohnjiang for (i = 0; i < num_xforms; i++) {
12834418919fSjohnjiang ret = rte_compressdev_private_xform_create(0,
12844418919fSjohnjiang (const struct rte_comp_xform *)
12854418919fSjohnjiang compress_xforms[i],
12864418919fSjohnjiang &priv_xforms[i]);
12874418919fSjohnjiang if (ret < 0) {
12884418919fSjohnjiang RTE_LOG(ERR, USER1,
12894418919fSjohnjiang "Compression private xform "
12904418919fSjohnjiang "could not be created\n");
12914418919fSjohnjiang ret_status = -1;
12924418919fSjohnjiang goto exit;
12934418919fSjohnjiang }
12944418919fSjohnjiang num_priv_xforms++;
12954418919fSjohnjiang }
12964418919fSjohnjiang if (capa->comp_feature_flags &
12974418919fSjohnjiang RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
12984418919fSjohnjiang /* Attach shareable private xform data to ops */
12994418919fSjohnjiang for (i = 0; i < num_bufs; i++)
13004418919fSjohnjiang ops[i]->private_xform =
13014418919fSjohnjiang priv_xforms[i % num_xforms];
13024418919fSjohnjiang } else {
13034418919fSjohnjiang /* Create rest of the private xforms for the other ops */
13044418919fSjohnjiang for (i = num_xforms; i < num_bufs; i++) {
13054418919fSjohnjiang ret = rte_compressdev_private_xform_create(0,
13064418919fSjohnjiang compress_xforms[i % num_xforms],
13074418919fSjohnjiang &priv_xforms[i]);
13084418919fSjohnjiang if (ret < 0) {
13094418919fSjohnjiang RTE_LOG(ERR, USER1,
13104418919fSjohnjiang "Compression private xform "
13114418919fSjohnjiang "could not be created\n");
13124418919fSjohnjiang ret_status = -1;
13134418919fSjohnjiang goto exit;
13144418919fSjohnjiang }
13154418919fSjohnjiang num_priv_xforms++;
13164418919fSjohnjiang }
13174418919fSjohnjiang /* Attach non shareable private xform data to ops */
13184418919fSjohnjiang for (i = 0; i < num_bufs; i++)
13194418919fSjohnjiang ops[i]->private_xform = priv_xforms[i];
13204418919fSjohnjiang }
13214418919fSjohnjiang
13224418919fSjohnjiang recovery_lb:
13234418919fSjohnjiang ret = test_run_enqueue_dequeue(ops, ops_processed, num_bufs);
13244418919fSjohnjiang if (ret < 0) {
13254418919fSjohnjiang RTE_LOG(ERR, USER1,
13264418919fSjohnjiang "Compression: enqueue/dequeue operation failed\n");
13274418919fSjohnjiang ret_status = -1;
13284418919fSjohnjiang goto exit;
13294418919fSjohnjiang }
13304418919fSjohnjiang
13314418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
13324418919fSjohnjiang test_priv_data->compressed_data_size[i] +=
13334418919fSjohnjiang ops_processed[i]->produced;
13344418919fSjohnjiang
13354418919fSjohnjiang if (ops_processed[i]->status ==
13364418919fSjohnjiang RTE_COMP_OP_STATUS_OUT_OF_SPACE_RECOVERABLE) {
13374418919fSjohnjiang
13384418919fSjohnjiang ops[i]->status =
13394418919fSjohnjiang RTE_COMP_OP_STATUS_NOT_PROCESSED;
13404418919fSjohnjiang ops[i]->src.offset +=
13414418919fSjohnjiang ops_processed[i]->consumed;
13424418919fSjohnjiang ops[i]->src.length -=
13434418919fSjohnjiang ops_processed[i]->consumed;
13444418919fSjohnjiang ops[i]->dst.offset +=
13454418919fSjohnjiang ops_processed[i]->produced;
13464418919fSjohnjiang
13474418919fSjohnjiang buf_ptr = rte_pktmbuf_append(
13484418919fSjohnjiang ops[i]->m_dst,
13494418919fSjohnjiang ops_processed[i]->produced);
13504418919fSjohnjiang
13514418919fSjohnjiang if (buf_ptr == NULL) {
13524418919fSjohnjiang RTE_LOG(ERR, USER1,
13534418919fSjohnjiang "Data recovery: append extra bytes to the current mbuf failed\n");
13544418919fSjohnjiang ret_status = -1;
13554418919fSjohnjiang goto exit;
13564418919fSjohnjiang }
13574418919fSjohnjiang goto recovery_lb;
13584418919fSjohnjiang }
13594418919fSjohnjiang }
13604418919fSjohnjiang }
13614418919fSjohnjiang
13624418919fSjohnjiang exit:
13634418919fSjohnjiang /* Free resources */
13644418919fSjohnjiang if (ret_status < 0)
13654418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
13664418919fSjohnjiang rte_comp_op_free(ops[i]);
1367*2d9fd380Sjfb8856606 ops[i] = NULL;
13684418919fSjohnjiang ops_processed[i] = NULL;
13694418919fSjohnjiang }
13704418919fSjohnjiang
13714418919fSjohnjiang /* Free compress private xforms */
13724418919fSjohnjiang for (i = 0; i < num_priv_xforms; i++) {
13734418919fSjohnjiang if (priv_xforms[i] != NULL) {
13744418919fSjohnjiang rte_compressdev_private_xform_free(0, priv_xforms[i]);
13754418919fSjohnjiang priv_xforms[i] = NULL;
13764418919fSjohnjiang }
13774418919fSjohnjiang }
13784418919fSjohnjiang
13794418919fSjohnjiang return ret_status;
13804418919fSjohnjiang }
13814418919fSjohnjiang
13824418919fSjohnjiang /**
13834418919fSjohnjiang * Prints out the test report. Memory freeing.
13844418919fSjohnjiang *
13854418919fSjohnjiang * Called after successful compression.
13864418919fSjohnjiang * Operation(s) status validation and decompression buffers freeing.
13874418919fSjohnjiang
13884418919fSjohnjiang * -1 returned if function fail.
13894418919fSjohnjiang *
13904418919fSjohnjiang * @param int_data
13914418919fSjohnjiang * Interim data containing session/transformation objects.
13924418919fSjohnjiang * @param test_data
13934418919fSjohnjiang * The test parameters set by users (command line parameters).
13944418919fSjohnjiang * @param test_priv_data
13954418919fSjohnjiang * A container used for aggregation all the private test arrays.
13964418919fSjohnjiang * @return
13974418919fSjohnjiang * - 2: Some operation is not supported
13984418919fSjohnjiang * - 1: Decompression should be skipped
13994418919fSjohnjiang * - 0: On success.
14004418919fSjohnjiang * - -1: On error.
14014418919fSjohnjiang */
14024418919fSjohnjiang static int
test_deflate_comp_finalize(const struct interim_data_params * int_data,const struct test_data_params * test_data,const struct test_private_arrays * test_priv_data)14034418919fSjohnjiang test_deflate_comp_finalize(const struct interim_data_params *int_data,
14044418919fSjohnjiang const struct test_data_params *test_data,
14054418919fSjohnjiang const struct test_private_arrays *test_priv_data)
14064418919fSjohnjiang {
14074418919fSjohnjiang /* local variables: */
14084418919fSjohnjiang unsigned int i;
14094418919fSjohnjiang struct priv_op_data *priv_data;
14104418919fSjohnjiang
14114418919fSjohnjiang /* from int_data: */
14124418919fSjohnjiang unsigned int num_xforms = int_data->num_xforms;
14134418919fSjohnjiang struct rte_comp_xform **compress_xforms = int_data->compress_xforms;
14144418919fSjohnjiang uint16_t *buf_idx = int_data->buf_idx;
14154418919fSjohnjiang unsigned int num_bufs = int_data->num_bufs;
14164418919fSjohnjiang
14174418919fSjohnjiang /* from test_priv_data: */
14184418919fSjohnjiang struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
14194418919fSjohnjiang uint64_t *compress_checksum = test_priv_data->compress_checksum;
14204418919fSjohnjiang struct rte_mbuf **uncomp_bufs = test_priv_data->uncomp_bufs;
14214418919fSjohnjiang struct rte_comp_op **ops = test_priv_data->ops;
14224418919fSjohnjiang
14234418919fSjohnjiang /* from test_data: */
14244418919fSjohnjiang unsigned int out_of_space = test_data->out_of_space;
14254418919fSjohnjiang unsigned int zlib_compress =
14264418919fSjohnjiang (test_data->zlib_dir == ZLIB_ALL ||
14274418919fSjohnjiang test_data->zlib_dir == ZLIB_COMPRESS);
14284418919fSjohnjiang unsigned int zlib_decompress =
14294418919fSjohnjiang (test_data->zlib_dir == ZLIB_ALL ||
14304418919fSjohnjiang test_data->zlib_dir == ZLIB_DECOMPRESS);
14314418919fSjohnjiang
14324418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
14334418919fSjohnjiang priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
14344418919fSjohnjiang uint16_t xform_idx = priv_data->orig_idx % num_xforms;
14354418919fSjohnjiang const struct rte_comp_compress_xform *compress_xform =
14364418919fSjohnjiang &compress_xforms[xform_idx]->compress;
14374418919fSjohnjiang enum rte_comp_huffman huffman_type =
14384418919fSjohnjiang compress_xform->deflate.huffman;
14394418919fSjohnjiang char engine[] = "zlib (directly, not PMD)";
14404418919fSjohnjiang if (zlib_decompress)
14414418919fSjohnjiang strlcpy(engine, "PMD", sizeof(engine));
14424418919fSjohnjiang
14434418919fSjohnjiang RTE_LOG(DEBUG, USER1, "Buffer %u compressed by %s from %u to"
14444418919fSjohnjiang " %u bytes (level = %d, huffman = %s)\n",
14454418919fSjohnjiang buf_idx[priv_data->orig_idx], engine,
14464418919fSjohnjiang ops_processed[i]->consumed, ops_processed[i]->produced,
14474418919fSjohnjiang compress_xform->level,
14484418919fSjohnjiang huffman_type_strings[huffman_type]);
14494418919fSjohnjiang RTE_LOG(DEBUG, USER1, "Compression ratio = %.2f\n",
14504418919fSjohnjiang ops_processed[i]->consumed == 0 ? 0 :
14514418919fSjohnjiang (float)ops_processed[i]->produced /
14524418919fSjohnjiang ops_processed[i]->consumed * 100);
14534418919fSjohnjiang if (compress_xform->chksum != RTE_COMP_CHECKSUM_NONE)
14544418919fSjohnjiang compress_checksum[i] = ops_processed[i]->output_chksum;
14554418919fSjohnjiang ops[i] = NULL;
14564418919fSjohnjiang }
14574418919fSjohnjiang
14584418919fSjohnjiang /*
14594418919fSjohnjiang * Check operation status and free source mbufs (destination mbuf and
14604418919fSjohnjiang * compress operation information is needed for the decompression stage)
14614418919fSjohnjiang */
14624418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
14634418919fSjohnjiang if (out_of_space && !zlib_compress) {
14644418919fSjohnjiang if (ops_processed[i]->status !=
14654418919fSjohnjiang RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED) {
14664418919fSjohnjiang RTE_LOG(ERR, USER1,
14674418919fSjohnjiang "Operation without expected out of "
14684418919fSjohnjiang "space status error\n");
14694418919fSjohnjiang return -1;
14704418919fSjohnjiang } else
14714418919fSjohnjiang continue;
14724418919fSjohnjiang }
14734418919fSjohnjiang
14744418919fSjohnjiang if (ops_processed[i]->status != RTE_COMP_OP_STATUS_SUCCESS) {
14754418919fSjohnjiang if (test_data->overflow == OVERFLOW_ENABLED) {
14764418919fSjohnjiang if (ops_processed[i]->status ==
14774418919fSjohnjiang RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED) {
14784418919fSjohnjiang RTE_LOG(INFO, USER1,
14794418919fSjohnjiang "Out-of-space-recoverable functionality"
14804418919fSjohnjiang " is not supported on this device\n");
14814418919fSjohnjiang return 2;
14824418919fSjohnjiang }
14834418919fSjohnjiang }
14844418919fSjohnjiang
14854418919fSjohnjiang RTE_LOG(ERR, USER1,
1486*2d9fd380Sjfb8856606 "Comp: Some operations were not successful\n");
14874418919fSjohnjiang return -1;
14884418919fSjohnjiang }
14894418919fSjohnjiang priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
14904418919fSjohnjiang rte_pktmbuf_free(uncomp_bufs[priv_data->orig_idx]);
14914418919fSjohnjiang uncomp_bufs[priv_data->orig_idx] = NULL;
14924418919fSjohnjiang }
14934418919fSjohnjiang
14944418919fSjohnjiang if (out_of_space && !zlib_compress)
14954418919fSjohnjiang return 1;
14964418919fSjohnjiang
14974418919fSjohnjiang return 0;
14984418919fSjohnjiang }
14994418919fSjohnjiang
15004418919fSjohnjiang /**
15014418919fSjohnjiang * The main decompression function.
15024418919fSjohnjiang *
15034418919fSjohnjiang * Function performs decompression operation.
15044418919fSjohnjiang * Operation(s) configuration, depending on CLI parameters.
15054418919fSjohnjiang * Operation(s) processing.
15064418919fSjohnjiang *
15074418919fSjohnjiang * @param int_data
15084418919fSjohnjiang * Interim data containing session/transformation objects.
15094418919fSjohnjiang * @param test_data
15104418919fSjohnjiang * The test parameters set by users (command line parameters).
15114418919fSjohnjiang * @param test_priv_data
15124418919fSjohnjiang * A container used for aggregation all the private test arrays.
15134418919fSjohnjiang * @return
15144418919fSjohnjiang * - 0: On success.
15154418919fSjohnjiang * - -1: On error.
15164418919fSjohnjiang */
15174418919fSjohnjiang static int
test_deflate_decomp_run(const struct interim_data_params * int_data,const struct test_data_params * test_data,struct test_private_arrays * test_priv_data)15184418919fSjohnjiang test_deflate_decomp_run(const struct interim_data_params *int_data,
15194418919fSjohnjiang const struct test_data_params *test_data,
15204418919fSjohnjiang struct test_private_arrays *test_priv_data)
15214418919fSjohnjiang {
15224418919fSjohnjiang
15234418919fSjohnjiang /* local variables: */
15244418919fSjohnjiang struct priv_op_data *priv_data;
15254418919fSjohnjiang unsigned int i;
15264418919fSjohnjiang uint16_t num_priv_xforms = 0;
15274418919fSjohnjiang int ret;
15284418919fSjohnjiang int ret_status = 0;
15294418919fSjohnjiang
15304418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
15314418919fSjohnjiang
15324418919fSjohnjiang /* from test_data: */
15334418919fSjohnjiang enum rte_comp_op_type operation_type = test_data->decompress_state;
15344418919fSjohnjiang unsigned int zlib_decompress =
15354418919fSjohnjiang (test_data->zlib_dir == ZLIB_ALL ||
15364418919fSjohnjiang test_data->zlib_dir == ZLIB_DECOMPRESS);
15374418919fSjohnjiang
15384418919fSjohnjiang /* from int_data: */
15394418919fSjohnjiang struct rte_comp_xform **decompress_xforms = int_data->decompress_xforms;
15404418919fSjohnjiang unsigned int num_xforms = int_data->num_xforms;
15414418919fSjohnjiang unsigned int num_bufs = int_data->num_bufs;
15424418919fSjohnjiang
15434418919fSjohnjiang /* from test_priv_data: */
15444418919fSjohnjiang struct rte_mbuf **uncomp_bufs = test_priv_data->uncomp_bufs;
1545*2d9fd380Sjfb8856606 struct rte_mbuf **comp_bufs = test_priv_data->comp_bufs;
15464418919fSjohnjiang struct rte_comp_op **ops = test_priv_data->ops;
15474418919fSjohnjiang struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
15484418919fSjohnjiang void **priv_xforms = test_priv_data->priv_xforms;
15494418919fSjohnjiang uint32_t *compressed_data_size = test_priv_data->compressed_data_size;
15504418919fSjohnjiang void **stream = test_priv_data->stream;
15514418919fSjohnjiang
15524418919fSjohnjiang const struct rte_compressdev_capabilities *capa =
15534418919fSjohnjiang rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
15544418919fSjohnjiang
15554418919fSjohnjiang ret = rte_comp_op_bulk_alloc(ts_params->op_pool, ops, num_bufs);
15564418919fSjohnjiang if (ret < 0) {
15574418919fSjohnjiang RTE_LOG(ERR, USER1,
15584418919fSjohnjiang "Decompress operations could not be allocated "
15594418919fSjohnjiang "from the mempool\n");
15604418919fSjohnjiang ret_status = -1;
15614418919fSjohnjiang goto exit;
15624418919fSjohnjiang }
15634418919fSjohnjiang
15644418919fSjohnjiang /* Source buffer is the compressed data from the previous operations */
15654418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
1566*2d9fd380Sjfb8856606 ops[i]->m_src = comp_bufs[i];
15674418919fSjohnjiang ops[i]->m_dst = uncomp_bufs[i];
15684418919fSjohnjiang ops[i]->src.offset = 0;
15694418919fSjohnjiang /*
15704418919fSjohnjiang * Set the length of the compressed data to the
15714418919fSjohnjiang * number of bytes that were produced in the previous stage
15724418919fSjohnjiang */
15734418919fSjohnjiang
15744418919fSjohnjiang if (compressed_data_size[i])
15754418919fSjohnjiang ops[i]->src.length = compressed_data_size[i];
15764418919fSjohnjiang else
15774418919fSjohnjiang ops[i]->src.length = ops_processed[i]->produced;
15784418919fSjohnjiang
15794418919fSjohnjiang ops[i]->dst.offset = 0;
15804418919fSjohnjiang
15814418919fSjohnjiang if (operation_type == RTE_COMP_OP_STATELESS) {
15824418919fSjohnjiang ops[i]->flush_flag = RTE_COMP_FLUSH_FINAL;
15834418919fSjohnjiang ops[i]->op_type = RTE_COMP_OP_STATELESS;
15844418919fSjohnjiang } else if (!zlib_decompress) {
15854418919fSjohnjiang ops[i]->flush_flag = RTE_COMP_FLUSH_SYNC;
15864418919fSjohnjiang ops[i]->op_type = RTE_COMP_OP_STATEFUL;
15874418919fSjohnjiang } else {
15884418919fSjohnjiang RTE_LOG(ERR, USER1,
15894418919fSjohnjiang "Decompression: stateful operations are"
15904418919fSjohnjiang " not supported in these tests yet\n");
15914418919fSjohnjiang ret_status = -1;
15924418919fSjohnjiang goto exit;
15934418919fSjohnjiang }
15944418919fSjohnjiang ops[i]->input_chksum = 0;
15954418919fSjohnjiang /*
15964418919fSjohnjiang * Copy private data from previous operations,
15974418919fSjohnjiang * to keep the pointer to the original buffer
15984418919fSjohnjiang */
15994418919fSjohnjiang memcpy(ops[i] + 1, ops_processed[i] + 1,
16004418919fSjohnjiang sizeof(struct priv_op_data));
16014418919fSjohnjiang }
16024418919fSjohnjiang
16034418919fSjohnjiang /*
16044418919fSjohnjiang * Free the previous compress operations,
16054418919fSjohnjiang * as they are not needed anymore
16064418919fSjohnjiang */
16074418919fSjohnjiang rte_comp_op_bulk_free(ops_processed, num_bufs);
16084418919fSjohnjiang
16094418919fSjohnjiang /* Decompress data (either with Zlib API or compressdev API */
16104418919fSjohnjiang if (zlib_decompress) {
16114418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
16124418919fSjohnjiang priv_data = (struct priv_op_data *)(ops[i] + 1);
16134418919fSjohnjiang uint16_t xform_idx = priv_data->orig_idx % num_xforms;
16144418919fSjohnjiang const struct rte_comp_xform *decompress_xform =
16154418919fSjohnjiang decompress_xforms[xform_idx];
16164418919fSjohnjiang
16174418919fSjohnjiang ret = decompress_zlib(ops[i], decompress_xform);
16184418919fSjohnjiang if (ret < 0) {
16194418919fSjohnjiang ret_status = -1;
16204418919fSjohnjiang goto exit;
16214418919fSjohnjiang }
16224418919fSjohnjiang
16234418919fSjohnjiang ops_processed[i] = ops[i];
16244418919fSjohnjiang }
16254418919fSjohnjiang } else {
16264418919fSjohnjiang if (operation_type == RTE_COMP_OP_STATELESS) {
16274418919fSjohnjiang /* Create decompress private xform data */
16284418919fSjohnjiang for (i = 0; i < num_xforms; i++) {
16294418919fSjohnjiang ret = rte_compressdev_private_xform_create(0,
16304418919fSjohnjiang (const struct rte_comp_xform *)
16314418919fSjohnjiang decompress_xforms[i],
16324418919fSjohnjiang &priv_xforms[i]);
16334418919fSjohnjiang if (ret < 0) {
16344418919fSjohnjiang RTE_LOG(ERR, USER1,
16354418919fSjohnjiang "Decompression private xform "
16364418919fSjohnjiang "could not be created\n");
16374418919fSjohnjiang ret_status = -1;
16384418919fSjohnjiang goto exit;
16394418919fSjohnjiang }
16404418919fSjohnjiang num_priv_xforms++;
16414418919fSjohnjiang }
16424418919fSjohnjiang
16434418919fSjohnjiang if (capa->comp_feature_flags &
16444418919fSjohnjiang RTE_COMP_FF_SHAREABLE_PRIV_XFORM) {
16454418919fSjohnjiang /* Attach shareable private xform data to ops */
16464418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
16474418919fSjohnjiang priv_data = (struct priv_op_data *)
16484418919fSjohnjiang (ops[i] + 1);
16494418919fSjohnjiang uint16_t xform_idx =
16504418919fSjohnjiang priv_data->orig_idx % num_xforms;
16514418919fSjohnjiang ops[i]->private_xform =
16524418919fSjohnjiang priv_xforms[xform_idx];
16534418919fSjohnjiang }
16544418919fSjohnjiang } else {
16554418919fSjohnjiang /* Create rest of the private xforms */
16564418919fSjohnjiang /* for the other ops */
16574418919fSjohnjiang for (i = num_xforms; i < num_bufs; i++) {
16584418919fSjohnjiang ret =
16594418919fSjohnjiang rte_compressdev_private_xform_create(0,
16604418919fSjohnjiang decompress_xforms[i % num_xforms],
16614418919fSjohnjiang &priv_xforms[i]);
16624418919fSjohnjiang if (ret < 0) {
16634418919fSjohnjiang RTE_LOG(ERR, USER1,
16644418919fSjohnjiang "Decompression private xform"
16654418919fSjohnjiang " could not be created\n");
16664418919fSjohnjiang ret_status = -1;
16674418919fSjohnjiang goto exit;
16684418919fSjohnjiang }
16694418919fSjohnjiang num_priv_xforms++;
16704418919fSjohnjiang }
16714418919fSjohnjiang
16724418919fSjohnjiang /* Attach non shareable private xform data */
16734418919fSjohnjiang /* to ops */
16744418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
16754418919fSjohnjiang priv_data = (struct priv_op_data *)
16764418919fSjohnjiang (ops[i] + 1);
16774418919fSjohnjiang uint16_t xform_idx =
16784418919fSjohnjiang priv_data->orig_idx;
16794418919fSjohnjiang ops[i]->private_xform =
16804418919fSjohnjiang priv_xforms[xform_idx];
16814418919fSjohnjiang }
16824418919fSjohnjiang }
16834418919fSjohnjiang } else {
16844418919fSjohnjiang /* Create a stream object for stateful decompression */
16854418919fSjohnjiang ret = rte_compressdev_stream_create(0,
16864418919fSjohnjiang decompress_xforms[0], stream);
16874418919fSjohnjiang if (ret < 0) {
16884418919fSjohnjiang RTE_LOG(ERR, USER1,
16894418919fSjohnjiang "Decompression stream could not be created, error %d\n",
16904418919fSjohnjiang ret);
16914418919fSjohnjiang ret_status = -1;
16924418919fSjohnjiang goto exit;
16934418919fSjohnjiang }
16944418919fSjohnjiang /* Attach stream to ops */
16954418919fSjohnjiang for (i = 0; i < num_bufs; i++)
16964418919fSjohnjiang ops[i]->stream = *stream;
16974418919fSjohnjiang }
16984418919fSjohnjiang
16994418919fSjohnjiang test_priv_data->num_priv_xforms = num_priv_xforms;
17004418919fSjohnjiang }
17014418919fSjohnjiang
17024418919fSjohnjiang exit:
17034418919fSjohnjiang return ret_status;
17044418919fSjohnjiang }
17054418919fSjohnjiang
17064418919fSjohnjiang /**
17074418919fSjohnjiang * Prints out the test report. Memory freeing.
17084418919fSjohnjiang *
17094418919fSjohnjiang * Called after successful decompression.
17104418919fSjohnjiang * Operation(s) status validation and compression buffers freeing.
17114418919fSjohnjiang
17124418919fSjohnjiang * -1 returned if function fail.
17134418919fSjohnjiang *
17144418919fSjohnjiang * @param int_data
17154418919fSjohnjiang * Interim data containing session/transformation objects.
17164418919fSjohnjiang * @param test_data
17174418919fSjohnjiang * The test parameters set by users (command line parameters).
17184418919fSjohnjiang * @param test_priv_data
17194418919fSjohnjiang * A container used for aggregation all the private test arrays.
17204418919fSjohnjiang * @return
17214418919fSjohnjiang * - 2: Next step must be executed by the caller (stateful decompression only)
17224418919fSjohnjiang * - 1: On success (caller should stop and exit)
17234418919fSjohnjiang * - 0: On success.
17244418919fSjohnjiang * - -1: On error.
17254418919fSjohnjiang */
17264418919fSjohnjiang static int
test_deflate_decomp_finalize(const struct interim_data_params * int_data,const struct test_data_params * test_data,const struct test_private_arrays * test_priv_data)17274418919fSjohnjiang test_deflate_decomp_finalize(const struct interim_data_params *int_data,
17284418919fSjohnjiang const struct test_data_params *test_data,
17294418919fSjohnjiang const struct test_private_arrays *test_priv_data)
17304418919fSjohnjiang {
17314418919fSjohnjiang /* local variables: */
17324418919fSjohnjiang unsigned int i;
17334418919fSjohnjiang struct priv_op_data *priv_data;
17344418919fSjohnjiang static unsigned int step;
17354418919fSjohnjiang
17364418919fSjohnjiang /* from int_data: */
17374418919fSjohnjiang uint16_t *buf_idx = int_data->buf_idx;
17384418919fSjohnjiang unsigned int num_bufs = int_data->num_bufs;
17394418919fSjohnjiang const char * const *test_bufs = int_data->test_bufs;
17404418919fSjohnjiang struct rte_comp_xform **compress_xforms = int_data->compress_xforms;
17414418919fSjohnjiang
17424418919fSjohnjiang /* from test_priv_data: */
17434418919fSjohnjiang struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
17444418919fSjohnjiang struct rte_mbuf **comp_bufs = test_priv_data->comp_bufs;
17454418919fSjohnjiang struct rte_comp_op **ops = test_priv_data->ops;
17464418919fSjohnjiang uint64_t *compress_checksum = test_priv_data->compress_checksum;
17474418919fSjohnjiang unsigned int *decomp_produced_data_size =
17484418919fSjohnjiang test_priv_data->decomp_produced_data_size;
17494418919fSjohnjiang char **all_decomp_data = test_priv_data->all_decomp_data;
17504418919fSjohnjiang
17514418919fSjohnjiang /* from test_data: */
17524418919fSjohnjiang unsigned int out_of_space = test_data->out_of_space;
17534418919fSjohnjiang enum rte_comp_op_type operation_type = test_data->decompress_state;
17544418919fSjohnjiang
17554418919fSjohnjiang unsigned int zlib_compress =
17564418919fSjohnjiang (test_data->zlib_dir == ZLIB_ALL ||
17574418919fSjohnjiang test_data->zlib_dir == ZLIB_COMPRESS);
17584418919fSjohnjiang unsigned int zlib_decompress =
17594418919fSjohnjiang (test_data->zlib_dir == ZLIB_ALL ||
17604418919fSjohnjiang test_data->zlib_dir == ZLIB_DECOMPRESS);
17614418919fSjohnjiang
17624418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
17634418919fSjohnjiang priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
17644418919fSjohnjiang char engine[] = "zlib, (directly, no PMD)";
17654418919fSjohnjiang if (zlib_compress)
17664418919fSjohnjiang strlcpy(engine, "pmd", sizeof(engine));
17674418919fSjohnjiang RTE_LOG(DEBUG, USER1,
17684418919fSjohnjiang "Buffer %u decompressed by %s from %u to %u bytes\n",
17694418919fSjohnjiang buf_idx[priv_data->orig_idx], engine,
17704418919fSjohnjiang ops_processed[i]->consumed, ops_processed[i]->produced);
17714418919fSjohnjiang ops[i] = NULL;
17724418919fSjohnjiang }
17734418919fSjohnjiang
17744418919fSjohnjiang /*
17754418919fSjohnjiang * Check operation status and free source mbuf (destination mbuf and
17764418919fSjohnjiang * compress operation information is still needed)
17774418919fSjohnjiang */
17784418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
17794418919fSjohnjiang if (out_of_space && !zlib_decompress) {
17804418919fSjohnjiang if (ops_processed[i]->status !=
17814418919fSjohnjiang RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED) {
17824418919fSjohnjiang
17834418919fSjohnjiang RTE_LOG(ERR, USER1,
17844418919fSjohnjiang "Operation without expected out of "
17854418919fSjohnjiang "space status error\n");
17864418919fSjohnjiang return -1;
17874418919fSjohnjiang } else
17884418919fSjohnjiang continue;
17894418919fSjohnjiang }
17904418919fSjohnjiang
17914418919fSjohnjiang if (operation_type == RTE_COMP_OP_STATEFUL
17924418919fSjohnjiang && (ops_processed[i]->status ==
17934418919fSjohnjiang RTE_COMP_OP_STATUS_OUT_OF_SPACE_RECOVERABLE
17944418919fSjohnjiang || ops_processed[i]->status ==
17954418919fSjohnjiang RTE_COMP_OP_STATUS_SUCCESS)) {
1796*2d9fd380Sjfb8856606
1797*2d9fd380Sjfb8856606 RTE_LOG(DEBUG, USER1,
1798*2d9fd380Sjfb8856606 ".............RECOVERABLE\n");
1799*2d9fd380Sjfb8856606
18004418919fSjohnjiang /* collect the output into all_decomp_data */
18014418919fSjohnjiang const void *ptr = rte_pktmbuf_read(
18024418919fSjohnjiang ops_processed[i]->m_dst,
18034418919fSjohnjiang ops_processed[i]->dst.offset,
18044418919fSjohnjiang ops_processed[i]->produced,
18054418919fSjohnjiang *all_decomp_data +
18064418919fSjohnjiang *decomp_produced_data_size);
18074418919fSjohnjiang if (ptr != *all_decomp_data +
18084418919fSjohnjiang *decomp_produced_data_size)
18094418919fSjohnjiang rte_memcpy(*all_decomp_data +
18104418919fSjohnjiang *decomp_produced_data_size,
18114418919fSjohnjiang ptr, ops_processed[i]->produced);
18124418919fSjohnjiang
18134418919fSjohnjiang *decomp_produced_data_size +=
18144418919fSjohnjiang ops_processed[i]->produced;
18154418919fSjohnjiang if (ops_processed[i]->src.length >
18164418919fSjohnjiang ops_processed[i]->consumed) {
18174418919fSjohnjiang if (ops_processed[i]->status ==
18184418919fSjohnjiang RTE_COMP_OP_STATUS_SUCCESS) {
18194418919fSjohnjiang RTE_LOG(ERR, USER1,
18204418919fSjohnjiang "Operation finished too early\n");
18214418919fSjohnjiang return -1;
18224418919fSjohnjiang }
18234418919fSjohnjiang step++;
18244418919fSjohnjiang if (step >= test_data->decompress_steps_max) {
18254418919fSjohnjiang RTE_LOG(ERR, USER1,
18264418919fSjohnjiang "Operation exceeded maximum steps\n");
18274418919fSjohnjiang return -1;
18284418919fSjohnjiang }
18294418919fSjohnjiang ops[i] = ops_processed[i];
18304418919fSjohnjiang ops[i]->status =
18314418919fSjohnjiang RTE_COMP_OP_STATUS_NOT_PROCESSED;
18324418919fSjohnjiang ops[i]->src.offset +=
18334418919fSjohnjiang ops_processed[i]->consumed;
18344418919fSjohnjiang ops[i]->src.length -=
18354418919fSjohnjiang ops_processed[i]->consumed;
18364418919fSjohnjiang /* repeat the operation */
18374418919fSjohnjiang return 2;
18384418919fSjohnjiang } else {
18394418919fSjohnjiang /* Compare the original stream with the */
18404418919fSjohnjiang /* decompressed stream (in size and the data) */
18414418919fSjohnjiang priv_data = (struct priv_op_data *)
18424418919fSjohnjiang (ops_processed[i] + 1);
18434418919fSjohnjiang const char *buf1 =
18444418919fSjohnjiang test_bufs[priv_data->orig_idx];
18454418919fSjohnjiang const char *buf2 = *all_decomp_data;
18464418919fSjohnjiang
18474418919fSjohnjiang if (compare_buffers(buf1, strlen(buf1) + 1,
18484418919fSjohnjiang buf2, *decomp_produced_data_size) < 0)
18494418919fSjohnjiang return -1;
18504418919fSjohnjiang /* Test checksums */
18514418919fSjohnjiang if (compress_xforms[0]->compress.chksum
18524418919fSjohnjiang != RTE_COMP_CHECKSUM_NONE) {
18534418919fSjohnjiang if (ops_processed[i]->output_chksum
18544418919fSjohnjiang != compress_checksum[i]) {
18554418919fSjohnjiang RTE_LOG(ERR, USER1,
18564418919fSjohnjiang "The checksums differ\n"
18574418919fSjohnjiang "Compression Checksum: %" PRIu64 "\tDecompression "
18584418919fSjohnjiang "Checksum: %" PRIu64 "\n", compress_checksum[i],
18594418919fSjohnjiang ops_processed[i]->output_chksum);
18604418919fSjohnjiang return -1;
18614418919fSjohnjiang }
18624418919fSjohnjiang }
18634418919fSjohnjiang }
18644418919fSjohnjiang } else if (ops_processed[i]->status !=
18654418919fSjohnjiang RTE_COMP_OP_STATUS_SUCCESS) {
18664418919fSjohnjiang RTE_LOG(ERR, USER1,
1867*2d9fd380Sjfb8856606 "Decomp: Some operations were not successful, status = %u\n",
1868*2d9fd380Sjfb8856606 ops_processed[i]->status);
18694418919fSjohnjiang return -1;
18704418919fSjohnjiang }
18714418919fSjohnjiang priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
18724418919fSjohnjiang rte_pktmbuf_free(comp_bufs[priv_data->orig_idx]);
18734418919fSjohnjiang comp_bufs[priv_data->orig_idx] = NULL;
18744418919fSjohnjiang }
18754418919fSjohnjiang
18764418919fSjohnjiang if (out_of_space && !zlib_decompress)
18774418919fSjohnjiang return 1;
18784418919fSjohnjiang
18794418919fSjohnjiang return 0;
18804418919fSjohnjiang }
18814418919fSjohnjiang
18824418919fSjohnjiang /**
18834418919fSjohnjiang * Validation of the output (compression/decompression) data.
18844418919fSjohnjiang *
18854418919fSjohnjiang * The function compares the source stream with the output stream,
18864418919fSjohnjiang * after decompression, to check if compression/decompression
18874418919fSjohnjiang * was correct.
18884418919fSjohnjiang * -1 returned if function fail.
18894418919fSjohnjiang *
18904418919fSjohnjiang * @param int_data
18914418919fSjohnjiang * Interim data containing session/transformation objects.
18924418919fSjohnjiang * @param test_data
18934418919fSjohnjiang * The test parameters set by users (command line parameters).
18944418919fSjohnjiang * @param test_priv_data
18954418919fSjohnjiang * A container used for aggregation all the private test arrays.
18964418919fSjohnjiang * @return
18974418919fSjohnjiang * - 0: On success.
18984418919fSjohnjiang * - -1: On error.
18994418919fSjohnjiang */
19004418919fSjohnjiang static int
test_results_validation(const struct interim_data_params * int_data,const struct test_data_params * test_data,const struct test_private_arrays * test_priv_data)19014418919fSjohnjiang test_results_validation(const struct interim_data_params *int_data,
19024418919fSjohnjiang const struct test_data_params *test_data,
19034418919fSjohnjiang const struct test_private_arrays *test_priv_data)
19044418919fSjohnjiang {
19054418919fSjohnjiang /* local variables: */
19064418919fSjohnjiang unsigned int i;
19074418919fSjohnjiang struct priv_op_data *priv_data;
19084418919fSjohnjiang const char *buf1;
19094418919fSjohnjiang const char *buf2;
19104418919fSjohnjiang char *contig_buf = NULL;
19114418919fSjohnjiang uint32_t data_size;
19124418919fSjohnjiang
19134418919fSjohnjiang /* from int_data: */
19144418919fSjohnjiang struct rte_comp_xform **compress_xforms = int_data->compress_xforms;
19154418919fSjohnjiang unsigned int num_bufs = int_data->num_bufs;
19164418919fSjohnjiang const char * const *test_bufs = int_data->test_bufs;
19174418919fSjohnjiang
19184418919fSjohnjiang /* from test_priv_data: */
19194418919fSjohnjiang uint64_t *compress_checksum = test_priv_data->compress_checksum;
19204418919fSjohnjiang struct rte_comp_op **ops_processed = test_priv_data->ops_processed;
19214418919fSjohnjiang
19224418919fSjohnjiang /*
19234418919fSjohnjiang * Compare the original stream with the decompressed stream
19244418919fSjohnjiang * (in size and the data)
19254418919fSjohnjiang */
19264418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
19274418919fSjohnjiang priv_data = (struct priv_op_data *)(ops_processed[i] + 1);
19284418919fSjohnjiang buf1 = test_data->use_external_mbufs ?
19294418919fSjohnjiang test_data->inbuf_memzone->addr :
19304418919fSjohnjiang test_bufs[priv_data->orig_idx];
19314418919fSjohnjiang data_size = test_data->use_external_mbufs ?
19324418919fSjohnjiang test_data->inbuf_data_size :
19334418919fSjohnjiang strlen(buf1) + 1;
19344418919fSjohnjiang
19354418919fSjohnjiang contig_buf = rte_malloc(NULL, ops_processed[i]->produced, 0);
19364418919fSjohnjiang if (contig_buf == NULL) {
19374418919fSjohnjiang RTE_LOG(ERR, USER1, "Contiguous buffer could not "
19384418919fSjohnjiang "be allocated\n");
19394418919fSjohnjiang goto exit;
19404418919fSjohnjiang }
19414418919fSjohnjiang
19424418919fSjohnjiang buf2 = rte_pktmbuf_read(ops_processed[i]->m_dst, 0,
19434418919fSjohnjiang ops_processed[i]->produced, contig_buf);
19444418919fSjohnjiang if (compare_buffers(buf1, data_size,
19454418919fSjohnjiang buf2, ops_processed[i]->produced) < 0)
19464418919fSjohnjiang goto exit;
19474418919fSjohnjiang
19484418919fSjohnjiang /* Test checksums */
19494418919fSjohnjiang if (compress_xforms[0]->compress.chksum !=
19504418919fSjohnjiang RTE_COMP_CHECKSUM_NONE) {
19514418919fSjohnjiang if (ops_processed[i]->output_chksum !=
19524418919fSjohnjiang compress_checksum[i]) {
19534418919fSjohnjiang RTE_LOG(ERR, USER1, "The checksums differ\n"
19544418919fSjohnjiang "Compression Checksum: %" PRIu64 "\tDecompression "
19554418919fSjohnjiang "Checksum: %" PRIu64 "\n", compress_checksum[i],
19564418919fSjohnjiang ops_processed[i]->output_chksum);
19574418919fSjohnjiang goto exit;
19584418919fSjohnjiang }
19594418919fSjohnjiang }
19604418919fSjohnjiang
19614418919fSjohnjiang rte_free(contig_buf);
19624418919fSjohnjiang contig_buf = NULL;
19634418919fSjohnjiang }
19644418919fSjohnjiang return 0;
19654418919fSjohnjiang
19664418919fSjohnjiang exit:
19674418919fSjohnjiang rte_free(contig_buf);
19684418919fSjohnjiang return -1;
19694418919fSjohnjiang }
19704418919fSjohnjiang
19714418919fSjohnjiang /**
19724418919fSjohnjiang * Compresses and decompresses input stream with compressdev API and Zlib API
19734418919fSjohnjiang *
19744418919fSjohnjiang * Basic test function. Common for all the functional tests.
19754418919fSjohnjiang * -1 returned if function fail.
19764418919fSjohnjiang *
19774418919fSjohnjiang * @param int_data
19784418919fSjohnjiang * Interim data containing session/transformation objects.
19794418919fSjohnjiang * @param test_data
19804418919fSjohnjiang * The test parameters set by users (command line parameters).
19814418919fSjohnjiang * @return
19824418919fSjohnjiang * - 1: Some operation not supported
19834418919fSjohnjiang * - 0: On success.
19844418919fSjohnjiang * - -1: On error.
19854418919fSjohnjiang */
19864418919fSjohnjiang
19874418919fSjohnjiang static int
test_deflate_comp_decomp(const struct interim_data_params * int_data,const struct test_data_params * test_data)19884418919fSjohnjiang test_deflate_comp_decomp(const struct interim_data_params *int_data,
19894418919fSjohnjiang const struct test_data_params *test_data)
19904418919fSjohnjiang {
19914418919fSjohnjiang unsigned int num_bufs = int_data->num_bufs;
19924418919fSjohnjiang unsigned int out_of_space = test_data->out_of_space;
19934418919fSjohnjiang
19944418919fSjohnjiang void *stream = NULL;
19954418919fSjohnjiang char *all_decomp_data = NULL;
19964418919fSjohnjiang unsigned int decomp_produced_data_size = 0;
19974418919fSjohnjiang
19984418919fSjohnjiang int ret_status = -1;
19994418919fSjohnjiang int ret;
20004418919fSjohnjiang struct rte_mbuf *uncomp_bufs[num_bufs];
20014418919fSjohnjiang struct rte_mbuf *comp_bufs[num_bufs];
20024418919fSjohnjiang struct rte_comp_op *ops[num_bufs];
20034418919fSjohnjiang struct rte_comp_op *ops_processed[num_bufs];
20044418919fSjohnjiang void *priv_xforms[num_bufs];
20054418919fSjohnjiang unsigned int i;
20064418919fSjohnjiang
20074418919fSjohnjiang uint64_t compress_checksum[num_bufs];
20084418919fSjohnjiang uint32_t compressed_data_size[num_bufs];
20094418919fSjohnjiang char *contig_buf = NULL;
20104418919fSjohnjiang
20114418919fSjohnjiang struct rte_mbuf_ext_shared_info compbuf_info;
20124418919fSjohnjiang struct rte_mbuf_ext_shared_info decompbuf_info;
20134418919fSjohnjiang
20144418919fSjohnjiang const struct rte_compressdev_capabilities *capa;
20154418919fSjohnjiang
20164418919fSjohnjiang /* Compressing with CompressDev */
20174418919fSjohnjiang unsigned int zlib_compress =
20184418919fSjohnjiang (test_data->zlib_dir == ZLIB_ALL ||
20194418919fSjohnjiang test_data->zlib_dir == ZLIB_COMPRESS);
20204418919fSjohnjiang unsigned int zlib_decompress =
20214418919fSjohnjiang (test_data->zlib_dir == ZLIB_ALL ||
20224418919fSjohnjiang test_data->zlib_dir == ZLIB_DECOMPRESS);
20234418919fSjohnjiang
20244418919fSjohnjiang struct test_private_arrays test_priv_data;
20254418919fSjohnjiang
20264418919fSjohnjiang test_priv_data.uncomp_bufs = uncomp_bufs;
20274418919fSjohnjiang test_priv_data.comp_bufs = comp_bufs;
20284418919fSjohnjiang test_priv_data.ops = ops;
20294418919fSjohnjiang test_priv_data.ops_processed = ops_processed;
20304418919fSjohnjiang test_priv_data.priv_xforms = priv_xforms;
20314418919fSjohnjiang test_priv_data.compress_checksum = compress_checksum;
20324418919fSjohnjiang test_priv_data.compressed_data_size = compressed_data_size;
20334418919fSjohnjiang
20344418919fSjohnjiang test_priv_data.stream = &stream;
20354418919fSjohnjiang test_priv_data.all_decomp_data = &all_decomp_data;
20364418919fSjohnjiang test_priv_data.decomp_produced_data_size = &decomp_produced_data_size;
20374418919fSjohnjiang
20384418919fSjohnjiang test_priv_data.num_priv_xforms = 0; /* it's used for deompression only */
20394418919fSjohnjiang
20404418919fSjohnjiang capa = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
20414418919fSjohnjiang if (capa == NULL) {
20424418919fSjohnjiang RTE_LOG(ERR, USER1,
20434418919fSjohnjiang "Compress device does not support DEFLATE\n");
20444418919fSjohnjiang return -1;
20454418919fSjohnjiang }
20464418919fSjohnjiang
20474418919fSjohnjiang /* Prepare the source mbufs with the data */
20484418919fSjohnjiang ret = test_setup_com_bufs(int_data, test_data, &test_priv_data);
20494418919fSjohnjiang if (ret < 0) {
20504418919fSjohnjiang ret_status = -1;
20514418919fSjohnjiang goto exit;
20524418919fSjohnjiang }
20534418919fSjohnjiang
2054*2d9fd380Sjfb8856606 RTE_LOG(DEBUG, USER1, "<<< COMPRESSION >>>\n");
2055*2d9fd380Sjfb8856606
20564418919fSjohnjiang /* COMPRESSION */
20574418919fSjohnjiang
20584418919fSjohnjiang /* Prepare output (destination) mbufs for compressed data */
20594418919fSjohnjiang ret = test_setup_output_bufs(
20604418919fSjohnjiang OPERATION_COMPRESSION,
20614418919fSjohnjiang out_of_space == 1 && !zlib_compress,
20624418919fSjohnjiang &test_priv_data,
20634418919fSjohnjiang int_data,
20644418919fSjohnjiang test_data,
20654418919fSjohnjiang &compbuf_info);
20664418919fSjohnjiang if (ret < 0) {
20674418919fSjohnjiang ret_status = -1;
20684418919fSjohnjiang goto exit;
20694418919fSjohnjiang }
20704418919fSjohnjiang
20714418919fSjohnjiang /* Run compression */
20724418919fSjohnjiang ret = test_deflate_comp_run(int_data, test_data, &test_priv_data);
20734418919fSjohnjiang if (ret < 0) {
20744418919fSjohnjiang ret_status = -1;
20754418919fSjohnjiang goto exit;
20764418919fSjohnjiang }
20774418919fSjohnjiang
20784418919fSjohnjiang ret = test_deflate_comp_finalize(int_data, test_data, &test_priv_data);
20794418919fSjohnjiang if (ret < 0) {
20804418919fSjohnjiang ret_status = -1;
20814418919fSjohnjiang goto exit;
20824418919fSjohnjiang } else if (ret == 1) {
20834418919fSjohnjiang ret_status = 0;
20844418919fSjohnjiang goto exit;
20854418919fSjohnjiang } else if (ret == 2) {
20864418919fSjohnjiang ret_status = 1; /* some operation not supported */
20874418919fSjohnjiang goto exit;
20884418919fSjohnjiang }
20894418919fSjohnjiang
20904418919fSjohnjiang /* DECOMPRESSION */
20914418919fSjohnjiang
2092*2d9fd380Sjfb8856606 RTE_LOG(DEBUG, USER1, "<<< DECOMPRESSION >>>\n");
2093*2d9fd380Sjfb8856606
20944418919fSjohnjiang /* Prepare output (destination) mbufs for decompressed data */
20954418919fSjohnjiang ret = test_setup_output_bufs(
20964418919fSjohnjiang OPERATION_DECOMPRESSION,
20974418919fSjohnjiang out_of_space == 1 && !zlib_decompress,
20984418919fSjohnjiang &test_priv_data,
20994418919fSjohnjiang int_data,
21004418919fSjohnjiang test_data,
21014418919fSjohnjiang &decompbuf_info);
21024418919fSjohnjiang if (ret < 0) {
21034418919fSjohnjiang ret_status = -1;
21044418919fSjohnjiang goto exit;
21054418919fSjohnjiang }
21064418919fSjohnjiang
21074418919fSjohnjiang /* Run decompression */
21084418919fSjohnjiang ret = test_deflate_decomp_run(int_data, test_data, &test_priv_data);
21094418919fSjohnjiang if (ret < 0) {
21104418919fSjohnjiang ret_status = -1;
21114418919fSjohnjiang goto exit;
21124418919fSjohnjiang }
21134418919fSjohnjiang
21144418919fSjohnjiang if (!zlib_decompress) {
21154418919fSjohnjiang next_step: /* next step for stateful decompression only */
21164418919fSjohnjiang ret = test_run_enqueue_dequeue(ops, ops_processed, num_bufs);
21174418919fSjohnjiang if (ret < 0) {
21184418919fSjohnjiang ret_status = -1;
21194418919fSjohnjiang RTE_LOG(ERR, USER1,
21204418919fSjohnjiang "Decompression: enqueue/dequeue operation failed\n");
21214418919fSjohnjiang }
21224418919fSjohnjiang }
21234418919fSjohnjiang
21244418919fSjohnjiang ret = test_deflate_decomp_finalize(int_data, test_data, &test_priv_data);
21254418919fSjohnjiang if (ret < 0) {
21264418919fSjohnjiang ret_status = -1;
21274418919fSjohnjiang goto exit;
21284418919fSjohnjiang } else if (ret == 1) {
21294418919fSjohnjiang ret_status = 0;
21304418919fSjohnjiang goto exit;
21314418919fSjohnjiang } else if (ret == 2) {
21324418919fSjohnjiang goto next_step;
21334418919fSjohnjiang }
21344418919fSjohnjiang
21354418919fSjohnjiang /* FINAL PROCESSING */
21364418919fSjohnjiang
21374418919fSjohnjiang ret = test_results_validation(int_data, test_data, &test_priv_data);
21384418919fSjohnjiang if (ret < 0) {
21394418919fSjohnjiang ret_status = -1;
21404418919fSjohnjiang goto exit;
21414418919fSjohnjiang }
21424418919fSjohnjiang ret_status = 0;
21434418919fSjohnjiang
21444418919fSjohnjiang exit:
21454418919fSjohnjiang /* Free resources */
21464418919fSjohnjiang
21474418919fSjohnjiang if (stream != NULL)
21484418919fSjohnjiang rte_compressdev_stream_free(0, stream);
21494418919fSjohnjiang if (all_decomp_data != NULL)
21504418919fSjohnjiang rte_free(all_decomp_data);
21514418919fSjohnjiang
21524418919fSjohnjiang /* Free compress private xforms */
21534418919fSjohnjiang for (i = 0; i < test_priv_data.num_priv_xforms; i++) {
21544418919fSjohnjiang if (priv_xforms[i] != NULL) {
21554418919fSjohnjiang rte_compressdev_private_xform_free(0, priv_xforms[i]);
21564418919fSjohnjiang priv_xforms[i] = NULL;
21574418919fSjohnjiang }
21584418919fSjohnjiang }
21594418919fSjohnjiang for (i = 0; i < num_bufs; i++) {
21604418919fSjohnjiang rte_pktmbuf_free(uncomp_bufs[i]);
21614418919fSjohnjiang rte_pktmbuf_free(comp_bufs[i]);
21624418919fSjohnjiang rte_comp_op_free(ops[i]);
21634418919fSjohnjiang rte_comp_op_free(ops_processed[i]);
21644418919fSjohnjiang }
21654418919fSjohnjiang rte_free(contig_buf);
21664418919fSjohnjiang
21674418919fSjohnjiang return ret_status;
21684418919fSjohnjiang }
21694418919fSjohnjiang
21704418919fSjohnjiang static int
test_compressdev_deflate_stateless_fixed(void)21714418919fSjohnjiang test_compressdev_deflate_stateless_fixed(void)
21724418919fSjohnjiang {
21734418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
21744418919fSjohnjiang uint16_t i;
21754418919fSjohnjiang int ret;
21764418919fSjohnjiang const struct rte_compressdev_capabilities *capab;
21774418919fSjohnjiang
21784418919fSjohnjiang capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
21794418919fSjohnjiang TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
21804418919fSjohnjiang
21814418919fSjohnjiang if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0)
21824418919fSjohnjiang return -ENOTSUP;
21834418919fSjohnjiang
21844418919fSjohnjiang struct rte_comp_xform *compress_xform =
21854418919fSjohnjiang rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
21864418919fSjohnjiang
21874418919fSjohnjiang if (compress_xform == NULL) {
21884418919fSjohnjiang RTE_LOG(ERR, USER1,
21894418919fSjohnjiang "Compress xform could not be created\n");
21904418919fSjohnjiang ret = TEST_FAILED;
21914418919fSjohnjiang goto exit;
21924418919fSjohnjiang }
21934418919fSjohnjiang
21944418919fSjohnjiang memcpy(compress_xform, ts_params->def_comp_xform,
21954418919fSjohnjiang sizeof(struct rte_comp_xform));
21964418919fSjohnjiang compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
21974418919fSjohnjiang
21984418919fSjohnjiang struct interim_data_params int_data = {
21994418919fSjohnjiang NULL,
22004418919fSjohnjiang 1,
22014418919fSjohnjiang NULL,
22024418919fSjohnjiang &compress_xform,
22034418919fSjohnjiang &ts_params->def_decomp_xform,
22044418919fSjohnjiang 1
22054418919fSjohnjiang };
22064418919fSjohnjiang
22074418919fSjohnjiang struct test_data_params test_data = {
22084418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
22094418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATELESS,
22104418919fSjohnjiang .buff_type = LB_BOTH,
22114418919fSjohnjiang .zlib_dir = ZLIB_DECOMPRESS,
22124418919fSjohnjiang .out_of_space = 0,
22134418919fSjohnjiang .big_data = 0,
2214*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
2215*2d9fd380Sjfb8856606 .ratio = RATIO_ENABLED
22164418919fSjohnjiang };
22174418919fSjohnjiang
22184418919fSjohnjiang for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
22194418919fSjohnjiang int_data.test_bufs = &compress_test_bufs[i];
22204418919fSjohnjiang int_data.buf_idx = &i;
22214418919fSjohnjiang
22224418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
22234418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
22244418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
22254418919fSjohnjiang if (ret < 0)
22264418919fSjohnjiang goto exit;
22274418919fSjohnjiang
22284418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
22294418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
22304418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
22314418919fSjohnjiang if (ret < 0)
22324418919fSjohnjiang goto exit;
22334418919fSjohnjiang }
22344418919fSjohnjiang
22354418919fSjohnjiang ret = TEST_SUCCESS;
22364418919fSjohnjiang
22374418919fSjohnjiang exit:
22384418919fSjohnjiang rte_free(compress_xform);
22394418919fSjohnjiang return ret;
22404418919fSjohnjiang }
22414418919fSjohnjiang
22424418919fSjohnjiang static int
test_compressdev_deflate_stateless_dynamic(void)22434418919fSjohnjiang test_compressdev_deflate_stateless_dynamic(void)
22444418919fSjohnjiang {
22454418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
22464418919fSjohnjiang uint16_t i;
22474418919fSjohnjiang int ret;
22484418919fSjohnjiang struct rte_comp_xform *compress_xform =
22494418919fSjohnjiang rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
22504418919fSjohnjiang
22514418919fSjohnjiang const struct rte_compressdev_capabilities *capab;
22524418919fSjohnjiang
22534418919fSjohnjiang capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
22544418919fSjohnjiang TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
22554418919fSjohnjiang
22564418919fSjohnjiang if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
22574418919fSjohnjiang return -ENOTSUP;
22584418919fSjohnjiang
22594418919fSjohnjiang if (compress_xform == NULL) {
22604418919fSjohnjiang RTE_LOG(ERR, USER1,
22614418919fSjohnjiang "Compress xform could not be created\n");
22624418919fSjohnjiang ret = TEST_FAILED;
22634418919fSjohnjiang goto exit;
22644418919fSjohnjiang }
22654418919fSjohnjiang
22664418919fSjohnjiang memcpy(compress_xform, ts_params->def_comp_xform,
22674418919fSjohnjiang sizeof(struct rte_comp_xform));
22684418919fSjohnjiang compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_DYNAMIC;
22694418919fSjohnjiang
22704418919fSjohnjiang struct interim_data_params int_data = {
22714418919fSjohnjiang NULL,
22724418919fSjohnjiang 1,
22734418919fSjohnjiang NULL,
22744418919fSjohnjiang &compress_xform,
22754418919fSjohnjiang &ts_params->def_decomp_xform,
22764418919fSjohnjiang 1
22774418919fSjohnjiang };
22784418919fSjohnjiang
22794418919fSjohnjiang struct test_data_params test_data = {
22804418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
22814418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATELESS,
22824418919fSjohnjiang .buff_type = LB_BOTH,
22834418919fSjohnjiang .zlib_dir = ZLIB_DECOMPRESS,
22844418919fSjohnjiang .out_of_space = 0,
22854418919fSjohnjiang .big_data = 0,
2286*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
2287*2d9fd380Sjfb8856606 .ratio = RATIO_ENABLED
22884418919fSjohnjiang };
22894418919fSjohnjiang
22904418919fSjohnjiang for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
22914418919fSjohnjiang int_data.test_bufs = &compress_test_bufs[i];
22924418919fSjohnjiang int_data.buf_idx = &i;
22934418919fSjohnjiang
22944418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
22954418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
22964418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
22974418919fSjohnjiang if (ret < 0)
22984418919fSjohnjiang goto exit;
22994418919fSjohnjiang
23004418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
23014418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
23024418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
23034418919fSjohnjiang if (ret < 0)
23044418919fSjohnjiang goto exit;
23054418919fSjohnjiang }
23064418919fSjohnjiang
23074418919fSjohnjiang ret = TEST_SUCCESS;
23084418919fSjohnjiang
23094418919fSjohnjiang exit:
23104418919fSjohnjiang rte_free(compress_xform);
23114418919fSjohnjiang return ret;
23124418919fSjohnjiang }
23134418919fSjohnjiang
23144418919fSjohnjiang static int
test_compressdev_deflate_stateless_multi_op(void)23154418919fSjohnjiang test_compressdev_deflate_stateless_multi_op(void)
23164418919fSjohnjiang {
23174418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
23184418919fSjohnjiang uint16_t num_bufs = RTE_DIM(compress_test_bufs);
23194418919fSjohnjiang uint16_t buf_idx[num_bufs];
23204418919fSjohnjiang uint16_t i;
23214418919fSjohnjiang int ret;
23224418919fSjohnjiang
23234418919fSjohnjiang for (i = 0; i < num_bufs; i++)
23244418919fSjohnjiang buf_idx[i] = i;
23254418919fSjohnjiang
23264418919fSjohnjiang struct interim_data_params int_data = {
23274418919fSjohnjiang compress_test_bufs,
23284418919fSjohnjiang num_bufs,
23294418919fSjohnjiang buf_idx,
23304418919fSjohnjiang &ts_params->def_comp_xform,
23314418919fSjohnjiang &ts_params->def_decomp_xform,
23324418919fSjohnjiang 1
23334418919fSjohnjiang };
23344418919fSjohnjiang
23354418919fSjohnjiang struct test_data_params test_data = {
23364418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
23374418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATELESS,
23384418919fSjohnjiang .buff_type = LB_BOTH,
23394418919fSjohnjiang .zlib_dir = ZLIB_DECOMPRESS,
23404418919fSjohnjiang .out_of_space = 0,
23414418919fSjohnjiang .big_data = 0,
2342*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
2343*2d9fd380Sjfb8856606 .ratio = RATIO_ENABLED
23444418919fSjohnjiang };
23454418919fSjohnjiang
23464418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
23474418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
23484418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
23494418919fSjohnjiang if (ret < 0)
23504418919fSjohnjiang return ret;
23514418919fSjohnjiang
23524418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
23534418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
23544418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
23554418919fSjohnjiang if (ret < 0)
23564418919fSjohnjiang return ret;
23574418919fSjohnjiang
23584418919fSjohnjiang return TEST_SUCCESS;
23594418919fSjohnjiang }
23604418919fSjohnjiang
23614418919fSjohnjiang static int
test_compressdev_deflate_stateless_multi_level(void)23624418919fSjohnjiang test_compressdev_deflate_stateless_multi_level(void)
23634418919fSjohnjiang {
23644418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
23654418919fSjohnjiang unsigned int level;
23664418919fSjohnjiang uint16_t i;
23674418919fSjohnjiang int ret;
23684418919fSjohnjiang struct rte_comp_xform *compress_xform =
23694418919fSjohnjiang rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
23704418919fSjohnjiang
23714418919fSjohnjiang if (compress_xform == NULL) {
23724418919fSjohnjiang RTE_LOG(ERR, USER1,
23734418919fSjohnjiang "Compress xform could not be created\n");
23744418919fSjohnjiang ret = TEST_FAILED;
23754418919fSjohnjiang goto exit;
23764418919fSjohnjiang }
23774418919fSjohnjiang
23784418919fSjohnjiang memcpy(compress_xform, ts_params->def_comp_xform,
23794418919fSjohnjiang sizeof(struct rte_comp_xform));
23804418919fSjohnjiang
23814418919fSjohnjiang struct interim_data_params int_data = {
23824418919fSjohnjiang NULL,
23834418919fSjohnjiang 1,
23844418919fSjohnjiang NULL,
23854418919fSjohnjiang &compress_xform,
23864418919fSjohnjiang &ts_params->def_decomp_xform,
23874418919fSjohnjiang 1
23884418919fSjohnjiang };
23894418919fSjohnjiang
23904418919fSjohnjiang struct test_data_params test_data = {
23914418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
23924418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATELESS,
23934418919fSjohnjiang .buff_type = LB_BOTH,
23944418919fSjohnjiang .zlib_dir = ZLIB_DECOMPRESS,
23954418919fSjohnjiang .out_of_space = 0,
23964418919fSjohnjiang .big_data = 0,
2397*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
2398*2d9fd380Sjfb8856606 .ratio = RATIO_ENABLED
23994418919fSjohnjiang };
24004418919fSjohnjiang
24014418919fSjohnjiang for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
24024418919fSjohnjiang int_data.test_bufs = &compress_test_bufs[i];
24034418919fSjohnjiang int_data.buf_idx = &i;
24044418919fSjohnjiang
24054418919fSjohnjiang for (level = RTE_COMP_LEVEL_MIN; level <= RTE_COMP_LEVEL_MAX;
24064418919fSjohnjiang level++) {
24074418919fSjohnjiang compress_xform->compress.level = level;
24084418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
24094418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
24104418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
24114418919fSjohnjiang if (ret < 0)
24124418919fSjohnjiang goto exit;
24134418919fSjohnjiang }
24144418919fSjohnjiang }
24154418919fSjohnjiang
24164418919fSjohnjiang ret = TEST_SUCCESS;
24174418919fSjohnjiang
24184418919fSjohnjiang exit:
24194418919fSjohnjiang rte_free(compress_xform);
24204418919fSjohnjiang return ret;
24214418919fSjohnjiang }
24224418919fSjohnjiang
24234418919fSjohnjiang #define NUM_XFORMS 3
24244418919fSjohnjiang static int
test_compressdev_deflate_stateless_multi_xform(void)24254418919fSjohnjiang test_compressdev_deflate_stateless_multi_xform(void)
24264418919fSjohnjiang {
24274418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
24284418919fSjohnjiang uint16_t num_bufs = NUM_XFORMS;
24294418919fSjohnjiang struct rte_comp_xform *compress_xforms[NUM_XFORMS] = {NULL};
24304418919fSjohnjiang struct rte_comp_xform *decompress_xforms[NUM_XFORMS] = {NULL};
24314418919fSjohnjiang const char *test_buffers[NUM_XFORMS];
24324418919fSjohnjiang uint16_t i;
24334418919fSjohnjiang unsigned int level = RTE_COMP_LEVEL_MIN;
24344418919fSjohnjiang uint16_t buf_idx[num_bufs];
24354418919fSjohnjiang int ret;
24364418919fSjohnjiang
24374418919fSjohnjiang /* Create multiple xforms with various levels */
24384418919fSjohnjiang for (i = 0; i < NUM_XFORMS; i++) {
24394418919fSjohnjiang compress_xforms[i] = rte_malloc(NULL,
24404418919fSjohnjiang sizeof(struct rte_comp_xform), 0);
24414418919fSjohnjiang if (compress_xforms[i] == NULL) {
24424418919fSjohnjiang RTE_LOG(ERR, USER1,
24434418919fSjohnjiang "Compress xform could not be created\n");
24444418919fSjohnjiang ret = TEST_FAILED;
24454418919fSjohnjiang goto exit;
24464418919fSjohnjiang }
24474418919fSjohnjiang
24484418919fSjohnjiang memcpy(compress_xforms[i], ts_params->def_comp_xform,
24494418919fSjohnjiang sizeof(struct rte_comp_xform));
24504418919fSjohnjiang compress_xforms[i]->compress.level = level;
24514418919fSjohnjiang level++;
24524418919fSjohnjiang
24534418919fSjohnjiang decompress_xforms[i] = rte_malloc(NULL,
24544418919fSjohnjiang sizeof(struct rte_comp_xform), 0);
24554418919fSjohnjiang if (decompress_xforms[i] == NULL) {
24564418919fSjohnjiang RTE_LOG(ERR, USER1,
24574418919fSjohnjiang "Decompress xform could not be created\n");
24584418919fSjohnjiang ret = TEST_FAILED;
24594418919fSjohnjiang goto exit;
24604418919fSjohnjiang }
24614418919fSjohnjiang
24624418919fSjohnjiang memcpy(decompress_xforms[i], ts_params->def_decomp_xform,
24634418919fSjohnjiang sizeof(struct rte_comp_xform));
24644418919fSjohnjiang }
24654418919fSjohnjiang
24664418919fSjohnjiang for (i = 0; i < NUM_XFORMS; i++) {
24674418919fSjohnjiang buf_idx[i] = 0;
24684418919fSjohnjiang /* Use the same buffer in all sessions */
24694418919fSjohnjiang test_buffers[i] = compress_test_bufs[0];
24704418919fSjohnjiang }
24714418919fSjohnjiang
24724418919fSjohnjiang struct interim_data_params int_data = {
24734418919fSjohnjiang test_buffers,
24744418919fSjohnjiang num_bufs,
24754418919fSjohnjiang buf_idx,
24764418919fSjohnjiang compress_xforms,
24774418919fSjohnjiang decompress_xforms,
24784418919fSjohnjiang NUM_XFORMS
24794418919fSjohnjiang };
24804418919fSjohnjiang
24814418919fSjohnjiang struct test_data_params test_data = {
24824418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
24834418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATELESS,
24844418919fSjohnjiang .buff_type = LB_BOTH,
24854418919fSjohnjiang .zlib_dir = ZLIB_DECOMPRESS,
24864418919fSjohnjiang .out_of_space = 0,
24874418919fSjohnjiang .big_data = 0,
2488*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
2489*2d9fd380Sjfb8856606 .ratio = RATIO_ENABLED
24904418919fSjohnjiang };
24914418919fSjohnjiang
24924418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
24934418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
24944418919fSjohnjiang if (ret < 0)
24954418919fSjohnjiang goto exit;
24964418919fSjohnjiang
24974418919fSjohnjiang ret = TEST_SUCCESS;
24984418919fSjohnjiang
24994418919fSjohnjiang exit:
25004418919fSjohnjiang for (i = 0; i < NUM_XFORMS; i++) {
25014418919fSjohnjiang rte_free(compress_xforms[i]);
25024418919fSjohnjiang rte_free(decompress_xforms[i]);
25034418919fSjohnjiang }
25044418919fSjohnjiang
25054418919fSjohnjiang return ret;
25064418919fSjohnjiang }
25074418919fSjohnjiang
25084418919fSjohnjiang static int
test_compressdev_deflate_stateless_sgl(void)25094418919fSjohnjiang test_compressdev_deflate_stateless_sgl(void)
25104418919fSjohnjiang {
25114418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
25124418919fSjohnjiang uint16_t i;
25134418919fSjohnjiang int ret;
25144418919fSjohnjiang const struct rte_compressdev_capabilities *capab;
25154418919fSjohnjiang
25164418919fSjohnjiang capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
25174418919fSjohnjiang TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
25184418919fSjohnjiang
25194418919fSjohnjiang if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
25204418919fSjohnjiang return -ENOTSUP;
25214418919fSjohnjiang
25224418919fSjohnjiang struct interim_data_params int_data = {
25234418919fSjohnjiang NULL,
25244418919fSjohnjiang 1,
25254418919fSjohnjiang NULL,
25264418919fSjohnjiang &ts_params->def_comp_xform,
25274418919fSjohnjiang &ts_params->def_decomp_xform,
25284418919fSjohnjiang 1
25294418919fSjohnjiang };
25304418919fSjohnjiang
25314418919fSjohnjiang struct test_data_params test_data = {
25324418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
25334418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATELESS,
25344418919fSjohnjiang .buff_type = SGL_BOTH,
25354418919fSjohnjiang .zlib_dir = ZLIB_DECOMPRESS,
25364418919fSjohnjiang .out_of_space = 0,
25374418919fSjohnjiang .big_data = 0,
2538*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
2539*2d9fd380Sjfb8856606 .ratio = RATIO_ENABLED
25404418919fSjohnjiang };
25414418919fSjohnjiang
25424418919fSjohnjiang for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
25434418919fSjohnjiang int_data.test_bufs = &compress_test_bufs[i];
25444418919fSjohnjiang int_data.buf_idx = &i;
25454418919fSjohnjiang
25464418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
25474418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
25484418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
25494418919fSjohnjiang if (ret < 0)
25504418919fSjohnjiang return ret;
25514418919fSjohnjiang
25524418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
25534418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
25544418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
25554418919fSjohnjiang if (ret < 0)
25564418919fSjohnjiang return ret;
25574418919fSjohnjiang
25584418919fSjohnjiang if (capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_LB_OUT) {
25594418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
25604418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
25614418919fSjohnjiang test_data.buff_type = SGL_TO_LB;
25624418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
25634418919fSjohnjiang if (ret < 0)
25644418919fSjohnjiang return ret;
25654418919fSjohnjiang
25664418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
25674418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
25684418919fSjohnjiang test_data.buff_type = SGL_TO_LB;
25694418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
25704418919fSjohnjiang if (ret < 0)
25714418919fSjohnjiang return ret;
25724418919fSjohnjiang }
25734418919fSjohnjiang
25744418919fSjohnjiang if (capab->comp_feature_flags & RTE_COMP_FF_OOP_LB_IN_SGL_OUT) {
25754418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
25764418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
25774418919fSjohnjiang test_data.buff_type = LB_TO_SGL;
25784418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
25794418919fSjohnjiang if (ret < 0)
25804418919fSjohnjiang return ret;
25814418919fSjohnjiang
25824418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
25834418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
25844418919fSjohnjiang test_data.buff_type = LB_TO_SGL;
25854418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
25864418919fSjohnjiang if (ret < 0)
25874418919fSjohnjiang return ret;
25884418919fSjohnjiang }
25894418919fSjohnjiang }
25904418919fSjohnjiang
25914418919fSjohnjiang return TEST_SUCCESS;
25924418919fSjohnjiang }
25934418919fSjohnjiang
25944418919fSjohnjiang static int
test_compressdev_deflate_stateless_checksum(void)25954418919fSjohnjiang test_compressdev_deflate_stateless_checksum(void)
25964418919fSjohnjiang {
25974418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
25984418919fSjohnjiang uint16_t i;
25994418919fSjohnjiang int ret;
26004418919fSjohnjiang const struct rte_compressdev_capabilities *capab;
26014418919fSjohnjiang
26024418919fSjohnjiang capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
26034418919fSjohnjiang TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
26044418919fSjohnjiang
26054418919fSjohnjiang /* Check if driver supports any checksum */
26064418919fSjohnjiang if ((capab->comp_feature_flags & RTE_COMP_FF_CRC32_CHECKSUM) == 0 &&
26074418919fSjohnjiang (capab->comp_feature_flags &
26084418919fSjohnjiang RTE_COMP_FF_ADLER32_CHECKSUM) == 0 &&
26094418919fSjohnjiang (capab->comp_feature_flags &
26104418919fSjohnjiang RTE_COMP_FF_CRC32_ADLER32_CHECKSUM) == 0)
26114418919fSjohnjiang return -ENOTSUP;
26124418919fSjohnjiang
26134418919fSjohnjiang struct rte_comp_xform *compress_xform =
26144418919fSjohnjiang rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
26154418919fSjohnjiang if (compress_xform == NULL) {
26164418919fSjohnjiang RTE_LOG(ERR, USER1, "Compress xform could not be created\n");
26174418919fSjohnjiang return TEST_FAILED;
26184418919fSjohnjiang }
26194418919fSjohnjiang
26204418919fSjohnjiang memcpy(compress_xform, ts_params->def_comp_xform,
26214418919fSjohnjiang sizeof(struct rte_comp_xform));
26224418919fSjohnjiang
26234418919fSjohnjiang struct rte_comp_xform *decompress_xform =
26244418919fSjohnjiang rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
26254418919fSjohnjiang if (decompress_xform == NULL) {
26264418919fSjohnjiang RTE_LOG(ERR, USER1, "Decompress xform could not be created\n");
26274418919fSjohnjiang rte_free(compress_xform);
26284418919fSjohnjiang return TEST_FAILED;
26294418919fSjohnjiang }
26304418919fSjohnjiang
26314418919fSjohnjiang memcpy(decompress_xform, ts_params->def_decomp_xform,
26324418919fSjohnjiang sizeof(struct rte_comp_xform));
26334418919fSjohnjiang
26344418919fSjohnjiang struct interim_data_params int_data = {
26354418919fSjohnjiang NULL,
26364418919fSjohnjiang 1,
26374418919fSjohnjiang NULL,
26384418919fSjohnjiang &compress_xform,
26394418919fSjohnjiang &decompress_xform,
26404418919fSjohnjiang 1
26414418919fSjohnjiang };
26424418919fSjohnjiang
26434418919fSjohnjiang struct test_data_params test_data = {
26444418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
26454418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATELESS,
26464418919fSjohnjiang .buff_type = LB_BOTH,
26474418919fSjohnjiang .zlib_dir = ZLIB_DECOMPRESS,
26484418919fSjohnjiang .out_of_space = 0,
26494418919fSjohnjiang .big_data = 0,
2650*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
2651*2d9fd380Sjfb8856606 .ratio = RATIO_ENABLED
26524418919fSjohnjiang };
26534418919fSjohnjiang
26544418919fSjohnjiang /* Check if driver supports crc32 checksum and test */
26554418919fSjohnjiang if ((capab->comp_feature_flags & RTE_COMP_FF_CRC32_CHECKSUM)) {
26564418919fSjohnjiang compress_xform->compress.chksum = RTE_COMP_CHECKSUM_CRC32;
26574418919fSjohnjiang decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_CRC32;
26584418919fSjohnjiang
26594418919fSjohnjiang for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
26604418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
26614418919fSjohnjiang int_data.test_bufs = &compress_test_bufs[i];
26624418919fSjohnjiang int_data.buf_idx = &i;
26634418919fSjohnjiang
26644418919fSjohnjiang /* Generate zlib checksum and test against selected
26654418919fSjohnjiang * drivers decompression checksum
26664418919fSjohnjiang */
26674418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
26684418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
26694418919fSjohnjiang if (ret < 0)
26704418919fSjohnjiang goto exit;
26714418919fSjohnjiang
26724418919fSjohnjiang /* Generate compression and decompression
26734418919fSjohnjiang * checksum of selected driver
26744418919fSjohnjiang */
26754418919fSjohnjiang test_data.zlib_dir = ZLIB_NONE;
26764418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
26774418919fSjohnjiang if (ret < 0)
26784418919fSjohnjiang goto exit;
26794418919fSjohnjiang }
26804418919fSjohnjiang }
26814418919fSjohnjiang
26824418919fSjohnjiang /* Check if driver supports adler32 checksum and test */
26834418919fSjohnjiang if ((capab->comp_feature_flags & RTE_COMP_FF_ADLER32_CHECKSUM)) {
26844418919fSjohnjiang compress_xform->compress.chksum = RTE_COMP_CHECKSUM_ADLER32;
26854418919fSjohnjiang decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_ADLER32;
26864418919fSjohnjiang
26874418919fSjohnjiang for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
26884418919fSjohnjiang int_data.test_bufs = &compress_test_bufs[i];
26894418919fSjohnjiang int_data.buf_idx = &i;
26904418919fSjohnjiang
26914418919fSjohnjiang /* Generate zlib checksum and test against selected
26924418919fSjohnjiang * drivers decompression checksum
26934418919fSjohnjiang */
26944418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
26954418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
26964418919fSjohnjiang if (ret < 0)
26974418919fSjohnjiang goto exit;
26984418919fSjohnjiang /* Generate compression and decompression
26994418919fSjohnjiang * checksum of selected driver
27004418919fSjohnjiang */
27014418919fSjohnjiang test_data.zlib_dir = ZLIB_NONE;
27024418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
27034418919fSjohnjiang if (ret < 0)
27044418919fSjohnjiang goto exit;
27054418919fSjohnjiang }
27064418919fSjohnjiang }
27074418919fSjohnjiang
27084418919fSjohnjiang /* Check if driver supports combined crc and adler checksum and test */
27094418919fSjohnjiang if ((capab->comp_feature_flags & RTE_COMP_FF_CRC32_ADLER32_CHECKSUM)) {
27104418919fSjohnjiang compress_xform->compress.chksum =
27114418919fSjohnjiang RTE_COMP_CHECKSUM_CRC32_ADLER32;
27124418919fSjohnjiang decompress_xform->decompress.chksum =
27134418919fSjohnjiang RTE_COMP_CHECKSUM_CRC32_ADLER32;
27144418919fSjohnjiang
27154418919fSjohnjiang for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
27164418919fSjohnjiang int_data.test_bufs = &compress_test_bufs[i];
27174418919fSjohnjiang int_data.buf_idx = &i;
27184418919fSjohnjiang
27194418919fSjohnjiang /* Generate compression and decompression
27204418919fSjohnjiang * checksum of selected driver
27214418919fSjohnjiang */
27224418919fSjohnjiang test_data.zlib_dir = ZLIB_NONE;
27234418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
27244418919fSjohnjiang if (ret < 0)
27254418919fSjohnjiang goto exit;
27264418919fSjohnjiang }
27274418919fSjohnjiang }
27284418919fSjohnjiang
27294418919fSjohnjiang ret = TEST_SUCCESS;
27304418919fSjohnjiang
27314418919fSjohnjiang exit:
27324418919fSjohnjiang rte_free(compress_xform);
27334418919fSjohnjiang rte_free(decompress_xform);
27344418919fSjohnjiang return ret;
27354418919fSjohnjiang }
27364418919fSjohnjiang
27374418919fSjohnjiang static int
test_compressdev_out_of_space_buffer(void)27384418919fSjohnjiang test_compressdev_out_of_space_buffer(void)
27394418919fSjohnjiang {
27404418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
27414418919fSjohnjiang int ret;
27424418919fSjohnjiang uint16_t i;
27434418919fSjohnjiang const struct rte_compressdev_capabilities *capab;
27444418919fSjohnjiang
27454418919fSjohnjiang RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
27464418919fSjohnjiang
27474418919fSjohnjiang capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
27484418919fSjohnjiang TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
27494418919fSjohnjiang
27504418919fSjohnjiang if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0)
27514418919fSjohnjiang return -ENOTSUP;
27524418919fSjohnjiang
27534418919fSjohnjiang struct interim_data_params int_data = {
27544418919fSjohnjiang &compress_test_bufs[0],
27554418919fSjohnjiang 1,
27564418919fSjohnjiang &i,
27574418919fSjohnjiang &ts_params->def_comp_xform,
27584418919fSjohnjiang &ts_params->def_decomp_xform,
27594418919fSjohnjiang 1
27604418919fSjohnjiang };
27614418919fSjohnjiang
27624418919fSjohnjiang struct test_data_params test_data = {
27634418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
27644418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATELESS,
27654418919fSjohnjiang .buff_type = LB_BOTH,
27664418919fSjohnjiang .zlib_dir = ZLIB_DECOMPRESS,
27674418919fSjohnjiang .out_of_space = 1, /* run out-of-space test */
27684418919fSjohnjiang .big_data = 0,
2769*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
2770*2d9fd380Sjfb8856606 .ratio = RATIO_ENABLED
27714418919fSjohnjiang };
27724418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
27734418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
27744418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
27754418919fSjohnjiang if (ret < 0)
27764418919fSjohnjiang goto exit;
27774418919fSjohnjiang
27784418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
27794418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
27804418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
27814418919fSjohnjiang if (ret < 0)
27824418919fSjohnjiang goto exit;
27834418919fSjohnjiang
27844418919fSjohnjiang if (capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
27854418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
27864418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
27874418919fSjohnjiang test_data.buff_type = SGL_BOTH;
27884418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
27894418919fSjohnjiang if (ret < 0)
27904418919fSjohnjiang goto exit;
27914418919fSjohnjiang
27924418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
27934418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
27944418919fSjohnjiang test_data.buff_type = SGL_BOTH;
27954418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
27964418919fSjohnjiang if (ret < 0)
27974418919fSjohnjiang goto exit;
27984418919fSjohnjiang }
27994418919fSjohnjiang
28004418919fSjohnjiang ret = TEST_SUCCESS;
28014418919fSjohnjiang
28024418919fSjohnjiang exit:
28034418919fSjohnjiang return ret;
28044418919fSjohnjiang }
28054418919fSjohnjiang
28064418919fSjohnjiang static int
test_compressdev_deflate_stateless_dynamic_big(void)28074418919fSjohnjiang test_compressdev_deflate_stateless_dynamic_big(void)
28084418919fSjohnjiang {
28094418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
28104418919fSjohnjiang uint16_t i = 0;
28114418919fSjohnjiang int ret;
2812*2d9fd380Sjfb8856606 unsigned int j;
28134418919fSjohnjiang const struct rte_compressdev_capabilities *capab;
28144418919fSjohnjiang char *test_buffer = NULL;
28154418919fSjohnjiang
28164418919fSjohnjiang capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
28174418919fSjohnjiang TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
28184418919fSjohnjiang
28194418919fSjohnjiang if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
28204418919fSjohnjiang return -ENOTSUP;
28214418919fSjohnjiang
28224418919fSjohnjiang if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
28234418919fSjohnjiang return -ENOTSUP;
28244418919fSjohnjiang
28254418919fSjohnjiang test_buffer = rte_malloc(NULL, BIG_DATA_TEST_SIZE, 0);
28264418919fSjohnjiang if (test_buffer == NULL) {
28274418919fSjohnjiang RTE_LOG(ERR, USER1,
28284418919fSjohnjiang "Can't allocate buffer for big-data\n");
28294418919fSjohnjiang return TEST_FAILED;
28304418919fSjohnjiang }
28314418919fSjohnjiang
28324418919fSjohnjiang struct interim_data_params int_data = {
28334418919fSjohnjiang (const char * const *)&test_buffer,
28344418919fSjohnjiang 1,
28354418919fSjohnjiang &i,
28364418919fSjohnjiang &ts_params->def_comp_xform,
28374418919fSjohnjiang &ts_params->def_decomp_xform,
28384418919fSjohnjiang 1
28394418919fSjohnjiang };
28404418919fSjohnjiang
28414418919fSjohnjiang struct test_data_params test_data = {
28424418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
28434418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATELESS,
28444418919fSjohnjiang .buff_type = SGL_BOTH,
28454418919fSjohnjiang .zlib_dir = ZLIB_DECOMPRESS,
28464418919fSjohnjiang .out_of_space = 0,
28474418919fSjohnjiang .big_data = 1,
2848*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
2849*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
28504418919fSjohnjiang };
28514418919fSjohnjiang
28524418919fSjohnjiang ts_params->def_comp_xform->compress.deflate.huffman =
28534418919fSjohnjiang RTE_COMP_HUFFMAN_DYNAMIC;
28544418919fSjohnjiang
28554418919fSjohnjiang /* fill the buffer with data based on rand. data */
28564418919fSjohnjiang srand(BIG_DATA_TEST_SIZE);
28574418919fSjohnjiang for (j = 0; j < BIG_DATA_TEST_SIZE - 1; ++j)
28584418919fSjohnjiang test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
28594418919fSjohnjiang test_buffer[BIG_DATA_TEST_SIZE - 1] = 0;
28604418919fSjohnjiang
28614418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
28624418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
28634418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
28644418919fSjohnjiang if (ret < 0)
28654418919fSjohnjiang goto exit;
28664418919fSjohnjiang
28674418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
28684418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
28694418919fSjohnjiang ret = test_deflate_comp_decomp(&int_data, &test_data);
28704418919fSjohnjiang if (ret < 0)
28714418919fSjohnjiang goto exit;
28724418919fSjohnjiang
28734418919fSjohnjiang ret = TEST_SUCCESS;
28744418919fSjohnjiang
28754418919fSjohnjiang exit:
28764418919fSjohnjiang ts_params->def_comp_xform->compress.deflate.huffman =
28774418919fSjohnjiang RTE_COMP_HUFFMAN_DEFAULT;
28784418919fSjohnjiang rte_free(test_buffer);
28794418919fSjohnjiang return ret;
28804418919fSjohnjiang }
28814418919fSjohnjiang
28824418919fSjohnjiang static int
test_compressdev_deflate_stateful_decomp(void)28834418919fSjohnjiang test_compressdev_deflate_stateful_decomp(void)
28844418919fSjohnjiang {
28854418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
28864418919fSjohnjiang int ret;
28874418919fSjohnjiang uint16_t i;
28884418919fSjohnjiang const struct rte_compressdev_capabilities *capab;
28894418919fSjohnjiang
28904418919fSjohnjiang capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
28914418919fSjohnjiang TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
28924418919fSjohnjiang
28934418919fSjohnjiang if (!(capab->comp_feature_flags & RTE_COMP_FF_STATEFUL_DECOMPRESSION))
28944418919fSjohnjiang return -ENOTSUP;
28954418919fSjohnjiang
28964418919fSjohnjiang struct interim_data_params int_data = {
28974418919fSjohnjiang &compress_test_bufs[0],
28984418919fSjohnjiang 1,
28994418919fSjohnjiang &i,
29004418919fSjohnjiang &ts_params->def_comp_xform,
29014418919fSjohnjiang &ts_params->def_decomp_xform,
29024418919fSjohnjiang 1
29034418919fSjohnjiang };
29044418919fSjohnjiang
29054418919fSjohnjiang struct test_data_params test_data = {
29064418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
29074418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATEFUL,
29084418919fSjohnjiang .buff_type = LB_BOTH,
29094418919fSjohnjiang .zlib_dir = ZLIB_COMPRESS,
29104418919fSjohnjiang .out_of_space = 0,
29114418919fSjohnjiang .big_data = 0,
29124418919fSjohnjiang .decompress_output_block_size = 2000,
29134418919fSjohnjiang .decompress_steps_max = 4,
2914*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
2915*2d9fd380Sjfb8856606 .ratio = RATIO_ENABLED
29164418919fSjohnjiang };
29174418919fSjohnjiang
29184418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
29194418919fSjohnjiang if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
29204418919fSjohnjiang ret = TEST_FAILED;
29214418919fSjohnjiang goto exit;
29224418919fSjohnjiang }
29234418919fSjohnjiang
29244418919fSjohnjiang if (capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
29254418919fSjohnjiang /* Now test with SGL buffers */
29264418919fSjohnjiang test_data.buff_type = SGL_BOTH;
29274418919fSjohnjiang if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
29284418919fSjohnjiang ret = TEST_FAILED;
29294418919fSjohnjiang goto exit;
29304418919fSjohnjiang }
29314418919fSjohnjiang }
29324418919fSjohnjiang
29334418919fSjohnjiang ret = TEST_SUCCESS;
29344418919fSjohnjiang
29354418919fSjohnjiang exit:
29364418919fSjohnjiang return ret;
29374418919fSjohnjiang }
29384418919fSjohnjiang
29394418919fSjohnjiang static int
test_compressdev_deflate_stateful_decomp_checksum(void)29404418919fSjohnjiang test_compressdev_deflate_stateful_decomp_checksum(void)
29414418919fSjohnjiang {
29424418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
29434418919fSjohnjiang int ret;
29444418919fSjohnjiang uint16_t i;
29454418919fSjohnjiang const struct rte_compressdev_capabilities *capab;
29464418919fSjohnjiang
29474418919fSjohnjiang capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
29484418919fSjohnjiang TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
29494418919fSjohnjiang
29504418919fSjohnjiang if (!(capab->comp_feature_flags & RTE_COMP_FF_STATEFUL_DECOMPRESSION))
29514418919fSjohnjiang return -ENOTSUP;
29524418919fSjohnjiang
29534418919fSjohnjiang /* Check if driver supports any checksum */
29544418919fSjohnjiang if (!(capab->comp_feature_flags &
29554418919fSjohnjiang (RTE_COMP_FF_CRC32_CHECKSUM | RTE_COMP_FF_ADLER32_CHECKSUM |
29564418919fSjohnjiang RTE_COMP_FF_CRC32_ADLER32_CHECKSUM)))
29574418919fSjohnjiang return -ENOTSUP;
29584418919fSjohnjiang
29594418919fSjohnjiang struct rte_comp_xform *compress_xform =
29604418919fSjohnjiang rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
29614418919fSjohnjiang if (compress_xform == NULL) {
29624418919fSjohnjiang RTE_LOG(ERR, USER1, "Compress xform could not be created\n");
29634418919fSjohnjiang return TEST_FAILED;
29644418919fSjohnjiang }
29654418919fSjohnjiang
29664418919fSjohnjiang memcpy(compress_xform, ts_params->def_comp_xform,
29674418919fSjohnjiang sizeof(struct rte_comp_xform));
29684418919fSjohnjiang
29694418919fSjohnjiang struct rte_comp_xform *decompress_xform =
29704418919fSjohnjiang rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
29714418919fSjohnjiang if (decompress_xform == NULL) {
29724418919fSjohnjiang RTE_LOG(ERR, USER1, "Decompress xform could not be created\n");
29734418919fSjohnjiang rte_free(compress_xform);
29744418919fSjohnjiang return TEST_FAILED;
29754418919fSjohnjiang }
29764418919fSjohnjiang
29774418919fSjohnjiang memcpy(decompress_xform, ts_params->def_decomp_xform,
29784418919fSjohnjiang sizeof(struct rte_comp_xform));
29794418919fSjohnjiang
29804418919fSjohnjiang struct interim_data_params int_data = {
29814418919fSjohnjiang &compress_test_bufs[0],
29824418919fSjohnjiang 1,
29834418919fSjohnjiang &i,
29844418919fSjohnjiang &compress_xform,
29854418919fSjohnjiang &decompress_xform,
29864418919fSjohnjiang 1
29874418919fSjohnjiang };
29884418919fSjohnjiang
29894418919fSjohnjiang struct test_data_params test_data = {
29904418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
29914418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATEFUL,
29924418919fSjohnjiang .buff_type = LB_BOTH,
29934418919fSjohnjiang .zlib_dir = ZLIB_COMPRESS,
29944418919fSjohnjiang .out_of_space = 0,
29954418919fSjohnjiang .big_data = 0,
29964418919fSjohnjiang .decompress_output_block_size = 2000,
29974418919fSjohnjiang .decompress_steps_max = 4,
2998*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
2999*2d9fd380Sjfb8856606 .ratio = RATIO_ENABLED
30004418919fSjohnjiang };
30014418919fSjohnjiang
30024418919fSjohnjiang /* Check if driver supports crc32 checksum and test */
30034418919fSjohnjiang if (capab->comp_feature_flags & RTE_COMP_FF_CRC32_CHECKSUM) {
30044418919fSjohnjiang compress_xform->compress.chksum = RTE_COMP_CHECKSUM_CRC32;
30054418919fSjohnjiang decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_CRC32;
30064418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
30074418919fSjohnjiang test_data.buff_type = LB_BOTH;
30084418919fSjohnjiang if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
30094418919fSjohnjiang ret = TEST_FAILED;
30104418919fSjohnjiang goto exit;
30114418919fSjohnjiang }
30124418919fSjohnjiang if (capab->comp_feature_flags &
30134418919fSjohnjiang RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
30144418919fSjohnjiang /* Now test with SGL buffers */
30154418919fSjohnjiang test_data.buff_type = SGL_BOTH;
30164418919fSjohnjiang if (test_deflate_comp_decomp(&int_data,
30174418919fSjohnjiang &test_data) < 0) {
30184418919fSjohnjiang ret = TEST_FAILED;
30194418919fSjohnjiang goto exit;
30204418919fSjohnjiang }
30214418919fSjohnjiang }
30224418919fSjohnjiang }
30234418919fSjohnjiang
30244418919fSjohnjiang /* Check if driver supports adler32 checksum and test */
30254418919fSjohnjiang if (capab->comp_feature_flags & RTE_COMP_FF_ADLER32_CHECKSUM) {
30264418919fSjohnjiang compress_xform->compress.chksum = RTE_COMP_CHECKSUM_ADLER32;
30274418919fSjohnjiang decompress_xform->decompress.chksum = RTE_COMP_CHECKSUM_ADLER32;
30284418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
30294418919fSjohnjiang test_data.buff_type = LB_BOTH;
30304418919fSjohnjiang if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
30314418919fSjohnjiang ret = TEST_FAILED;
30324418919fSjohnjiang goto exit;
30334418919fSjohnjiang }
30344418919fSjohnjiang if (capab->comp_feature_flags &
30354418919fSjohnjiang RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
30364418919fSjohnjiang /* Now test with SGL buffers */
30374418919fSjohnjiang test_data.buff_type = SGL_BOTH;
30384418919fSjohnjiang if (test_deflate_comp_decomp(&int_data,
30394418919fSjohnjiang &test_data) < 0) {
30404418919fSjohnjiang ret = TEST_FAILED;
30414418919fSjohnjiang goto exit;
30424418919fSjohnjiang }
30434418919fSjohnjiang }
30444418919fSjohnjiang }
30454418919fSjohnjiang
30464418919fSjohnjiang /* Check if driver supports combined crc and adler checksum and test */
30474418919fSjohnjiang if (capab->comp_feature_flags & RTE_COMP_FF_CRC32_ADLER32_CHECKSUM) {
30484418919fSjohnjiang compress_xform->compress.chksum =
30494418919fSjohnjiang RTE_COMP_CHECKSUM_CRC32_ADLER32;
30504418919fSjohnjiang decompress_xform->decompress.chksum =
30514418919fSjohnjiang RTE_COMP_CHECKSUM_CRC32_ADLER32;
30524418919fSjohnjiang /* Zlib doesn't support combined checksum */
30534418919fSjohnjiang test_data.zlib_dir = ZLIB_NONE;
30544418919fSjohnjiang /* Compress stateless, decompress stateful with compressdev */
30554418919fSjohnjiang test_data.buff_type = LB_BOTH;
30564418919fSjohnjiang if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
30574418919fSjohnjiang ret = TEST_FAILED;
30584418919fSjohnjiang goto exit;
30594418919fSjohnjiang }
30604418919fSjohnjiang if (capab->comp_feature_flags &
30614418919fSjohnjiang RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) {
30624418919fSjohnjiang /* Now test with SGL buffers */
30634418919fSjohnjiang test_data.buff_type = SGL_BOTH;
30644418919fSjohnjiang if (test_deflate_comp_decomp(&int_data,
30654418919fSjohnjiang &test_data) < 0) {
30664418919fSjohnjiang ret = TEST_FAILED;
30674418919fSjohnjiang goto exit;
30684418919fSjohnjiang }
30694418919fSjohnjiang }
30704418919fSjohnjiang }
30714418919fSjohnjiang
30724418919fSjohnjiang ret = TEST_SUCCESS;
30734418919fSjohnjiang
30744418919fSjohnjiang exit:
30754418919fSjohnjiang rte_free(compress_xform);
30764418919fSjohnjiang rte_free(decompress_xform);
30774418919fSjohnjiang return ret;
30784418919fSjohnjiang }
30794418919fSjohnjiang
30804418919fSjohnjiang static const struct rte_memzone *
make_memzone(const char * name,size_t size)30814418919fSjohnjiang make_memzone(const char *name, size_t size)
30824418919fSjohnjiang {
30834418919fSjohnjiang unsigned int socket_id = rte_socket_id();
30844418919fSjohnjiang char mz_name[RTE_MEMZONE_NAMESIZE];
30854418919fSjohnjiang const struct rte_memzone *memzone;
30864418919fSjohnjiang
30874418919fSjohnjiang snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "%s_%u", name, socket_id);
30884418919fSjohnjiang memzone = rte_memzone_lookup(mz_name);
30894418919fSjohnjiang if (memzone != NULL && memzone->len != size) {
30904418919fSjohnjiang rte_memzone_free(memzone);
30914418919fSjohnjiang memzone = NULL;
30924418919fSjohnjiang }
30934418919fSjohnjiang if (memzone == NULL) {
30944418919fSjohnjiang memzone = rte_memzone_reserve_aligned(mz_name, size, socket_id,
30954418919fSjohnjiang RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE);
30964418919fSjohnjiang if (memzone == NULL)
30974418919fSjohnjiang RTE_LOG(ERR, USER1, "Can't allocate memory zone %s",
30984418919fSjohnjiang mz_name);
30994418919fSjohnjiang }
31004418919fSjohnjiang return memzone;
31014418919fSjohnjiang }
31024418919fSjohnjiang
31034418919fSjohnjiang static int
test_compressdev_external_mbufs(void)31044418919fSjohnjiang test_compressdev_external_mbufs(void)
31054418919fSjohnjiang {
31064418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
31074418919fSjohnjiang size_t data_len = 0;
31084418919fSjohnjiang uint16_t i;
31094418919fSjohnjiang int ret = TEST_FAILED;
31104418919fSjohnjiang
31114418919fSjohnjiang for (i = 0; i < RTE_DIM(compress_test_bufs); i++)
31124418919fSjohnjiang data_len = RTE_MAX(data_len, strlen(compress_test_bufs[i]) + 1);
31134418919fSjohnjiang
31144418919fSjohnjiang struct interim_data_params int_data = {
31154418919fSjohnjiang NULL,
31164418919fSjohnjiang 1,
31174418919fSjohnjiang NULL,
31184418919fSjohnjiang &ts_params->def_comp_xform,
31194418919fSjohnjiang &ts_params->def_decomp_xform,
31204418919fSjohnjiang 1
31214418919fSjohnjiang };
31224418919fSjohnjiang
31234418919fSjohnjiang struct test_data_params test_data = {
31244418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
31254418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATELESS,
31264418919fSjohnjiang .buff_type = LB_BOTH,
31274418919fSjohnjiang .zlib_dir = ZLIB_DECOMPRESS,
31284418919fSjohnjiang .out_of_space = 0,
31294418919fSjohnjiang .big_data = 0,
31304418919fSjohnjiang .use_external_mbufs = 1,
31314418919fSjohnjiang .inbuf_data_size = data_len,
31324418919fSjohnjiang .inbuf_memzone = make_memzone("inbuf", data_len),
31334418919fSjohnjiang .compbuf_memzone = make_memzone("compbuf", data_len *
31344418919fSjohnjiang COMPRESS_BUF_SIZE_RATIO),
31354418919fSjohnjiang .uncompbuf_memzone = make_memzone("decompbuf", data_len),
31364418919fSjohnjiang .overflow = OVERFLOW_DISABLED
31374418919fSjohnjiang };
31384418919fSjohnjiang
31394418919fSjohnjiang for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
31404418919fSjohnjiang /* prepare input data */
31414418919fSjohnjiang data_len = strlen(compress_test_bufs[i]) + 1;
31424418919fSjohnjiang rte_memcpy(test_data.inbuf_memzone->addr, compress_test_bufs[i],
31434418919fSjohnjiang data_len);
31444418919fSjohnjiang test_data.inbuf_data_size = data_len;
31454418919fSjohnjiang int_data.buf_idx = &i;
31464418919fSjohnjiang
31474418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
31484418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
31494418919fSjohnjiang if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
31504418919fSjohnjiang goto exit;
31514418919fSjohnjiang
31524418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
31534418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
31544418919fSjohnjiang if (test_deflate_comp_decomp(&int_data, &test_data) < 0)
31554418919fSjohnjiang goto exit;
31564418919fSjohnjiang }
31574418919fSjohnjiang
31584418919fSjohnjiang ret = TEST_SUCCESS;
31594418919fSjohnjiang
31604418919fSjohnjiang exit:
31614418919fSjohnjiang rte_memzone_free(test_data.inbuf_memzone);
31624418919fSjohnjiang rte_memzone_free(test_data.compbuf_memzone);
31634418919fSjohnjiang rte_memzone_free(test_data.uncompbuf_memzone);
31644418919fSjohnjiang return ret;
31654418919fSjohnjiang }
31664418919fSjohnjiang
31674418919fSjohnjiang static int
test_compressdev_deflate_stateless_fixed_oos_recoverable(void)31684418919fSjohnjiang test_compressdev_deflate_stateless_fixed_oos_recoverable(void)
31694418919fSjohnjiang {
31704418919fSjohnjiang struct comp_testsuite_params *ts_params = &testsuite_params;
31714418919fSjohnjiang uint16_t i;
31724418919fSjohnjiang int ret;
31734418919fSjohnjiang int comp_result;
31744418919fSjohnjiang const struct rte_compressdev_capabilities *capab;
31754418919fSjohnjiang
31764418919fSjohnjiang capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
31774418919fSjohnjiang TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
31784418919fSjohnjiang
31794418919fSjohnjiang if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_FIXED) == 0)
31804418919fSjohnjiang return -ENOTSUP;
31814418919fSjohnjiang
31824418919fSjohnjiang struct rte_comp_xform *compress_xform =
31834418919fSjohnjiang rte_malloc(NULL, sizeof(struct rte_comp_xform), 0);
31844418919fSjohnjiang
31854418919fSjohnjiang if (compress_xform == NULL) {
31864418919fSjohnjiang RTE_LOG(ERR, USER1,
31874418919fSjohnjiang "Compress xform could not be created\n");
31884418919fSjohnjiang ret = TEST_FAILED;
31894418919fSjohnjiang goto exit;
31904418919fSjohnjiang }
31914418919fSjohnjiang
31924418919fSjohnjiang memcpy(compress_xform, ts_params->def_comp_xform,
31934418919fSjohnjiang sizeof(struct rte_comp_xform));
31944418919fSjohnjiang compress_xform->compress.deflate.huffman = RTE_COMP_HUFFMAN_FIXED;
31954418919fSjohnjiang
31964418919fSjohnjiang struct interim_data_params int_data = {
31974418919fSjohnjiang NULL,
31984418919fSjohnjiang 1,
31994418919fSjohnjiang NULL,
32004418919fSjohnjiang &compress_xform,
32014418919fSjohnjiang &ts_params->def_decomp_xform,
32024418919fSjohnjiang 1
32034418919fSjohnjiang };
32044418919fSjohnjiang
32054418919fSjohnjiang struct test_data_params test_data = {
32064418919fSjohnjiang .compress_state = RTE_COMP_OP_STATELESS,
32074418919fSjohnjiang .decompress_state = RTE_COMP_OP_STATELESS,
32084418919fSjohnjiang .buff_type = LB_BOTH,
32094418919fSjohnjiang .zlib_dir = ZLIB_DECOMPRESS,
32104418919fSjohnjiang .out_of_space = 0,
32114418919fSjohnjiang .big_data = 0,
3212*2d9fd380Sjfb8856606 .overflow = OVERFLOW_ENABLED,
3213*2d9fd380Sjfb8856606 .ratio = RATIO_ENABLED
32144418919fSjohnjiang };
32154418919fSjohnjiang
32164418919fSjohnjiang for (i = 0; i < RTE_DIM(compress_test_bufs); i++) {
32174418919fSjohnjiang int_data.test_bufs = &compress_test_bufs[i];
32184418919fSjohnjiang int_data.buf_idx = &i;
32194418919fSjohnjiang
32204418919fSjohnjiang /* Compress with compressdev, decompress with Zlib */
32214418919fSjohnjiang test_data.zlib_dir = ZLIB_DECOMPRESS;
32224418919fSjohnjiang comp_result = test_deflate_comp_decomp(&int_data, &test_data);
32234418919fSjohnjiang if (comp_result < 0) {
32244418919fSjohnjiang ret = TEST_FAILED;
32254418919fSjohnjiang goto exit;
32264418919fSjohnjiang } else if (comp_result > 0) {
32274418919fSjohnjiang ret = -ENOTSUP;
32284418919fSjohnjiang goto exit;
32294418919fSjohnjiang }
32304418919fSjohnjiang
32314418919fSjohnjiang /* Compress with Zlib, decompress with compressdev */
32324418919fSjohnjiang test_data.zlib_dir = ZLIB_COMPRESS;
32334418919fSjohnjiang comp_result = test_deflate_comp_decomp(&int_data, &test_data);
32344418919fSjohnjiang if (comp_result < 0) {
32354418919fSjohnjiang ret = TEST_FAILED;
32364418919fSjohnjiang goto exit;
32374418919fSjohnjiang } else if (comp_result > 0) {
32384418919fSjohnjiang ret = -ENOTSUP;
32394418919fSjohnjiang goto exit;
32404418919fSjohnjiang }
32414418919fSjohnjiang }
32424418919fSjohnjiang
32434418919fSjohnjiang ret = TEST_SUCCESS;
32444418919fSjohnjiang
32454418919fSjohnjiang exit:
32464418919fSjohnjiang rte_free(compress_xform);
32474418919fSjohnjiang return ret;
32484418919fSjohnjiang }
32494418919fSjohnjiang
3250*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_LB_1op(void)3251*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_LB_1op(void)
3252*2d9fd380Sjfb8856606 {
3253*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
3254*2d9fd380Sjfb8856606 uint16_t i = 0;
3255*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
3256*2d9fd380Sjfb8856606 int j;
3257*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
3258*2d9fd380Sjfb8856606 char *test_buffer = NULL;
3259*2d9fd380Sjfb8856606
3260*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3261*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3262*2d9fd380Sjfb8856606
3263*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3264*2d9fd380Sjfb8856606 return -ENOTSUP;
3265*2d9fd380Sjfb8856606
3266*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3267*2d9fd380Sjfb8856606 return -ENOTSUP;
3268*2d9fd380Sjfb8856606
3269*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
3270*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
3271*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
3272*2d9fd380Sjfb8856606 "Can't allocate buffer for 'im buffer' test\n");
3273*2d9fd380Sjfb8856606 return TEST_FAILED;
3274*2d9fd380Sjfb8856606 }
3275*2d9fd380Sjfb8856606
3276*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
3277*2d9fd380Sjfb8856606 (const char * const *)&test_buffer,
3278*2d9fd380Sjfb8856606 1,
3279*2d9fd380Sjfb8856606 &i,
3280*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
3281*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
3282*2d9fd380Sjfb8856606 1
3283*2d9fd380Sjfb8856606 };
3284*2d9fd380Sjfb8856606
3285*2d9fd380Sjfb8856606 struct test_data_params test_data = {
3286*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
3287*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
3288*2d9fd380Sjfb8856606 /* must be LB to SGL,
3289*2d9fd380Sjfb8856606 * input LB buffer reaches its maximum,
3290*2d9fd380Sjfb8856606 * if ratio 1.3 than another mbuf must be
3291*2d9fd380Sjfb8856606 * created and attached
3292*2d9fd380Sjfb8856606 */
3293*2d9fd380Sjfb8856606 .buff_type = LB_BOTH,
3294*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
3295*2d9fd380Sjfb8856606 .out_of_space = 0,
3296*2d9fd380Sjfb8856606 .big_data = 1,
3297*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
3298*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
3299*2d9fd380Sjfb8856606 };
3300*2d9fd380Sjfb8856606
3301*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3302*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
3303*2d9fd380Sjfb8856606
3304*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
3305*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_LB);
3306*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
3307*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3308*2d9fd380Sjfb8856606
3309*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
3310*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3311*2d9fd380Sjfb8856606 ret = TEST_FAILED;
3312*2d9fd380Sjfb8856606 goto end;
3313*2d9fd380Sjfb8856606 }
3314*2d9fd380Sjfb8856606
3315*2d9fd380Sjfb8856606 end:
3316*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3317*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
3318*2d9fd380Sjfb8856606 rte_free(test_buffer);
3319*2d9fd380Sjfb8856606 return ret;
3320*2d9fd380Sjfb8856606 }
3321*2d9fd380Sjfb8856606
3322*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_LB_2ops_first(void)3323*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_LB_2ops_first(void)
3324*2d9fd380Sjfb8856606 {
3325*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
3326*2d9fd380Sjfb8856606 uint16_t i = 0;
3327*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
3328*2d9fd380Sjfb8856606 int j;
3329*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
3330*2d9fd380Sjfb8856606 char *test_buffer = NULL;
3331*2d9fd380Sjfb8856606 const char *test_buffers[2];
3332*2d9fd380Sjfb8856606
3333*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3334*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3335*2d9fd380Sjfb8856606
3336*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3337*2d9fd380Sjfb8856606 return -ENOTSUP;
3338*2d9fd380Sjfb8856606
3339*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3340*2d9fd380Sjfb8856606 return -ENOTSUP;
3341*2d9fd380Sjfb8856606
3342*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
3343*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
3344*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
3345*2d9fd380Sjfb8856606 "Can't allocate buffer for 'im buffer' test\n");
3346*2d9fd380Sjfb8856606 return TEST_FAILED;
3347*2d9fd380Sjfb8856606 }
3348*2d9fd380Sjfb8856606
3349*2d9fd380Sjfb8856606 test_buffers[0] = test_buffer;
3350*2d9fd380Sjfb8856606 test_buffers[1] = compress_test_bufs[0];
3351*2d9fd380Sjfb8856606
3352*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
3353*2d9fd380Sjfb8856606 (const char * const *)test_buffers,
3354*2d9fd380Sjfb8856606 2,
3355*2d9fd380Sjfb8856606 &i,
3356*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
3357*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
3358*2d9fd380Sjfb8856606 1
3359*2d9fd380Sjfb8856606 };
3360*2d9fd380Sjfb8856606
3361*2d9fd380Sjfb8856606 struct test_data_params test_data = {
3362*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
3363*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
3364*2d9fd380Sjfb8856606 .buff_type = LB_BOTH,
3365*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
3366*2d9fd380Sjfb8856606 .out_of_space = 0,
3367*2d9fd380Sjfb8856606 .big_data = 1,
3368*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
3369*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
3370*2d9fd380Sjfb8856606 };
3371*2d9fd380Sjfb8856606
3372*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3373*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
3374*2d9fd380Sjfb8856606
3375*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
3376*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_LB);
3377*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
3378*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3379*2d9fd380Sjfb8856606
3380*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
3381*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3382*2d9fd380Sjfb8856606 ret = TEST_FAILED;
3383*2d9fd380Sjfb8856606 goto end;
3384*2d9fd380Sjfb8856606 }
3385*2d9fd380Sjfb8856606
3386*2d9fd380Sjfb8856606 end:
3387*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3388*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
3389*2d9fd380Sjfb8856606 rte_free(test_buffer);
3390*2d9fd380Sjfb8856606 return ret;
3391*2d9fd380Sjfb8856606 }
3392*2d9fd380Sjfb8856606
3393*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_LB_2ops_second(void)3394*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_LB_2ops_second(void)
3395*2d9fd380Sjfb8856606 {
3396*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
3397*2d9fd380Sjfb8856606 uint16_t i = 0;
3398*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
3399*2d9fd380Sjfb8856606 int j;
3400*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
3401*2d9fd380Sjfb8856606 char *test_buffer = NULL;
3402*2d9fd380Sjfb8856606 const char *test_buffers[2];
3403*2d9fd380Sjfb8856606
3404*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3405*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3406*2d9fd380Sjfb8856606
3407*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3408*2d9fd380Sjfb8856606 return -ENOTSUP;
3409*2d9fd380Sjfb8856606
3410*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3411*2d9fd380Sjfb8856606 return -ENOTSUP;
3412*2d9fd380Sjfb8856606
3413*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
3414*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
3415*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
3416*2d9fd380Sjfb8856606 "Can't allocate buffer for 'im buffer' test\n");
3417*2d9fd380Sjfb8856606 return TEST_FAILED;
3418*2d9fd380Sjfb8856606 }
3419*2d9fd380Sjfb8856606
3420*2d9fd380Sjfb8856606 test_buffers[0] = compress_test_bufs[0];
3421*2d9fd380Sjfb8856606 test_buffers[1] = test_buffer;
3422*2d9fd380Sjfb8856606
3423*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
3424*2d9fd380Sjfb8856606 (const char * const *)test_buffers,
3425*2d9fd380Sjfb8856606 2,
3426*2d9fd380Sjfb8856606 &i,
3427*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
3428*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
3429*2d9fd380Sjfb8856606 1
3430*2d9fd380Sjfb8856606 };
3431*2d9fd380Sjfb8856606
3432*2d9fd380Sjfb8856606 struct test_data_params test_data = {
3433*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
3434*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
3435*2d9fd380Sjfb8856606 .buff_type = LB_BOTH,
3436*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
3437*2d9fd380Sjfb8856606 .out_of_space = 0,
3438*2d9fd380Sjfb8856606 .big_data = 1,
3439*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
3440*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
3441*2d9fd380Sjfb8856606 };
3442*2d9fd380Sjfb8856606
3443*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3444*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
3445*2d9fd380Sjfb8856606
3446*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
3447*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_LB);
3448*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
3449*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3450*2d9fd380Sjfb8856606
3451*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
3452*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3453*2d9fd380Sjfb8856606 ret = TEST_FAILED;
3454*2d9fd380Sjfb8856606 goto end;
3455*2d9fd380Sjfb8856606 }
3456*2d9fd380Sjfb8856606
3457*2d9fd380Sjfb8856606 end:
3458*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3459*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
3460*2d9fd380Sjfb8856606 rte_free(test_buffer);
3461*2d9fd380Sjfb8856606 return ret;
3462*2d9fd380Sjfb8856606 }
3463*2d9fd380Sjfb8856606
3464*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_LB_3ops(void)3465*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_LB_3ops(void)
3466*2d9fd380Sjfb8856606 {
3467*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
3468*2d9fd380Sjfb8856606 uint16_t i = 0;
3469*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
3470*2d9fd380Sjfb8856606 int j;
3471*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
3472*2d9fd380Sjfb8856606 char *test_buffer = NULL;
3473*2d9fd380Sjfb8856606 const char *test_buffers[3];
3474*2d9fd380Sjfb8856606
3475*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3476*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3477*2d9fd380Sjfb8856606
3478*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3479*2d9fd380Sjfb8856606 return -ENOTSUP;
3480*2d9fd380Sjfb8856606
3481*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3482*2d9fd380Sjfb8856606 return -ENOTSUP;
3483*2d9fd380Sjfb8856606
3484*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
3485*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
3486*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
3487*2d9fd380Sjfb8856606 "Can't allocate buffer for 'im buffer' test\n");
3488*2d9fd380Sjfb8856606 return TEST_FAILED;
3489*2d9fd380Sjfb8856606 }
3490*2d9fd380Sjfb8856606
3491*2d9fd380Sjfb8856606 test_buffers[0] = compress_test_bufs[0];
3492*2d9fd380Sjfb8856606 test_buffers[1] = test_buffer;
3493*2d9fd380Sjfb8856606 test_buffers[2] = compress_test_bufs[1];
3494*2d9fd380Sjfb8856606
3495*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
3496*2d9fd380Sjfb8856606 (const char * const *)test_buffers,
3497*2d9fd380Sjfb8856606 3,
3498*2d9fd380Sjfb8856606 &i,
3499*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
3500*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
3501*2d9fd380Sjfb8856606 1
3502*2d9fd380Sjfb8856606 };
3503*2d9fd380Sjfb8856606
3504*2d9fd380Sjfb8856606 struct test_data_params test_data = {
3505*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
3506*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
3507*2d9fd380Sjfb8856606 .buff_type = LB_BOTH,
3508*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
3509*2d9fd380Sjfb8856606 .out_of_space = 0,
3510*2d9fd380Sjfb8856606 .big_data = 1,
3511*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
3512*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
3513*2d9fd380Sjfb8856606 };
3514*2d9fd380Sjfb8856606
3515*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3516*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
3517*2d9fd380Sjfb8856606
3518*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
3519*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_LB);
3520*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
3521*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3522*2d9fd380Sjfb8856606
3523*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
3524*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3525*2d9fd380Sjfb8856606 ret = TEST_FAILED;
3526*2d9fd380Sjfb8856606 goto end;
3527*2d9fd380Sjfb8856606 }
3528*2d9fd380Sjfb8856606
3529*2d9fd380Sjfb8856606 end:
3530*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3531*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
3532*2d9fd380Sjfb8856606 rte_free(test_buffer);
3533*2d9fd380Sjfb8856606 return ret;
3534*2d9fd380Sjfb8856606 }
3535*2d9fd380Sjfb8856606
3536*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_LB_4ops(void)3537*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_LB_4ops(void)
3538*2d9fd380Sjfb8856606 {
3539*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
3540*2d9fd380Sjfb8856606 uint16_t i = 0;
3541*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
3542*2d9fd380Sjfb8856606 int j;
3543*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
3544*2d9fd380Sjfb8856606 char *test_buffer = NULL;
3545*2d9fd380Sjfb8856606 const char *test_buffers[4];
3546*2d9fd380Sjfb8856606
3547*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3548*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3549*2d9fd380Sjfb8856606
3550*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3551*2d9fd380Sjfb8856606 return -ENOTSUP;
3552*2d9fd380Sjfb8856606
3553*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3554*2d9fd380Sjfb8856606 return -ENOTSUP;
3555*2d9fd380Sjfb8856606
3556*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_LB, 0);
3557*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
3558*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
3559*2d9fd380Sjfb8856606 "Can't allocate buffer for 'im buffer' test\n");
3560*2d9fd380Sjfb8856606 return TEST_FAILED;
3561*2d9fd380Sjfb8856606 }
3562*2d9fd380Sjfb8856606
3563*2d9fd380Sjfb8856606 test_buffers[0] = compress_test_bufs[0];
3564*2d9fd380Sjfb8856606 test_buffers[1] = test_buffer;
3565*2d9fd380Sjfb8856606 test_buffers[2] = compress_test_bufs[1];
3566*2d9fd380Sjfb8856606 test_buffers[3] = test_buffer;
3567*2d9fd380Sjfb8856606
3568*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
3569*2d9fd380Sjfb8856606 (const char * const *)test_buffers,
3570*2d9fd380Sjfb8856606 4,
3571*2d9fd380Sjfb8856606 &i,
3572*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
3573*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
3574*2d9fd380Sjfb8856606 1
3575*2d9fd380Sjfb8856606 };
3576*2d9fd380Sjfb8856606
3577*2d9fd380Sjfb8856606 struct test_data_params test_data = {
3578*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
3579*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
3580*2d9fd380Sjfb8856606 .buff_type = LB_BOTH,
3581*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
3582*2d9fd380Sjfb8856606 .out_of_space = 0,
3583*2d9fd380Sjfb8856606 .big_data = 1,
3584*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
3585*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
3586*2d9fd380Sjfb8856606 };
3587*2d9fd380Sjfb8856606
3588*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3589*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
3590*2d9fd380Sjfb8856606
3591*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
3592*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_LB);
3593*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_LB - 1; ++j)
3594*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3595*2d9fd380Sjfb8856606
3596*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
3597*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3598*2d9fd380Sjfb8856606 ret = TEST_FAILED;
3599*2d9fd380Sjfb8856606 goto end;
3600*2d9fd380Sjfb8856606 }
3601*2d9fd380Sjfb8856606
3602*2d9fd380Sjfb8856606 end:
3603*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3604*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
3605*2d9fd380Sjfb8856606 rte_free(test_buffer);
3606*2d9fd380Sjfb8856606 return ret;
3607*2d9fd380Sjfb8856606 }
3608*2d9fd380Sjfb8856606
3609*2d9fd380Sjfb8856606
3610*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_SGL_1op(void)3611*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_1op(void)
3612*2d9fd380Sjfb8856606 {
3613*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
3614*2d9fd380Sjfb8856606 uint16_t i = 0;
3615*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
3616*2d9fd380Sjfb8856606 int j;
3617*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
3618*2d9fd380Sjfb8856606 char *test_buffer = NULL;
3619*2d9fd380Sjfb8856606
3620*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3621*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3622*2d9fd380Sjfb8856606
3623*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3624*2d9fd380Sjfb8856606 return -ENOTSUP;
3625*2d9fd380Sjfb8856606
3626*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3627*2d9fd380Sjfb8856606 return -ENOTSUP;
3628*2d9fd380Sjfb8856606
3629*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
3630*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
3631*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
3632*2d9fd380Sjfb8856606 "Can't allocate buffer for big-data\n");
3633*2d9fd380Sjfb8856606 return TEST_FAILED;
3634*2d9fd380Sjfb8856606 }
3635*2d9fd380Sjfb8856606
3636*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
3637*2d9fd380Sjfb8856606 (const char * const *)&test_buffer,
3638*2d9fd380Sjfb8856606 1,
3639*2d9fd380Sjfb8856606 &i,
3640*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
3641*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
3642*2d9fd380Sjfb8856606 1
3643*2d9fd380Sjfb8856606 };
3644*2d9fd380Sjfb8856606
3645*2d9fd380Sjfb8856606 struct test_data_params test_data = {
3646*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
3647*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
3648*2d9fd380Sjfb8856606 .buff_type = SGL_BOTH,
3649*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
3650*2d9fd380Sjfb8856606 .out_of_space = 0,
3651*2d9fd380Sjfb8856606 .big_data = 1,
3652*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
3653*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
3654*2d9fd380Sjfb8856606 };
3655*2d9fd380Sjfb8856606
3656*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3657*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
3658*2d9fd380Sjfb8856606
3659*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
3660*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_SGL);
3661*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
3662*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3663*2d9fd380Sjfb8856606
3664*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
3665*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3666*2d9fd380Sjfb8856606 ret = TEST_FAILED;
3667*2d9fd380Sjfb8856606 goto end;
3668*2d9fd380Sjfb8856606 }
3669*2d9fd380Sjfb8856606
3670*2d9fd380Sjfb8856606 end:
3671*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3672*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
3673*2d9fd380Sjfb8856606 rte_free(test_buffer);
3674*2d9fd380Sjfb8856606 return ret;
3675*2d9fd380Sjfb8856606 }
3676*2d9fd380Sjfb8856606
3677*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_SGL_2ops_first(void)3678*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_2ops_first(void)
3679*2d9fd380Sjfb8856606 {
3680*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
3681*2d9fd380Sjfb8856606 uint16_t i = 0;
3682*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
3683*2d9fd380Sjfb8856606 int j;
3684*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
3685*2d9fd380Sjfb8856606 char *test_buffer = NULL;
3686*2d9fd380Sjfb8856606 const char *test_buffers[2];
3687*2d9fd380Sjfb8856606
3688*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3689*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3690*2d9fd380Sjfb8856606
3691*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3692*2d9fd380Sjfb8856606 return -ENOTSUP;
3693*2d9fd380Sjfb8856606
3694*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3695*2d9fd380Sjfb8856606 return -ENOTSUP;
3696*2d9fd380Sjfb8856606
3697*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
3698*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
3699*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
3700*2d9fd380Sjfb8856606 "Can't allocate buffer for big-data\n");
3701*2d9fd380Sjfb8856606 return TEST_FAILED;
3702*2d9fd380Sjfb8856606 }
3703*2d9fd380Sjfb8856606
3704*2d9fd380Sjfb8856606 test_buffers[0] = test_buffer;
3705*2d9fd380Sjfb8856606 test_buffers[1] = compress_test_bufs[0];
3706*2d9fd380Sjfb8856606
3707*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
3708*2d9fd380Sjfb8856606 (const char * const *)test_buffers,
3709*2d9fd380Sjfb8856606 2,
3710*2d9fd380Sjfb8856606 &i,
3711*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
3712*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
3713*2d9fd380Sjfb8856606 1
3714*2d9fd380Sjfb8856606 };
3715*2d9fd380Sjfb8856606
3716*2d9fd380Sjfb8856606 struct test_data_params test_data = {
3717*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
3718*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
3719*2d9fd380Sjfb8856606 .buff_type = SGL_BOTH,
3720*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
3721*2d9fd380Sjfb8856606 .out_of_space = 0,
3722*2d9fd380Sjfb8856606 .big_data = 1,
3723*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
3724*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
3725*2d9fd380Sjfb8856606 };
3726*2d9fd380Sjfb8856606
3727*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3728*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
3729*2d9fd380Sjfb8856606
3730*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
3731*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_SGL);
3732*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
3733*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3734*2d9fd380Sjfb8856606
3735*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
3736*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3737*2d9fd380Sjfb8856606 ret = TEST_FAILED;
3738*2d9fd380Sjfb8856606 goto end;
3739*2d9fd380Sjfb8856606 }
3740*2d9fd380Sjfb8856606
3741*2d9fd380Sjfb8856606 end:
3742*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3743*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
3744*2d9fd380Sjfb8856606 rte_free(test_buffer);
3745*2d9fd380Sjfb8856606 return ret;
3746*2d9fd380Sjfb8856606 }
3747*2d9fd380Sjfb8856606
3748*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_SGL_2ops_second(void)3749*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_2ops_second(void)
3750*2d9fd380Sjfb8856606 {
3751*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
3752*2d9fd380Sjfb8856606 uint16_t i = 0;
3753*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
3754*2d9fd380Sjfb8856606 int j;
3755*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
3756*2d9fd380Sjfb8856606 char *test_buffer = NULL;
3757*2d9fd380Sjfb8856606 const char *test_buffers[2];
3758*2d9fd380Sjfb8856606
3759*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3760*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3761*2d9fd380Sjfb8856606
3762*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3763*2d9fd380Sjfb8856606 return -ENOTSUP;
3764*2d9fd380Sjfb8856606
3765*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3766*2d9fd380Sjfb8856606 return -ENOTSUP;
3767*2d9fd380Sjfb8856606
3768*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
3769*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
3770*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
3771*2d9fd380Sjfb8856606 "Can't allocate buffer for big-data\n");
3772*2d9fd380Sjfb8856606 return TEST_FAILED;
3773*2d9fd380Sjfb8856606 }
3774*2d9fd380Sjfb8856606
3775*2d9fd380Sjfb8856606 test_buffers[0] = compress_test_bufs[0];
3776*2d9fd380Sjfb8856606 test_buffers[1] = test_buffer;
3777*2d9fd380Sjfb8856606
3778*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
3779*2d9fd380Sjfb8856606 (const char * const *)test_buffers,
3780*2d9fd380Sjfb8856606 2,
3781*2d9fd380Sjfb8856606 &i,
3782*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
3783*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
3784*2d9fd380Sjfb8856606 1
3785*2d9fd380Sjfb8856606 };
3786*2d9fd380Sjfb8856606
3787*2d9fd380Sjfb8856606 struct test_data_params test_data = {
3788*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
3789*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
3790*2d9fd380Sjfb8856606 .buff_type = SGL_BOTH,
3791*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
3792*2d9fd380Sjfb8856606 .out_of_space = 0,
3793*2d9fd380Sjfb8856606 .big_data = 1,
3794*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
3795*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
3796*2d9fd380Sjfb8856606 };
3797*2d9fd380Sjfb8856606
3798*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3799*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
3800*2d9fd380Sjfb8856606
3801*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
3802*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_SGL);
3803*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
3804*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3805*2d9fd380Sjfb8856606
3806*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
3807*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3808*2d9fd380Sjfb8856606 ret = TEST_FAILED;
3809*2d9fd380Sjfb8856606 goto end;
3810*2d9fd380Sjfb8856606 }
3811*2d9fd380Sjfb8856606
3812*2d9fd380Sjfb8856606 end:
3813*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3814*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
3815*2d9fd380Sjfb8856606 rte_free(test_buffer);
3816*2d9fd380Sjfb8856606 return ret;
3817*2d9fd380Sjfb8856606 }
3818*2d9fd380Sjfb8856606
3819*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_SGL_3ops(void)3820*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_3ops(void)
3821*2d9fd380Sjfb8856606 {
3822*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
3823*2d9fd380Sjfb8856606 uint16_t i = 0;
3824*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
3825*2d9fd380Sjfb8856606 int j;
3826*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
3827*2d9fd380Sjfb8856606 char *test_buffer = NULL;
3828*2d9fd380Sjfb8856606 const char *test_buffers[3];
3829*2d9fd380Sjfb8856606
3830*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3831*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3832*2d9fd380Sjfb8856606
3833*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3834*2d9fd380Sjfb8856606 return -ENOTSUP;
3835*2d9fd380Sjfb8856606
3836*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3837*2d9fd380Sjfb8856606 return -ENOTSUP;
3838*2d9fd380Sjfb8856606
3839*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
3840*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
3841*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
3842*2d9fd380Sjfb8856606 "Can't allocate buffer for big-data\n");
3843*2d9fd380Sjfb8856606 return TEST_FAILED;
3844*2d9fd380Sjfb8856606 }
3845*2d9fd380Sjfb8856606
3846*2d9fd380Sjfb8856606 test_buffers[0] = compress_test_bufs[0];
3847*2d9fd380Sjfb8856606 test_buffers[1] = test_buffer;
3848*2d9fd380Sjfb8856606 test_buffers[2] = compress_test_bufs[1];
3849*2d9fd380Sjfb8856606
3850*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
3851*2d9fd380Sjfb8856606 (const char * const *)test_buffers,
3852*2d9fd380Sjfb8856606 3,
3853*2d9fd380Sjfb8856606 &i,
3854*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
3855*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
3856*2d9fd380Sjfb8856606 1
3857*2d9fd380Sjfb8856606 };
3858*2d9fd380Sjfb8856606
3859*2d9fd380Sjfb8856606 struct test_data_params test_data = {
3860*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
3861*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
3862*2d9fd380Sjfb8856606 .buff_type = SGL_BOTH,
3863*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
3864*2d9fd380Sjfb8856606 .out_of_space = 0,
3865*2d9fd380Sjfb8856606 .big_data = 1,
3866*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
3867*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
3868*2d9fd380Sjfb8856606 };
3869*2d9fd380Sjfb8856606
3870*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3871*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
3872*2d9fd380Sjfb8856606
3873*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
3874*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_SGL);
3875*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
3876*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3877*2d9fd380Sjfb8856606
3878*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
3879*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3880*2d9fd380Sjfb8856606 ret = TEST_FAILED;
3881*2d9fd380Sjfb8856606 goto end;
3882*2d9fd380Sjfb8856606 }
3883*2d9fd380Sjfb8856606
3884*2d9fd380Sjfb8856606 end:
3885*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3886*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
3887*2d9fd380Sjfb8856606 rte_free(test_buffer);
3888*2d9fd380Sjfb8856606 return ret;
3889*2d9fd380Sjfb8856606 }
3890*2d9fd380Sjfb8856606
3891*2d9fd380Sjfb8856606
3892*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_SGL_4ops(void)3893*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_4ops(void)
3894*2d9fd380Sjfb8856606 {
3895*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
3896*2d9fd380Sjfb8856606 uint16_t i = 0;
3897*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
3898*2d9fd380Sjfb8856606 int j;
3899*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
3900*2d9fd380Sjfb8856606 char *test_buffer = NULL;
3901*2d9fd380Sjfb8856606 const char *test_buffers[4];
3902*2d9fd380Sjfb8856606
3903*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3904*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3905*2d9fd380Sjfb8856606
3906*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3907*2d9fd380Sjfb8856606 return -ENOTSUP;
3908*2d9fd380Sjfb8856606
3909*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3910*2d9fd380Sjfb8856606 return -ENOTSUP;
3911*2d9fd380Sjfb8856606
3912*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_SGL, 0);
3913*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
3914*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
3915*2d9fd380Sjfb8856606 "Can't allocate buffer for big-data\n");
3916*2d9fd380Sjfb8856606 return TEST_FAILED;
3917*2d9fd380Sjfb8856606 }
3918*2d9fd380Sjfb8856606
3919*2d9fd380Sjfb8856606 test_buffers[0] = compress_test_bufs[0];
3920*2d9fd380Sjfb8856606 test_buffers[1] = test_buffer;
3921*2d9fd380Sjfb8856606 test_buffers[2] = compress_test_bufs[1];
3922*2d9fd380Sjfb8856606 test_buffers[3] = test_buffer;
3923*2d9fd380Sjfb8856606
3924*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
3925*2d9fd380Sjfb8856606 (const char * const *)test_buffers,
3926*2d9fd380Sjfb8856606 4,
3927*2d9fd380Sjfb8856606 &i,
3928*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
3929*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
3930*2d9fd380Sjfb8856606 1
3931*2d9fd380Sjfb8856606 };
3932*2d9fd380Sjfb8856606
3933*2d9fd380Sjfb8856606 struct test_data_params test_data = {
3934*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
3935*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
3936*2d9fd380Sjfb8856606 .buff_type = SGL_BOTH,
3937*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
3938*2d9fd380Sjfb8856606 .out_of_space = 0,
3939*2d9fd380Sjfb8856606 .big_data = 1,
3940*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
3941*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
3942*2d9fd380Sjfb8856606 };
3943*2d9fd380Sjfb8856606
3944*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3945*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
3946*2d9fd380Sjfb8856606
3947*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
3948*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_SGL);
3949*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_SGL - 1; ++j)
3950*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
3951*2d9fd380Sjfb8856606
3952*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
3953*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
3954*2d9fd380Sjfb8856606 ret = TEST_FAILED;
3955*2d9fd380Sjfb8856606 goto end;
3956*2d9fd380Sjfb8856606 }
3957*2d9fd380Sjfb8856606
3958*2d9fd380Sjfb8856606 end:
3959*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
3960*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
3961*2d9fd380Sjfb8856606 rte_free(test_buffer);
3962*2d9fd380Sjfb8856606 return ret;
3963*2d9fd380Sjfb8856606 }
3964*2d9fd380Sjfb8856606
3965*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_SGL_over_1op(void)3966*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_over_1op(void)
3967*2d9fd380Sjfb8856606 {
3968*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
3969*2d9fd380Sjfb8856606 uint16_t i = 0;
3970*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
3971*2d9fd380Sjfb8856606 int j;
3972*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
3973*2d9fd380Sjfb8856606 char *test_buffer = NULL;
3974*2d9fd380Sjfb8856606
3975*2d9fd380Sjfb8856606 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
3976*2d9fd380Sjfb8856606
3977*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
3978*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
3979*2d9fd380Sjfb8856606
3980*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
3981*2d9fd380Sjfb8856606 return -ENOTSUP;
3982*2d9fd380Sjfb8856606
3983*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
3984*2d9fd380Sjfb8856606 return -ENOTSUP;
3985*2d9fd380Sjfb8856606
3986*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_OVER, 0);
3987*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
3988*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
3989*2d9fd380Sjfb8856606 "Can't allocate buffer for big-data\n");
3990*2d9fd380Sjfb8856606 return TEST_FAILED;
3991*2d9fd380Sjfb8856606 }
3992*2d9fd380Sjfb8856606
3993*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
3994*2d9fd380Sjfb8856606 (const char * const *)&test_buffer,
3995*2d9fd380Sjfb8856606 1,
3996*2d9fd380Sjfb8856606 &i,
3997*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
3998*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
3999*2d9fd380Sjfb8856606 1
4000*2d9fd380Sjfb8856606 };
4001*2d9fd380Sjfb8856606
4002*2d9fd380Sjfb8856606 struct test_data_params test_data = {
4003*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
4004*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
4005*2d9fd380Sjfb8856606 .buff_type = SGL_BOTH,
4006*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
4007*2d9fd380Sjfb8856606 .out_of_space = 0,
4008*2d9fd380Sjfb8856606 .big_data = 1,
4009*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
4010*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
4011*2d9fd380Sjfb8856606 };
4012*2d9fd380Sjfb8856606
4013*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
4014*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
4015*2d9fd380Sjfb8856606
4016*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
4017*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_OVER);
4018*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_OVER - 1; ++j)
4019*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
4020*2d9fd380Sjfb8856606
4021*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
4022*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
4023*2d9fd380Sjfb8856606 ret = TEST_SUCCESS;
4024*2d9fd380Sjfb8856606 goto end;
4025*2d9fd380Sjfb8856606 }
4026*2d9fd380Sjfb8856606
4027*2d9fd380Sjfb8856606 end:
4028*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
4029*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
4030*2d9fd380Sjfb8856606 rte_free(test_buffer);
4031*2d9fd380Sjfb8856606
4032*2d9fd380Sjfb8856606 return ret;
4033*2d9fd380Sjfb8856606 }
4034*2d9fd380Sjfb8856606
4035*2d9fd380Sjfb8856606
4036*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_SGL_over_2ops_first(void)4037*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_over_2ops_first(void)
4038*2d9fd380Sjfb8856606 {
4039*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
4040*2d9fd380Sjfb8856606 uint16_t i = 0;
4041*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
4042*2d9fd380Sjfb8856606 int j;
4043*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
4044*2d9fd380Sjfb8856606 char *test_buffer = NULL;
4045*2d9fd380Sjfb8856606 const char *test_buffers[2];
4046*2d9fd380Sjfb8856606
4047*2d9fd380Sjfb8856606 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
4048*2d9fd380Sjfb8856606
4049*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
4050*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
4051*2d9fd380Sjfb8856606
4052*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
4053*2d9fd380Sjfb8856606 return -ENOTSUP;
4054*2d9fd380Sjfb8856606
4055*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
4056*2d9fd380Sjfb8856606 return -ENOTSUP;
4057*2d9fd380Sjfb8856606
4058*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_OVER, 0);
4059*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
4060*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
4061*2d9fd380Sjfb8856606 "Can't allocate buffer for big-data\n");
4062*2d9fd380Sjfb8856606 return TEST_FAILED;
4063*2d9fd380Sjfb8856606 }
4064*2d9fd380Sjfb8856606
4065*2d9fd380Sjfb8856606 test_buffers[0] = test_buffer;
4066*2d9fd380Sjfb8856606 test_buffers[1] = compress_test_bufs[0];
4067*2d9fd380Sjfb8856606
4068*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
4069*2d9fd380Sjfb8856606 (const char * const *)test_buffers,
4070*2d9fd380Sjfb8856606 2,
4071*2d9fd380Sjfb8856606 &i,
4072*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
4073*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
4074*2d9fd380Sjfb8856606 1
4075*2d9fd380Sjfb8856606 };
4076*2d9fd380Sjfb8856606
4077*2d9fd380Sjfb8856606 struct test_data_params test_data = {
4078*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
4079*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
4080*2d9fd380Sjfb8856606 .buff_type = SGL_BOTH,
4081*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
4082*2d9fd380Sjfb8856606 .out_of_space = 0,
4083*2d9fd380Sjfb8856606 .big_data = 1,
4084*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
4085*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
4086*2d9fd380Sjfb8856606 };
4087*2d9fd380Sjfb8856606
4088*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
4089*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
4090*2d9fd380Sjfb8856606
4091*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
4092*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_OVER);
4093*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_OVER - 1; ++j)
4094*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
4095*2d9fd380Sjfb8856606
4096*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
4097*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
4098*2d9fd380Sjfb8856606 ret = TEST_SUCCESS;
4099*2d9fd380Sjfb8856606 goto end;
4100*2d9fd380Sjfb8856606 }
4101*2d9fd380Sjfb8856606
4102*2d9fd380Sjfb8856606 end:
4103*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
4104*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
4105*2d9fd380Sjfb8856606 rte_free(test_buffer);
4106*2d9fd380Sjfb8856606 return ret;
4107*2d9fd380Sjfb8856606 }
4108*2d9fd380Sjfb8856606
4109*2d9fd380Sjfb8856606 static int
test_compressdev_deflate_im_buffers_SGL_over_2ops_second(void)4110*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_over_2ops_second(void)
4111*2d9fd380Sjfb8856606 {
4112*2d9fd380Sjfb8856606 struct comp_testsuite_params *ts_params = &testsuite_params;
4113*2d9fd380Sjfb8856606 uint16_t i = 0;
4114*2d9fd380Sjfb8856606 int ret = TEST_SUCCESS;
4115*2d9fd380Sjfb8856606 int j;
4116*2d9fd380Sjfb8856606 const struct rte_compressdev_capabilities *capab;
4117*2d9fd380Sjfb8856606 char *test_buffer = NULL;
4118*2d9fd380Sjfb8856606 const char *test_buffers[2];
4119*2d9fd380Sjfb8856606
4120*2d9fd380Sjfb8856606 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
4121*2d9fd380Sjfb8856606
4122*2d9fd380Sjfb8856606 capab = rte_compressdev_capability_get(0, RTE_COMP_ALGO_DEFLATE);
4123*2d9fd380Sjfb8856606 TEST_ASSERT(capab != NULL, "Failed to retrieve device capabilities");
4124*2d9fd380Sjfb8856606
4125*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_HUFFMAN_DYNAMIC) == 0)
4126*2d9fd380Sjfb8856606 return -ENOTSUP;
4127*2d9fd380Sjfb8856606
4128*2d9fd380Sjfb8856606 if ((capab->comp_feature_flags & RTE_COMP_FF_OOP_SGL_IN_SGL_OUT) == 0)
4129*2d9fd380Sjfb8856606 return -ENOTSUP;
4130*2d9fd380Sjfb8856606
4131*2d9fd380Sjfb8856606 test_buffer = rte_malloc(NULL, IM_BUF_DATA_TEST_SIZE_OVER, 0);
4132*2d9fd380Sjfb8856606 if (test_buffer == NULL) {
4133*2d9fd380Sjfb8856606 RTE_LOG(ERR, USER1,
4134*2d9fd380Sjfb8856606 "Can't allocate buffer for big-data\n");
4135*2d9fd380Sjfb8856606 return TEST_FAILED;
4136*2d9fd380Sjfb8856606 }
4137*2d9fd380Sjfb8856606
4138*2d9fd380Sjfb8856606 test_buffers[0] = compress_test_bufs[0];
4139*2d9fd380Sjfb8856606 test_buffers[1] = test_buffer;
4140*2d9fd380Sjfb8856606
4141*2d9fd380Sjfb8856606 struct interim_data_params int_data = {
4142*2d9fd380Sjfb8856606 (const char * const *)test_buffers,
4143*2d9fd380Sjfb8856606 2,
4144*2d9fd380Sjfb8856606 &i,
4145*2d9fd380Sjfb8856606 &ts_params->def_comp_xform,
4146*2d9fd380Sjfb8856606 &ts_params->def_decomp_xform,
4147*2d9fd380Sjfb8856606 1
4148*2d9fd380Sjfb8856606 };
4149*2d9fd380Sjfb8856606
4150*2d9fd380Sjfb8856606 struct test_data_params test_data = {
4151*2d9fd380Sjfb8856606 .compress_state = RTE_COMP_OP_STATELESS,
4152*2d9fd380Sjfb8856606 .decompress_state = RTE_COMP_OP_STATELESS,
4153*2d9fd380Sjfb8856606 .buff_type = SGL_BOTH,
4154*2d9fd380Sjfb8856606 .zlib_dir = ZLIB_NONE,
4155*2d9fd380Sjfb8856606 .out_of_space = 0,
4156*2d9fd380Sjfb8856606 .big_data = 1,
4157*2d9fd380Sjfb8856606 .overflow = OVERFLOW_DISABLED,
4158*2d9fd380Sjfb8856606 .ratio = RATIO_DISABLED
4159*2d9fd380Sjfb8856606 };
4160*2d9fd380Sjfb8856606
4161*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
4162*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DYNAMIC;
4163*2d9fd380Sjfb8856606
4164*2d9fd380Sjfb8856606 /* fill the buffer with data based on rand. data */
4165*2d9fd380Sjfb8856606 srand(IM_BUF_DATA_TEST_SIZE_OVER);
4166*2d9fd380Sjfb8856606 for (j = 0; j < IM_BUF_DATA_TEST_SIZE_OVER - 1; ++j)
4167*2d9fd380Sjfb8856606 test_buffer[j] = (uint8_t)(rand() % ((uint8_t)-1)) | 1;
4168*2d9fd380Sjfb8856606
4169*2d9fd380Sjfb8856606 /* Compress with compressdev, decompress with compressdev */
4170*2d9fd380Sjfb8856606 if (test_deflate_comp_decomp(&int_data, &test_data) < 0) {
4171*2d9fd380Sjfb8856606 ret = TEST_SUCCESS;
4172*2d9fd380Sjfb8856606 goto end;
4173*2d9fd380Sjfb8856606 }
4174*2d9fd380Sjfb8856606
4175*2d9fd380Sjfb8856606 end:
4176*2d9fd380Sjfb8856606 ts_params->def_comp_xform->compress.deflate.huffman =
4177*2d9fd380Sjfb8856606 RTE_COMP_HUFFMAN_DEFAULT;
4178*2d9fd380Sjfb8856606 rte_free(test_buffer);
4179*2d9fd380Sjfb8856606 return ret;
4180*2d9fd380Sjfb8856606 }
4181*2d9fd380Sjfb8856606
41824418919fSjohnjiang static struct unit_test_suite compressdev_testsuite = {
41834418919fSjohnjiang .suite_name = "compressdev unit test suite",
41844418919fSjohnjiang .setup = testsuite_setup,
41854418919fSjohnjiang .teardown = testsuite_teardown,
41864418919fSjohnjiang .unit_test_cases = {
41874418919fSjohnjiang TEST_CASE_ST(NULL, NULL,
41884418919fSjohnjiang test_compressdev_invalid_configuration),
41894418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
41904418919fSjohnjiang test_compressdev_deflate_stateless_fixed),
41914418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
41924418919fSjohnjiang test_compressdev_deflate_stateless_dynamic),
41934418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
41944418919fSjohnjiang test_compressdev_deflate_stateless_dynamic_big),
41954418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
41964418919fSjohnjiang test_compressdev_deflate_stateless_multi_op),
41974418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
41984418919fSjohnjiang test_compressdev_deflate_stateless_multi_level),
41994418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
42004418919fSjohnjiang test_compressdev_deflate_stateless_multi_xform),
42014418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
42024418919fSjohnjiang test_compressdev_deflate_stateless_sgl),
42034418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
42044418919fSjohnjiang test_compressdev_deflate_stateless_checksum),
42054418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
42064418919fSjohnjiang test_compressdev_out_of_space_buffer),
42074418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
42084418919fSjohnjiang test_compressdev_deflate_stateful_decomp),
42094418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
42104418919fSjohnjiang test_compressdev_deflate_stateful_decomp_checksum),
42114418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
42124418919fSjohnjiang test_compressdev_external_mbufs),
42134418919fSjohnjiang TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
42144418919fSjohnjiang test_compressdev_deflate_stateless_fixed_oos_recoverable),
4215*2d9fd380Sjfb8856606
4216*2d9fd380Sjfb8856606 /* Positive test cases for IM buffer handling verification */
4217*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4218*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_LB_1op),
4219*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4220*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_LB_2ops_first),
4221*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4222*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_LB_2ops_second),
4223*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4224*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_LB_3ops),
4225*2d9fd380Sjfb8856606
4226*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4227*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_LB_4ops),
4228*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4229*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_1op),
4230*2d9fd380Sjfb8856606
4231*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4232*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_2ops_first),
4233*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4234*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_2ops_second),
4235*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4236*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_3ops),
4237*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4238*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_4ops),
4239*2d9fd380Sjfb8856606
4240*2d9fd380Sjfb8856606 /* Negative test cases for IM buffer handling verification */
4241*2d9fd380Sjfb8856606
4242*2d9fd380Sjfb8856606 /* For this test huge mempool is necessary.
4243*2d9fd380Sjfb8856606 * It tests one case:
4244*2d9fd380Sjfb8856606 * only one op containing big amount of data, so that
4245*2d9fd380Sjfb8856606 * number of requested descriptors higher than number
4246*2d9fd380Sjfb8856606 * of available descriptors (128)
4247*2d9fd380Sjfb8856606 */
4248*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4249*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_over_1op),
4250*2d9fd380Sjfb8856606
4251*2d9fd380Sjfb8856606 /* For this test huge mempool is necessary.
4252*2d9fd380Sjfb8856606 * 2 ops. First op contains big amount of data:
4253*2d9fd380Sjfb8856606 * number of requested descriptors higher than number
4254*2d9fd380Sjfb8856606 * of available descriptors (128), the second op is
4255*2d9fd380Sjfb8856606 * relatively small. In this case both ops are rejected
4256*2d9fd380Sjfb8856606 */
4257*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4258*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_over_2ops_first),
4259*2d9fd380Sjfb8856606
4260*2d9fd380Sjfb8856606 TEST_CASE_ST(generic_ut_setup, generic_ut_teardown,
4261*2d9fd380Sjfb8856606 test_compressdev_deflate_im_buffers_SGL_over_2ops_second),
4262*2d9fd380Sjfb8856606
42634418919fSjohnjiang TEST_CASES_END() /**< NULL terminate unit test array */
42644418919fSjohnjiang }
42654418919fSjohnjiang };
42664418919fSjohnjiang
42674418919fSjohnjiang static int
test_compressdev(void)42684418919fSjohnjiang test_compressdev(void)
42694418919fSjohnjiang {
42704418919fSjohnjiang return unit_test_suite_runner(&compressdev_testsuite);
42714418919fSjohnjiang }
42724418919fSjohnjiang
42734418919fSjohnjiang REGISTER_TEST_COMMAND(compressdev_autotest, test_compressdev);
4274