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 391BDA056D; Thu, 12 Mar 2020 16:18:14 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CD9811C07E; Thu, 12 Mar 2020 16:17:18 +0100 (CET) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 631C22BE6 for ; Thu, 12 Mar 2020 16:17:10 +0100 (CET) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151710euoutp027576f7016fba3516c7291b3ffb3f2dd8~7l3a9I38F2975329753euoutp02L for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200312151710euoutp027576f7016fba3516c7291b3ffb3f2dd8~7l3a9I38F2975329753euoutp02L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026230; bh=9m5HlxPdt2tJAqp+93xZw06/163gjT2G2iNw44jQSew=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ep7z2hJITbBLs70xG2eX/4gYZHplc/7XeHZd8i/yKy5RUcX+N6DgVJ+XQWpuaIFdd PjEGfu6RhvAtc5JngC/l3ZLJ3okCXkWoqSqTdWgC60fnZ2GKSJcNFivHVlAgnt2kSy /MivNuXZKMnyP2tVzLlUrtfGNZpi5IMzc5/svcGQ= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200312151709eucas1p217d90f3d2113ee9875595a6339054195~7l3aspGY62375023750eucas1p2e for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 72.62.61286.5725A6E5; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200312151709eucas1p1a01f789059de888cb2d719526434e4f9~7l3aWte7-0788307883eucas1p15 for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151709eusmtrp21ac866d7f8bd78ad04f5a306aa8c24eb~7l3aWQMOk1238412384eusmtrp2F for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-bc-5e6a52758601 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 81.2D.07950.5725A6E5; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151709eusmtip19b3f4223700ce067895841d1abb3f02e~7l3aHJ2vP0817408174eusmtip10 for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:47 +0100 Message-Id: <20200312151654.7218-7-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrAIsWRmVeSWpSXmKPExsWy7djP87qlQVlxBhPaDS3efdrO5MDo8WvB UtYAxigum5TUnMyy1CJ9uwSujHWL5jMWLPesuHqgj7GBcb9dFyMnh4SAicTpXU1sXYxcHEIC Kxgl2o5cYIZw2pkk/i2bC+W0MUn0f77FAtOyau9+JojEckaJlcdOMMK1TH8+nRmkik3AVuLI zK+sILaIgIDE587FbCC2sICbxMcvE5hAbBYBVYmtb26B2b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R8YFDnlcQbmhqaW1gamhubG5tZKInz dggcjBESSE8sSc1OTS1ILYLpY+LglGpgnLpILzL3fcmXhKznE4unRETqXYrl6zlz65TBr+6b 1UdXbeZwq/5UbyM5o5U9xIhvQ2Xv8bDkbOctXy9c55zeLNx7IU8ptaHqkxarbMq712Hfdm8R OvktamLGtoDtK3anKZVkXcn797TvSKSci/aexz9W3FjCwa553ro98kKBqen5OZG25+uuK7EU ZyQaajEXFScCAJLfwjwyAgAA X-CMS-MailID: 20200312151709eucas1p1a01f789059de888cb2d719526434e4f9 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200312151709eucas1p1a01f789059de888cb2d719526434e4f9 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151709eucas1p1a01f789059de888cb2d719526434e4f9 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 06/13] app/test: add rte_security_session_update 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" Signed-off-by: Lukasz Wojciechowski Change-Id: I3d5df17a33913a94e6ad6806de91c7157184e3b4 --- app/test/test_security.c | 225 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index 885281703..cf13b8080 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -234,6 +234,35 @@ mock_session_create(void *device, return mock_session_create_exp.ret; } +/** + * session_update mockup + * + * Verified parameters: device, sess, conf. + */ +static struct mock_session_update_data { + void *device; + struct rte_security_session *sess; + struct rte_security_session_conf *conf; + + int ret; + + int called; + int failed; +} mock_session_update_exp = {NULL, NULL, NULL, 0, 0, 0}; + +static int +mock_session_update(void *device, + struct rte_security_session *sess, + struct rte_security_session_conf *conf) { + mock_session_update_exp.called++; + + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, device); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, sess); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, conf); + + return mock_session_update_exp.ret; +} + /** * session_destroy mockup * @@ -274,6 +303,7 @@ struct rte_security_ops empty_ops = { NULL }; */ struct rte_security_ops mock_ops = { .session_create = mock_session_create, + .session_update = mock_session_update, .session_destroy = mock_session_destroy, }; @@ -296,6 +326,7 @@ static struct security_testsuite_params { /** * struct security_unittest_params defines parameters initialized * for every test case. The parameters are initialized in ut_setup + * or ut_setup_with_session (depending on the testcase) * and released in ut_teardown. * The instance of this structure is stored in unittest_params variable. */ @@ -361,9 +392,11 @@ ut_setup(void) { ut_params->sess = NULL; mock_session_create_exp.called = 0; + mock_session_update_exp.called = 0; mock_session_destroy_exp.called = 0; mock_session_create_exp.failed = 0; + mock_session_update_exp.failed = 0; mock_session_destroy_exp.failed = 0; return TEST_SUCCESS; @@ -374,6 +407,7 @@ ut_setup(void) { * created with rte_security_session_create and stored in test case parameters. * It's used both to release sessions created in test cases' bodies * which are assigned to ut_params->sess + * as well as sessions created in ut_setup_with_session. */ static int destroy_session_with_check(void) { @@ -407,6 +441,43 @@ ut_teardown(void) { destroy_session_with_check(); } +/** + * ut_setup_with_session initializes test case parameters by + * - calling standard ut_setup, + * - creating a session that can be used in test case. + */ +static int +ut_setup_with_session(void) { + struct security_unittest_params *ut_params = &unittest_params; + struct security_testsuite_params *ts_params = &testsuite_params; + struct rte_security_session *sess; + + int ret = ut_setup(); + if (ret != TEST_SUCCESS) { + return ret; + } + + mock_session_create_exp.device = NULL; + mock_session_create_exp.conf = &ut_params->conf; + mock_session_create_exp.mp = ts_params->session_mpool; + mock_session_create_exp.ret = 0; + + sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf, + ts_params->session_mpool); + TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create, sess); + TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess, + "Expecting session_create to be called with %p sess parameter, " + "but it's called %p sess parameter", + sess, mock_session_create_exp.sess); + TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1); + + // store created session in test case parameters so it can be released + // after test case in ut_teardown by destroy_session_with_check. + ut_params->sess = sess; + + return TEST_SUCCESS; +} + /** * Test functions @@ -629,6 +700,145 @@ test_rte_security_session_create_success(void) } +/** + * rte_security_session_update tests + */ + +/** + * Test execution of rte_security_session_update with NULL instance + */ +static int +test_rte_security_session_update_inv_param_context(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + int ret = rte_security_session_update(NULL, ut_params->sess, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update with invalid + * security operations structure (NULL) + */ +static int +test_rte_security_session_update_inv_param_context_ops(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + ut_params->ctx.ops = NULL; + + int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update with empty + * security operations + */ +static int +test_rte_security_session_update_inv_param_context_ops_fun(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + ut_params->ctx.ops = &empty_ops; + + int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -ENOTSUP, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update with NULL conf parameter + */ +static int +test_rte_security_session_update_inv_param_configuration(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess, + NULL); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update with NULL sess parameter + */ +static int +test_rte_security_session_update_inv_param_session(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + int ret = rte_security_session_update(&ut_params->ctx, NULL, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update when session_update + * security operation fails + */ +static int +test_rte_security_session_update_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + mock_session_update_exp.device = NULL; + mock_session_update_exp.sess = ut_params->sess; + mock_session_update_exp.conf = &ut_params->conf; + mock_session_update_exp.ret = -1; // return failure status + + int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -1, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update in successful execution path + */ +static int +test_rte_security_session_update_success(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + mock_session_update_exp.device = NULL; + mock_session_update_exp.sess = ut_params->sess; + mock_session_update_exp.conf = &ut_params->conf; + mock_session_update_exp.ret = 0; // return success status + + int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, 0, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1); + + return TEST_SUCCESS; +} + + /** * Declaration of testcases */ @@ -654,6 +864,21 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_rte_security_session_create_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_inv_param_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_inv_param_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_inv_param_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_inv_param_configuration), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_inv_param_session), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; -- 2.17.1