X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest%2Ftest_cryptodev_blockcipher.c;h=3cdb2c96e8e2ba7119f7fee4aea23f590db3d671;hb=95e0f23022a36d5d66957af3da7f2925b44a9a80;hp=473dad9629aaa60cd5fc3da6cf968bd34a77c744;hpb=b4c469ec4f3beef3117ffc62675d9672144c099f;p=dpdk.git diff --git a/app/test/test_cryptodev_blockcipher.c b/app/test/test_cryptodev_blockcipher.c index 473dad9629..3cdb2c96e8 100644 --- a/app/test/test_cryptodev_blockcipher.c +++ b/app/test/test_cryptodev_blockcipher.c @@ -11,7 +11,6 @@ #include #include -#include #include "test.h" #include "test_cryptodev.h" @@ -36,7 +35,8 @@ verify_algo_support(const struct blockcipher_test_case *t, if (capability == NULL) return -1; - if (cap_idx.algo.cipher != RTE_CRYPTO_CIPHER_NULL) + if (cap_idx.algo.cipher != RTE_CRYPTO_CIPHER_NULL && + !(t->test_data->wrapped_key)) ret = rte_cryptodev_sym_capability_check_cipher(capability, tdata->cipher_key.len, tdata->iv.len); @@ -94,6 +94,7 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t, uint8_t dst_pattern = 0xb6; uint8_t tmp_src_buf[MBUF_SIZE]; uint8_t tmp_dst_buf[MBUF_SIZE]; + uint32_t pad_len; int nb_segs = 1; uint32_t nb_iterates = 0; @@ -103,11 +104,20 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t, if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { - printf("Device doesn't support sesionless operations " + printf("Device doesn't support sessionless operations " "Test Skipped.\n"); snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED"); - return 0; + return TEST_SKIPPED; + } + } + if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_DIGEST_ENCRYPTED) { + if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { + printf("Device doesn't support encrypted digest " + "Test Skipped.\n"); + snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, + "SKIPPED"); + return TEST_SKIPPED; } } if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) { @@ -120,7 +130,7 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t, "Test Skipped.\n"); snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED"); - return 0; + return TEST_SKIPPED; } } else { if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { @@ -129,12 +139,26 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t, "Test Skipped.\n"); snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED"); - return 0; + return TEST_SKIPPED; } } nb_segs = 3; } + if (!!(feat_flags & RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY) ^ + tdata->wrapped_key) { + snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, + "SKIPPED"); + return TEST_SKIPPED; + } + + if (global_api_test_type == CRYPTODEV_RAW_API_TEST && + !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)) { + printf("Device doesn't support raw data-path APIs. " + "Test Skipped.\n"); + snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED"); + return TEST_SKIPPED; + } if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { uint64_t oop_flags = RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT | @@ -146,7 +170,14 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t, "Test Skipped.\n"); snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED"); - return 0; + return TEST_SKIPPED; + } + if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { + printf("Raw Data Path APIs do not support OOP, " + "Test Skipped.\n"); + snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED"); + status = TEST_SKIPPED; + goto error_exit; } } @@ -163,13 +194,17 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t, "Device does not support this algorithm." "Test Skipped.\n"); snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED"); - return 0; + return TEST_SKIPPED; } /* preparing data */ if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) buf_len += digest_len; + pad_len = RTE_ALIGN(buf_len, 16) - buf_len; + if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) + buf_len += pad_len; + /* for contiguous mbuf, nb_segs is 1 */ ibuf = create_segmented_mbuf(mbuf_pool, tdata->ciphertext.len, nb_segs, src_pattern); @@ -194,9 +229,31 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t, 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); + if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) + rte_memcpy(buf_p, + tdata->ciphertext.data + tdata->ciphertext.len, + digest_len); + else + rte_memcpy(buf_p, tdata->digest.data, digest_len); else memset(buf_p, 0, digest_len); + if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) { + buf_p = rte_pktmbuf_append(ibuf, pad_len); + if (!buf_p) { + snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " + "FAILED: %s", __LINE__, + "No room to append mbuf"); + status = TEST_FAILED; + goto error_exit; + } + if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) { + const uint8_t *temp_p = tdata->ciphertext.data + + tdata->ciphertext.len + + digest_len; + rte_memcpy(buf_p, temp_p, pad_len); + } else + memset(buf_p, 0xa5, pad_len); + } if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { obuf = rte_pktmbuf_alloc(mbuf_pool); @@ -209,7 +266,7 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t, } memset(obuf->buf_addr, dst_pattern, obuf->buf_len); - buf_p = rte_pktmbuf_append(obuf, buf_len); + buf_p = rte_pktmbuf_append(obuf, buf_len + pad_len); if (!buf_p) { snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " "FAILED: %s", __LINE__, @@ -344,6 +401,26 @@ iterate: cipher_xform->next = NULL; init_xform = auth_xform; } + } else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN_ENC) { + if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { + auth_xform = op->sym->xform; + cipher_xform = auth_xform->next; + cipher_xform->next = NULL; + } else { + auth_xform->next = cipher_xform; + cipher_xform->next = NULL; + init_xform = auth_xform; + } + } else if (t->op_mask == BLOCKCIPHER_TEST_OP_DEC_AUTH_VERIFY) { + if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { + cipher_xform = op->sym->xform; + auth_xform = cipher_xform->next; + auth_xform->next = NULL; + } else { + cipher_xform->next = auth_xform; + auth_xform->next = NULL; + init_xform = cipher_xform; + } } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_ENCRYPT) || (t->op_mask == BLOCKCIPHER_TEST_OP_DECRYPT)) { if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) @@ -379,11 +456,20 @@ iterate: cipher_xform->cipher.key.data = cipher_key; cipher_xform->cipher.key.length = tdata->cipher_key.len; cipher_xform->cipher.iv.offset = IV_OFFSET; - cipher_xform->cipher.iv.length = tdata->iv.len; + cipher_xform->cipher.dataunit_len = tdata->xts_dataunit_len; + + if (tdata->crypto_algo == RTE_CRYPTO_CIPHER_NULL) + cipher_xform->cipher.iv.length = 0; + else + cipher_xform->cipher.iv.length = tdata->iv.len; sym_op->cipher.data.offset = tdata->cipher_offset; sym_op->cipher.data.length = tdata->ciphertext.len - tdata->cipher_offset; + if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) { + sym_op->cipher.data.length += tdata->digest.len; + sym_op->cipher.data.length += pad_len; + } rte_memcpy(rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFFSET), tdata->iv.data, tdata->iv.len); @@ -427,9 +513,14 @@ iterate: nb_iterates == 0) { sess = rte_cryptodev_sym_session_create(sess_mpool); - rte_cryptodev_sym_session_init(dev_id, sess, init_xform, - sess_priv_mpool); - if (!sess) { + status = rte_cryptodev_sym_session_init(dev_id, sess, + init_xform, sess_priv_mpool); + if (status == -ENOTSUP) { + snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "UNSUPPORTED"); + status = TEST_SKIPPED; + goto error_exit; + } + if (!sess || status < 0) { snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " "FAILED: %s", __LINE__, "Session creation failed"); @@ -453,25 +544,36 @@ iterate: } /* Process crypto operation */ - if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { - snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, - "line %u FAILED: %s", - __LINE__, "Error sending packet for encryption"); - status = TEST_FAILED; - goto error_exit; - } + if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { + uint8_t is_cipher = 0, is_auth = 0; + if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) + is_cipher = 1; + if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) + is_auth = 1; - op = NULL; + process_sym_raw_dp_op(dev_id, 0, op, is_cipher, is_auth, 0, + tdata->iv.len); + } else { + if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { + snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, + "line %u FAILED: %s", + __LINE__, "Error sending packet for encryption"); + status = TEST_FAILED; + goto error_exit; + } - while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) - rte_pause(); + op = NULL; - if (!op) { - snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, - "line %u FAILED: %s", - __LINE__, "Failed to process sym crypto op"); - status = TEST_FAILED; - goto error_exit; + while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) + rte_pause(); + + if (!op) { + snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, + "line %u FAILED: %s", + __LINE__, "Failed to process sym crypto op"); + status = TEST_FAILED; + goto error_exit; + } } debug_hexdump(stdout, "m_src(after):", @@ -505,6 +607,8 @@ iterate: tdata->cipher_offset; compare_len = tdata->ciphertext.len - tdata->cipher_offset; + if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) + compare_len += tdata->digest.len; } else { compare_ref = tdata->plaintext.data + tdata->cipher_offset; @@ -523,18 +627,24 @@ iterate: } } - if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) { - uint8_t *auth_res = pktmbuf_mtod_offset(iobuf, - tdata->ciphertext.len); + /* Check digest data only in enc-then-auth_gen case. + * In auth_gen-then-enc case, cipher text contains both encrypted + * plain text and encrypted digest value. If cipher text is correct, + * it implies digest is also generated properly. + */ + if (!(t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED)) + if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) { + uint8_t *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 " - "FAILED: %s", __LINE__, "Generated " - "digest data not as expected"); - status = TEST_FAILED; - goto error_exit; + if (memcmp(auth_res, tdata->digest.data, digest_len)) { + snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " + "FAILED: %s", __LINE__, "Generated " + "digest data not as expected"); + status = TEST_FAILED; + goto error_exit; + } } - } /* The only parts that should have changed in the buffer are * plaintext/ciphertext and digest. @@ -596,6 +706,10 @@ iterate: changed_len = sym_op->cipher.data.length; } + if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) + changed_len = sym_op->cipher.data.length + + digest_len + pad_len; + for (i = 0; i < mbuf->buf_len; i++) { if (i == head_unchanged_len) i += changed_len; @@ -652,6 +766,9 @@ iterate: if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) changed_len += digest_len; + if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) + changed_len = sym_op->cipher.data.length; + for (i = 0; i < mbuf->buf_len; i++) { /* Skip headroom used by PMD */ @@ -703,83 +820,401 @@ error_exit: return status; } -int -test_blockcipher_all_tests(struct rte_mempool *mbuf_pool, - struct rte_mempool *op_mpool, - struct rte_mempool *sess_mpool, - struct rte_mempool *sess_priv_mpool, - uint8_t dev_id, - enum blockcipher_test_type test_type) +static int +blockcipher_test_case_run(const void *data) { - int status, overall_status = TEST_SUCCESS; - uint32_t i, test_index = 0; + const struct blockcipher_test_case *tc_data = data; + int status; char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1]; - uint32_t n_test_cases = 0; - const struct blockcipher_test_case *tcs = NULL; + + status = test_blockcipher_one_case(tc_data, + p_testsuite_params->mbuf_pool, + p_testsuite_params->op_mpool, + p_testsuite_params->session_mpool, + p_testsuite_params->session_priv_mpool, + p_testsuite_params->valid_devs[0], + test_msg); + return status; +} + +static int +aes_chain_setup(void) +{ + uint8_t dev_id = p_testsuite_params->valid_devs[0]; + struct rte_cryptodev_info dev_info; + uint64_t feat_flags; + const enum rte_crypto_cipher_algorithm ciphers[] = { + RTE_CRYPTO_CIPHER_NULL, + RTE_CRYPTO_CIPHER_AES_CTR, + RTE_CRYPTO_CIPHER_AES_CBC + }; + const enum rte_crypto_auth_algorithm auths[] = { + RTE_CRYPTO_AUTH_NULL, + RTE_CRYPTO_AUTH_SHA1_HMAC, + RTE_CRYPTO_AUTH_AES_XCBC_MAC, + RTE_CRYPTO_AUTH_SHA256_HMAC, + RTE_CRYPTO_AUTH_SHA512_HMAC, + RTE_CRYPTO_AUTH_SHA224_HMAC, + RTE_CRYPTO_AUTH_SHA384_HMAC + }; + + rte_cryptodev_info_get(dev_id, &dev_info); + feat_flags = dev_info.feature_flags; + + if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || + ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && + !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { + RTE_LOG(INFO, USER1, "Feature flag requirements for AES Chain " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 + && check_auth_capabilities_supported(auths, + RTE_DIM(auths)) != 0) { + RTE_LOG(INFO, USER1, "Capability requirements for AES Chain " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + return 0; +} + +static int +aes_cipheronly_setup(void) +{ + uint8_t dev_id = p_testsuite_params->valid_devs[0]; + struct rte_cryptodev_info dev_info; + uint64_t feat_flags; + const enum rte_crypto_cipher_algorithm ciphers[] = { + RTE_CRYPTO_CIPHER_NULL, + RTE_CRYPTO_CIPHER_AES_CTR, + RTE_CRYPTO_CIPHER_AES_CBC, + RTE_CRYPTO_CIPHER_AES_ECB, + RTE_CRYPTO_CIPHER_AES_XTS + }; + const enum rte_crypto_auth_algorithm auths[] = { + RTE_CRYPTO_AUTH_NULL, + RTE_CRYPTO_AUTH_SHA1_HMAC, + RTE_CRYPTO_AUTH_AES_XCBC_MAC + }; + + rte_cryptodev_info_get(dev_id, &dev_info); + feat_flags = dev_info.feature_flags; + + if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || + ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && + !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { + RTE_LOG(INFO, USER1, "Feature flag requirements for AES Cipheronly " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 + && check_auth_capabilities_supported(auths, + RTE_DIM(auths)) != 0) { + RTE_LOG(INFO, USER1, "Capability requirements for AES Cipheronly " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + return 0; +} + +static int +aes_docsis_setup(void) +{ + uint8_t dev_id = p_testsuite_params->valid_devs[0]; + struct rte_cryptodev_info dev_info; + uint64_t feat_flags; + const enum rte_crypto_cipher_algorithm ciphers[] = { + RTE_CRYPTO_CIPHER_AES_DOCSISBPI + }; + + rte_cryptodev_info_get(dev_id, &dev_info); + feat_flags = dev_info.feature_flags; + + /* Data-path service does not support DOCSIS yet */ + if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || + (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { + RTE_LOG(INFO, USER1, "Feature flag requirements for AES Docsis " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { + RTE_LOG(INFO, USER1, "Capability requirements for AES Docsis " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + return 0; +} + +static int +triple_des_chain_setup(void) +{ + uint8_t dev_id = p_testsuite_params->valid_devs[0]; + struct rte_cryptodev_info dev_info; + uint64_t feat_flags; + const enum rte_crypto_cipher_algorithm ciphers[] = { + RTE_CRYPTO_CIPHER_3DES_CTR, + RTE_CRYPTO_CIPHER_3DES_CBC + }; + const enum rte_crypto_auth_algorithm auths[] = { + RTE_CRYPTO_AUTH_SHA1_HMAC, + RTE_CRYPTO_AUTH_SHA1 + }; + + rte_cryptodev_info_get(dev_id, &dev_info); + feat_flags = dev_info.feature_flags; + + if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || + ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && + !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { + RTE_LOG(INFO, USER1, "Feature flag requirements for 3DES Chain " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 + && check_auth_capabilities_supported(auths, + RTE_DIM(auths)) != 0) { + RTE_LOG(INFO, USER1, "Capability requirements for 3DES Chain " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + return 0; +} + +static int +triple_des_cipheronly_setup(void) +{ + uint8_t dev_id = p_testsuite_params->valid_devs[0]; + struct rte_cryptodev_info dev_info; + uint64_t feat_flags; + const enum rte_crypto_cipher_algorithm ciphers[] = { + RTE_CRYPTO_CIPHER_3DES_CTR, + RTE_CRYPTO_CIPHER_3DES_CBC + }; + + rte_cryptodev_info_get(dev_id, &dev_info); + feat_flags = dev_info.feature_flags; + + if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || + ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && + !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { + RTE_LOG(INFO, USER1, "Feature flag requirements for 3DES " + "Cipheronly testsuite not met\n"); + return TEST_SKIPPED; + } + + if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { + RTE_LOG(INFO, USER1, "Capability requirements for 3DES " + "Cipheronly testsuite not met\n"); + return TEST_SKIPPED; + } + + return 0; +} + +static int +des_cipheronly_setup(void) +{ + uint8_t dev_id = p_testsuite_params->valid_devs[0]; + struct rte_cryptodev_info dev_info; + uint64_t feat_flags; + const enum rte_crypto_cipher_algorithm ciphers[] = { + RTE_CRYPTO_CIPHER_DES_CBC + }; + + rte_cryptodev_info_get(dev_id, &dev_info); + feat_flags = dev_info.feature_flags; + + if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || + ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && + !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { + RTE_LOG(INFO, USER1, "Feature flag requirements for DES " + "Cipheronly testsuite not met\n"); + return TEST_SKIPPED; + } + + if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { + RTE_LOG(INFO, USER1, "Capability requirements for DES " + "Cipheronly testsuite not met\n"); + return TEST_SKIPPED; + } + + return 0; +} + +static int +des_docsis_setup(void) +{ + uint8_t dev_id = p_testsuite_params->valid_devs[0]; + struct rte_cryptodev_info dev_info; + uint64_t feat_flags; + const enum rte_crypto_cipher_algorithm ciphers[] = { + RTE_CRYPTO_CIPHER_DES_DOCSISBPI + }; + + rte_cryptodev_info_get(dev_id, &dev_info); + feat_flags = dev_info.feature_flags; + + /* Data-path service does not support DOCSIS yet */ + if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || + (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { + RTE_LOG(INFO, USER1, "Feature flag requirements for DES Docsis " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { + RTE_LOG(INFO, USER1, "Capability requirements for DES Docsis " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + return 0; +} + +static int +authonly_setup(void) +{ + uint8_t dev_id = p_testsuite_params->valid_devs[0]; + struct rte_cryptodev_info dev_info; + uint64_t feat_flags; + const enum rte_crypto_auth_algorithm auths[] = { + RTE_CRYPTO_AUTH_MD5, + RTE_CRYPTO_AUTH_MD5_HMAC, + RTE_CRYPTO_AUTH_SHA1, + RTE_CRYPTO_AUTH_SHA1_HMAC, + RTE_CRYPTO_AUTH_SHA224, + RTE_CRYPTO_AUTH_SHA224_HMAC, + RTE_CRYPTO_AUTH_SHA256, + RTE_CRYPTO_AUTH_SHA256_HMAC, + RTE_CRYPTO_AUTH_SHA384, + RTE_CRYPTO_AUTH_SHA384_HMAC, + RTE_CRYPTO_AUTH_SHA512, + RTE_CRYPTO_AUTH_SHA512_HMAC, + RTE_CRYPTO_AUTH_AES_CMAC, + RTE_CRYPTO_AUTH_NULL, + RTE_CRYPTO_AUTH_AES_XCBC_MAC + }; + + rte_cryptodev_info_get(dev_id, &dev_info); + feat_flags = dev_info.feature_flags; + + if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || + ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && + !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { + RTE_LOG(INFO, USER1, "Feature flag requirements for Auth Only " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { + RTE_LOG(INFO, USER1, "Capability requirements for Auth Only " + "testsuite not met\n"); + return TEST_SKIPPED; + } + + return 0; +} + +struct unit_test_suite * +build_blockcipher_test_suite(enum blockcipher_test_type test_type) +{ + int i, n_test_cases = 0; + struct unit_test_suite *ts; + const char *ts_name = NULL; + const struct blockcipher_test_case *blk_tcs; + struct unit_test_case *tc; + int (*ts_setup)(void) = NULL; switch (test_type) { case BLKCIPHER_AES_CHAIN_TYPE: - n_test_cases = sizeof(aes_chain_test_cases) / - sizeof(aes_chain_test_cases[0]); - tcs = aes_chain_test_cases; + n_test_cases = RTE_DIM(aes_chain_test_cases); + blk_tcs = aes_chain_test_cases; + ts_name = "AES Chain"; + ts_setup = aes_chain_setup; break; case BLKCIPHER_AES_CIPHERONLY_TYPE: - n_test_cases = sizeof(aes_cipheronly_test_cases) / - sizeof(aes_cipheronly_test_cases[0]); - tcs = aes_cipheronly_test_cases; + n_test_cases = RTE_DIM(aes_cipheronly_test_cases); + blk_tcs = aes_cipheronly_test_cases; + ts_name = "AES Cipher Only"; + ts_setup = aes_cipheronly_setup; break; case BLKCIPHER_AES_DOCSIS_TYPE: - n_test_cases = sizeof(aes_docsis_test_cases) / - sizeof(aes_docsis_test_cases[0]); - tcs = aes_docsis_test_cases; + n_test_cases = RTE_DIM(aes_docsis_test_cases); + blk_tcs = aes_docsis_test_cases; + ts_name = "AES Docsis"; + ts_setup = aes_docsis_setup; break; case BLKCIPHER_3DES_CHAIN_TYPE: - n_test_cases = sizeof(triple_des_chain_test_cases) / - sizeof(triple_des_chain_test_cases[0]); - tcs = triple_des_chain_test_cases; + n_test_cases = RTE_DIM(triple_des_chain_test_cases); + blk_tcs = triple_des_chain_test_cases; + ts_name = "3DES Chain"; + ts_setup = triple_des_chain_setup; break; case BLKCIPHER_3DES_CIPHERONLY_TYPE: - n_test_cases = sizeof(triple_des_cipheronly_test_cases) / - sizeof(triple_des_cipheronly_test_cases[0]); - tcs = triple_des_cipheronly_test_cases; + n_test_cases = RTE_DIM(triple_des_cipheronly_test_cases); + blk_tcs = triple_des_cipheronly_test_cases; + ts_name = "3DES Cipher Only"; + ts_setup = triple_des_cipheronly_setup; break; case BLKCIPHER_DES_CIPHERONLY_TYPE: - n_test_cases = sizeof(des_cipheronly_test_cases) / - sizeof(des_cipheronly_test_cases[0]); - tcs = des_cipheronly_test_cases; + n_test_cases = RTE_DIM(des_cipheronly_test_cases); + blk_tcs = des_cipheronly_test_cases; + ts_name = "DES Cipher Only"; + ts_setup = des_cipheronly_setup; break; case BLKCIPHER_DES_DOCSIS_TYPE: - n_test_cases = sizeof(des_docsis_test_cases) / - sizeof(des_docsis_test_cases[0]); - tcs = des_docsis_test_cases; + n_test_cases = RTE_DIM(des_docsis_test_cases); + blk_tcs = des_docsis_test_cases; + ts_name = "DES Docsis"; + ts_setup = des_docsis_setup; break; case BLKCIPHER_AUTHONLY_TYPE: - n_test_cases = sizeof(hash_test_cases) / - sizeof(hash_test_cases[0]); - tcs = hash_test_cases; + n_test_cases = RTE_DIM(hash_test_cases); + blk_tcs = hash_test_cases; + ts_name = "Auth Only"; + ts_setup = authonly_setup; break; default: - break; + return NULL; } - for (i = 0; i < n_test_cases; i++) { - const struct blockcipher_test_case *tc = &tcs[i]; - - status = test_blockcipher_one_case(tc, mbuf_pool, op_mpool, - sess_mpool, sess_priv_mpool, dev_id, - test_msg); - - printf(" %u) TestCase %s %s\n", test_index ++, - tc->test_descr, test_msg); - - if (status != TEST_SUCCESS) { - if (overall_status == TEST_SUCCESS) - overall_status = status; + ts = calloc(1, sizeof(struct unit_test_suite) + + (sizeof(struct unit_test_case) * (n_test_cases + 1))); + ts->suite_name = ts_name; + ts->setup = ts_setup; - if (tc->feature_mask & BLOCKCIPHER_TEST_FEATURE_STOPPER) - break; - } + for (i = 0; i < n_test_cases; i++) { + tc = &ts->unit_test_cases[i]; + tc->name = blk_tcs[i].test_descr; + tc->enabled = 1; + tc->setup = ut_setup; + tc->teardown = ut_teardown; + tc->testcase = NULL; + tc->testcase_with_data = blockcipher_test_case_run; + tc->data = &blk_tcs[i]; } + tc = &ts->unit_test_cases[i]; + tc->name = NULL; + tc->enabled = 0; + tc->setup = NULL; + tc->teardown = NULL; + tc->testcase = NULL; + tc->testcase_with_data = NULL; + tc->data = NULL; + + return ts; +} - return overall_status; +void +free_blockcipher_test_suite(struct unit_test_suite *ts) +{ + free(ts); }