test/event: add asymmetric cases for crypto adapter
[dpdk.git] / app / test / test_ipsec.c
index 4007eff..8da025b 100644 (file)
@@ -2,6 +2,8 @@
  * Copyright(c) 2018 Intel Corporation
  */
 
+#include "test.h"
+
 #include <time.h>
 
 #include <rte_common.h>
 #include <rte_cycles.h>
 #include <rte_bus_vdev.h>
 #include <rte_ip.h>
-
 #include <rte_crypto.h>
 #include <rte_cryptodev.h>
-#include <rte_cryptodev_pmd.h>
 #include <rte_lcore.h>
+
+#ifdef RTE_EXEC_ENV_WINDOWS
+static int
+test_ipsec(void)
+{
+       printf("ipsec not supported on Windows, skipping test\n");
+       return TEST_SKIPPED;
+}
+
+#else
+
 #include <rte_ipsec.h>
 #include <rte_random.h>
 #include <rte_esp.h>
 #include <rte_security_driver.h>
 
-#include "test.h"
 #include "test_cryptodev.h"
 
 #define VDEV_ARGS_SIZE 100
@@ -237,7 +247,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 +312,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 +434,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 +454,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;
@@ -632,7 +642,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;
@@ -653,7 +664,7 @@ create_crypto_session(struct ipsec_unitest_params *ut,
        if (s == NULL)
                return -ENOMEM;
 
-       /* initiliaze SA crypto session for device */
+       /* initialize SA crypto session for device */
        rc = rte_cryptodev_sym_session_init(dev_id, s,
                        ut->crypto_xforms, qp->mp_session_private);
        if (rc == 0) {
@@ -689,11 +700,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);
@@ -743,7 +754,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;
@@ -1167,6 +1178,34 @@ 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)
 {
@@ -1175,9 +1214,8 @@ destroy_sa(uint32_t j)
 
        rte_ipsec_sa_fini(ut->ss[j].sa);
        rte_free(ut->ss[j].sa);
-       rte_cryptodev_sym_session_clear(ts->valid_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]));
+
+       destroy_session(ut, ts->valid_dev, j);
 }
 
 static int
@@ -1219,7 +1257,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 */
@@ -1321,7 +1359,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 */
@@ -1430,7 +1468,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 */
@@ -1508,7 +1546,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 */
@@ -1595,8 +1633,8 @@ inline_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
                        "ibuf pkt_len is not equal to obuf pkt_len");
 
                /* check mbuf ol_flags */
-               TEST_ASSERT(ut_params->ibuf[j]->ol_flags & PKT_TX_SEC_OFFLOAD,
-                       "ibuf PKT_TX_SEC_OFFLOAD is not set");
+               TEST_ASSERT(ut_params->ibuf[j]->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD,
+                           "ibuf RTE_MBUF_F_TX_SEC_OFFLOAD is not set");
        }
        return 0;
 }
@@ -1616,7 +1654,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 */
@@ -1694,7 +1732,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 */
@@ -1770,7 +1808,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 */
@@ -1883,7 +1921,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 */
@@ -1976,7 +2014,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 */
@@ -2076,7 +2114,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 */
@@ -2177,7 +2215,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 */
@@ -2310,7 +2348,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 */
@@ -2320,7 +2358,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 */
@@ -2396,7 +2434,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 */
@@ -2406,7 +2444,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 */
@@ -2471,33 +2509,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 */
        }
@@ -2509,4 +2547,6 @@ test_ipsec(void)
        return unit_test_suite_runner(&ipsec_testsuite);
 }
 
+#endif /* !RTE_EXEC_ENV_WINDOWS */
+
 REGISTER_TEST_COMMAND(ipsec_autotest, test_ipsec);