app/test: check scatter-gather for crypto drivers
[dpdk.git] / app / test / test_cryptodev_blockcipher.c
index f1fe624..01aef3b 100644 (file)
@@ -41,6 +41,7 @@
 #include <rte_cryptodev_pmd.h>
 
 #include "test.h"
+#include "test_cryptodev.h"
 #include "test_cryptodev_blockcipher.h"
 #include "test_cryptodev_aes_test_vectors.h"
 #include "test_cryptodev_des_test_vectors.h"
@@ -64,6 +65,7 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
        struct rte_crypto_sym_op *sym_op = NULL;
        struct rte_crypto_op *op = NULL;
        struct rte_cryptodev_sym_session *sess = NULL;
+       struct rte_cryptodev_info dev_info;
 
        int status = TEST_SUCCESS;
        const struct blockcipher_test_data *tdata = t->test_data;
@@ -77,6 +79,19 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
        uint8_t tmp_src_buf[MBUF_SIZE];
        uint8_t tmp_dst_buf[MBUF_SIZE];
 
+       int nb_segs = 1;
+
+       if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) {
+               rte_cryptodev_info_get(dev_id, &dev_info);
+               if (!(dev_info.feature_flags &
+                               RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
+                       printf("Device doesn't support scatter-gather. "
+                                       "Test Skipped.\n");
+                       return 0;
+               }
+               nb_segs = 3;
+       }
+
        if (tdata->cipher_key.len)
                memcpy(cipher_key, tdata->cipher_key.data,
                        tdata->cipher_key.len);
@@ -101,49 +116,38 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
        }
 
        /* preparing data */
-       ibuf = rte_pktmbuf_alloc(mbuf_pool);
-       if (!ibuf) {
-               snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
-                       "line %u FAILED: %s",
-                       __LINE__, "Allocation of rte_mbuf failed");
-               status = TEST_FAILED;
-               goto error_exit;
-       }
-       memset(ibuf->buf_addr, src_pattern, ibuf->buf_len);
-
        if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER)
                buf_len += tdata->iv.len;
        if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
                buf_len += digest_len;
 
-       buf_p = rte_pktmbuf_append(ibuf, buf_len);
-       if (!buf_p) {
+       /* for contiguous mbuf, nb_segs is 1 */
+       ibuf = create_segmented_mbuf(mbuf_pool,
+                       tdata->ciphertext.len, nb_segs, src_pattern);
+       if (ibuf == NULL) {
                snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
                        "line %u FAILED: %s",
-                       __LINE__, "No room to append mbuf");
+                       __LINE__, "Cannot create source mbuf");
                status = TEST_FAILED;
                goto error_exit;
        }
 
-       if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
-               rte_memcpy(buf_p, tdata->iv.data, tdata->iv.len);
-               buf_p += tdata->iv.len;
-       }
-
        /* only encryption requires plaintext.data input,
         * decryption/(digest gen)/(digest verify) use ciphertext.data
         * to be computed
         */
-       if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) {
-               rte_memcpy(buf_p, tdata->plaintext.data,
-                       tdata->plaintext.len);
-               buf_p += tdata->plaintext.len;
-       } else {
-               rte_memcpy(buf_p, tdata->ciphertext.data,
-                       tdata->ciphertext.len);
-               buf_p += tdata->ciphertext.len;
-       }
+       if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
+               pktmbuf_write(ibuf, 0, tdata->plaintext.len,
+                               tdata->plaintext.data);
+       else
+               pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
+                               tdata->ciphertext.data);
 
+       if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
+               rte_memcpy(rte_pktmbuf_prepend(ibuf, tdata->iv.len),
+                               tdata->iv.data, tdata->iv.len);
+       }
+       buf_p = rte_pktmbuf_append(ibuf, digest_len);
        if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
                rte_memcpy(buf_p, tdata->digest.data, digest_len);
        else
@@ -314,17 +318,17 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
 
                if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
                        auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
-                       sym_op->auth.digest.data = rte_pktmbuf_mtod_offset
-                               (iobuf, uint8_t *, digest_offset);
+                       sym_op->auth.digest.data = pktmbuf_mtod_offset
+                               (iobuf, digest_offset);
                        sym_op->auth.digest.phys_addr =
-                               rte_pktmbuf_mtophys_offset(iobuf,
+                               pktmbuf_mtophys_offset(iobuf,
                                        digest_offset);
                } else {
                        auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
-                       sym_op->auth.digest.data = rte_pktmbuf_mtod_offset
-                               (sym_op->m_src, uint8_t *, digest_offset);
+                       sym_op->auth.digest.data = pktmbuf_mtod_offset
+                               (sym_op->m_src, digest_offset);
                        sym_op->auth.digest.phys_addr =
-                               rte_pktmbuf_mtophys_offset(sym_op->m_src,
+                               pktmbuf_mtophys_offset(sym_op->m_src,
                                        digest_offset);
                }
 
@@ -403,13 +407,10 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
        }
 
        if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
-               uint8_t *crypto_res;
+               uint8_t buffer[2048];
                const uint8_t *compare_ref;
                uint32_t compare_len;
 
-               crypto_res = rte_pktmbuf_mtod_offset(iobuf, uint8_t *,
-                       tdata->iv.len);
-
                if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) {
                        compare_ref = tdata->ciphertext.data;
                        compare_len = tdata->ciphertext.len;
@@ -418,7 +419,8 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
                        compare_len = tdata->plaintext.len;
                }
 
-               if (memcmp(crypto_res, compare_ref, compare_len)) {
+               if (memcmp(rte_pktmbuf_read(iobuf, tdata->iv.len, compare_len,
+                               buffer), compare_ref, compare_len)) {
                        snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
                                "FAILED: %s", __LINE__,
                                "Crypto data not as expected");
@@ -431,12 +433,11 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
                uint8_t *auth_res;
 
                if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER)
-                       auth_res = rte_pktmbuf_mtod_offset(iobuf,
-                               uint8_t *,
-                               tdata->iv.len + tdata->ciphertext.len);
+                       auth_res = pktmbuf_mtod_offset(iobuf,
+                                       tdata->iv.len + tdata->ciphertext.len);
                else
-                       auth_res = rte_pktmbuf_mtod_offset(iobuf,
-                               uint8_t *, tdata->ciphertext.len);
+                       auth_res = pktmbuf_mtod_offset(iobuf,
+                                       tdata->ciphertext.len);
 
                if (memcmp(auth_res, tdata->digest.data, digest_len)) {
                        snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "