X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest%2Ftest_ipsec.c;h=c6d6b88d6d9e84990445c12b9128382a212dd752;hb=f0243339496d48e6f5d76e6ef6741d6986b965d0;hp=0667dd021e63200b9ee2407daf2d1c8edb6e162f;hpb=3feaf4127ccc9abe7fa04d66de7afb59e5b78ddc;p=dpdk.git diff --git a/app/test/test_ipsec.c b/app/test/test_ipsec.c index 0667dd021e..c6d6b88d6d 100644 --- a/app/test/test_ipsec.c +++ b/app/test/test_ipsec.c @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -237,7 +236,7 @@ fill_crypto_xform(struct ipsec_unitest_params *ut_params, } static int -check_cryptodev_capablity(const struct ipsec_unitest_params *ut, +check_cryptodev_capability(const struct ipsec_unitest_params *ut, uint8_t dev_id) { struct rte_cryptodev_sym_capability_idx cap_idx; @@ -302,7 +301,7 @@ testsuite_setup(void) /* Find first valid crypto device */ for (i = 0; i < nb_devs; i++) { - rc = check_cryptodev_capablity(ut_params, i); + rc = check_cryptodev_capability(ut_params, i); if (rc == 0) { ts_params->valid_dev = i; ts_params->valid_dev_found = 1; @@ -424,7 +423,7 @@ testsuite_teardown(void) } static int -ut_setup(void) +ut_setup_ipsec(void) { struct ipsec_testsuite_params *ts_params = &testsuite_params; struct ipsec_unitest_params *ut_params = &unittest_params; @@ -444,7 +443,7 @@ ut_setup(void) } static void -ut_teardown(void) +ut_teardown_ipsec(void) { struct ipsec_testsuite_params *ts_params = &testsuite_params; struct ipsec_unitest_params *ut_params = &unittest_params; @@ -452,8 +451,10 @@ ut_teardown(void) for (i = 0; i < BURST_SIZE; i++) { /* free crypto operation structure */ - if (ut_params->cop[i]) + if (ut_params->cop[i]) { rte_crypto_op_free(ut_params->cop[i]); + ut_params->cop[i] = NULL; + } /* * free mbuf - both obuf and ibuf are usually the same, @@ -463,17 +464,17 @@ ut_teardown(void) if (ut_params->obuf[i]) { rte_pktmbuf_free(ut_params->obuf[i]); if (ut_params->ibuf[i] == ut_params->obuf[i]) - ut_params->ibuf[i] = 0; - ut_params->obuf[i] = 0; + ut_params->ibuf[i] = NULL; + ut_params->obuf[i] = NULL; } if (ut_params->ibuf[i]) { rte_pktmbuf_free(ut_params->ibuf[i]); - ut_params->ibuf[i] = 0; + ut_params->ibuf[i] = NULL; } if (ut_params->testbuf[i]) { rte_pktmbuf_free(ut_params->testbuf[i]); - ut_params->testbuf[i] = 0; + ut_params->testbuf[i] = NULL; } } @@ -572,7 +573,7 @@ setup_test_string_tunneled(struct rte_mempool *mpool, const char *string, struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); uint32_t hdrlen = sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_esp_hdr); - uint32_t taillen = sizeof(struct esp_tail); + uint32_t taillen = sizeof(struct rte_esp_tail); uint32_t t_len = len + hdrlen + taillen; uint32_t padlen; @@ -584,7 +585,7 @@ setup_test_string_tunneled(struct rte_mempool *mpool, const char *string, padlen = RTE_ALIGN(t_len, 4) - t_len; t_len += padlen; - struct esp_tail espt = { + struct rte_esp_tail espt = { .pad_len = padlen, .next_proto = IPPROTO_IPIP, }; @@ -630,7 +631,8 @@ create_dummy_sec_session(struct ipsec_unitest_params *ut, static struct rte_security_session_conf conf; ut->ss[j].security.ses = rte_security_session_create(&dummy_sec_ctx, - &conf, qp->mp_session_private); + &conf, qp->mp_session, + qp->mp_session_private); if (ut->ss[j].security.ses == NULL) return -ENOMEM; @@ -687,11 +689,11 @@ fill_ipsec_param(uint32_t replay_win_sz, uint64_t flags) prm->userdata = 1; prm->flags = flags; - prm->replay_win_sz = replay_win_sz; /* setup ipsec xform */ prm->ipsec_xform = ut_params->ipsec_xform; prm->ipsec_xform.salt = (uint32_t)rte_rand(); + prm->ipsec_xform.replay_win_sz = replay_win_sz; /* setup tunnel related fields */ prm->tun.hdr_len = sizeof(ipv4_outer); @@ -741,7 +743,7 @@ create_sa(enum rte_security_session_action_type action_type, ut->ss[j].type = action_type; rc = create_session(ut, &ts->qp_conf, ts->valid_dev, j); if (rc != 0) - return TEST_FAILED; + return rc; rc = rte_ipsec_sa_init(ut->ss[j].sa, &ut->sa_prm, sz); rc = (rc > 0 && (uint32_t)rc <= sz) ? 0 : -EINVAL; @@ -1165,15 +1167,44 @@ test_ipsec_dump_buffers(struct ipsec_unitest_params *ut_params, int i) } } +static void +destroy_dummy_sec_session(struct ipsec_unitest_params *ut, + uint32_t j) +{ + rte_security_session_destroy(&dummy_sec_ctx, + ut->ss[j].security.ses); + ut->ss[j].security.ctx = NULL; +} + +static void +destroy_crypto_session(struct ipsec_unitest_params *ut, + uint8_t crypto_dev, uint32_t j) +{ + rte_cryptodev_sym_session_clear(crypto_dev, ut->ss[j].crypto.ses); + rte_cryptodev_sym_session_free(ut->ss[j].crypto.ses); + memset(&ut->ss[j], 0, sizeof(ut->ss[j])); +} + +static void +destroy_session(struct ipsec_unitest_params *ut, + uint8_t crypto_dev, uint32_t j) +{ + if (ut->ss[j].type == RTE_SECURITY_ACTION_TYPE_NONE) + return destroy_crypto_session(ut, crypto_dev, j); + else + return destroy_dummy_sec_session(ut, j); +} + static void destroy_sa(uint32_t j) { struct ipsec_unitest_params *ut = &unittest_params; + struct ipsec_testsuite_params *ts = &testsuite_params; rte_ipsec_sa_fini(ut->ss[j].sa); rte_free(ut->ss[j].sa); - rte_cryptodev_sym_session_free(ut->ss[j].crypto.ses); - memset(&ut->ss[j], 0, sizeof(ut->ss[j])); + + destroy_session(ut, ts->valid_dev, j); } static int @@ -1215,7 +1246,7 @@ test_ipsec_crypto_inb_burst_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* Generate test mbuf data */ @@ -1317,7 +1348,7 @@ test_ipsec_crypto_outb_burst_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* Generate input mbuf data */ @@ -1426,7 +1457,7 @@ test_ipsec_inline_crypto_inb_burst_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* Generate inbound mbuf data */ @@ -1504,7 +1535,7 @@ test_ipsec_inline_proto_inb_burst_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* Generate inbound mbuf data */ @@ -1612,7 +1643,7 @@ test_ipsec_inline_crypto_outb_burst_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* Generate test mbuf data */ @@ -1690,7 +1721,7 @@ test_ipsec_inline_proto_outb_burst_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* Generate test mbuf data */ @@ -1766,7 +1797,7 @@ test_ipsec_lksd_proto_inb_burst_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* Generate test mbuf data */ @@ -1879,7 +1910,7 @@ test_ipsec_replay_inb_inside_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* Generate inbound mbuf data */ @@ -1972,7 +2003,7 @@ test_ipsec_replay_inb_outside_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* Generate test mbuf data */ @@ -2072,7 +2103,7 @@ test_ipsec_replay_inb_repeat_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* Generate test mbuf data */ @@ -2173,7 +2204,7 @@ test_ipsec_replay_inb_inside_burst_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* Generate inbound mbuf data */ @@ -2306,7 +2337,7 @@ test_ipsec_crypto_inb_burst_2sa_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* create second rte_ipsec_sa */ @@ -2316,7 +2347,7 @@ test_ipsec_crypto_inb_burst_2sa_null_null(int i) if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i); destroy_sa(0); - return TEST_FAILED; + return rc; } /* Generate test mbuf data */ @@ -2392,7 +2423,7 @@ test_ipsec_crypto_inb_burst_2sa_4grp_null_null(int i) test_cfg[i].replay_win_sz, test_cfg[i].flags, 0); if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i); - return TEST_FAILED; + return rc; } /* create second rte_ipsec_sa */ @@ -2402,7 +2433,7 @@ test_ipsec_crypto_inb_burst_2sa_4grp_null_null(int i) if (rc != 0) { RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i); destroy_sa(0); - return TEST_FAILED; + return rc; } /* Generate test mbuf data */ @@ -2467,33 +2498,33 @@ static struct unit_test_suite ipsec_testsuite = { .setup = testsuite_setup, .teardown = testsuite_teardown, .unit_test_cases = { - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_crypto_inb_burst_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_crypto_outb_burst_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_inline_crypto_inb_burst_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_inline_crypto_outb_burst_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_inline_proto_inb_burst_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_inline_proto_outb_burst_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_lksd_proto_inb_burst_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_lksd_proto_outb_burst_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_replay_inb_inside_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_replay_inb_outside_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_replay_inb_repeat_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_replay_inb_inside_burst_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_crypto_inb_burst_2sa_null_null_wrapper), - TEST_CASE_ST(ut_setup, ut_teardown, + TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec, test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper), TEST_CASES_END() /**< NULL terminate unit test array */ }