test/crypto: add tests for virtio-crypto
authorJay Zhou <jianjay.zhou@huawei.com>
Tue, 17 Apr 2018 09:23:25 +0000 (17:23 +0800)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Mon, 23 Apr 2018 17:20:10 +0000 (18:20 +0100)
Only RTE_CRYPTO_CIPHER_AES_CBC cipher
algorithm are tested as unit test, it is supported both by the
cryptodev-backend-builtin and cryptodev-vhost-user of qemu side.

Signed-off-by: Jay Zhou <jianjay.zhou@huawei.com>
Reviewed-by: Fan Zhang <roy.fan.zhang@intel.com>
test/test/test_cryptodev.c
test/test/test_cryptodev.h
test/test/test_cryptodev_aes_test_vectors.h
test/test/test_cryptodev_blockcipher.c
test/test/test_cryptodev_blockcipher.h

index d1d7925..2f31ec9 100644 (file)
@@ -1819,6 +1819,25 @@ test_AES_cipheronly_qat_all(void)
        return TEST_SUCCESS;
 }
 
+static int
+test_AES_cipheronly_virtio_all(void)
+{
+       struct crypto_testsuite_params *ts_params = &testsuite_params;
+       int status;
+
+       status = test_blockcipher_all_tests(ts_params->mbuf_pool,
+               ts_params->op_mpool,
+               ts_params->session_mpool,
+               ts_params->valid_devs[0],
+               rte_cryptodev_driver_id_get(
+               RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)),
+               BLKCIPHER_AES_CIPHERONLY_TYPE);
+
+       TEST_ASSERT_EQUAL(status, 0, "Test failed");
+
+       return TEST_SUCCESS;
+}
+
 static int
 test_AES_chain_dpaa_sec_all(void)
 {
@@ -8879,6 +8898,18 @@ static struct unit_test_suite cryptodev_qat_testsuite  = {
        }
 };
 
+static struct unit_test_suite cryptodev_virtio_testsuite = {
+       .suite_name = "Crypto VIRTIO Unit Test Suite",
+       .setup = testsuite_setup,
+       .teardown = testsuite_teardown,
+       .unit_test_cases = {
+               TEST_CASE_ST(ut_setup, ut_teardown,
+                               test_AES_cipheronly_virtio_all),
+
+               TEST_CASES_END() /**< NULL terminate unit test array */
+       }
+};
+
 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
        .suite_name = "Crypto Device AESNI MB Unit Test Suite",
        .setup = testsuite_setup,
@@ -9807,6 +9838,22 @@ test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
        return unit_test_suite_runner(&cryptodev_qat_testsuite);
 }
 
+static int
+test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
+{
+       gbl_driver_id = rte_cryptodev_driver_id_get(
+                       RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
+
+       if (gbl_driver_id == -1) {
+               RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded. Check if "
+                               "CONFIG_RTE_LIBRTE_PMD_VIRTIO_CRYPTO is enabled "
+                               "in config file to run this testsuite.\n");
+               return TEST_FAILED;
+       }
+
+       return unit_test_suite_runner(&cryptodev_virtio_testsuite);
+}
+
 static int
 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
 {
@@ -10040,3 +10087,4 @@ REGISTER_TEST_COMMAND(cryptodev_sw_mrvl_autotest, test_cryptodev_mrvl);
 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
+REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
index 9a01403..a630ee8 100644 (file)
@@ -63,6 +63,7 @@
 #define CRYPTODEV_NAME_SCHEDULER_PMD   crypto_scheduler
 #define CRYPTODEV_NAME_MRVL_PMD                crypto_mrvl
 #define CRYPTODEV_NAME_CCP_PMD         crypto_ccp
+#define CRYPTODEV_NAME_VIRTIO_PMD      crypto_virtio
 
 /**
  * Write (spread) data from buffer to mbuf data
index 6f2422a..724c1e0 100644 (file)
@@ -1544,7 +1544,8 @@ static const struct blockcipher_test_case aes_cipheronly_test_cases[] = {
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_MRVL |
-                       BLOCKCIPHER_TEST_TARGET_PMD_CCP
+                       BLOCKCIPHER_TEST_TARGET_PMD_CCP |
+                       BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
        },
        {
                .test_descr = "AES-128-CBC Decryption",
@@ -1557,7 +1558,8 @@ static const struct blockcipher_test_case aes_cipheronly_test_cases[] = {
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_MRVL |
-                       BLOCKCIPHER_TEST_TARGET_PMD_CCP
+                       BLOCKCIPHER_TEST_TARGET_PMD_CCP |
+                       BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
        },
        {
                .test_descr = "AES-192-CBC Encryption",
@@ -1569,7 +1571,8 @@ static const struct blockcipher_test_case aes_cipheronly_test_cases[] = {
                        BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
-                       BLOCKCIPHER_TEST_TARGET_PMD_CCP
+                       BLOCKCIPHER_TEST_TARGET_PMD_CCP |
+                       BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
        },
        {
                .test_descr = "AES-192-CBC Encryption Scater gather",
@@ -1591,7 +1594,8 @@ static const struct blockcipher_test_case aes_cipheronly_test_cases[] = {
                        BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
-                       BLOCKCIPHER_TEST_TARGET_PMD_CCP
+                       BLOCKCIPHER_TEST_TARGET_PMD_CCP |
+                       BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
        },
        {
                .test_descr = "AES-192-CBC Decryption Scatter Gather",
@@ -1612,7 +1616,8 @@ static const struct blockcipher_test_case aes_cipheronly_test_cases[] = {
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_MRVL |
-                       BLOCKCIPHER_TEST_TARGET_PMD_CCP
+                       BLOCKCIPHER_TEST_TARGET_PMD_CCP |
+                       BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
        },
        {
                .test_descr = "AES-256-CBC Decryption",
@@ -1625,7 +1630,8 @@ static const struct blockcipher_test_case aes_cipheronly_test_cases[] = {
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_MRVL |
-                       BLOCKCIPHER_TEST_TARGET_PMD_CCP
+                       BLOCKCIPHER_TEST_TARGET_PMD_CCP |
+                       BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
        },
        {
                .test_descr = "AES-256-CBC OOP Encryption",
@@ -1636,7 +1642,8 @@ static const struct blockcipher_test_case aes_cipheronly_test_cases[] = {
                        BLOCKCIPHER_TEST_TARGET_PMD_QAT |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
-                       BLOCKCIPHER_TEST_TARGET_PMD_CCP
+                       BLOCKCIPHER_TEST_TARGET_PMD_CCP |
+                       BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
        },
        {
                .test_descr = "AES-256-CBC OOP Decryption",
@@ -1647,7 +1654,8 @@ static const struct blockcipher_test_case aes_cipheronly_test_cases[] = {
                        BLOCKCIPHER_TEST_TARGET_PMD_QAT |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC |
                        BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC |
-                       BLOCKCIPHER_TEST_TARGET_PMD_CCP
+                       BLOCKCIPHER_TEST_TARGET_PMD_CCP |
+                       BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO
        },
        {
                .test_descr = "AES-128-CTR Encryption",
index 5835b3e..e51a124 100644 (file)
@@ -70,6 +70,8 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
                        RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
        int mrvl_pmd = rte_cryptodev_driver_id_get(
                        RTE_STR(CRYPTODEV_NAME_MRVL_PMD));
+       int virtio_pmd = rte_cryptodev_driver_id_get(
+                       RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
 
        int nb_segs = 1;
 
@@ -97,7 +99,8 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
                        driver_id == openssl_pmd ||
                        driver_id == armv8_pmd ||
                        driver_id == mrvl_pmd ||
-                       driver_id == ccp_pmd) { /* Fall through */
+                       driver_id == ccp_pmd ||
+                       driver_id == virtio_pmd) { /* Fall through */
                digest_len = tdata->digest.len;
        } else if (driver_id == aesni_mb_pmd ||
                        driver_id == scheduler_pmd) {
@@ -574,6 +577,8 @@ test_blockcipher_all_tests(struct rte_mempool *mbuf_pool,
                        RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
        int mrvl_pmd = rte_cryptodev_driver_id_get(
                        RTE_STR(CRYPTODEV_NAME_MRVL_PMD));
+       int virtio_pmd = rte_cryptodev_driver_id_get(
+                       RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
 
        switch (test_type) {
        case BLKCIPHER_AES_CHAIN_TYPE:
@@ -638,6 +643,8 @@ test_blockcipher_all_tests(struct rte_mempool *mbuf_pool,
                target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC;
        else if (driver_id == mrvl_pmd)
                target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MRVL;
+       else if (driver_id == virtio_pmd)
+               target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO;
        else
                TEST_ASSERT(0, "Unrecognized cryptodev type");
 
index 93ef0ae..4b88764 100644 (file)
@@ -28,6 +28,7 @@
 #define BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC   0x0040 /* DPAA_SEC flag */
 #define BLOCKCIPHER_TEST_TARGET_PMD_MRVL       0x0080 /* Marvell flag */
 #define BLOCKCIPHER_TEST_TARGET_PMD_CCP                0x0040 /* CCP flag */
+#define BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO     0x0200 /* VIRTIO flag */
 
 #define BLOCKCIPHER_TEST_OP_CIPHER     (BLOCKCIPHER_TEST_OP_ENCRYPT | \
                                        BLOCKCIPHER_TEST_OP_DECRYPT)