From patchwork Wed Apr 8 03:13:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67938 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8910DA0597; Wed, 8 Apr 2020 05:14:59 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 052ED1BF9F; Wed, 8 Apr 2020 05:14:52 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id ED7FD1BF4F for ; Wed, 8 Apr 2020 05:14:49 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031449euoutp01b2c1231dc76c5597ff2e147c146fd455~DubcLjApx2124521245euoutp01S for ; Wed, 8 Apr 2020 03:14:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200408031449euoutp01b2c1231dc76c5597ff2e147c146fd455~DubcLjApx2124521245euoutp01S DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315689; bh=6a2Xly4e2RQVZ5KWe0oFbGy8UD3L0ciDiIJwhpHoi/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qYmoLAzIA0qCcf88kwwjykoMdUW49/OqUMtkrWQnLRkonovuMMaMt8msJrVce+EgS vGM5bZQIktbiCPodkNDxrQ0JKeENXO3RY4B2/SRxzT7Y3xoarCyDwbU6zEMe9Kd/ea xgd/BLAb80WofrRjLmPxy6AQOA3VYZG1CKYWExrY= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200408031448eucas1p1ba27c39a1354539caec0ba5b99839314~DubbLTqcX2413824138eucas1p1T; Wed, 8 Apr 2020 03:14:48 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id E6.1A.60698.8A14D8E5; Wed, 8 Apr 2020 04:14:48 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200408031447eucas1p1376332353faa0d217e7be8c32271405f~DubaAsLba2413424134eucas1p1g; Wed, 8 Apr 2020 03:14:47 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200408031447eusmtrp28054a7c940a9b305cd3575bb7497edb6~DubaAEHfj0734007340eusmtrp2h; Wed, 8 Apr 2020 03:14:47 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-2e-5e8d41a8a08a Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 21.DA.08375.7A14D8E5; Wed, 8 Apr 2020 04:14:47 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200408031446eusmtip17ea6353cb9f59779c3ca32e91e744602~DubZKeUD62835528355eusmtip1c; Wed, 8 Apr 2020 03:14:46 +0000 (GMT) From: Lukasz Wojciechowski To: Thomas Monjalon , Akhil Goyal , Declan Doherty , Aviad Yehezkel , Boris Pismenny , Radu Nicolau , Anoob Joseph Cc: dev@dpdk.org, stable@dpdk.org Date: Wed, 8 Apr 2020 05:13:39 +0200 Message-Id: <20200408031351.4288-2-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+NgFmpnleLIzCtJLcpLzFFi42LZduznOd0Vjr1xBpu2iVusPzOP0eLU7Q/M Fh8mL2G0OPajnd3izYMmFot3n7YzWbR1CVj86/jDbvHpwQkWB06PDSf6WT1+LVjK6rF4z0sm j2fTDzN5HLs5jd1j47sdTAFsUVw2Kak5mWWpRfp2CVwZp+YsZCxYYlyx8lEfawPjCu0uRk4O CQETiY7Px1i6GLk4hARWMErsvLWeCcL5wihx4sF2qMxnRolfn+czwrTcmPGCGcQWEljOKLFp jylc0YKpS9lAEmwCthJHZn5lBUmICCxmktjzYRVYN7OAosTdlV/BioQFnCQmvH/G3sXIwcEi oCqx/n4+SJhXwEVix9UpLBDL5CVWbzjADFLCKeAqsfssF0S4nV3i3okECNtF4nDjczYIW1ji 1fEt7BC2jMT/nfPBvpEQ2MYocfX3T0YIZz+jxPXeFVBV1hKH//1mA1nALKApsX6XPogpIeAo 8euBDoTJJ3HjrSDE8XwSk7ZNZ4YI80p0tAlBzNCTeNozlRFm65+1T6CO95Bof/GeHRJSlxkl bk/wm8AoPwth1QJGxlWM4qmlxbnpqcXGeanlesWJucWleel6yfm5mxiByeP0v+NfdzDu+5N0 iFGAg1GJh/dBYk+cEGtiWXFl7iFGCQ5mJRFeqd7OOCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8 xotexgoJpCeWpGanphakFsFkmTg4pRoYV5v9VHmyZI+XpHXAVqb/P81yHk1c/+333haJ+FP1 vSXFE7/o7LzlsmYK6y31rVUtW+52h787qVz/Z4fC9VtN7vw/W37eWKhkFBdyQzjXetrl9Pjz f2JqFxlUPq1aWqPesNDW5cr849ItQs2/ZzDumXir89Ot4PpcVd+eUzr3UoQyXQ8ZshdOVmIp zkg01GIuKk4EAAoIBVkaAwAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrJLMWRmVeSWpSXmKPExsVy+t/xu7rLHXvjDJ5d5rBYf2Yeo8Wp2x+Y LT5MXsJocexHO7vFmwdNLBbvPm1nsmjrErD41/GH3eLTgxMsDpweG070s3r8WrCU1WPxnpdM Hs+mH2byOHZzGrvHxnc7mALYovRsivJLS1IVMvKLS2yVog0tjPQMLS30jEws9QyNzWOtjEyV 9O1sUlJzMstSi/TtEvQyTs1ZyFiwxLhi5aM+1gbGFdpdjJwcEgImEjdmvGDuYuTiEBJYyiix /dsO9i5GDqCEjMSHSwIQNcISf651sUHUfGSUaFjZzgySYBOwlTgy8ysrSEJEYDmTxNJP85lB mpkFlCX6tliB1AgLOElMeP8MbCaLgKrE+vv5IGFeAReJHVensEDMl5dYveEAWCengKvE7rNc IGEhgXqJw3cvs01g5FvAyLCKUSS1tDg3PbfYUK84Mbe4NC9dLzk/dxMjMJi3Hfu5eQfjpY3B hxgFOBiVeHgfJPbECbEmlhVX5h5ilOBgVhLhlertjBPiTUmsrEotyo8vKs1JLT7EaAp00kRm KdHkfGCk5ZXEG5oamltYGpobmxubWSiJ83YIHIwREkhPLEnNTk0tSC2C6WPi4JRqYPS6r8L2 tVW9xIOx9/CVwG9XJ+qyf/cqZ1x30vYc/8PfchPVLnyd16Nus55TpOhvub/sJfepMsbc/3XT 9z1NnbxGOeNuckplpY6F8IoNzx73PXPrPuizL6Iy4Lfo813F11dZRN5tE4y7v4Zp8VPhR0Uq k7/IX56lxHnDpF+zVmjF1n4xZam+HCWW4oxEQy3mouJEADOB6L58AgAA X-CMS-MailID: 20200408031447eucas1p1376332353faa0d217e7be8c32271405f X-Msg-Generator: CA X-RootMTR: 20200408031447eucas1p1376332353faa0d217e7be8c32271405f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031447eucas1p1376332353faa0d217e7be8c32271405f References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 01/13] security: fix verification of parameters 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" This patch adds verification of the parameters to the ret_security API functions. All required parameters are checked if they are not NULL. Checks verify full chain of pointers, e.g. in case of verification of "instance->ops->session_XXX", they check also "instance" and "instance->ops". Fixes: c261d1431bd8 ("security: introduce security API and framework") Cc: akhil.goyal@nxp.com Fixes: 1a08c379b9b5 ("security: support user data retrieval") Cc: anoob.joseph@caviumnetworks.com Cc: stable@dpdk.org Signed-off-by: Lukasz Wojciechowski --- config/common_base | 1 + lib/librte_security/rte_security.c | 59 +++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/config/common_base b/config/common_base index c31175f9d..ef1cdbb62 100644 --- a/config/common_base +++ b/config/common_base @@ -695,6 +695,7 @@ CONFIG_RTE_LIBRTE_PMD_NITROX=y # Compile generic security library # CONFIG_RTE_LIBRTE_SECURITY=y +CONFIG_RTE_LIBRTE_SECURITY_DEBUG=n # # Compile generic compression device library diff --git a/lib/librte_security/rte_security.c b/lib/librte_security/rte_security.c index bc81ce15d..f1b4a894e 100644 --- a/lib/librte_security/rte_security.c +++ b/lib/librte_security/rte_security.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright 2017 NXP. * Copyright(c) 2017 Intel Corporation. + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved */ #include @@ -9,6 +10,19 @@ #include "rte_security.h" #include "rte_security_driver.h" +/* Macro to check for invalid pointers */ +#define RTE_PTR_OR_ERR_RET(ptr, retval) do { \ + if ((ptr) == NULL) \ + return retval; \ +} while (0) + +/* Macro to check for invalid pointers chains */ +#define RTE_PTR_CHAIN3_OR_ERR_RET(p1, p2, p3, retval, last_retval) do { \ + RTE_PTR_OR_ERR_RET(p1, retval); \ + RTE_PTR_OR_ERR_RET(p1->p2, retval); \ + RTE_PTR_OR_ERR_RET(p1->p2->p3, last_retval); \ +} while (0) + struct rte_security_session * rte_security_session_create(struct rte_security_ctx *instance, struct rte_security_session_conf *conf, @@ -16,10 +30,9 @@ rte_security_session_create(struct rte_security_ctx *instance, { struct rte_security_session *sess = NULL; - if (conf == NULL) - return NULL; - - RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_create, NULL); + RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, session_create, NULL, NULL); + RTE_PTR_OR_ERR_RET(conf, NULL); + RTE_PTR_OR_ERR_RET(mp, NULL); if (rte_mempool_get(mp, (void **)&sess)) return NULL; @@ -38,14 +51,19 @@ rte_security_session_update(struct rte_security_ctx *instance, struct rte_security_session *sess, struct rte_security_session_conf *conf) { - RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_update, -ENOTSUP); + RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, session_update, -EINVAL, + -ENOTSUP); + RTE_PTR_OR_ERR_RET(sess, -EINVAL); + RTE_PTR_OR_ERR_RET(conf, -EINVAL); + return instance->ops->session_update(instance->device, sess, conf); } unsigned int rte_security_session_get_size(struct rte_security_ctx *instance) { - RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_get_size, 0); + RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, session_get_size, 0, 0); + return instance->ops->session_get_size(instance->device); } @@ -54,7 +72,11 @@ rte_security_session_stats_get(struct rte_security_ctx *instance, struct rte_security_session *sess, struct rte_security_stats *stats) { - RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_stats_get, -ENOTSUP); + RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, session_stats_get, -EINVAL, + -ENOTSUP); + /* Parameter sess can be NULL in case of getting global statistics. */ + RTE_PTR_OR_ERR_RET(stats, -EINVAL); + return instance->ops->session_stats_get(instance->device, sess, stats); } @@ -64,7 +86,9 @@ rte_security_session_destroy(struct rte_security_ctx *instance, { int ret; - RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_destroy, -ENOTSUP); + RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, session_destroy, -EINVAL, + -ENOTSUP); + RTE_PTR_OR_ERR_RET(sess, -EINVAL); if (instance->sess_cnt) instance->sess_cnt--; @@ -81,7 +105,11 @@ rte_security_set_pkt_metadata(struct rte_security_ctx *instance, struct rte_security_session *sess, struct rte_mbuf *m, void *params) { - RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->set_pkt_metadata, -ENOTSUP); +#ifdef RTE_LIBRTE_SECURITY_DEBUG + RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, set_pkt_metadata, -EINVAL, + -ENOTSUP); + RTE_PTR_OR_ERR_RET(sess, -EINVAL); +#endif return instance->ops->set_pkt_metadata(instance->device, sess, m, params); } @@ -91,7 +119,9 @@ rte_security_get_userdata(struct rte_security_ctx *instance, uint64_t md) { void *userdata = NULL; - RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->get_userdata, NULL); +#ifdef RTE_LIBRTE_SECURITY_DEBUG + RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, get_userdata, NULL, NULL); +#endif if (instance->ops->get_userdata(instance->device, md, &userdata)) return NULL; @@ -101,7 +131,8 @@ rte_security_get_userdata(struct rte_security_ctx *instance, uint64_t md) const struct rte_security_capability * rte_security_capabilities_get(struct rte_security_ctx *instance) { - RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->capabilities_get, NULL); + RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, capabilities_get, NULL, NULL); + return instance->ops->capabilities_get(instance->device); } @@ -113,7 +144,9 @@ rte_security_capability_get(struct rte_security_ctx *instance, const struct rte_security_capability *capability; uint16_t i = 0; - RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->capabilities_get, NULL); + RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, capabilities_get, NULL, NULL); + RTE_PTR_OR_ERR_RET(idx, NULL); + capabilities = instance->ops->capabilities_get(instance->device); if (capabilities == NULL) @@ -121,7 +154,7 @@ rte_security_capability_get(struct rte_security_ctx *instance, while ((capability = &capabilities[i++])->action != RTE_SECURITY_ACTION_TYPE_NONE) { - if (capability->action == idx->action && + if (capability->action == idx->action && capability->protocol == idx->protocol) { if (idx->protocol == RTE_SECURITY_PROTOCOL_IPSEC) { if (capability->ipsec.proto == From patchwork Wed Apr 8 03:13:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67937 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D0D9AA0597; Wed, 8 Apr 2020 05:14:50 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B357B1BF68; Wed, 8 Apr 2020 05:14:50 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 73F171BF4F for ; Wed, 8 Apr 2020 05:14:49 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031448euoutp020f406a5a37d3384eaa1a5d53c144960c~DubbjFCOa2216822168euoutp02C for ; Wed, 8 Apr 2020 03:14:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200408031448euoutp020f406a5a37d3384eaa1a5d53c144960c~DubbjFCOa2216822168euoutp02C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315688; bh=0YWcS2qDaQ1h6nZKYypd2a8cIslnGFvrqlEK4e4zOo0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iZZDKy5wTtdpvWu5wRZeG/68TGpitS/RMCbc4nk+3FW9C9r6LRRdAWT45i2wytWBm o6HVNF9phhqPD5ix/dBbsTRBSdtRGkRBIAx+8h5KiQzxNPg4rUn/QTxvlI4rzpSEEp W5WcI2eUaM+U/Oq+1Um78QZzIgWKHeFUVDtfsqsE= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200408031448eucas1p22a7b59b647c4d72688fe1c2e5147e6b5~DubbHbPlR3007630076eucas1p2m; Wed, 8 Apr 2020 03:14:48 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 79.47.60679.8A14D8E5; Wed, 8 Apr 2020 04:14:48 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200408031448eucas1p2b36997fc73f5b5e2aadb6e4bb965063b~DubavevPR3010930109eucas1p2f; Wed, 8 Apr 2020 03:14:48 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200408031448eusmtrp1d233b60bdb978746c8da787083a23a75~Dubau5Ghg1153511535eusmtrp1s; Wed, 8 Apr 2020 03:14:48 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-59-5e8d41a8b5a8 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id EE.69.07950.7A14D8E5; Wed, 8 Apr 2020 04:14:47 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200408031447eusmtip1f23b69fbcdb1d9ccab61a8f17fea714c~DubaE0oDM2966429664eusmtip1Z; Wed, 8 Apr 2020 03:14:47 +0000 (GMT) From: Lukasz Wojciechowski To: Akhil Goyal , Declan Doherty , Aviad Yehezkel , Boris Pismenny , Radu Nicolau Cc: dev@dpdk.org, stable@dpdk.org Date: Wed, 8 Apr 2020 05:13:40 +0200 Message-Id: <20200408031351.4288-3-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+NgFvrOIsWRmVeSWpSXmKPExsWy7djPc7orHHvjDL69kLRYf2Yeo8WHyUsY LY79aGe3ePOgicXi3aftTBZtXQIW/zr+sDuwe/xasJTVY/Gel0wez6YfZvLY+G4HUwBLFJdN SmpOZllqkb5dAlfGtgdnGQuO8FTcObuUvYFxFlcXIyeHhICJxOMrq9i6GLk4hARWMEo0X+xj gnC+MEpcmDKFHcL5zCixd8d7NpiWn8cmM0MkljNKdC4+glD1/2w7C0gVm4CtxJGZX1lBEiIC Jxglrvf+ZwVJMAsoStxd+RVslLCAq8TqldsZuxg5OFgEVCUObHACCfMKuEjsnb6JHWKbvMTq DQeYQUo4gcp3n+UCGSkh8JpNYu7XJVAXuUjM+fuRCcIWlnh1fAtUr4zE6ck9LBAN2xglrv7+ yQjh7Ac5aAVUlbXE4X+/2UA2MAtoSqzfpQ8RdpS4+PogC0hYQoBP4sZbQYjz+SQmbZvODBHm lehoE4Ko1pN42jOVEWbtn7VPWCBsD4nzN7ayQsLnMqPE8XfLGCcwys9CWLaAkXEVo3hqaXFu emqxUV5quV5xYm5xaV66XnJ+7iZGYHI4/e/4lx2Mu/4kHWIU4GBU4uF9kNgTJ8SaWFZcmXuI UYKDWUmEV6q3M06INyWxsiq1KD++qDQntfgQozQHi5I4r/Gil7FCAumJJanZqakFqUUwWSYO TqkGRsE8/zmVIbyP1rEozvd6ujLm3NRr9Vzf/P6fPp41O07DdKLk/E53o1dedttttvMurHkQ W7azcVPDpIK1LJrCC5U/CqtfT5JYVK1zY8Xu73zF/BuX+guK7ngqHbrlT9d26bN/E14pZ8Zc 5Nukweezv7CBkVcqcEp/0RXFns5Z5ZWhIqxzi5h0lViKMxINtZiLihMBBphPXwoDAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRmVeSWpSXmKPExsVy+t/xu7rLHXvjDOZfsLFYf2Yeo8WHyUsY LY79aGe3ePOgicXi3aftTBZtXQIW/zr+sDuwe/xasJTVY/Gel0wez6YfZvLY+G4HUwBLlJ5N UX5pSapCRn5xia1StKGFkZ6hpYWekYmlnqGxeayVkamSvp1NSmpOZllqkb5dgl7GtgdnGQuO 8FTcObuUvYFxFlcXIyeHhICJxM9jk5m7GLk4hASWMkpcXPCYpYuRAyghI/HhkgBEjbDEn2td bBA1HxklFjd+ZgJJsAnYShyZ+ZUVJCEicAao+dk1NpBmZgFlib4tViA1wgKuEqtXbmcECbMI qEoc2OAEEuYVcJHYO30TO8R8eYnVGw4wg5RwApXvPgt2mpBAvcThu5fZJjDyLWBkWMUoklpa nJueW2ykV5yYW1yal66XnJ+7iREYpNuO/dyyg7HrXfAhRgEORiUe3geJPXFCrIllxZW5hxgl OJiVRHilejvjhHhTEiurUovy44tKc1KLDzGaAp00kVlKNDkfGEF5JfGGpobmFpaG5sbmxmYW SuK8HQIHY4QE0hNLUrNTUwtSi2D6mDg4pRoYe9q/JM55t+NM1KLz16JvmDCXF/FeCjGw6pDJ /FBqqecWpPn2z/241gWL1y8/L2+/6d7X5VfXbT6/h3/XNLZnr6+cFmzf/dMhk3Vv4rUfU2w2 aQiFzJuT///c4Su2DEoVhsxzHI7v3DHhiWZQAheL9YeFfUv0TERvhD98to/b98i6WZFGG3uZ nJRYijMSDbWYi4oTAVvITntoAgAA X-CMS-MailID: 20200408031448eucas1p2b36997fc73f5b5e2aadb6e4bb965063b X-Msg-Generator: CA X-RootMTR: 20200408031448eucas1p2b36997fc73f5b5e2aadb6e4bb965063b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031448eucas1p2b36997fc73f5b5e2aadb6e4bb965063b References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 02/13] security: fix return types in documentation 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" Enhance returned values description for rte_security_session_destroy and some other minor description changes. Fixes: c261d1431bd8 ("security: introduce security API and framework") Cc: akhil.goyal@nxp.com Cc: stable@dpdk.org Signed-off-by: Lukasz Wojciechowski --- lib/librte_security/rte_security.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/librte_security/rte_security.h b/lib/librte_security/rte_security.h index ef47118fa..747830d67 100644 --- a/lib/librte_security/rte_security.h +++ b/lib/librte_security/rte_security.h @@ -378,7 +378,7 @@ rte_security_session_create(struct rte_security_ctx *instance, * @param conf update configuration parameters * @return * - On success returns 0 - * - On failure return errno + * - On failure returns a negative errno value. */ __rte_experimental int @@ -403,12 +403,14 @@ rte_security_session_get_size(struct rte_security_ctx *instance); * return it to its original mempool. * * @param instance security instance - * @param sess security session to freed + * @param sess security session to be freed * * @return * - 0 if successful. - * - -EINVAL if session is NULL. + * - -EINVAL if session or context instance is NULL. * - -EBUSY if not all device private data has been freed. + * - -ENOTSUP if destroying private data is not supported. + * - other negative values in case of freeing private data errors. */ int rte_security_session_destroy(struct rte_security_ctx *instance, From patchwork Wed Apr 8 03:13:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67939 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 371AAA0597; Wed, 8 Apr 2020 05:15:11 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8EB2C1BFDC; Wed, 8 Apr 2020 05:14:53 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 0F2E41BF59 for ; Wed, 8 Apr 2020 05:14:50 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031449euoutp0212a4646abd540fd83c74053e3da137dc~DubcEtOoD1520415204euoutp02u for ; Wed, 8 Apr 2020 03:14:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200408031449euoutp0212a4646abd540fd83c74053e3da137dc~DubcEtOoD1520415204euoutp02u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315689; bh=sCO9XcrD4PyGG+Zcp+KKj387AgtiVcHhRhOPgGMgGic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Es4GchucSSkoZCJPdpRwUujxrqP6JlboWjoW9w3Elqpi8AIn/5ulNTbKQGFmIEWHp Tb/PzGVrg93oWrRjPqTGOVKXQeOxf8KJaHU6WP5rARZn6xwYnA/okhIlBos2UJDHCN N2bGDeDEaObmCs8RkeAKjRbOgwyVUYRmoNwniL5Y= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200408031449eucas1p2a8d1c39005f0922f3d36654a197942c7~Dubb4d-P-2966729667eucas1p2-; Wed, 8 Apr 2020 03:14:49 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 7E.1B.61286.9A14D8E5; Wed, 8 Apr 2020 04:14:49 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200408031448eucas1p2d6df7ff419bb093606a2f9115297f45a~Dubbf8ZGC3008430084eucas1p2a; Wed, 8 Apr 2020 03:14:48 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200408031448eusmtrp2fc03eecda968a7c78e8250a8ef4d0c6e~DubbfYmTB0734007340eusmtrp2i; Wed, 8 Apr 2020 03:14:48 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-67-5e8d41a9c434 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id C1.DA.08375.8A14D8E5; Wed, 8 Apr 2020 04:14:48 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200408031448eusmtip17b6f42317642d8c4c3c2c249f614e7fd~Duba2asTJ2835528355eusmtip1d; Wed, 8 Apr 2020 03:14:48 +0000 (GMT) From: Lukasz Wojciechowski To: Akhil Goyal , Declan Doherty , Radu Nicolau , Boris Pismenny , Aviad Yehezkel Cc: dev@dpdk.org, stable@dpdk.org Date: Wed, 8 Apr 2020 05:13:41 +0200 Message-Id: <20200408031351.4288-4-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+NgFvrBIsWRmVeSWpSXmKPExsWy7djP87orHXvjDJq+cFqsPzOP0eLD5CWM Fsd+tLNbvHnQxGLx7tN2Jou2LgGLfx1/2B3YPX4tWMrqsXjPSyaPZ9MPM3lsfLeDKYAlissm JTUnsyy1SN8ugStjyfWTbAUt3BWX/35laWBcy9nFyMkhIWAisab9NmMXIxeHkMAKRol3PSdZ IJwvjBKTJ1+CynxmlOi5cY8ZpuXH9RPsEInljBLfHr9ih6v61Q8yjJODTcBW4sjMr6wgCRGB E4wS12c2gCWYBRQl7q78ygZiCwuYSyy7tQtsLIuAqsSRG31gNq+Ai8S3mS/YINbJS6zecAAo zsHBKeAqsfssF8hMCYH3bBKzm5+xQtS4SLyafJgRwhaWeHV8CzuELSPxf+d8JoiGbYwSV3// ZIRw9gNd1LsCqspa4vC/32wgG5gFNCXW79KHCDtK7J9/jgkkLCHAJ3HjrSDE/XwSk7ZNZ4YI 80p0tAlBVOtJPO2Zygiz9s/aJywQtofEthdPoMF4mVHizNMbrBMY5WchLFvAyLiKUTy1tDg3 PbXYMC+1XK84Mbe4NC9dLzk/dxMjMD2c/nf80w7Gr5eSDjEKcDAq8fA+SOyJE2JNLCuuzD3E KMHBrCTCK9XbGSfEm5JYWZValB9fVJqTWnyIUZqDRUmc13jRy1ghgfTEktTs1NSC1CKYLBMH p1QDI2eb0M6JkdtunWuflMJwoMOtZfnt6vJUlYDtXdLic7O/KH8t+pqnG1iwc5sXd85i9sDP HyNYnY7+v33xtM3hLSr13efa5XPboi9NXJESeOX36Qsh8bzebHL/j3x54F5/9fC5X7u3bil/ fe3shgU/J135dmIKY/6d8hOL7JhUJ188cCx2ulJOFaMSS3FGoqEWc1FxIgAI8smgCwMAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRmVeSWpSXmKPExsVy+t/xu7orHHvjDM72GlisPzOP0eLD5CWM Fsd+tLNbvHnQxGLx7tN2Jou2LgGLfx1/2B3YPX4tWMrqsXjPSyaPZ9MPM3lsfLeDKYAlSs+m KL+0JFUhI7+4xFYp2tDCSM/Q0kLPyMRSz9DYPNbKyFRJ384mJTUnsyy1SN8uQS9jyfWTbAUt 3BWX/35laWBcy9nFyMkhIWAi8eP6CXYQW0hgKaPEp1t5XYwcQHEZiQ+XBCBKhCX+XOti62Lk Air5yCix//5NZpAEm4CtxJGZX1lBEiICZxglOh5cYwNpZhZQlujbYgVSIyxgLrHs1i6wehYB VYkjN/rAbF4BF4lvM1+wQSyQl1i94QAzSCungKvE7rNcEOfUSxy+e5ltAiPfAkaGVYwiqaXF uem5xYZ6xYm5xaV56XrJ+bmbGIFBuu3Yz807GC9tDD7EKMDBqMTD+yCxJ06INbGsuDL3EKME B7OSCK9Ub2ecEG9KYmVValF+fFFpTmrxIUZToJsmMkuJJucDIyivJN7Q1NDcwtLQ3Njc2MxC SZy3Q+BgjJBAemJJanZqakFqEUwfEwenVAPjIv7I+F0W/6bUXfj5T4ZNJP35DQX13kaPN1pz 1LSmWl4591tYaMWUygD+A7z3Zk9UXKf752H0xIc6M4r51mfdmca5dfmss5Me6Tg8nHBSgp/3 wewp6cJv4v9bbzrlMyHmzMq6bQ5Tvdy/V+6fcnK+VtKmvafkrpx4NsPkn13dZLvMF3mTGKYf zFBiKc5INNRiLipOBADmWHQHaAIAAA== X-CMS-MailID: 20200408031448eucas1p2d6df7ff419bb093606a2f9115297f45a X-Msg-Generator: CA X-RootMTR: 20200408031448eucas1p2d6df7ff419bb093606a2f9115297f45a X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031448eucas1p2d6df7ff419bb093606a2f9115297f45a References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 03/13] security: fix session counter 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" Fix session counter to be decreased in rte_security_session_destroy only when session was successfully destroyed. Formerly session counter was decreased prior session destroying and returning session object to mempool. It remained decreased even if session was not destroyed and mempool object released making counter invalid. Fixes: c261d1431bd8 ("security: introduce security API and framework") Cc: akhil.goyal@nxp.com Cc: stable@dpdk.org Signed-off-by: Lukasz Wojciechowski --- lib/librte_security/rte_security.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/librte_security/rte_security.c b/lib/librte_security/rte_security.c index f1b4a894e..ae57d3421 100644 --- a/lib/librte_security/rte_security.c +++ b/lib/librte_security/rte_security.c @@ -90,14 +90,16 @@ rte_security_session_destroy(struct rte_security_ctx *instance, -ENOTSUP); RTE_PTR_OR_ERR_RET(sess, -EINVAL); + ret = instance->ops->session_destroy(instance->device, sess); + if (ret != 0) + return ret; + + rte_mempool_put(rte_mempool_from_obj(sess), (void *)sess); + if (instance->sess_cnt) instance->sess_cnt--; - ret = instance->ops->session_destroy(instance->device, sess); - if (!ret) - rte_mempool_put(rte_mempool_from_obj(sess), (void *)sess); - - return ret; + return 0; } int From patchwork Wed Apr 8 03:13:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67940 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id AB2C8A0597; Wed, 8 Apr 2020 05:15:21 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A3A861BFC4; Wed, 8 Apr 2020 05:14:55 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id BC23E1BF92 for ; Wed, 8 Apr 2020 05:14:51 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031451euoutp01a3a57d11695dc7164faff0234bc3da2c~Dubd_VpR61461214612euoutp01J for ; Wed, 8 Apr 2020 03:14:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200408031451euoutp01a3a57d11695dc7164faff0234bc3da2c~Dubd_VpR61461214612euoutp01J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315691; bh=eWKfuyzJ/4Kv3fP8aeQW/Vnu7OJaUhy4egd6L5FLCCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kp1pd81hFarVeRgumjMz9rDWSRqvfCsqYuagbw2/T45fHgvRIduDRhPfshh3H1I6R kdctEIK053yDxs9ebcsX21EeELo+uJ1RM7TlnhaO1EtktQjmkhBZtST12UMKqbAx6h 9/+NOzOdfnUp0Wz0b6kKau6ABwmrMcHiXd9wBMko= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200408031451eucas1p2a8e420fc0f1ebbddd9796fd3a45f88ad~DubdgS2jE3010930109eucas1p2g; Wed, 8 Apr 2020 03:14:51 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 87.1A.60698.AA14D8E5; Wed, 8 Apr 2020 04:14:50 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200408031449eucas1p1ca89719463cbaf29e9f7c81beaec88c2~DubcOtPeA0246502465eucas1p1P; Wed, 8 Apr 2020 03:14:49 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200408031449eusmtrp14a59d67cc43257ef48ed5c5986a420f4~DubcOJ0KX1153511535eusmtrp1t; Wed, 8 Apr 2020 03:14:49 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-32-5e8d41aae868 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 6F.69.07950.9A14D8E5; Wed, 8 Apr 2020 04:14:49 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200408031448eusmtip19322579c55db4f496b30edf6d02b31df~Dubbm4l-X2966429664eusmtip1a; Wed, 8 Apr 2020 03:14:48 +0000 (GMT) From: Lukasz Wojciechowski To: Thomas Monjalon , Pavan Nikhilesh , Jerin Jacob Cc: dev@dpdk.org, stable@dpdk.org Date: Wed, 8 Apr 2020 05:13:42 +0200 Message-Id: <20200408031351.4288-5-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+NgFnrKIsWRmVeSWpSXmKPExsWy7djPc7qrHHvjDLY+NrV492k7k8XESSYW F9dZWPzr+MNu8enBCRYHVo8NJ/pZPX4tWMrqcezmNPYA5igum5TUnMyy1CJ9uwSujCN/uQva 2Cp6Zq1kamDsZu1i5OSQEDCR+Nd1nLmLkYtDSGAFo8TEZ11MEM4XRok3DXvZIJzPjBJPH/xm h2nZ/HAfVNVyRol1T6YzwVW92nqOCaSKTcBW4sjMr2BLRAT6GCXm7xcGsZkFFCXurvzKBmIL C1hIzOnpAqthEVCVmPBxCtgGXgEXib8tB6EOlJdYveEA0IEcHJwCrhK7z3KB7JIQuMwm8bpj NTNEjYvE8f5tjBC2sMSr41ugLpWROD25hwWiYRujxNXfPxkhnP2MEtd7V0BVWUsc/vebDWQD s4CmxPpd+hBhR4k/84+DhSUE+CRuvBWEuJ9PYtK26cwQYV6JjjYhiGo9iac9Uxlh1v5Z+4QF osRDYupxW0jwXGaUaNnwm20Co/wshF0LGBlXMYqnlhbnpqcWG+ellusVJ+YWl+al6yXn525i BEb+6X/Hv+5g3Pcn6RCjAAejEg/vg8SeOCHWxLLiytxDjBIczEoivFK9nXFCvCmJlVWpRfnx RaU5qcWHGKU5WJTEeY0XvYwVEkhPLEnNTk0tSC2CyTJxcEo1MCo5VS9I7/pokhj59usVyVvb pavz/ixMisiQ/qwjfHfCREnW7l3zr/5dv/nNxi2fGBPPRJ1PnRPynv34x8AsVdUv9SdUXvCc 5ru0/4tSamH8HykWw3zJ/cfWlZyzmX7qg6LOkn/mc6dc/z9jfY0279WAldUH39wtaG2xnXhm Ymwi1/F7+x1nZN5VYinOSDTUYi4qTgQAeURKxfgCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCLMWRmVeSWpSXmKPExsVy+t/xu7orHXvjDDYuU7B492k7k8XESSYW F9dZWPzr+MNu8enBCRYHVo8NJ/pZPX4tWMrqcezmNPYA5ig9m6L80pJUhYz84hJbpWhDCyM9 Q0sLPSMTSz1DY/NYKyNTJX07m5TUnMyy1CJ9uwS9jCN/uQva2Cp6Zq1kamDsZu1i5OSQEDCR 2PxwH1MXIxeHkMBSRom7W98ydzFyACVkJD5cEoCoEZb4c62LDcQWEvjIKPFyVyCIzSZgK3Fk 5ldWkF4RgT5Gif+fDrKD9DILKEv0bbECqREWsJCY09MFtotFQFViwscp7CA2r4CLxN+Wg1A3 yEus3nAAbC2ngKvE7rNcEKvqJQ7fvcw2gZFvASPDKkaR1NLi3PTcYiO94sTc4tK8dL3k/NxN jMAQ3Hbs55YdjF3vgg8xCnAwKvHwPkjsiRNiTSwrrsw9xCjBwawkwivV2xknxJuSWFmVWpQf X1Sak1p8iNEU6KaJzFKiyfnA+MgriTc0NTS3sDQ0NzY3NrNQEuftEDgYIySQnliSmp2aWpBa BNPHxMEp1cCYzHOE9+mXhCW+T94dSm181PznxmGxld0rl/0o9NA56jdpQtbn1Ux9XCwJLUGT n05Qk/d8tHm2mM8dtZgd+vfYFos4GK2TTZ5539K+nGHZ183/K+pTplaU/nsr0+byVddCoPJQ 6nybeX11E8McHXTW84vOXm/J/Sk1XfhRHetPxWmPd+5dtmqCEktxRqKhFnNRcSIAvDRlclcC AAA= X-CMS-MailID: 20200408031449eucas1p1ca89719463cbaf29e9f7c81beaec88c2 X-Msg-Generator: CA X-RootMTR: 20200408031449eucas1p1ca89719463cbaf29e9f7c81beaec88c2 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031449eucas1p1ca89719463cbaf29e9f7c81beaec88c2 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 04/13] app/test: fix macro definition 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" Wrap RTE_TEST_TRACE_FAILURE macro definition into #ifndef clause as it might be already defined. Fixes: 5afc521eac6a ("eal: add test assert macros") Cc: pbhagavatula@caviumnetworks.com Cc: stable@dpdk.org Signed-off-by: Lukasz Wojciechowski --- app/test/test.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/test/test.h b/app/test/test.h index ac0c50616..8ac581cbc 100644 --- a/app/test/test.h +++ b/app/test/test.h @@ -22,7 +22,9 @@ # define TEST_TRACE_FAILURE(_file, _line, _func) #endif -#define RTE_TEST_TRACE_FAILURE TEST_TRACE_FAILURE +#ifndef RTE_TEST_TRACE_FAILURE +# define RTE_TEST_TRACE_FAILURE TEST_TRACE_FAILURE +#endif #include From patchwork Wed Apr 8 03:13:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67941 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E3C0CA0597; Wed, 8 Apr 2020 05:15:31 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EDDEC1C02A; Wed, 8 Apr 2020 05:14:56 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 4BEDB1BF92 for ; Wed, 8 Apr 2020 05:14:52 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031452euoutp02018c1d0a5a07e8fdd8a4f6c3569c9e49~Dubeiy8IN2216822168euoutp02G for ; Wed, 8 Apr 2020 03:14:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200408031452euoutp02018c1d0a5a07e8fdd8a4f6c3569c9e49~Dubeiy8IN2216822168euoutp02G DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315692; bh=WrcdDMMRND8v2u1ONiKug0Uemv1+AJ6IvTjxmpvaYco=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WoshjppJ7B/uo2Bqe0epSqe02q425pQy8jaQEJhX04oS1g5XC90Hs8Dc3cyNqsgRm I6afmY/Co33x7UsviKdIxznARQnQKCSAbMTCeoH2KhghQjl4y0Y9KoJGQ7G/zYy74F xcCcajQReDUXpR72iDbPpJ5YlUKdlkom5PtDGRVg= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200408031451eucas1p1e45060f1d6691fad32ef52e172dcf2c2~Dubd9o1no2414224142eucas1p1b for ; Wed, 8 Apr 2020 03:14:51 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id F9.47.60679.BA14D8E5; Wed, 8 Apr 2020 04:14:51 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200408031450eucas1p1a0b6ca84cbac2f7542212e185de1ddf5~DubddCPFj1426114261eucas1p1o for ; Wed, 8 Apr 2020 03:14:50 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200408031450eusmtrp20ab5a9fb1dda18666b33ce83b000cbff~DubdchX3A0734007340eusmtrp2j for ; Wed, 8 Apr 2020 03:14:50 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-5d-5e8d41abc88f Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 42.DA.08375.AA14D8E5; Wed, 8 Apr 2020 04:14:50 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200408031449eusmtip102647f5a9696a55a84ded6bf00b6304f~DubcStBYm2835528355eusmtip1e for ; Wed, 8 Apr 2020 03:14:49 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Wed, 8 Apr 2020 05:13:43 +0200 Message-Id: <20200408031351.4288-6-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+NgFjrNIsWRmVeSWpSXmKPExsWy7djPc7qrHXvjDF62yFi8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGSumihQ82s9YsWBxL3sD4+T5jF2MnBwSAiYSS5/vYO1i5OIQ EljBKHHh5j92CKedSWJa3wI2kCohgTYmiWczxWE6/q/sZoIoWs4oMevdIkYIB6jo0dQWJpAq NgFbiSMzv7KC2CICLBIrv39nAbGZBQQkHt97BhYXFnCWWNR5ESzOIqAq8Wj1BrA4r4CLxOS7 51khtslLrN5wgLmLkYODU8BVYvdZLpBdEgJr2CSapk9lg6hxkdi26RHUP8ISr45vYYewZST+ 75zPBNGwjVHi6u+fjBDOfkaJ670roKqsJQ7/+80GsoFZQFNi/S59iLCjxJ2dZ8EWSwjwSdx4 KwhxP5/EpG3TocK8Eh1tQhDVehJPe6Yywqz9s/YJC4TtIfHhQAszJHwuM0p87djNOoFRfhbC sgWMjKsYxVNLi3PTU4uN8lLL9YoTc4tL89L1kvNzNzECo/j0v+NfdjDu+pN0iFGAg1GJh/dB Yk+cEGtiWXFl7iFGCQ5mJRFeqd7OOCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8xotexgoJpCeW pGanphakFsFkmTg4pRoYs/Ovq8xUt7jLWOrnwenqMiMlb1byU7cXhse2SW21cZVleHq3Lpi7 +rCH3omj25zNjpuyyeae2Pnn7LJi56NnVJ2fH19aom7NcH5Rv+L+sxkr1V4sTWFeHN28lOOx 4vQtCpJ7+pIa377MLPjX9EkidaXz9aTrO4tfNUwWnGbnyMLLH6ykOnerEktxRqKhFnNRcSIA 2pofXd4CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrNLMWRmVeSWpSXmKPExsVy+t/xu7qrHHvjDNauNLV492k7kwOjx68F S1kDGKP0bIryS0tSFTLyi0tslaINLYz0DC0t9IxMLPUMjc1jrYxMlfTtbFJSczLLUov07RL0 MlZMFSl4tJ+xYsHiXvYGxsnzGbsYOTkkBEwk/q/sZupi5OIQEljKKHF39nKWLkYOoISMxIdL AhA1whJ/rnWxQdS0MEnMW7mLHSTBJmArcWTmV1YQW0SARWLl9+8sIDazgIDE43vPwOLCAs4S izovgsVZBFQlHq3eABbnFXCRmHz3PCvEAnmJ1RsOMIPs5RRwldh9lgskLCRQL3H47mW2CYx8 CxgZVjGKpJYW56bnFhvqFSfmFpfmpesl5+duYgQG1LZjPzfvYLy0MfgQowAHoxIP74PEnjgh 1sSy4srcQ4wSHMxKIrxSvZ1xQrwpiZVVqUX58UWlOanFhxhNgW6ayCwlmpwPDPa8knhDU0Nz C0tDc2NzYzMLJXHeDoGDMUIC6YklqdmpqQWpRTB9TBycUg2M0/8pXvrzZ5ZMxTuuxF93T9+W iXoqPef5kyRB5kSbhXfjjs4+ZP9v/opQvjMTOR0XiMRwGStNrb8fFhRk5zxf3/YFY9evWZKl Z04oph4vsBQubK70nO0atOB70v0ProGiftyNNTbK91oUFLhVp91Z9J/j/50E7ZYLDd8y/aUX bf514pQ+U42CEktxRqKhFnNRcSIAYaZyOz4CAAA= X-CMS-MailID: 20200408031450eucas1p1a0b6ca84cbac2f7542212e185de1ddf5 X-Msg-Generator: CA X-RootMTR: 20200408031450eucas1p1a0b6ca84cbac2f7542212e185de1ddf5 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031450eucas1p1a0b6ca84cbac2f7542212e185de1ddf5 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 05/13] app/test: introduce librte security 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" This patch introduces set of unit tests of librte_security API functions. Tests are added to dpdk-test application and can be run with "security_autotest" runtime command. This is the first patch in the series of patches as adding all test cases for all API functions in a single patch would make it unreadable. This patch defines structure of the file and necessary test framework initialization. It also contains first subset of unit tests for rte_security_session_create API function. Structure of the tests file is following: - macros for making tests more readable; - mockup structures and functions for rte_security_ops; - test suite and test cases setup and teardown functions; - tests functions; - declaration of testcases. Signed-off-by: Lukasz Wojciechowski --- app/test/Makefile | 2 + app/test/meson.build | 3 + app/test/test_security.c | 683 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 688 insertions(+) create mode 100644 app/test/test_security.c diff --git a/app/test/Makefile b/app/test/Makefile index 1f080d162..153610a32 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -231,6 +231,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_BPF) += test_bpf.c SRCS-$(CONFIG_RTE_LIBRTE_RCU) += test_rcu_qsbr.c test_rcu_qsbr_perf.c +SRCS-$(CONFIG_RTE_LIBRTE_SECURITY) += test_security.c + SRCS-$(CONFIG_RTE_LIBRTE_IPSEC) += test_ipsec.c SRCS-$(CONFIG_RTE_LIBRTE_IPSEC) += test_ipsec_sad.c ifeq ($(CONFIG_RTE_LIBRTE_IPSEC),y) diff --git a/app/test/meson.build b/app/test/meson.build index 351d29cb6..f3c775b34 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -103,6 +103,7 @@ test_sources = files('commands.c', 'test_ring_perf.c', 'test_rwlock.c', 'test_sched.c', + 'test_security.c', 'test_service_cores.c', 'test_spinlock.c', 'test_stack.c', @@ -150,6 +151,7 @@ test_deps = ['acl', 'reorder', 'rib', 'ring', + 'security', 'stack', 'timer' ] @@ -211,6 +213,7 @@ fast_tests = [ ['rwlock_rds_wrm_autotest', true], ['rwlock_rde_wro_autotest', true], ['sched_autotest', true], + ['security_autotest', false], ['spinlock_autotest', true], ['stack_autotest', false], ['stack_lf_autotest', false], diff --git a/app/test/test_security.c b/app/test/test_security.c new file mode 100644 index 000000000..3fc83abae --- /dev/null +++ b/app/test/test_security.c @@ -0,0 +1,683 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + */ + +#include +#include +#include +#include +#include +#include + +/* Before including rte_test.h file you can define + * RTE_TEST_TRACE_FAILURE(_file, _line, _func) macro to better trace/debug test + * failures. Mostly useful in development phase. + */ +#ifndef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE(_file, _line, _func) \ + RTE_LOG(DEBUG, EAL, "in %s:%d %s\n", _file, _line, _func) +#endif + +#include +#include "test.h" + +/** + * Security + * ======= + * + * Basic unit tests of the librte_security API. + * + * Structure of the file: + * - macros for making tests more readable; + * - mockup structures and functions for rte_security_ops; + * - test suite and test cases setup and teardown functions; + * - tests functions; + * - declaration of testcases. + */ + + +/** + * Macros + * + * Set of macros for making tests easier to read. + */ + +/** + * Verify condition inside mocked up function. + * Mockup function cannot return a test error, so the failure + * of assertion increases counter and print logs. + * The counter can be verified later to check if test case should fail. + * + * @param fail_counter fail counter + * @param cond condition expected to be true + * @param msg printf style formatting string for custom message + */ +#define MOCK_TEST_ASSERT(fail_counter, cond, msg, ...) do { \ + if (!(cond)) { \ + fail_counter++; \ + RTE_LOG(DEBUG, EAL, "Test assert %s line %d failed: " \ + msg "\n", __func__, __LINE__, \ + ##__VA_ARGS__); \ + RTE_TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \ + } \ +} while (0) + +/** + * Verify equality condition inside mocked up function. + * Mockup function cannot return a test error, so the failure + * of assertion increases counter and print logs. + * The counter can be verified later to check if test case should fail. + * + * @param fail_counter fail counter + * @param a first value of comparison + * @param b second value of comparison + * @param msg printf style formatting string for custom message + */ +#define MOCK_TEST_ASSERT_EQUAL(fail_counter, a, b, msg, ...) \ + MOCK_TEST_ASSERT(fail_counter, (a) == (b), msg, ##__VA_ARGS__) + + +/** + * Verify if parameter of the mocked up function matches expected value. + * The expected value is stored in data structure in the field matching + * parameter name. + * + * @param data structure with expected values + * @param parameter name of the parameter (both field and parameter name) + * @param spec printf style spec for parameter + */ +#define MOCK_TEST_ASSERT_PARAMETER(data, parameter, spec) \ + MOCK_TEST_ASSERT_EQUAL(data.failed, data.parameter, parameter, \ + "Expecting parameter %s to be " spec \ + " but it's " spec, RTE_STR(parameter), \ + data.parameter, parameter) + +/** + * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for pointer type parameters. + * + * @param data structure with expected values + * @param parameter name of the parameter (both field and parameter name) + */ +#define MOCK_TEST_ASSERT_POINTER_PARAMETER(data, parameter) \ + MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%p") + +/** + * Verify number of calls of the mocked up function + * and check if there were any fails during execution. + * The fails statistics inside mocked up functions are collected + * as "failed" field in mockup structures. + * + * @param mock_data structure with statistics (called, failed) + * @param exp_calls expected number of mockup function calls + */ +#define TEST_ASSERT_MOCK_CALLS(mock_data, exp_calls) do { \ + TEST_ASSERT_EQUAL(exp_calls, mock_data.called, \ + "Expecting sub op to be called %d times, " \ + "but it's called %d times", \ + exp_calls, mock_data.called); \ + TEST_ASSERT_EQUAL(0, mock_data.failed, \ + "Expecting sub op asserts not to fail, " \ + "but they're failed %d times", \ + mock_data.failed); \ +} while (0) + +/** + * Assert tested function result match expected value + * + * @param f_name name of tested function + * @param f_ret value returned by the function + * @param exp_ret expected returned value + * @param fmt printf style format for returned value + */ +#define TEST_ASSERT_MOCK_FUNCTION_CALL_RET(f_name, f_ret, exp_ret, fmt) \ + TEST_ASSERT_EQUAL(exp_ret, f_ret, "Expecting " RTE_STR(f_name) \ + " to return " fmt ", but it returned " fmt \ + "\n", exp_ret, f_ret) + +/** + * Assert tested function result is not NULL + * + * @param f_name name of tested function + * @param f_ret value returned by the function + */ +#define TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(f_name, f_ret) \ + TEST_ASSERT_NOT_NULL(f_ret, "Expecting " RTE_STR(f_name) \ + " to return not NULL\n") + +/** + * Verify that sess_cnt counter value matches expected + * + * @param expected_sessions_count expected counter value + */ +#define TEST_ASSERT_SESSION_COUNT(expected_sessions_count) do { \ + struct security_unittest_params *ut_params = &unittest_params; \ + TEST_ASSERT_EQUAL(expected_sessions_count, \ + ut_params->ctx.sess_cnt, \ + "Expecting session counter to be %u," \ + " but it's %u", expected_sessions_count, \ + ut_params->ctx.sess_cnt); \ +} while (0) + +/** + * Verify usage of mempool by checking if number of allocated objects matches + * expectations. The mempool is used to manage objects for sessions data. + * A single object is acquired from mempool during session_create + * and put back in session_destroy. + * + * @param expected_mempool_usage expected number of used mempool objects + */ +#define TEST_ASSERT_MEMPOOL_USAGE(expected_mempool_usage) do { \ + struct security_testsuite_params *ts_params = &testsuite_params;\ + unsigned int mempool_usage; \ + mempool_usage = rte_mempool_in_use_count( \ + ts_params->session_mpool); \ + TEST_ASSERT_EQUAL(expected_mempool_usage, mempool_usage, \ + "Expecting %u mempool allocations, " \ + "but there are %u allocated objects", \ + expected_mempool_usage, mempool_usage); \ +} while (0) + + +/** + * Mockup structures and functions for rte_security_ops; + * + * Set of structures for controlling mockup functions calls. + * Every mockup function X has its corresponding X_data structure + * and an instance of that structure X_exp. + * Structure contains parameters that a mockup function is expected + * to be called with, a value to return (.ret) and 2 statistics: + * .called (number of times the mockup function was called) + * and .failed (number of assertion fails during mockup function call). + * + * Mockup functions verify that the parameters they are called with match + * expected values. The expected values should be stored in corresponding + * structures prior to mockup functions call. Every failure of such + * verification increases .failed counter. Every call of mockup function + * increases .called counter. Function returns value stored in .ret field + * of the structure. + * In case of some parameters in some functions the expected value is unknown + * and cannot be detrmined prior to call. Such parameters are stored + * in structure and can be compared or analyzed later in test case code. + * + * Below structures and functions follow the rules just described. + * Additional remarks and exceptions are added in comments. + */ + +/** + * session_create mockup + * + * Verified parameters: device, conf, mp. + * Saved, not verified parameters: sess. + */ +static struct mock_session_create_data { + void *device; + struct rte_security_session_conf *conf; + struct rte_security_session *sess; + struct rte_mempool *mp; + + int ret; + + int called; + int failed; +} mock_session_create_exp = {NULL, NULL, NULL, NULL, 0, 0, 0}; + +static int +mock_session_create(void *device, + struct rte_security_session_conf *conf, + struct rte_security_session *sess, + struct rte_mempool *mp) +{ + mock_session_create_exp.called++; + + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, device); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, conf); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_create_exp, mp); + + mock_session_create_exp.sess = sess; + + return mock_session_create_exp.ret; +} + +/** + * session_destroy mockup + * + * Verified parameters: device, sess. + */ +static struct mock_session_destroy_data { + void *device; + struct rte_security_session *sess; + + int ret; + + int called; + int failed; +} mock_session_destroy_exp = {NULL, NULL, 0, 0, 0}; + +static int +mock_session_destroy(void *device, struct rte_security_session *sess) +{ + mock_session_destroy_exp.called++; + + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, device); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_destroy_exp, sess); + + return mock_session_destroy_exp.ret; +} + +/** + * empty_ops + * + * is an empty security operations set (all function pointers set to NULL) + */ +struct rte_security_ops empty_ops = { NULL }; + +/** + * mock_ops + * + * is a security operations set using mockup functions + */ +struct rte_security_ops mock_ops = { + .session_create = mock_session_create, + .session_destroy = mock_session_destroy, +}; + + +/** + * Test suite and test cases setup and teardown functions. + */ + +/** + * struct security_testsuite_params defines parameters initialized once + * for whole tests suite. + * Currently the only stored parameter is session_mpool a mempool created + * once in testsuite_setup and released in testsuite_teardown. + * The instance of this structure is stored in testsuite_params variable. + */ +static struct security_testsuite_params { + struct rte_mempool *session_mpool; +} testsuite_params = { NULL }; + +/** + * struct security_unittest_params defines parameters initialized + * for every test case. The parameters are initialized in ut_setup + * and released in ut_teardown. + * The instance of this structure is stored in unittest_params variable. + */ +static struct security_unittest_params { + struct rte_security_ctx ctx; + struct rte_security_session_conf conf; + struct rte_security_session *sess; +} unittest_params = { + .ctx = { + .device = NULL, + .ops = &mock_ops, + .sess_cnt = 0, + }, + .sess = NULL, +}; + +#define SECURITY_TEST_MEMPOOL_NAME "SecurityTestsMempoolName" +#define SECURITY_TEST_MEMPOOL_SIZE 15 +#define SECURITY_TEST_SESSION_OBJECT_SIZE sizeof(struct rte_security_session) + +/** + * testsuite_setup initializes whole test suite parameters. + * It creates a new mempool used in all test cases + * and verifies if it properly created. + */ +static int +testsuite_setup(void) +{ + struct security_testsuite_params *ts_params = &testsuite_params; + ts_params->session_mpool = rte_mempool_create( + SECURITY_TEST_MEMPOOL_NAME, + SECURITY_TEST_MEMPOOL_SIZE, + SECURITY_TEST_SESSION_OBJECT_SIZE, + 0, 0, NULL, NULL, NULL, NULL, + SOCKET_ID_ANY, 0); + TEST_ASSERT_NOT_NULL(ts_params->session_mpool, + "Cannot create mempool %s\n", rte_strerror(rte_errno)); + return TEST_SUCCESS; +} + +/** + * testsuite_teardown releases test suite wide parameters. + */ +static void +testsuite_teardown(void) +{ + struct security_testsuite_params *ts_params = &testsuite_params; + if (ts_params->session_mpool) { + rte_mempool_free(ts_params->session_mpool); + ts_params->session_mpool = NULL; + } +} + +/** + * ut_setup initializes test case parameters to default values. + * It resets also any .called and .failed statistics of mockup functions + * usage. + */ +static int +ut_setup(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + ut_params->ctx.device = NULL; + ut_params->ctx.ops = &mock_ops; + ut_params->ctx.sess_cnt = 0; + ut_params->sess = NULL; + + mock_session_create_exp.called = 0; + mock_session_destroy_exp.called = 0; + + mock_session_create_exp.failed = 0; + mock_session_destroy_exp.failed = 0; + + return TEST_SUCCESS; +} + +/** + * destroy_session_with_check is a helper function releasing session + * 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 + */ +static int +destroy_session_with_check(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + if (ut_params->sess != NULL) { + /* Assure that mockup function for destroy operation is set. */ + ut_params->ctx.ops = &mock_ops; + + mock_session_destroy_exp.device = NULL; + mock_session_destroy_exp.sess = ut_params->sess; + mock_session_destroy_exp.ret = 0; + mock_session_destroy_exp.called = 0; + mock_session_destroy_exp.failed = 0; + + 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); + + ut_params->sess = NULL; + } + return TEST_SUCCESS; +} + +/** + * ut_teardown releases test case parameters. + */ +static void +ut_teardown(void) +{ + destroy_session_with_check(); +} + + +/** + * Test functions + * + * Each test function is related to a single test case. + * They are arranged by tested rte_security API function + * and by rte_security execution paths sequence in code. + */ + +/** + * rte_security_session_create tests + */ + +/** + * Test execution of rte_security_session_create with NULL instance + */ +static int +test_session_create_inv_context(void) +{ + struct security_testsuite_params *ts_params = &testsuite_params; + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_session *sess; + + sess = rte_security_session_create(NULL, &ut_params->conf, + ts_params->session_mpool); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create, + sess, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0); + TEST_ASSERT_MEMPOOL_USAGE(0); + TEST_ASSERT_SESSION_COUNT(0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_create with invalid + * security operations structure (NULL) + */ +static int +test_session_create_inv_context_ops(void) +{ + struct security_testsuite_params *ts_params = &testsuite_params; + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_session *sess; + + ut_params->ctx.ops = NULL; + + sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf, + ts_params->session_mpool); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create, + sess, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0); + TEST_ASSERT_MEMPOOL_USAGE(0); + TEST_ASSERT_SESSION_COUNT(0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_create with empty + * security operations + */ +static int +test_session_create_inv_context_ops_fun(void) +{ + struct security_testsuite_params *ts_params = &testsuite_params; + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_session *sess; + + ut_params->ctx.ops = &empty_ops; + + sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf, + ts_params->session_mpool); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create, + sess, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0); + TEST_ASSERT_MEMPOOL_USAGE(0); + TEST_ASSERT_SESSION_COUNT(0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_create with NULL conf parameter + */ +static int +test_session_create_inv_configuration(void) +{ + struct security_testsuite_params *ts_params = &testsuite_params; + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_session *sess; + + sess = rte_security_session_create(&ut_params->ctx, NULL, + ts_params->session_mpool); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create, + sess, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0); + TEST_ASSERT_MEMPOOL_USAGE(0); + TEST_ASSERT_SESSION_COUNT(0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_create with NULL mp parameter + */ +static int +test_session_create_inv_mempool(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_session *sess; + + sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf, + NULL); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create, + sess, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0); + TEST_ASSERT_MEMPOOL_USAGE(0); + TEST_ASSERT_SESSION_COUNT(0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_create in case when mempool + * is fully used and no object can be got from it + */ +static int +test_session_create_mempool_empty(void) +{ + struct security_testsuite_params *ts_params = &testsuite_params; + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_session *tmp[SECURITY_TEST_MEMPOOL_SIZE]; + struct rte_security_session *sess; + + /* Get all available objects from mempool. */ + int i, ret; + for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) { + ret = rte_mempool_get(ts_params->session_mpool, + (void **)(&tmp[i])); + TEST_ASSERT_EQUAL(0, ret, + "Expect getting %d object from mempool" + " to succeed", i); + } + TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE); + + sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf, + ts_params->session_mpool); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create, + sess, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 0); + TEST_ASSERT_MEMPOOL_USAGE(SECURITY_TEST_MEMPOOL_SIZE); + TEST_ASSERT_SESSION_COUNT(0); + + /* Put objects back to the pool. */ + for (i = 0; i < SECURITY_TEST_MEMPOOL_SIZE; ++i) + rte_mempool_put(ts_params->session_mpool, (void *)(tmp[i])); + TEST_ASSERT_MEMPOOL_USAGE(0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_create when session_create + * security operation fails + */ +static int +test_session_create_ops_failure(void) +{ + struct security_testsuite_params *ts_params = &testsuite_params; + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_session *sess; + + 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 = -1; /* Return failure status. */ + + sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf, + ts_params->session_mpool); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_create, + sess, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1); + TEST_ASSERT_MEMPOOL_USAGE(0); + TEST_ASSERT_SESSION_COUNT(0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_create in successful execution path + */ +static int +test_session_create_success(void) +{ + struct security_testsuite_params *ts_params = &testsuite_params; + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_session *sess; + + 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; /* Return success status. */ + + 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); + TEST_ASSERT_MEMPOOL_USAGE(1); + TEST_ASSERT_SESSION_COUNT(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; +} + + +/** + * Declaration of testcases + */ +static struct unit_test_suite security_testsuite = { + .suite_name = "generic security", + .setup = testsuite_setup, + .teardown = testsuite_teardown, + .unit_test_cases = { + TEST_CASE_ST(ut_setup, ut_teardown, + test_session_create_inv_context), + TEST_CASE_ST(ut_setup, ut_teardown, + test_session_create_inv_context_ops), + TEST_CASE_ST(ut_setup, ut_teardown, + test_session_create_inv_context_ops_fun), + TEST_CASE_ST(ut_setup, ut_teardown, + test_session_create_inv_configuration), + TEST_CASE_ST(ut_setup, ut_teardown, + test_session_create_inv_mempool), + TEST_CASE_ST(ut_setup, ut_teardown, + test_session_create_mempool_empty), + TEST_CASE_ST(ut_setup, ut_teardown, + test_session_create_ops_failure), + TEST_CASE_ST(ut_setup, ut_teardown, + test_session_create_success), + + TEST_CASES_END() /**< NULL terminate unit test array */ + } +}; + +static int +test_security(void) +{ + rte_log_set_global_level(RTE_LOG_DEBUG); + rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG); + + return unit_test_suite_runner(&security_testsuite); +} + +REGISTER_TEST_COMMAND(security_autotest, test_security); From patchwork Wed Apr 8 03:13:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67942 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org 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/f2cBsZkFBCQe33sGFhcW8JSYP3sXI4jNIqAqsfv3LCCbg4NXwEXiS3sF xC55idUbDjCDhDkFXCV2n+UCWSUhsIZNom/tYUaIGheJGYcfsUPYwhKvjm+BsmUkTk/uYYFo 2MYocfX3T0YIZz+jxPXeFVBV1hKH//1mA9nALKApsX6XPkTYUeLbk7ssIGEJAT6JG28FIc7n k5i0bTozRJhXoqNNCKJaT+Jpz1RGmLV/1j5hgbA9JI6cegENqsuMEpO7wicwys9C2LWAkXEV o3hqaXFuemqxYV5quV5xYm5xaV66XnJ+7iZGYPye/nf80w7Gr5eSDjEKcDAq8fA+SOyJE2JN LCuuzD3EKMHBrCTCK9XbGSfEm5JYWZValB9fVJqTWnyIUZqDRUmc13jRy1ghgfTEktTs1NSC 1CKYLBMHp1QDY5la4j3ht5IfTVfbsW7MsUkJjDc5NH3jk5kJ/cfFRD9++ch9NjzD6qixct7n 5XsvPX6lt9TS/vBqo0Ce0+bJRXsrLj/jfhZYedCd1WeRvljG56aS1IsNTrxHxZ7NPvjIKsBI yf76S60r7z2TBH/4q13jvHRnor7TohwZgeQ7EV93vss8b11zTImlOCPRUIu5qDgRANy3dRjb AgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJLMWRmVeSWpSXmKPExsVy+t/xu7qrHXvjDO6/FbZ492k7kwOjx68F S1kDGKP0bIryS0tSFTLyi0tslaINLYz0DC0t9IxMLPUMjc1jrYxMlfTtbFJSczLLUov07RL0 MiYcu8hUsNG9YurCr6wNjLtsuhg5OSQETCQ+fb7C3MXIxSEksJRR4k3XG9YuRg6ghIzEh0sC EDXCEn+udbFB1LQwSey4c4cdJMEmYCtxZOZXVhBbRIBFYuX37ywgNrOAgMTje8/A4sICnhLz Z+9iBLFZBFQldv+exQgyn1fAReJLewXEfHmJ1RsOMIOEOQVcJXaf5QIJCwnUSxy+e5ltAiPf AkaGVYwiqaXFuem5xUZ6xYm5xaV56XrJ+bmbGIHBtO3Yzy07GLveBR9iFOBgVOLhfZDYEyfE mlhWXJl7iFGCg1lJhFeqtzNOiDclsbIqtSg/vqg0J7X4EKMp0EkTmaVEk/OBgZ5XEm9oamhu YWlobmxubGahJM7bIXAwRkggPbEkNTs1tSC1CKaPiYNTqoFRPOKJtK3kf5s19tHsW7lfvjTI eL/1YOFa+TQ7/9Nlh84Vvur8uP3PK6FOueev/y9MdHJ/ZcKq7OQb1lBz1qhD/9pXn6khkbeK dJec7+K5ytpoudt1w6OkfZeiAuyWuHNx2bHIeOxZH5PznuOK7Kav7BNq8tTVDUq2Hzo+cfIN Q+VGIc9N0xSVWIozEg21mIuKEwHSCnQiPAIAAA== X-CMS-MailID: 20200408031451eucas1p2769ae9d814ef1ccd286407767054e117 X-Msg-Generator: CA 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 */ } }; From patchwork Wed Apr 8 03:13:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67943 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B0C21A0597; Wed, 8 Apr 2020 05:15:59 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6FA581C06D; Wed, 8 Apr 2020 05:15:00 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 43C1B1BFC2 for ; Wed, 8 Apr 2020 05:14:53 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031453euoutp02c3192eff208cf059de7b763681666879~DubfbpHBi1520915209euoutp02x for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200408031453euoutp02c3192eff208cf059de7b763681666879~DubfbpHBi1520915209euoutp02x DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315693; bh=QqhM7SFSEoVaEdMEtC+Yi4ZZhSzv0A99gHzsJFwdofY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OnkQ/8idDhG+y+o5IYFz3KSMryQXcpOpg3OAM1wr+dd3woE+uW3upz4+AuYRz8xbD 4KT34HZKlSXOl4kK0wkz7yZRtZkckc1TihWto4A1fRaQeNwK/c8eN+2iHWnCwvz29k 3qt6Vpmyfxz+Q7XkB076QkHW6bGXHd+swFGZcN2M= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200408031452eucas1p115428ee17d9716a5221a27ebd9e28a47~DubetymeS1603216032eucas1p14 for ; Wed, 8 Apr 2020 03:14:52 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id E7.1A.60698.CA14D8E5; Wed, 8 Apr 2020 04:14:52 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200408031451eucas1p2313bee1d227e5966fb37c5326aa72529~DubeSulhd3001230012eucas1p2y for ; Wed, 8 Apr 2020 03:14:51 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200408031451eusmtrp2c6ee96a986bcd63b38881dbef6bf00ed~DubeSOWTk0734007340eusmtrp2k for ; Wed, 8 Apr 2020 03:14:51 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-34-5e8d41acb49a Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 62.DA.08375.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 20200408031451eusmtip1a9abf79cd1e01e2391ab23517ea678b8~Dubd79I1t2835528355eusmtip1f for ; Wed, 8 Apr 2020 03:14:51 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Wed, 8 Apr 2020 05:13:45 +0200 Message-Id: <20200408031351.4288-8-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+NgFjrNIsWRmVeSWpSXmKPExsWy7djP87prHHvjDB5281u8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGT27L7AVXNSoaDvWytjAeEypi5GTQ0LARGLHwmssXYxcHEIC Kxglrj6dzgzhtDNJvFn/lh3CaWOS+Pq1iQWm5e6kDVCJ5YwS+99vZ4GrmrjpDCNIFZuArcSR mV9ZQWwRARaJld+/g3UzCwhIPL73DCwuLOAt8a/tPlicRUBV4vnZ7UwgNq+Ai8S9hW/ZILbJ S6zecADoJg4OTgFXid1nuUB2SQisYJOYM+09O0SNi8TcOcdZIWxhiVfHt0DFZST+75zPBNGw Dei53z8ZIZz9jBLXe1dAVVlLHP73mw1kA7OApsT6XfoQYUeJWc3rWEHCEgJ8EjfeCkLczycx adt0Zogwr0RHmxBEtZ7E056pjDBr/6x9Ag0sD4n9a69CA+syo0TXnkvMExjlZyEsW8DIuIpR PLW0ODc9tdg4L7Vcrzgxt7g0L10vOT93EyMwik//O/51B+O+P0mHGAU4GJV4eB8k9sQJsSaW FVfmHmKU4GBWEuGV6u2ME+JNSaysSi3Kjy8qzUktPsQozcGiJM5rvOhlrJBAemJJanZqakFq EUyWiYNTqoHxjK3x4n1ryn5yrnye4XN6i/5O9Vkzn7rFfLplMs3WyuPDxYjyfbVPXqQbZWwX 9bHZzXL6mNl6l5zFX89t49Di3CHfWJSpsyrzn81+FU5VW9G6+ULblT8ItE70FWkycHL31ty/ O+ihdZLRx+x2sWNt2hHBFbP3HfYVWC31pe+wt6Lu44cL0/4osRRnJBpqMRcVJwIAAJJnFN4C AAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7qrHXvjDF5e0LN492k7kwOjx68F S1kDGKP0bIryS0tSFTLyi0tslaINLYz0DC0t9IxMLPUMjc1jrYxMlfTtbFJSczLLUov07RL0 Mnp2X2AruKhR0XaslbGB8ZhSFyMnh4SAicTdSRvYuxi5OIQEljJK9L17w9zFyAGUkJH4cEkA okZY4s+1LjaImhYmiTvfTzOBJNgEbCWOzPzKCmKLCLBIrPz+nQXEZhYQkHh87xlYXFjAW+Jf 232wOIuAqsTzs9vBenkFXCTuLXzLBrFAXmL1hgNgezkFXCV2n+UCCQsJ1EscvnuZbQIj3wJG hlWMIqmlxbnpucWGesWJucWleel6yfm5mxiB4bTt2M/NOxgvbQw+xCjAwajEw/sgsSdOiDWx rLgy9xCjBAezkgivVG9nnBBvSmJlVWpRfnxRaU5q8SFGU6CbJjJLiSbnA0M9ryTe0NTQ3MLS 0NzY3NjMQkmct0PgYIyQQHpiSWp2ampBahFMHxMHp1QDo7Tih/pSuyVzIu+XSebzTo/1/7Ym +o+j/ixlxd+iZjO+is9UmX/rmJUJb3H5jRffS9+yTA95sjSH51K0rNCtx9cX5mtGLvFZo+6m PuOy6sHKOMt3tge3L9i4Y1PRTLkQadXDzaJ3Nd1W8yU/EH00h0P+2G4Hxd8eFdoGR4qis39r v2F+IO3XqMRSnJFoqMVcVJwIALgJSC49AgAA X-CMS-MailID: 20200408031451eucas1p2313bee1d227e5966fb37c5326aa72529 X-Msg-Generator: CA X-RootMTR: 20200408031451eucas1p2313bee1d227e5966fb37c5326aa72529 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031451eucas1p2313bee1d227e5966fb37c5326aa72529 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 07/13] app/test: add rte security session get size 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_get_size function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 132 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index daaf30b62..9c5e7d0da 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -268,6 +268,30 @@ mock_session_update(void *device, return mock_session_update_exp.ret; } +/** + * session_get_size mockup + * + * Verified parameters: device. + */ +static struct mock_session_get_size_data { + void *device; + + unsigned int ret; + + int called; + int failed; +} mock_session_get_size_exp = {NULL, 0U, 0, 0}; + +static unsigned int +mock_session_get_size(void *device) +{ + mock_session_get_size_exp.called++; + + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_get_size_exp, device); + + return mock_session_get_size_exp.ret; +} + /** * session_destroy mockup * @@ -309,6 +333,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_get_size = mock_session_get_size, .session_destroy = mock_session_destroy, }; @@ -401,10 +426,12 @@ ut_setup(void) mock_session_create_exp.called = 0; mock_session_update_exp.called = 0; + mock_session_get_size_exp.called = 0; mock_session_destroy_exp.called = 0; mock_session_create_exp.failed = 0; mock_session_update_exp.failed = 0; + mock_session_get_size_exp.failed = 0; mock_session_destroy_exp.failed = 0; return TEST_SUCCESS; @@ -856,6 +883,100 @@ test_session_update_success(void) } +/** + * rte_security_session_get_size tests + */ + +/** + * Test execution of rte_security_session_get_size with NULL instance + */ +static int +test_session_get_size_inv_context(void) +{ + unsigned int ret = rte_security_session_get_size(NULL); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size, + ret, 0, "%u"); + TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_get_size with invalid + * security operations structure (NULL) + */ +static int +test_session_get_size_inv_context_ops(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + ut_params->ctx.ops = NULL; + + unsigned int ret = rte_security_session_get_size(&ut_params->ctx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size, + ret, 0, "%u"); + TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_get_size with empty + * security operations + */ +static int +test_session_get_size_inv_context_ops_fun(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + ut_params->ctx.ops = &empty_ops; + + unsigned int ret = rte_security_session_get_size(&ut_params->ctx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size, + ret, 0, "%u"); + TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_get_size when session_get_size + * security operation fails + */ +static int +test_session_get_size_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + mock_session_get_size_exp.device = NULL; + mock_session_get_size_exp.ret = 0; + + unsigned int ret = rte_security_session_get_size(&ut_params->ctx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size, + ret, 0, "%u"); + TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_get_size in successful execution path + */ +static int +test_session_get_size_success(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + mock_session_get_size_exp.device = NULL; + mock_session_get_size_exp.ret = 1024; + + unsigned int ret = rte_security_session_get_size(&ut_params->ctx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_get_size, + ret, 1024U, "%u"); + TEST_ASSERT_MOCK_CALLS(mock_session_get_size_exp, 1); + + return TEST_SUCCESS; +} + + /** * Declaration of testcases */ @@ -896,6 +1017,17 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_session_update_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_get_size_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_get_size_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_get_size_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_get_size_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_get_size_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Wed Apr 8 03:13:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67944 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 97C78A0597; Wed, 8 Apr 2020 05:16:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A13AD1C0AD; Wed, 8 Apr 2020 05:15:01 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 606901BFC6 for ; Wed, 8 Apr 2020 05:14:53 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031453euoutp01e0cb883a361456844d9d0cd1c5a1a311~DubfjiIIK2124521245euoutp01V for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200408031453euoutp01e0cb883a361456844d9d0cd1c5a1a311~DubfjiIIK2124521245euoutp01V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315693; bh=acA+ii0yOmD1r+6N7MuYyRPvxP2ro9kXIxZa9EtWUq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k3zOi1DfgIP07E/fs/fuLAPX1uMDTdKBqRpM6nvA53T/jz0x37UWRox+agNrVkY9z pKDfGOqwpo53oHPfGFi3uZ3o5WWKmnSUe8n9d9nIGizJkNzgvwOMjuvCaAXmW98iUF KxOQ3QCrO8cYhyRIXSvgbTgEvf+Gh0y5wOLvYD44= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200408031453eucas1p23b63e592bf2f5647d40d8222a1632469~DubfZaa2L3007630076eucas1p2p for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 1A.47.60679.CA14D8E5; Wed, 8 Apr 2020 04:14:52 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200408031452eucas1p2f75a75363e148c54f38b01b9a9a0ea47~DubevlBZ73008430084eucas1p2b for ; Wed, 8 Apr 2020 03:14:52 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200408031452eusmtrp150bf150a2ca1a983c86af1b10f40c737~DubevEZFu1153511535eusmtrp1v for ; Wed, 8 Apr 2020 03:14:52 +0000 (GMT) X-AuditID: cbfec7f4-0cbff7000001ed07-60-5e8d41acc1dd Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id EF.69.07950.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 20200408031451eusmtip158925a75978c374169ea783dd0624177~DubeYNslp2966429664eusmtip1c for ; Wed, 8 Apr 2020 03:14:51 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Wed, 8 Apr 2020 05:13:46 +0200 Message-Id: <20200408031351.4288-9-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+NgFjrBIsWRmVeSWpSXmKPExsWy7djPc7prHHvjDJbutLB492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4Mubs+sRUMMG04tClfywNjId0uxg5OSQETCQ2rr7O3sXIxSEk sIJRouvMWjaQhJBAO5PEt4OlEIk2JomHnQ1sMB1rH01igUgsZ5T43viIDa5qzYmJrCBVbAK2 EkdmfgWzRQRYJFZ+/84CYjMLCEg8vvcMLC4s4COxraOTGcRmEVCVOP3vDlgNr4CLxPI5V5gg tslLrN5wAKiGg4NTwFVi91kukF0SAmvYJO5N/AFV4yJxaslUZghbWOLV8S3sELaMxOnJPSwQ DdsYJa7+/skI4exnlLjeuwKqylri8L/fbCAbmAU0Jdbv0gcxJQQcJf7/K4Uw+SRuvBWEOJ9P YtK26cwQYV6JjjYhiBl6Ek97pjLCbP2z9gkLRImHRO8RR0joXGaUeLbxP+MERvlZCKsWMDKu YhRPLS3OTU8tNspLLdcrTswtLs1L10vOz93ECIzf0/+Of9nBuOtP0iFGAQ5GJR7eB4k9cUKs iWXFlbmHGCU4mJVEeKV6O+OEeFMSK6tSi/Lji0pzUosPMUpzsCiJ8xovehkrJJCeWJKanZpa kFoEk2Xi4JRqYFzGeCqiPd537uKdh25+c+zOrst7cKWrxyHNR6dtyqaWV3ttfm+Z58i8Zq30 otd7dxz8YclYNn+C5KMfs2tKk7oYClmatp5Qmzylt6pNSTf2zak/xXn7u/I/bt2rFyFkK7q+ Mu/kUnvVn0G28hvYz8oGneSS7JFvXhjTaFt8b8mRikXbyhat/K3EUpyRaKjFXFScCACILXto 2wIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7prHHvjDN5O57N492k7kwOjx68F S1kDGKP0bIryS0tSFTLyi0tslaINLYz0DC0t9IxMLPUMjc1jrYxMlfTtbFJSczLLUov07RL0 Mubs+sRUMMG04tClfywNjId0uxg5OSQETCTWPprE0sXIxSEksJRR4uHcmexdjBxACRmJD5cE IGqEJf5c62KDqGlhkjj+/xI7SIJNwFbiyMyvrCC2iACLxMrv31lAbGYBAYnH956BxYUFfCS2 dXQyg9gsAqoSp//dAavhFXCRWD7nChPEAnmJ1RsOMIPs5RRwldh9lgskLCRQL3H47mW2CYx8 CxgZVjGKpJYW56bnFhvpFSfmFpfmpesl5+duYgSG07ZjP7fsYOx6F3yIUYCDUYmH90FiT5wQ a2JZcWXuIUYJDmYlEV6p3s44Id6UxMqq1KL8+KLSnNTiQ4ymQDdNZJYSTc4HhnpeSbyhqaG5 haWhubG5sZmFkjhvh8DBGCGB9MSS1OzU1ILUIpg+Jg5OqQbGshfBmsZXUs9JKWwLfHRLKPH8 CXGL8w4pWpW21lGXGecIJdqnzVER7Z50kNspIsV7e71FH3devGSBRvUM7z2LTP4//nTT8MCT M8EpxnMkdKI0+udMifedzun//zvXqmeqnM+YDl9ee8LK40+69ukN0cEr9Y+e+Tf33JquTL5j 5p03Hb69996ixFKckWioxVxUnAgAHWRU/T0CAAA= X-CMS-MailID: 20200408031452eucas1p2f75a75363e148c54f38b01b9a9a0ea47 X-Msg-Generator: CA X-RootMTR: 20200408031452eucas1p2f75a75363e148c54f38b01b9a9a0ea47 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031452eucas1p2f75a75363e148c54f38b01b9a9a0ea47 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 08/13] app/test: add rte security session stats get 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_stats_get function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 173 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index 9c5e7d0da..c495449b0 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -292,6 +292,36 @@ mock_session_get_size(void *device) return mock_session_get_size_exp.ret; } +/** + * session_stats_get mockup + * + * Verified parameters: device, sess, stats. + */ +static struct mock_session_stats_get_data { + void *device; + struct rte_security_session *sess; + struct rte_security_stats *stats; + + int ret; + + int called; + int failed; +} mock_session_stats_get_exp = {NULL, NULL, NULL, 0, 0, 0}; + +static int +mock_session_stats_get(void *device, + struct rte_security_session *sess, + struct rte_security_stats *stats) +{ + mock_session_stats_get_exp.called++; + + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, device); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, sess); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_stats_get_exp, stats); + + return mock_session_stats_get_exp.ret; +} + /** * session_destroy mockup * @@ -334,6 +364,7 @@ struct rte_security_ops mock_ops = { .session_create = mock_session_create, .session_update = mock_session_update, .session_get_size = mock_session_get_size, + .session_stats_get = mock_session_stats_get, .session_destroy = mock_session_destroy, }; @@ -427,11 +458,13 @@ ut_setup(void) mock_session_create_exp.called = 0; mock_session_update_exp.called = 0; mock_session_get_size_exp.called = 0; + mock_session_stats_get_exp.called = 0; mock_session_destroy_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; return TEST_SUCCESS; @@ -977,6 +1010,133 @@ test_session_get_size_success(void) } +/** + * rte_security_session_stats_get tests + */ + +/** + * Test execution of rte_security_session_stats_get with NULL instance + */ +static int +test_session_stats_get_inv_context(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_stats stats; + + int ret = rte_security_session_stats_get(NULL, ut_params->sess, &stats); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_stats_get with invalid + * security operations structure (NULL) + */ +static int +test_session_stats_get_inv_context_ops(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_stats stats; + ut_params->ctx.ops = NULL; + + int ret = rte_security_session_stats_get(&ut_params->ctx, + ut_params->sess, &stats); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_stats_get with empty + * security operations + */ +static int +test_session_stats_get_inv_context_ops_fun(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_stats stats; + ut_params->ctx.ops = &empty_ops; + + int ret = rte_security_session_stats_get(&ut_params->ctx, + ut_params->sess, &stats); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get, + ret, -ENOTSUP, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_stats_get with NULL stats parameter + */ +static int +test_session_stats_get_inv_stats(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + int ret = rte_security_session_stats_get(&ut_params->ctx, + ut_params->sess, NULL); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_stats_get when session_stats_get + * security operation fails + */ +static int +test_session_stats_get_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_stats stats; + + mock_session_stats_get_exp.device = NULL; + mock_session_stats_get_exp.sess = ut_params->sess; + mock_session_stats_get_exp.stats = &stats; + mock_session_stats_get_exp.ret = -1; + + int ret = rte_security_session_stats_get(&ut_params->ctx, + ut_params->sess, &stats); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get, + ret, -1, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_stats_get in successful execution + * path + */ +static int +test_session_stats_get_success(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_stats stats; + + mock_session_stats_get_exp.device = NULL; + mock_session_stats_get_exp.sess = ut_params->sess; + mock_session_stats_get_exp.stats = &stats; + mock_session_stats_get_exp.ret = 0; + + int ret = rte_security_session_stats_get(&ut_params->ctx, + ut_params->sess, &stats); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_stats_get, + ret, 0, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_stats_get_exp, 1); + + return TEST_SUCCESS; +} + + /** * Declaration of testcases */ @@ -1028,6 +1188,19 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_session_get_size_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_stats_get_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_stats_get_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_stats_get_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_stats_get_inv_stats), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_stats_get_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_stats_get_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Wed Apr 8 03:13:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67945 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org 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/ZwGxmQUEJB7fewYWFxbwkvg0sxHMZhFQlVh/9hcjiM0r4Crx9OA0 Foht8hKrNxwA2sbBwQkU332WC2SXhMAKNonfW75C1bhITN/TyghhC0u8Or6FHcKWkfi/cz4T RMM2Romrv38yQjj7gc7uXQFVZS1x+N9vNpANzAKaEut36UOEHSXOv+5lBwlLCPBJ3HgrCHE/ n8SkbdOZIcK8Eh1tQhDVehJPe6Yywqz9s/YJ1GkeEkeX/GWBBOJlRomj3+MnMMrPQti1gJFx FaN4amlxbnpqsWFearlecWJucWleul5yfu4mRmAEn/53/NMOxq+Xkg4xCnAwKvHwPkjsiRNi TSwrrsw9xCjBwawkwivV2xknxJuSWFmVWpQfX1Sak1p8iFGag0VJnNd40ctYIYH0xJLU7NTU gtQimCwTB6dUA+PCoxyhKozLZ1lbtDSaf2r0DMpMS1e6c/WxoqGe277cyJgTcTvOcvUEMiYm lvnqZRldXBtgIzqXo7Kuw3DLp3kxWR5Ri5nLHp36Jmneb7OKU8KXr/RgQN5kHSfb81sbYud/ afOr2Z4kcmM93w7DeQ+T95WE3DTw3HcuNfDIj2N9X6v4V746oMRSnJFoqMVcVJwIACXhWMXc AgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7prHHvjDGb0alm8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GZ23NjIVNOtUzFz1jamB8YdqFyMnh4SAicTfvkbmLkYuDiGBpYwSHa0P2LsYOYASMhIfLglA 1AhL/LnWxQZR08IksfJLOzNIgk3AVuLIzK+sILaIAIvEyu/fWUBsZgEBicf3noHFhQW8JD7N bASzWQRUJdaf/cUIYvMKuEo8PTiNBWKBvMTqDQeYQfZyAsV3n+UCCQsJ1EscvnuZbQIj3wJG hlWMIqmlxbnpucWGesWJucWleel6yfm5mxiB4bTt2M/NOxgvbQw+xCjAwajEw/sgsSdOiDWx rLgy9xCjBAezkgivVG9nnBBvSmJlVWpRfnxRaU5q8SFGU6CbJjJLiSbnA0M9ryTe0NTQ3MLS 0NzY3NjMQkmct0PgYIyQQHpiSWp2ampBahFMHxMHp1QDo/0c17VVd8x8FzQ/CH9n9PJb27O5 cgdnxV8WP7gnIUig7PanJgubOYpt8uZ6nDrJInPM1i2xMjpzXj/EXdUzZs6sJuu/+145vdjj Iazf02H9MWGK74I9Sa1/pIJuzn8c8Ez/7hq9yuB3bMdeirKoS9ekcPJyfNj05uvKSwqLXoVN ef36/7UYdSWW4oxEQy3mouJEAI8kMrU9AgAA X-CMS-MailID: 20200408031452eucas1p1b4de173fadca62824b472b8a3dd69e32 X-Msg-Generator: CA 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 */ } }; From patchwork Wed Apr 8 03:13:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67946 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org 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/vPQOLCwt4Syx4948JxGYRUJWYs3sNO4jNK+AqsbLrIiPE MnmJ1RsOAM3k4OAEiu8+ywWyS0JgDZvE/I73TBA1LhIH+75C1QtLvDq+hR3ClpE4PRniHQmB bYwSV3//ZIRw9jNKXO9dAVVlLXH43282kA3MApoS63fpQ4QdJaZNPsAEEpYQ4JO48VYQ4n4+ iUnbpjNDhHklOtqEIKr1JJ72TGWEWftn7RMWCNtD4vG+OdAQvcwo8WPTLuYJjPKzEJYtYGRc xSieWlqcm55abJyXWq5XnJhbXJqXrpecn7uJERjDp/8d/7qDcd+fpEOMAhyMSjy8DxJ74oRY E8uKK3MPMUpwMCuJ8Er1dsYJ8aYkVlalFuXHF5XmpBYfYpTmYFES5zVe9DJWSCA9sSQ1OzW1 ILUIJsvEwSnVwNj9RNiAzWNtgZWs+nebHsnDJrH76zxtN16w4nq09dxEF87Pm721OGqncApf V5vj0jJbaQbvH9O7z1Xbnt/a73S8nOH7w0+PrsXfOpm9Wk/wRJCTsvPqjk8Nu0+FG045KM+i s+b2N5dblqc52sLTeg9K3jFR6WG9Yv+b48WhLQb7JlxcEK736aYSS3FGoqEWc1FxIgCBwYmi 3QIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7prHXvjDB49YbN492k7kwOjx68F S1kDGKP0bIryS0tSFTLyi0tslaINLYz0DC0t9IxMLPUMjc1jrYxMlfTtbFJSczLLUov07RL0 Mmb8Xstc8Nyi4ubrqewNjOsMuhg5OSQETCS6lu5k6WLk4hASWMoo8WDdCtYuRg6ghIzEh0sC EDXCEn+udbFB1LQwSXQ/uMoGkmATsJU4MvMrK4gtIsAisfL7dxYQm1lAQOLxvWdgcWEBb4kF 7/4xgdgsAqoSc3avYQexeQVcJVZ2XWSEWCAvsXrDAWaQvZxA8d1nuUDCQgL1EofvXmabwMi3 gJFhFaNIamlxbnpusZFecWJucWleul5yfu4mRmA4bTv2c8sOxq53wYcYBTgYlXh4HyT2xAmx 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 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 */ } }; From patchwork Wed Apr 8 03:13:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67947 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CDE53A0597; Wed, 8 Apr 2020 05:16:34 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 160171C0C2; Wed, 8 Apr 2020 05:15:06 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 7B4691BFEF for ; Wed, 8 Apr 2020 05:14:54 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031454euoutp02461fba4d8a6a38a53e20a9e7013ec59c~DubgmGGs_2216822168euoutp02H for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200408031454euoutp02461fba4d8a6a38a53e20a9e7013ec59c~DubgmGGs_2216822168euoutp02H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315694; bh=8VegCETjPiT4EPKmJx9B77YVijkzsbz01Ic1CnoLdUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M+eoWrMVA2Yk7d1/mpCgYGtQCGOqslhP+N/MGsUEc1F+hZh+X+81VIclSKFeC4ZiI vWrHw5vt0vSQitmZtJGRG4+Wx8EWH6VeePiTI+OFa0fXUdFNR2X5uN/YnwJz6dbRe7 e3PLtP+8zcPQMyxyCuYvXHrK38wtV599Zpy6d6Dc= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200408031454eucas1p25b550bef399e438bee71be4aef454d99~Dubgg7stK3007630076eucas1p2r for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 3A.47.60679.EA14D8E5; Wed, 8 Apr 2020 04:14:54 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200408031453eucas1p1b26ad6b1f924b817e83fc2d2d61a0b0b~Dubf9_6wl2413824138eucas1p1X for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200408031453eusmtrp24602df414e9119f843ccb3b218dcbda1~Dubf9hL3M2369123691eusmtrp2C for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-61-5e8d41ae6c64 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id A2.DA.08375.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 20200408031453eusmtip1bba9834aca0dff7b7e1224ec30ce467c~Dubfno23-2835528355eusmtip1h for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Wed, 8 Apr 2020 05:13:49 +0200 Message-Id: <20200408031351.4288-12-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+NgFjrFIsWRmVeSWpSXmKPExsWy7djPc7rrHHvjDKafY7d492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4Mlbvb2Mq2GhdMXnbc+YGxmuGXYycHBICJhKnn31l7GLk4hAS WMEoMfP+RRYIp51JYt/l2+wgVUICbUwS7Rs8YToOT9nIClG0nFFiy4ReZggHqOj5nV9sIFVs ArYSR2Z+ZQWxRQRYJFZ+/84CYjMLCEg8vvcMLC4s4C5xY+NFMJtFQFVix+susBpeAVeJ61/e MENsk5dYveEAkM3BwQkU332WC2SXhMAKNokFF+eyQdS4SGz7cR+qXlji1fEt7BC2jMT/nfOZ IBq2MUpc/f2TEcLZzyhxvXcFVJW1xOF/v9lANjALaEqs36UPEXaU+HtmEVhYQoBP4sZbQYj7 +SQmbZvODBHmlehoE4Ko1pN42jOVEWbtn7VPWCBsD4l993dBQ/Qyo8SxmdvYJjDKz0JYtoCR cRWjeGppcW56arFRXmq5XnFibnFpXrpecn7uJkZgDJ/+d/zLDsZdf5IOMQpwMCrx8D5I7IkT Yk0sK67MPcQowcGsJMIr1dsZJ8SbklhZlVqUH19UmpNafIhRmoNFSZzXeNHLWCGB9MSS1OzU 1ILUIpgsEwenVAPjcn7D/WeWzNnKnJMX6HfrzJSoVb9rtF9I39755s8h7TX5+8z5Wx7xLn0U uLKmIeLCw7MvL+mydTi41pxie7xjF+tSxsPLtSJvL2n4rPrh26LCPWHGdo7GiW2JBb9ZTrH8 M80K2N3J6DlxYu/Jp7Ev+k0F5Xn7utoTOOrf+bo3F0xib3RjVfuqxFKckWioxVxUnAgALmtf H90CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7prHXvjDPadVbJ492k7kwOjx68F S1kDGKP0bIryS0tSFTLyi0tslaINLYz0DC0t9IxMLPUMjc1jrYxMlfTtbFJSczLLUov07RL0 Mlbvb2Mq2GhdMXnbc+YGxmuGXYycHBICJhKHp2xk7WLk4hASWMoocX3Va+YuRg6ghIzEh0sC EDXCEn+udbFB1LQwSdy7uZEJJMEmYCtxZOZXVhBbRIBFYuX37ywgNrOAgMTje8/A4sIC7hI3 Nl4Es1kEVCV2vO4Cq+EVcJW4/uUNM8QCeYnVGw6A7eUEiu8+ywUSFhKolzh89zLbBEa+BYwM qxhFUkuLc9Nziw31ihNzi0vz0vWS83M3MQLDaduxn5t3MF7aGHyIUYCDUYmH90FiT5wQa2JZ cWXuIUYJDmYlEV6p3s44Id6UxMqq1KL8+KLSnNTiQ4ymQDdNZJYSTc4HhnpeSbyhqaG5haWh ubG5sZmFkjhvh8DBGCGB9MSS1OzU1ILUIpg+Jg5OqQZGzoYj9WclypRNVvmZWHLrGjH/Xxy/ fu0vvplaDw6oCrsXdUys//487ccOixPuE7qFOQO8zqsFNGz7FX5vbjvn6ZuVJ8/J3Zr/Oncb 6/KiRZqd2U/M0ic8nL9O/b1B4Mzvp0+Kn07aI5J38+8cXhmrix+bdtU+1q1I2rFoR0G4ZCWj m5+TdbWHEktxRqKhFnNRcSIA4aT0Sz0CAAA= X-CMS-MailID: 20200408031453eucas1p1b26ad6b1f924b817e83fc2d2d61a0b0b X-Msg-Generator: CA X-RootMTR: 20200408031453eucas1p1b26ad6b1f924b817e83fc2d2d61a0b0b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031453eucas1p1b26ad6b1f924b817e83fc2d2d61a0b0b References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 11/13] app/test: add rte security get userdata 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_get_userdata function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 191 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index a1f0e7879..230b53891 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -76,6 +76,19 @@ #define MOCK_TEST_ASSERT_EQUAL(fail_counter, a, b, msg, ...) \ MOCK_TEST_ASSERT(fail_counter, (a) == (b), msg, ##__VA_ARGS__) +/** + * Verify not null condition inside mocked up function. + * Mockup function cannot return a test error, so the failure + * of assertion increases counter and print logs. + * The counter can be verified later to check if test case should fail. + * + * @param fail_counter fail counter + * @param val value expected not to be NULL + * @param msg printf style formatting string for custom message + */ +#define MOCK_TEST_ASSERT_NOT_NULL(fail_counter, val, msg, ...) \ + MOCK_TEST_ASSERT(fail_counter, (val) != NULL, msg, ##__VA_ARGS__) + /** * Verify if parameter of the mocked up function matches expected value. @@ -101,6 +114,15 @@ #define MOCK_TEST_ASSERT_POINTER_PARAMETER(data, parameter) \ MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%p") +/** + * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for uint64_t type parameters. + * + * @param data structure with expected values + * @param parameter name of the parameter (both field and parameter name) + */ +#define MOCK_TEST_ASSERT_U64_PARAMETER(data, parameter) \ + MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%" PRIu64) + /** * Verify number of calls of the mocked up function * and check if there were any fails during execution. @@ -381,6 +403,43 @@ mock_set_pkt_metadata(void *device, return mock_set_pkt_metadata_exp.ret; } +/** + * get_userdata mockup + * + * Verified parameters: device, md. + * The userdata parameter works as an output parameter, so a passed address + * is verified not to be NULL and filled with userdata stored in structure. + */ +static struct mock_get_userdata_data { + void *device; + uint64_t md; + void *userdata; + + int ret; + + int called; + int failed; +} mock_get_userdata_exp = {NULL, 0UL, NULL, 0, 0, 0}; + +static int +mock_get_userdata(void *device, + uint64_t md, + void **userdata) +{ + mock_get_userdata_exp.called++; + + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_get_userdata_exp, device); + MOCK_TEST_ASSERT_U64_PARAMETER(mock_get_userdata_exp, md); + + MOCK_TEST_ASSERT_NOT_NULL(mock_get_userdata_exp.failed, + userdata, + "Expecting parameter userdata not to be NULL but it's %p", + userdata); + *userdata = mock_get_userdata_exp.userdata; + + return mock_get_userdata_exp.ret; +} + /** * empty_ops * @@ -400,6 +459,7 @@ struct rte_security_ops mock_ops = { .session_stats_get = mock_session_stats_get, .session_destroy = mock_session_destroy, .set_pkt_metadata = mock_set_pkt_metadata, + .get_userdata = mock_get_userdata, }; @@ -495,6 +555,7 @@ ut_setup(void) mock_session_stats_get_exp.called = 0; mock_session_destroy_exp.called = 0; mock_set_pkt_metadata_exp.called = 0; + mock_get_userdata_exp.called = 0; mock_session_create_exp.failed = 0; mock_session_update_exp.failed = 0; @@ -502,6 +563,7 @@ ut_setup(void) mock_session_stats_get_exp.failed = 0; mock_session_destroy_exp.failed = 0; mock_set_pkt_metadata_exp.failed = 0; + mock_get_userdata_exp.failed = 0; return TEST_SUCCESS; } @@ -1478,6 +1540,124 @@ test_set_pkt_metadata_success(void) } +/** + * rte_security_get_userdata tests + */ + +/** + * Test execution of rte_security_get_userdata with NULL instance + */ +static int +test_get_userdata_inv_context(void) +{ +#ifdef RTE_LIBRTE_SECURITY_DEBUG + uint64_t md = 0xDEADBEEF; + + void *ret = rte_security_get_userdata(NULL, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_get_userdata with invalid + * security operations structure (NULL) + */ +static int +test_get_userdata_inv_context_ops(void) +{ +#ifdef RTE_LIBRTE_SECURITY_DEBUG + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + ut_params->ctx.ops = NULL; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_get_userdata with empty + * security operations + */ +static int +test_get_userdata_inv_context_ops_fun(void) +{ +#ifdef RTE_LIBRTE_SECURITY_DEBUG + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + ut_params->ctx.ops = &empty_ops; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_get_userdata when get_userdata + * security operation fails + */ +static int +test_get_userdata_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + void *userdata = (void *)0x7E577E57; + + mock_get_userdata_exp.device = NULL; + mock_get_userdata_exp.md = md; + mock_get_userdata_exp.userdata = userdata; + mock_get_userdata_exp.ret = -1; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_get_userdata in successful execution path + */ +static int +test_get_userdata_success(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + void *userdata = (void *)0x7E577E57; + + mock_get_userdata_exp.device = NULL; + mock_get_userdata_exp.md = md; + mock_get_userdata_exp.userdata = userdata; + mock_get_userdata_exp.ret = 0; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, userdata, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1); + + return TEST_SUCCESS; +} + + /** * Declaration of testcases */ @@ -1568,6 +1748,17 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_set_pkt_metadata_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Wed Apr 8 03:13:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67948 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1328CA0597; Wed, 8 Apr 2020 05:16:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D03C41C0C7; Wed, 8 Apr 2020 05:15:07 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id D82931BF60 for ; Wed, 8 Apr 2020 05:14:54 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031454euoutp025070be77993878880a506a0c882b59d9~Dubg8k5SN1520915209euoutp02y for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200408031454euoutp025070be77993878880a506a0c882b59d9~Dubg8k5SN1520915209euoutp02y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315694; bh=xVHLCwwZpPMlphGkAsIF+b88Vi+kHzKTZBCeQBv7bUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aS74Zm/YQuJopYelMzyuLvliVId4Ynv8KPWt2P0xm2zY9eZisvfhI7xP1x8D7ky6G GiF3C49ox4X+HpOrQDjxWYR961psDFNt0dT1apOMoSzCQ6nsLTx0W5YniHpzNBbGXI C8auUY179C1bXF18NlcyrXa7iR6EGz5hqb4d4oLs= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200408031454eucas1p1fdc0c643498b2849a453fa70f4ade098~DubgoYZfW2414224142eucas1p1d for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 3F.1B.61286.EA14D8E5; Wed, 8 Apr 2020 04:14:54 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200408031454eucas1p112c6eded420bdcfdb09fad83bf485afb~DubgU9FeL0246502465eucas1p1Q for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200408031454eusmtrp14ee134718918a8bb28b19f25b9cc1bb4~DubgUcYdy1153511535eusmtrp1x for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-6f-5e8d41aeb047 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 20.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 20200408031453eusmtip13f923838f200c8f93abd7178774e9211~DubgCJ_pK2966429664eusmtip1e for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Wed, 8 Apr 2020 05:13:50 +0200 Message-Id: <20200408031351.4288-13-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+NgFjrFIsWRmVeSWpSXmKPExsWy7djP87rrHHvjDPp/CVu8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGY/6WpgKlmtX3P/7h7WB8ZtKFyMnh4SAicTuNbeYuxi5OIQE VjBKPH36ghXCaWeSaDgwkQXCaWOSmPq4kQ2mZfmLp0wQieWMEgsmvGIBSYBVTV7oCmKzCdhK HJn5lRXEFhFgkVj5/TtYDbOAgMTje8/A4sIC3hJfv7Wyg9gsAqoSF1asAVvAK+AqsWPSBCaI ZfISqzccALqPg4MTKL77LBfIXgmBNWwS2xY/YIWocZGY3fALql5Y4tXxLewQtozE6ck9LBAN 2xglrv7+yQjh7GeUuN67AqrKWuLwv99sIBuYBTQl1u/Shwg7Skx9+Y8VJCwhwCdx460gxP18 EpO2TWeGCPNKdLQJQVTrSTztmcoIs/bP2icsELaHxIntu6CBeJlR4v+BFcwTGOVnISxbwMi4 ilE8tbQ4Nz212DAvtVyvODG3uDQvXS85P3cTIzCGT/87/mkH49dLSYcYBTgYlXh4HyT2xAmx JpYVV+YeYpTgYFYS4ZXq7YwT4k1JrKxKLcqPLyrNSS0+xCjNwaIkzmu86GWskEB6Yklqdmpq QWoRTJaJg1OqgbHaL1337xFmn0lmIWv0O+I/SyzQiYtccJnBsq+DoWiFi9mtJUwzc2NtRYSD jKx2Kr9Uk7gotz3+W/2mz1ZaRjvEYu+IHD+3OiUw+dCcVyfEcx/bFF/t2119bqPp3E5tyV7/ 279OPtBK0KyLlxb+xPqyM3Lr/4Ynqo+MqlxVz2m8qtcXOld6R4mlOCPRUIu5qDgRABL7417d AgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7prHXvjDKa12Fq8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GY/6WpgKlmtX3P/7h7WB8ZtKFyMnh4SAicTyF0+Zuhi5OIQEljJKbPhwg62LkQMoISPx4ZIA RI2wxJ9rXWwQNS1MEkePNbGDJNgEbCWOzPzKCmKLCLBIrPz+nQXEZhYQkHh87xlYXFjAW+Lr t1awehYBVYkLK9awgdi8Aq4SOyZNYIJYIC+xesMBZpC9nEDx3We5QMJCAvUSh+9eZpvAyLeA kWEVo0hqaXFuem6xkV5xYm5xaV66XnJ+7iZGYDhtO/Zzyw7GrnfBhxgFOBiVeHgfJPbECbEm lhVX5h5ilOBgVhLhlertjBPiTUmsrEotyo8vKs1JLT7EaAp000RmKdHkfGCo55XEG5oamltY GpobmxubWSiJ83YIHIwREkhPLEnNTk0tSC2C6WPi4JRqYGzo75oa++VheNc74eWWTyfHXglz ym1fsXmZ1W7emzl/7iyLSVpym0/2hLrscbGDG1dsNDl/hOHw157L4jUFH1b78++9cpa7tM91 3pta7QObbj9K4+wPcylbWrrp05qp5TlLq/z1WuXXT6k4HqxUcbFG5nXo/TtMSx893p+gbpfx QL8xpzHmd5QSS3FGoqEWc1FxIgB2uFnaPQIAAA== X-CMS-MailID: 20200408031454eucas1p112c6eded420bdcfdb09fad83bf485afb X-Msg-Generator: CA X-RootMTR: 20200408031454eucas1p112c6eded420bdcfdb09fad83bf485afb X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031454eucas1p112c6eded420bdcfdb09fad83bf485afb References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 12/13] app/test: add rte security capabilities get 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_capabilities_get function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 138 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index 230b53891..9da81fa1d 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -440,6 +440,30 @@ mock_get_userdata(void *device, return mock_get_userdata_exp.ret; } +/** + * capabilities_get mockup + * + * Verified parameters: device. + */ +static struct mock_capabilities_get_data { + void *device; + + struct rte_security_capability *ret; + + int called; + int failed; +} mock_capabilities_get_exp = {NULL, NULL, 0, 0}; + +static const struct rte_security_capability * +mock_capabilities_get(void *device) +{ + mock_capabilities_get_exp.called++; + + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_capabilities_get_exp, device); + + return mock_capabilities_get_exp.ret; +} + /** * empty_ops * @@ -460,6 +484,7 @@ struct rte_security_ops mock_ops = { .session_destroy = mock_session_destroy, .set_pkt_metadata = mock_set_pkt_metadata, .get_userdata = mock_get_userdata, + .capabilities_get = mock_capabilities_get, }; @@ -556,6 +581,7 @@ ut_setup(void) mock_session_destroy_exp.called = 0; mock_set_pkt_metadata_exp.called = 0; mock_get_userdata_exp.called = 0; + mock_capabilities_get_exp.called = 0; mock_session_create_exp.failed = 0; mock_session_update_exp.failed = 0; @@ -564,6 +590,7 @@ ut_setup(void) mock_session_destroy_exp.failed = 0; mock_set_pkt_metadata_exp.failed = 0; mock_get_userdata_exp.failed = 0; + mock_capabilities_get_exp.failed = 0; return TEST_SUCCESS; } @@ -1658,6 +1685,106 @@ test_get_userdata_success(void) } +/** + * rte_security_capabilities_get tests + */ + +/** + * Test execution of rte_security_capabilities_get with NULL instance + */ +static int +test_capabilities_get_inv_context(void) +{ + const struct rte_security_capability *ret; + ret = rte_security_capabilities_get(NULL); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capabilities_get with invalid + * security operations structure (NULL) + */ +static int +test_capabilities_get_inv_context_ops(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + ut_params->ctx.ops = NULL; + + const struct rte_security_capability *ret; + ret = rte_security_capabilities_get(&ut_params->ctx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capabilities_get with empty + * security operations + */ +static int +test_capabilities_get_inv_context_ops_fun(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + ut_params->ctx.ops = &empty_ops; + + const struct rte_security_capability *ret; + ret = rte_security_capabilities_get(&ut_params->ctx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capabilities_get when capabilities_get + * security operation fails + */ +static int +test_capabilities_get_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = NULL; + + const struct rte_security_capability *ret; + ret = rte_security_capabilities_get(&ut_params->ctx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capabilities_get in successful execution path + */ +static int +test_capabilities_get_success(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability capabilities; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = &capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capabilities_get(&ut_params->ctx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capabilities_get, + ret, &capabilities, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + + /** * Declaration of testcases */ @@ -1759,6 +1886,17 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_get_userdata_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capabilities_get_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capabilities_get_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capabilities_get_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capabilities_get_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capabilities_get_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Wed Apr 8 03:13:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 67949 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DD094A0597; Wed, 8 Apr 2020 05:16:58 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9865E1C0D9; Wed, 8 Apr 2020 05:15:09 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id D31AF1C026 for ; Wed, 8 Apr 2020 05:14:56 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031456euoutp0113de26ea35889258c621565b49770b7b~DubixVoWz2124521245euoutp01W for ; Wed, 8 Apr 2020 03:14:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200408031456euoutp0113de26ea35889258c621565b49770b7b~DubixVoWz2124521245euoutp01W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315696; bh=DcvIeR6QZN9wf1EeEUt09vUdUeGmniee/KVSPZzFulc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eOx3kixiODBR9zfHDxLIIHk681pH2ItXxcr1fSCmHV+OlxT2cQmGfOaFIgaiDY1zM hkbZ6UvavSB/rKl+MwQZqBsCe43DEOMEPwoS7KWS68JgjBOHUIYnUayEk5caXdf7rw +EtDLcIxBs2QlemQ7M7wD9PQJr/NPLjvZyPb0fjA= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200408031455eucas1p1ebe02820c2085919d0b3bad4ba99ab7c~Dubh92rqO1426114261eucas1p1q for ; Wed, 8 Apr 2020 03:14:55 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 28.1A.60698.FA14D8E5; Wed, 8 Apr 2020 04:14:55 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200408031454eucas1p2e09e0ab0a1ffa5c657bcf35d89c40a55~Dubg5qB772966729667eucas1p2C for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200408031454eusmtrp2db22b48a010d2628efae53a6041cee76~Dubg5IbeZ2369123691eusmtrp2D for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) X-AuditID: cbfec7f5-a0fff7000001ed1a-39-5e8d41af10cd Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id C2.DA.08375.EA14D8E5; Wed, 8 Apr 2020 04:14:54 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200408031454eusmtip130d412eaa01f25f8013bb105081e5ae5~Dubgc05rK2835528355eusmtip1i for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Wed, 8 Apr 2020 05:13:51 +0200 Message-Id: <20200408031351.4288-14-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+NgFjrDIsWRmVeSWpSXmKPExsWy7djPc7rrHXvjDGbdUrZ492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4MuZ/f8tasKKVseL5j0PsDYz/C7oYOTkkBEwkHl96ztjFyMUh JLCCUWL3+r3MEE47k8TKiY0sEE4bk8SHJwuYYVrmb7zCDpFYziix4d5tRriqZ38vMYFUsQnY ShyZ+ZUVxBYRYJFY+f07C4jNLCAg8fjeM7C4sICnxPYra9hBbBYBVYnPdx6D9fIKuEpMePGf FWKbvMTqDQeANnNwcALFd5/lAtklIbCCTeLQrs+MEDUuEi9P9zBB2MISr45vYYewZST+75zP BNGwjVHi6u+fjBDOfkaJ670roKqsJQ7/+80GsoFZQFNi/S59iLCjxNT3b8EWSwjwSdx4Kwhx P5/EpG3TocK8Eh1tQhDVehJPe6Yywqz9s/YJC4TtIXGqdzYrJHwuM0p8enCbeQKj/CyEZQsY GVcxiqeWFuempxYb56WW6xUn5haX5qXrJefnbmIExvHpf8e/7mDc9yfpEKMAB6MSD++DxJ44 IdbEsuLK3EOMEhzMSiK8Ur2dcUK8KYmVValF+fFFpTmpxYcYpTlYlMR5jRe9jBUSSE8sSc1O TS1ILYLJMnFwSjUwKgkoSkUezs04oPul1qdmMtPGF90VeoVme6+JHPBPnmH6uyiQM3HSyjvF GfmhB6T7tnydrfdo7mE2wZu6rbX8nsYvrl6SFSid93pulc9Fw/SMCEnvh7Vm9xYalcQuPp8T uuH01XuZp/89sF2+w07KXuKJ3Ze3l/NSuqZvE4zZ+Wpq30rz5KaFSizFGYmGWsxFxYkANRZj 9d8CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7rrHHvjDG73q1i8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GfO/v2UtWNHKWPH8xyH2Bsb/BV2MnBwSAiYS8zdeYQexhQSWMkrM7QSyOYDiMhIfLglAlAhL /LnWxdbFyAVU0sIkceXKG1aQBJuArcSRmV/BbBEBFomV37+zgNjMAgISj+89A4sLC3hKbL+y Bmw+i4CqxOc7j5lAbF4BV4kJL/6zQiyQl1i94QAzyF5OoPjus1wQ59RLHL57mW0CI98CRoZV jCKppcW56bnFhnrFibnFpXnpesn5uZsYgeG07djPzTsYL20MPsQowMGoxMP7ILEnTog1say4 MvcQowQHs5IIr1RvZ5wQb0piZVVqUX58UWlOavEhRlOgmyYyS4km5wNDPa8k3tDU0NzC0tDc 2NzYzEJJnLdD4GCMkEB6YklqdmpqQWoRTB8TB6dUAyObQJbtvGU24dN0pdZ+fjIpd/LtGznc E04Gd3jGulWECYgob7pj1FMe1u/t63nkVPwJoSOyey9MOZO8/9SuzLm+PvckrrPdSExSa7Wo Tlpp13f41r+mmfOjMs/lhGwJfST3OY/9EGuU+47/9aoTDkfFy7+s3yzxYdMVk/9vyn2O8FlH BYrv6FFiKc5INNRiLipOBABY4d2GPQIAAA== X-CMS-MailID: 20200408031454eucas1p2e09e0ab0a1ffa5c657bcf35d89c40a55 X-Msg-Generator: CA X-RootMTR: 20200408031454eucas1p2e09e0ab0a1ffa5c657bcf35d89c40a55 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031454eucas1p2e09e0ab0a1ffa5c657bcf35d89c40a55 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 13/13] app/test: add rte security capability get 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_capability_get function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 522 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 522 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index 9da81fa1d..d5b76a127 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -1785,6 +1785,497 @@ test_capabilities_get_success(void) } +/** + * rte_security_capability_get tests + */ + +/** + * Test execution of rte_security_capability_get with NULL instance + */ +static int +test_capability_get_inv_context(void) +{ + struct rte_security_capability_idx idx; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(NULL, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get with invalid + * security operations structure (NULL) + */ +static int +test_capability_get_inv_context_ops(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx; + ut_params->ctx.ops = NULL; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get with empty + * security operations + */ +static int +test_capability_get_inv_context_ops_fun(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx; + ut_params->ctx.ops = &empty_ops; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get with NULL idx parameter + */ +static int +test_capability_get_inv_idx(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, NULL); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities_get + * security operation fails + */ +static int +test_capability_get_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = NULL; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * is empty (contains only RTE_SECURITY_ACTION_TYPE_NONE ending entry) + */ +static int +test_capability_get_empty_table(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching action + */ +static int +test_capability_get_no_matching_action(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching protocol + */ +static int +test_capability_get_no_matching_protocol(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_MACSEC, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_PDCP, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when macsec protocol + * is searched and capabilities table contain proper entry. + * However macsec records search is not supported in rte_security. + */ +static int +test_capability_get_no_support_for_macsec(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_MACSEC, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_MACSEC, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching ipsec proto field + */ +static int +test_capability_get_ipsec_mismatch_proto(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_AH, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching ipsec mode field + */ +static int +test_capability_get_ipsec_mismatch_mode(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching ipsec direction field + */ +static int +test_capability_get_ipsec_mismatch_dir(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, + .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, + .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * contains matching ipsec entry + */ +static int +test_capability_get_ipsec_match(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, + .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_IPSEC, + .ipsec = { + .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, + .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, + .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, &capabilities[1], "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * does not contain entry with matching pdcp domain field + */ +static int +test_capability_get_pdcp_mismatch_domain(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_PDCP, + .pdcp = { + .domain = RTE_SECURITY_PDCP_MODE_CONTROL, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_PDCP, + .pdcp = { + .domain = RTE_SECURITY_PDCP_MODE_DATA, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_capability_get when capabilities table + * contains matching pdcp entry + */ +static int +test_capability_get_pdcp_match(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct rte_security_capability_idx idx = { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_PDCP, + .pdcp = { + .domain = RTE_SECURITY_PDCP_MODE_CONTROL, + }, + }; + struct rte_security_capability capabilities[] = { + { + .action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_PDCP, + .pdcp = { + .domain = RTE_SECURITY_PDCP_MODE_CONTROL, + }, + }, + { + .action = RTE_SECURITY_ACTION_TYPE_NONE, + }, + }; + + mock_capabilities_get_exp.device = NULL; + mock_capabilities_get_exp.ret = capabilities; + + const struct rte_security_capability *ret; + ret = rte_security_capability_get(&ut_params->ctx, &idx); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get, + ret, &capabilities[1], "%p"); + TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1); + + return TEST_SUCCESS; +} + /** * Declaration of testcases */ @@ -1897,6 +2388,37 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_capabilities_get_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_inv_idx), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_empty_table), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_no_matching_action), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_no_matching_protocol), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_no_support_for_macsec), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_ipsec_mismatch_proto), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_ipsec_mismatch_mode), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_ipsec_mismatch_dir), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_ipsec_match), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_pdcp_mismatch_domain), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_capability_get_pdcp_match), + TEST_CASES_END() /**< NULL terminate unit test array */ } };