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 2BF08A0597; Wed, 8 Apr 2020 05:16:18 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0AD731C0B3; Wed, 8 Apr 2020 05:15:03 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id D5C0A1BFC6 for ; Wed, 8 Apr 2020 05:14:53 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031453euoutp021ec3dce8ba2205b011ee24533a5cd1bf~DubgAaqNA1520415204euoutp02y for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200408031453euoutp021ec3dce8ba2205b011ee24533a5cd1bf~DubgAaqNA1520415204euoutp02y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315693; bh=igxkj1rh0eTu9I7h5X2CfjMMhnmGhIJ6tYnNcUVR9fk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DdH4nLTaSVz9mKcjfHh5gntpxnO50cCONxZgiAkpweFymqLGOaZSgadDM1yoD9Rpz IaAUQCdrzmV5ju3NlWr92zAlan8d1jTUxdC3JT2dxZ+RwQ+wCRFsOx3wgGUoAwdT5v nnjX6rlVcjJW3lrvwOPkEF5xQWxtUN9Tv3BzkeDs= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200408031453eucas1p2d94754d90b8310b89f089840b78481fb~Dubfg4Eo-3011330113eucas1p2i for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 1F.1B.61286.DA14D8E5; Wed, 8 Apr 2020 04:14:53 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200408031452eucas1p1b4de173fadca62824b472b8a3dd69e32~DubfNvIM51426114261eucas1p1p for ; Wed, 8 Apr 2020 03:14:52 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200408031452eusmtrp2ea5bd290ad631599cf0c37f58396978f~DubfNPsoS2369123691eusmtrp2B for ; Wed, 8 Apr 2020 03:14:52 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-6d-5e8d41ad166d Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 82.DA.08375.CA14D8E5; Wed, 8 Apr 2020 04:14:52 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200408031452eusmtip133453df0c715a7c8dcddd751a7c30025~Dube0O3_q2835528355eusmtip1g 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:47 +0200 Message-Id: <20200408031351.4288-10-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+NgFjrJIsWRmVeSWpSXmKPExsWy7djP87prHXvjDH5fYLd492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4MjpvbWQqaNapmLnqG1MD4w/VLkZODgkBE4nry/YxdzFycQgJ rGCUuLvnAwuE084ksWjSUWaQKiGBNiaJA7fjYTr+9jVCdSxnlLh+8yArhANUtPXsejaQKjYB W4kjM7+ygtgiAiwSK79/ZwG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xCjBAezkgivVG9nnBBvSmJlVWpRfnxRaU5q8SFGU6CbJjJLiSbnA0M9ryTe0NTQ3MLS 0NzY3NjMQkmct0PgYIyQQHpiSWp2ampBahFMHxMHp1QDo/0c17VVd8x8FzQ/CH9n9PJb27O5 cgdnxV8WP7gnIUig7PanJgubOYpt8uZ6nDrJInPM1i2xMjpzXj/EXdUzZs6sJuu/+145vdjj Iazf02H9MWGK74I9Sa1/pIJuzn8c8Ez/7hq9yuB3bMdeirKoS9ekcPJyfNj05uvKSwqLXoVN ef36/7UYdSWW4oxEQy3mouJEAI8kMrU9AgAA X-CMS-MailID: 20200408031452eucas1p1b4de173fadca62824b472b8a3dd69e32 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200408031452eucas1p1b4de173fadca62824b472b8a3dd69e32 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031452eucas1p1b4de173fadca62824b472b8a3dd69e32 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 09/13] app/test: add rte security session destroy 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_destroy function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 166 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index c495449b0..b1a907bd9 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -1137,6 +1137,159 @@ test_session_stats_get_success(void) } +/** + * rte_security_session_destroy tests + */ + +/** + * Test execution of rte_security_session_destroy with NULL instance + */ +static int +test_session_destroy_inv_context(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(1); + + int ret = rte_security_session_destroy(NULL, ut_params->sess); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0); + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_destroy with invalid + * security operations structure (NULL) + */ +static int +test_session_destroy_inv_context_ops(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + ut_params->ctx.ops = NULL; + + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(1); + + int ret = rte_security_session_destroy(&ut_params->ctx, + ut_params->sess); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0); + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_destroy with empty + * security operations + */ +static int +test_session_destroy_inv_context_ops_fun(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + ut_params->ctx.ops = &empty_ops; + + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(1); + + int ret = rte_security_session_destroy(&ut_params->ctx, + ut_params->sess); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy, + ret, -ENOTSUP, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0); + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_destroy with NULL sess parameter + */ +static int +test_session_destroy_inv_session(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(1); + + int ret = rte_security_session_destroy(&ut_params->ctx, NULL); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 0); + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_destroy when session_destroy + * security operation fails + */ +static int +test_session_destroy_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + mock_session_destroy_exp.device = NULL; + mock_session_destroy_exp.sess = ut_params->sess; + mock_session_destroy_exp.ret = -1; + + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(1); + + int ret = rte_security_session_destroy(&ut_params->ctx, + ut_params->sess); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy, + ret, -1, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1); + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_destroy in successful execution path + */ +static int +test_session_destroy_success(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + mock_session_destroy_exp.device = NULL; + mock_session_destroy_exp.sess = ut_params->sess; + mock_session_destroy_exp.ret = 0; + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(1); + + int ret = rte_security_session_destroy(&ut_params->ctx, + ut_params->sess); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_destroy, + ret, 0, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_destroy_exp, 1); + TEST_ASSERT_MEMPOOL_USAGE(0); + TEST_ASSERT_SESSION_COUNT(0); + + /* + * Remove session from test case parameters, so it won't be destroyed + * during test case teardown. + */ + ut_params->sess = NULL; + + return TEST_SUCCESS; +} + + /** * Declaration of testcases */ @@ -1201,6 +1354,19 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_session_stats_get_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_destroy_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_destroy_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_destroy_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_destroy_inv_session), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_destroy_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_destroy_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; -- 2.17.1