Skip to content

Commit 55dda0a

Browse files
Martin KellyJonathan Cameron
authored andcommitted
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>
1 parent 71b52d2 commit 55dda0a

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

‎tools/iio/iio_generic_buffer.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void print_usage(void)
248248
"Capture, convert and output data from IIO device buffer\n"
249249
" -a Auto-activate all available channels\n"
250250
" -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"
252252
" -e Disable wait for event (new data)\n"
253253
" -g Use trigger-less mode\n"
254254
" -l <n> Set buffer length to n samples\n"
@@ -330,12 +330,12 @@ static const struct option longopts[] = {
330330

331331
int main(int argc, char **argv)
332332
{
333-
unsigned long num_loops = 2;
333+
unsigned long long num_loops = 2;
334334
unsigned long timedelay = 1000000;
335335
unsigned long buf_len = 128;
336336

337337
ssize_t i;
338-
unsigned long j;
338+
unsigned long long j;
339339
unsigned long toread;
340340
int ret, c;
341341
int fp = -1;
@@ -369,7 +369,7 @@ int main(int argc, char **argv)
369369
break;
370370
case 'c':
371371
errno = 0;
372-
num_loops = strtoul(optarg, &dummy, 10);
372+
num_loops = strtoll(optarg, &dummy, 10);
373373
if (errno) {
374374
ret = -errno;
375375
goto error;
@@ -637,7 +637,7 @@ int main(int argc, char **argv)
637637
goto error;
638638
}
639639

640-
for (j = 0; j < num_loops; j++) {
640+
for (j = 0; j < num_loops || num_loops < 0; j++) {
641641
if (!noevents) {
642642
struct pollfd pfd = {
643643
.fd = fp,

0 commit comments

Comments
 (0)