From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CDE53A0597; Wed, 8 Apr 2020 05:16:34 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 160171C0C2; Wed, 8 Apr 2020 05:15:06 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 7B4691BFEF for ; Wed, 8 Apr 2020 05:14:54 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200408031454euoutp02461fba4d8a6a38a53e20a9e7013ec59c~DubgmGGs_2216822168euoutp02H for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200408031454euoutp02461fba4d8a6a38a53e20a9e7013ec59c~DubgmGGs_2216822168euoutp02H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586315694; bh=8VegCETjPiT4EPKmJx9B77YVijkzsbz01Ic1CnoLdUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M+eoWrMVA2Yk7d1/mpCgYGtQCGOqslhP+N/MGsUEc1F+hZh+X+81VIclSKFeC4ZiI vWrHw5vt0vSQitmZtJGRG4+Wx8EWH6VeePiTI+OFa0fXUdFNR2X5uN/YnwJz6dbRe7 e3PLtP+8zcPQMyxyCuYvXHrK38wtV599Zpy6d6Dc= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200408031454eucas1p25b550bef399e438bee71be4aef454d99~Dubgg7stK3007630076eucas1p2r for ; Wed, 8 Apr 2020 03:14:54 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 3A.47.60679.EA14D8E5; Wed, 8 Apr 2020 04:14:54 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200408031453eucas1p1b26ad6b1f924b817e83fc2d2d61a0b0b~Dubf9_6wl2413824138eucas1p1X for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200408031453eusmtrp24602df414e9119f843ccb3b218dcbda1~Dubf9hL3M2369123691eusmtrp2C for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-61-5e8d41ae6c64 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id A2.DA.08375.DA14D8E5; Wed, 8 Apr 2020 04:14:53 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200408031453eusmtip1bba9834aca0dff7b7e1224ec30ce467c~Dubfno23-2835528355eusmtip1h for ; Wed, 8 Apr 2020 03:14:53 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Wed, 8 Apr 2020 05:13:49 +0200 Message-Id: <20200408031351.4288-12-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFIsWRmVeSWpSXmKPExsWy7djPc7rrHHvjDKafY7d492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4Mlbvb2Mq2GhdMXnbc+YGxmuGXYycHBICJhKnn31l7GLk4hAS WMEoMfP+RRYIp51JYt/l2+wgVUICbUwS7Rs8YToOT9nIClG0nFFiy4ReZggHqOj5nV9sIFVs ArYSR2Z+ZQWxRQRYJF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YmH90FiT5wQa2JZ cWXuIUYJDmYlEV6p3s44Id6UxMqq1KL8+KLSnNTiQ4ymQDdNZJYSTc4HhnpeSbyhqaG5haWh ubG5sZmFkjhvh8DBGCGB9MSS1OzU1ILUIpg+Jg5OqQZGzoYj9WclypRNVvmZWHLrGjH/Xxy/ fu0vvplaDw6oCrsXdUys//487ccOixPuE7qFOQO8zqsFNGz7FX5vbjvn6ZuVJ8/J3Zr/Oncb 6/KiRZqd2U/M0ic8nL9O/b1B4Mzvp0+Kn07aI5J38+8cXhmrix+bdtU+1q1I2rFoR0G4ZCWj m5+TdbWHEktxRqKhFnNRcSIA4aT0Sz0CAAA= X-CMS-MailID: 20200408031453eucas1p1b26ad6b1f924b817e83fc2d2d61a0b0b X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200408031453eucas1p1b26ad6b1f924b817e83fc2d2d61a0b0b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200408031453eucas1p1b26ad6b1f924b817e83fc2d2d61a0b0b References: <20200312151654.7218-1-l.wojciechow@partner.samsung.com> <20200408031351.4288-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v2 11/13] app/test: add rte security get userdata tests X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add unit tests for rte_security_get_userdata function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 191 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index a1f0e7879..230b53891 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -76,6 +76,19 @@ #define MOCK_TEST_ASSERT_EQUAL(fail_counter, a, b, msg, ...) \ MOCK_TEST_ASSERT(fail_counter, (a) == (b), msg, ##__VA_ARGS__) +/** + * Verify not null condition inside mocked up function. + * Mockup function cannot return a test error, so the failure + * of assertion increases counter and print logs. + * The counter can be verified later to check if test case should fail. + * + * @param fail_counter fail counter + * @param val value expected not to be NULL + * @param msg printf style formatting string for custom message + */ +#define MOCK_TEST_ASSERT_NOT_NULL(fail_counter, val, msg, ...) \ + MOCK_TEST_ASSERT(fail_counter, (val) != NULL, msg, ##__VA_ARGS__) + /** * Verify if parameter of the mocked up function matches expected value. @@ -101,6 +114,15 @@ #define MOCK_TEST_ASSERT_POINTER_PARAMETER(data, parameter) \ MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%p") +/** + * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for uint64_t type parameters. + * + * @param data structure with expected values + * @param parameter name of the parameter (both field and parameter name) + */ +#define MOCK_TEST_ASSERT_U64_PARAMETER(data, parameter) \ + MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%" PRIu64) + /** * Verify number of calls of the mocked up function * and check if there were any fails during execution. @@ -381,6 +403,43 @@ mock_set_pkt_metadata(void *device, return mock_set_pkt_metadata_exp.ret; } +/** + * get_userdata mockup + * + * Verified parameters: device, md. + * The userdata parameter works as an output parameter, so a passed address + * is verified not to be NULL and filled with userdata stored in structure. + */ +static struct mock_get_userdata_data { + void *device; + uint64_t md; + void *userdata; + + int ret; + + int called; + int failed; +} mock_get_userdata_exp = {NULL, 0UL, NULL, 0, 0, 0}; + +static int +mock_get_userdata(void *device, + uint64_t md, + void **userdata) +{ + mock_get_userdata_exp.called++; + + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_get_userdata_exp, device); + MOCK_TEST_ASSERT_U64_PARAMETER(mock_get_userdata_exp, md); + + MOCK_TEST_ASSERT_NOT_NULL(mock_get_userdata_exp.failed, + userdata, + "Expecting parameter userdata not to be NULL but it's %p", + userdata); + *userdata = mock_get_userdata_exp.userdata; + + return mock_get_userdata_exp.ret; +} + /** * empty_ops * @@ -400,6 +459,7 @@ struct rte_security_ops mock_ops = { .session_stats_get = mock_session_stats_get, .session_destroy = mock_session_destroy, .set_pkt_metadata = mock_set_pkt_metadata, + .get_userdata = mock_get_userdata, }; @@ -495,6 +555,7 @@ ut_setup(void) mock_session_stats_get_exp.called = 0; mock_session_destroy_exp.called = 0; mock_set_pkt_metadata_exp.called = 0; + mock_get_userdata_exp.called = 0; mock_session_create_exp.failed = 0; mock_session_update_exp.failed = 0; @@ -502,6 +563,7 @@ ut_setup(void) mock_session_stats_get_exp.failed = 0; mock_session_destroy_exp.failed = 0; mock_set_pkt_metadata_exp.failed = 0; + mock_get_userdata_exp.failed = 0; return TEST_SUCCESS; } @@ -1478,6 +1540,124 @@ test_set_pkt_metadata_success(void) } +/** + * rte_security_get_userdata tests + */ + +/** + * Test execution of rte_security_get_userdata with NULL instance + */ +static int +test_get_userdata_inv_context(void) +{ +#ifdef RTE_LIBRTE_SECURITY_DEBUG + uint64_t md = 0xDEADBEEF; + + void *ret = rte_security_get_userdata(NULL, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_get_userdata with invalid + * security operations structure (NULL) + */ +static int +test_get_userdata_inv_context_ops(void) +{ +#ifdef RTE_LIBRTE_SECURITY_DEBUG + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + ut_params->ctx.ops = NULL; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_get_userdata with empty + * security operations + */ +static int +test_get_userdata_inv_context_ops_fun(void) +{ +#ifdef RTE_LIBRTE_SECURITY_DEBUG + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + ut_params->ctx.ops = &empty_ops; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_get_userdata when get_userdata + * security operation fails + */ +static int +test_get_userdata_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + void *userdata = (void *)0x7E577E57; + + mock_get_userdata_exp.device = NULL; + mock_get_userdata_exp.md = md; + mock_get_userdata_exp.userdata = userdata; + mock_get_userdata_exp.ret = -1; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_get_userdata in successful execution path + */ +static int +test_get_userdata_success(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + void *userdata = (void *)0x7E577E57; + + mock_get_userdata_exp.device = NULL; + mock_get_userdata_exp.md = md; + mock_get_userdata_exp.userdata = userdata; + mock_get_userdata_exp.ret = 0; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, userdata, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1); + + return TEST_SUCCESS; +} + + /** * Declaration of testcases */ @@ -1568,6 +1748,17 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_set_pkt_metadata_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; -- 2.17.1