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 08931A0597; Thu, 9 Apr 2020 19:26:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 06BFD1D405; Thu, 9 Apr 2020 19:25:42 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id D72A11C2F3 for ; Thu, 9 Apr 2020 19:25:34 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172534euoutp02097379ca2535b4e35b25faab12f5ae7b~ENrh6v6LJ2095420954euoutp02l for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200409172534euoutp02097379ca2535b4e35b25faab12f5ae7b~ENrh6v6LJ2095420954euoutp02l DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453134; bh=UU/wxp6Tjzo1nyxDa7i6/6DQF7d/5k1o9xF1LLYCsYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RusurEuNirc/Xf90rwm9ZGXF+EaUMXapiaaOn/hIxkYwjUsGRVYPVl0eEi8zqoR83 OuEtcYWhRDrUVGjh2m9mcvz/OKm70DKrLQRt4Cw4Fb0BVY6/Fzb4THRoHNpvstKR0h 3qv8DhNooRJP4qXfm08f6wEwsTZWsnIEqFSPRkLs= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200409172534eucas1p1cddf0003b30be0883964c81cc2157caf~ENrhsH2V40985509855eucas1p1y for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id B3.F2.61286.E8A5F8E5; Thu, 9 Apr 2020 18:25:34 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200409172533eucas1p252ed0cac1689b067a83589a0665c9033~ENrhNfuD30102501025eucas1p2m for ; Thu, 9 Apr 2020 17:25:33 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172533eusmtrp1bd51c8bea937c7e839e3c81af6221f6e~ENrhM-VAo2463624636eusmtrp1I for ; Thu, 9 Apr 2020 17:25:33 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-33-5e8f5a8e0a9d Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id B4.48.07950.D8A5F8E5; Thu, 9 Apr 2020 18:25:33 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172533eusmtip17bdd34a42266d579550e1c30dd70d302~ENrg274x60696506965eusmtip1R for ; Thu, 9 Apr 2020 17:25:33 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:24:55 +0200 Message-Id: <20200409172502.1693-7-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+NgFjrNIsWRmVeSWpSXmKPExsWy7djP87p9Uf1xBqd3SFm8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGROOXWQq2OheMXXhV9YGxl02XYwcHBICJhL/tnp2MXJxCAms YJTovHiCFcJpZ5J4fPELM4TTxiSx59Jm9i5GTrCO7ptbmSASyxklJjVfZ4Sr+jh5JytIFZuA rcSRmV/BbBEBFomV37+zgNjM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xCnAwKvHwGjD0xwmx JpYVV+YeYpTgYFYS4fVu6o0T4k1JrKxKLcqPLyrNSS0+xGgKdNREZinR5HxgsOeVxBuaGppb WBqaG5sbm1koifN2CByMERJITyxJzU5NLUgtgulj4uCUamBkWyS8iPUgn6uO3KuZcxfKyjza eCvzxKqGT5OW5p1TfS2+nCN/ja+JuvazZ9+P8Dg/z/+hsIdtvu0S42mBtcFhFYyT15Q9tcur kVm5dULof8+Fwr7L3s3LPHqa5+lEE5mHRqkxZ10FX3put481ySnknD7j8wvV9+cmvs4PbI5L Fg1PcPIq/2yoxFKckWioxVxUnAgAFTeBnD4CAAA= X-CMS-MailID: 20200409172533eucas1p252ed0cac1689b067a83589a0665c9033 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200409172533eucas1p252ed0cac1689b067a83589a0665c9033 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172533eucas1p252ed0cac1689b067a83589a0665c9033 References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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