test/threads: add unit test
[dpdk.git] / app / test / test_cryptodev_asym.c
index e3eb0e3..573af2a 100644 (file)
@@ -317,7 +317,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
        uint8_t input[TEST_DATA_SIZE] = {0};
        uint8_t *result = NULL;
 
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
 
        xform_tc.next = NULL;
        xform_tc.xform_type = data_tc->modex.xform_type;
@@ -452,14 +452,14 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
        }
 
        if (!sessionless) {
-               sess = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
-                               ts_params->session_mpool);
-               if (!sess) {
+               ret = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
+                               ts_params->session_mpool, &sess);
+               if (ret < 0) {
                        snprintf(test_msg, ASYM_TEST_MSG_LEN,
                                        "line %u "
                                        "FAILED: %s", __LINE__,
                                        "Session creation failed");
-                       status = TEST_FAILED;
+                       status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                        goto error_exit;
                }
 
@@ -549,7 +549,7 @@ test_one_case(const void *test_case, int sessionless)
                                                status = test_cryptodev_asym_op(
                                                        &testsuite_params,
                                                        &tc, test_msg, sessionless, i,
-                                                       RTE_RSA_KET_TYPE_QT);
+                                                       RTE_RSA_KEY_TYPE_QT);
                                        }
                                        if (status)
                                                break;
@@ -645,7 +645,7 @@ test_rsa_sign_verify(void)
        uint8_t dev_id = ts_params->valid_devs[0];
        void *sess = NULL;
        struct rte_cryptodev_info dev_info;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
 
        /* Test case supports op with exponent key only,
         * Check in PMD feature flag for RSA exponent key type support.
@@ -658,12 +658,12 @@ test_rsa_sign_verify(void)
                return TEST_SKIPPED;
        }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+       ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-       if (!sess) {
+       if (ret < 0) {
                RTE_LOG(ERR, USER1, "Session creation failed for "
                        "sign_verify\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -685,7 +685,7 @@ test_rsa_enc_dec(void)
        uint8_t dev_id = ts_params->valid_devs[0];
        void *sess = NULL;
        struct rte_cryptodev_info dev_info;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
 
        /* Test case supports op with exponent key only,
         * Check in PMD feature flag for RSA exponent key type support.
@@ -698,11 +698,11 @@ test_rsa_enc_dec(void)
                return TEST_SKIPPED;
        }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+       ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-       if (!sess) {
+       if (ret < 0) {
                RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -725,7 +725,7 @@ test_rsa_sign_verify_crt(void)
        uint8_t dev_id = ts_params->valid_devs[0];
        void *sess = NULL;
        struct rte_cryptodev_info dev_info;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
 
        /* Test case supports op with quintuple format key only,
         * Check im PMD feature flag for RSA quintuple key type support.
@@ -737,12 +737,12 @@ test_rsa_sign_verify_crt(void)
                return TEST_SKIPPED;
        }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+       ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-       if (!sess) {
+       if (ret < 0) {
                RTE_LOG(ERR, USER1, "Session creation failed for "
                        "sign_verify_crt\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -765,7 +765,7 @@ test_rsa_enc_dec_crt(void)
        uint8_t dev_id = ts_params->valid_devs[0];
        void *sess = NULL;
        struct rte_cryptodev_info dev_info;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
 
        /* Test case supports op with quintuple format key only,
         * Check in PMD feature flag for RSA quintuple key type support.
@@ -777,12 +777,12 @@ test_rsa_enc_dec_crt(void)
                return TEST_SKIPPED;
        }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+       ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-       if (!sess) {
+       if (ret < 0) {
                RTE_LOG(ERR, USER1, "Session creation failed for "
                        "enc_dec_crt\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1046,7 +1046,7 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL, *result_op = NULL;
        void *sess = NULL;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
        uint8_t output[TEST_DH_MOD_LEN];
        struct rte_crypto_asym_xform xform = *xfrm;
        uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
@@ -1073,12 +1073,12 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
        asym_op->dh.shared_secret.data = output;
        asym_op->dh.shared_secret.length = sizeof(output);
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1129,7 +1129,7 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL, *result_op = NULL;
        void *sess = NULL;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
        uint8_t output[TEST_DH_MOD_LEN];
        struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1151,12 +1151,12 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
        asym_op->dh.priv_key.data = output;
        asym_op->dh.priv_key.length = sizeof(output);
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1210,7 +1210,7 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL, *result_op = NULL;
        void *sess = NULL;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
        uint8_t output[TEST_DH_MOD_LEN];
        struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1240,12 +1240,12 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
                                        0);
        asym_op->dh.priv_key = dh_test_params.priv_key;
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1299,7 +1299,7 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL, *result_op = NULL;
        void *sess = NULL;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
        uint8_t out_pub_key[TEST_DH_MOD_LEN];
        uint8_t out_prv_key[TEST_DH_MOD_LEN];
        struct rte_crypto_asym_xform pub_key_xform;
@@ -1329,12 +1329,12 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
        asym_op->dh.priv_key.data = out_prv_key;
        asym_op->dh.priv_key.length = sizeof(out_prv_key);
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1418,12 +1418,12 @@ test_mod_inv(void)
                                return TEST_SKIPPED;
                }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool);
-       if (!sess) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1, "line %u "
                                "FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1542,13 +1542,13 @@ test_mod_exp(void)
                goto error_exit;
        }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool);
-       if (!sess) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                 "line %u "
                                "FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1652,13 +1652,14 @@ test_dsa_sign(void)
        uint8_t r[TEST_DH_MOD_LEN];
        uint8_t s[TEST_DH_MOD_LEN];
        uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
+       int ret;
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                 "line %u FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
        /* set up crypto op data structure */
@@ -1787,7 +1788,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
        struct rte_crypto_asym_op *asym_op;
        struct rte_cryptodev_info dev_info;
        struct rte_crypto_op *op = NULL;
-       int status = TEST_SUCCESS, ret;
+       int ret, status = TEST_SUCCESS;
 
        switch (curve_id) {
        case SECP192R1:
@@ -1832,12 +1833,12 @@ test_ecdsa_sign_verify(enum curve curve_id)
        xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
        xform.ec.curve_id = input_params.curve;
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto exit;
        }
 
@@ -1989,7 +1990,7 @@ test_ecpm(enum curve curve_id)
        struct rte_crypto_asym_op *asym_op;
        struct rte_cryptodev_info dev_info;
        struct rte_crypto_op *op = NULL;
-       int status = TEST_SUCCESS, ret;
+       int ret, status = TEST_SUCCESS;
 
        switch (curve_id) {
        case SECP192R1:
@@ -2034,12 +2035,12 @@ test_ecpm(enum curve curve_id)
        xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
        xform.ec.curve_id = input_params.curve;
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto exit;
        }