From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0054.outbound.protection.outlook.com [104.47.41.54]) by dpdk.org (Postfix) with ESMTP id 5FE7E7CB6 for ; Sun, 28 May 2017 21:59:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=X8GJlgfA+6NJ6uxSWpU1zmbqrDIHljvkABMYQzgIsk8=; b=bBTGDRRGefWbUDpR9xnUEiDGcd5k3QPtxTwAqbQk/zAH+vEFRSyx62eIh2s0XIVJmuJlPTgQnl/OQpjewA9D/gj35dSIgxTdskTI+eMDauFdJ+01jAmoaN7AUfF5XaacR5KBn90ghTKtSdU0wjNI1KIVhTN6aex5rXKalU0fzG4= Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=caviumnetworks.com; Received: from jerin.domain.name (111.93.218.67) by CY1PR0701MB1725.namprd07.prod.outlook.com (10.163.21.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1124.9; Sun, 28 May 2017 19:59:53 +0000 From: Jerin Jacob To: dev@dpdk.org Cc: bruce.richardson@intel.com, harry.van.haaren@intel.com, hemant.agrawal@nxp.com, gage.eads@intel.com, nipun.gupta@nxp.com, narender.vangati@intel.com, nikhil.rao@intel.com, gprathyusha@caviumnetworks.com Date: Mon, 29 May 2017 01:28:25 +0530 Message-Id: <20170528195854.6064-5-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170528195854.6064-1-jerin.jacob@caviumnetworks.com> References: <20170528195854.6064-1-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BMXPR01CA0003.INDPRD01.PROD.OUTLOOK.COM (10.174.214.141) To CY1PR0701MB1725.namprd07.prod.outlook.com (10.163.21.14) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY1PR0701MB1725: X-MS-Office365-Filtering-Correlation-Id: 126e3b2f-8f35-485c-27a0-08d4a6041d19 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:CY1PR0701MB1725; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 3:Hf+F4wJPFivn5UKNUA7EG5WCK4gym+69UbWN/pzrfU+FEL67y4m9p/I2FmSpTteXOeR1lqXXsMlvfWkYHLubvj6Hk5MIuS+9WiFqJP93paIPjKzwFM45CaTTIaKeinMh+4UgUpbmSrP7JrdQLe2+RlOFrewe7HsXNbtCrFHRah1Zg2zPcACeOjHxt5Z1b3mSAs14b/klssj1ZpPVx4ZsBgyxbJvt3fPD6FtbDraXkGTYKhv9OWtr6NHaqFbmUVBnH+GuImblRppubrdKb9EflhrwquW9fMz4rmZIIMjEY57/yxCeqLPLobkr4WWFhNAENpixB3d2d53e8BkirFUvdw==; 25:zZOWvX8gbHJFOkRUDYZm/Yk3hiVCxfES1mZtbB9kRxBSZSrrE6rc6aN6PwBEXMshLi1UFAHK3jg9W5hkudVmbsxL0F7GY9b5ospv7zsMLx5/5Do0xu9y7H9MmiNeaYsjhwDkXPXtx9xzSSMJKsaHmRhDizDYN2ikZZDNZTfoE2gDfj7pYtWV9fZv2Lsy289bnm7Fw8yiG0PP/N2YJA3180zD7Vs41W0+fDQoB2C3XoyBgMhjpGa6Mm134M/EF6uJESvrSTnbDEkFD73vchN+3tpFZ2HzQdj9iS6RCHQ0lBXBxhJrhIT+PJOyxX1HLFX2pJMMQKfXIC15jXCYs+MRDM4jDjjAh47aY9qef3Sm2BW00RZE/Y09V+XSKocB2/32YzJ5sRE7i28aQbn/9sEKVEIfr3Ovz5ck4ZVTM9nWBzIkToLvW3MGT+X2Dg/TXNxLcL/eevzwqZ3sOQ8tFNS/wrRTv21z9KMyhAKqyjCyNeM= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 31:WV0JxZsPtiJ4MwtvaG3FVOohdUQpkLqrGfi9OumG5hP3TEhMkAzxXJGDpLCMK0FK05ivWl6Iki0YnWp+l2bjso80IaiF7KK7ISEQWu3yWOEv3XNEawnlWL0DH5QCo+bBiL+dMne+OEWrDqM/svtZC6PbTVmzt4beAKzCNnehcZWdDSkqXoNx6GKDbheIis2GZGUg17mI2NY2Ag4SsQr7RoCUm7A5lG9CRnpjm3RTyWc=; 20:XQ18bKlGz6ZgOp3nTO5bvDM/cpqP23UKNaKqeg3HNdftz4bdn+avAKWXK4m83x/sdmx4DnV1reayrlUut9tj6CmEjH9NmyRC3AoNoJ/vxwTre6h6xveI31tipzzjUVxulFAykr82iD0IMLqWBEbMn69ngO7amkVTXT8quwcTb/25KsBzP3OUdVGqX9QMmw+UQKkTBR51GkUw84eSQQrwoidY8Xk7BYQQmnKsGsvmqD+WYBv+3cZ7xs21yUooyTmXjuZwTqEY9XSECd9l4lKpUsBRitsqK2vqzSgcSgvCEhWDzh4tqM4QRgoJbHLu4hv8MevB4IIrPw3uo84bu0gAOy+WFj8Av0st0pYb47x9bpgzJpUfbiye3aj0L1rHzOhUC0R6XEELr8INQIUDloa42AV5EU/Yu2AgAOmacth8P8iO8m8z2JonXAG+CDfpXxZP4IpQsKYRr1boIWwGoJYlNf0aKZGutQUJZcOkvaex1xnuTAt6Uh1ijIrjvbah89xGIoltCLrpIIWjXF9lDnAgR3ihd8WjMYFGStJP4EjXKSqtMUWqXxTFNqyd5/RCx0xy9XTdW2MM+vdj2VbdSSu8++A8Da+Gcp9D+NrCMmkBoOg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700073)(100105000095)(100000701073)(100105300095)(100000702073)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(100000703073)(100105400095)(6041248)(20161123562025)(20161123555025)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(100000704073)(100105200095)(100000705073)(100105500095); SRVR:CY1PR0701MB1725; BCL:0; PCL:0; RULEID:(100000800073)(100110000095)(100000801073)(100110300095)(100000802073)(100110100095)(100000803073)(100110400095)(100000804073)(100110200095)(100000805073)(100110500095); SRVR:CY1PR0701MB1725; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0701MB1725; 4:vA9EIIQiqMHCQVMhrYc0n64rrx3PmOJmd9jqfQlb?= =?us-ascii?Q?Sa0sHWBXoSSmtNWMQiWdpwNI1UxvQxkxYC8riemdXIlIRZY/SABMA2/0FwJ3?= =?us-ascii?Q?r6T7UVAAc+t2IA4CEjN8msxjaw9Zk62QvUpgQz8f4D+Tu6IIqq/86fctUWjS?= =?us-ascii?Q?zJe4LzAMtqfCBmDlayHEuevdeYq5ra+lKhy0l4vkQosuFIVOc0vDCZJ5cSMa?= =?us-ascii?Q?yqzRyR6wCoLKqmhKYfbrbpaPJ74OZdQdTp+56m9DIigBsOaTeoIjeiT3c3wo?= =?us-ascii?Q?igj/uDRfC8qrJhmdzQJf6x8MrBwnEEj9Tk4U6NFSfSPjxsL7UWZ/YdIONV4o?= =?us-ascii?Q?CwsRoLum1SWf37mV0qeA6u4pGYAUD2miAiuvjz4mV8kHRfZ3Tw5Zt8zlphdy?= =?us-ascii?Q?3rnGNc95oVEgRe2cKqMWcg2h/voCxSAgB8hwWOdx3UIJ8lzF4QQygJqAW2oJ?= =?us-ascii?Q?BwkKcBs6JeDvaPe+h/WKaLFB13nHvWoGVINkbWrpZGiaH75zuaCepXjgo+pZ?= =?us-ascii?Q?S6ZXAOHX5OHuKyt48fb98d1DgnN4MLviGrNEqBUV0YSn8IyG4CQkYiHk/F2d?= =?us-ascii?Q?F0fSmU6D2tBFi1/0PE3WOT05pBBmzzFAoF3Pb70GWiT6nA5nDVZNl+e0VsSb?= =?us-ascii?Q?vVgQg90C9uxMpZjrMq2XDEmpLlfc4n9muM4adB4OxRPWBy0dL94Pu1vd1SDN?= =?us-ascii?Q?0QxDOp9qvLtMMdSkZJj2Z8i6i9wCqEHYnK08FuC8G6S6EoyefFV+fNpwbLWN?= =?us-ascii?Q?gEvjyWCuJ68JwaxKWbrYSfhcUKSOLjKJNJRFqHZSd6pTd9ZPekQMUhrZ71C3?= =?us-ascii?Q?xYBjZXkRT9fsAWbTgR+uFKp3aJracu+wPEI9CptOkvrbUgPty/LcNhyjdWV/?= =?us-ascii?Q?Q8qvtfSxMGiMyyauSF7PiomqGe+lqcgS10Gj3/r2gEbSwZ86JKHrLr27IAF+?= =?us-ascii?Q?vhO5Sog6TQq5zRyGnXoqeLfxfPNQly4PLArsRXbIn3iwZedP9gTMkXXgC2vH?= =?us-ascii?Q?mGeKkijCMc4QtZZfMmdXpMx3sR97LulHF01GdfAHENfW5SByGaMxa9UhFcjd?= =?us-ascii?Q?7leFOZMGXEZQrCzmFhBj4jDTwMJPqMExcjLcMGZSPsPgCZr3Ob9OGcAVoAr4?= =?us-ascii?Q?pu6piuzdpOs=3D?= X-Forefront-PRVS: 03218BFD9F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39450400003)(39850400002)(39410400002)(39840400002)(39400400002)(81166006)(6486002)(66066001)(4326008)(50986999)(76176999)(50226002)(189998001)(72206003)(36756003)(6506006)(38730400002)(5003940100001)(5009440100003)(110136004)(107886003)(42186005)(53416004)(7736002)(8676002)(48376002)(50466002)(1076002)(3846002)(6116002)(6512007)(2361001)(305945005)(2906002)(6666003)(478600001)(25786009)(5660300001)(2351001)(6916009)(42882006)(2950100002)(33646002)(8656002)(47776003)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0701MB1725; H:jerin.domain.name; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0701MB1725; 23:E/F6rz0tk4RyFgQz2lg1q72Cf3WeNXaH/u+vom9?= =?us-ascii?Q?UvfkoSs4xjTyQhioBuV7w13JVjNY7lgJHm8D0B86USOrX0JeCbeIuyQGI3Di?= =?us-ascii?Q?KNRPBlhpV7w27v0IZjG1XeWLC5sdfo68eqi1qCmhhwWWH09tSD2dDH5XzxUX?= =?us-ascii?Q?d9kNPNd/E9+Rxbv2hQMm7/udF/rou7J3csPCfaOlZlPW6RU/nirxM1amPVpQ?= =?us-ascii?Q?tbCHqwQGgqBnzAC0lwHspDALB8BN2JfRrYrjMHvbQPWQR5ONNDYG7SYkmo1N?= =?us-ascii?Q?/AvhWlp7jnLS/avbaj74XSYi0UgzikyaBrkmBq3QCSxhQwkGoskcAjqOE5Gv?= =?us-ascii?Q?vE1r2rzGNi1Y5/aBqW8eQAcdhvZY0t5rlP4ptfwcjc+n2INqHRp9fHutCyb/?= =?us-ascii?Q?uju5aAUU560L76+Znn8ekwvPBwCqO7Qqe8hUZkoylajlOYfFPpP1YxVlsvwA?= =?us-ascii?Q?0xg0Dp/N+OvTqi0pvF82id1QDWShPU6hH6EmXmVHifRyBhokltt5fnizCyGV?= =?us-ascii?Q?OtKa5eRag/8m5VQzqkUKaoLBUxCGcJPMKaJ2eXZ3XE/NrcYDllUDCturvwfz?= =?us-ascii?Q?2IMxHjKiOR52hjGqridWa4FN/OYdKglPyCWrtx0sNVtCHXPaR+FWKsmdvnhr?= =?us-ascii?Q?it1lVleRUiU4YgR2wSjvXu3Vf0HYgNfU+j3DbhXkY6RQ81sPlTK3SPjTzBSO?= =?us-ascii?Q?cl+zw3D7bgtsXhbje8/a2h/mIWutPZDkYixwlpUM7O8MlLVyGraKZ2KUSWpq?= =?us-ascii?Q?uyTLMkaO8JFitMzoXEm8fzCoE0ygwkNQ9hnk666QeUwytXW2Pr5iLZwVA+9P?= =?us-ascii?Q?WSWfY1FMa61O2TpIHh0pHPLO6cELmucUzTSsZdOoccmukyl6h8P/3Ljed2/P?= =?us-ascii?Q?bgWgSRkeBJCMMp7HJ2Ldxc01wlZqnquY6z49o6vhEZ23b+E21IwsnNCEltoN?= =?us-ascii?Q?MEPYXvHJqylB7qcy48mhLxoMgkqnChaX/JXPOQr2R5cU/nGCcECSy1V27fJs?= =?us-ascii?Q?MNJo0bNAd7vfGe1yF561nxYIIwFEWjSonNx22QCgSA2PCWgax+p+066sYgwd?= =?us-ascii?Q?CMQCejY9z5IfC9biS5jEp8DrEjE58nXn0BchiK403H3ZMZbGfm5A10spPXa2?= =?us-ascii?Q?LhB/cVbVnwyDo3RJ3V6c0a0bqQolXgJlroZKNumNOZJ+lftWUzEHHL+2DOqF?= =?us-ascii?Q?+yhVdFC6Tpyc6Whe55SCiYAvBEQZZO5c8eBii?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 6:jeTP7zGm97EEQb/lXUeZazhLE/s6OMsu+8aHVljuwG87dxul8mTOK+1MvvIjfFuDMIZAqSUVZ7siWGyVnif1qiUWwePpl8yuxaG8sYiYcjNimUfFbTI39JYReK5ETDlkWKee0hgsDkMmXcT21XTpAc3wMxFGKrLs2caNyahmF5oBFARgeceVmp0JHtrCcpIPjNHdTmkRn6vp01EIwwFgTC4C0rSaUVX2uAPbEnwpZAe/8Cl2jf7bKO6DXqiKlgRK5T/NKzDWS9iD3uS3oK2KGUDAd19zV2CDmMMVmrrAuuQfpawhV8GIA5C0ukNJdnQ5k8yyL9HxIGyFImmi7orbhniMicoERSrj2V34LZ5rTKkrYN0lkOLlDLezr3iwCo5M/SrRJ5Gw9w5T2lT3Bq2JkfvpB5N0HKzMPw2fO4pZA65RqzjzqRmAIUa464G+JltbjPkhT67vaMpzy4Ogrv7qKdmu/GUpkCoQnjXk3C9Sc/S27NORjZILwyp23qVWHZqOaCmNVeV1WOa9NBn2o4sdSg== X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 5:zz0OfpvpCp3UWpibat1QDI3fWFiKmyUaO5NrbHxFXTAz709gmvnDF0jFIzC6A/cInfvKZc6ulRAHhYayaydDMVPybtd3JDsmcomN7CP3I1APnNrWQ8yIYg4ZwSoyYvUvsJyz4ynNEg+6f6kG86o7V7/31c/ub1jdCXc6aHwiFehZkfh8KshBEsQ+NPRrsjNg0yGjocHgBSOxJVUgPWyfk/Zkv3bshWCsYNn5ACL4J02L2ddYJttclNPxdOlpl0+OEfJaub7e4MEhZ/7aHc+hu8hnPcEvVN5oHGFgFae0xWqLaK7NlWDZUk7R1QeUiDGbZ4+5VIASnbNgwF/ssSzfeK/5F5LXF3GiM1eqZlG29hunS6d3WyVIXfwfWNM3bOUfF1T1wPAZQfu1/loAigpiODSgcDlEdJnHABPGOmk4M8Osy3GLNu3v4TIK7/i/Df6Wx1TRJVFAvy+8gPHvhqDD4TxbF720BB+FluSNZV5diVmX6Aygk9nvdFeOmzrkWxbh; 24:VPg+p7oELqJjcRVEugXDSYLPrGyr1YQnnjHKnQOOBt4I5lDlLNxAQ5qu2wX4CCYnNsvwI7aMoL7phytGKFRA+3XxHlsG9/0YBlcgVMfdNJ4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 7:/pJBViyzTzR63JD0TFbkgEOGjuaCCg14L3aYf92J6FNB3iQMbxs+2LsumwLXmQQGwGE2+pfZXMSxMxpKQOaFKK381c3i+aXZOzwxrYxnYe71SbZ/JUc6syxzjAs5KSqsyr1MOdFK992Z3gC3loUsc0afWuFP/VjWm5XyCLYCvPc9Fb5bcjCHVJwqD9m1kl/8HhaKWxDodGgpLlwEGaflzahzmT+8bvyMyli8du6D3eG0VR8lliwNOBKa5v9jDmfbl3IZgEY+GOMfrXsf0TlwthmwvcCxxslHI0ILiff34MfJ5dTOjK7oK7PhS1KiVw2HriUHr4VQDWaI/Gx/bJsOxQ== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2017 19:59:53.0162 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0701MB1725 Subject: [dpdk-dev] [PATCH 04/33] app/testeventdev: add string parsing helpers 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: Sun, 28 May 2017 19:59:59 -0000 From: Guduri Prathyusha Add a couple of help functions that will allow parsing many types of input parameters, i.e.: bool, 16, 32, 64 bits, hex and list of cores etc. Derived from examples/ip_pipeline/parser.h Signed-off-by: Guduri Prathyusha --- app/test-eventdev/Makefile | 1 + app/test-eventdev/parser.c | 432 +++++++++++++++++++++++++++++++++++++++++++++ app/test-eventdev/parser.h | 79 +++++++++ 3 files changed, 512 insertions(+) create mode 100644 app/test-eventdev/parser.c create mode 100644 app/test-eventdev/parser.h diff --git a/app/test-eventdev/Makefile b/app/test-eventdev/Makefile index 8f4fc5f45..2e552a084 100644 --- a/app/test-eventdev/Makefile +++ b/app/test-eventdev/Makefile @@ -40,5 +40,6 @@ CFLAGS += $(WERROR_FLAGS) # SRCS-y := evt_main.c SRCS-y += evt_test.c +SRCS-y += parser.c include $(RTE_SDK)/mk/rte.app.mk diff --git a/app/test-eventdev/parser.c b/app/test-eventdev/parser.c new file mode 100644 index 000000000..d267447a2 --- /dev/null +++ b/app/test-eventdev/parser.c @@ -0,0 +1,432 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2016 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * For my_ether_aton() function: + * + * Copyright (c) 2009, Olivier MATZ + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the University of California, Berkeley nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * For inet_pton4() and inet_pton6() functions: + * + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "parser.h" + +static uint32_t +get_hex_val(char c) +{ + switch (c) { + case '0': case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': + return c - '0'; + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + return c - 'A' + 10; + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + return c - 'a' + 10; + default: + return 0; + } +} + +int +parser_read_arg_bool(const char *p) +{ + p = skip_white_spaces(p); + int result = -EINVAL; + + if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) || + ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) { + p += 3; + result = 1; + } + + if (((p[0] == 'o') && (p[1] == 'n')) || + ((p[0] == 'O') && (p[1] == 'N'))) { + p += 2; + result = 1; + } + + if (((p[0] == 'n') && (p[1] == 'o')) || + ((p[0] == 'N') && (p[1] == 'O'))) { + p += 2; + result = 0; + } + + if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) || + ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) { + p += 3; + result = 0; + } + + p = skip_white_spaces(p); + + if (p[0] != '\0') + return -EINVAL; + + return result; +} + +int +parser_read_uint64(uint64_t *value, const char *p) +{ + char *next; + uint64_t val; + + p = skip_white_spaces(p); + if (!isdigit(*p)) + return -EINVAL; + + val = strtoul(p, &next, 10); + if (p == next) + return -EINVAL; + + p = next; + switch (*p) { + case 'T': + val *= 1024ULL; + /* fall through */ + case 'G': + val *= 1024ULL; + /* fall through */ + case 'M': + val *= 1024ULL; + /* fall through */ + case 'k': + case 'K': + val *= 1024ULL; + p++; + break; + } + + p = skip_white_spaces(p); + if (*p != '\0') + return -EINVAL; + + *value = val; + return 0; +} + +int +parser_read_int32(int32_t *value, const char *p) +{ + char *next; + int32_t val; + + p = skip_white_spaces(p); + if (!isdigit(*p)) + return -EINVAL; + + val = strtol(p, &next, 10); + if (p == next) + return -EINVAL; + + *value = val; + return 0; +} + +int +parser_read_uint64_hex(uint64_t *value, const char *p) +{ + char *next; + uint64_t val; + + p = skip_white_spaces(p); + + val = strtoul(p, &next, 16); + if (p == next) + return -EINVAL; + + p = skip_white_spaces(next); + if (*p != '\0') + return -EINVAL; + + *value = val; + return 0; +} + +int +parser_read_uint32(uint32_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT32_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parser_read_uint32_hex(uint32_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64_hex(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT32_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parser_read_uint16(uint16_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT16_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parser_read_uint16_hex(uint16_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64_hex(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT16_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parser_read_uint8(uint8_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT8_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parser_read_uint8_hex(uint8_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64_hex(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT8_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +int +parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens) +{ + uint32_t i; + + if ((string == NULL) || + (tokens == NULL) || + (*n_tokens < 1)) + return -EINVAL; + + for (i = 0; i < *n_tokens; i++) { + tokens[i] = strtok_r(string, PARSE_DELIMITER, &string); + if (tokens[i] == NULL) + break; + } + + if ((i == *n_tokens) && + (strtok_r(string, PARSE_DELIMITER, &string) != NULL)) + return -E2BIG; + + *n_tokens = i; + return 0; +} + +int +parse_hex_string(char *src, uint8_t *dst, uint32_t *size) +{ + char *c; + uint32_t len, i; + + /* Check input parameters */ + if ((src == NULL) || + (dst == NULL) || + (size == NULL) || + (*size == 0)) + return -1; + + len = strlen(src); + if (((len & 3) != 0) || + (len > (*size) * 2)) + return -1; + *size = len / 2; + + for (c = src; *c != 0; c++) { + if ((((*c) >= '0') && ((*c) <= '9')) || + (((*c) >= 'A') && ((*c) <= 'F')) || + (((*c) >= 'a') && ((*c) <= 'f'))) + continue; + + return -1; + } + + /* Convert chars to bytes */ + for (i = 0; i < *size; i++) + dst[i] = get_hex_val(src[2 * i]) * 16 + + get_hex_val(src[2 * i + 1]); + + return 0; +} + +int +parse_lcores_list(bool lcores[], const char *corelist) +{ + int i, idx = 0; + int min, max; + char *end = NULL; + + if (corelist == NULL) + return -1; + while (isblank(*corelist)) + corelist++; + i = strlen(corelist); + while ((i > 0) && isblank(corelist[i - 1])) + i--; + + /* Get list of lcores */ + min = RTE_MAX_LCORE; + do { + while (isblank(*corelist)) + corelist++; + if (*corelist == '\0') + return -1; + idx = strtoul(corelist, &end, 10); + + if (end == NULL) + return -1; + while (isblank(*end)) + end++; + if (*end == '-') { + min = idx; + } else if ((*end == ',') || (*end == '\0')) { + max = idx; + if (min == RTE_MAX_LCORE) + min = idx; + for (idx = min; idx <= max; idx++) + lcores[idx] = 1; + + min = RTE_MAX_LCORE; + } else + return -1; + corelist = end + 1; + } while (*end != '\0'); + + return 0; +} diff --git a/app/test-eventdev/parser.h b/app/test-eventdev/parser.h new file mode 100644 index 000000000..75a5a3b45 --- /dev/null +++ b/app/test-eventdev/parser.h @@ -0,0 +1,79 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __INCLUDE_PARSER_H__ +#define __INCLUDE_PARSER_H__ + +#include + +#define PARSE_DELIMITER " \f\n\r\t\v" + +#define skip_white_spaces(pos) \ +({ \ + __typeof__(pos) _p = (pos); \ + for ( ; isspace(*_p); _p++) \ + ; \ + _p; \ +}) + +static inline size_t +skip_digits(const char *src) +{ + size_t i; + + for (i = 0; isdigit(src[i]); i++) + ; + + return i; +} + +int parser_read_arg_bool(const char *p); + +int parser_read_uint64(uint64_t *value, const char *p); +int parser_read_uint32(uint32_t *value, const char *p); +int parser_read_uint16(uint16_t *value, const char *p); +int parser_read_uint8(uint8_t *value, const char *p); + +int parser_read_uint64_hex(uint64_t *value, const char *p); +int parser_read_uint32_hex(uint32_t *value, const char *p); +int parser_read_uint16_hex(uint16_t *value, const char *p); +int parser_read_uint8_hex(uint8_t *value, const char *p); + +int parser_read_int32(int32_t *value, const char *p); + +int parse_hex_string(char *src, uint8_t *dst, uint32_t *size); + +int parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens); + +int parse_lcores_list(bool lcores[], const char *corelist); +#endif -- 2.13.0