libbladeRF_test: Added functionality to open/close test
Configurable repetitions, a millisecond-granularity delay before closing, and adjustable log-level have been added to this test. These changes are intended to verify correct operation after repeated open/close operations over extended period of time.
This commit is contained in:
parent
c262e84bf4
commit
d5cecb011c
2 changed files with 57 additions and 17 deletions
|
|
@ -10,7 +10,7 @@ if(MSVC)
|
|||
set(INCLUDES ${INCLUDES} ${MSVC_C99_INCLUDES})
|
||||
endif()
|
||||
|
||||
set(SRC src/main.c)
|
||||
set(SRC src/main.c ${BLADERF_HOST_COMMON_SOURCE_DIR}/conversions.c)
|
||||
|
||||
if(MSVC)
|
||||
set(SRC ${SRC}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
#include <libbladeRF.h>
|
||||
|
||||
#include "conversions.h"
|
||||
|
||||
static const struct option long_options[] = {
|
||||
{ "device", required_argument, NULL, 'd' },
|
||||
{ "count", required_argument, NULL, 'c' },
|
||||
{ "wait", required_argument, NULL, 'w' },
|
||||
{ "reset", no_argument, NULL, 'r' },
|
||||
{ "no-reset", no_argument, NULL, 'n' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
|
|
@ -18,34 +23,65 @@ int main(int argc, char *argv[])
|
|||
int status = 0;
|
||||
char *devstr = NULL;
|
||||
struct bladerf *dev;
|
||||
bool reset_on_open = true;
|
||||
unsigned int count = 1;
|
||||
unsigned int wait = 250;
|
||||
unsigned int i;
|
||||
bool ok;
|
||||
bladerf_log_level log_level = BLADERF_LOG_LEVEL_INFO;
|
||||
|
||||
opt = 0;
|
||||
bladerf_log_set_verbosity(BLADERF_LOG_LEVEL_VERBOSE);
|
||||
|
||||
while (opt != -1) {
|
||||
opt = getopt_long(argc, argv, "d:rnh", long_options, &opt_ind);
|
||||
opt = getopt_long(argc, argv, "d:c:w:rnv:h", long_options, &opt_ind);
|
||||
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
devstr = optarg;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
count = str2uint(optarg, 1, UINT_MAX, &ok);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Invalid count: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
wait = str2uint(optarg, 1, 60 * 60 * 1000, &ok);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Invalid wait period: %s\n", optarg);
|
||||
return -1;
|
||||
} else {
|
||||
wait *= 1000;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
/* This is the default option, so it's actually redundant to
|
||||
* do this. However, this is here to allow us to exercise the
|
||||
* API call. */
|
||||
bladerf_set_usb_reset_on_open(true);
|
||||
reset_on_open = true;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
bladerf_set_usb_reset_on_open(false);
|
||||
reset_on_open = false;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
log_level = str2loglevel(optarg, &ok);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Invalid log level: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
printf("Usage: %s [options]\n", argv[0]);
|
||||
printf(" -d, --device <str> Specify device to open.\n");
|
||||
printf(" -c, --count <n> Number of times to open/close.\n");
|
||||
printf(" -w, --wait <n> Wait <n> ms before closing.\n");
|
||||
printf(" -r, --reset Enable USB reset on open.\n");
|
||||
printf(" -n, --no-reset Disable USB reset on open.\n");
|
||||
printf(" -v, --verbosity <l> Set libbladeRF verbosity level.\n");
|
||||
printf(" -h, --help Show this text.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
|
|
@ -55,17 +91,21 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
status = bladerf_open(&dev, devstr);
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "Failed to open device: %s\n",
|
||||
bladerf_strerror(status));
|
||||
return 1;
|
||||
bladerf_log_set_verbosity(log_level);
|
||||
|
||||
bladerf_set_usb_reset_on_open(reset_on_open);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
status = bladerf_open(&dev, devstr);
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "Failed to open device: %s\n",
|
||||
bladerf_strerror(status));
|
||||
} else {
|
||||
usleep(wait);
|
||||
bladerf_close(dev);
|
||||
}
|
||||
}
|
||||
|
||||
puts("\n\nPress any key to close the device and exit.\n");
|
||||
(void) getchar();
|
||||
|
||||
bladerf_close(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue