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 E3DA0A0597; Thu, 9 Apr 2020 19:27:25 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 297F91D428; Thu, 9 Apr 2020 19:25:50 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 126E81D152 for ; Thu, 9 Apr 2020 19:25:37 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200409172536euoutp0121cfd6bd344f088ec147f8e78749daaa~ENrj9wYct0978309783euoutp01u for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200409172536euoutp0121cfd6bd344f088ec147f8e78749daaa~ENrj9wYct0978309783euoutp01u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1586453136; bh=VBX15qrJrVOvkAVv2EZtrvyLR1nuCRIAyYS5gjixiDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hoIotLdd7Dse3DQgcOPgb+NHqt8IYIbmzwY3qQ8JABsuYxHVLXJFVO+DIhj4Zunt5 VszpG+s15gG4xpMJwD5hohN7jed/zRh7L9n5KAp4gc8VN7eC3SRUw02CBsz6NSOPov aaeTzvFhmrowDFoi+i19aEfiAiEyIr5buVw6t8Gw= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200409172536eucas1p2a145c3adbf0472bf007692af93a79a4c~ENrjxL1Q80102601026eucas1p2E for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id C2.50.60679.09A5F8E5; Thu, 9 Apr 2020 18:25:36 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200409172536eucas1p282854dae8a3b6cceafdea5e2f4fa0896~ENrjQmXFU1612816128eucas1p2H for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200409172536eusmtrp19e2e85ab83dfac27f60629033cae0e87~ENrjQGY0E2463624636eusmtrp1O for ; Thu, 9 Apr 2020 17:25:36 +0000 (GMT) X-AuditID: cbfec7f4-0e5ff7000001ed07-dd-5e8f5a9048bd Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 15.48.07950.F8A5F8E5; Thu, 9 Apr 2020 18:25:36 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200409172535eusmtip1167b2fee9fff17199151e132afa7dbb6~ENri4wcCj0696506965eusmtip1S for ; Thu, 9 Apr 2020 17:25:35 +0000 (GMT) From: Lukasz Wojciechowski To: Cc: dev@dpdk.org Date: Thu, 9 Apr 2020 19:25:00 +0200 Message-Id: <20200409172502.1693-12-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409172502.1693-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNIsWRmVeSWpSXmKPExsWy7djPc7oTovrjDC4vUbN492k7kwOjx68F S1kDGKO4bFJSczLLUov07RK4Mj79CSxotK7Ys3sZcwPjMsMuRk4OCQETiaYFP9m7GLk4hARW MEos+bqeFcJpZ5KYOu8kC4TTxiRx4PY8VpiWWasboFqWM0oc2n2HDa7qx99vbCBVbAK2Ekdm fgXrEBFgkVj5/TsLiM0sICDx+N4zsL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pRfnxRaU5q8SFGU6CjJjJLiSbnAwM9ryTe0NTQ3MLS0NzY 3NjMQkmct0PgYIyQQHpiSWp2ampBahFMHxMHp1QD45KHK+/oHHvy8LXkOuHVxctlNsx5qZBf fChlwZFZMbUMWv1L9V4rmKleNDpWMPXi/aPaGdufHy28fOV3qw2n4+H5DmXCO7rjPeQKjskl bOz4I/6+hzfbX+qioa7jLPPXqVHKDyV3by1K2Fet9/SsxTYm+Qd1+5e2T6m9miCdWFtbmB26 /MS5/0osxRmJhlrMRcWJAEUlusY8AgAA X-CMS-MailID: 20200409172536eucas1p282854dae8a3b6cceafdea5e2f4fa0896 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200409172536eucas1p282854dae8a3b6cceafdea5e2f4fa0896 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200409172536eucas1p282854dae8a3b6cceafdea5e2f4fa0896 References: <20200408031351.4288-1-l.wojciechow@partner.samsung.com> <20200409172502.1693-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-dev] [PATCH v3 11/13] app/test: add rte security get userdata tests X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add unit tests for rte_security_get_userdata function. Signed-off-by: Lukasz Wojciechowski --- app/test/test_security.c | 191 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) diff --git a/app/test/test_security.c b/app/test/test_security.c index 193ab2ba9..53b9e122e 100644 --- a/app/test/test_security.c +++ b/app/test/test_security.c @@ -76,6 +76,19 @@ #define MOCK_TEST_ASSERT_EQUAL(fail_counter, a, b, msg, ...) \ MOCK_TEST_ASSERT(fail_counter, (a) == (b), msg, ##__VA_ARGS__) +/** + * Verify not null condition inside mocked up function. + * Mockup function cannot return a test error, so the failure + * of assertion increases counter and print logs. + * The counter can be verified later to check if test case should fail. + * + * @param fail_counter fail counter + * @param val value expected not to be NULL + * @param msg printf style formatting string for custom message + */ +#define MOCK_TEST_ASSERT_NOT_NULL(fail_counter, val, msg, ...) \ + MOCK_TEST_ASSERT(fail_counter, (val) != NULL, msg, ##__VA_ARGS__) + /** * Verify if parameter of the mocked up function matches expected value. @@ -101,6 +114,15 @@ #define MOCK_TEST_ASSERT_POINTER_PARAMETER(data, parameter) \ MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%p") +/** + * Wrap for MOCK_TEST_ASSERT_PARAMETER macro for uint64_t type parameters. + * + * @param data structure with expected values + * @param parameter name of the parameter (both field and parameter name) + */ +#define MOCK_TEST_ASSERT_U64_PARAMETER(data, parameter) \ + MOCK_TEST_ASSERT_PARAMETER(data, parameter, "%" PRIu64) + /** * Verify number of calls of the mocked up function * and check if there were any fails during execution. @@ -381,6 +403,43 @@ mock_set_pkt_metadata(void *device, return mock_set_pkt_metadata_exp.ret; } +/** + * get_userdata mockup + * + * Verified parameters: device, md. + * The userdata parameter works as an output parameter, so a passed address + * is verified not to be NULL and filled with userdata stored in structure. + */ +static struct mock_get_userdata_data { + void *device; + uint64_t md; + void *userdata; + + int ret; + + int called; + int failed; +} mock_get_userdata_exp = {NULL, 0UL, NULL, 0, 0, 0}; + +static int +mock_get_userdata(void *device, + uint64_t md, + void **userdata) +{ + mock_get_userdata_exp.called++; + + MOCK_TEST_ASSERT_POINTER_PARAMETER(mock_get_userdata_exp, device); + MOCK_TEST_ASSERT_U64_PARAMETER(mock_get_userdata_exp, md); + + MOCK_TEST_ASSERT_NOT_NULL(mock_get_userdata_exp.failed, + userdata, + "Expecting parameter userdata not to be NULL but it's %p", + userdata); + *userdata = mock_get_userdata_exp.userdata; + + return mock_get_userdata_exp.ret; +} + /** * empty_ops * @@ -400,6 +459,7 @@ struct rte_security_ops mock_ops = { .session_stats_get = mock_session_stats_get, .session_destroy = mock_session_destroy, .set_pkt_metadata = mock_set_pkt_metadata, + .get_userdata = mock_get_userdata, }; @@ -495,6 +555,7 @@ ut_setup(void) mock_session_stats_get_exp.called = 0; mock_session_destroy_exp.called = 0; mock_set_pkt_metadata_exp.called = 0; + mock_get_userdata_exp.called = 0; mock_session_create_exp.failed = 0; mock_session_update_exp.failed = 0; @@ -502,6 +563,7 @@ ut_setup(void) mock_session_stats_get_exp.failed = 0; mock_session_destroy_exp.failed = 0; mock_set_pkt_metadata_exp.failed = 0; + mock_get_userdata_exp.failed = 0; return TEST_SUCCESS; } @@ -1478,6 +1540,124 @@ test_set_pkt_metadata_success(void) } +/** + * rte_security_get_userdata tests + */ + +/** + * Test execution of rte_security_get_userdata with NULL instance + */ +static int +test_get_userdata_inv_context(void) +{ +#ifdef RTE_DEBUG + uint64_t md = 0xDEADBEEF; + + void *ret = rte_security_get_userdata(NULL, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_get_userdata with invalid + * security operations structure (NULL) + */ +static int +test_get_userdata_inv_context_ops(void) +{ +#ifdef RTE_DEBUG + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + ut_params->ctx.ops = NULL; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_get_userdata with empty + * security operations + */ +static int +test_get_userdata_inv_context_ops_fun(void) +{ +#ifdef RTE_DEBUG + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + ut_params->ctx.ops = &empty_ops; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 0); + + return TEST_SUCCESS; +#else + return TEST_SKIPPED; +#endif +} + +/** + * Test execution of rte_security_get_userdata when get_userdata + * security operation fails + */ +static int +test_get_userdata_ops_failure(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + void *userdata = (void *)0x7E577E57; + + mock_get_userdata_exp.device = NULL; + mock_get_userdata_exp.md = md; + mock_get_userdata_exp.userdata = userdata; + mock_get_userdata_exp.ret = -1; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, NULL, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1); + + return TEST_SUCCESS; +} + +/** + * Test execution of rte_security_get_userdata in successful execution path + */ +static int +test_get_userdata_success(void) +{ + struct security_unittest_params *ut_params = &unittest_params; + uint64_t md = 0xDEADBEEF; + void *userdata = (void *)0x7E577E57; + + mock_get_userdata_exp.device = NULL; + mock_get_userdata_exp.md = md; + mock_get_userdata_exp.userdata = userdata; + mock_get_userdata_exp.ret = 0; + + void *ret = rte_security_get_userdata(&ut_params->ctx, md); + TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_get_userdata, + ret, userdata, "%p"); + TEST_ASSERT_MOCK_CALLS(mock_get_userdata_exp, 1); + + return TEST_SUCCESS; +} + + /** * Declaration of testcases */ @@ -1568,6 +1748,17 @@ static struct unit_test_suite security_testsuite = { TEST_CASE_ST(ut_setup_with_session, ut_teardown, test_set_pkt_metadata_success), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_inv_context), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_inv_context_ops), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_inv_context_ops_fun), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_ops_failure), + TEST_CASE_ST(ut_setup_with_session, ut_teardown, + test_get_userdata_success), + TEST_CASES_END() /**< NULL terminate unit test array */ } }; -- 2.17.1