test/crypto: add session-less cases in asym mod exp
[dpdk.git] / app / test / test_cryptodev_asym.c
index 95e7d34..ea3005b 100644 (file)
@@ -283,7 +283,7 @@ test_cryptodev_asym_ver(union test_case_structure *data_tc,
 static int
 test_cryptodev_asym_op(struct crypto_testsuite_params *ts_params,
        union test_case_structure *data_tc,
-       char *test_msg)
+       char *test_msg, int sessionless)
 {
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL;
@@ -382,27 +382,31 @@ test_cryptodev_asym_op(struct crypto_testsuite_params *ts_params,
                goto error_exit;
        }
 
-       sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
-       if (!sess) {
-               snprintf(test_msg, ASYM_TEST_MSG_LEN,
-                               "line %u "
-                               "FAILED: %s", __LINE__,
-                               "Session creation failed");
-               status = TEST_FAILED;
-               goto error_exit;
-       }
-
-       if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
-                       ts_params->session_mpool) < 0) {
-               snprintf(test_msg, ASYM_TEST_MSG_LEN,
-                               "line %u FAILED: %s",
-                               __LINE__, "unabled to config sym session");
-               status = TEST_FAILED;
-               goto error_exit;
-       }
+       if (!sessionless) {
+               sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
+               if (!sess) {
+                       snprintf(test_msg, ASYM_TEST_MSG_LEN,
+                                       "line %u "
+                                       "FAILED: %s", __LINE__,
+                                       "Session creation failed");
+                       status = TEST_FAILED;
+                       goto error_exit;
+               }
 
-       rte_crypto_op_attach_asym_session(op, sess);
+               if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
+                               ts_params->session_mpool) < 0) {
+                       snprintf(test_msg, ASYM_TEST_MSG_LEN,
+                                       "line %u FAILED: %s",
+                                       __LINE__, "unabled to config sym session");
+                       status = TEST_FAILED;
+                       goto error_exit;
+               }
 
+               rte_crypto_op_attach_asym_session(op, sess);
+       } else {
+               asym_op->xform = &xform_tc;
+               op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
+       }
        RTE_LOG(DEBUG, USER1, "Process ASYM operation");
 
        /* Process crypto operation */
@@ -433,7 +437,10 @@ test_cryptodev_asym_op(struct crypto_testsuite_params *ts_params,
                goto error_exit;
        }
 
-       snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
+       if (!sessionless)
+               snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
+       else
+               snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
 
 error_exit:
                if (sess != NULL) {
@@ -451,7 +458,7 @@ error_exit:
 }
 
 static int
-test_one_case(const void *test_case)
+test_one_case(const void *test_case, int sessionless)
 {
        int status = TEST_SUCCESS;
        char test_msg[ASYM_TEST_MSG_LEN + 1];
@@ -460,7 +467,8 @@ test_one_case(const void *test_case)
        union test_case_structure tc;
        memcpy(&tc, test_case, sizeof(tc));
 
-       status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg);
+       status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg,
+                       sessionless);
 
        printf("  %u) TestCase %s %s\n", test_index++,
                tc.modex.description, test_msg);
@@ -501,14 +509,31 @@ static int
 test_one_by_one(void)
 {
        int status = TEST_SUCCESS;
+       struct crypto_testsuite_params *ts_params = &testsuite_params;
        uint32_t i = 0;
+       uint8_t dev_id = ts_params->valid_devs[0];
+       struct rte_cryptodev_info dev_info;
+       int sessionless = 0;
+
+       rte_cryptodev_info_get(dev_id, &dev_info);
+       if ((dev_info.feature_flags &
+                       RTE_CRYPTODEV_FF_ASYM_SESSIONLESS)) {
+               sessionless = 1;
+       }
 
        /* Go through all test cases */
        test_index = 0;
        for (i = 0; i < test_vector.size; i++) {
-               if (test_one_case(test_vector.address[i]) != TEST_SUCCESS)
+               if (test_one_case(test_vector.address[i], 0) != TEST_SUCCESS)
                        status = TEST_FAILED;
        }
+       if (sessionless) {
+               for (i = 0; i < test_vector.size; i++) {
+                       if (test_one_case(test_vector.address[i], 1)
+                                       != TEST_SUCCESS)
+                               status = TEST_FAILED;
+               }
+       }
 
        TEST_ASSERT_EQUAL(status, 0, "Test failed");
        return status;
@@ -710,9 +735,10 @@ static int
 testsuite_setup(void)
 {
        struct crypto_testsuite_params *ts_params = &testsuite_params;
+       uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
        struct rte_cryptodev_info info;
-       uint32_t i = 0, nb_devs, dev_id;
-       int ret;
+       int ret, dev_id = -1;
+       uint32_t i, nb_devs;
        uint16_t qp_id;
 
        memset(ts_params, 0, sizeof(*ts_params));
@@ -748,36 +774,36 @@ testsuite_setup(void)
                }
        }
 
-       nb_devs = rte_cryptodev_count();
+       /* Get list of valid crypto devs */
+       nb_devs = rte_cryptodev_devices_get(
+                               rte_cryptodev_driver_name_get(gbl_driver_id),
+                               valid_devs, RTE_CRYPTO_MAX_DEVS);
        if (nb_devs < 1) {
                RTE_LOG(ERR, USER1, "No crypto devices found?\n");
                return TEST_FAILED;
        }
 
-       /* Create list of valid crypto devs */
-       for (i = 0; i < nb_devs; i++) {
-               rte_cryptodev_info_get(i, &info);
-               if (info.driver_id == gbl_driver_id)
-                       ts_params->valid_devs[ts_params->valid_dev_count++] = i;
+       /*
+        * Get first valid asymmetric device found in test suite param and
+        * break
+        */
+       for (i = 0; i < nb_devs ; i++) {
+               rte_cryptodev_info_get(valid_devs[i], &info);
+               if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
+                       dev_id = ts_params->valid_devs[0] = valid_devs[i];
+                       break;
+               }
        }
 
-       if (ts_params->valid_dev_count < 1)
-               return TEST_FAILED;
-
-       /* Set up all the qps on the first of the valid devices found */
-
-       dev_id = ts_params->valid_devs[0];
-
-       rte_cryptodev_info_get(dev_id, &info);
-
-       /* check if device support asymmetric, skip if not */
-       if (!(info.feature_flags &
-                               RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
+       if (dev_id == -1) {
                RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
-                               "Test Skipped.\n");
+                       "Test skipped.\n");
                return TEST_FAILED;
        }
 
+       /* Set valid device count */
+       ts_params->valid_dev_count = nb_devs;
+
        /* configure device with num qp */
        ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
        ts_params->conf.socket_id = SOCKET_ID_ANY;
@@ -1790,6 +1816,19 @@ static struct unit_test_suite cryptodev_qat_asym_testsuite  = {
        }
 };
 
+static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
+       .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
+       .setup = testsuite_setup,
+       .teardown = testsuite_teardown,
+       .unit_test_cases = {
+               TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
+               TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
+               TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
+               TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
+               TEST_CASES_END() /**< NULL terminate unit test array */
+       }
+};
+
 static int
 test_cryptodev_openssl_asym(void)
 {
@@ -1822,7 +1861,45 @@ test_cryptodev_qat_asym(void)
        return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
 }
 
+static int
+test_cryptodev_octeontx_asym(void)
+{
+       gbl_driver_id = rte_cryptodev_driver_id_get(
+                       RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
+       if (gbl_driver_id == -1) {
+               RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded. Check if "
+                               "CONFIG_RTE_LIBRTE_PMD_OCTEONTX_CRYPTO is "
+                               "enabled in config file to run this "
+                               "testsuite.\n");
+               return TEST_FAILED;
+       }
+       return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
+}
+
+static int
+test_cryptodev_octeontx2_asym(void)
+{
+       gbl_driver_id = rte_cryptodev_driver_id_get(
+                       RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
+       if (gbl_driver_id == -1) {
+               RTE_LOG(ERR, USER1, "OCTEONTX2 PMD must be loaded. Check if "
+                               "CONFIG_RTE_LIBRTE_PMD_OCTEONTX2_CRYPTO is "
+                               "enabled in config file to run this "
+                               "testsuite.\n");
+               return TEST_FAILED;
+       }
+
+       /* Use test suite registered for crypto_octeontx PMD */
+       return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
+}
+
 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
                                          test_cryptodev_openssl_asym);
 
 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
+
+REGISTER_TEST_COMMAND(cryptodev_octeontx_asym_autotest,
+                                         test_cryptodev_octeontx_asym);
+
+REGISTER_TEST_COMMAND(cryptodev_octeontx2_asym_autotest,
+                                         test_cryptodev_octeontx2_asym);