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 D829CA0597; Wed, 8 Apr 2020 05:16:25 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6339C1C0B9; Wed, 8 Apr 2020 05:15:04 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 70C3C1BFE2 for ; Wed, 8 Apr 2020 05:14:54 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031454euoutp015ae761fab785821a5162d93d2cba54c4~Dubgjh7TO1461214612euoutp01K for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200408031454euoutp015ae761fab785821a5162d93d2cba54c4~Dubgjh7TO1461214612euoutp01K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315694; bh=YwentnYwXBn5wJD8++p1IOcwOw+d81KxW633X+6HyZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZO75/sxK5KIvBrx/NtzJ8ZOlIcan6OoUVmsTGDy5L4rU359OcYkZvWQ0YtA2ol232 RUctoSNYtUHXCl6E3Vj2TZnztV+Jk6DZptMQZiPPVI+SW8W+aRXpRQODURVYpokOe0 Bnz66NOVi/uB5wIVkBuRoAvLs8xvTL5cPQJ1Iscs= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200408031453eucas1p23db7c46f20428fc1b0e3b26030db7e8b~DubgHLU_L3004730047eucas1p2d for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 08.1A.60698.DA14D8E5; Wed, 8 Apr 2020 04:14:53 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200408031453eucas1p15bf7f54b1a5b1ae7810a72c71bd6271c~DubffN1c72413424134eucas1p1h for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200408031453eusmtrp109715a9ea018f10454e41bf11dc891a2~DubfexhT-1153511535eusmtrp1w for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-36-5e8d41ad4d25 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 00.79.07950.DA14D8E5; Wed, 8 Apr 2020 04:14:53 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200408031452eusmtip1c7620b4f397a565b3b377ae76bb5ca00~DubfMrI3Y2966429664eusmtip1d for ; Wed, 8 Apr 2020 03:14:52 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Wed, 8 Apr 2020 05:13:48 +0200 Message-Id: <20200408031351.4288-11-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+NgFjrFIsWRmVeSWpSXmKPExsWy7djPc7prHXvjDG7+0bF492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4Mmb8Xstc8Nyi4ubrqewNjOsMuhg5OSQETCQuddxk7mLk4hAS WMEoseJmDwuE084kcamlByrTxiQx9epUNpiWrqU7WUBsIYHljBIvJ7rBFR2af5cZJMEmYCtx ZOZXVhBbRIBFYuX372ANzAICEo/vPQO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x JpYVV+YeYpTgYFYS4ZXq7YwT4k1JrKxKLcqPLyrNSS0+xGgKdNNEZinR5HxgqOeVxBuaGppb WBqaG5sbm1koifN2CByMERJITyxJzU5NLUgtgulj4uCUamDc+Cv07WG2qcnPdy0+vvF6xbK/ 5TmOZuErFzUopU+4t+3bzHNLWkwTXv1fllX6+dqP7TUpsXGyqtt+x0tmGUzM+P1M1ffNhEdy DX5Giy3kYx13NJ/pSUnu/OrDIG4VyDprX/gtx4Kfve6NPU8ktOpEjc6vy7bjU5qxx+2lv1rQ b/tKwbMBEn+VWIozEg21mIuKEwGu77UPPQIAAA== X-CMS-MailID: 20200408031453eucas1p15bf7f54b1a5b1ae7810a72c71bd6271c X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200408031453eucas1p15bf7f54b1a5b1ae7810a72c71bd6271c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031453eucas1p15bf7f54b1a5b1ae7810a72c71bd6271c References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 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..a1f0e7879 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_LIBRTE_SECURITY_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_LIBRTE_SECURITY_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_LIBRTE_SECURITY_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_LIBRTE_SECURITY_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