From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0057.outbound.protection.outlook.com [104.47.34.57]) by dpdk.org (Postfix) with ESMTP id BD3BC7CEF for ; Tue, 23 Jan 2018 15:24:54 +0100 (CET) Received: from BN3PR03CA0076.namprd03.prod.outlook.com (10.167.1.164) by CY1PR03MB1422.namprd03.prod.outlook.com (10.163.17.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Tue, 23 Jan 2018 14:24:52 +0000 Received: from BY2FFO11OLC011.protection.gbl (2a01:111:f400:7c0c::186) by BN3PR03CA0076.outlook.office365.com (2a01:111:e400:7a4d::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.428.17 via Frontend Transport; Tue, 23 Jan 2018 14:24:52 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11OLC011.mail.protection.outlook.com (10.1.15.22) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.428.12 via Frontend Transport; Tue, 23 Jan 2018 14:24:50 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.39]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id w0NDj5Rj022838; Tue, 23 Jan 2018 06:45:32 -0700 From: Shreyansh Jain To: , CC: , , , Shreyansh Jain Date: Tue, 23 Jan 2018 19:29:08 +0530 Message-ID: <20180123135910.10755-9-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180123135910.10755-1-shreyansh.jain@nxp.com> References: <20180102125749.2379-1-shreyansh.jain@nxp.com> <20180123135910.10755-1-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131611910920611276; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(346002)(39380400002)(39860400002)(376002)(396003)(2980300002)(1109001)(1110001)(339900001)(199004)(189003)(8936002)(106466001)(50226002)(356003)(68736007)(305945005)(105606002)(2906002)(498600001)(76176011)(51416003)(59450400001)(4326008)(1076002)(36756003)(104016004)(97736004)(316002)(53936002)(16586007)(48376002)(110136005)(54906003)(336011)(47776003)(2950100002)(5660300001)(85426001)(81156014)(81166006)(8676002)(77096007)(5890100001)(50466002)(86362001)(6666003)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR03MB1422; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11OLC011; 1:Mplhb0Np3mqUAE+iXlgscLx502fhgzSqo9VWCE5Tc2/EeCNe8dqHgfqU3xszx/rz/0o02G28ahg1WImmrvx+up79kU/ZKjWJAFhxReMTTmbRtyoqXs2EjC6OX8xlLftD MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7593176e-65a2-4099-1aec-08d5626d1106 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(5600026)(4604075)(2017052603307); SRVR:CY1PR03MB1422; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1422; 3:zBoLH5KOrZ4HNakCBdCAUyzDu8mGwRU87UJcPL51EGiskeuGKJg7cGQJAKZT0nlENibCvWXVk7jK7ywhUHSQb58LBaL7z40IQ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BPkbMqpuUnvpwxB4jvxvZyQiWe6VK31BAbNEqXZzq1QBl9n1SJ45TmcnOegY7zDaGq1+wMJhhXO/DSNGOsSJdFL3k6JXW4Yfi4Nb+mWmOdHUKpWbv8fiQnLbEaDsmsBowoPfXvLXiyzsqLmz8eHho9r9KT9AeWAQdBlrf X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095135)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231023)(2400081)(944501161)(6055026)(6096035)(20161123565025)(20161123561025)(20161123563025)(20161123559100)(201703131430075)(201703131433075)(201703131448075)(201703151042153)(20161123556025)(201708071742011); SRVR:CY1PR03MB1422; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:CY1PR03MB1422; X-Forefront-PRVS: 05610E64EE X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR03MB1422; 23:Zww5prRVVSPAXxfCFmq/mJ6GbS7BHLykZpXGTbpo5?= =?us-ascii?Q?SkAU5681e0INccJsZPZzuZlKkrSMi+YkFqYCNXYCvQch4RDMm5zex0oMHp9f?= =?us-ascii?Q?KtJCTZvgn9ZMqDOq1n07n/XTgDRVuqE2hY3CZRS+SQiWTmtnI30nks1tqZq8?= =?us-ascii?Q?FpsBB5VWSOeecz9d+9//anw90wprLwcVEhdVQHvkrnYztdpAfNqfaL0CsjR8?= =?us-ascii?Q?gISmubmDGGd9mS8xAh2XoH0Z9ScrkWzfhvOqJ4lEIXhg2WXC7fa55CsHD9Ot?= =?us-ascii?Q?SjE7Kdq07iKmvYfpCkmylLrjIT917gq/XFnxI8iiHeytcE06jZWesO9X+QJ2?= =?us-ascii?Q?86rB2ADJQIKfzLY8DB5RFRQvAPbmLH42ZKD2vtK2NpUW15fOhlnqddp0SB6+?= =?us-ascii?Q?E6GiEeUb37d8mPMIykWcCHTK8xRWnJD7mWkJqzD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tnGU4Yac59i4s6r/bi4oz5klcgNCvHbYDGSm+73cvu3siTpbWRTUnTVBHHV9k7MfE9T5uNgXyrPlZj5cRH/sZutObcXpl8kahDhMTZxMab/fzGeU04g0L96fjKYMJEuAJEWwcM0IgDvv1qzNLpphfh0Akv6/1t2iUNob5CFs8bOwXV7LGuFim92wIz9SH/q+pAja4Algo=; 5:tWCLfpgGkJGNdEL4Y2co4ngbwUIyVJ9rRs7s89Ywl76VoyTv5tkuMs+D2wKLpGOdKNGIdzfSwO3R4encif51VPo+SLOO5uvrM77fZF4/+Pm3cVF+HSYnwElDuOcBfQ3uCjvQVv+MkKQw4U8ewc1cG92WT2uvkPgip0FCJrkWqR0=; 24:yJHmACqKTaKlDBDQ404opFk/+HHNjRU+5oYptzFjV2QzNlKfLlp4ZHBhO8XZ4ckny2Lw5Sc6XHxASlyv56fa8ZleyaIf01XnqfQiCvNbu5g=; 7:RtHJPskYJuswYc+aNqksJWvxbCitYQyZxy+YY0sNN4lsWCwT/KGsqcLWzs80wEcNGoqfRw4NZzrKjmBfQfmKSBN6f8pbmgJjKPgNhlUHNuQUBqrQxP2VmT4tF6ilACbrS3gFxVQBZmwglk67wHCMYC/llZJSx62X7uV2WvGgVRMQoqNt1ijMt1aWbUiSo3C2vkbVJ8AVieaoUEcz9H7ZFGqPZONY9sxCVDimtufpXHncKMTIfrzO+srddNPt2fxq SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jan 2018 14:24:50.1111 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7593176e-65a2-4099-1aec-08d5626d1106 X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB1422 Subject: [dpdk-dev] [PATCH v2 08/10] drivers/raw: support for rawdev testcases 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: , X-List-Received-Date: Tue, 23 Jan 2018 14:24:56 -0000 Patch introduces rawdev unit testcase for validation against the Skeleton rawdev dummy PMD implementation. Test cases are added along with the skeleton driver implementation. It can be enabled by using vdev argument to any DPDK binary: --vdev="rawdev_skeleton,self_test=1" In case 'self_test=1' is not provided, autotest doesn't execute the test cases but the vdev is still available for application use. Signed-off-by: Shreyansh Jain --- drivers/raw/skeleton_rawdev/Makefile | 1 + drivers/raw/skeleton_rawdev/skeleton_rawdev.c | 66 +++- drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c | 431 +++++++++++++++++++++ 3 files changed, 497 insertions(+), 1 deletion(-) create mode 100644 drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c diff --git a/drivers/raw/skeleton_rawdev/Makefile b/drivers/raw/skeleton_rawdev/Makefile index 4d9b2f804..d5e34361a 100644 --- a/drivers/raw/skeleton_rawdev/Makefile +++ b/drivers/raw/skeleton_rawdev/Makefile @@ -21,5 +21,6 @@ LIBABIVER := 1 # all source are stored in SRCS-y # SRCS-$(CONFIG_RTE_LIBRTE_PMD_SKELETON_RAWDEV) += skeleton_rawdev.c +SRCS-$(CONFIG_RTE_LIBRTE_PMD_SKELETON_RAWDEV) += skeleton_rawdev_test.c include $(RTE_SDK)/mk/rte.lib.mk diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev.c b/drivers/raw/skeleton_rawdev/skeleton_rawdev.c index b38188e11..2dfba0081 100644 --- a/drivers/raw/skeleton_rawdev/skeleton_rawdev.c +++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev.c @@ -541,6 +541,8 @@ static const struct rte_rawdev_ops skeleton_rawdev_ops = { .firmware_version_get = skeleton_rawdev_firmware_version_get, .firmware_load = skeleton_rawdev_firmware_load, .firmware_unload = skeleton_rawdev_firmware_unload, + + .dev_selftest = test_rawdev_skeldev, }; static int @@ -630,11 +632,62 @@ skeleton_rawdev_destroy(const char *name) return 0; } +static int +skeldev_get_selftest(const char *key __rte_unused, + const char *value, + void *opaque) +{ + int *flag = opaque; + *flag = atoi(value); + return 0; +} + +static int +skeldev_parse_vdev_args(struct rte_vdev_device *vdev) +{ + int selftest = 0; + const char *name; + const char *params; + + static const char *const args[] = { + SKELETON_SELFTEST_ARG, + NULL + }; + + name = rte_vdev_device_name(vdev); + + params = rte_vdev_device_args(vdev); + if (params != NULL && params[0] != '\0') { + struct rte_kvargs *kvlist = rte_kvargs_parse(params, args); + + if (!kvlist) { + SKELETON_PMD_INFO( + "Ignoring unsupported params supplied '%s'", + name); + } else { + int ret = rte_kvargs_process(kvlist, + SKELETON_SELFTEST_ARG, + skeldev_get_selftest, &selftest); + if (ret != 0 || (selftest < 0 || selftest > 1)) { + SKELETON_PMD_ERR("%s: Error in parsing args", + name); + rte_kvargs_free(kvlist); + ret = -1; /* enforce if selftest is invalid */ + return ret; + } + } + + rte_kvargs_free(kvlist); + } + + return selftest; +} + static int skeleton_rawdev_probe(struct rte_vdev_device *vdev) { const char *name; - int ret = 0; + int selftest = 0, ret = 0; name = rte_vdev_device_name(vdev); @@ -647,7 +700,18 @@ skeleton_rawdev_probe(struct rte_vdev_device *vdev) SKELETON_PMD_INFO("Init %s on NUMA node %d", name, rte_socket_id()); + selftest = skeldev_parse_vdev_args(vdev); + /* In case of invalid argument, selftest != 1; ignore other values */ + ret = skeleton_rawdev_create(name, vdev, rte_socket_id()); + if (!ret) { + /* In case command line argument for 'selftest' was passed; + * if invalid arguments were passed, execution continues but + * without selftest. + */ + if (selftest == 1) + test_rawdev_skeldev(); + } /* Device instance created; Second instance not posible */ skeldev_init_once = 1; diff --git a/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c new file mode 100644 index 000000000..5c6abc13c --- /dev/null +++ b/drivers/raw/skeleton_rawdev/skeleton_rawdev_test.c @@ -0,0 +1,431 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2017 NXP + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* Using relative path as skeleton_rawdev is not part of exported headers */ +#include "skeleton_rawdev.h" + +#define TEST_DEV_ID 0 +#define TEST_DEV_NAME "rawdev_skeleton" + +#define SKELDEV_LOGS(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, skeleton_pmd_logtype, fmt "\n", \ + ##args) + +#define SKELDEV_TEST_INFO(fmt, args...) \ + SKELDEV_LOGS(INFO, fmt, ## args) +#define SKELDEV_TEST_DEBUG(fmt, args...) \ + SKELDEV_LOGS(DEBUG, fmt, ## args) + +#define SKELDEV_TEST_RUN(setup, teardown, test) \ + skeldev_test_run(setup, teardown, test, #test) + +#define TEST_SUCCESS 0 +#define TEST_FAILED -1 + +static int total; +static int passed; +static int failed; +static int unsupported; + +static int +testsuite_setup(void) +{ + uint8_t count; + count = rte_rawdev_count(); + if (!count) { + SKELDEV_TEST_INFO("\tNo existing rawdev; " + "Creating 'skeldev_rawdev'"); + return rte_vdev_init(TEST_DEV_NAME, NULL); + } + + return TEST_SUCCESS; +} + +static void local_teardown(void); + +static void +testsuite_teardown(void) +{ + local_teardown(); +} + +static void +local_teardown(void) +{ + rte_vdev_uninit(TEST_DEV_NAME); +} + +static int +test_rawdev_count(void) +{ + uint8_t count; + count = rte_rawdev_count(); + RTE_TEST_ASSERT(count > 0, "Invalid rawdev count %" PRIu8, count); + return TEST_SUCCESS; +} + +static int +test_rawdev_get_dev_id(void) +{ + int ret; + ret = rte_rawdev_get_dev_id("invalid_rawdev_device"); + RTE_TEST_ASSERT_FAIL(ret, "Expected <0 for invalid dev name ret=%d", + ret); + return TEST_SUCCESS; +} + +static int +test_rawdev_socket_id(void) +{ + int socket_id; + socket_id = rte_rawdev_socket_id(TEST_DEV_ID); + RTE_TEST_ASSERT(socket_id != -EINVAL, + "Failed to get socket_id %d", socket_id); + socket_id = rte_rawdev_socket_id(RTE_RAWDEV_MAX_DEVS); + RTE_TEST_ASSERT(socket_id == -EINVAL, + "Expected -EINVAL %d", socket_id); + + return TEST_SUCCESS; +} + +static int +test_rawdev_info_get(void) +{ + int ret; + struct rte_rawdev_info rdev_info = {0}; + struct skeleton_rawdev_conf skel_conf = {0}; + + ret = rte_rawdev_info_get(TEST_DEV_ID, NULL); + RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret); + + rdev_info.dev_private = &skel_conf; + + ret = rte_rawdev_info_get(TEST_DEV_ID, &rdev_info); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get raw dev info"); + + return TEST_SUCCESS; +} + +static int +test_rawdev_configure(void) +{ + int ret; + struct rte_rawdev_info rdev_info = {0}; + struct skeleton_rawdev_conf rdev_conf_set = {0}; + struct skeleton_rawdev_conf rdev_conf_get = {0}; + + /* Check invalid configuration */ + ret = rte_rawdev_configure(TEST_DEV_ID, NULL); + RTE_TEST_ASSERT(ret == -EINVAL, + "Null configure; Expected -EINVAL, got %d", ret); + + /* Valid configuration test */ + rdev_conf_set.num_queues = 1; + rdev_conf_set.capabilities = SKELETON_CAPA_FW_LOAD | + SKELETON_CAPA_FW_RESET; + + rdev_info.dev_private = &rdev_conf_set; + ret = rte_rawdev_configure(TEST_DEV_ID, + (rte_rawdev_obj_t)&rdev_info); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to configure rawdev (%d)", ret); + + rdev_info.dev_private = &rdev_conf_get; + ret = rte_rawdev_info_get(TEST_DEV_ID, + (rte_rawdev_obj_t)&rdev_info); + RTE_TEST_ASSERT_SUCCESS(ret, + "Failed to obtain rawdev configuration (%d)", + ret); + + RTE_TEST_ASSERT_EQUAL(rdev_conf_set.num_queues, + rdev_conf_get.num_queues, + "Configuration test failed; num_queues (%d)(%d)", + rdev_conf_set.num_queues, + rdev_conf_get.num_queues); + RTE_TEST_ASSERT_EQUAL(rdev_conf_set.capabilities, + rdev_conf_get.capabilities, + "Configuration test failed; capabilities"); + + return TEST_SUCCESS; +} + +static int +test_rawdev_queue_default_conf_get(void) +{ + int ret, i; + struct rte_rawdev_info rdev_info = {0}; + struct skeleton_rawdev_conf rdev_conf_get = {0}; + struct skeleton_rawdev_queue q = {0}; + + /* Get the current configuration */ + rdev_info.dev_private = &rdev_conf_get; + ret = rte_rawdev_info_get(TEST_DEV_ID, + (rte_rawdev_obj_t)&rdev_info); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain rawdev configuration (%d)", + ret); + + /* call to test_rawdev_configure would have set the num_queues = 1 */ + RTE_TEST_ASSERT_SUCCESS(!(rdev_conf_get.num_queues > 0), + "Invalid number of queues (%d). Expected 1", + rdev_conf_get.num_queues); + /* All queues by default should have state = DETACH and + * depth = DEF_DEPTH + */ + for (i = 0; i < rdev_conf_get.num_queues; i++) { + rte_rawdev_queue_conf_get(TEST_DEV_ID, i, &q); + RTE_TEST_ASSERT_EQUAL(q.depth, SKELETON_QUEUE_DEF_DEPTH, + "Invalid default depth of queue (%d)", + q.depth); + RTE_TEST_ASSERT_EQUAL(q.state, SKELETON_QUEUE_DETACH, + "Invalid default state of queue (%d)", + q.state); + } + + return TEST_SUCCESS; +} + +static int +test_rawdev_queue_setup(void) +{ + int ret; + struct rte_rawdev_info rdev_info = {0}; + struct skeleton_rawdev_conf rdev_conf_get = {0}; + struct skeleton_rawdev_queue qset = {0}; + struct skeleton_rawdev_queue qget = {0}; + + /* Get the current configuration */ + rdev_info.dev_private = &rdev_conf_get; + ret = rte_rawdev_info_get(TEST_DEV_ID, + (rte_rawdev_obj_t)&rdev_info); + RTE_TEST_ASSERT_SUCCESS(ret, + "Failed to obtain rawdev configuration (%d)", + ret); + + /* call to test_rawdev_configure would have set the num_queues = 1 */ + RTE_TEST_ASSERT_SUCCESS(!(rdev_conf_get.num_queues > 0), + "Invalid number of queues (%d). Expected 1", + rdev_conf_get.num_queues); + + /* Modify the queue depth for Queue 0 and attach it */ + qset.depth = 15; + qset.state = SKELETON_QUEUE_ATTACH; + ret = rte_rawdev_queue_setup(TEST_DEV_ID, 0, &qset); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup queue (%d)", ret); + + /* Now, fetching the queue 0 should show depth as 15 */ + ret = rte_rawdev_queue_conf_get(TEST_DEV_ID, 0, &qget); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret); + + RTE_TEST_ASSERT_EQUAL(qset.depth, qget.depth, + "Failed to set queue depth: Need(%d), has(%d)", + qset.depth, qget.depth); + + return TEST_SUCCESS; +} + +/* After executing test_rawdev_queue_setup, queue_id=0 would have depth as 15. + * Releasing should set it back to default. state would set to DETACH + */ +static int +test_rawdev_queue_release(void) +{ + int ret; + struct skeleton_rawdev_queue qget = {0}; + + /* Now, fetching the queue 0 should show depth as 100 */ + ret = rte_rawdev_queue_release(TEST_DEV_ID, 0); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to release queue 0; (%d)", ret); + + /* Now, fetching the queue 0 should show depth as default */ + ret = rte_rawdev_queue_conf_get(TEST_DEV_ID, 0, &qget); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret); + + RTE_TEST_ASSERT_EQUAL(qget.depth, SKELETON_QUEUE_DEF_DEPTH, + "Release of Queue 0 failed; (depth)"); + + RTE_TEST_ASSERT_EQUAL(qget.state, SKELETON_QUEUE_DETACH, + "Release of Queue 0 failed; (state)"); + + return TEST_SUCCESS; +} + +static int +test_rawdev_attr_set_get(void) +{ + int ret; + int *dummy_value; + uint64_t ret_value; + + /* Set an attribute and fetch it */ + ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test1", 100); + RTE_TEST_ASSERT(!ret, "Unable to set an attribute (Test1)"); + + dummy_value = malloc(sizeof(int)); + if (!dummy_value) + RTE_TEST_ASSERT(1, "Unable to allocate memory (dummy_value)"); + + *dummy_value = 200; + ret = rte_rawdev_set_attr(TEST_DEV_ID, "Test2", (uint64_t)dummy_value); + + /* Check if attributes have been set */ + ret = rte_rawdev_get_attr(TEST_DEV_ID, "Test1", &ret_value); + RTE_TEST_ASSERT_EQUAL(ret_value, 100, + "Attribute (Test1) not set correctly (%lu)", + ret_value); + + ret_value = 0; + ret = rte_rawdev_get_attr(TEST_DEV_ID, "Test2", &ret_value); + RTE_TEST_ASSERT_EQUAL(*((int *)ret_value), 200, + "Attribute (Test2) not set correctly (%lu)", + ret_value); + + return TEST_SUCCESS; +} + +static int +test_rawdev_start_stop(void) +{ + int ret; + struct rte_rawdev_info rdev_info = {0}; + struct skeleton_rawdev_conf rdev_conf_get = {0}; + + /* Get the current configuration */ + rdev_info.dev_private = &rdev_conf_get; + + rte_rawdev_start(TEST_DEV_ID); + ret = rte_rawdev_info_get(TEST_DEV_ID, (rte_rawdev_obj_t)&rdev_info); + RTE_TEST_ASSERT_SUCCESS(ret, + "Failed to obtain rawdev configuration (%d)", + ret); + RTE_TEST_ASSERT_EQUAL(rdev_conf_get.device_state, SKELETON_DEV_RUNNING, + "Device start failed. State is (%d)", + rdev_conf_get.device_state); + + rte_rawdev_stop(TEST_DEV_ID); + ret = rte_rawdev_info_get(TEST_DEV_ID, (rte_rawdev_obj_t)&rdev_info); + RTE_TEST_ASSERT_SUCCESS(ret, + "Failed to obtain rawdev configuration (%d)", + ret); + RTE_TEST_ASSERT_EQUAL(rdev_conf_get.device_state, SKELETON_DEV_STOPPED, + "Device stop failed. State is (%d)", + rdev_conf_get.device_state); + + return TEST_SUCCESS; +} + +static int +test_rawdev_enqdeq(void) +{ + int ret; + unsigned int count = 1; + uint16_t queue_id = 0; + struct rte_rawdev_buf buffers[1]; + struct rte_rawdev_buf *deq_buffers; + + buffers[0].buf_addr = malloc(strlen(TEST_DEV_NAME) + 3); + if (!buffers[0].buf_addr) + goto cleanup; + snprintf(buffers[0].buf_addr, strlen(TEST_DEV_NAME) + 2, "%s%d", + TEST_DEV_NAME, 0); + + ret = rte_rawdev_enqueue_buffers(TEST_DEV_ID, + (struct rte_rawdev_buf **)&buffers, + count, &queue_id); + RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count, + "Unable to enqueue buffers"); + + deq_buffers = malloc(sizeof(struct rte_rawdev_buf) * count); + if (!deq_buffers) + goto cleanup; + + ret = rte_rawdev_dequeue_buffers(TEST_DEV_ID, + (struct rte_rawdev_buf **)&deq_buffers, + count, &queue_id); + RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count, + "Unable to dequeue buffers"); + + if (deq_buffers) + free(deq_buffers); + + return TEST_SUCCESS; +cleanup: + if (buffers[0].buf_addr) + free(buffers[0].buf_addr); + if (deq_buffers) + free(deq_buffers); + + return TEST_FAILED; +} + +static void skeldev_test_run(int (*setup)(void), + void (*teardown)(void), + int (*test)(void), + const char *name) +{ + int ret = 0; + + if (setup) { + ret = setup(); + if (ret < 0) { + SKELDEV_TEST_INFO("Error setting up test %s", name); + unsupported++; + } + } + + if (test) { + ret = test(); + if (ret < 0) { + failed++; + SKELDEV_TEST_INFO("%s Failed", name); + } else { + passed++; + SKELDEV_TEST_DEBUG("%s Passed", name); + } + } + + if (teardown) + teardown(); + + total++; +} + +int +test_rawdev_skeldev(void) +{ + testsuite_setup(); + + SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_count); + SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_get_dev_id); + SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_socket_id); + SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_info_get); + SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_configure); + SKELDEV_TEST_RUN(test_rawdev_configure, NULL, + test_rawdev_queue_default_conf_get); + SKELDEV_TEST_RUN(test_rawdev_configure, NULL, test_rawdev_queue_setup); + SKELDEV_TEST_RUN(test_rawdev_queue_setup, NULL, + test_rawdev_queue_release); + SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_attr_set_get); + SKELDEV_TEST_RUN(NULL, NULL, test_rawdev_start_stop); + SKELDEV_TEST_RUN(test_rawdev_queue_setup, NULL, test_rawdev_enqdeq); + + testsuite_teardown(); + + SKELDEV_TEST_INFO("Total tests : %d", total); + SKELDEV_TEST_INFO("Passed : %d", passed); + SKELDEV_TEST_INFO("Failed : %d", failed); + SKELDEV_TEST_INFO("Not supported : %d", unsupported); + + if (failed) + return -1; + + return 0; +}; -- 2.14.1