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 2A5E4A0597; Thu, 9 Apr 2020 19:27:17 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CD6861D423; Thu, 9 Apr 2020 19:25:48 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 507311D14E for ; Thu, 9 Apr 2020 19:25:36 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172536euoutp012f91f2da493001fb58ca7590fe329876~ENrjQHxKz0867408674euoutp01A for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200409172536euoutp012f91f2da493001fb58ca7590fe329876~ENrjQHxKz0867408674euoutp01A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453136; bh=QzLzQkIIUAfM+0w3FM/J8GqPFXwYKon9p78YLKE8q2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F/7NHvmrSFgm5OpyAIuQVcCHdRjVzRUFtBr44DUefjOlTXobPzCUdmhO4KbH9TQBX KluoqgMKDW0stcXwWiweD3Ox6epg9YIiFj6KEuIw0ZOeS8ksiHYAwo9WmA2P2R+8tz qqrlH1nQiV95lA5H1dlz0zrniUYC+E+Qm70aESHU= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200409172535eucas1p1c267aaf9538331d2ccebf8bd4cd6ad37~ENrjHdp890986409864eucas1p10 for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id A2.50.60679.F8A5F8E5; Thu, 9 Apr 2020 18:25:35 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200409172535eucas1p2c215489de77c708fc0bec6b9e2e3dd6d~ENriy00nG1612816128eucas1p2G for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172535eusmtrp1f1715c1cbccf0bf660787c704a21727a~ENriyVApI2463624636eusmtrp1N for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) X-AuditID: cbfec7f4-0cbff7000001ed07-dc-5e8f5a8fefad Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id F4.48.07950.F8A5F8E5; Thu, 9 Apr 2020 18:25:35 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172535eusmtip1004175d246becc1d20bd308938d163fe~ENrid2CdO0977009770eusmtip1i for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:24:59 +0200 Message-Id: <20200409172502.1693-11-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJIsWRmVeSWpSXmKPExsWy7djP87r9Uf1xBgueWlm8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGUe+FBUst6j4fv0MUwPjO/0uRk4OCQETiU/z25m7GLk4hARW MErc7ZrBCOG0M0msW7GABcJpY5KYeXkdUxcjB1jL6r/REPHljBIL3l1jhitq+drIBjKXTcBW 4sjMr6wgtogAi8TK799ZQGxmAQGJx/eegcWFBbwlNrW2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/vqg0J7X4EKMp0FETmaVEk/OBgZ5XEm9oamhuYWlobmxu bGahJM7bIXAwRkggPbEkNTs1tSC1CKaPiYNTqoFxbezaV4Ly1cF7wrusW0Jey67ac/e36f5W bzdJh9lTrUtf3j+eV7crT+zS6r8pK95ciZh2RNB+/UQpZdWqzAPqK16pX5nDWsObqGLhOO/D Vr+aTatTzQTVJxx5JLLi4FHVS7KLZlo2N0xc/M7garhmVdfWVU6Zxx9pyX04oi+w45L+48ZF hRw1SizFGYmGWsxFxYkAs+e77zwCAAA= X-CMS-MailID: 20200409172535eucas1p2c215489de77c708fc0bec6b9e2e3dd6d X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200409172535eucas1p2c215489de77c708fc0bec6b9e2e3dd6d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172535eucas1p2c215489de77c708fc0bec6b9e2e3dd6d References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 10/13] app/test: add rte security set pkt metadata 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_set_pkt_metadata function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 201 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index b1a907bd9..193ab2ba9 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -348,6 +348,39 @@ mock_session_destroy(void *device, struct rte_security_session *sess) return mock_session_destroy_exp.ret; } +/** + * set_pkt_metadata mockup + * + * Verified parameters: device, sess, m, params. + */ +static struct mock_set_pkt_metadata_data { + void *device; + struct rte_security_session *sess; + struct rte_mbuf *m; + void *params; + + int ret; + + int called; + int failed; +} mock_set_pkt_metadata_exp = {NULL, NULL, NULL, NULL, 0, 0, 0}; + +static int +mock_set_pkt_metadata(void *device, + struct rte_security_session *sess, + struct rte_mbuf *m, + void *params) +{ + mock_set_pkt_metadata_exp.called++; + + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, device); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, sess); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, m); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_set_pkt_metadata_exp, params); + + return mock_set_pkt_metadata_exp.ret; +} + /** * empty_ops * @@ -366,6 +399,7 @@ struct rte_security_ops mock_ops = { .session_get_size = mock_session_get_size, .session_stats_get = mock_session_stats_get, .session_destroy = mock_session_destroy, + .set_pkt_metadata = mock_set_pkt_metadata, }; @@ -460,12 +494,14 @@ ut_setup(void) mock_session_get_size_exp.called = 0; mock_session_stats_get_exp.called = 0; mock_session_destroy_exp.called = 0; + mock_set_pkt_metadata_exp.called = 0; mock_session_create_exp.failed = 0; mock_session_update_exp.failed = 0; mock_session_get_size_exp.failed = 0; mock_session_stats_get_exp.failed = 0; mock_session_destroy_exp.failed = 0; + mock_set_pkt_metadata_exp.failed = 0; return TEST_SUCCESS; } @@ -1290,6 +1326,158 @@ test_session_destroy_success(void) } +/** + * rte_security_set_pkt_metadata tests + */ + +/** + * Test execution of rte_security_set_pkt_metadata with NULL instance + */ +static int +test_set_pkt_metadata_inv_context(void) +{ +#ifdef RTE_DEBUG + struct security_unittest_params *ut_params = &unittest_params; + struct rte_mbuf m; + int params; + + int ret = rte_security_set_pkt_metadata(NULL, ut_params->sess, &m, + ¶ms); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_set_pkt_metadata with invalid + * security operations structure (NULL) + */ +static int +test_set_pkt_metadata_inv_context_ops(void) +{ +#ifdef RTE_DEBUG + struct security_unittest_params *ut_params = &unittest_params; + struct rte_mbuf m; + int params; + ut_params->ctx.ops = NULL; + + int ret = rte_security_set_pkt_metadata(&ut_params->ctx, + ut_params->sess, &m, ¶ms); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_set_pkt_metadata with empty + * security operations + */ +static int +test_set_pkt_metadata_inv_context_ops_fun(void) +{ +#ifdef RTE_DEBUG + struct security_unittest_params *ut_params = &unittest_params; + struct rte_mbuf m; + int params; + ut_params->ctx.ops = &empty_ops; + + int ret = rte_security_set_pkt_metadata(&ut_params->ctx, + ut_params->sess, &m, ¶ms); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata, + ret, -ENOTSUP, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_set_pkt_metadata with NULL sess parameter + */ +static int +test_set_pkt_metadata_inv_session(void) +{ +#ifdef RTE_DEBUG + struct security_unittest_params *ut_params = &unittest_params; + struct rte_mbuf m; + int params; + + int ret = rte_security_set_pkt_metadata(&ut_params->ctx, NULL, + &m, ¶ms); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_set_pkt_metadata when set_pkt_metadata + * security operation fails + */ +static int +test_set_pkt_metadata_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_mbuf m; + int params; + + mock_set_pkt_metadata_exp.device = NULL; + mock_set_pkt_metadata_exp.sess = ut_params->sess; + mock_set_pkt_metadata_exp.m = &m; + mock_set_pkt_metadata_exp.params = ¶ms; + mock_set_pkt_metadata_exp.ret = -1; + + int ret = rte_security_set_pkt_metadata(&ut_params->ctx, + ut_params->sess, &m, ¶ms); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata, + ret, -1, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_set_pkt_metadata in successful execution path + */ +static int +test_set_pkt_metadata_success(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_mbuf m; + int params; + + mock_set_pkt_metadata_exp.device = NULL; + mock_set_pkt_metadata_exp.sess = ut_params->sess; + mock_set_pkt_metadata_exp.m = &m; + mock_set_pkt_metadata_exp.params = ¶ms; + mock_set_pkt_metadata_exp.ret = 0; + + int ret = rte_security_set_pkt_metadata(&ut_params->ctx, + ut_params->sess, &m, ¶ms); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_set_pkt_metadata, + ret, 0, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_set_pkt_metadata_exp, 1); + + return TEST_SUCCESS; +} + + /** * Declaration of testcases */ @@ -1367,6 +1555,19 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_session_destroy_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_set_pkt_metadata_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_set_pkt_metadata_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_set_pkt_metadata_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_set_pkt_metadata_inv_session), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_set_pkt_metadata_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_set_pkt_metadata_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; -- 2.17.1