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 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 V1YQW0RAQOJz52K2LkYODmEBF4mOW04gJouAqsTRex4gFbwCrhLXLvx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3Njc2MzCyVx3g6B gzFCAumJJanZqakFqUUwfUwcnFINjDq3vtiZrZNMSM6N/vri1rF3Gx6qTb30Vjj6sPm20GWf Xe4/6H4847z3PN2tec2PtFOXmDbarMmT0pY+28H+qLXGrytR+vr5tR0HpA0bFcXUen4EdVj/ jo2Wlct+eeWh9a1pbZMi76jIbHjUpXnx5JLe5WJMxZx2PFzO7333XHB+ahYubcg1SYmlOCPR UIu5qDgRAK9HmEkvAgAA X-CMS-MailID: 20200312151710eucas1p1c3590b55d00bea25b26539a560199b96 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" 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 */ } }; -- 2.17.1