mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 10:42:11 +00:00
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>
This commit is contained in:
parent
71b52d2c74
commit
55dda0abcf
@ -248,7 +248,7 @@ void print_usage(void)
|
|||||||
"Capture, convert and output data from IIO device buffer\n"
|
"Capture, convert and output data from IIO device buffer\n"
|
||||||
" -a Auto-activate all available channels\n"
|
" -a Auto-activate all available channels\n"
|
||||||
" -A Force-activate ALL channels\n"
|
" -A Force-activate ALL channels\n"
|
||||||
" -c <n> Do n conversions\n"
|
" -c <n> Do n conversions, or loop forever if n < 0\n"
|
||||||
" -e Disable wait for event (new data)\n"
|
" -e Disable wait for event (new data)\n"
|
||||||
" -g Use trigger-less mode\n"
|
" -g Use trigger-less mode\n"
|
||||||
" -l <n> Set buffer length to n samples\n"
|
" -l <n> Set buffer length to n samples\n"
|
||||||
@ -330,12 +330,12 @@ static const struct option longopts[] = {
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
unsigned long num_loops = 2;
|
unsigned long long num_loops = 2;
|
||||||
unsigned long timedelay = 1000000;
|
unsigned long timedelay = 1000000;
|
||||||
unsigned long buf_len = 128;
|
unsigned long buf_len = 128;
|
||||||
|
|
||||||
ssize_t i;
|
ssize_t i;
|
||||||
unsigned long j;
|
unsigned long long j;
|
||||||
unsigned long toread;
|
unsigned long toread;
|
||||||
int ret, c;
|
int ret, c;
|
||||||
int fp = -1;
|
int fp = -1;
|
||||||
@ -369,7 +369,7 @@ int main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
errno = 0;
|
errno = 0;
|
||||||
num_loops = strtoul(optarg, &dummy, 10);
|
num_loops = strtoll(optarg, &dummy, 10);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
goto error;
|
goto error;
|
||||||
@ -637,7 +637,7 @@ int main(int argc, char **argv)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < num_loops; j++) {
|
for (j = 0; j < num_loops || num_loops < 0; j++) {
|
||||||
if (!noevents) {
|
if (!noevents) {
|
||||||
struct pollfd pfd = {
|
struct pollfd pfd = {
|
||||||
.fd = fp,
|
.fd = fp,
|
||||||
|
Loading…
Reference in New Issue
Block a user