From patchwork Thu Mar 12 15:16:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 66591 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 0753BA056D; Thu, 12 Mar 2020 16:17:33 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7D8201C02C; Thu, 12 Mar 2020 16:17:14 +0100 (CET) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id D44E51BFBF for ; Thu, 12 Mar 2020 16:17:09 +0100 (CET) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151709euoutp01c0bcad4af48d056638be5b759809f7a7~7l3Z4eESR0471204712euoutp01F for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200312151709euoutp01c0bcad4af48d056638be5b759809f7a7~7l3Z4eESR0471204712euoutp01F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026229; bh=FBIjnB53Kv79V96klEGMOMPGn+YQdKjlGAkns8pOWII=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JlEELGuJ/rPok3ZXQwBH0mJXu5YC/ebZyTcgyhlmuGK3f+5dejv7Vs6fdH19neBqb uA3zRReFp5HFautovLh1r6qxeXcvxbVKyGnXp4X1xS5Ix2zVy5g113Tn2ESe91Uyvh U1I1FSEieA6NqHIrv5L5PGPmApUse9kzVt/2bU1k= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200312151708eucas1p1148720a7b0cfd75b33e7672ec552ceaa~7l3Zypwy31595115951eucas1p1c for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 4A.B9.60698.4725A6E5; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200312151708eucas1p2acee543b5f9d236b8e43cd4d1fbed489~7l3ZJnZch1644416444eucas1p2y for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151708eusmtrp25661d89ce27ea885d280eb38fee10b37~7l3ZJI_Rw1238312383eusmtrp2G for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-a1-5e6a527446e1 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 31.3F.08375.4725A6E5; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151708eusmtip140b4fd4f8e0ca59ec353ac9c84c4585d~7l3Y8-2xU1532415324eusmtip1Q for ; Thu, 12 Mar 2020 15:17:07 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:42 +0100 Message-Id: <20200312151654.7218-2-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrHIsWRmVeSWpSXmKPExsWy7djP87olQVlxBv1zlS3efdrO5MDo8WvB UtYAxigum5TUnMyy1CJ9uwSujIuXPzMWfDOouDc5vYGxXauLkZNDQsBE4u/HM+xdjFwcQgIr GCXe3D7KCuG0M0kseDafEcJpY5JY++wrUIYDrOX0dFOI+HJGiVsXH7LDdbw5PoEVZC6bgK3E kZlfwWwRAQGJz52L2UBsYQE3iQ03N4PZLAKqEvNWnwezeQVcJA497meHuEleYvWGA8wgNqeA q8SNSc/BTpIQmMEmsePobUaIIheJFY0XmCFsYYlXx7dANctI/N85nwmioZ9RYu+/t+xQ3YwS qy/PYoKospY4/O83G8g/zAKaEut36UOEHSXWtkxigXiTT+LGW0GQMDOQOWnbdGaIMK9ER5sQ RLWexNOeqYwwa/+sfcICYXtIXHz4jA0SKEBbv19/zj6BUW4WwrIFjIyrGMVTS4tz01OLjfNS y/WKE3OLS/PS9ZLzczcxAmP19L/jX3cw7vuTdIhRgINRiYfXQCwrTog1say4MvcQowQHs5II b7x8epwQb0piZVVqUX58UWlOavEhRmkOFiVxXuNFL2OFBNITS1KzU1MLUotgskwcnFINjLZb NzQLv92YrZEc4rCG7fDSoq8TPX5NOrn25TOTlU+PuNa2Or2LVtiRNrXT2C7c85bamqKD3lGz tj4xXDJplugdx82udRLvnU+YGdneFZgneTNs7ny52UdX7v2hzbTCNSf2+Sars78VLjXIsO6/ fs0pu9YiLjlCZo6YQ0rmU1PRQ+Z9ueLB/UosxRmJhlrMRcWJAMYeXxXRAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprLLMWRmVeSWpSXmKPExsVy+t/xu7olQVlxBrMO8Vi8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GRcvf2Ys+GZQcW9yegNju1YXIweHhICJxOnppl2MXBxCAksZJQ6c2MEIEZeR+HBJoIuRE8gU lvhzrYsNoqaVSeJQ8yRmkASbgK3EkZlfWUFsEQEBic+di9lAbGEBN4kNNzeD2SwCqhLzVp8H s3kFXCQOPe5nhxgqL7F6wwGwOZwCrhI3Jj0HmyMEVPP8/xLmCYy8CxgZVjGKpJYW56bnFhvq FSfmFpfmpesl5+duYgQGzbZjPzfvYLy0MfgQowAHoxIPr4FYVpwQa2JZcWXuIUYJDmYlEd54 +fQ4Id6UxMqq1KL8+KLSnNTiQ4ymQEdNZJYSTc4HBnReSbyhqaG5haWhubG5sZmFkjhvh8DB GCGB9MSS1OzU1ILUIpg+Jg5OqQbGKM0YEfHDaznPeHYEnt7cnHuv+KHdxsPcVy/cdU4xU33i seWdme2vzL/TdIq3JRtPUJUxtdv88szqdak5BruS2BeoZ2Uujrh4I+m2Dce6510Oy59/8+8V y7xquSmmXiXjnatV1+ub7XXMQjbpWg08kgpVep2cJ50+xeTwz3b8s/Xjwu+hhyqUWIozEg21 mIuKEwEimSgGMAIAAA== X-CMS-MailID: 20200312151708eucas1p2acee543b5f9d236b8e43cd4d1fbed489 X-Msg-Generator: CA X-RootMTR: 20200312151708eucas1p2acee543b5f9d236b8e43cd4d1fbed489 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151708eucas1p2acee543b5f9d236b8e43cd4d1fbed489 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 01/13] librte_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". Signed-off-by: Lukasz Wojciechowski Change-Id: I1724c926a1a0a13fd16d76f19842a0b40fbea1b2 --- lib/librte_security/rte_security.c | 58 +++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/lib/librte_security/rte_security.c b/lib/librte_security/rte_security.c index bc81ce15d..40a0e9ce5 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,12 @@ #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) + struct rte_security_session * rte_security_session_create(struct rte_security_ctx *instance, struct rte_security_session_conf *conf, @@ -16,10 +23,11 @@ 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_OR_ERR_RET(instance, NULL); + RTE_PTR_OR_ERR_RET(instance->ops, NULL); + RTE_PTR_OR_ERR_RET(instance->ops->session_create, 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 +46,20 @@ 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_OR_ERR_RET(instance, -EINVAL); + RTE_PTR_OR_ERR_RET(instance->ops, -EINVAL); + RTE_PTR_OR_ERR_RET(instance->ops->session_update, -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_OR_ERR_RET(instance, 0); + RTE_PTR_OR_ERR_RET(instance->ops, 0); + RTE_PTR_OR_ERR_RET(instance->ops->session_get_size, 0); return instance->ops->session_get_size(instance->device); } @@ -54,7 +68,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_OR_ERR_RET(instance, -EINVAL); + RTE_PTR_OR_ERR_RET(instance->ops, -EINVAL); + RTE_PTR_OR_ERR_RET(instance->ops->session_stats_get, -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 +82,10 @@ rte_security_session_destroy(struct rte_security_ctx *instance, { int ret; - RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_destroy, -ENOTSUP); + RTE_PTR_OR_ERR_RET(instance, -EINVAL); + RTE_PTR_OR_ERR_RET(instance->ops, -EINVAL); + RTE_PTR_OR_ERR_RET(instance->ops->session_destroy, -ENOTSUP); + RTE_PTR_OR_ERR_RET(sess, -EINVAL); if (instance->sess_cnt) instance->sess_cnt--; @@ -81,7 +102,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); + RTE_PTR_OR_ERR_RET(instance, -EINVAL); + RTE_PTR_OR_ERR_RET(instance->ops, -EINVAL); + RTE_PTR_OR_ERR_RET(instance->ops->set_pkt_metadata, -ENOTSUP); + RTE_PTR_OR_ERR_RET(sess, -EINVAL); + RTE_PTR_OR_ERR_RET(m, -EINVAL); return instance->ops->set_pkt_metadata(instance->device, sess, m, params); } @@ -91,7 +116,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); + RTE_PTR_OR_ERR_RET(instance, NULL); + RTE_PTR_OR_ERR_RET(instance->ops, NULL); + RTE_PTR_OR_ERR_RET(instance->ops->get_userdata, NULL); if (instance->ops->get_userdata(instance->device, md, &userdata)) return NULL; @@ -101,7 +128,9 @@ 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_OR_ERR_RET(instance, NULL); + RTE_PTR_OR_ERR_RET(instance->ops, NULL); + RTE_PTR_OR_ERR_RET(instance->ops->capabilities_get, NULL); return instance->ops->capabilities_get(instance->device); } @@ -113,7 +142,10 @@ 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_OR_ERR_RET(instance, NULL); + RTE_PTR_OR_ERR_RET(instance->ops, NULL); + RTE_PTR_OR_ERR_RET(instance->ops->capabilities_get, NULL); + RTE_PTR_OR_ERR_RET(idx, NULL); capabilities = instance->ops->capabilities_get(instance->device); if (capabilities == NULL) @@ -121,7 +153,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 Mar 12 15:16:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 66593 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 61DCEA056D; Thu, 12 Mar 2020 16:18:00 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 61FF51C069; Thu, 12 Mar 2020 16:17:17 +0100 (CET) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id EDC592BE6 for ; Thu, 12 Mar 2020 16:17:09 +0100 (CET) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151708euoutp02133c5573c2474fa3c97aef0ed9f87874~7l3Z1LgWc2883228832euoutp02E for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200312151708euoutp02133c5573c2474fa3c97aef0ed9f87874~7l3Z1LgWc2883228832euoutp02E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026229; bh=UYs81vHk7L2HTFMlShroWqer0pBFWXMBvFVL12msEX0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DAnx7CHzYqvx2IlHf1BG0aJENOctbmJxXHgTdRRl0NSFpCb9JTda7F6Qn9RoorwFu qaHTGalJo73bXrf9oD35738hJ31HjyQucxttibsTGcAV1oVs7c8aRJgzMj50HHHvo9 yHiNGjpPxxPP1ddmTMqLJjJVn6LZL3VOCd4RCzp4= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200312151708eucas1p28be06cdcb04cfedc52290e3428cb6d4e~7l3ZrJQoq1665316653eucas1p2m for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 71.62.61286.4725A6E5; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200312151708eucas1p12db7c8e402be03dd255d53114217dabd~7l3ZXeKnW1794017940eucas1p1Z for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151708eusmtrp278eff720880642a3b0606bd7d0f1f87e~7l3ZW7zeq1238412384eusmtrp2A for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) X-AuditID: cbfec7f2-f0bff7000001ef66-b7-5e6a52741ccd Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 51.3F.08375.4725A6E5; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151708eusmtip11a948de968a0dff7f5390a3e5c2d7964~7l3ZJJBGq1553915539eusmtip1N for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:43 +0100 Message-Id: <20200312151654.7218-3-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPIsWRmVeSWpSXmKPExsWy7djP87olQVlxBv37tCzefdrO5MDo8WvB UtYAxigum5TUnMyy1CJ9uwSujDuvnzIWNPBU/Ns4j7mB8RlnFyMnh4SAicShSdPZQGwhgRWM EivnhHQxcgHZ7UwSKydvZoVw2pgkFt+9xgTTseHHckaIxHJGicXTVzPDtWzs28sOUsUmYCtx ZOZXVhBbREBA4nPnYrAdwgKeElf/72YGsVkEVCWWvbzDAmLzCrhIPPv1kxFig7zE6g0HwGo4 BVwlbkx6DnaGhMAcNomfn7ZCFblItC3ZyQphC0u8Or6FHcKWkfi/cz4TREM/o8Tef2/ZIZwZ jBKrL8+CesJa4vC/30AncXAwC2hKrN+lDxF2lJiycy0jSFhCgE/ixltBkDAzkDlp23RmiDCv REebEES1nsTTnqmMMGv/rH3CAmF7SGz62wANFKCth77fY5vAKDcLYdkCRsZVjOKppcW56anF hnmp5XrFibnFpXnpesn5uZsYgdF6+t/xTzsYv15KOsQowMGoxMNrIJYVJ8SaWFZcmXuIUYKD WUmEN14+PU6INyWxsiq1KD++qDQntfgQozQHi5I4r/Gil7FCAumJJanZqakFqUUwWSYOTqkG xgXeu2KsjrFqOTtcS1wRaaiu4qZpcPG/erLfxvxFOjvnRlnc7HkVuu3A0aLY5CLDyh+Wnhqn JtTu2tLg2LB/olF/Klfpwhp+KfswS4PWPVmsbHZtJ0qqndK2LyoOywkuZ30TU/JOW4rvYc0L NcWv31Yfe+j478cF46DTK4KXXNw0w7rzstRmJZbijERDLeai4kQAFcAgltICAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHLMWRmVeSWpSXmKPExsVy+t/xu7olQVlxBv/fSVi8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GXdeP2UsaOCp+LdxHnMD4zPOLkZODgkBE4kNP5YzdjFycQgJLGWU2LdgC5DDAZSQkfhwSQCi Rljiz7UuNhBbSKCVSaJjThWIzSZgK3Fk5ldWEFtEQEDic+disBphAU+Jq/93M4PYLAKqEste 3mEBsXkFXCSe/frJCDFTXmL1hgNgNZwCrhI3Jj1nhZjvIvH8/xLmCYy8CxgZVjGKpJYW56bn FhvqFSfmFpfmpesl5+duYgSGzbZjPzfvYLy0MfgQowAHoxIPr4FYVpwQa2JZcWXuIUYJDmYl Ed54+fQ4Id6UxMqq1KL8+KLSnNTiQ4ymQEdNZJYSTc4HhnReSbyhqaG5haWhubG5sZmFkjhv h8DBGCGB9MSS1OzU1ILUIpg+Jg5OqQZGi99KyV/y3TTtewQnlW/dGX14eSKbIJfYCse/Gmv6 XzlxKGhOuH1nlYKqytXDqS6H6w9IxHAoTPfkaWsInPBxsqI9gwbjr+oXQoaSL7/a6p97ZO36 quKZDu9kDtb2/9cVWFXCgjVfO+edqNjE0RFuUJs2i1W8Yin78Tkr2k9sPPnAS0okwVGJpTgj 0VCLuag4EQBaiZ79MQIAAA== X-CMS-MailID: 20200312151708eucas1p12db7c8e402be03dd255d53114217dabd X-Msg-Generator: CA X-RootMTR: 20200312151708eucas1p12db7c8e402be03dd255d53114217dabd X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151708eucas1p12db7c8e402be03dd255d53114217dabd References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 02/13] librte_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. Signed-off-by: Lukasz Wojciechowski Change-Id: Ic18ee9e76507f8888da1a0921b3a2a914a2434d2 --- 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 Mar 12 15:16:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 66589 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 48A1BA056D; Thu, 12 Mar 2020 16:17:12 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D7ACF2BE6; Thu, 12 Mar 2020 16:17:11 +0100 (CET) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id A5E842BE6 for ; Thu, 12 Mar 2020 16:17:09 +0100 (CET) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151709euoutp025b4c0dad3e6f44394525fef3f1f18d31~7l3Z_Kxi52975029750euoutp02I for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200312151709euoutp025b4c0dad3e6f44394525fef3f1f18d31~7l3Z_Kxi52975029750euoutp02I DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026229; bh=yqKjO09WUlDl03fF1ubf0yfsJpW107DL2GKAdWZPBrs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ugdugJGXZt/azJkT0sJKm2a5TmtaCHvRVHM0P80xz0HGQidhYW/Kt0fvQmJy9eqDz YK3E7F/qhtVQxDVCWvnmulsXECM/8s315MAGI3njRYZH77crCwv3omVvXd8nobuO8u gSLf1ay5kLwwm6xTcuSN37ZB1pN1jZb0SnSixMXA= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200312151709eucas1p14391317f5d6a8da00989ac48ea63f4ce~7l3Z3lsNi0788307883eucas1p13 for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 6A.B9.60698.4725A6E5; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200312151708eucas1p2536ef1df74b35ead436db85f8a5628b4~7l3Zqell81996519965eucas1p2m for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151708eusmtrp2bca861c93403c48c6db3df9a7f1a03cb~7l3Zo0A-v1238312383eusmtrp2I for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-a3-5e6a52747a06 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 71.3F.08375.4725A6E5; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151708eusmtip1617f4b268e9bb934eeba9bd047c57cd2~7l3ZVVyC91553915539eusmtip1O for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:44 +0100 Message-Id: <20200312151654.7218-4-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsWy7djP87qlQVlxBjN4Ld592s7kwOjxa8FS 1gDGKC6blNSczLLUIn27BK6MKx9VCz5wVez5PJu1gXEVZxcjB4eEgInE/2upXYxcHEICKxgl XmxcwtjFyAnktDNJTJrkBpFoY5KYdu0SO0gCpKF7ykx2iKLljBLvzntCFAE1LHz4jwUkwSZg K3Fk5ldWEFtEQEDic+diNhBbWMBaYvreNWAbWARUJY7fOgoW5xVwkXgw8RUzxAJ5idUbDoDZ nAKuEjcmPWcFWSAhMIdNYtHW5ywQRS4S795+hbKFJV4d3wJ1nYzE/53zmSAa+hkl9v57yw7h zGCUWH15FhNElbXE4X+/2UABwCygKbF+lz5E2FFi7Ym/TJBw4ZO48VYQJMwMZE7aNp0ZIswr 0dEmBFGtJ/G0ZyojzNo/a59AneMhsa3zKjMkUIC2znp/h20Co9wshGULGBlXMYqnlhbnpqcW G+ellusVJ+YWl+al6yXn525iBEbp6X/Hv+5g3Pcn6RCjAAejEg+vgVhWnBBrYllxZe4hRgkO ZiUR3nj59Dgh3pTEyqrUovz4otKc1OJDjNIcLErivMaLXsYKCaQnlqRmp6YWpBbBZJk4OKUa GJfNcap4yzfjjl/A+0NmN38ueyp7M2jbnyj2Ty9WtYo92J1+5ajfhZ3bZL/3R4nyzT4ULGMs 3OaQVrtLrvRmgGvdt901lznZf7XvyVLcFahh+q6wcQcnY2PPy62PJ1Uu8m6aGsq1JbUqatL7 t7+vBO8NXra/dOPaX2+Pn0iLysmeu5VrL8evN1FKLMUZiYZazEXFiQBzA7DuzgIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHLMWRmVeSWpSXmKPExsVy+t/xu7olQVlxBhP/aVu8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GVc+qhZ84KrY83k2awPjKs4uRk4OCQETie4pM9m7GLk4hASWMkpMODKRsYuRAyghI/HhkgBE jbDEn2tdbBA1rUwSD7qWs4Ik2ARsJY7M/ApmiwgISHzuXMwGYgsLWEtM37uGEcRmEVCVOH7r KFicV8BF4sHEV8wQQ+UlVm84AGZzCrhK3Jj0HGyOEFDN8/9LmCcw8i5gZFjFKJJaWpybnlts qFecmFtcmpeul5yfu4kRGDbbjv3cvIPx0sbgQ4wCHIxKPLwGYllxQqyJZcWVuYcYJTiYlUR4 4+XT44R4UxIrq1KL8uOLSnNSiw8xmgIdNZFZSjQ5HxjSeSXxhqaG5haWhubG5sZmFkrivB0C B2OEBNITS1KzU1MLUotg+pg4OKUaGPl1p59qiGhiPK45oTTpzp6v5t3CR0Ibgs2EGeae8rpR Wnt5j6yapE5d8ul+7X+TVr1k41/wfOkiK72yjcI6bOt+HFS+an8rY8pzvagnnzt+Hb77ZPtZ nqA37huvFqxYU7iCy3HJP8enGqwZL9MOZDGvXiTrb6W8MNZ+G8uxluc7D1v/jwz9EqHEUpyR aKjFXFScCAAS5G4mMQIAAA== X-CMS-MailID: 20200312151708eucas1p2536ef1df74b35ead436db85f8a5628b4 X-Msg-Generator: CA X-RootMTR: 20200312151708eucas1p2536ef1df74b35ead436db85f8a5628b4 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151708eucas1p2536ef1df74b35ead436db85f8a5628b4 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 03/13] librte_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 destoyed. 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. Signed-off-by: Lukasz Wojciechowski Change-Id: I75ebfc26811ec2159b973fae36b2c9fb08868f11 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 40a0e9ce5..74a314903 100644 --- a/lib/librte_security/rte_security.c +++ b/lib/librte_security/rte_security.c @@ -87,14 +87,16 @@ rte_security_session_destroy(struct rte_security_ctx *instance, RTE_PTR_OR_ERR_RET(instance->ops->session_destroy, -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 Mar 12 15:16:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 66590 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 4B65BA056D; Thu, 12 Mar 2020 16:17:21 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4A78F1C01E; Thu, 12 Mar 2020 16:17:13 +0100 (CET) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id D88051BFC9 for ; Thu, 12 Mar 2020 16:17:09 +0100 (CET) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151709euoutp01cd6ee98d4f2c74f7a8efe943d05b58e4~7l3aHsZSk0474204742euoutp01D for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200312151709euoutp01cd6ee98d4f2c74f7a8efe943d05b58e4~7l3aHsZSk0474204742euoutp01D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026229; bh=a9JoLQ6I84KSNR2xpJDU/ZXMUkDAgTS0qD54bhtPwjY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=mhHTGJJBEoFjbtI6GdFQwnYqNcP7gHzDVRBqUr7tAugRfEUsh/sovztvK8nNSyM+Y o9xC7jkdgN+UeDfR/XHcUbmsiCkrUmBCOy/h5mb3ptZOEcuevjvOs0X5+VNqzOXrH/ +exa7SL3shqT7yuPSN9tDF2FH+rYCN2lJMMpf86w= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200312151709eucas1p2d7edc51eb91589632624d8a0dd117d71~7l3aCP-0r1602216022eucas1p2r for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id ED.BD.60679.5725A6E5; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200312151708eucas1p18d3cde72ccadf22d43b8907ab9de6d97~7l3Z1crod0788407884eucas1p10 for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151708eusmtrp2e420f715b7a77dcd3ffe829a5d46f986~7l3Z0-9JO1238312383eusmtrp2J for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) X-AuditID: cbfec7f4-0cbff7000001ed07-28-5e6a52759977 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id B1.3F.08375.4725A6E5; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151708eusmtip117955b0339eac3f42b301124ac3fac7f~7l3Zn_MqQ1547515475eusmtip1O for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:45 +0100 Message-Id: <20200312151654.7218-5-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsWy7djPc7qlQVlxBu/fcFm8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGZv3n2QqOMla0THzNHMD412WLkZODgkBE4kZ586xdzFycQgJ rGCU2LqmlQ3CaWeS6J7VwAzhtDFJPHpxiAmm5dOrz4wQieWMEl9XHWSEa3l3YCszSBWbgK3E kZlfWUFsEQEBic+di9lAbGEBU4kdryaB2SwCqhK7Gq4ALefg4BVwkZj21hBigbzE6g0HwMZw CrhK3Jj0nBVkvoTAHDaJdV/+MkMUuUis+PaDDcIWlnh1fAs7hC0j8X/nfCaIhn5Gib3/3rJD ODMYJVZfngX1g7XE4X+/2UA2MwtoSqzfpQ8RdpTYsbAL7CAJAT6JG28FQcLMQOakbdOZIcK8 Eh1tQhDVehJPe6Yywqz9s/YJC0SJh8SDfWogYSGQpT3zeSYwys1CWLWAkXEVo3hqaXFuemqx UV5quV5xYm5xaV66XnJ+7iZGYKSe/nf8yw7GXX+SDjEKcDAq8fAaiGXFCbEmlhVX5h5ilOBg VhLhjZdPjxPiTUmsrEotyo8vKs1JLT7EKM3BoiTOa7zoZayQQHpiSWp2ampBahFMlomDU6qB kf2wYrT6nTk/5x2Zu3yZ3iauXcuDyu5HhX/g/RHpe1xG66xJg63RdflD+Qu1528O85Jf51Te 92K9ZXXUNOn6F0zv12V9Ffh2r8Jt9uSWU5U+zP+9Wqc6GBzfICb41voo61HpjE1O+VxVW9bO 21Z1ZYnFq6DW0NuHe9KP+6lMKS489Nlg5mx1QyWW4oxEQy3mouJEANMKVqHQAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprLLMWRmVeSWpSXmKPExsVy+t/xu7olQVlxBmtbrC3efdrO5MDo8WvB UtYAxig9m6L80pJUhYz84hJbpWhDCyM9Q0sLPSMTSz1DY/NYKyNTJX07m5TUnMyy1CJ9uwS9 jM37TzIVnGSt6Jh5mrmB8S5LFyMnh4SAicSnV58Zuxi5OIQEljJKHG/ZCZTgAErISHy4JABR Iyzx51oXG4gtJNDKJHHlbBCIzSZgK3Fk5ldWEFtEQEDic+disBphAVOJHa8mgdksAqoSuxqu sIOM5BVwkZj21hBipLzE6g0HmEFsTgFXiRuTnrNCjHeReP5/CfMERt4FjAyrGEVSS4tz03OL DfWKE3OLS/PS9ZLzczcxAoNm27Gfm3cwXtoYfIhRgINRiYfXQCwrTog1say4MvcQowQHs5II b7x8epwQb0piZVVqUX58UWlOavEhRlOgmyYyS4km5wMDOq8k3tDU0NzC0tDc2NzYzEJJnLdD 4GCMkEB6YklqdmpqQWoRTB8TB6dUA6OPKfc/h7/VGxb4FtlKhgT3fPSV1DK6utY8WyN9fe7e LxZBVq9PHPj09fN8tyt1bhKLvNrbWju2Cmlv/dzcNemonuqDv58VF/2pXKHtvqXnX7Ccx7p/ L3Xf3HKbwdd/4pXZc2+pq90xm1Vu3W86oBu6gPFxQsIrJd+Z0TGf90vrmrH8tXixQVWJpTgj 0VCLuag4EQCGc9KAMAIAAA== X-CMS-MailID: 20200312151708eucas1p18d3cde72ccadf22d43b8907ab9de6d97 X-Msg-Generator: CA X-RootMTR: 20200312151708eucas1p18d3cde72ccadf22d43b8907ab9de6d97 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151708eucas1p18d3cde72ccadf22d43b8907ab9de6d97 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 04/13] app/test: fix macro definition X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Wrap RTE_TEST_TRACE_FAILURE macro definition into #ifndef clause as it might be already defined. Signed-off-by: Lukasz Wojciechowski Change-Id: I0da5c66d5a7ae369214acfdfd3f872c2fc417d19 --- app/test/test.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/test/test.h b/app/test/test.h index ac0c50616..8ac581cbc 100644 --- a/app/test/test.h +++ b/app/test/test.h @@ -22,7 +22,9 @@ # define TEST_TRACE_FAILURE(_file, _line, _func) #endif -#define RTE_TEST_TRACE_FAILURE TEST_TRACE_FAILURE +#ifndef RTE_TEST_TRACE_FAILURE +# define RTE_TEST_TRACE_FAILURE TEST_TRACE_FAILURE +#endif #include From patchwork Thu Mar 12 15:16:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 66595 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 D6823A056D; Thu, 12 Mar 2020 16:18:28 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 380211C0AB; Thu, 12 Mar 2020 16:17:20 +0100 (CET) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 738E11BFBF for ; Thu, 12 Mar 2020 16:17:10 +0100 (CET) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151709euoutp02ea8c8d30a74c488e83a326e074fd96f1~7l3atn0Fp2888228882euoutp024 for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200312151709euoutp02ea8c8d30a74c488e83a326e074fd96f1~7l3atn0Fp2888228882euoutp024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026229; bh=omWloqvYb+jHTLXKny9NC+bIfnLplV3RtKyAQ5mx29w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Rr10YPp626ZpsFy5QMOa6ZZjykI6+OybH/3YNcbzy3xiWcTkEskG6Yl0APW4sYMTR 1fyVQr1psuWElKD2DokMtYxcFMJNcUJMyACtIn2NnWH0Y1AXkvI92zgF2fY4z0DGEc tFV6gErVOiPBD8Vk/UZipPQAq2dCVzUAFjIIYuRw= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200312151709eucas1p1f1d393a23c33c5f18bc6ea12cc4b999d~7l3ae1vzU1662616626eucas1p1u for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 1E.BD.60679.5725A6E5; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200312151709eucas1p2df38aed23b7445d3db7d4d3ea8fe3222~7l3aGc74i1975519755eucas1p2y for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151709eusmtrp2cfa5c5563d2840d3857e5433d0b2b489~7l3aF8tu01238312383eusmtrp2L for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) X-AuditID: cbfec7f4-0cbff7000001ed07-2a-5e6a5275edaf Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 61.2D.07950.5725A6E5; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151709eusmtip18b7813aa31c7f08cad38da99319b5fe6~7l3Z26jhQ1547415474eusmtip1X for ; Thu, 12 Mar 2020 15:17:08 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:46 +0100 Message-Id: <20200312151654.7218-6-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrAIsWRmVeSWpSXmKPExsWy7djP87qlQVlxBodmaFi8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGfPniBWsO8hYMffPUvYGxsaFjF2MnBwSAiYS3x40M3cxcnEI CaxglFhy5ikjhNPOJLHp20QmCKeNSWLri3esXYwcYC0HJuVBxJczStw908cK13Gtaz8TyFw2 AVuJIzO/soLYIgICEp87F7OB2MICDhIXf0wCs1kEVCW+te5hBrF5BVwkmpa9YIK4SV5i9YYD YHFOAVeJG5Oegy2QEJjDJjHp93p2iCIXiXfLLkE1CEu8Or4FKi4j8X/nfCaIhn5Gib3/3rJD ODMYJVZfngXVYS1x+N9vNpB/mAU0Jdbv0ocIO0pMaHnADvEmn8SNt4IgYWYgc9K26cwQYV6J jjYhiGo9iac9Uxlh1v5Z+4QFwvaQ+LhuBzRQgLZOO/uVbQKj3CyEZQsYGVcxiqeWFuempxYb 5aWW6xUn5haX5qXrJefnbmIExuvpf8e/7GDc9SfpEKMAB6MSD6+BWFacEGtiWXFl7iFGCQ5m JRHeePn0OCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8xotexgoJpCeWpGanphakFsFkmTg4pRoY nbgLFpq473wknLfhrVPLRn2xRxI+Vffe3JrmptfL2Ky1+EJCZoZcTvKzuCbJIqWESwcP8G/M ybz3pjqjZGfEq2eOV2IZ9x1m/fhH3mN35q/MTVOXxezhyJ56cOFR7mAOoZppnY++rD7b3//0 zWLB6cG3gu/u85jJNk9A8cx91ynLVwso5p5gUGIpzkg01GIuKk4EADiRzDDTAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPLMWRmVeSWpSXmKPExsVy+t/xu7qlQVlxBo1/+SzefdrO5MDo8WvB UtYAxig9m6L80pJUhYz84hJbpWhDCyM9Q0sLPSMTSz1DY/NYKyNTJX07m5TUnMyy1CJ9uwS9 jPlzxArWHWSsmPtnKXsDY+NCxi5GDg4JAROJA5Pyuhi5OIQEljJKrFy4kxUiLiPx4ZJAFyMn kCks8edaFxtETSuTxPI9ExlBEmwCthJHZn5lBbFFBAQkPncuZgOxhQUcJC7+mARmswioSnxr 3cMMYvMKuEg0LXvBBDFUXmL1hgNgcU4BV4kbk56DzRECqnn+fwnzBEbeBYwMqxhFUkuLc9Nz i430ihNzi0vz0vWS83M3MQIDZ9uxn1t2MHa9Cz7EKMDBqMTDayCWFSfEmlhWXJl7iFGCg1lJ hDdePj1OiDclsbIqtSg/vqg0J7X4EKMp0FETmaVEk/OBQZ1XEm9oamhuYWlobmxubGahJM7b IXAwRkggPbEkNTs1tSC1CKaPiYNTqoGxL0Q5MZlJPmjlB+56icdvrE7rfboxo3jNRd6w1OcO R7Zb3Vbc3232t+6g9TLPA7WSmgpb/tfFbfq7++lPV2Z+i/wZnQlyWpsjcr6tjp7Bd+Eny80/ 9mWCxQXNc1cemLlKZ8dk6/r9kWeZzFfyzFAJUn43vbBQ2YSjoucmg/m2i0v7GYpeHzqpxFKc kWioxVxUnAgA9/4LmDICAAA= X-CMS-MailID: 20200312151709eucas1p2df38aed23b7445d3db7d4d3ea8fe3222 X-Msg-Generator: CA X-RootMTR: 20200312151709eucas1p2df38aed23b7445d3db7d4d3ea8fe3222 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151709eucas1p2df38aed23b7445d3db7d4d3ea8fe3222 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 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 Change-Id: I3a4585f56ef1a75b2984fcea3a3e4a30e4c2d8a6 --- app/test/Makefile | 2 + app/test/meson.build | 3 + app/test/test_security.c | 670 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 675 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 0a2ce710f..89e4299fd 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' ] @@ -209,6 +211,7 @@ fast_test_names = [ 'rwlock_rds_wrm_autotest', 'rwlock_rde_wro_autotest', 'sched_autotest', + 'security_autotest', 'spinlock_autotest', 'stack_autotest', 'stack_lf_autotest', diff --git a/app/test/test_security.c b/app/test/test_security.c new file mode 100644 index 000000000..885281703 --- /dev/null +++ b/app/test/test_security.c @@ -0,0 +1,670 @@ +/* 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 + */ +#define TEST_ASSERT_MOCK_FUNCTION_CALL_RET(f_name, f_ret, exp_ret, \ + ret_spec) do { \ + TEST_ASSERT_EQUAL(exp_ret, f_ret, "Expecting " RTE_STR(f_name) \ + " to return " ret_spec ", but it returned " ret_spec "\n", \ + exp_ret, f_ret); \ +} while (0) + +/** + * 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) do { \ + TEST_ASSERT_NOT_NULL(f_ret, "Expecting " RTE_STR(f_name) \ + " to return not NULL\n"); \ +} while (0) + +/** + * 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 mempool objects in use + */ +#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 alse 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_rte_security_session_create_inv_param_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_rte_security_session_create_inv_param_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_rte_security_session_create_inv_param_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_rte_security_session_create_inv_param_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_rte_security_session_create_inv_param_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_rte_security_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_rte_security_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_rte_security_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_rte_security_session_create_inv_param_context), + TEST_CASE_ST(ut_setup, ut_teardown, + test_rte_security_session_create_inv_param_context_ops), + TEST_CASE_ST(ut_setup, ut_teardown, + test_rte_security_session_create_inv_param_context_ops_fun), + TEST_CASE_ST(ut_setup, ut_teardown, + test_rte_security_session_create_inv_param_configuration), + TEST_CASE_ST(ut_setup, ut_teardown, + test_rte_security_session_create_inv_param_mempool), + TEST_CASE_ST(ut_setup, ut_teardown, + test_rte_security_session_create_mempool_empty), + TEST_CASE_ST(ut_setup, ut_teardown, + test_rte_security_session_create_ops_failure), + TEST_CASE_ST(ut_setup, ut_teardown, + test_rte_security_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 Mar 12 15:16:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 66594 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 391BDA056D; Thu, 12 Mar 2020 16:18:14 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CD9811C07E; Thu, 12 Mar 2020 16:17:18 +0100 (CET) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 631C22BE6 for ; Thu, 12 Mar 2020 16:17:10 +0100 (CET) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151710euoutp027576f7016fba3516c7291b3ffb3f2dd8~7l3a9I38F2975329753euoutp02L for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200312151710euoutp027576f7016fba3516c7291b3ffb3f2dd8~7l3a9I38F2975329753euoutp02L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026230; bh=9m5HlxPdt2tJAqp+93xZw06/163gjT2G2iNw44jQSew=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ep7z2hJITbBLs70xG2eX/4gYZHplc/7XeHZd8i/yKy5RUcX+N6DgVJ+XQWpuaIFdd PjEGfu6RhvAtc5JngC/l3ZLJ3okCXkWoqSqTdWgC60fnZ2GKSJcNFivHVlAgnt2kSy /MivNuXZKMnyP2tVzLlUrtfGNZpi5IMzc5/svcGQ= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200312151709eucas1p217d90f3d2113ee9875595a6339054195~7l3aspGY62375023750eucas1p2e for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 72.62.61286.5725A6E5; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200312151709eucas1p1a01f789059de888cb2d719526434e4f9~7l3aWte7-0788307883eucas1p15 for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151709eusmtrp21ac866d7f8bd78ad04f5a306aa8c24eb~7l3aWQMOk1238412384eusmtrp2F for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-bc-5e6a52758601 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 81.2D.07950.5725A6E5; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151709eusmtip19b3f4223700ce067895841d1abb3f02e~7l3aHJ2vP0817408174eusmtip10 for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:47 +0100 Message-Id: <20200312151654.7218-7-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrAIsWRmVeSWpSXmKPExsWy7djP87qlQVlxBhPaDS3efdrO5MDo8WvB UtYAxigum5TUnMyy1CJ9uwSujHWL5jMWLPesuHqgj7GBcb9dFyMnh4SAicTpXU1sXYxcHEIC Kxgl2o5cYIZw2pkk/i2bC+W0MUn0f77FAtOyau9+JojEckaJlcdOMMK1TH8+nRmkik3AVuLI zK+sILaIgIDE587FbCC2sICbxMcvE5hAbBYBVYmtb26B2bwCLhLLHy5jh9ggL7F6wwGwOZwC rhI3Jj1nBVkgITCHTeLT7ytMEEUuErtXfmWGsIUlXh3fAtUsI/F/53wmiIZ+Rom9/96yQzgz GCVWX54F1W0tcfjfb6CTODiYBTQl1u/Shwg7Ssy7dI0VJCwhwCdx460gSJgZyJy0DeQxkDCv REebEES1nsTTnqmMMGv/rH0CDSEPiQdXz7JDAgVo66U5P5knMMrNQli2gJFxFaN4amlxbnpq sWFearlecWJucWleul5yfu4mRmC8nv53/NMOxq+Xkg4xCnAwKvHwGohlxQmxJpYVV+YeYpTg YFYS4Y2XT48T4k1JrKxKLcqPLyrNSS0+xCjNwaIkzmu86GWskEB6YklqdmpqQWoRTJaJg1Oq gXGn0AfHSZ1vcpK0JdUzWm0Zby0yrZCYdfxqVNjCT/Zp897r7lpjtLNw1ZQmV8P3Sw6u6vne q1ina3XIL+/Mg+DCgl6etUGzeUO8Y+9OTninVVT7yayYb8uf3V3nI6dbtWfOXbN1/konh2O3 Sk3vLko4vf0dt5nX3iNfDs259PqbkuSsspceFdZKLMUZiYZazEXFiQAieANd0wIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPLMWRmVeSWpSXmKPExsVy+t/xu7qlQVlxBvPnS1u8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GesWzWcsWO5ZcfVAH2MD4367LkZODgkBE4lVe/czdTFycQgJLGWUWPZhBlsXIwdQQkbiwyUB iBphiT/XutggalqZJJZ9fswEkmATsJU4MvMrK4gtIiAg8blzMRuILSzgJvHxywSwGhYBVYmt b26B2bwCLhLLHy5jhxgqL7F6wwFmEJtTwFXixqTnYHOEgGqe/1/CPIGRdwEjwypGkdTS4tz0 3GIjveLE3OLSvHS95PzcTYzAwNl27OeWHYxd74IPMQpwMCrx8BqIZcUJsSaWFVfmHmKU4GBW EuGNl0+PE+JNSaysSi3Kjy8qzUktPsRoCnTURGYp0eR8YFDnlcQbmhqaW1gamhubG5tZKInz dggcjBESSE8sSc1OTS1ILYLpY+LglGpgnLpILzL3fcmXhKznE4unRETqXYrl6zlz65TBr+6b 1UdXbeZwq/5UbyM5o5U9xIhvQ2Xv8bDkbOctXy9c55zeLNx7IU8ptaHqkxarbMq712Hfdm8R OvktamLGtoDtK3anKZVkXcn797TvSKSci/aexz9W3FjCwa553ro98kKBqen5OZG25+uuK7EU ZyQaajEXFScCAJLfwjwyAgAA X-CMS-MailID: 20200312151709eucas1p1a01f789059de888cb2d719526434e4f9 X-Msg-Generator: CA X-RootMTR: 20200312151709eucas1p1a01f789059de888cb2d719526434e4f9 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151709eucas1p1a01f789059de888cb2d719526434e4f9 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 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" Signed-off-by: Lukasz Wojciechowski Change-Id: I3d5df17a33913a94e6ad6806de91c7157184e3b4 --- app/test/test_security.c | 225 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index 885281703..cf13b8080 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -234,6 +234,35 @@ 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 * @@ -274,6 +303,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, }; @@ -296,6 +326,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. */ @@ -361,9 +392,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; @@ -374,6 +407,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) { @@ -407,6 +441,43 @@ 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 @@ -629,6 +700,145 @@ test_rte_security_session_create_success(void) } +/** + * rte_security_session_update tests + */ + +/** + * Test execution of rte_security_session_update with NULL instance + */ +static int +test_rte_security_session_update_inv_param_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_rte_security_session_update_inv_param_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_rte_security_session_update_inv_param_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_rte_security_session_update_inv_param_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_rte_security_session_update_inv_param_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_rte_security_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_rte_security_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 */ @@ -654,6 +864,21 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_rte_security_session_create_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_inv_param_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_inv_param_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_inv_param_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_inv_param_configuration), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_inv_param_session), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_update_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Thu Mar 12 15:16:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 66597 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 B8C4DA056D; Thu, 12 Mar 2020 16:18:57 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AA41B1C0BE; Thu, 12 Mar 2020 16:17:22 +0100 (CET) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id ACAE32BE6 for ; Thu, 12 Mar 2020 16:17:10 +0100 (CET) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151710euoutp014dee6dbb13e3b2a52efe8809ec5fbf17~7l3a_KMBS0594005940euoutp01K for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200312151710euoutp014dee6dbb13e3b2a52efe8809ec5fbf17~7l3a_KMBS0594005940euoutp01K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026230; bh=ryNbrMY0w9JMLHi/WM+ZmUR+ackKFbkjvc+x5YF/z4Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nDIRIIH8/8HSVW0UTKKYcPcyd0QC4CW1ls+vH188z4+khGw89oX/euN7MSmdC5aMB 9z/07kea52SPIx6znNwsG1Kvjh3Sj9oaliot2j/fKfb4Ndg1wJV1egDKsQooJF3I41 WyhyX1ZQ+SRZSte/CQ+aEtLQgY9jY/03PKUYTsRU= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200312151709eucas1p1cf443df68476fdb61399e1e9b6bedfe9~7l3ax712F0788307883eucas1p16 for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 7E.BD.60679.5725A6E5; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200312151709eucas1p139311cecb925f566cbbf1444d14c31b1~7l3ae7Msw1595115951eucas1p1g for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151709eusmtrp217d1c83ed6145c4ba3520b7311e9f210~7l3aeed4V1238312383eusmtrp2M for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) X-AuditID: cbfec7f4-0cbff7000001ed07-2c-5e6a527554ce Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 22.3F.08375.5725A6E5; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151709eusmtip1a8a8f81c93bf4be9e19274dd10232833~7l3aTQoLi1547515475eusmtip1P for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:48 +0100 Message-Id: <20200312151654.7218-8-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrHIsWRmVeSWpSXmKPExsWy7djPc7qlQVlxBgsuW1u8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGfemfGYs6NCq+L/yAGsDY7NKFyMnh4SAicS2W0dZuhi5OIQE VjBKfFhwhR3CaWeS2LlpEiOE08Yk0fT/EhtMy4HVM9ggEssZJf78eMcEkgBrObiXC8RmE7CV ODLzKyuILSIgIPG5czFYs7CAh0T37j1AKzg4WARUJR71uYOEeQVcJBbdmckKMV9eYvWGA8wg NqeAq8SNSc9ZQXZJCMxhk9g79xlUkYvElP5JLBC2sMSr41vYIWwZif875zNBNPQzSuz995Yd wpnBKLH68iwmiCpricP/frOBXMEsoCmxfpc+RNhR4uGVZ0wgYQkBPokbbwVBwsxA5qRt05kh wrwSHW1CENV6Ek97pjLCrP2z9gnUOR4S87ZuhoYP0NYLP+6xTWCUm4WwbAEj4ypG8dTS4tz0 1GKjvNRyveLE3OLSvHS95PzcTYzAWD397/iXHYy7/iQdYhTgYFTi4TUQy4oTYk0sK67MPcQo wcGsJMIbL58eJ8SbklhZlVqUH19UmpNafIhRmoNFSZzXeNHLWCGB9MSS1OzU1ILUIpgsEwen VAMj93nrl+U5EWfePZzYJ7f0h8qTaS8/KUSpFZ2fYSlnp3+hfPIuzlubUv4uUXZss/q1VMc6 QmHhlW/7johxReg2aUwJPvPqo9GywFcTw/59fvsi/MzcwFVTWTYfux6Rs3xaoIrh/4Obz6WH 6RatVVheklx34u6F/HsdW5av8l3jMOutQ5le0W1ONyWW4oxEQy3mouJEAJ8UB6DRAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHLMWRmVeSWpSXmKPExsVy+t/xu7qlQVlxBkuvqlu8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GfemfGYs6NCq+L/yAGsDY7NKFyMnh4SAicSB1TPYuhi5OIQEljJKXOloAXI4gBIyEh8uCUDU CEv8udYFVdPKJHH/yHEWkASbgK3EkZlfWUFsEQEBic+di9lAbGEBD4nu3XvYQeawCKhKPOpz BwnzCrhILLozkxViprzE6g0HmEFsTgFXiRuTnoPFhYBqnv9fwjyBkXcBI8MqRpHU0uLc9Nxi Q73ixNzi0rx0veT83E2MwLDZduzn5h2MlzYGH2IU4GBU4uE1EMuKE2JNLCuuzD3EKMHBrCTC Gy+fHifEm5JYWZValB9fVJqTWnyI0RToponMUqLJ+cCQziuJNzQ1NLewNDQ3Njc2s1AS5+0Q OBgjJJCeWJKanZpakFoE08fEwSnVwJj897XWypmCe82r3GQDuydt1f4WtUBN6W+4p/TEZ7Vu SwUVFjpm7V2mpCFoXPdl6UGfwDbP5V+9M/8ECG+aEpX/YN9CXs8HcnvaEkOMLmZfFLrOOPeV /d7p604p19+/Wfawd3Mkw+XYrMJt2/Zl83/dtlpCW2LR1n+qhx+fmSCb+6s25v4ZGU4lluKM REMt5qLiRAANwu05MQIAAA== X-CMS-MailID: 20200312151709eucas1p139311cecb925f566cbbf1444d14c31b1 X-Msg-Generator: CA X-RootMTR: 20200312151709eucas1p139311cecb925f566cbbf1444d14c31b1 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151709eucas1p139311cecb925f566cbbf1444d14c31b1 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 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" Signed-off-by: Lukasz Wojciechowski Change-Id: I1d1238d38c0cca5ba9c14c8ba395a16d686ae110 --- app/test/test_security.c | 131 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index cf13b8080..d4b3e9515 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -263,6 +263,29 @@ 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 * @@ -304,6 +327,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, }; @@ -393,10 +417,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; @@ -839,6 +865,100 @@ test_rte_security_session_update_success(void) } +/** + * rte_security_session_get_size tests + */ + +/** + * Test execution of rte_security_session_get_size with NULL instance + */ +static int +test_rte_security_session_get_size_inv_param_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_rte_security_session_get_size_inv_param_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_rte_security_session_get_size_inv_param_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_rte_security_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_rte_security_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 */ @@ -879,6 +999,17 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_rte_security_session_update_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_get_size_inv_param_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_get_size_inv_param_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_get_size_inv_param_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_get_size_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_get_size_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Thu Mar 12 15:16:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wojciechowski X-Patchwork-Id: 66596 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 7B56CA056D; Thu, 12 Mar 2020 16:18:43 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7A12A1C0B3; Thu, 12 Mar 2020 16:17:21 +0100 (CET) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 8837F1BFC9 for ; Thu, 12 Mar 2020 16:17:10 +0100 (CET) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151710euoutp02412d97eacedd10d8db223e32679bd001~7l3bI2c872975029750euoutp02J for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200312151710euoutp02412d97eacedd10d8db223e32679bd001~7l3bI2c872975029750euoutp02J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026230; bh=VIVTeODXDCX/JANAKU8NjLFYDZlBtIsK5k1x4sHavAE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BCJm8K/K3WEeOspX0YK1u3xGLhlAi4A5ph1ec4jbBHu+HMFaXf3+wqO0OsNX784+8 3je8gR7VljEl5BB4nsSOUpg+oGIlmsgXzDAlnwQ3OS5fI+ZoK19qe7xjb+RHc2eMZK rdRfo98qg2kLlk9VW45FdPO0h4UY1JJgS8qVCkFI= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200312151710eucas1p203d0656e583c4ac0dac64237bdd6ae1b~7l3a91yHy2375023750eucas1p2g for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 9E.BD.60679.6725A6E5; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200312151709eucas1p15263f75e2ad73aa9b8d2fb2d4cf51439~7l3arVK_I0782307823eucas1p1r for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151709eusmtrp20750385c54d5fd383974420e94dde52e~7l3aq3qN11238412384eusmtrp2G for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-2d-5e6a5276900e Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id C1.2D.07950.5725A6E5; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151709eusmtip1df0f7ff24db9d97539df233012c3f0c9~7l3afeYMO1553915539eusmtip1P for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:49 +0100 Message-Id: <20200312151654.7218-9-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsWy7djPc7plQVlxBj9+sFq8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGS9P72IqeGdWcfKzSQPjUv0uRk4OCQETiU/Xz7B0MXJxCAms YJS492ERG4TTziSx4Ow+dginjUli9p797DAtU+f8Z4ZILGeUuNzagtCy6sEvZpAqNgFbiSMz v7KC2CICAhKfOxezgdjCAp4S368cB1rIwcEioCrx91woiMkr4CLxdUIWxHx5idUbDoBN4RRw lbgx6TkryHgJgTlsEseb25khilwkNjS1MELYwhKvjm+BOk5G4v/O+UwQDf2MEnv/vWWHcGYw Sqy+PIsJospa4vC/32wgm5kFNCXW74IGhqNE25KfjCBhCQE+iRtvBUHCzEDmpG3TmSHCvBId bUIQ1XoST3umMsKs/bP2CQuE7SHRcPIeEyRIgLYue9HMPoFRbhbCsgWMjKsYxVNLi3PTU4uN 8lLL9YoTc4tL89L1kvNzNzECI/X0v+NfdjDu+pN0iFGAg1GJh9dALCtOiDWxrLgy9xCjBAez kghvvHx6nBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXFe40UvY4UE0hNLUrNTUwtSi2CyTBycUg2M EaorF1RzrvmVJjI3c178HIGSD7lf94kcKAiK3TzJatHXRtdJoXNNxG8uKn7fWpNausG64cjP vJpLbU4C7Z+CPCJvH18gk/dp78J1Ww+84zv6k/HpE5Vvl+InHjfdkfIi/UzX2vVerbqXHO71 t9/hW+ehW/f8tJ3S4sMNk0svHLEv/LPo2wxnJyWW4oxEQy3mouJEAJQub6HQAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprDLMWRmVeSWpSXmKPExsVy+t/xu7qlQVlxBi3TTSzefdrO5MDo8WvB UtYAxig9m6L80pJUhYz84hJbpWhDCyM9Q0sLPSMTSz1DY/NYKyNTJX07m5TUnMyy1CJ9uwS9 jJendzEVvDOrOPnZpIFxqX4XIyeHhICJxNQ5/5m7GLk4hASWMkocb3zA1sXIAZSQkfhwSQCi Rljiz7UuNoiaViaJt8uXsoEk2ARsJY7M/MoKYosICEh87lwMFhcW8JT4fuU4C8gcFgFVib/n QkFMXgEXia8TsiBGykus3nCAGcTmFHCVuDHpOdgUIaCS5/+XME9g5F3AyLCKUSS1tDg3PbfY SK84Mbe4NC9dLzk/dxMjMGS2Hfu5ZQdj17vgQ4wCHIxKPLwGYllxQqyJZcWVuYcYJTiYlUR4 4+XT44R4UxIrq1KL8uOLSnNSiw8xmgKdNJFZSjQ5HxjOeSXxhqaG5haWhubG5sZmFkrivB0C B2OEBNITS1KzU1MLUotg+pg4OKUaGJdMMGk/sHmBCJ/19I9bi+OFb/U7XTm1euO1qa+MA+p3 9zh5Tb6tMuPdpeT9whqG680kLrPceOPw0kaEb8bEsgNBz1zNmxrN7ilbGa55Uv90/r1Ujfri 2mUvJjUI72O7er3il/2zt+18+uw9dyZaMwYJBm3+kyF94cO/o6uVLv2TfHIuUFToobgSS3FG oqEWc1FxIgApIAZoLwIAAA== X-CMS-MailID: 20200312151709eucas1p15263f75e2ad73aa9b8d2fb2d4cf51439 X-Msg-Generator: CA X-RootMTR: 20200312151709eucas1p15263f75e2ad73aa9b8d2fb2d4cf51439 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151709eucas1p15263f75e2ad73aa9b8d2fb2d4cf51439 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 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" Signed-off-by: Lukasz Wojciechowski Change-Id: Ib373d2e01aba2924e2f21ff2d5edfa1643e9eff4 --- app/test/test_security.c | 172 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index d4b3e9515..647a2dd0a 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -286,6 +286,35 @@ 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 * @@ -328,6 +357,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, }; @@ -418,11 +448,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; @@ -959,6 +991,133 @@ test_rte_security_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_rte_security_session_stats_get_inv_param_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_rte_security_session_stats_get_inv_param_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_rte_security_session_stats_get_inv_param_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_rte_security_session_stats_get_inv_param_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_rte_security_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_rte_security_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 */ @@ -1010,6 +1169,19 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_rte_security_session_get_size_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_stats_get_inv_param_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_stats_get_inv_param_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_stats_get_inv_param_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_stats_get_inv_param_stats), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_stats_get_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_stats_get_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Thu Mar 12 15:16: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: 66598 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 2C95BA056E; Thu, 12 Mar 2020 16:19:14 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CE7D61C0C5; Thu, 12 Mar 2020 16:17:23 +0100 (CET) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 01A262BE6 for ; Thu, 12 Mar 2020 16:17:11 +0100 (CET) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151710euoutp012562f6e0e90c720cc47c1f5034b12de2~7l3bjq8kS0594305943euoutp01J for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200312151710euoutp012562f6e0e90c720cc47c1f5034b12de2~7l3bjq8kS0594305943euoutp01J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026230; bh=rxjwED2j6idGWtR2BI/xAgWu+8XPq93cS43i5LvWjeU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KBQvjLgywg6FUWGnMGrsPE9JrYXE52nNtn/+ju7Uy49KELL7FWW/R0Jv0eah3saDf Fhmg6IKbf4fd6peHT+JKr+VN0oYj4sCtazbGc29mhlADdL8wThRiYY9dNUA8joWown y78fSDfkmkcprDgHpi3J3YmWty3lub3WscOI4Lgc= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200312151710eucas1p213c73a1bb31ae9ab3a07c0ddf919f0ee~7l3bRAth12375023750eucas1p2i for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 0B.B9.60698.6725A6E5; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200312151710eucas1p22f051449e6e7edeadefe65b66ffaed32~7l3a6lLT61698716987eucas1p2x for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151710eusmtrp23ca1bba26d778ae00defcc1cdfee636b~7l3a6DbOQ1238312383eusmtrp2N for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) X-AuditID: cbfec7f5-a0fff7000001ed1a-a8-5e6a52768ec3 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id E1.2D.07950.6725A6E5; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151709eusmtip1aa38ae54be42f6110588c3b68dfe782e~7l3arkQlM1532415324eusmtip1S for ; Thu, 12 Mar 2020 15:17:09 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:50 +0100 Message-Id: <20200312151654.7218-10-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsWy7djP87plQVlxBr3PZCzefdrO5MDo8WvB UtYAxigum5TUnMyy1CJ9uwSujKs/77AUHNStuHJtMmsD41X1LkYODgkBE4lv6wq7GDk5hARW MErsu5UCYbczSVycr9fFyAVktzFJrFz+iwUkAVI/b9V+VojEckaJU//bWCAcoI5zX3rBqtgE bCWOzPzKCmKLCAhIfO5czAZiCwu4S8zv/gEWZxFQlbj94hSYzSvgKnH65H92iA3yEqs3HGAG sTmB4jcmPWeFiM9hk/h8rQbCdpFo2reLCcIWlnh1fAtUr4zE/53zmUAOkhDoZ5TY++8tO4Qz g1Fi9eVZUB3WEof//WYD+Z9ZQFNi/S59iLCjxJx1X9ggwcInceOtIEiYGcictG06M0SYV6Kj TQiiWk/iac9URpi1f9Y+gQaQh8TehZOhYQK0dXnjRKYJjHKzEJYtYGRcxSieWlqcm55abJyX Wq5XnJhbXJqXrpecn7uJERinp/8d/7qDcd+fpEOMAhyMSjy8BmJZcUKsiWXFlbmHGCU4mJVE eOPl0+OEeFMSK6tSi/Lji0pzUosPMUpzsCiJ8xovehkrJJCeWJKanZpakFoEk2Xi4JRqYJyq OOXwE4ellb99r88QWBXItJLz1uLIlrhZOso8oSy6P38sdAno+KbgupDr8Z/ZTR4GeVMe3Dz/ fIvvo7zNRj/4trmnsXB8lDwV+URdiMVg/bvNpTfOtczaGLrm7v9bs4/NWmrwIcj1za5GcfPI iIvv7z7amW/3KfZCr/rHCtmPi159Kpv4rqddiaU4I9FQi7moOBEAtYJGcs8CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHLMWRmVeSWpSXmKPExsVy+t/xu7plQVlxBrdOMVu8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GVd/3mEpOKhbceXaZNYGxqvqXYycHBICJhLzVu1n7WLk4hASWMoocf35FLYuRg6ghIzEh0sC EDXCEn+udbGB2EICrUwSu/rUQGw2AVuJIzO/soLYIgICEp87F4PVCAu4S8zv/gEWZxFQlbj9 4hSYzSvgKnH65H92iJnyEqs3HGAGsTmB4jcmPWeFmO8i8fz/EuYJjLwLGBlWMYqklhbnpucW G+kVJ+YWl+al6yXn525iBIbNtmM/t+xg7HoXfIhRgINRiYfXQCwrTog1say4MvcQowQHs5II b7x8epwQb0piZVVqUX58UWlOavEhRlOgoyYyS4km5wNDOq8k3tDU0NzC0tDc2NzYzEJJnLdD 4GCMkEB6YklqdmpqQWoRTB8TB6dUAyND0Lvf8uf/vV34rKjzNNfTBc0Wxu5/z982Vle3zfkg yrj44g/Lw/7vw8R+umx99rTj18GrVTeC3ivY/k4zUHlx4GO8av6jJ4wyljOXqKi8qdvTW3Zb aqpLYaSNwCVG2QSxP+5Ky4OFTv5+svrRHiPPjqtHVF+sXql9U3pDc+Sr/Oe//CcrlzoosRRn JBpqMRcVJwIAoF/HDDECAAA= X-CMS-MailID: 20200312151710eucas1p22f051449e6e7edeadefe65b66ffaed32 X-Msg-Generator: CA X-RootMTR: 20200312151710eucas1p22f051449e6e7edeadefe65b66ffaed32 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151710eucas1p22f051449e6e7edeadefe65b66ffaed32 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 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" Signed-off-by: Lukasz Wojciechowski Change-Id: Id1543157b4ce89bd5ec07fc46ff67b65ec3b4a89 --- app/test/test_security.c | 160 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index 647a2dd0a..dc11b96ff 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -1118,6 +1118,153 @@ test_rte_security_session_stats_get_success(void) } +/** + * rte_security_session_destroy tests + */ + +/** + * Test execution of rte_security_session_destroy with NULL instance + */ +static int +test_rte_security_session_destroy_inv_param_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_rte_security_session_destroy_inv_param_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_rte_security_session_destroy_inv_param_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_rte_security_session_destroy_inv_param_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_rte_security_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_rte_security_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 */ @@ -1182,6 +1329,19 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_rte_security_session_stats_get_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_destroy_inv_param_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_destroy_inv_param_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_destroy_inv_param_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_destroy_inv_param_session), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_destroy_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_session_destroy_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Thu Mar 12 15:16: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: 66599 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 88E59A056D; Thu, 12 Mar 2020 16:19:32 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 235FB1C0CE; Thu, 12 Mar 2020 16:17:25 +0100 (CET) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 10C621BFBF for ; Thu, 12 Mar 2020 16:17:11 +0100 (CET) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151710euoutp01c9d29802ae89516b7927cfd60c1cb9d3~7l3bkX-xQ0474204742euoutp01E for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200312151710euoutp01c9d29802ae89516b7927cfd60c1cb9d3~7l3bkX-xQ0474204742euoutp01E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026230; bh=dn0wr9Wp6Y8StzL2s7wq+NPqdjDPCu2dmcQiGHjSTaw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FihYWITiRPnS1PA/Px9GwWw4VXWkM08ieTDuXHKO9vUd+eyme0CeE6BEuyM4YceOB JlO1OJaQzF/kS9n2QDHIORenJA7BKaw4Mynailed3GjpK2SRXzlzmp3aStH8rJhpsN c0OdSta9IxmkTEuE46l9d8FR6f+nBuBgix3jDsVw= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200312151710eucas1p125e9705aeaa33f31bd3b0bc9c82d4276~7l3bW_PVG1595115951eucas1p1i for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 2B.B9.60698.6725A6E5; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200312151710eucas1p10124737620ec6414aa593e7fa67ee56b~7l3bGebbT0788307883eucas1p18 for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151710eusmtrp2e49e130299f524cbfc9c78e8cf7ff104~7l3bF_Qbd1238312383eusmtrp2O for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-a9-5e6a5276e3d7 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 52.2D.07950.6725A6E5; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151710eusmtip1856ab0de4d5229c683f36af768507a23~7l3a3tMYM1547415474eusmtip1Y for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:51 +0100 Message-Id: <20200312151654.7218-11-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPIsWRmVeSWpSXmKPExsWy7djPc7plQVlxBi9fqFi8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGb2/djAWvLWpmPn7P2MD41STLkYODgkBE4k9a/m7GLk4hARW MEpsXjeXHcJpZ5K4efM2E4TTxiTxsGk2UIYTrKPpVQ8jRGI5o8T6+c/Z4FpeH13BAlLFJmAr cWTmV1YQW0RAQOJz52I2EFtYwENi3ZL/zCA2i4CqxL77B8DqeQVcJXZvuM4IsUFeYvWGA2A1 nEDxG5Oes4IskBCYwyaxY910qDNcJCbtO8UEYQtLvDq+BSouI/F/53wmiIZ+Rom9/96yQzgz GCVWX54F1WEtcfjfbzZQEDALaEqs36UPEXaUWNO4hQkSMnwSN94KgoSZgcxJ26YzQ4R5JTra hCCq9SSe9kxlhFn7Z+0TFgjbQ+Lj3xvQcATaOv91E/sERrlZCMsWMDKuYhRPLS3OTU8tNs5L LdcrTswtLs1L10vOz93ECIzW0/+Of93BuO9P0iFGAQ5GJR5eA7GsOCHWxLLiytxDjBIczEoi vPHy6XFCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeY0XvYwVEkhPLEnNTk0tSC2CyTJxcEo1MN5N dfuj4HK3mIFxxuqsTQnt83fclo9cL7xpx9yALs9s88SIsBOF+7/5rAxm7X8x0eKv0MvE4Lq4 NobV9RYst/xKV4oYHcq49cVnq5vLjRyF5nS/uqzna19+VFi67fqDlk9b55b5dRxRFj9jN+GI uUVE7TzHf1we1WHsdYePimyd+EPBP6PhrxJLcUaioRZzUXEiACcE98DSAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHLMWRmVeSWpSXmKPExsVy+t/xu7plQVlxBrdvCFi8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 Gb2/djAWvLWpmPn7P2MD41STLkZODgkBE4mmVz2MILaQwFJGiZ17ZbsYOYDiMhIfLglAlAhL /LnWxdbFyAVU0sok8f/XVGaQBJuArcSRmV9ZQWwRAQGJz52L2UBsYQEPiXVL/oPVsAioSuy7 f4AFxOYVcJXYveE6I8RQeYnVGw6A1XACxW9Mes4KcYOLxPP/S5gnMPIuYGRYxSiSWlqcm55b bKRXnJhbXJqXrpecn7uJERg224793LKDsetd8CFGAQ5GJR5eA7GsOCHWxLLiytxDjBIczEoi vPHy6XFCvCmJlVWpRfnxRaU5qcWHGE2BjprILCWanA8M6bySeENTQ3MLS0NzY3NjMwslcd4O gYMxQgLpiSWp2ampBalFMH1MHJxSDYwqpk4XH3+7wniBIb2gKyHgZ266wppPy6bercwOFdSY UvFghXj4M+aK/7ef6X8MLuZlPjt7z+FuCdNL+6uPOj3I2b2K6TTLM+1b7hNO3byl8E5/zdPd 4le2vHPXTVEL6NgYY667/nGsarl+y4mEIy7uyk5uZyT7y8y2Rz6YXqwlwBz1vmdh5C0lluKM REMt5qLiRAAODhC4MQIAAA== X-CMS-MailID: 20200312151710eucas1p10124737620ec6414aa593e7fa67ee56b X-Msg-Generator: CA X-RootMTR: 20200312151710eucas1p10124737620ec6414aa593e7fa67ee56b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151710eucas1p10124737620ec6414aa593e7fa67ee56b References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 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" Signed-off-by: Lukasz Wojciechowski Change-Id: Id5b4304e83a12443c62557c2a917125084e14f6b --- app/test/test_security.c | 204 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index dc11b96ff..fa9141f89 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -341,6 +341,38 @@ mock_session_destroy(void *device, 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 * @@ -359,6 +391,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, }; @@ -450,12 +483,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; } @@ -1265,6 +1300,160 @@ test_rte_security_session_destroy_success(void) } +/** + * rte_security_set_pkt_metadata tests + */ + +/** + * Test execution of rte_security_set_pkt_metadata with NULL instance + */ +static int +test_rte_security_set_pkt_metadata_inv_param_context(void) +{ + 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; +} + +/** + * Test execution of rte_security_set_pkt_metadata with invalid + * security operations structure (NULL) + */ +static int +test_rte_security_set_pkt_metadata_inv_param_context_ops(void) +{ + 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; +} + +/** + * Test execution of rte_security_set_pkt_metadata with empty + * security operations + */ +static int +test_rte_security_set_pkt_metadata_inv_param_context_ops_fun(void) +{ + 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; +} + +/** + * Test execution of rte_security_set_pkt_metadata with NULL sess parameter + */ +static int +test_rte_security_set_pkt_metadata_inv_param_session(void) +{ + 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; +} + +/** + * Test execution of rte_security_set_pkt_metadata with NULL m parameter + */ +static int +test_rte_security_set_pkt_metadata_inv_param_m(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + int params; + + int ret = rte_security_set_pkt_metadata(&ut_params->ctx, ut_params->sess, + NULL, ¶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; +} + +/** + * Test execution of rte_security_set_pkt_metadata when set_pkt_metadata + * security operation fails + */ +static int +test_rte_security_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_rte_security_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 */ @@ -1342,6 +1531,21 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_rte_security_session_destroy_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_set_pkt_metadata_inv_param_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_set_pkt_metadata_inv_param_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_set_pkt_metadata_inv_param_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_set_pkt_metadata_inv_param_session), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_set_pkt_metadata_inv_param_m), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_set_pkt_metadata_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_set_pkt_metadata_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Thu Mar 12 15:16: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: 66600 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 B5512A056D; Thu, 12 Mar 2020 16:19:53 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4DA621C0D8; Thu, 12 Mar 2020 16:17:26 +0100 (CET) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 424C82BE6 for ; Thu, 12 Mar 2020 16:17:11 +0100 (CET) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151711euoutp023c79cf32df528be67c2da03681489692~7l3bwgZF62886028860euoutp026 for ; Thu, 12 Mar 2020 15:17:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200312151711euoutp023c79cf32df528be67c2da03681489692~7l3bwgZF62886028860euoutp026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026231; bh=ur16/Xz8RWoRsBV/JcoOCdDJVx6UqdV9MW9Hap+r3BE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=of1qpjoD29pSSfUk87ma69/0lNEHYMaRxdir8ujqc8/N2XEp5Xvf7SNp71iXVwdTL OWNX3LGMZcUIA+T+pTB4/6L4u3qVgsTqOdQ/PwW0a7Ai+extIknnmYPq2HHAM+R3I1 a9b6FWFv4O7oPIflVbUtuCNEEzM6kxJi6ssGvtqQ= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200312151710eucas1p1cc0127ed7ed5f1815287ed9343eda99e~7l3boN8JD0077900779eucas1p1X for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id D2.62.61286.6725A6E5; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200312151710eucas1p1c3590b55d00bea25b26539a560199b96~7l3bUpNCf1794017940eucas1p1d for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151710eusmtrp2aadf893cd6feef6d314c20bc4fd5e7f8~7l3bUJKG01238312383eusmtrp2P for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-be-5e6a52765fc9 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 42.3F.08375.6725A6E5; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151710eusmtip1d37df7a53f160a0fddca16ac27682d2d~7l3bElQnf1532415324eusmtip1T for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:52 +0100 Message-Id: <20200312151654.7218-12-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsWy7djPc7plQVlxBk+PGlm8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGTMWrWYq6LCuONBk1cB41bCLkZNDQsBEou9MO1MXIxeHkMAK RomD776zQDjtTBIr9hxlh3DamCROH77AAtNy+dkVVojEckaJliUHEFqm7f/ACFLFJmArcWTm V1YQW0RAQOJz52K2LkYODmEBF4mOW04gJouAqsTRex4gFbwCrhLXLvxhhJgvL7F6wwFmEJsT KH5j0nNWiPgMNok3czkgbBeJzoeroeqFJV4d38IOYctI/N85H+wdCYF+Rom9/96yQzgzGCVW X57FBFFlLXH432+we5gFNCXW79KHCDtKtJ8+yggSlhDgk7jxVhAkzAxkTto2nRkizCvR0SYE Ua0n8bRnKiPM2j9rn7BAlHhI7OzKgQQI0NKXO4+xTWCUm4WwawEj4ypG8dTS4tz01GLDvNRy veLE3OLSvHS95PzcTYzAKD397/inHYxfLyUdYhTgYFTi4TUQy4oTYk0sK67MPcQowcGsJMIb L58eJ8SbklhZlVqUH19UmpNafIhRmoNFSZzXeNHLWCGB9MSS1OzU1ILUIpgsEwenVANj4N9D WVuYf5l4X3a/zFO8Q/VlBfPHG7b8dnpZut8k01UuFNwX+Lsj+5J6uqFN48KI14c3TM522b7x 6t45rFOWNMaYbWEP/6WxLtLy4avVV/JUHrZGOO4NWXxLnWv6nY2rli62UN39oivM/HeO3oG0 y48zY/bucrwQ63WQ52RrecSpNRd/Pp/eosRSnJFoqMVcVJwIAPWsS3XOAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprDLMWRmVeSWpSXmKPExsVy+t/xu7plQVlxBn/PyFq8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GTMWrWYq6LCuONBk1cB41bCLkZNDQsBE4vKzK6xdjFwcQgJLGSW231vP3MXIAZSQkfhwSQCi Rljiz7UuNoiaViaJqWeOsoEk2ARsJY7M/MoKYosICEh87lzMBtIrLOAi0XHLCcRkEVCVOHrP A6SCV8BV4tqFP4wQI+UlVm84wAxicwLFb0x6DjZFCKjz+f8lzBMYeRcwMqxiFEktLc5Nzy02 1CtOzC0uzUvXS87P3cQIDJltx35u3sF4aWPwIUYBDkYlHl4Dsaw4IdbEsuLK3EOMEhzMSiK8 8fLpcUK8KYmVValF+fFFpTmpxYcYTYFumsgsJZqcDwznvJJ4Q1NDcwtLQ3Njc2MzCyVx3g6B gzFCAumJJanZqakFqUUwfUwcnFINjDq3vtiZrZNMSM6N/vri1rF3Gx6qTb30Vjj6sPm20GWf Xe4/6H4847z3PN2tec2PtFOXmDbarMmT0pY+28H+qLXGrytR+vr5tR0HpA0bFcXUen4EdVj/ jo2Wlct+eeWh9a1pbZMi76jIbHjUpXnx5JLe5WJMxZx2PFzO7333XHB+ahYubcg1SYmlOCPR UIu5qDgRAK9HmEkvAgAA X-CMS-MailID: 20200312151710eucas1p1c3590b55d00bea25b26539a560199b96 X-Msg-Generator: CA X-RootMTR: 20200312151710eucas1p1c3590b55d00bea25b26539a560199b96 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151710eucas1p1c3590b55d00bea25b26539a560199b96 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 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" Signed-off-by: Lukasz Wojciechowski Change-Id: I310b40b7e3749efde96d27fe2b448410a33c51c4 --- app/test/test_security.c | 178 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index fa9141f89..e8aba2870 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -75,6 +75,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. @@ -99,6 +112,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. @@ -373,6 +395,42 @@ 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 * @@ -392,6 +450,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, }; @@ -484,6 +543,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; @@ -491,6 +551,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; } @@ -1454,6 +1515,112 @@ test_rte_security_set_pkt_metadata_success(void) } +/** + * rte_security_get_userdata tests + */ + +/** + * Test execution of rte_security_get_userdata with NULL instance + */ +static int +test_rte_security_get_userdata_inv_param_context(void) +{ + 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; +} + +/** + * Test execution of rte_security_get_userdata with invalid + * security operations structure (NULL) + */ +static int +test_rte_security_get_userdata_inv_param_context_ops(void) +{ + 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; +} + +/** + * Test execution of rte_security_get_userdata with empty + * security operations + */ +static int +test_rte_security_get_userdata_inv_param_context_ops_fun(void) +{ + 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; +} + +/** + * Test execution of rte_security_get_userdata when get_userdata + * security operation fails + */ +static int +test_rte_security_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_rte_security_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 */ @@ -1546,6 +1713,17 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_rte_security_set_pkt_metadata_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_get_userdata_inv_param_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_get_userdata_inv_param_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_get_userdata_inv_param_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_get_userdata_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_get_userdata_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Thu Mar 12 15:16: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: 66601 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 9C6C4A056D; Thu, 12 Mar 2020 16:20:07 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6EF831C10C; Thu, 12 Mar 2020 16:17:27 +0100 (CET) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id A0AE42BE6 for ; Thu, 12 Mar 2020 16:17:11 +0100 (CET) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151711euoutp02d38dade6c64d8db7c983eb9fed2f5302~7l3cJNQS22892528925euoutp02z for ; Thu, 12 Mar 2020 15:17:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200312151711euoutp02d38dade6c64d8db7c983eb9fed2f5302~7l3cJNQS22892528925euoutp02z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026231; bh=XTYbNWcrP25QCQQf/+gPRqGFbyG15EJfzn5VU3HEW0Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=S5LwNxcsQnrDA2LpspRDsNWYOH+/1HCyRLyutM82j/OI3Azcf2I84kqrLVQVlLaLC 9EFQR//iHeyu4riSNWuES+bbYdUZ+ZKllVZ+QSuuhN9QfJIoU2b9LlqKD2ykmqUqJy MTtKq+lUaFlic0z+vrwPLlQsRBrv28Ii3j2Mx4W4= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200312151711eucas1p1c3c7876942e2c02df9e4f63f9a3e425d~7l3buKhIj1794017940eucas1p1e for ; Thu, 12 Mar 2020 15:17:11 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id F2.62.61286.6725A6E5; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200312151710eucas1p21882b138d4fd79753f993c30c997e615~7l3bgder31698716987eucas1p2y for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151710eusmtrp2364d8a76f6ef7b5225dfa2cabf10cb9a~7l3bgB3Mt1238312383eusmtrp2Q for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-c0-5e6a52763c70 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 62.3F.08375.6725A6E5; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151710eusmtip19317a169ef5581543d77f85d3926792a~7l3bQx_Ux1547515475eusmtip1Q for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:53 +0100 Message-Id: <20200312151654.7218-13-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrHIsWRmVeSWpSXmKPExsWy7djPc7plQVlxBptu2Fi8+7SdyYHR49eC pawBjFFcNimpOZllqUX6dglcGQ/uTGQveKRT8f/lM+YGxq1qXYycHBICJhI/ry5l7mLk4hAS WMEo8erKLSinnUniT/MTRginjUli2+9JzDAtc77OYQKxhQSWM0psmmAF13Hi/AE2kASbgK3E kZlfWUFsEQEBic+di8HiwgIeEnMWLGPvYuTgYBFQlZi9ix0kzCvgKvH0x1dGiPnyEqs3HADb xQkUvzHpOSvIfAmBBWwSb16+gDrCRWLmqkvsELawxKvjW6BsGYn/O+czQTT0M0rs/feWHcKZ wSix+vIsJogqa4nD/36zgVzBLKApsX6XPkTYUeL+VIjjJAT4JG68FQQJMwOZk7ZNZ4YI80p0 tAlBVOtJPO2Zygiz9s/aJywQtofE/s1H2CFhArR15f8nLBMY5WYhLFvAyLiKUTy1tDg3PbXY MC+1XK84Mbe4NC9dLzk/dxMjMFZP/zv+aQfj10tJhxgFOBiVeHgNxLLihFgTy4orcw8xSnAw K4nwxsunxwnxpiRWVqUW5ccXleakFh9ilOZgURLnNV70MlZIID2xJDU7NbUgtQgmy8TBKdXA aHBV7L9PmuShjtntCbbnDiXFm5Wc7glmPvajdcJesa27ahdP8TefkOGzPXfu4WmBX2NW3Fm3 ueTOxkes77RO7OiILt5xpTva/+KbLaJtH+fUefX1WmWVf9y+Ujz8477FocxZabYcr+zEnRY8 nCLapixZOOeb6b//YotMjjcwWngemHXg9YvmIiWW4oxEQy3mouJEAGITkA/RAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprLLMWRmVeSWpSXmKPExsVy+t/xu7plQVlxBisXalm8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GQ/uTGQveKRT8f/lM+YGxq1qXYycHBICJhJzvs5hArGFBJYySlzbwtLFyAEUl5H4cEkAokRY 4s+1LrYuRi6gklYmiU2zZzKCJNgEbCWOzPzKCmKLCAhIfO5czAZiCwt4SMxZsIwdZA6LgKrE 7F3sIGFeAVeJpz++MkLMlJdYveEAM4jNCRS/Mek5K8QJLhLP/y9hnsDIu4CRYRWjSGppcW56 brGhXnFibnFpXrpecn7uJkZg0Gw79nPzDsZLG4MPMQpwMCrx8BqIZcUJsSaWFVfmHmKU4GBW EuGNl0+PE+JNSaysSi3Kjy8qzUktPsRoCnTTRGYp0eR8YEDnlcQbmhqaW1gamhubG5tZKInz dggcjBESSE8sSc1OTS1ILYLpY+LglGpgZPjy5/XS6RsnnEjk2xs+p+Xyxn4OE0Mj59LneyfM Wavdsj3la+CzCyy5NS0Bf25xB/jaRN3psG3JPXbi1baY3tXaL7b9nB3YPOPS2pb7S7Ypf3nj FOz2+0LHb9P71fI8YaHH1wb0PGZ2sl9du+De9Jef9y2ZOKHB6MCLN/3CVhs2lZ6uWat777kS S3FGoqEWc1FxIgBLIHpZMAIAAA== X-CMS-MailID: 20200312151710eucas1p21882b138d4fd79753f993c30c997e615 X-Msg-Generator: CA X-RootMTR: 20200312151710eucas1p21882b138d4fd79753f993c30c997e615 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151710eucas1p21882b138d4fd79753f993c30c997e615 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 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" Signed-off-by: Lukasz Wojciechowski Change-Id: Iaa273d1b4e663a6238ad67bbf0ec6dd40c21d075 --- app/test/test_security.c | 137 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index e8aba2870..895e4a03e 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -431,6 +431,29 @@ 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 * @@ -451,6 +474,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, }; @@ -544,6 +568,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; @@ -552,6 +577,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; } @@ -1621,6 +1647,106 @@ test_rte_security_get_userdata_success(void) } +/** + * rte_security_capabilities_get tests + */ + +/** + * Test execution of rte_security_capabilities_get with NULL instance + */ +static int +test_rte_security_capabilities_get_inv_param_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_rte_security_capabilities_get_inv_param_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_rte_security_capabilities_get_inv_param_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_rte_security_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_rte_security_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 */ @@ -1724,6 +1850,17 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_rte_security_get_userdata_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capabilities_get_inv_param_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capabilities_get_inv_param_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capabilities_get_inv_param_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capabilities_get_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capabilities_get_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; From patchwork Thu Mar 12 15:16: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: 66602 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 283AFA056D; Thu, 12 Mar 2020 16:20:31 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 814E01C116; Thu, 12 Mar 2020 16:17:28 +0100 (CET) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id CFF341BFC9 for ; Thu, 12 Mar 2020 16:17:11 +0100 (CET) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200312151711euoutp01b71eb1662f7dd42dffd21442d815ef83~7l3cTVxWm0593705937euoutp01L for ; Thu, 12 Mar 2020 15:17:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200312151711euoutp01b71eb1662f7dd42dffd21442d815ef83~7l3cTVxWm0593705937euoutp01L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584026231; bh=lw4bU9RQsNg8xU1Drw4oVUPdCtfTsnP7I7lwcqoGLQk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sf4VLCSW3Wzbn1aXK0yGtzxjpBmcrwXkNY0LVxWG3ukpex1HI8nqyEzPQ/Cq7yjdS OKLl16C0uLnSRKg79Mhn28lZYY+CPg+uDTShRAVqS8ZZncHU7ezrdieogFo/9As3++ qSzOrpWhep0qNYFL2NCZrQy1DDKaoLvrkMUNXuRs= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200312151711eucas1p1a9263209a126ee5152c780123a4720ef~7l3cFaVph0788407884eucas1p15 for ; Thu, 12 Mar 2020 15:17:11 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 3F.BD.60679.7725A6E5; Thu, 12 Mar 2020 15:17:11 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200312151710eucas1p1fd5b1484c9ee807327d2d34511a47a12~7l3bqMVrd1600616006eucas1p1b for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200312151710eusmtrp25f0db73fcb66271e7159c31825c9b642~7l3bpvgy41238412384eusmtrp2K for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-31-5e6a5277d84a Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id A2.2D.07950.6725A6E5; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) Received: from Padamandas.example.org (unknown [106.120.51.19]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200312151710eusmtip1e61467ed058068d4ac64f846f681b2f4~7l3bc68Nd0799007990eusmtip1Z for ; Thu, 12 Mar 2020 15:17:10 +0000 (GMT) From: Lukasz Wojciechowski To: dev@dpdk.org Date: Thu, 12 Mar 2020 16:16:54 +0100 Message-Id: <20200312151654.7218-14-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrIIsWRmVeSWpSXmKPExsWy7djP87rlQVlxBh3fRS3efdrO5MDo8WvB UtYAxigum5TUnMyy1CJ9uwSujBvtS1kL/nUwVhxbd4a1gfF2SRcjJ4eEgInEty/97F2MXBxC AisYJd7d+MkE4bQzScxsO8EI4bQxSUyc8YEFpuXhtm5WiMRyRomWNT9Z4VoatjxmA6liE7CV ODLzKyuILSIgIPG5czFYXFjATeLL8qNgk1gEVCU+XzoMFucVcJV4v6oVaoO8xOoNB5hBbE6g +I1Jz8EWSAhMYZNYdPYiI0SRi8SEw9dYIWxhiVfHt7BD2DIS/3fOZ4Jo6GeU2PvvLTuEM4NR YvXlWUwQVdYSh//9BlrNwcEsoCmxfpc+RNhRYmdfHwtIWEKAT+LGW0GQMDOQOWnbdGaIMK9E R5sQRLWexNOeqYwwa/+sfQJ1v4fEjPXToIECtPXh68nMExjlZiEsW8DIuIpRPLW0ODc9tdgo L7Vcrzgxt7g0L10vOT93EyMwYk//O/5lB+OuP0mHGAU4GJV4eA3EsuKEWBPLiitzDzFKcDAr ifDGy6fHCfGmJFZWpRblxxeV5qQWH2KU5mBREuc1XvQyVkggPbEkNTs1tSC1CCbLxMEp1cC4 deeGt4nla5plXS957lcV/37CPHdB2eHHNZb8z9/qvX7G5l+RXv/3WMp03qD06qd3z/AfNrp+ t145Q/GJ4t9dGfvW5G2aw/L/gIMtl51z5YTr9+fZvY1L+Zi6pNzFstbqhirflaJw8xOeX75s FDll2Voxa/ej983LDZTlrUJaTXhctv3OvZqixFKckWioxVxUnAgAbvFzbNQCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHLMWRmVeSWpSXmKPExsVy+t/xu7plQVlxBvcnm1m8+7SdyYHR49eC pawBjFF6NkX5pSWpChn5xSW2StGGFkZ6hpYWekYmlnqGxuaxVkamSvp2NimpOZllqUX6dgl6 GTfal7IW/OtgrDi27gxrA+Ptki5GTg4JAROJh9u6WUFsIYGljBKnflR3MXIAxWUkPlwSgCgR lvhzrYsNoqSVSWLqYV4Qm03AVuLIzK9grSICAhKfOxeD1QgLuEl8WX6UBcRmEVCV+HzpMFic V8BV4v2qVhaImfISqzccYAaxOYHiNyY9hzrBReL5/yXMExh5FzAyrGIUSS0tzk3PLTbSK07M LS7NS9dLzs/dxAgMm23Hfm7Zwdj1LvgQowAHoxIPr4FYVpwQa2JZcWXuIUYJDmYlEd54+fQ4 Id6UxMqq1KL8+KLSnNTiQ4ymQEdNZJYSTc4HhnReSbyhqaG5haWhubG5sZmFkjhvh8DBGCGB 9MSS1OzU1ILUIpg+Jg5OqQbGSXP2sPo7Bzqvbau7Y6Nk9/LibQFjx/0x+XI3jI/8Wv45fhWP 4rzbWkqtJ2y/nm0xM+ZaevhEaoRH8BKOu8XXt9VIm27tEum3S5ky5UDZ972VE+7uOnptxvZt 83z1PzTF2bwq433MkfZplmHht+IvdrMFLHZn5u816zq9VWxlTOzq/2fUZ2/rU2Ipzkg01GIu Kk4EADzT5DkxAgAA X-CMS-MailID: 20200312151710eucas1p1fd5b1484c9ee807327d2d34511a47a12 X-Msg-Generator: CA X-RootMTR: 20200312151710eucas1p1fd5b1484c9ee807327d2d34511a47a12 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200312151710eucas1p1fd5b1484c9ee807327d2d34511a47a12 References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH 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" Signed-off-by: Lukasz Wojciechowski Change-Id: I228cba78333b54aee3b50e89709b438e45f374db --- 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 895e4a03e..d28bab16a 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -1747,6 +1747,497 @@ test_rte_security_capabilities_get_success(void) } +/** + * rte_security_capability_get tests + */ + +/** + * Test execution of rte_security_capability_get with NULL instance + */ +static int +test_rte_security_capability_get_inv_param_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_rte_security_capability_get_inv_param_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_rte_security_capability_get_inv_param_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_rte_security_capability_get_inv_param_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_rte_security_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_rte_security_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_rte_security_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_rte_security_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_rte_security_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_rte_security_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_rte_security_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_rte_security_capability_get_ipsec_mismatch_direction(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_rte_security_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_rte_security_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_rte_security_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 */ @@ -1861,6 +2352,37 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_rte_security_capabilities_get_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_inv_param_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_inv_param_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_inv_param_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_inv_param_idx), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_empty_table), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_no_matching_action), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_no_matching_protocol), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_no_support_for_macsec), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_ipsec_mismatch_proto), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_ipsec_mismatch_mode), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_ipsec_mismatch_direction), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_ipsec_match), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_pdcp_mismatch_domain), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_rte_security_capability_get_pdcp_match), + TEST_CASES_END() /**< NULL terminate unit test array */ } };