aboutsummaryrefslogtreecommitdiffstats
path: root/tools/iio
diff options
context:
space:
mode:
authorMartin Kelly <mkelly@xevo.com>2018-05-17 20:14:46 -0400
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2018-05-20 09:55:58 -0400
commit55dda0abcf9d36bf5c3e21c8423b7c00a1125e27 (patch)
tree622ec5263913368c19f71172ff984cb8f41f3b01 /tools/iio
parent71b52d2c746b2915d615e29f5873e1ee5f3c5f52 (diff)
tools: iio: iio_generic_buffer: allow continuous looping
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 <mkelly@xevo.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'tools/iio')
-rw-r--r--tools/iio/iio_generic_buffer.c10
1 files 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)
248 "Capture, convert and output data from IIO device buffer\n" 248 "Capture, convert and output data from IIO device buffer\n"
249 " -a Auto-activate all available channels\n" 249 " -a Auto-activate all available channels\n"
250 " -A Force-activate ALL channels\n" 250 " -A Force-activate ALL channels\n"
251 " -c <n> Do n conversions\n" 251 " -c <n> Do n conversions, or loop forever if n < 0\n"
252 " -e Disable wait for event (new data)\n" 252 " -e Disable wait for event (new data)\n"
253 " -g Use trigger-less mode\n" 253 " -g Use trigger-less mode\n"
254 " -l <n> Set buffer length to n samples\n" 254 " -l <n> Set buffer length to n samples\n"
@@ -330,12 +330,12 @@ static const struct option longopts[] = {
330 330
331int main(int argc, char **argv) 331int main(int argc, char **argv)
332{ 332{
333 unsigned long num_loops = 2; 333 unsigned long long num_loops = 2;
334 unsigned long timedelay = 1000000; 334 unsigned long timedelay = 1000000;
335 unsigned long buf_len = 128; 335 unsigned long buf_len = 128;
336 336
337 ssize_t i; 337 ssize_t i;
338 unsigned long j; 338 unsigned long long j;
339 unsigned long toread; 339 unsigned long toread;
340 int ret, c; 340 int ret, c;
341 int fp = -1; 341 int fp = -1;
@@ -369,7 +369,7 @@ int main(int argc, char **argv)
369 break; 369 break;
370 case 'c': 370 case 'c':
371 errno = 0; 371 errno = 0;
372 num_loops = strtoul(optarg, &dummy, 10); 372 num_loops = strtoll(optarg, &dummy, 10);
373 if (errno) { 373 if (errno) {
374 ret = -errno; 374 ret = -errno;
375 goto error; 375 goto error;
@@ -637,7 +637,7 @@ int main(int argc, char **argv)
637 goto error; 637 goto error;
638 } 638 }
639 639
640 for (j = 0; j < num_loops; j++) { 640 for (j = 0; j < num_loops || num_loops < 0; j++) {
641 if (!noevents) { 641 if (!noevents) {
642 struct pollfd pfd = { 642 struct pollfd pfd = {
643 .fd = fp, 643 .fd = fp,