From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D732CA0547; Wed, 20 Oct 2021 10:22:35 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8D0EF411BB; Wed, 20 Oct 2021 10:22:33 +0200 (CEST) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2085.outbound.protection.outlook.com [40.107.92.85]) by mails.dpdk.org (Postfix) with ESMTP id B8F7140683 for ; Wed, 20 Oct 2021 10:22:23 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IjoB3ymd8xg70ML6y9265esxyz1ZuraAlREh6Lblzzc7xya3hkgmB7Cr6hfdPksjZhJblsUh71+fWkNbjr95mXDJUxHrKcE2hUSKDMQFmlBAufv4LwVE8XqmBY6H/PLXF/5LVyxfUbOM8ImTD5cvIrK1brsWmJyphshNq724T3PqPxH3r1RPA9S5L7lET1cbpYxbVgQ3+yqB45qNxoKM9kvNmMuvuU5uuv4J54nfT7quCaZYZ0Q0ykqbQhSVdxh+WGKw0Iy38n/P3oYmQj/ZVmP0nCIvoB0aXdaZLfnCxmD57VdaeoizFtXSJvhYAJoWpwr82W4+ltwrCp/mSPE5rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RMngUD/DhjNgde+VVAeZnZyV5dI+nE2n/WwXl2gl/1c=; b=fbzvyibUcEd+oxq9uNMCFGITbbJ01zV8T7pPfxYczwq282tre1nal5KjD/t2kiZe3EAa39Sd1COLPQX2B9B3j/dKFz5CBqXtMh489GQ1i+NJUbZ75qgUTiRcEFi+f/1z56JabMPE/IQmOt8sMIVX/2MfsejnfiR+ZtysIiWErxdDtUnUEEKusajnwxM0sFRxVs7I3fE7p+Kqo/qY5y9FcCS0w/+taLqRj+Nj6ajpS6kUnmXCTf1CpC56kkTtwhS/a/uYPUceV/dzkBwEZd0LZyaNNyyho/golSKIZvN+DuXYDbNkyZ7LbkfpCHp+s7nD1fBZKixAG0iEieo4txnOpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=monjalon.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RMngUD/DhjNgde+VVAeZnZyV5dI+nE2n/WwXl2gl/1c=; b=BWZPWK3AuyysWx0EWjKVByy+q8Fk8QtcDAco0+uqXYjEY/cBlSZJKSDDM4fjnmAf265CLBu8GAPfy7uri7x9ZGyEm+NDQ895MqUPinxTIo2dYlCGvH+VLHl3EZeytW+FBW5X/PwRUvJnwCnjKad63JcSJSnxBJPTsp0NPRURrGo8gcqOZWTgad5M0pTb0TKIv/PqFaAxCccqZZryYjOVJ2WHvGx3bezIXFRWpFb8Mxe3C4SxfhFbBAIRV/Xy1c7HJ8/ls9hI3RkOiuPSal4a/Qa1GbruL+qailU5U+JZmGoDEkPBTmztVNdoqrD+cqav8SfUNO23Mkjz6tpCkU1EhA== Received: from DM5PR07CA0113.namprd07.prod.outlook.com (2603:10b6:4:ae::42) by DM6PR12MB2987.namprd12.prod.outlook.com (2603:10b6:5:3b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Wed, 20 Oct 2021 08:22:22 +0000 Received: from DM6NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:4:ae:cafe::72) by DM5PR07CA0113.outlook.office365.com (2603:10b6:4:ae::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Wed, 20 Oct 2021 08:22:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; monjalon.net; dkim=none (message not signed) header.d=none;monjalon.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT014.mail.protection.outlook.com (10.13.173.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Wed, 20 Oct 2021 08:22:21 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 20 Oct 2021 08:22:18 +0000 From: Xueming Li To: , Gaetan Rivet CC: , Thomas Monjalon , "Lior Margalit" Date: Wed, 20 Oct 2021 16:22:00 +0800 Message-ID: <20211020082200.2412189-4-xuemingl@nvidia.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211020082200.2412189-1-xuemingl@nvidia.com> References: <20211005123012.264727-1-xuemingl@nvidia.com> <20211020082200.2412189-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 67f75303-1fc1-458f-d574-08d993a2bd6e X-MS-TrafficTypeDiagnostic: DM6PR12MB2987: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:114; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c+5dx9CUApqVuweXEm96Sn/UJfVMuMswQvPrORoqR9Eyf7j6UNm4R9mjlHVMi2Z0y3gLl+v+wu1r2q5+bEqq4gTLc9sbit2adc3L5y1F0afB8zxzzXbAWExcmDUraM/Lznu1Q2VZZkNK4t34S2nxb+bW8ythn+UV6BwknktCbHRpHfYplT10koCVb5rGK10TDlWCa/rZ7rUcUXMgG6PFXYltR4datdV2mwsBJBU56Kupx+uD8CFzSC7iQ1RpwfLcJrPFJjWiRJbYBPLYKjaFvtV+xkluh6SNXw49eDUvuiYbVJhBLZm5IcTv6kFd5MGrQkHMd/ZpwPQ4AlM8E4/lsnnyobZt9ceG1/gf81bfxMe9F0mbA3xPH5BhlFAJ8NkB/Ha7QhdJwoJOQ5asd7VVKVR1xO84zmi8xAMK9izvcrhlZorcmgBna6O4M2APAmgL0wWRTZsBBxm2KYYvilLwUJslENyWW43fyzZCgiCACEGMsidlDsJQuI9zVHASRnlZDa8nzOpjVEIySM34NKYMO/ha5XY/WVSKCPrEMLILu4y7cYoKL2BqwTlwrcQBEp7qqjt1t3cnwjNS8uYvxWs7wX0QiEjZSfASeuR0DT+1gbFpFEZFQ6C1dv2Sfyf6yMP40v2vGnboYBX5XnD6mf4eO4zplWqTD3qjD6IOtgcaPW0mS5XKVjOKRX7pS5QE+02GpOJNbBsKkAz8jZ+4n/7BQw== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(36756003)(83380400001)(7636003)(356005)(2906002)(508600001)(6666004)(107886003)(1076003)(86362001)(36860700001)(82310400003)(70586007)(47076005)(2616005)(6286002)(426003)(336012)(8676002)(186003)(16526019)(8936002)(4326008)(26005)(54906003)(110136005)(7696005)(55016002)(70206006)(5660300002)(36906005)(316002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2021 08:22:21.7181 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 67f75303-1fc1-458f-d574-08d993a2bd6e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2987 Subject: [dpdk-dev] [PATCH v3 3/3] test/devargs: add devargs test cases X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Initial version to test Global devargs syntax. Signed-off-by: Xueming Li --- app/test/meson.build | 2 + app/test/test_devargs.c | 184 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+) create mode 100644 app/test/test_devargs.c diff --git a/app/test/meson.build b/app/test/meson.build index a16374b7a10..842388b0d32 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -42,6 +42,7 @@ test_sources = files( 'test_cryptodev_security_pdcp.c', 'test_cycles.c', 'test_debug.c', + 'test_devargs.c', 'test_distributor.c', 'test_distributor_perf.c', 'test_dmadev.c', @@ -204,6 +205,7 @@ fast_tests = [ ['common_autotest', true], ['cpuflags_autotest', true], ['debug_autotest', true], + ['devargs_autotest', true], ['eal_flags_c_opt_autotest', false], ['eal_flags_main_opt_autotest', false], ['eal_flags_n_opt_autotest', false], diff --git a/app/test/test_devargs.c b/app/test/test_devargs.c new file mode 100644 index 00000000000..13e95f052b0 --- /dev/null +++ b/app/test/test_devargs.c @@ -0,0 +1,184 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2021 NVIDIA Corporation & Affiliates + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "test.h" + +/* Check layer arguments. */ +static int +test_args(const char *devargs, const char *layer, const char *args, const int n) +{ + struct rte_kvargs *kvlist; + + if (n == 0) { + if (args != NULL && strlen(args) > 0) { + printf("rte_devargs_parse(%s) %s args parsed (not expected)\n", + devargs, layer); + return -1; + } else { + return 0; + } + } + if (args == NULL) { + printf("rte_devargs_parse(%s) %s args not parsed\n", + devargs, layer); + return -1; + } + kvlist = rte_kvargs_parse(args, NULL); + if (kvlist == NULL) { + printf("rte_devargs_parse(%s) %s_str: %s not parsed\n", + devargs, layer, args); + return -1; + } + if ((int)kvlist->count != n) { + printf("rte_devargs_parse(%s) %s_str: %s kv number %u, not %d\n", + devargs, layer, args, kvlist->count, n); + return -1; + } + return 0; +} + +/* Test several valid cases */ +static int +test_valid_devargs(void) +{ + static const struct { + const char *devargs; + int bus_kv; + int class_kv; + int driver_kv; + const char *bus; + const char *name; + const char *class; + } list[] = { + /* Global devargs syntax: */ + { "bus=pci", + 1, 0, 0, "pci", NULL, NULL}, + { "class=eth", + 0, 1, 0, NULL, NULL, "eth" }, + { "bus=pci,addr=1:2.3/class=eth/driver=abc,k0=v0", + 2, 1, 2, "pci", "0000:01:02.3", "eth" }, + { "bus=vdev,name=/dev/file/name/class=eth", + 2, 1, 0, "vdev", "/dev/file/name", "eth" }, + { "bus=vdev,name=/class/bus/path/class=eth", + 2, 1, 0, "vdev", "/class/bus/path", "eth" }, + { "bus=vdev,name=///dblslsh/class=eth", + 2, 1, 0, "vdev", "///dblslsh", "eth" }, + /* Legacy devargs syntax: */ + { "1:2.3", 0, 0, 0, + "pci", "1:2.3", NULL }, + { "pci:1:2.3,k0=v0", + 0, 0, 1, "pci", "1:2.3", NULL }, + { "net_virtio_user0,iface=test,path=/dev/vhost-net,queues=1", + 0, 0, 3, "vdev", "net_virtio_user0", NULL }, + { "net_virtio_user0,iface=test,path=/class/bus/,queues=1", + 0, 0, 3, "vdev", "net_virtio_user0", NULL }, + }; + struct rte_devargs da; + uint32_t i; + int ret; + int fail = 0; + + for (i = 0; i < RTE_DIM(list); i++) { + memset(&da, 0, sizeof(da)); + ret = rte_devargs_parse(&da, list[i].devargs); + if (ret < 0) { + printf("rte_devargs_parse(%s) returned %d (but should not)\n", + list[i].devargs, ret); + goto fail; + } + if ((list[i].bus_kv > 0 || list[i].bus != NULL) && + da.bus == NULL) { + printf("rte_devargs_parse(%s) bus not parsed\n", + list[i].devargs); + goto fail; + } + if (test_args(list[i].devargs, "bus", da.bus_str, + list[i].bus_kv) != 0) + goto fail; + if (list[i].bus != NULL && + strcmp(da.bus->name, list[i].bus) != 0) { + printf("rte_devargs_parse(%s) bus name (%s) not expected (%s)\n", + list[i].devargs, da.bus->name, list[i].bus); + goto fail; + } + if ((list[i].class_kv > 0 || list[i].class != NULL) && + da.cls == NULL) { + printf("rte_devargs_parse(%s) class not parsed\n", + list[i].devargs); + goto fail; + } + if (test_args(list[i].devargs, "class", da.cls_str, + list[i].class_kv) != 0) + goto fail; + if (list[i].class != NULL && + strcmp(da.cls->name, list[i].class) != 0) { + printf("rte_devargs_parse(%s) class name (%s) not expected (%s)\n", + list[i].devargs, da.cls->name, list[i].class); + goto fail; + } + if (test_args(list[i].devargs, "driver", da.drv_str, + list[i].driver_kv) != 0) + goto fail; + if (list[i].name != NULL && + strcmp(da.name, list[i].name) != 0) { + printf("rte_devargs_parse(%s) device name (%s) not expected (%s)\n", + list[i].devargs, da.name, list[i].name); + goto fail; + } + goto cleanup; +fail: + fail = -1; +cleanup: + rte_devargs_reset(&da); + } + return fail; +} + +/* Test several invalid cases */ +static int +test_invalid_devargs(void) +{ + static const char * const list[] = { + "bus=wrong-bus", + "class=wrong-class"}; + struct rte_devargs da; + uint32_t i; + int ret; + int fail = 0; + + for (i = 0; i < RTE_DIM(list); i++) { + ret = rte_devargs_parse(&da, list[i]); + if (ret >= 0) { + printf("rte_devargs_parse(%s) returned %d (but should not)\n", + list[i], ret); + fail = ret; + } + rte_devargs_reset(&da); + } + return fail; +} + +static int +test_devargs(void) +{ + printf("== test valid case ==\n"); + if (test_valid_devargs() < 0) + return -1; + printf("== test invalid case ==\n"); + if (test_invalid_devargs() < 0) + return -1; + return 0; +} + +REGISTER_TEST_COMMAND(devargs_autotest, test_devargs); -- 2.33.0