From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DD094A0597; Wed, 8 Apr 2020 05:16:58 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9865E1C0D9; Wed, 8 Apr 2020 05:15:09 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id D31AF1C026 for ; Wed, 8 Apr 2020 05:14:56 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031456euoutp0113de26ea35889258c621565b49770b7b~DubixVoWz2124521245euoutp01W for ; Wed, 8 Apr 2020 03:14:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200408031456euoutp0113de26ea35889258c621565b49770b7b~DubixVoWz2124521245euoutp01W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315696; bh=DcvIeR6QZN9wf1EeEUt09vUdUeGmniee/KVSPZzFulc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eOx3kixiODBR9zfHDxLIIHk681pH2ItXxcr1fSCmHV+OlxT2cQmGfOaFIgaiDY1zM hkbZ6UvavSB/rKl+MwQZqBsCe43DEOMEPwoS7KWS68JgjBOHUIYnUayEk5caXdf7rw +EtDLcIxBs2QlemQ7M7wD9PQJr/NPLjvZyPb0fjA= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200408031455eucas1p1ebe02820c2085919d0b3bad4ba99ab7c~Dubh92rqO1426114261eucas1p1q for ; Wed, 8 Apr 2020 03:14:55 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 28.1A.60698.FA14D8E5; Wed, 8 Apr 2020 04:14:55 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200408031454eucas1p2e09e0ab0a1ffa5c657bcf35d89c40a55~Dubg5qB772966729667eucas1p2C for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200408031454eusmtrp2db22b48a010d2628efae53a6041cee76~Dubg5IbeZ2369123691eusmtrp2D for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) X-AuditID: cbfec7f5-a0fff7000001ed1a-39-5e8d41af10cd Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id C2.DA.08375.EA14D8E5; Wed, 8 Apr 2020 04:14:54 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200408031454eusmtip130d412eaa01f25f8013bb105081e5ae5~Dubgc05rK2835528355eusmtip1i for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Wed, 8 Apr 2020 05:13:51 +0200 Message-Id: <20200408031351.4288-14-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrDIsWRmVeSWpSXmKPExsWy7djPc7rrHXvjDGbdUrZ492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4MuZ/f8tasKKVseL5j0PsDYz/C7oYOTkkBEwkHl96ztjFyMUh JLCCUWL3+r3MEE47k8TKiY0sEE4bk8SHJwuYYVrmb7zCDpFYziix4d5tRriqZ38vMYFUsQnY ShyZ+ZUVxBYRYJFY+f07C4jNLCAg8fjeM7C4sICnxPYra9hBbBYBVYnPdx6D9fIKuEpMePGf FWKbvMTqDQeANnNwcALFd5/lAtklIbCCTeLQrs+MEDUuEi9P9zBB2MISr45vYYewZST+75zP BNGwjVHi6u+fjBDOfkaJ670roKqsJQ7/+80GsoFZQFNi/S59iLCjxNT3b8EWSwjwSdx4Kwhx P5/EpG3TocK8Eh1tQhDVehJPe6Yywqz9s/YJC4TtIXGqdzYrJHwuM0p8enCbeQKj/CyEZQsY GVcxiqeWFuempxYb56WW6xUn5haX5qXrJefnbmIExvHpf8e/7mDc9yfpEKMAB6MSD++DxJ44 IdbEsuLK3EOMEhzMSiK8Ur2dcUK8KYmVValF+fFFpTmpxYcYpTlYlMR5jRe9jBUSSE8sSc1O TS1ILYLJMnFwSjUwKgkoSkUezs04oPul1qdmMtPGF90VeoVme6+JHPBPnmH6uyiQM3HSyjvF GfmhB6T7tnydrfdo7mE2wZu6rbX8nsYvrl6SFSid93pulc9Fw/SMCEnvh7Vm9xYalcQuPp8T uuH01XuZp/89sF2+w07KXuKJ3Ze3l/NSuqZvE4zZ+Wpq30rz5KaFSizFGYmGWsxFxYkANRZj 9d8CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7rrHHvjDG73q1i8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GfO/v2UtWNHKWPH8xyH2Bsb/BV2MnBwSAiYS8zdeYQexhQSWMkrM7QSyOYDiMhIfLglAlAhL /LnWxdbFyAVU0sIkceXKG1aQBJuArcSRmV/BbBEBFomV37+zgNjMAgISj+89A4sLC3hKbL+y Bmw+i4CqxOc7j5lAbF4BV4kJL/6zQiyQl1i94QAzyF5OoPjus1wQ59RLHL57mW0CI98CRoZV jCKppcW56bnFhnrFibnFpXnpesn5uZsYgeG07djPzTsYL20MPsQowMGoxMP7ILEnTog1say4 MvcQowQHs5IIr1RvZ5wQb0piZVVqUX58UWlOavEhRlOgmyYyS4km5wNDPa8k3tDU0NzC0tDc 2NzYzEJJnLdD4GCMkEB6YklqdmpqQWoRTB8TB6dUAyObQJbtvGU24dN0pdZ+fjIpd/LtGznc E04Gd3jGulWECYgob7pj1FMe1u/t63nkVPwJoSOyey9MOZO8/9SuzLm+PvckrrPdSExSa7Wo Tlpp13f41r+mmfOjMs/lhGwJfST3OY/9EGuU+47/9aoTDkfFy7+s3yzxYdMVk/9vyn2O8FlH BYrv6FFiKc5INNRiLipOBABY4d2GPQIAAA== X-CMS-MailID: 20200408031454eucas1p2e09e0ab0a1ffa5c657bcf35d89c40a55 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200408031454eucas1p2e09e0ab0a1ffa5c657bcf35d89c40a55 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031454eucas1p2e09e0ab0a1ffa5c657bcf35d89c40a55 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 13/13] app/test: add rte security capability get tests X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add unit tests for rte_security_capability_get function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 522 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 522 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index 9da81fa1d..d5b76a127 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -1785,6 +1785,497 @@ test_capabilities_get_success(void) } +/** + * rte_security_capability_get tests + */ + +/** + * Test execution of rte_security_capability_get with NULL instance + */ +static int +test_capability_get_inv_context(void) +{ + struct rte_security_capability_idx idx; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(NULL, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get with invalid + * security operations structure (NULL) + */ +static int +test_capability_get_inv_context_ops(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx; + ut_params->ctx.ops = NULL; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get with empty + * security operations + */ +static int +test_capability_get_inv_context_ops_fun(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx; + ut_params->ctx.ops = &empty_ops; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get with NULL idx parameter + */ +static int +test_capability_get_inv_idx(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, NULL); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities_get + * security operation fails + */ +static int +test_capability_get_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = NULL; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * is empty (contains only RTE_SECURITY_ACTION_TYPE_NONE ending entry) + */ +static int +test_capability_get_empty_table(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching action + */ +static int +test_capability_get_no_matching_action(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching protocol + */ +static int +test_capability_get_no_matching_protocol(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_MACSEC, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_PDCP, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when macsec protocol + * is searched and capabilities table contain proper entry. + * However macsec records search is not supported in rte_security. + */ +static int +test_capability_get_no_support_for_macsec(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_MACSEC, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_MACSEC, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching ipsec proto field + */ +static int +test_capability_get_ipsec_mismatch_proto(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_AH, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching ipsec mode field + */ +static int +test_capability_get_ipsec_mismatch_mode(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching ipsec direction field + */ +static int +test_capability_get_ipsec_mismatch_dir(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, + .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, + .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * contains matching ipsec entry + */ +static int +test_capability_get_ipsec_match(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, + .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, + .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, &capabilities[1], "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching pdcp domain field + */ +static int +test_capability_get_pdcp_mismatch_domain(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_PDCP, + .pdcp = { + .domain = RTE_SECURITY_PDCP_MODE_CONTROL, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_PDCP, + .pdcp = { + .domain = RTE_SECURITY_PDCP_MODE_DATA, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * contains matching pdcp entry + */ +static int +test_capability_get_pdcp_match(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_PDCP, + .pdcp = { + .domain = RTE_SECURITY_PDCP_MODE_CONTROL, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_PDCP, + .pdcp = { + .domain = RTE_SECURITY_PDCP_MODE_CONTROL, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, &capabilities[1], "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + /** * Declaration of testcases */ @@ -1897,6 +2388,37 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_capabilities_get_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_inv_idx), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_empty_table), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_no_matching_action), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_no_matching_protocol), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_no_support_for_macsec), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_ipsec_mismatch_proto), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_ipsec_mismatch_mode), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_ipsec_mismatch_dir), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_ipsec_match), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_pdcp_mismatch_domain), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_pdcp_match), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; -- 2.17.1