From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0059.outbound.protection.outlook.com [104.47.36.59]) by dpdk.org (Postfix) with ESMTP id BD2961B16A for ; Tue, 2 Jan 2018 13:44:03 +0100 (CET) Received: from BN6PR03CA0074.namprd03.prod.outlook.com (10.164.122.140) by MWHPR03MB2702.namprd03.prod.outlook.com (10.168.207.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.323.15; Tue, 2 Jan 2018 12:44:01 +0000 Received: from BN1BFFO11FD046.protection.gbl (2a01:111:f400:7c10::1:139) by BN6PR03CA0074.outlook.office365.com (2603:10b6:405:6f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.386.5 via Frontend Transport; Tue, 2 Jan 2018 12:44:01 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; 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 BN1BFFO11FD046.mail.protection.outlook.com (10.58.145.1) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Tue, 2 Jan 2018 12:43:37 +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 w02Chfdh020140; Tue, 2 Jan 2018 05:43:59 -0700 From: Shreyansh Jain To: CC: , , , Shreyansh Jain Date: Tue, 2 Jan 2018 18:27:49 +0530 Message-ID: <20180102125749.2379-6-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102125749.2379-1-shreyansh.jain@nxp.com> References: <20180102125749.2379-1-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131593706172278662; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(336005)(396003)(346002)(376002)(39860400002)(39380400002)(2980300002)(1110001)(1109001)(339900001)(189003)(199004)(85426001)(104016004)(305945005)(36756003)(77096006)(68736007)(53936002)(8656006)(97736004)(2906002)(498600001)(81156014)(356003)(4326008)(51416003)(59450400001)(6666003)(8676002)(76176011)(48376002)(50466002)(54906003)(5890100001)(2351001)(86362001)(6916009)(1076002)(5660300001)(106466001)(16586007)(2950100002)(81166006)(50226002)(105606002)(8936002)(47776003)(316002); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR03MB2702; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD046; 1:8c6wI/NzJn31h2wRptwI8KnsHF78/JKSXviXfcbeiJKhJKtLKZqLLW6blsIUbU5o6SqUfsAA7SABHJJdfe8OCftLVSWfDHXKfTayecb6Nf+5SXcvetUf+IfawqXklIWG MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 5e79ccad-e8e4-4e14-6786-08d551de718a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4628075)(201703131517081)(5600026)(4604075)(2017052603307); SRVR:MWHPR03MB2702; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2702; 3:QmLHcDZA6GYzsD0wJLD7HTf+A7Q3N50dv79vqymbnEU3bLbbbFbpc/qb+cFiH3VD/WoXXZibT6d0ExWMlSrPmWE6XV9vSb8ChT4x6iEWN74byl4VZ20Ex8+AaHquWcoG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n0cuwkCPJz28nEEC6Sa20IR/phRIvXixC5ayFfhrB1lO3SjoNo44/6igjfRDqBiGL9PH5OUMMrwGzrgarOhZdGQF/vN6ruxDzTXJuw6zUVsn24AYF1+Scxp7E6sDknpo+ncX7SXzY2Ec39mtjuk8rMHc X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095135)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231023)(944510075)(944921075)(946801075)(946901075)(3002001)(10201501046)(6055026)(6096035)(201703131430075)(201703131433075)(201703131448075)(201703161259150)(201703151042153)(20161123565025)(20161123561025)(20161123556025)(20161123563025)(20161123559100)(201708071742011); SRVR:MWHPR03MB2702; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:MWHPR03MB2702; X-Forefront-PRVS: 0540846A1D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR03MB2702; 23:LGkeTZf+HPfY7jWm2KwcGgjPllk9somW/pNCqN8Vw?= =?us-ascii?Q?YQgsNc6x4NZZypPu3uE3V9RlA9jT8tRndHfZ+4ViSH1ozqCC3Ystts/fEy66?= =?us-ascii?Q?8PsNpcomNvWT2QSvCDSYrXcvp6wJac4RTyYbFEn1v7wueidKO7w6rZMpRCdv?= =?us-ascii?Q?Z9PP9fwIrgcbZOaDOUMa2uWYgyhVpg9m8i0/2lgL1FAGxRIhn468912Axmqr?= =?us-ascii?Q?nKYkAWwE6eQsyOp6VA775yH1K2RFhAVlkOdmFgMV3ufDcpQrTIE7QcdB1Lb9?= =?us-ascii?Q?RViBn03S54LfLHiTyuyb4iI5wjT85N/so+vbysJHajP2znUxfffqeeeIRSr5?= =?us-ascii?Q?+tTwZmyNCx2ffActEy4oW+xOspGC0uqJpA4rKvmUtYC0YwhuQtLga9JQyV4f?= =?us-ascii?Q?Pa2NeZ303YWjwfis9tCsSXeCdZDFfjImSAXEuCcYIPHQ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/+PMbs7EPggZ+Yuue90ppMFm3zH/C8pwtvX2zrjlaQPcbxpqpNabDj+YWCxygL0/hUYZ2kuSWOd2P3mV64cfJ4BjtQyoTa+3kvcS0wrzWmvEecVk7ZVPDfgjGZHea2oB6BZeRl+CYnlgqiHR/3HSgxkX6+PaHTSc6CqJzuqnu4HLtdrpNYI349yD4I/IlOBfW7xw9c+Zk6FssDFfARdnikI0q5sBKjnZLeNI=; 5:z4R4juNk0u6TRrNOb/6X6RtOFAsMh2ybzrVByjtT09SpIANblQ6HS3CmMWN8+AL1Fqh+g3ynM1yTD11YyFcOUh70+jXFK1+EZVc6Gdie1qaD/2jUJoaFdqEzIwuqS5/2hKGsNeVa+S259pEnmbB0PjdLT+40LIEtmDEvO+6vjp4=; 24:GWF7ZK06Q4aCSVuu3JHI5GU5Kv8Ac/hful9qpY3U3VawulLFkRiv7mr2k8/aL7bmGJhZMr7AoeBI9BJLz/feWrhoFjm90knETtE4dwwMy0E=; 7:CG981fsst9WgdDPz+rs1xeT/qm8D/92Yu7ETPTcGeHXg1JQ6eUX/aIjAN2hiBWsaEWmxnDoZr+Crd/OzKufW6le0eZto5asRPq3wCYOKZrcACdmOrC0A7vgq+OgpzR1cNmTN2himIZJoHZ0Lk3Kr+7Uh9KyclAOBHluUEMEEMWf2ExXu7sX2i0uHCJQAJFBleLUeAh+uZsuJhe1xJDRJk/dHDidlJNI0UXotGCuFuvIfm6pNaHFpR5lq4CH/5MId SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jan 2018 12:43:37.0562 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5e79ccad-e8e4-4e14-6786-08d551de718a 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: MWHPR03MB2702 Subject: [dpdk-dev] [PATCH v1 5/5] test: 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, 02 Jan 2018 12:44:04 -0000 Patch introduces rawdev unit testcase for validation against the Skeleton rawdev dummy PMD implementation. Signed-off-by: Shreyansh Jain --- test/test/Makefile | 4 + test/test/test_rawdev.c | 376 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 380 insertions(+) create mode 100644 test/test/test_rawdev.c diff --git a/test/test/Makefile b/test/test/Makefile index bb54c9808..038343d38 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -214,6 +214,10 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_SW_EVENTDEV) += test_eventdev_sw.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_OCTEONTX_SSOVF) += test_eventdev_octeontx.c endif +ifeq ($(CONFIG_RTE_LIBRTE_RAWDEV),y) +SRCS-y += test_rawdev.c +endif + SRCS-$(CONFIG_RTE_LIBRTE_KVARGS) += test_kvargs.c CFLAGS += -O3 diff --git a/test/test/test_rawdev.c b/test/test/test_rawdev.c new file mode 100644 index 000000000..000331387 --- /dev/null +++ b/test/test/test_rawdev.c @@ -0,0 +1,376 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2017 NXP + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "test.h" + +/* Using relative path as skeleton_rawdev is not part of exported headers */ +#include "../../drivers/raw/skeleton_rawdev/skeleton_rawdev.h" + +#define TEST_DEV_ID 0 +#define TEST_DEV_NAME "rawdev_skeleton" + +static int +testsuite_setup(void) +{ + uint8_t count; + count = rte_rawdev_count(); + if (!count) { + printf("\tNo existing rawdev; Creating 'skeldev_rawdev'\n"); + 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(); + 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"); + 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); + TEST_ASSERT(socket_id != -EINVAL, "Failed to get socket_id %d", + socket_id); + socket_id = rte_rawdev_socket_id(RTE_RAWDEV_MAX_DEVS); + 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); + TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret); + + rdev_info.dev_private = &skel_conf; + + ret = rte_rawdev_info_get(TEST_DEV_ID, &rdev_info); + 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); + 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); + 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); + TEST_ASSERT_SUCCESS(ret, "Failed to obtain rawdev configuration (%d)", + ret); + + 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); + 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); + TEST_ASSERT_SUCCESS(ret, "Failed to obtain rawdev configuration (%d)", + ret); + + /* call to test_rawdev_configure would have set the num_queues = 1 */ + 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); + TEST_ASSERT_EQUAL(q.depth, SKELETON_QUEUE_DEF_DEPTH, + "Invalid default depth of queue (%d)", + q.depth); + 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); + TEST_ASSERT_SUCCESS(ret, "Failed to obtain rawdev configuration (%d)", + ret); + + /* call to test_rawdev_configure would have set the num_queues = 1 */ + 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); + 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); + TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret); + + 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); + 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); + TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret); + + TEST_ASSERT_EQUAL(qget.depth, SKELETON_QUEUE_DEF_DEPTH, + "Release of Queue 0 failed; (depth)"); + + 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); + TEST_ASSERT(!ret, "Unable to set an attribute (Test1)"); + + dummy_value = malloc(sizeof(int)); + if (!dummy_value) + 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); + 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); + 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); + TEST_ASSERT_SUCCESS(ret, "Failed to obtain rawdev configuration (%d)", + ret); + 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); + TEST_ASSERT_SUCCESS(ret, "Failed to obtain rawdev configuration (%d)", + ret); + 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); + 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); + 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 struct unit_test_suite rawdev_testsuite = { + .suite_name = "rawdev code unit tests", + .setup = testsuite_setup, + .teardown = testsuite_teardown, + .unit_test_cases = { + TEST_CASE_ST(NULL, NULL, + test_rawdev_count), + TEST_CASE_ST(NULL, NULL, + test_rawdev_get_dev_id), + TEST_CASE_ST(NULL, NULL, + test_rawdev_socket_id), + TEST_CASE_ST(NULL, NULL, + test_rawdev_info_get), + TEST_CASE_ST(NULL, NULL, + test_rawdev_configure), + TEST_CASE_ST(test_rawdev_configure, NULL, + test_rawdev_queue_default_conf_get), + TEST_CASE_ST(test_rawdev_configure, NULL, + test_rawdev_queue_setup), + TEST_CASE_ST(test_rawdev_queue_setup, NULL, + test_rawdev_queue_release), + TEST_CASE_ST(NULL, NULL, + test_rawdev_attr_set_get), + TEST_CASE_ST(NULL, NULL, + test_rawdev_start_stop), + TEST_CASE_ST(test_rawdev_queue_setup, NULL, + test_rawdev_enqdeq), + TEST_CASES_END() /**< NULL terminate unit test array */ + } +}; + +static int +test_rawdev(void) +{ + return unit_test_suite_runner(&rawdev_testsuite); +} + +REGISTER_TEST_COMMAND(rawdev_autotest, test_rawdev); -- 2.14.1