From patchwork Fri May 18 00:14:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10407909 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6BE6D602C2 for ; Fri, 18 May 2018 00:15:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59F23287BE for ; Fri, 18 May 2018 00:15:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EA1A287C7; Fri, 18 May 2018 00:15:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A72E287C0 for ; Fri, 18 May 2018 00:15:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751698AbeERAPK (ORCPT ); Thu, 17 May 2018 20:15:10 -0400 Received: from mail-sn1nam01on0054.outbound.protection.outlook.com ([104.47.32.54]:22558 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751530AbeERAPJ (ORCPT ); Thu, 17 May 2018 20:15:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uievolution.onmicrosoft.com; s=selector1-xevo-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pldMZU6HzzyrQ//Bx3pavlGEPUD3IwMPoCMRPwCbxi0=; b=ghGfETxqkeKgLtaBLE8F2PxRxXcO/VXoiMPQHmf15VjddcCLr9C+2DuUJ04vnRj+zimkqbx8UIVgco2U7DczR23FuZ9PxLRG0+9sgJMh9brcKduJBWo2NDruZiFkYIjAn4TjAYzQts86UO35cJvycbdpYcdOYPq/kiV595vglho= Received: from columbia.corp.xevo.com (65.122.179.226) by MW2PR0102MB3417.prod.exchangelabs.com (2603:10b6:302:3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.776.11; Fri, 18 May 2018 00:15:07 +0000 From: Martin Kelly To: linux-iio@vger.kernel.org Cc: Jonathan Cameron , Martin Kelly Subject: [PATCH v2 2/2] tools: iio: iio_generic_buffer: allow continuous looping Date: Thu, 17 May 2018 17:14:46 -0700 Message-Id: <20180518001446.15607-2-mkelly@xevo.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180518001446.15607-1-mkelly@xevo.com> References: <20180518001446.15607-1-mkelly@xevo.com> MIME-Version: 1.0 X-Originating-IP: [65.122.179.226] X-ClientProxiedBy: MWHPR22CA0003.namprd22.prod.outlook.com (2603:10b6:300:ef::13) To MW2PR0102MB3417.prod.exchangelabs.com (2603:10b6:302:3::10) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:MW2PR0102MB3417; X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3417; 3:pnx8IYMVhoBC4FbX3Ij42WHcdCpfDfAqbOKbX+9y//5Ift/oQDXIgnWUlDUMRTDfqWpuvSVXfGnEoymYgGiXp9Qltv3Q9mhE6F9rceSghdVDnIZ0zfNaisiA0m6eLoSlYV2caej+GZRfXzF7Scl7XjKC3N5q25UnJyKr4+ixMDhn9l9Mr79LCY3pZXLXVCZGKG3RERHpl4uIjmEJl3scpGYbHelE1KiFPmUDtyOJ9yLJ1NflV6L+3/VO5iTO7bfi; 25:BIWmhuw7U13YIBTBJqSx4zLMRQWBENKlfmbf3R8+ZlXzDewedHj3+obESSrhRfXJZnOQ8SRPJkaBSAqJnq5xf1orRy6RwqCOFT3h6nTT3VA4igAxUxCAgYL66qmVKdNWf5wTObHqlqu7X0JwZuynh/I/NrDGuUl3sr9AD1ny2x+U3n+vLweqZljG1OFMz3izM6pcY7lkwYdQL4iJSRUlTU9LwvUGCUgvaKqhTxmrzhJkiD5JcKnH45vp8rRZRX/ir5J9n918+7LI4U3G2ZQu5FdqBEL37Sn9N/zwtyrJn+tVq+lLdhIITPh/iZ/QLxyEDLd3plQjbamEy8so8BGl+A==; 31:ydOiRcMpGIDeSG2cd3wJZS4SBgseZqB9df7c04u7N6oMXgbm/M5wJ1aGP8kY9zHJql+8NXFXZtvg1t/j2FtYn9CgeHwKCrzqcZnT4AlMSuQemE3zqDQrPS1kx0dIb3FvniA69q/7R2/QuAepX/QmwjwWqIK/SHDPcyXA5iVn+nL60cRKFTfpcc401qh4hLtCYQZJsoVYeEjV1929FtRUHxE81NnkAlfWE9KUTQmzoPk= X-MS-TrafficTypeDiagnostic: MW2PR0102MB3417: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=mkelly@xevo.com; X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3417; 20:/B1INxK0QIUywIQGTuhnmVOtupaS5JxRF6I8kT381yDW0jxvjXgKfXvmzik2CVwROMookHDIxfioH71b4qb9ojGOI+nd0VLtYorq7CM3nYSliXVsqlmQlE/NQdX9pwAhbOzoQo/BBbix947E7gqUqJnfJyJUhMxh1H6Gdl655soGNDg3gS5mVHP3fWaqJYFhBTwU04s6I0JeCOcy9orc9sew8E4zKWIQnbPkupDbsbzS0d4XlyM9kxD7YNOddIngKL5ALdtOfw4pZ1/ELE+IZ4qkyk/g62tj8xILTsa5h6IEByeqgLnX+ni7rsljymWeynmITkXxLrTI8WsVm19qfJbE56B+094FHoHpigQJIN1Yn0ljzKj2iZ3zKO1sDh0eOZ+AqYUNJhTsENQ7wMYPvhLdT2TQpHZGN8QfrK26Ye4SQVLgxCWzMlnVUImnPcOZpUrn+41Yqa+Fj+RioyCEqvfMQpcKiVEohY+FK+IKZl1B4zE20tjuAG6d5yVhALl1; 4:WMXLW2qO7Yu15wEqo1QvrNeR8f1IdQx7iz1qO+kVmtRHfoN6bqcpW0fOBK3yDzira55sThzYWUQ8HgEAm2xzS9XljHQDqMTGb0eiHVudcnKnhbI98R4tipuDpoo3c9t8eFNE7ycKPAfcMKjzybgAgQQfNo5/VdqJq8/A+rhhEBtfoVe1+csIpBQ1bQZWFQfoEcVpBHc4zjX4xAX2ESoQKGYjKwD3Qf55hu2C/VwGz9ZKkbieoDez/SM+mNwYSslYoxMhH8ppZBFHFL6oW32cJg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(10201501046)(3002001)(93006095)(93001095)(149027)(150027)(6041310)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:MW2PR0102MB3417; BCL:0; PCL:0; RULEID:; SRVR:MW2PR0102MB3417; X-Forefront-PRVS: 0676F530A9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(396003)(39840400004)(366004)(346002)(376002)(189003)(199004)(3846002)(54906003)(2906002)(86362001)(25786009)(50226002)(6486002)(8676002)(81156014)(97736004)(81166006)(8936002)(48376002)(316002)(66066001)(6116002)(50466002)(5660300001)(16586007)(1076002)(106356001)(105586002)(47776003)(6916009)(68736007)(2361001)(6666003)(386003)(59450400001)(2351001)(76176011)(7736002)(16526019)(2616005)(305945005)(51416003)(956004)(486006)(26005)(52116002)(7696005)(446003)(11346002)(36756003)(478600001)(4326008)(476003)(186003)(53936002)(107886003)(41533002); DIR:OUT; SFP:1101; SCL:1; SRVR:MW2PR0102MB3417; H:columbia.corp.xevo.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: xevo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MW2PR0102MB3417; 23:tsdsRbiiMJHAWS/c9vhxh65mtuSbFfQi3PiKR3o?= =?us-ascii?Q?BFx7G92HwtH332BzqEcMXl4iM+chCZi7hBiJLYfHSjjqJnslX2H3sBi+x6D4?= =?us-ascii?Q?5S6LppilAWAU617kbBVatGzOWZYHYhF+miD7IAZH9KjGAJVYe7j+NpZBpXMx?= =?us-ascii?Q?EodC/qEjseeAEGSzQrQg45cM3GnjaNTe+KQLTLWbNVUqpdtw9bmQVLQVW4Jo?= =?us-ascii?Q?Wu53QE0+7x2gLSPUUkluwlsLXQToTWxwp7/sQJZWluZFHTl6lpjNtwcmbAgE?= =?us-ascii?Q?LDe2vAZf8B0itm0xXnWtsk9jJpXPCosa1un1Cplkyn6LQEXfRqzBaZBb3b96?= =?us-ascii?Q?ZM+3b9+//P1Rd69+zcr9CoGUyGkzomqBd5+n08RFWf92ZwjC+Jfqc6dpHrs5?= =?us-ascii?Q?K6BbwaBrq0oOfxPPNA6Pe5ZY3KuKqX9SrS54ZmAUSFpLCO/VzWLqhYBhPl4L?= =?us-ascii?Q?s/mo7bwWoAe4Kt7h0PneDeCLDocFNdTHRdwX+JAxEKnD5aiizYXb7g4Gw+p5?= =?us-ascii?Q?XfQSFm2nwISSb+BEcqKrseDFdZk7uCr49dSLa3VchXADQCqFV2k0j98A2n8S?= =?us-ascii?Q?hu+cXpLm47C2xKPPVX63tT99zu3fQgZ7E2vWNeG5w9RZ7P3WUmKlV1IUy0dO?= =?us-ascii?Q?PC0ADMxO3lJTuSxWFDII0mZvaA/E11eN/7tjf/ZEiMTTOouS7kMSCC1EEyzP?= =?us-ascii?Q?KOii97XGJa+3WWcLVXySv+Sbcvu3FUhNIJFcr6Yk9Z6RRkFnajjJV3FXyRC7?= =?us-ascii?Q?OeQ/Ec8DKmi9HRpTCOX4NOwAU7oS+qgutFWaQxRMKcInkVfZAabutxCIMtDK?= =?us-ascii?Q?7VNPb8oaNInAW+22ehvS/DniaCo49cqqU2+qnhVj8sNstpcn8JESg4HFO8JU?= =?us-ascii?Q?GSzJtFWqNhTkWRpMzuMlQq1htGKowouR7tcQowBr5GViY+yaGjq95EoiVoxE?= =?us-ascii?Q?9qPUyUbZL9oroGBPnzn3yttkwqJextjr0GaJXXhkuKDtnLGQYFBJA1H/+6eO?= =?us-ascii?Q?Je+HEEOflNTLvhvIFV0MZ506AP36NjOklXnuWHF5hay03M9sbPNcJo16+lPj?= =?us-ascii?Q?nw4GP9UuywWF7iMRKSwolcfNw99XWvIQm0c9VoXAO0psRjdeX89ZzoKoBJYp?= =?us-ascii?Q?JWwmTvINfdRlfNg6WH5UP05m5kfY0E7bmHpscFhkZAmB3O92z7/6msnFcbZG?= =?us-ascii?Q?8RUK52NKl2P4g7PWXuk03gKeeDhoPlNC4Q8PujWD0pFZDNRzey7rQMp1Yzys?= =?us-ascii?Q?IBYWmVAThoyowl77v+IgXzmemVsHkmB4hucmjKKulY/JRZX45q7TKju3ymwB?= =?us-ascii?Q?vY+SRSONhQcNPuOBLC1sUv9I=3D?= X-Microsoft-Antispam-Message-Info: Wd34s6zCl9s56oLnLESCeh5oFXsx8AkLIddQCAld/A+XWT+c6mF8wNrWM2Sn3TAS8/sOeWtYmWF/eux7s7AOzIAfUXiYyxds7xQLkzCeMEAS7mCoJOxsi1kyRSCLiRRR5bJOIV2ckpGxPzh2iwZV0lhNTEvpCeKkZfJB+ik1dHeExnciLoXgZepTU/uRv+wF X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3417; 6:zEMIFEBUhPejvg1A6/4rQOQ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I9f X-MS-Office365-Filtering-Correlation-Id: 2fca4b11-1d6e-4164-0788-08d5bc5469bd X-OriginatorOrg: xevo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2018 00:15:07.9751 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2fca4b11-1d6e-4164-0788-08d5bc5469bd X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e0a7ca1f-2458-4cd6-a7c7-d733c07495ab X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR0102MB3417 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sometimes it's useful to stream samples forever, such as when stress-testing a driver overnight to check for memory leaks or other issues. When the program receives a signal, it will gracefully cleanup, so it is still safe to terminate at any time. Add support for specifying a negative -c option, meaning that we should loop forever. To do so, we need to use a long long (instead of just long) for num_loops so that current code specifying num_loops greater than UNSIGNED_LONG_MAX doesn't break. Signed-off-by: Martin Kelly --- v2: - Make j unsigned long long to match num_loops. Another option for implementing this would be to implicitly assume looping forever if -c is not specified (instead of the current default of 2). I did not do this out of fear of breaking existing users but would be OK with doing so, as I like it as a default. If you'd like to go this route, let me know. tools/iio/iio_generic_buffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c index aa765c11992b..3040830d7797 100644 --- a/tools/iio/iio_generic_buffer.c +++ b/tools/iio/iio_generic_buffer.c @@ -248,7 +248,7 @@ void print_usage(void) "Capture, convert and output data from IIO device buffer\n" " -a Auto-activate all available channels\n" " -A Force-activate ALL channels\n" - " -c Do n conversions\n" + " -c Do n conversions, or loop forever if n < 0\n" " -e Disable wait for event (new data)\n" " -g Use trigger-less mode\n" " -l Set buffer length to n samples\n" @@ -330,12 +330,12 @@ static const struct option longopts[] = { int main(int argc, char **argv) { - unsigned long num_loops = 2; + unsigned long long num_loops = 2; unsigned long timedelay = 1000000; unsigned long buf_len = 128; ssize_t i; - unsigned long j; + unsigned long long j; unsigned long toread; int ret, c; int fp = -1; @@ -369,7 +369,7 @@ int main(int argc, char **argv) break; case 'c': errno = 0; - num_loops = strtoul(optarg, &dummy, 10); + num_loops = strtoll(optarg, &dummy, 10); if (errno) { ret = -errno; goto error; @@ -637,7 +637,7 @@ int main(int argc, char **argv) goto error; } - for (j = 0; j < num_loops; j++) { + for (j = 0; j < num_loops || num_loops < 0; j++) { if (!noevents) { struct pollfd pfd = { .fd = fp,