From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0077.outbound.protection.outlook.com [104.47.2.77]) by dpdk.org (Postfix) with ESMTP id 8A9441B746 for ; Wed, 31 Jan 2018 09:59:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=K6/g960ygTuO9NA68/rCLT9KalI1LyM1QJsrSnsrFAc=; b=grvI46vlc4Mvy+slETESLobdg/DuXQWvsKmbUwB9/GHxsj6HeDRZja8zUIgYXXTnmkCr5dVHy+RvM156Y+cL/d+jOezEwq9zpMGKqhKHnu8QWZNSaDzBwi453NfIc1a1BYFV73+onAstEEJxFDnFkqjT/vDhj+g1TAUykAYprJE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=shreyansh.jain@nxp.com; Received: from Tophie.ap.freescale.net (192.88.169.1) by VI1PR0401MB2462.eurprd04.prod.outlook.com (2603:10a6:800:55::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.444.14; Wed, 31 Jan 2018 08:59:23 +0000 From: Shreyansh Jain To: thomas@monjalon.net Cc: dev@dpdk.org, hemant.agrawal@nxp.com, fiona.trahe@intel.com, rosen.xu@intel.com, Shreyansh Jain Date: Wed, 31 Jan 2018 14:43:16 +0530 Message-Id: <20180131091318.7894-9-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180131091318.7894-1-shreyansh.jain@nxp.com> References: <20180130145710.24757-1-shreyansh.jain@nxp.com> <20180131091318.7894-1-shreyansh.jain@nxp.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.88.169.1] X-ClientProxiedBy: HK2PR02CA0168.apcprd02.prod.outlook.com (2603:1096:201:1f::28) To VI1PR0401MB2462.eurprd04.prod.outlook.com (2603:10a6:800:55::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 96b67cc3-a1b8-45c3-6db0-08d56888eeaf X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:VI1PR0401MB2462; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0401MB2462; 3:DpOtoNVtOUo/cTjBCD7s+R0sBvOvklHc3cmUU5qe2zkdHLTXCId5fNIHnUHJy5Z/r/GrrbKOt//F9eG8REoD3J9ssLBbMmfH6Kgf+4rZg35gJdLwVU6YputHvXb3PczHw1R1nhz1jMjxqR/JiwpoWqT1lFwPyiB3QVe7gsUk+KMjPijxlJSgLEhRcYf55TzqsOYEWxScDNAZea7FDhwCk3b5+S14HhYaAdIRejv2QiltQFLJpZ4XagDNOGZhO/1I; 25:enTwD4pJRtrY1Hjt3FUu8+R0KM0v5wtjGFlujKqAliZ/LHu6cDHdN39koYgU405L9wnm7pHD6tygf0ILveN+RLQ6EYlvlx2/ZDAHRatLr8Yb0Q47Vv+RMtzqbfogBAxcVVPviZn5sGUoeQ8kRrdKcO0WWHHJXRPKEu9rnMnEiVPQrYSf1QAZvdhnEQ2Gs8sB59wvk712FsJUw1qnK98aJ1D899S1nDF83JN2gIqlEJeblKJtdBusdnJeCft84gG1I5TYNxQZzjaE7wh0KXYYV2Gp+mwuv7u/rFVqMlZkgRXjxs6njplFraJsrsitHlmYAcXVvB9wXsDHLozVxEHRFw==; 31:N3QGWcJzm/KUhFGs1zW9ZQ/ok3VIsWApE0x6CWJX6vxhKEq5JluqEN08tzyrE44Z8k7jx2duhKc9fkP12EiHrAf75kCb9885R1z9JYRUz8TPnjMwOfAcEuhMMjAU6mWYmMugICRpjNhrCPGO/Dl9FBZZRQEENQlcA5aDwP1j73gCe8RrlWi909kQmIWiNwIj4iC+OdwTW5KsPheFSR7rfxzQtiouxKFbX4SXfLZWFq4= X-MS-TrafficTypeDiagnostic: VI1PR0401MB2462: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0401MB2462; 20:4sh/kMgZFw6ZWnCIqKSWxtuzBRXqlMcugmuDochXqiTCmdyLfHrFb77wAwU6g+vIyeg4FIGsO79IPg0cL/sxE6m8aDPY1d26zT39k9UsD+24PDt3YWA04TwcuqKNODC/W3aVt8nIm3XTMB+a7KEshDlFtzZwCe58kgO6TznfXM0RqPOuu52rkH+jlRrCaXeyDD/nCdDrD5G5fXeWZSblXUoDwibb6L+kbgyepV8E2Qqceoe+M28w3IX9y06haIxxMfWXwVnqOLAGNZBnfBEA0ExQytRvRv2l9YBJGKGHggFNbDF2vQa77BN8m/XZbdrVCVmA8SK10YDPWr2DJwQhyu4MggF9ffd6nrRkcbtM+PynZXWMI+y90/XGbmTpIszo2OLLrJu0l8jOjNIytQNR5cRTl02IgmJ92vE2b9yUu7vey6+eIb3PIo6TSGOF8NYtpHOdUa/y4VE8DmuhYwc2+xkqlAW/8K3S0Ces7y4PgIaHtzL6vvh7T/XSOOFEGVTe; 4:2Phz4DvE7w8bl9RWVfu6OvjcctXwQMbRJxnRqtUTCEv8ZAm8KZZaud8FpRo9SnVcIT20CcgyaJBohJJ6Jutns8U2FoxfBJmZTy+z5GV6uoZfzGu/tnD2QIxBzSoEkbX3Xg/26kecKqnCuegXBO6dU+6ekoVUJ5MIaDMR9fXsH5vLfQ4bg7y4G6VXmzHNc5p5Xy0hsvckt0ChJPO1Empp4xeLluh/V94DXb4n3hyuYzX6lyOJXsyCqYZDI6fmwBomhMKRbYaqQzEhG8GBSYrBgORrDoqZKs8OksQvsT5hCajphnq4pjcHUnavXYyk1Re/ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3002001)(3231101)(2400082)(944501161)(93006095)(93001095)(10201501046)(6055026)(6041288)(20161123562045)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011); SRVR:VI1PR0401MB2462; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0401MB2462; X-Forefront-PRVS: 056929CBB8 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(39380400002)(376002)(366004)(346002)(39860400002)(199004)(189003)(6486002)(5890100001)(6512007)(50226002)(8676002)(48376002)(4326008)(81156014)(316002)(8936002)(66066001)(6666003)(2950100002)(81166006)(6916009)(53936002)(16526019)(5660300001)(47776003)(186003)(26005)(106356001)(2361001)(97736004)(16586007)(305945005)(478600001)(51416003)(386003)(36756003)(86362001)(105586002)(68736007)(2351001)(76176011)(1076002)(52116002)(2906002)(6506007)(25786009)(3846002)(6116002)(50466002)(59450400001)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0401MB2462; H:Tophie.ap.freescale.net; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0401MB2462; 23:WHVrMo2ft/ZqTCRb0MwuxjUPe/tUrLQ3Gx3vRRR?= =?us-ascii?Q?iCyWaNYF13VJAP1F7AwR/FMJUi6sMqGPh7tIHXv8DVnO3kaA+LrfMAcFVPXt?= =?us-ascii?Q?Qoxe95L7VyWLddxQ7T7gag1g2KdmYl9xhaOYO8SN6EKsDJSev492R7mWOurS?= =?us-ascii?Q?WxyXB167vskW1PWQkMcdnD+dZhNCc4/FPOWUPU4lahb8+b+iqco7NmaIRi86?= =?us-ascii?Q?EHJziH9lq5TlXzla/RUW+6cVKm0kFWkbr93dNyzy9yGm3x4nxC8q9Tw6IFhE?= =?us-ascii?Q?LrrwZ6LTSbHtgMN5ydPlgjI+7J2pToBS25mqq8C4YX4hF16OjLdqz5haOXyr?= =?us-ascii?Q?upKQOeanCngIOBz6BnIJVBjAp0J0x17LqEdv5br8/W/VGdH+Y3aP1GxfYTB2?= =?us-ascii?Q?f1bRs12frGDcN2pVtAJzsX+e7oYgPE0hHKPk+U06JLnHcwiArG+x7RImg7Vo?= =?us-ascii?Q?LOeIO4+YIymVT+FiEk6YNjE9tSSmvXFT+euzhJKoKlXrQbhWsRFh2NyHNgQ/?= =?us-ascii?Q?ZkjGO7JwWQ+7LsWlpQQmWRiS0UjN0oVzlctKILGC7rOM8l36D0h0dVdAL5gs?= =?us-ascii?Q?0hZSFbSl8TgcO7QN3udqDuGvyClYXCz3yC6LBkIjfuHDZPjzTFbqqFgg9r9j?= =?us-ascii?Q?6T850B4fM/jv3XR6HxyfDQZBfIYkOI/4jJ+b8qyURslab5Gi2K7xJidnblCo?= =?us-ascii?Q?fHwS8JtrYRj4+tvy0asY9D1CyaV1+AoplLebTpd87L6f+VZ6y8AtCFg1TZ2X?= =?us-ascii?Q?iVYjKHaDb0pWodq5xO9SG1ey12D9xhcbrZpVDziZViu/UWl6xER+JoTQ9HN/?= =?us-ascii?Q?2LTmm1twr58pbMHkyCur3/55VK7EUVva91lGJGBeaFj80n0BVF2OjgL5qWPc?= =?us-ascii?Q?ofp7OGOUMVHQvwxfNzMBS+Qzk9aFvPlCsSMIlq3z8sxFbCTzI6FG2B+jS/GM?= =?us-ascii?Q?CR5KERlm+2yhcgzdO3ruALCXACzM98eWBsLdh2fgrzia+JwxlNHF86rfAiNl?= =?us-ascii?Q?HMxtrVDMS6oIV06Vh5P7SfhJHzF2+Ro5XK/P+E+MkfNJmGBRz/LXNYY4fONV?= =?us-ascii?Q?agVrKPpioQmfv3sjqAZh5BB04DZMJn0vwcnC6oMe3bd0s53eal+Mwg/IbQL2?= =?us-ascii?Q?1z6ZmQaezZ51nqBYvKcpWgZDueiPxsxzqlPTRE37eVUw9BUpmAGraSlxf885?= =?us-ascii?Q?mJy6Fwx+wyLx+C00igCxPGaKgD7yMt0VZMcEV?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0401MB2462; 6:g9P31c5aaq4S6uvP0PPgbgM6iX5P8depSwUvwhHYmf0ar6zozy8kK7njIJruS7RoHCvYAY5zLurV5jNmyYEi5AKt2f9iMfhtuByITbaLy8Yikc858DiDyI2orqknbJOM8/Uhm24x0zFP+nRB3tOFkQdSH0jb7gAyBuqdXVeEiiDusZd9gpscS4hGFzXWSsRp7CykvdCF3MgfWIJODdsT7SGqx2NqfnVrik2sHxTGxeNHLLWra0Iyqk0jEQLLsHCmEJIDuxynFQ9UXxqh3JwcndwGk864bwokdUUnvCGQapjxDvijCXJJx3CRUnS/Mk4qlNy/m67h+5XX3fGr3F4rSr033nROOezfm1rKsdRstCI=; 5:xm3e5DyYZp6l1W/Vn2+K+HvBSgZ1pJYVH7qpwj1P7MZgi0YcOYFrSf1XPot00sjkPRozpCq2AiPhMDP22BFZ/G7WdBrYqq/RSXSri+eCAzbDvhacDrZ+BVers8l9yu2jIV0La1NrhY5Eno1FqDVl8qeQA9e2W3HQciqWGx1nTPQ=; 24:WaRuprqtNmUFpQMmPccT2w/OBIaWUP4q20f4xr4MMbcdxY4MCz6jrta5iNBwOEfK4GqkG2KEg8v5XPUqWwIzNIkr71ddgmdpvllX7SLnEJc=; 7:uYMb5txmwmjRGOsfaHpbDS44NmQlARffjUwyXt1BZZmMurMFQcMOgaFVsqq2DuGi1ZkEwyKFjEhZnjL3Aav2ptWaL281uH5SoRzfIipP/cxl+enNLSEoKbSVax/JM0M78BmBYsYLuJvWx2uQSxB0JCgmZ5RKLgmgEfaIHWOv6E8diMjXAOxMK14Up7XYTxbbyXU19pJypoLl0TGRYVbaDIeAOytKRHtopY+s4lhts/Z2teHtuwltl8CyZ0c5dORZ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2018 08:59:23.7108 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 96b67cc3-a1b8-45c3-6db0-08d56888eeaf X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2462 Subject: [dpdk-dev] [PATCH v4 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: Wed, 31 Jan 2018 08:59:32 -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 6318359d1..379cb9d17 100644 --- a/drivers/raw/skeleton_rawdev/Makefile +++ b/drivers/raw/skeleton_rawdev/Makefile @@ -23,5 +23,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 062d732ec..53c8c13e0 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..3e62b1d16 --- /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 = NULL; + + 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