From patchwork Thu Apr 9 17:24: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: 68064 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 A9E2FA0597; Thu, 9 Apr 2020 19:25:43 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5B55E1C2C0; Thu, 9 Apr 2020 19:25:34 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 16FF41BF1B for ; Thu, 9 Apr 2020 19:25:31 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172530euoutp0150d3d5bf0aa5584c37209d5377c9b822~ENreEeguw0978309783euoutp01q for ; Thu, 9 Apr 2020 17:25:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200409172530euoutp0150d3d5bf0aa5584c37209d5377c9b822~ENreEeguw0978309783euoutp01q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453130; bh=D+yKErKT0gB5hOObuVTAElRuR7IGi9JsRhDXn7p5Qx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qutIBPNjmfa2ReBoSZFQ8dvm6jRbnT/olJI9SQ7kyKsT7RUHeoQD9vDSKN3L0kvMM Jchtkt8sdWsdpRIQqu2vgnO7F33yLdLZkqu3b+h2lU3GZmlRITaz0fZqRoV+d5YfFa D+zUnV2xKTOKexKXOzkQLoHa38neW3PF8CwvtuYQ= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200409172530eucas1p2c85d5eeea83d6b8755f1f96f108cb8de~ENrd8JtdB2361523615eucas1p2C; Thu, 9 Apr 2020 17:25:30 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 92.71.60698.A8A5F8E5; Thu, 9 Apr 2020 18:25:30 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200409172529eucas1p1f02aaf66052f45ac75ba9e9f63ef1c3a~ENrdfboiw0650506505eucas1p1B; Thu, 9 Apr 2020 17:25:29 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172529eusmtrp131e602943bf6e4c9c96b18631c495e35~ENrdeN5t82215922159eusmtrp1k; Thu, 9 Apr 2020 17:25:29 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-80-5e8f5a8a0b3c Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 92.48.07950.98A5F8E5; Thu, 9 Apr 2020 18:25:29 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172529eusmtip1cea41c6cc2c6660ec166f2a00c8eb6bc~ENrcuc5w41096110961eusmtip1o; Thu, 9 Apr 2020 17:25:29 +0000 (GMT) From: Lukasz Wojciechowski To: Akhil Goyal , Declan Doherty , Aviad Yehezkel , Radu Nicolau , Boris Pismenny , Anoob Joseph Cc: dev@dpdk.org, stable@dpdk.org Date: Thu, 9 Apr 2020 19:24:50 +0200 Message-Id: <20200409172502.1693-2-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgleLIzCtJLcpLzFFi42LZduznOd2uqP44g+PfhSzWn5nHaHHq9gdm iw+TlzBaHPvRzm7x5kETi8W7T9uZLNq6BCz+dfxhd+Dw2HCin9Xj14KlrB6L97xk8ng2/TCT x8Z3O5gCWKO4bFJSczLLUov07RK4Mh5v/cte8Fm/4sDOVYwNjAc0uhg5OSQETCR2tB5jB7GF BFYwSvxtd+pi5AKyvzBKnGm5xgLhfGaUmHSwjbmLkQOso6U7HyK+nFGi8dw9RriiEzO/MIKM YhOwlTgy8ysrSEJE4BejxLN1d1hAEswCihJ3V35lA7GFBZwktu6cALabRUBVYsr+P8wgNq+A i8SEbU9ZIe6Tl1i94QBYnFPAVeLW8UvMIEMlBH6zSfzb/h+qyEWieeYbKFtY4tXxLewQtozE 6ck9LBAN2xglrv7+yQjh7GeUuN67AqrKWuLwv99sIM8xC2hKrN+lD/Gno8S3e9EQJp/EjbeC EPfzSUzaNh0aErwSHW1CEDP0JJ72TGWE2fpn7RMWCNtDon3iSmZIAF1mlNi34A7TBEb5WQi7 FjAyrmIUTy0tzk1PLTbOSy3XK07MLS7NS9dLzs/dxAhMF6f/Hf+6g3Hfn6RDjAIcjEo8vB1M /XFCrIllxZW5hxglOJiVRHi9m3rjhHhTEiurUovy44tKc1KLDzFKc7AoifMaL3oZKySQnliS mp2aWpBaBJNl4uCUamAscEjutj1Zt3TmCamjXV8iopp2rmKxfF+unfrAQjTlzI+svUGM/2a8 Sykw9q5s616eIJ9bv9dRh+Hu/kWrasp8rn2s0eB9cEC4OraX+/5u1z8By0IT+udsfp4nLydZ mvqgIeqym89Cjka/SeptD0x7v5n+fTdjyZTfbG9q828pJ1bdjhdL61ZiKc5INNRiLipOBACr WyMREwMAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrPLMWRmVeSWpSXmKPExsVy+t/xu7qdUf1xBp/3m1isPzOP0eLU7Q/M Fh8mL2G0OPajnd3izYMmFot3n7YzWbR1CVj86/jD7sDhseFEP6vHrwVLWT0W73nJ5PFs+mEm j43vdjAFsEbp2RTll5akKmTkF5fYKkUbWhjpGVpa6BmZWOoZGpvHWhmZKunb2aSk5mSWpRbp 2yXoZTze+pe94LN+xYGdqxgbGA9odDFycEgImEi0dOd3MXJxCAksZZS4tWopO0RcRuLDJYEu Rk4gU1jiz7UuNhBbSOAjo8SEBRogNpuArcSRmV9ZQXpFBP4xSuz9OokFpJdZQFmib4sVSI2w gJPE1p0T2EFsFgFViSn7/zCD2LwCLhITtj1lhZgvL7F6wwGwOKeAq8St45eYIXbVS9zu+sM4 gZFvASPDKkaR1NLi3PTcYiO94sTc4tK8dL3k/NxNjMDA3Xbs55YdjF3vgg8xCnAwKvHwGjD0 xwmxJpYVV+YeYpTgYFYS4fVu6o0T4k1JrKxKLcqPLyrNSS0+xGgKdNREZinR5HxgVOWVxBua GppbWBqaG5sbm1koifN2CByMERJITyxJzU5NLUgtgulj4uCUamBs/sGephkXqPvx3tFX+rO3 ar2/w3Hm0WmJzMPbBYWvtf9vWJTqVGjzVNvrqaKJfvOGbseUio9fU6/atLw6zvqkcrrNhsQr Fy7kzn+6Jnrf4mnKB+efeL7FiX/Shvlaem8Wxq54cudiddTECIWD3sa6J5rl/eKqnzfeX2VX 9tqpJo87Ikni20knJZbijERDLeai4kQAtD1Pk3ICAAA= X-CMS-MailID: 20200409172529eucas1p1f02aaf66052f45ac75ba9e9f63ef1c3a X-Msg-Generator: CA X-RootMTR: 20200409172529eucas1p1f02aaf66052f45ac75ba9e9f63ef1c3a X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172529eucas1p1f02aaf66052f45ac75ba9e9f63ef1c3a References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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 Acked-by: Anoob Joseph --- lib/librte_security/rte_security.c | 59 +++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/lib/librte_security/rte_security.c b/lib/librte_security/rte_security.c index bc81ce15d..38ccc2ea9 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_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_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 Thu Apr 9 17:24: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: 68065 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 B3209A0597; Thu, 9 Apr 2020 19:25:56 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1C63A1D16B; Thu, 9 Apr 2020 19:25:37 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 8D3291BF1B for ; Thu, 9 Apr 2020 19:25:31 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172531euoutp010a33c8a0b1dee7480ef66fe9d274e8c4~ENrezRGq80657706577euoutp01U for ; Thu, 9 Apr 2020 17:25:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200409172531euoutp010a33c8a0b1dee7480ef66fe9d274e8c4~ENrezRGq80657706577euoutp01U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453131; bh=0YWcS2qDaQ1h6nZKYypd2a8cIslnGFvrqlEK4e4zOo0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=srG1PvDF4mU1mdN8Kxt53j697SeSNRqjBQY+TSgpmDcibcPKxLsS5iAiFsn3qJ18x 0XSTqkkmlNJjmMcCf/erdqG24yzxGiksrY7oDE9QDMezP1TYUwEatnIxEF5DX+y9Yu Ok7uGeOt5M6a+fAVAnynYM8kvKduUB8SlyF8OQvw= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200409172531eucas1p20535b5dadb764a800291657244a5dd43~ENrel8Z6v2361523615eucas1p2E; Thu, 9 Apr 2020 17:25:31 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 23.71.60698.B8A5F8E5; Thu, 9 Apr 2020 18:25:31 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200409172530eucas1p27297a83a9d7508e3f8a8f88850cbe37c~ENreUAbDG0102501025eucas1p2j; Thu, 9 Apr 2020 17:25:30 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172530eusmtrp1661710d928334d6531f457af107608b3~ENreTXSqT2463624636eusmtrp1B; Thu, 9 Apr 2020 17:25:30 +0000 (GMT) X-AuditID: cbfec7f5-a0fff7000001ed1a-83-5e8f5a8beb05 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 23.48.07950.A8A5F8E5; Thu, 9 Apr 2020 18:25:30 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172530eusmtip1ce8939012396c4d7596df736f288f12b~ENrdlkzqV0696806968eusmtip1T; Thu, 9 Apr 2020 17:25:29 +0000 (GMT) From: Lukasz Wojciechowski To: Akhil Goyal , Declan Doherty , Boris Pismenny , Aviad Yehezkel , Radu Nicolau Cc: dev@dpdk.org, stable@dpdk.org Date: Thu, 9 Apr 2020 19:24:51 +0200 Message-Id: <20200409172502.1693-3-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBIsWRmVeSWpSXmKPExsWy7djPc7rdUf1xBj+fs1qsPzOP0eLD5CWM Fsd+tLNbvHnQxGLx7tN2Jou2LgGLfx1/2B3YPX4tWMrqsXjPSyaPZ9MPM3lsfLeDKYAlissm JTUnsyy1SN8ugStj24OzjAVHeCrunF3K3sA4i6uLkZNDQsBE4n5vM3sXIxeHkMAKRokJU7aw QThfGCUWzrrCClIlJPCZUeLgQ1+YjufXFjFDFC1nlDi78SUThANU1LTkKCNIFZuArcSRmV9Z QRIiAicYJaZPXswEkmAWUJS4u/IrG4gtLOAq8evrHTCbRUBV4nZPN9g6XgEXiamN21gh1slL rN5wgBnE5gSqv3X8EthqCYHXbBLHn21khyhykbj56jgjhC0s8er4Fqi4jMTpyT0sEA3bGCWu /v7JCOHsZ5S43rsCqspa4vC/30BncACdpymxfpc+RNhRorPhFDNIWEKAT+LGW0GIB/gkJm2b DhXmlehoE4Ko1pN42jOVEWbtn7VPWCBsD4k98/ZBw/Qyo8Tau+fYJjDKz0JYtoCRcRWjeGpp cW56arFxXmq5XnFibnFpXrpecn7uJkZgejj97/jXHYz7/iQdYhTgYFTi4e1g6o8TYk0sK67M PcQowcGsJMLr3dQbJ8SbklhZlVqUH19UmpNafIhRmoNFSZzXeNHLWCGB9MSS1OzU1ILUIpgs EwenVAOjRWxc5XvOkxWbP/V67txu+/vj9H0XD+l9ucs260ioWUpy7U87SY7VP2IWBpxzs/aP jpa/uGW/37ZyyxvaO5ZmlHN/m1kiNUHxcN1PkT9lzcdVmFdzxEl3bQ7SM/fYptnc38n05Oqh kMnNdvPmVaTsn9On5x3NvLd48vSPYT5c4f4LVlls3dqmxFKckWioxVxUnAgAO2EJYwsDAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRmVeSWpSXmKPExsVy+t/xu7pdUf1xBpfnaVmsPzOP0eLD5CWM Fsd+tLNbvHnQxGLx7tN2Jou2LgGLfx1/2B3YPX4tWMrqsXjPSyaPZ9MPM3lsfLeDKYAlSs+m KL+0JFUhI7+4xFYp2tDCSM/Q0kLPyMRSz9DYPNbKyFRJ384mJTUnsyy1SN8uQS9j24OzjAVH eCrunF3K3sA4i6uLkZNDQsBE4vm1RcxdjFwcQgJLGSX6r+1h6mLkAErISHy4JABRIyzx51oX G4gtJPCRUWJFiwSIzSZgK3Fk5ldWkF4RgTOMEmsvngHrZRZQlujbYgVSIyzgKvHr6x2wXhYB VYnbPd2sIDavgIvE1MZtrBDz5SVWbzjADGJzAtXfOn6JGWJXvcTtrj+MExj5FjAyrGIUSS0t zk3PLTbSK07MLS7NS9dLzs/dxAgM023Hfm7Zwdj1LvgQowAHoxIPrwFDf5wQa2JZcWXuIUYJ DmYlEV7vpt44Id6UxMqq1KL8+KLSnNTiQ4ymQEdNZJYSTc4HxlBeSbyhqaG5haWhubG5sZmF kjhvh8DBGCGB9MSS1OzU1ILUIpg+Jg5OqQbGKH81ff+NZ4tFC9c+Lp1orKxvd0JjaucOB89n x6JdeW77CUhNyv69bNHsOU/n8efwfVq5153Dy3mjgJhoNF9b4tLqOXts5nXsSGCavPgTY2XE h+szfi3YLcgoJbhrY2VIXgPbTuYf5xbqLlbqk2/Mt54myuVw40/rBpk6oYi1y0OdBGuk//Ao sRRnJBpqMRcVJwIAueDvHGkCAAA= X-CMS-MailID: 20200409172530eucas1p27297a83a9d7508e3f8a8f88850cbe37c X-Msg-Generator: CA X-RootMTR: 20200409172530eucas1p27297a83a9d7508e3f8a8f88850cbe37c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172530eucas1p27297a83a9d7508e3f8a8f88850cbe37c References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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 Acked-by: Anoob Joseph --- 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 Thu Apr 9 17:24:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 68066 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 1DB0FA0597; Thu, 9 Apr 2020 19:26:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0D2001D177; Thu, 9 Apr 2020 19:25:39 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 6E7621BF1B for ; Thu, 9 Apr 2020 19:25:32 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172532euoutp027b3b5c060d173fe3b9c194e06e6c77e4~ENrfoSEyj2095420954euoutp02j for ; Thu, 9 Apr 2020 17:25:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200409172532euoutp027b3b5c060d173fe3b9c194e06e6c77e4~ENrfoSEyj2095420954euoutp02j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453132; bh=OlcosswvJXilB/2xJwKx19G4Sv0RWdYzyzXv2rY0p38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JDSy/aC1pzE+tWOiTDjnge2uayt3wENVo9rW719bcYR9zG0PLXnTy9lB7wnAl5XWz g81ZVo47wp8lrEY3Pkoe+WGeyrKxz0kDwd3e/KFedgj4RAJKalzwDpIrYUbgzrhezH suU37ZZDiBvDfZjLWyKR9qYDln2AVpQxIpF6hWNY= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200409172532eucas1p1cfe4b7d36652caceb9f46255a4fc81c6~ENrfc-xN50986409864eucas1p1u; Thu, 9 Apr 2020 17:25:32 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id C1.F2.61286.B8A5F8E5; Thu, 9 Apr 2020 18:25:32 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200409172531eucas1p1c3ec21532e5e232ff2d68d56f096e71c~ENre_MOBB2193421934eucas1p1E; Thu, 9 Apr 2020 17:25:31 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172531eusmtrp12170ba3be553e58eadab0a8448dcb4a2~ENre9nqCH2463624636eusmtrp1D; Thu, 9 Apr 2020 17:25:31 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-2f-5e8f5a8b37b2 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id A3.48.07950.B8A5F8E5; Thu, 9 Apr 2020 18:25:31 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172530eusmtip1e7e97b2a043377aa5cbe5be2d81b6e80~ENreVcUOs1096110961eusmtip1p; Thu, 9 Apr 2020 17:25:30 +0000 (GMT) From: Lukasz Wojciechowski To: Akhil Goyal , Declan Doherty , Boris Pismenny , Radu Nicolau , Aviad Yehezkel Cc: dev@dpdk.org, stable@dpdk.org Date: Thu, 9 Apr 2020 19:24:52 +0200 Message-Id: <20200409172502.1693-4-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOIsWRmVeSWpSXmKPExsWy7djPc7o9Uf1xBk8XMVqsPzOP0eLD5CWM Fsd+tLNbvHnQxGLx7tN2Jou2LgGLfx1/2B3YPX4tWMrqsXjPSyaPZ9MPM3lsfLeDKYAlissm JTUnsyy1SN8ugSuj8007W0ELd8XtP13sDYxrObsYOTkkBEwkVn/awtTFyMUhJLCCUWLP1WPM EM4XRolra84zgVQJCXxmlOi7nATTseD0ChaIouWMEp+vfGKHcICKTlxsZwSpYhOwlTgy8ysr SEJE4ASjxIH3f8BGMQsoStxd+ZUNxBYWMJf48PIxWJxFQFXi4uG7LCA2r4CLxOubBxkh1slL rN5wgBnE5hRwlbh1/BLYfRIC79kkrp+cyQRR5CJx9m0DVIOwxKvjW9ghbBmJ05N7WCAatjFK XP39kxHC2c8ocb13BVSVtcThf7+BTuIAOk9TYv0ufYiwo8TWf+eYQcISAnwSN94KQjzAJzFp 23SoMK9ER5sQRLWexNOeqYwwa/+sfcICUeIhsWNjDCSALjNKzLkwk3kCo/wshF0LGBlXMYqn lhbnpqcWG+allusVJ+YWl+al6yXn525iBCaH0/+Of9rB+PVS0iFGAQ5GJR5eA4b+OCHWxLLi ytxDjBIczEoivN5NvXFCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeY0XvYwVEkhPLEnNTk0tSC2C yTJxcEo1MJq5LFAXmPn8w5RJgl8/X47482j2Ct+EXROMz/7d8Vlt9uz3bpKrTsqeWt/5aF6y 4M6whKlfGJp8T7ZO3nNl6bn1xj8ueBWy19zM5lqcNvlTdGFMokHAxztRjeHuni7leccuGZiX L4ioczvDJMlhUq9dWFua8Xtx6qEjWec2h3yYYV635NoSVVslluKMREMt5qLiRAD5HiBDCgMA AA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRmVeSWpSXmKPExsVy+t/xu7rdUf1xBj8Xy1isPzOP0eLD5CWM Fsd+tLNbvHnQxGLx7tN2Jou2LgGLfx1/2B3YPX4tWMrqsXjPSyaPZ9MPM3lsfLeDKYAlSs+m KL+0JFUhI7+4xFYp2tDCSM/Q0kLPyMRSz9DYPNbKyFRJ384mJTUnsyy1SN8uQS+j8007W0EL d8XtP13sDYxrObsYOTkkBEwkFpxewdLFyMUhJLCUUWL3pzPsXYwcQAkZiQ+XBCBqhCX+XOti g6j5yCjxb8IbRpAEm4CtxJGZX1lBEiICZxgldq2bwALSzCygLNG3xQqkRljAXOLDy8dMIDaL gKrExcN3WUBsXgEXidc3DzJCLJCXWL3hADOIzSngKnHr+CUwW0igXuJ21x/GCYx8CxgZVjGK pJYW56bnFhvpFSfmFpfmpesl5+duYgQG6rZjP7fsYOx6F3yIUYCDUYmH14ChP06INbGsuDL3 EKMEB7OSCK93U2+cEG9KYmVValF+fFFpTmrxIUZToKMmMkuJJucDoyivJN7Q1NDcwtLQ3Njc 2MxCSZy3Q+BgjJBAemJJanZqakFqEUwfEwenVAPjnFmhoZnBzLIHp8xXUrmd4rGJQWza/10z MnblJ5cK79AuT2W0fDNx3aFn9nuO6H7NVew5Kf/KhinltgeDUa3h49dacxY9F+Ve6Xe2a4ei v8neBxdWC0g0tmT/tqrnsFH0uTz3rpqNhcbr32+Cii/WCd47bB1VcIGNwe1td75r49EO4dfP L75RYinOSDTUYi4qTgQAr5lcmmoCAAA= X-CMS-MailID: 20200409172531eucas1p1c3ec21532e5e232ff2d68d56f096e71c X-Msg-Generator: CA X-RootMTR: 20200409172531eucas1p1c3ec21532e5e232ff2d68d56f096e71c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172531eucas1p1c3ec21532e5e232ff2d68d56f096e71c References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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 Acked-by: Anoob Joseph --- 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 38ccc2ea9..d475b0977 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 Thu Apr 9 17:24:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 68067 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 03243A0597; Thu, 9 Apr 2020 19:26:19 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B2D531D37F; Thu, 9 Apr 2020 19:25:40 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 2554C1C2B4 for ; Thu, 9 Apr 2020 19:25:33 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172532euoutp023ffda8a2297ec66882b75519f6883717~ENrgRJYjk2096020960euoutp02i for ; Thu, 9 Apr 2020 17:25:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200409172532euoutp023ffda8a2297ec66882b75519f6883717~ENrgRJYjk2096020960euoutp02i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453132; bh=5t6Er6wp1FOx7AjUi/z3GKlKuF+0d9Qq/zxnMShYpmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=reP57MisHXWURTxLcyt07Lkx5iwwukpcHLodmY+10bRzZvwyKsLh5sTbgvFClxjMF YPzoWfhH0fH8abVTLkbcHlR7wIqRFdDfk4NHuGc64FiXzxVwZCBqoPAWsU5HBekiQw FOgoiOP/pRxVT1neT9BxqBWjxRDrJyerfCn3fCOY= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200409172532eucas1p24b60db9791eb29c3a4588dbe8a1c1142~ENrgLTKi90290902909eucas1p2l; Thu, 9 Apr 2020 17:25:32 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id C3.71.60698.C8A5F8E5; Thu, 9 Apr 2020 18:25:32 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200409172532eucas1p285bc6767be1d62a0098d177a7757169f~ENrflAqXq0102601026eucas1p2D; Thu, 9 Apr 2020 17:25:32 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172532eusmtrp1d5f5394579b398bbc66044fd5987fa2b~ENrfkctEq2463624636eusmtrp1F; Thu, 9 Apr 2020 17:25:32 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-86-5e8f5a8ce688 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 6C.B9.08375.C8A5F8E5; Thu, 9 Apr 2020 18:25:32 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172531eusmtip15a65647648a58e0f2a7605e6a6821906~ENrfB27gU0971609716eusmtip1V; Thu, 9 Apr 2020 17:25:31 +0000 (GMT) From: Lukasz Wojciechowski To: Jerin Jacob , Thomas Monjalon , Pavan Nikhilesh Cc: dev@dpdk.org, stable@dpdk.org Date: Thu, 9 Apr 2020 19:24:53 +0200 Message-Id: <20200409172502.1693-5-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBIsWRmVeSWpSXmKPExsWy7djPc7o9Uf1xBmvW6Fu8+7SdyWLiJBOL i+ssLP51/GG3+PTgBIsDq8eGE/2sHr8WLGX1OHZzGnsAcxSXTUpqTmZZapG+XQJXRteXXraC /WwVN/7vZ2xg3MTaxcjJISFgIvF47x6mLkYuDiGBFYwSZ07MZYFwvjBKbN/8lxHC+cwosWby AWaYlk2bjkC1LGeUOH/tDgtIAqxqzhtuEJtNwFbiyMyvrCBFIgI9jBL3b3wH62YWUJS4u/Ir G4gtLGAt0bn7L5jNIqAqcWJxO1gNr4CLxNF9f6EOlJdYvQFiM6eAq8St45eYQYZKCFxnk3hw dCUTRJGLROOCqVC2sMSr41vYIWwZidOTe1ggGrYxSlz9/ZMRwtnPKHG9dwVUlbXE4X+/gc7g ADpPU2L9Ln2IsKPEgd5fzCBhCQE+iRtvBSEe4JOYtG06VJhXoqNNCKJaT+Jpz1RGmLV/1j5h gbA9JI793gMNxsuMEk9nH2aewCg/C2HZAkbGVYziqaXFuempxcZ5qeV6xYm5xaV56XrJ+bmb GIHxf/rf8a87GPf9STrEKMDBqMTD28HUHyfEmlhWXJl7iFGCg1lJhNe7qTdOiDclsbIqtSg/ vqg0J7X4EKM0B4uSOK/xopexQgLpiSWp2ampBalFMFkmDk6pBsbtzdWCF3QOzvPnXNxzXzEt ZzXPpRXzIzhl30ZP9bAM/bvsn7FG3O0HVyIuBWdF5+1j89wSPDnl0Je0a1MNEu6skZ5vef7R 3znzHjd+PlpRZ/7WO3uGP1toX2QV/zK74qg7Hasq1nV9azi0o/Na9+oM2WV60qc1LEw+3Qw/ 8i5fbPsK3flzj7xTYinOSDTUYi4qTgQAzNocmfsCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrOLMWRmVeSWpSXmKPExsVy+t/xu7o9Uf1xBv8ucVq8+7SdyWLiJBOL i+ssLP51/GG3+PTgBIsDq8eGE/2sHr8WLGX1OHZzGnsAc5SeTVF+aUmqQkZ+cYmtUrShhZGe oaWFnpGJpZ6hsXmslZGpkr6dTUpqTmZZapG+XYJeRteXXraC/WwVN/7vZ2xg3MTaxcjJISFg IrFp0xGmLkYuDiGBpYwSKw9eZOti5ABKyEh8uCQAUSMs8edaFxtEzUdGiQedy9hBEmwCthJH Zn5lBUmICPQxSiz+O5UdpJlZQFmib4sVSI2wgLVE5+6/bCA2i4CqxInF7cwgNq+Ai8TRfX+h jpCXWL3hAFicU8BV4tbxS2C2kEC9xO2uP4wTGPkWMDKsYhRJLS3OTc8tNtQrTswtLs1L10vO z93ECAzEbcd+bt7BeGlj8CFGAQ5GJR5eA4b+OCHWxLLiytxDjBIczEoivN5NvXFCvCmJlVWp RfnxRaU5qcWHGE2BjprILCWanA+MkrySeENTQ3MLS0NzY3NjMwslcd4OgYMxQgLpiSWp2amp BalFMH1MHJxSDYwmX314Ay7f4mw+I8bR++PFzsqnV8OTHl750DTp/IYs66J3MTp+14w2Ptae u3iiwTdZlycr74QVvoubPunvrcuf15W8e+96fJ/fp1/TeH3KJgdM3n5v1vJLaXdZTlYm1ppY Xm6W2pEt0eqU9FHie7XxDh3/gAV31+/j9VO20Q3dr3n+ySezX9fWK7EUZyQaajEXFScCAFV3 9XJaAgAA X-CMS-MailID: 20200409172532eucas1p285bc6767be1d62a0098d177a7757169f X-Msg-Generator: CA X-RootMTR: 20200409172532eucas1p285bc6767be1d62a0098d177a7757169f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172532eucas1p285bc6767be1d62a0098d177a7757169f References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 04/13] app/test: remove 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" Remove RTE_TEST_TRACE_FAILURE macro definition from app/test/test.h as it might be already defined and cause build problems. Also it is good to leave the decision of additional logs to the final user of test.h and rte_test.h Fixes: 5afc521eac6a ("eal: add test assert macros") Cc: pbhagavatula@caviumnetworks.com Cc: stable@dpdk.org Signed-off-by: Lukasz Wojciechowski --- app/test/test.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/test/test.h b/app/test/test.h index ac0c50616..b07f6c1ef 100644 --- a/app/test/test.h +++ b/app/test/test.h @@ -22,8 +22,6 @@ # define TEST_TRACE_FAILURE(_file, _line, _func) #endif -#define RTE_TEST_TRACE_FAILURE TEST_TRACE_FAILURE - #include #define TEST_ASSERT RTE_TEST_ASSERT From patchwork Thu Apr 9 17:24:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 68069 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 3B9DEA0597; Thu, 9 Apr 2020 19:26:36 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6121F1D40B; Thu, 9 Apr 2020 19:25:43 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 117F81C437 for ; Thu, 9 Apr 2020 19:25:34 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172534euoutp01311465a95bffb69d26b4693103ad1844~ENrh6WQud0978309783euoutp01t for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200409172534euoutp01311465a95bffb69d26b4693103ad1844~ENrh6WQud0978309783euoutp01t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453134; bh=WrcdDMMRND8v2u1ONiKug0Uemv1+AJ6IvTjxmpvaYco=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lq9Pef6qMslK4PkHv8v0o6ZK0x3B5/bZUz/iOqwdaXKVKwo1Cuebu1/BBhQBo3Ctr x9LguAlpsz0a4M56hbRmpIV+FkcaG8v0hbRZYrjRPLUQKXmbWfO14VHzIUCX/oNfK7 iu7f2rWTjwsQmUHoSsdbErvOZf4eNydJPgW7Pkzg= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200409172534eucas1p2099daf82245f993879db947d5d79fc62~ENrhyEc711612816128eucas1p2E for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id D3.F2.61286.E8A5F8E5; Thu, 9 Apr 2020 18:25:34 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200409172533eucas1p1f4363aa89cfbda87e5d20da1006e21c0~ENrgyXlqu0987109871eucas1p1o for ; Thu, 9 Apr 2020 17:25:33 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172533eusmtrp11239e15c2ef2d6275bc55cb5b6292c88~ENrgx4gFP2463624636eusmtrp1H for ; Thu, 9 Apr 2020 17:25:33 +0000 (GMT) X-AuditID: cbfec7f2-f0bff7000001ef66-34-5e8f5a8ef17b Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id CC.B9.08375.D8A5F8E5; Thu, 9 Apr 2020 18:25:33 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172532eusmtip1e2d21e889fa9bb6326009d6211ecce29~ENrft6aOi1096110961eusmtip1q for ; Thu, 9 Apr 2020 17:25:32 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:24:54 +0200 Message-Id: <20200409172502.1693-6-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrDIsWRmVeSWpSXmKPExsWy7djPc7p9Uf1xBrc/yFm8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGSumihQ82s9YsWBxL3sD4+T5jF2MnBwSAiYST54+Yuti5OIQ EljBKPHpwmxWCKedSWLS26NQThuTxMTJD1hgWubP/QrWLiSwnFHi21IPuKLWyffBEmwCthJH Zn5lBbFFBFgkVn7/DtbMLCAg8fjeM7C4sICzxJ2528DiLAKqEpevTWEDsXkFXCR2bGpghlgm L7F6wwEwm1PAVeLW8UvMIMskBFawScz8PIkNoshFom3KLyYIW1ji1fEt7BC2jMTpyT0sEA3b GCWu/v7JCOHsZ5S43rsCqspa4vC/30CTOIDO05RYv0sfIuwo8e31TiaQsIQAn8SNt4IQD/BJ TNo2nRkizCvR0SYEUa0n8bRnKiPM2j9rn0ADy0Oi/cV/dkgAXWaU+DvnCdsERvlZCMsWMDKu YhRPLS3OTU8tNsxLLdcrTswtLs1L10vOz93ECIzj0/+Of9rB+PVS0iFGAQ5GJR5eA4b+OCHW xLLiytxDjBIczEoivN5NvXFCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeY0XvYwVEkhPLEnNTk0t SC2CyTJxcEo1MG7T6fy2acF+119LCnwMZh4MmW//I/zMOpPeL346B2zPeHXnrRGe9kr82b6V v5cEpTIWF97dkrjvqtf2ZzEP5JO1xHS2tG/aHNx46/OtT/y9V02bT/4/FS5g3rZ8bcXOrzU/ Ksyz7PlfLGBcK9Q6lev8jF3Tj6bKfLWTcW0U8tT8WvTu2NtNm0OUWIozEg21mIuKEwFO4sKt 3wIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrDLMWRmVeSWpSXmKPExsVy+t/xu7q9Uf1xBrfPSVm8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GSumihQ82s9YsWBxL3sD4+T5jF2MnBwSAiYS8+d+BbK5OIQEljJKzDzbx9TFyAGUkJH4cEkA okZY4s+1LjaImhYmicPfrzCBJNgEbCWOzPzKCmKLCLBIrPz+nQXEZhYQkHh87xlYXFjAWeLO 3G1gcRYBVYnL16awgdi8Ai4SOzY1MEMskJdYveEAmM0p4Cpx6/glMFtIoF7idtcfxgmMfAsY GVYxiqSWFuem5xYb6hUn5haX5qXrJefnbmIEhtS2Yz8372C8tDH4EKMAB6MSD68BQ3+cEGti WXFl7iFGCQ5mJRFe76beOCHelMTKqtSi/Pii0pzU4kOMpkBHTWSWEk3OB4Z7Xkm8oamhuYWl obmxubGZhZI4b4fAwRghgfTEktTs1NSC1CKYPiYOTqkGRs4N1x63stR8VDGWMLdJ4vl4KkB5 6hqpXeIidZa69YsZPkb87/ZgXnxocdTPYq1QxnoPPfaNO+bPF8u/ErvuU7PKt/1KXRltsr4i 66YGf/28kVc44PqzjZMDlOzfGpiUspmY5p54nl0WcyT5UZ3SPcYvc3Yc+1ySonnkdte2by4m Allcf9MclViKMxINtZiLihMBQtaUMj8CAAA= X-CMS-MailID: 20200409172533eucas1p1f4363aa89cfbda87e5d20da1006e21c0 X-Msg-Generator: CA X-RootMTR: 20200409172533eucas1p1f4363aa89cfbda87e5d20da1006e21c0 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172533eucas1p1f4363aa89cfbda87e5d20da1006e21c0 References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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 Thu Apr 9 17:24:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 68068 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 08931A0597; Thu, 9 Apr 2020 19:26:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 06BFD1D405; Thu, 9 Apr 2020 19:25:42 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id D72A11C2F3 for ; Thu, 9 Apr 2020 19:25:34 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172534euoutp02097379ca2535b4e35b25faab12f5ae7b~ENrh6v6LJ2095420954euoutp02l for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200409172534euoutp02097379ca2535b4e35b25faab12f5ae7b~ENrh6v6LJ2095420954euoutp02l DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453134; bh=UU/wxp6Tjzo1nyxDa7i6/6DQF7d/5k1o9xF1LLYCsYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RusurEuNirc/Xf90rwm9ZGXF+EaUMXapiaaOn/hIxkYwjUsGRVYPVl0eEi8zqoR83 OuEtcYWhRDrUVGjh2m9mcvz/OKm70DKrLQRt4Cw4Fb0BVY6/Fzb4THRoHNpvstKR0h 3qv8DhNooRJP4qXfm08f6wEwsTZWsnIEqFSPRkLs= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200409172534eucas1p1cddf0003b30be0883964c81cc2157caf~ENrhsH2V40985509855eucas1p1y for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id B3.F2.61286.E8A5F8E5; Thu, 9 Apr 2020 18:25:34 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200409172533eucas1p252ed0cac1689b067a83589a0665c9033~ENrhNfuD30102501025eucas1p2m for ; Thu, 9 Apr 2020 17:25:33 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172533eusmtrp1bd51c8bea937c7e839e3c81af6221f6e~ENrhM-VAo2463624636eusmtrp1I for ; Thu, 9 Apr 2020 17:25:33 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-33-5e8f5a8e0a9d Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id B4.48.07950.D8A5F8E5; Thu, 9 Apr 2020 18:25:33 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172533eusmtip17bdd34a42266d579550e1c30dd70d302~ENrg274x60696506965eusmtip1R for ; Thu, 9 Apr 2020 17:25:33 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:24:55 +0200 Message-Id: <20200409172502.1693-7-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNIsWRmVeSWpSXmKPExsWy7djP87p9Uf1xBqd3SFm8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGROOXWQq2OheMXXhV9YGxl02XYwcHBICJhL/tnp2MXJxCAms YJTovHiCFcJpZ5J4fPELM4TTxiSx59Jm9i5GTrCO7ptbmSASyxklJjVfZ4Sr+jh5JytIFZuA rcSRmV/BbBEBFomV37+zgNjMAgISj+89A4sLC3hKPNi2hxHEZhFQlbjz9BQTiM0r4CIx7c8f Voht8hKrNxxgBrE5BVwlbh2/BHaShMAaNokDXyZCneQiceLzXjYIW1ji1fEtUHEZidOTe1gg GrYxSlz9/ZMRwtnPKHG9dwVUlbXE4X+/2UDBwSygKbF+lz5E2FHi17WVLJBQ4pO48VYQ4gE+ iUnbpjNDhHklOtqEIKr1JJ72TGWEWftn7RMWCNtD4tbBo9Awvcwo8XnhUZYJjPKzEJYtYGRc xSieWlqcm55abJiXWq5XnJhbXJqXrpecn7uJERjFp/8d/7SD8eulpEOMAhyMSjy8Bgz9cUKs iWXFlbmHGCU4mJVEeL2beuOEeFMSK6tSi/Lji0pzUosPMUpzsCiJ8xovehkrJJCeWJKanZpa kFoEk2Xi4JRqYJQ/0b3Y9nFwnsYz4VzrRvaUlCy1BM3XIaYtUk82KLLOFXBfUX37eNstMY0t /+coTH19REnPjNlBS8rKxlwqRv/bTvMFEvWb2KvOB9Wtv3jQQ88p7tLpOQ5H5D6rLJbZ73Kw q2H5rpgVUzMluX8vett19sipz6yXwhcd65i1eumbcxn3D3MJFSqxFGckGmoxFxUnAgDxenUT 3gIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrNLMWRmVeSWpSXmKPExsVy+t/xu7q9Uf1xBl97TC3efdrO5MDo8WvB UtYAxig9m6L80pJUhYz84hJbpWhDCyM9Q0sLPSMTSz1DY/NYKyNTJX07m5TUnMyy1CJ9uwS9 jAnHLjIVbHSvmLrwK2sD4y6bLkZODgkBE4num1uZuhi5OIQEljJKTHzznaWLkQMoISPx4ZIA RI2wxJ9rXWwQNS1MEj/v/WQGSbAJ2EocmfmVFcQWEWCRWPkdpJeTg1lAQOLxvWdgcWEBT4kH 2/YwgtgsAqoSd56eYgKxeQVcJKb9+cMKsUBeYvWGA2AzOQVcJW4dvwRmCwnUS9zu+sM4gZFv ASPDKkaR1NLi3PTcYiO94sTc4tK8dL3k/NxNjMCA2nbs55YdjF3vgg8xCnAwKvHwGjD0xwmx JpYVV+YeYpTgYFYS4fVu6o0T4k1JrKxKLcqPLyrNSS0+xGgKdNREZinR5HxgsOeVxBuaGppb WBqaG5sbm1koifN2CByMERJITyxJzU5NLUgtgulj4uCUamBkWyS8iPUgn6uO3KuZcxfKyjza eCvzxKqGT5OW5p1TfS2+nCN/ja+JuvazZ9+P8Dg/z/+hsIdtvu0S42mBtcFhFYyT15Q9tcur kVm5dULof8+Fwr7L3s3LPHqa5+lEE5mHRqkxZ10FX3put481ySnknD7j8wvV9+cmvs4PbI5L Fg1PcPIq/2yoxFKckWioxVxUnAgAFTeBnD4CAAA= X-CMS-MailID: 20200409172533eucas1p252ed0cac1689b067a83589a0665c9033 X-Msg-Generator: CA X-RootMTR: 20200409172533eucas1p252ed0cac1689b067a83589a0665c9033 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172533eucas1p252ed0cac1689b067a83589a0665c9033 References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 06/13] app/test: add rte security session update tests X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add unit tests for rte_security_session_update function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 229 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index 3fc83abae..daaf30b62 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -238,6 +238,36 @@ mock_session_create(void *device, return mock_session_create_exp.ret; } +/** + * session_update mockup + * + * Verified parameters: device, sess, conf. + */ +static struct mock_session_update_data { + void *device; + struct rte_security_session *sess; + struct rte_security_session_conf *conf; + + int ret; + + int called; + int failed; +} mock_session_update_exp = {NULL, NULL, NULL, 0, 0, 0}; + +static int +mock_session_update(void *device, + struct rte_security_session *sess, + struct rte_security_session_conf *conf) +{ + mock_session_update_exp.called++; + + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, device); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, sess); + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_session_update_exp, conf); + + return mock_session_update_exp.ret; +} + /** * session_destroy mockup * @@ -278,6 +308,7 @@ struct rte_security_ops empty_ops = { NULL }; */ struct rte_security_ops mock_ops = { .session_create = mock_session_create, + .session_update = mock_session_update, .session_destroy = mock_session_destroy, }; @@ -300,6 +331,7 @@ static struct security_testsuite_params { /** * struct security_unittest_params defines parameters initialized * for every test case. The parameters are initialized in ut_setup + * or ut_setup_with_session (depending on the testcase) * and released in ut_teardown. * The instance of this structure is stored in unittest_params variable. */ @@ -368,9 +400,11 @@ ut_setup(void) ut_params->sess = NULL; mock_session_create_exp.called = 0; + mock_session_update_exp.called = 0; mock_session_destroy_exp.called = 0; mock_session_create_exp.failed = 0; + mock_session_update_exp.failed = 0; mock_session_destroy_exp.failed = 0; return TEST_SUCCESS; @@ -381,6 +415,7 @@ ut_setup(void) * created with rte_security_session_create and stored in test case parameters. * It's used both to release sessions created in test cases' bodies * which are assigned to ut_params->sess + * as well as sessions created in ut_setup_with_session. */ static int destroy_session_with_check(void) @@ -416,6 +451,46 @@ ut_teardown(void) destroy_session_with_check(); } +/** + * ut_setup_with_session initializes test case parameters by + * - calling standard ut_setup, + * - creating a session that can be used in test case. + */ +static int +ut_setup_with_session(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + struct security_testsuite_params *ts_params = &testsuite_params; + struct rte_security_session *sess; + + int ret = ut_setup(); + if (ret != TEST_SUCCESS) + return ret; + + mock_session_create_exp.device = NULL; + mock_session_create_exp.conf = &ut_params->conf; + mock_session_create_exp.mp = ts_params->session_mpool; + mock_session_create_exp.ret = 0; + + sess = rte_security_session_create(&ut_params->ctx, &ut_params->conf, + ts_params->session_mpool); + TEST_ASSERT_MOCK_FUNCTION_CALL_NOT_NULL(rte_security_session_create, + sess); + TEST_ASSERT_EQUAL(sess, mock_session_create_exp.sess, + "Expecting session_create to be called with %p sess" + " parameter, but it's called %p sess parameter", + sess, mock_session_create_exp.sess); + TEST_ASSERT_MOCK_CALLS(mock_session_create_exp, 1); + + /* + * Store created session in test case parameters, so it can be released + * after test case in ut_teardown by destroy_session_with_check. + */ + ut_params->sess = sess; + + return TEST_SUCCESS; +} + /** * Test functions @@ -642,6 +717,145 @@ test_session_create_success(void) } +/** + * rte_security_session_update tests + */ + +/** + * Test execution of rte_security_session_update with NULL instance + */ +static int +test_session_update_inv_context(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + int ret = rte_security_session_update(NULL, ut_params->sess, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update with invalid + * security operations structure (NULL) + */ +static int +test_session_update_inv_context_ops(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + ut_params->ctx.ops = NULL; + + int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update with empty + * security operations + */ +static int +test_session_update_inv_context_ops_fun(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + ut_params->ctx.ops = &empty_ops; + + int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -ENOTSUP, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update with NULL conf parameter + */ +static int +test_session_update_inv_configuration(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess, + NULL); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update with NULL sess parameter + */ +static int +test_session_update_inv_session(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + int ret = rte_security_session_update(&ut_params->ctx, NULL, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -EINVAL, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 0); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update when session_update + * security operation fails + */ +static int +test_session_update_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + mock_session_update_exp.device = NULL; + mock_session_update_exp.sess = ut_params->sess; + mock_session_update_exp.conf = &ut_params->conf; + mock_session_update_exp.ret = -1; /* Return failure status. */ + + int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, -1, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_session_update in successful execution path + */ +static int +test_session_update_success(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + + mock_session_update_exp.device = NULL; + mock_session_update_exp.sess = ut_params->sess; + mock_session_update_exp.conf = &ut_params->conf; + mock_session_update_exp.ret = 0; /* Return success status. */ + + int ret = rte_security_session_update(&ut_params->ctx, ut_params->sess, + &ut_params->conf); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_session_update, + ret, 0, "%d"); + TEST_ASSERT_MOCK_CALLS(mock_session_update_exp, 1); + + return TEST_SUCCESS; +} + + /** * Declaration of testcases */ @@ -667,6 +881,21 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_session_create_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_inv_configuration), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_inv_session), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_session_update_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Thu Apr 9 17:24:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 68070 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 20863A0597; Thu, 9 Apr 2020 19:26:48 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A9FC91D411; Thu, 9 Apr 2020 19:25:44 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 143631C43F for ; Thu, 9 Apr 2020 19:25:35 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172534euoutp01e441fb7940ff86a18caade9b09f98fe0~ENriCjyZS0657706577euoutp01X for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200409172534euoutp01e441fb7940ff86a18caade9b09f98fe0~ENriCjyZS0657706577euoutp01X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453134; bh=QqhM7SFSEoVaEdMEtC+Yi4ZZhSzv0A99gHzsJFwdofY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gT+yVZONEO1OIQnQW6JAfjunqc6axVaW6HXAjXjQy2FkozzFkT2ETxiKEKHe8dSyM GALddHnZmvhzd6uPJ7qe0zIdmfS+ttmxY4Q1JaOLULJ5jBOp8qMDFm5aU2LN3U6t4X zR9JBL2vYc07ivnMJZ1FTd/mrh2vuKsr2/Z5lLsw= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200409172534eucas1p2a16ee6de118626bb6c4d9d2f9496b1d5~ENrh58bqT2398523985eucas1p25 for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 62.50.60679.E8A5F8E5; Thu, 9 Apr 2020 18:25:34 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200409172534eucas1p2ee383bc5d8efd40ea8b883b78126ed9f~ENrhlVghu0369803698eucas1p2n for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172534eusmtrp1bee3c0c3f30441b0833d35a5b1cdf859~ENrhk137u2463624636eusmtrp1J for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-d9-5e8f5a8e862e Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id D4.48.07950.E8A5F8E5; Thu, 9 Apr 2020 18:25:34 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172534eusmtip171f7ea7802590ccd045d7c99837abede~ENrhS7Biq0978609786eusmtip1u for ; Thu, 9 Apr 2020 17:25:33 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:24:56 +0200 Message-Id: <20200409172502.1693-8-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFIsWRmVeSWpSXmKPExsWy7djP87p9Uf1xBgdvqVm8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGT27L7AVXNSoaDvWytjAeEypi5GTQ0LAROLSxUmMXYxcHEIC KxglHuz8B+W0M0m8W3qYCaRKSKCNSeLzDQWYjqdzOpkhipYzSjybsocFwgEq+rnwOytIFZuA rcSRmV/BbBEBFomV37+zgNjMAgISj+89A4sLC3hLLDz/ixHEZhFQlXh1vBMszivgIrFvzj1G iG3yEqs3HGAGsTkFXCVuHb8EtllCYA2bxJuVp5khilwkVj3+wgphCwMN2sIOYctInJ7cwwLR sI1R4urvn4wQzn5Gieu9K6CqrCUO//vN1sXIAXSepsT6XfogpoSAo8TexckQJp/EjbeCEPfz SUzaNp0ZIswr0dEmBDFDT+Jpz1RGmK1/1j5hgbA9JI7OAQUiKHwuM0o86brKMoFRfhbCrgWM jKsYxVNLi3PTU4uN8lLL9YoTc4tL89L1kvNzNzECY/j0v+NfdjDu+pN0iFGAg1GJh9eAoT9O iDWxrLgy9xCjBAezkgivd1NvnBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXFe40UvY4UE0hNLUrNT UwtSi2CyTBycUg2MKias9ZdrwvsdtM4HO3Ub1aisj955V02JpXlmAvsUT6Vtq7jfnZToPxj1 sH67+meNM3nHdBWMOs86Hn59r/XoKmU7Fk9TrgqOmvmuhw7dMVfzFXyzIVGskncyj6PXBcuN aquCa7NDjrbu3HE549EBY9UXvGfq9rruW7Pp5uHf03eynucpVm1QYinOSDTUYi4qTgQAKu6g Sd0CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrNLMWRmVeSWpSXmKPExsVy+t/xu7p9Uf1xBrc+C1q8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GT27L7AVXNSoaDvWytjAeEypi5GTQ0LAROLpnE7mLkYuDiGBpYwSNw8/Yu1i5ABKyEh8uCQA USMs8edaFxtETQuTxPz3X9hBEmwCthJHZn5lBbFFBFgkVn7/zgJiMwsISDy+9wwsLizgLbHw /C9GEJtFQFXi1fFOsDivgIvEvjn3GCEWyEus3nCAGcTmFHCVuHX8EpgtJFAvcbvrD+MERr4F jAyrGEVSS4tz03OLjfSKE3OLS/PS9ZLzczcxAgNq27GfW3Ywdr0LPsQowMGoxMNrwNAfJ8Sa WFZcmXuIUYKDWUmE17upN06INyWxsiq1KD++qDQntfgQoynQUROZpUST84HBnlcSb2hqaG5h aWhubG5sZqEkztshcDBGSCA9sSQ1OzW1ILUIpo+Jg1OqgdHlbJn0Ba89LI8T/wWsKXQUn/3z noXxxhme6cfZPOvqDxT9j2q1y7tp57OXYe+eAv3vno4/M9lFPOWeOblu35T3f9/MqQUrT94O /3bq6VZvLe/T/3c7t36e/+9ye0J08TZNE9GDvaEsCZLXRD5s/J6zyVHvwp3JU544Za1y7rkh GmTk27aZtVOJpTgj0VCLuag4EQC/oECVPgIAAA== X-CMS-MailID: 20200409172534eucas1p2ee383bc5d8efd40ea8b883b78126ed9f X-Msg-Generator: CA X-RootMTR: 20200409172534eucas1p2ee383bc5d8efd40ea8b883b78126ed9f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172534eucas1p2ee383bc5d8efd40ea8b883b78126ed9f References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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 Thu Apr 9 17:24:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 68071 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 DB21CA0597; Thu, 9 Apr 2020 19:26:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 010391D418; Thu, 9 Apr 2020 19:25:46 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id D94691C437 for ; Thu, 9 Apr 2020 19:25:35 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172535euoutp028695180a251d15b8539bee62f4d7506d~ENri1vdtd2096020960euoutp02j for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200409172535euoutp028695180a251d15b8539bee62f4d7506d~ENri1vdtd2096020960euoutp02j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453135; bh=acA+ii0yOmD1r+6N7MuYyRPvxP2ro9kXIxZa9EtWUq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tsx6aCSSYnSO9oAvOiAfQTugJ7UP6NaJdiuutwjD6hMXKupNgYojDsEQCFDly0s6n wpclchC2FJaUVDO0fWowURSPcery/xwgOw+pDZOq9xumUlATBg55oDZ4w/MqCc47S4 wpvOZV49WCbbyTj1bdkdWxnofeVJ7ECuy2IlsVcw= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200409172535eucas1p23dd5f75264f146bbd0c1ac7d366f4380~ENrinqmks0369803698eucas1p2o for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id F3.F2.61286.F8A5F8E5; Thu, 9 Apr 2020 18:25:35 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200409172534eucas1p2852ae56687fd5bae343437b07198c070~ENrh-zb3t2381823818eucas1p2- for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172534eusmtrp1a3a2fa212b5a0eae301aed532a02bec0~ENrh-V7Mh2463624636eusmtrp1K for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-37-5e8f5a8f27cb Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id EC.B9.08375.E8A5F8E5; Thu, 9 Apr 2020 18:25:34 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172534eusmtip15054d345eda775610733ae487cd42248~ENrhsDg5f0696806968eusmtip1U for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:24:57 +0200 Message-Id: <20200409172502.1693-9-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJIsWRmVeSWpSXmKPExsWy7djP87r9Uf1xBm0dIhbvPm1ncmD0+LVg KWsAYxSXTUpqTmZZapG+XQJXxpxdn5gKJphWHLr0j6WB8ZBuFyMnh4SAicSCCd+ZQWwhgRWM EvdfG3cxcgHZ7UwS0160MEI4bUwS85rmMsN0zHh9kAkisZxR4s6yd6xwVbMe3GcEqWITsJU4 MvMrK4gtIsAisfL7dxYQm1lAQOLxvWdgcWEBH4l5DVfAbBYBVYml27uBbA4OXgEXidN36iGW yUus3nAAbDGngKvEreOXmEF2SQisYJM43HgV6iIXieb/7VC2sMSr41vYIWwZidOTe1ggGrYx Slz9/ZMRwtnPKHG9dwVUlbXE4X+/2UA2MwtoSqzfpQ8RdpS42/qZHSQsIcAnceOtIMT9fBKT tk1nhgjzSnS0CUFU60k87ZnKCLP2z9onLBAlHhIn14RBgucyo8TH1UsZJzDKz0LYtYCRcRWj eGppcW56arFhXmq5XnFibnFpXrpecn7uJkZgBJ/+d/zTDsavl5IOMQpwMCrx8Bow9McJsSaW FVfmHmKU4GBWEuH1buqNE+JNSaysSi3Kjy8qzUktPsQozcGiJM5rvOhlrJBAemJJanZqakFq EUyWiYNTqoHRtXWF8bMzHObVrvs/q932W8qvs+LPAqHbUVP3h8lcMvDnWHX4S+DsbjXzD2Jf LN74SH6VZLbOi+P4PNE1/PiNWk5rzikrzklf2Pkj4e1MSe+uLMaTad+y4mVXmm79VKDDz/2S J+pD+SMx37Z6KaXa2lJvdz+R8zy+65+bb3/J97PjnFCSjIkSS3FGoqEWc1FxIgC/JYrP3AIA AA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7p9Uf1xBvuX6Fi8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GXN2fWIqmGBacejSP5YGxkO6XYycHBICJhIzXh9k6mLk4hASWMoosbN7GmsXIwdQQkbiwyUB iBphiT/XutggalqYJCasOs4EkmATsJU4MvMrK4gtIsAisfL7dxYQm1lAQOLxvWdgcWEBH4l5 DVfAbBYBVYml27vB5vMKuEicvlMPMV9eYvWGA8wgNqeAq8St45fAbCGBeonbXX8YJzDyLWBk WMUoklpanJueW2yoV5yYW1yal66XnJ+7iREYTtuO/dy8g/HSxuBDjAIcjEo8vAYM/XFCrIll xZW5hxglOJiVRHi9m3rjhHhTEiurUovy44tKc1KLDzGaAt00kVlKNDkfGOp5JfGGpobmFpaG 5sbmxmYWSuK8HQIHY4QE0hNLUrNTUwtSi2D6mDg4pRoYxYQemyU8mci/eXVosOTEXZMeTjq9 64LRiUNntzNf3/PVf/ObixuzmziaVuQn3Wuvn65jnGb3Su5T/T4TBSF5oWmcJ52mrl5Yby6f 7Kp4weVhccyK2V6Jn3Y+WMlftKt5TpLbiaZiN1Px2+VpwhJ1PYYWjvHBq6Qj9vPWlX1iNNnd JDVdc1OgEktxRqKhFnNRcSIAHEK6Vj0CAAA= X-CMS-MailID: 20200409172534eucas1p2852ae56687fd5bae343437b07198c070 X-Msg-Generator: CA X-RootMTR: 20200409172534eucas1p2852ae56687fd5bae343437b07198c070 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172534eucas1p2852ae56687fd5bae343437b07198c070 References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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 Thu Apr 9 17:24:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 68072 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 5E162A0597; Thu, 9 Apr 2020 19:27:05 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 50E791D41D; Thu, 9 Apr 2020 19:25:47 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 5B93A1D152 for ; Thu, 9 Apr 2020 19:25:36 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172536euoutp025dd32a307cc0808d24088adff8618a62~ENrjT32H32229522295euoutp02J for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200409172536euoutp025dd32a307cc0808d24088adff8618a62~ENrjT32H32229522295euoutp02J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453136; bh=igxkj1rh0eTu9I7h5X2CfjMMhnmGhIJ6tYnNcUVR9fk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=up54j6Sb6hWC84cUB5mcXXWGL7tgQZjGmuDs3Py/G7swc7R+akhwXheIfuAJdsS9Z +yueyuG9qvF92+2wRmmpVptrfRFynvWvUW6l6aCTI1IRptPGMtmfDHk4ToaXkvphH+ SPWWnQ+ES7T4mm8Z4bkrpt5slZIvtB9CXpjMpAiQ= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200409172535eucas1p24b523894175c6cde11693ac9ef0d4fa6~ENrjBjbPy0369803698eucas1p2q for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 82.50.60679.F8A5F8E5; Thu, 9 Apr 2020 18:25:35 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200409172535eucas1p152b3d17bd9d2194f9f2669116130331d~ENriVtq7J2193421934eucas1p1G for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172535eusmtrp118732d4df1fcc1ee03b03fd08b6d8ddb~ENriVPsJH2463624636eusmtrp1M for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-db-5e8f5a8fa146 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 2D.B9.08375.F8A5F8E5; Thu, 9 Apr 2020 18:25:35 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172534eusmtip12b2ccc658c6fb3d7f43709c51367db56~ENriEf5QQ0971609716eusmtip1W for ; Thu, 9 Apr 2020 17:25:34 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:24:58 +0200 Message-Id: <20200409172502.1693-10-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFIsWRmVeSWpSXmKPExsWy7djPc7r9Uf1xBh3/jC3efdrO5MDo8WvB UtYAxigum5TUnMyy1CJ9uwSujM5bG5kKmnUqZq76xtTA+EO1i5GDQ0LARGLVUpcuRi4OIYEV jBLL9jxjhHDamSQat31mhnDamCS+P3zE1MXICdYxfck+JojEckaJG+euIVQ1fPjOCFLFJmAr cWTmV1YQW0SARWLl9+8sIDazgIDE43vPwOLCAl4SRzccYAa5g0VAVWLSphSQMK+Aq8S1Wy+Z IZbJS6wGK+Hk4ASK3zp+CWyXhMAKNonPy68zQhS5SLw9sA/qOmGJV8e3sEPYMhKnJ/ewQDRs Y5S4+vsnI4Szn1Hieu8KqCpricP/frOBXMEsoCmxfpc+RNhR4sOsQ8yQQOKTuPFWEOJ+PolJ 26ZDhXklOtqEIKr1JJ72TGWEWftn7RMWCNtDYt7Oa+yQ8LnMKLF32mzGCYzysxCWLWBkXMUo nlpanJueWmyUl1quV5yYW1yal66XnJ+7iREYw6f/Hf+yg3HXn6RDjAIcjEo8vAYM/XFCrIll xZW5hxglOJiVRHi9m3rjhHhTEiurUovy44tKc1KLDzFKc7AoifMaL3oZKySQnliSmp2aWpBa BJNl4uCUamA0uXpvqoPx+YlVO4u+vimdrKxy7qpz0dqibTYTZml+c3yUvexqxtLT1tNutn7P 3vnrysyXe+UVu4v4nY53pX1i7hI6vNHEhP8U9+3wLdLb7BKYNsd5b5BIMdMKXvfrmd+tjoiP zPeu1r/pmZTWMFPtS/2RM9rfbPOPn/9bePmScDTDDgPflO4YJZbijERDLeai4kQAJn8Sh90C AAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7r9Uf1xBs9+sVu8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GZ23NjIVNOtUzFz1jamB8YdqFyMnh4SAicT0JfuYuhi5OIQEljJK7Jj2CcjhAErISHy4JABR Iyzx51oXG0RNC5PEklcr2UASbAK2EkdmfmUFsUUEWCRWfv/OAmIzCwhIPL73DCwuLOAlcXTD AWaQmSwCqhKTNqWAhHkFXCWu3XrJDDFfXmI1WAknBydQ/NbxS2C2kEC9xO2uP4wTGPkWMDKs YhRJLS3OTc8tNtQrTswtLs1L10vOz93ECAynbcd+bt7BeGlj8CFGAQ5GJR5eA4b+OCHWxLLi ytxDjBIczEoivN5NvXFCvCmJlVWpRfnxRaU5qcWHGE2BbprILCWanA8M9bySeENTQ3MLS0Nz Y3NjMwslcd4OgYMxQgLpiSWp2ampBalFMH1MHJxSDYyWEhd9b6ucPHG8KDj1eXpJtsS+CbEv WdS+Bqb2f9/fcXfTqde5d9rPCQpUebOmxMXcnbTp4/c0FfvG9EP8G6vvma5o9LvSIMPyOfPO J819Uh4ROa0nlz6J/GLbu17nfDYrd5LuXc5Qtoh1Xyt5ko199ivLqJtPE0t8uurhOq9tr2dI m+c1fFRiKc5INNRiLipOBADEDSAMPQIAAA== X-CMS-MailID: 20200409172535eucas1p152b3d17bd9d2194f9f2669116130331d X-Msg-Generator: CA X-RootMTR: 20200409172535eucas1p152b3d17bd9d2194f9f2669116130331d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172535eucas1p152b3d17bd9d2194f9f2669116130331d References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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 Thu Apr 9 17:24:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 68073 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 2A5E4A0597; Thu, 9 Apr 2020 19:27:17 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CD6861D423; Thu, 9 Apr 2020 19:25:48 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 507311D14E for ; Thu, 9 Apr 2020 19:25:36 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172536euoutp012f91f2da493001fb58ca7590fe329876~ENrjQHxKz0867408674euoutp01A for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200409172536euoutp012f91f2da493001fb58ca7590fe329876~ENrjQHxKz0867408674euoutp01A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453136; bh=QzLzQkIIUAfM+0w3FM/J8GqPFXwYKon9p78YLKE8q2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F/7NHvmrSFgm5OpyAIuQVcCHdRjVzRUFtBr44DUefjOlTXobPzCUdmhO4KbH9TQBX KluoqgMKDW0stcXwWiweD3Ox6epg9YIiFj6KEuIw0ZOeS8ksiHYAwo9WmA2P2R+8tz qqrlH1nQiV95lA5H1dlz0zrniUYC+E+Qm70aESHU= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200409172535eucas1p1c267aaf9538331d2ccebf8bd4cd6ad37~ENrjHdp890986409864eucas1p10 for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id A2.50.60679.F8A5F8E5; Thu, 9 Apr 2020 18:25:35 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200409172535eucas1p2c215489de77c708fc0bec6b9e2e3dd6d~ENriy00nG1612816128eucas1p2G for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172535eusmtrp1f1715c1cbccf0bf660787c704a21727a~ENriyVApI2463624636eusmtrp1N for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) X-AuditID: cbfec7f4-0cbff7000001ed07-dc-5e8f5a8fefad Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id F4.48.07950.F8A5F8E5; Thu, 9 Apr 2020 18:25:35 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172535eusmtip1004175d246becc1d20bd308938d163fe~ENrid2CdO0977009770eusmtip1i for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:24:59 +0200 Message-Id: <20200409172502.1693-11-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJIsWRmVeSWpSXmKPExsWy7djP87r9Uf1xBgueWlm8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGUe+FBUst6j4fv0MUwPjO/0uRk4OCQETiU/z25m7GLk4hARW MErc7ZrBCOG0M0msW7GABcJpY5KYeXkdUxcjB1jL6r/REPHljBIL3l1jhitq+drIBjKXTcBW 4sjMr6wgtogAi8TK799ZQGxmAQGJx/eegcWFBbwlNrW2gtksAqoSV849B6vhFXCVOPvgLQvE ffISqzccYAaxOYHit45fAlsmIbCETWLdhXYWiItcJKbtj4OoF5Z4dXwLO4QtI3F6cg8LRP02 Romrv38yQjj7GSWu966AqrKWOPzvNxvIIGYBTYn1u6AB4yjRf2QWG8R8PokbbwUh7ueTmLRt OjNEmFeio00IolpP4mnPVEaYtX/WPoE630Pi8K3r7JDwucwocXPeR6YJjPKzEJYtYGRcxSie Wlqcm55abJSXWq5XnJhbXJqXrpecn7uJERjBp/8d/7KDcdefpEOMAhyMSjy8Bgz9cUKsiWXF lbmHGCU4mJVEeL2beuOEeFMSK6tSi/Lji0pzUosPMUpzsCiJ8xovehkrJJCeWJKanZpakFoE k2Xi4JRqYAxUYOC6/bO0r9H9upb2tJTFnZE/d54692TFmmfhHFlzV3pPz3AUT1Xtu9FduLOo 7S1r5uUO4bUXjhroumk3sf/cvr/jR3tA2KIPl8XqatVORaxyeJFtayjAH2xVeEyHZa2Vz6xt XW3Tly95Mu2kDdP6jzdZvM0jNsgzu3178zb4+IzzDow77imxFGckGmoxFxUnAgD93KKS3AIA AA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJLMWRmVeSWpSXmKPExsVy+t/xu7r9Uf1xBlM+Klm8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GUe+FBUst6j4fv0MUwPjO/0uRg4OCQETidV/o7sYuTiEBJYySmx4fIgVIi4j8eGSQBcjJ5Ap LPHnWhcbRE0Lk8T3GVtYQBJsArYSR2Z+ZQWxRQRYJFZ+/w4WZxYQkHh87xlYXFjAW2JTayuY zSKgKnHl3HOwGl4BV4mzD96yQCyQl1i94QAziM0JFL91/BKYLSRQL3G76w/jBEa+BYwMqxhF UkuLc9Nzi430ihNzi0vz0vWS83M3MQKDaduxn1t2MHa9Cz7EKMDBqMTDa8DQHyfEmlhWXJl7 iFGCg1lJhNe7qTdOiDclsbIqtSg/vqg0J7X4EKMp0FETmaVEk/OBgZ5XEm9oamhuYWlobmxu bGahJM7bIXAwRkggPbEkNTs1tSC1CKaPiYNTqoFxbezaV4Ly1cF7wrusW0Jey67ac/e36f5W bzdJh9lTrUtf3j+eV7crT+zS6r8pK95ciZh2RNB+/UQpZdWqzAPqK16pX5nDWsObqGLhOO/D Vr+aTatTzQTVJxx5JLLi4FHVS7KLZlo2N0xc/M7garhmVdfWVU6Zxx9pyX04oi+w45L+48ZF hRw1SizFGYmGWsxFxYkAs+e77zwCAAA= X-CMS-MailID: 20200409172535eucas1p2c215489de77c708fc0bec6b9e2e3dd6d X-Msg-Generator: CA X-RootMTR: 20200409172535eucas1p2c215489de77c708fc0bec6b9e2e3dd6d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172535eucas1p2c215489de77c708fc0bec6b9e2e3dd6d References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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..193ab2ba9 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_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_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_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_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 Thu Apr 9 17:25:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 68074 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 E3DA0A0597; Thu, 9 Apr 2020 19:27:25 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 297F91D428; Thu, 9 Apr 2020 19:25:50 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 126E81D152 for ; Thu, 9 Apr 2020 19:25:37 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172536euoutp0121cfd6bd344f088ec147f8e78749daaa~ENrj9wYct0978309783euoutp01u for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200409172536euoutp0121cfd6bd344f088ec147f8e78749daaa~ENrj9wYct0978309783euoutp01u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453136; bh=VBX15qrJrVOvkAVv2EZtrvyLR1nuCRIAyYS5gjixiDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hoIotLdd7Dse3DQgcOPgb+NHqt8IYIbmzwY3qQ8JABsuYxHVLXJFVO+DIhj4Zunt5 VszpG+s15gG4xpMJwD5hohN7jed/zRh7L9n5KAp4gc8VN7eC3SRUw02CBsz6NSOPov aaeTzvFhmrowDFoi+i19aEfiAiEyIr5buVw6t8Gw= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200409172536eucas1p2a145c3adbf0472bf007692af93a79a4c~ENrjxL1Q80102601026eucas1p2E for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id C2.50.60679.09A5F8E5; Thu, 9 Apr 2020 18:25:36 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200409172536eucas1p282854dae8a3b6cceafdea5e2f4fa0896~ENrjQmXFU1612816128eucas1p2H for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172536eusmtrp19e2e85ab83dfac27f60629033cae0e87~ENrjQGY0E2463624636eusmtrp1O for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-dd-5e8f5a9048bd Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 15.48.07950.F8A5F8E5; Thu, 9 Apr 2020 18:25:36 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172535eusmtip1167b2fee9fff17199151e132afa7dbb6~ENri4wcCj0696506965eusmtip1S for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:25:00 +0200 Message-Id: <20200409172502.1693-12-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNIsWRmVeSWpSXmKPExsWy7djPc7oTovrjDC4vUbN492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4Mj79CSxotK7Ys3sZcwPjMsMuRk4OCQETiaYFP9m7GLk4hARW MEos+bqeFcJpZ5KYOu8kC4TTxiRx4PY8VpiWWasboFqWM0oc2n2HDa7qx99vbCBVbAK2Ekdm fgXrEBFgkVj5/TsLiM0sICDx+N4zsLiwgLvEpubtYDaLgKpEe8NyRhCbV8BV4viUZjaIbfIS qzccYAaxOYHit45fYgZZJiGwhE3i3OE57BBFLhIt398yQdjCEq+Ob4GKy0icntzDAtGwjVHi 6u+fjBDOfkaJ670roKqsJQ7/+w20jgPoPE2J9bv0IcKOEstWzwILSwjwSdx4KwjxAJ/EpG3T mSHCvBIdbUIQ1XoST3umMsKs/bP2CQuE7SExc8V0aABdZpToOPuCcQKj/CyEZQsYGVcxiqeW FuempxYb5aWW6xUn5haX5qXrJefnbmIERvHpf8e/7GDc9SfpEKMAB6MSD68BQ3+cEGtiWXFl 7iFGCQ5mJRFe76beOCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8xotexgoJpCeWpGanphakFsFk mTg4pRoYhWdcshItmfKr1+uE+fcNb/7YyWakXpu5wjvyu3vBrNNNpyZ8XBxTOKEzqGLuztDn Tw6IBSbZWzFx7Lsnv+mq7Htr017bOS92bUjb8vZdjcPPLK2HpjUm+3WenYp6mLD6wqE4Yab1 +93falduZvXhMjr0aMEkniy35njzJYeVV++1YznneujmUiWW4oxEQy3mouJEAIT9D6PeAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJLMWRmVeSWpSXmKPExsVy+t/xu7oTovrjDC6cZbR492k7kwOjx68F S1kDGKP0bIryS0tSFTLyi0tslaINLYz0DC0t9IxMLPUMjc1jrYxMlfTtbFJSczLLUov07RL0 Mj79CSxotK7Ys3sZcwPjMsMuRk4OCQETiVmrG9i7GLk4hASWMkrsmNQM5HAAJWQkPlwSgKgR lvhzrYsNxBYSaGGS+HIyG8RmE7CVODLzKyuILSLAIrHy+3cWEJtZQEDi8b1nYHFhAXeJTc3b wWwWAVWJ9obljCA2r4CrxPEpzWwQ8+UlVm84wAxicwLFbx2/xAyxq17idtcfxgmMfAsYGVYx iqSWFuem5xYb6RUn5haX5qXrJefnbmIEBtO2Yz+37GDsehd8iFGAg1GJh9eAoT9OiDWxrLgy 9xCjBAezkgivd1NvnBBvSmJlVWpRfnxRaU5q8SFGU6CjJjJLiSbnAwM9ryTe0NTQ3MLS0NzY 3NjMQkmct0PgYIyQQHpiSWp2ampBahFMHxMHp1QD45KHK+/oHHvy8LXkOuHVxctlNsx5qZBf fChlwZFZMbUMWv1L9V4rmKleNDpWMPXi/aPaGdufHy28fOV3qw2n4+H5DmXCO7rjPeQKjskl bOz4I/6+hzfbX+qioa7jLPPXqVHKDyV3by1K2Fet9/SsxTYm+Qd1+5e2T6m9miCdWFtbmB26 /MS5/0osxRmJhlrMRcWJAEUlusY8AgAA X-CMS-MailID: 20200409172536eucas1p282854dae8a3b6cceafdea5e2f4fa0896 X-Msg-Generator: CA X-RootMTR: 20200409172536eucas1p282854dae8a3b6cceafdea5e2f4fa0896 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172536eucas1p282854dae8a3b6cceafdea5e2f4fa0896 References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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 193ab2ba9..53b9e122e 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_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_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_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 Thu Apr 9 17:25:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 68075 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 46C82A0597; Thu, 9 Apr 2020 19:27:35 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6C4F41D443; Thu, 9 Apr 2020 19:25:51 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 7D08E1D152 for ; Thu, 9 Apr 2020 19:25:37 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172537euoutp0209625418feb6792eb2979c34e0bf40ea~ENrkXbeaA2229522295euoutp02K for ; Thu, 9 Apr 2020 17:25:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200409172537euoutp0209625418feb6792eb2979c34e0bf40ea~ENrkXbeaA2229522295euoutp02K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453137; bh=bbaULdOoK7Yqq1zoQqLeE0AbsAwWKDjSXHli5Qu5bes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=buaryCoSemCltSbBIHzZqnByQPYp98cBXV4mS/ZSkTJFjUhCEJfeh2oHOvJWZlK5h zqweG2KLbD/Yxd6wmxn+Bn87btDTr/DTR8TaUXWBG//5SJJtchtTIEhgYOcqtZE4cs iZXPTXpJb4H8C8jpxeqg08fM824xv67AA5oehA8E= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200409172536eucas1p29d87b1885c875b91678dfea59c1022f4~ENrj7Our10369803698eucas1p2s for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id D4.F2.61286.09A5F8E5; Thu, 9 Apr 2020 18:25:36 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200409172536eucas1p1396c04fb7a9fb80db2a5670f8f3453bb~ENrjochmm2198621986eucas1p16 for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172536eusmtrp15a0dcf736a19fe726700682e150549b7~ENrjn_UFe2463624636eusmtrp1P for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) X-AuditID: cbfec7f2-f0bff7000001ef66-3a-5e8f5a9012c3 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 35.48.07950.09A5F8E5; Thu, 9 Apr 2020 18:25:36 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172536eusmtip1cbbc78d6a18a6b61941a1cfa7b34eceb~ENrjUEhbK0978609786eusmtip1v for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:25:01 +0200 Message-Id: <20200409172502.1693-13-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNIsWRmVeSWpSXmKPExsWy7djP87oTovrjDD6+1rN492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4Mg6cjShYrl0xv20nUwPjN5UuRk4OCQETiYOtixi7GLk4hARW MEqc/bYRymlnklj+8CM7hNPGJLH3SC8zTEvv/JVsEInljBI/t3axwlX1n/jPBlLFJmArcWTm V1YQW0SARWLl9+8sIDazgIDE43vPwOLCAt4Sz/YdZgSxWQRUJV4euw7WyyvgKrGqfwYjxDZ5 idUbDoBt5gSK3zp+iRlkmYTACjaJU3d2sEAUuUg07T0AdZ6wxKvjW9ghbBmJ05N7WCAatjFK XP39kxHC2c8ocb13BVSVtcThf7+BVnMAnacpsX6XPkTYUeLcr+tgYQkBPokbbwUhHuCTmLRt OjNEmFeio00IolpP4mnPVEaYtX/WPoE6zUNi1adN0AC6zCjx7s5XxgmM8rMQli1gZFzFKJ5a WpybnlpsmJdarlecmFtcmpeul5yfu4kRGMWn/x3/tIPx66WkQ4wCHIxKPLwGDP1xQqyJZcWV uYcYJTiYlUR4vZt644R4UxIrq1KL8uOLSnNSiw8xSnOwKInzGi96GSskkJ5YkpqdmlqQWgST ZeLglGpgTL/+K+L3F+6tv9e0+B0Ve5pz/f7SY11Lq62lZy/Uf6D/vff3GsYUPZv5hUYOHi0z 2MwO21yYu+Jezb1lDvpat+auXlCsurGEW3L6qzUehxwnRc/nnvfxX+L8y+lTD2tvUV+h/OER y6Ok05n2Sye0G8ru1X1Q7jv57UctlbcHNsn7HTo4ecZp/utKLMUZiYZazEXFiQBN1dQB3gIA AA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7oTovrjDJp3y1i8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GQfORhQs166Y37aTqYHxm0oXIyeHhICJRO/8lWxdjFwcQgJLGSWaJq5k7mLkAErISHy4JABR Iyzx51oXVE0Lk8SqlbeYQBJsArYSR2Z+ZQWxRQRYJFZ+/84CYjMLCEg8vvcMLC4s4C3xbN9h RhCbRUBV4uWx62wgNq+Aq8Sq/hmMEAvkJVZvOMAMYnMCxW8dvwRmCwnUS9zu+sM4gZFvASPD KkaR1NLi3PTcYiO94sTc4tK8dL3k/NxNjMBw2nbs55YdjF3vgg8xCnAwKvHwGjD0xwmxJpYV V+YeYpTgYFYS4fVu6o0T4k1JrKxKLcqPLyrNSS0+xGgKdNREZinR5HxgqOeVxBuaGppbWBqa G5sbm1koifN2CByMERJITyxJzU5NLUgtgulj4uCUamA85vNh1RFBjp2WT91OXJtcl+Vse23t OYOPHx5wS1x93OmXZsC25oCKoI+wsKN5hXJpXWrB3Mddwh/9FGY38sSZ3mGoNKspvq+4+M0n ho7lydwHt8SwP4h4lhbQvnDeqxMPv8muOTCj1vzFjeDtfgVzxew+r1vR+qAkb3ltvIbbkylK mdc37DuvxFKckWioxVxUnAgAHMXLLz0CAAA= X-CMS-MailID: 20200409172536eucas1p1396c04fb7a9fb80db2a5670f8f3453bb X-Msg-Generator: CA X-RootMTR: 20200409172536eucas1p1396c04fb7a9fb80db2a5670f8f3453bb X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172536eucas1p1396c04fb7a9fb80db2a5670f8f3453bb References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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 53b9e122e..3570da2a2 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 Thu Apr 9 17:25:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 68076 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 56299A0597; Thu, 9 Apr 2020 19:27:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B982B1D449; Thu, 9 Apr 2020 19:25:52 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id CB3751D177 for ; Thu, 9 Apr 2020 19:25:38 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172538euoutp01752e13adc665925f82ef8752088622a0~ENrlmc3lL0866708667euoutp01E for ; Thu, 9 Apr 2020 17:25:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200409172538euoutp01752e13adc665925f82ef8752088622a0~ENrlmc3lL0866708667euoutp01E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453138; bh=e+nN2F7pjxRemqf/4p1ZpdSGaP5iAfaCW/Lw8vlpY/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cc2QQ/XAj8wGsnJK0ruBwRryPeT7FpUZk+POvKu2GToq+MPUjyOIv1WptDBx0XcNS vgbJHXVQlIMFQQFOmMNbj0fSgFKoHsNzljQ/G7+JUGDLOjV2dLpEslUtGhqE7iJnRz yCpIaGoON1nJ+W1PdzSjvMvJxUTvnh1vkA+U1crU= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200409172538eucas1p14259446a1cb38c14f73773b015694b48~ENrlZJoZ40986309863eucas1p1s for ; Thu, 9 Apr 2020 17:25:38 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 66.71.60698.29A5F8E5; Thu, 9 Apr 2020 18:25:38 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200409172538eucas1p1dcd99eeedf6fca44c2e2e53e94b08d91~ENrlElAdF0986309863eucas1p1r for ; Thu, 9 Apr 2020 17:25:38 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172538eusmtrp1a82acb22239342b7695af4278d66d647~ENrlEG5yO2463624636eusmtrp1U for ; Thu, 9 Apr 2020 17:25:38 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-90-5e8f5a922b04 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id AE.B9.08375.19A5F8E5; Thu, 9 Apr 2020 18:25:38 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172536eusmtip10a91d71efee01c49a13349aa34c0f9f3~ENrjrfXMF1119111191eusmtip1I for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:25:02 +0200 Message-Id: <20200409172502.1693-14-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNIsWRmVeSWpSXmKPExsWy7djPc7qTovrjDDZsFbZ492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4Mu6s2sxcsKKVseLio1nsDYz/C7oYOTkkBEwkJh++xdLFyMUh JLCCUeLRnR9sEE47k8St2+vYQaqEBNqYJDY+tOti5ADruPnMGKJmOaPEu+bTrBAOUM2jnZuZ QBrYBGwljsz8ygpiiwiwSKz8/p0FxGYWEJB4fO8ZWFxYwFNi7sNJYAtYBFQlXs3fwwhi8wq4 SryacYER4jx5idUbDjCD2JxA8VvHLzGDLJMQWMEmMXNfJztEkYtE/6L1zBC2sMSr41ug4jIS pyf3sEA0bGOUuPr7JyOEs59R4nrvCqgqa4nD/36zgfzGLKApsX6XPkTYUWLPugZmiJf5JG68 FYR4gE9i0rbpUGFeiY42IYhqPYmnPVMZYdb+WfuEBcL2kNj15zEjJIAuM0pcfvGWeQKj/CyE ZQsYGVcxiqeWFuempxYb56WW6xUn5haX5qXrJefnbmIERvHpf8e/7mDc9yfpEKMAB6MSD28H U3+cEGtiWXFl7iFGCQ5mJRFe76beOCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8xotexgoJpCeW pGanphakFsFkmTg4pRoYfVgMS43enYtqtdHdmPA+ScTxiZ71sdV1S05NUTvw7cCV159ftYSe LNWY/kVw5yPDB9fvR8lolRulZXBVWFicyJXp3Gybp79zOluiNi/nvV3/b1+7bZ12fbtbvYDz 4QUF07nUV3GnZ/5ffXAPf7t5gVlNuPeeaeekJyTnXfl1aMG0hIR7zhP6lViKMxINtZiLihMB /DiJON4CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xu7qTovrjDBbUW7z7tJ3JgdHj14Kl rAGMUXo2RfmlJakKGfnFJbZK0YYWRnqGlhZ6RiaWeobG5rFWRqZK+nY2Kak5mWWpRfp2CXoZ d1ZtZi5Y0cpYcfHRLPYGxv8FXYwcHBICJhI3nxl3MXJxCAksZZS43rCBDSIuI/HhkkAXIyeQ KSzx51oXG0RNC5PEjl0rGUESbAK2EkdmfmUFsUUEWCRWfv/OAmIzCwhIPL73DCwuLOApMffh JHYQm0VAVeLV/D1gvbwCrhKvZlxghFggL7F6wwFmEJsTKH7r+CUwW0igXuJ21x/GCYx8CxgZ VjGKpJYW56bnFhvqFSfmFpfmpesl5+duYgSG07ZjPzfvYLy0MfgQowAHoxIPrwFDf5wQa2JZ cWXuIUYJDmYlEV7vpt44Id6UxMqq1KL8+KLSnNTiQ4ymQEdNZJYSTc4HhnpeSbyhqaG5haWh ubG5sZmFkjhvh8DBGCGB9MSS1OzU1ILUIpg+Jg5OqQbG/OdpIpzWi5bP7updNe/PRYab5hO3 dDXP38f5/fWeado2PyJ1lP58X7r/ZvDRBEfJgv4s64e2P4W8fhanbmFQ0/puX8Bu9XNCTZLd 4xNXnU7mSXR/iO5+Ys5gvPnfqa9PPVgksk7UVx81jpC7tyklQu73O+3YL1NSP4fUF3UlS5Yv Zkln+nNFiaU4I9FQi7moOBEA0SeE/T0CAAA= X-CMS-MailID: 20200409172538eucas1p1dcd99eeedf6fca44c2e2e53e94b08d91 X-Msg-Generator: CA X-RootMTR: 20200409172538eucas1p1dcd99eeedf6fca44c2e2e53e94b08d91 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172538eucas1p1dcd99eeedf6fca44c2e2e53e94b08d91 References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 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 3570da2a2..724ce56f4 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 */ } };