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 35538A0597; Wed, 8 Apr 2020 05:15:46 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 966F91C037; Wed, 8 Apr 2020 05:14:58 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 8600D1BFBA for ; Wed, 8 Apr 2020 05:14:52 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031452euoutp016d87a2a809bdfae293a5dc17cc45f1f8~Dubev0p2i1710017100euoutp017 for ; Wed, 8 Apr 2020 03:14:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200408031452euoutp016d87a2a809bdfae293a5dc17cc45f1f8~Dubev0p2i1710017100euoutp017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315692; bh=UU/wxp6Tjzo1nyxDa7i6/6DQF7d/5k1o9xF1LLYCsYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=frL9rUSn+FZ8D2z/OT3q1fzXP33GkbyDuX+KRtltRc1HbH7F9yy2iT8QLdL604Qa4 THDtCoR+k9UzoZWmWJGgFlYpHVkViwN9XtDc+Nri/D5amnbA8fZuBqKN88bQWJMVLf I9ktHsWtm8HTyfJj85RkZq21E46p6qbeGz80Tbfc= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200408031452eucas1p165ed036da649d93ac9583c6a5310afeb~DubefQwvc2413824138eucas1p1V for ; Wed, 8 Apr 2020 03:14:52 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id FE.1B.61286.BA14D8E5; Wed, 8 Apr 2020 04:14:51 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200408031451eucas1p2769ae9d814ef1ccd286407767054e117~Dubd55Jri3007630076eucas1p2o for ; Wed, 8 Apr 2020 03:14:51 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200408031451eusmtrp187f966137a2b3e36b615f3618d962330~Dubd5aXst1153511535eusmtrp1u for ; Wed, 8 Apr 2020 03:14:51 +0000 (GMT) X-AuditID: cbfec7f2-f0bff7000001ef66-6a-5e8d41abd171 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id CF.69.07950.BA14D8E5; Wed, 8 Apr 2020 04:14:51 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200408031451eusmtip1c9f4d83c400fae9d30fb34c0b8a1aa03~Dubdgnkog2966429664eusmtip1b for ; Wed, 8 Apr 2020 03:14:50 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Wed, 8 Apr 2020 05:13:44 +0200 Message-Id: <20200408031351.4288-7-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+NgFjrBIsWRmVeSWpSXmKPExsWy7djP87qrHXvjDLbttbZ492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4MiYcu8hUsNG9YurCr6wNjLtsuhg5OSQETCQmzJ7O2MXIxSEk sIJR4mz3URYIp51JovHdYiYIp41J4vavf6wwLZ8+X2EGsYUEljNKLN/tAle0aGInG0iCTcBW 4sjMr2ANIgIsEiu/f2cBsZkFBCQe33sGFhcW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Cg1lJhFeqtzNOiDclsbIqtSg/vqg0J7X4EKMp0EkTmaVEk/OBgZ5XEm9oamhu YWlobmxubGahJM7bIXAwRkggPbEkNTs1tSC1CKaPiYNTqoFRPOKJtK3kf5s19tHsW7lfvjTI eL/1YOFa+TQ7/9Nlh84Vvur8uP3PK6FOueev/y9MdHJ/ZcKq7OQb1lBz1qhD/9pXn6khkbeK dJec7+K5ytpoudt1w6OkfZeiAuyWuHNx2bHIeOxZH5PznuOK7Kav7BNq8tTVDUq2Hzo+cfIN Q+VGIc9N0xSVWIozEg21mIuKEwHSCnQiPAIAAA== X-CMS-MailID: 20200408031451eucas1p2769ae9d814ef1ccd286407767054e117 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200408031451eucas1p2769ae9d814ef1ccd286407767054e117 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031451eucas1p2769ae9d814ef1ccd286407767054e117 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 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" Add unit tests for rte_security_session_update function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 229 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index 3fc83abae..daaf30b62 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -238,6 +238,36 @@ 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 * @@ -278,6 +308,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, }; @@ -300,6 +331,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. */ @@ -368,9 +400,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; @@ -381,6 +415,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) @@ -416,6 +451,46 @@ 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 @@ -642,6 +717,145 @@ test_session_create_success(void) } +/** + * rte_security_session_update tests + */ + +/** + * Test execution of rte_security_session_update with NULL instance + */ +static int +test_session_update_inv_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_session_update_inv_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_session_update_inv_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_session_update_inv_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_session_update_inv_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_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_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 */ @@ -667,6 +881,21 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_session_create_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_inv_configuration), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_inv_session), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; -- 2.17.1