From d5cecb011cb460ad054e49846d7ef0cb974aacd5 Mon Sep 17 00:00:00 2001 From: Jon Szymaniak Date: Fri, 27 Nov 2015 23:00:49 -0500 Subject: [PATCH] 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. --- .../libbladeRF_test/test_open/CMakeLists.txt | 2 +- .../libbladeRF_test/test_open/src/main.c | 72 ++++++++++++++----- 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/host/libraries/libbladeRF_test/test_open/CMakeLists.txt b/host/libraries/libbladeRF_test/test_open/CMakeLists.txt index 6d8939c3..f8fb32de 100644 --- a/host/libraries/libbladeRF_test/test_open/CMakeLists.txt +++ b/host/libraries/libbladeRF_test/test_open/CMakeLists.txt @@ -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} diff --git a/host/libraries/libbladeRF_test/test_open/src/main.c b/host/libraries/libbladeRF_test/test_open/src/main.c index c2439076..b64c5346 100644 --- a/host/libraries/libbladeRF_test/test_open/src/main.c +++ b/host/libraries/libbladeRF_test/test_open/src/main.c @@ -1,10 +1,15 @@ #include #include #include +#include #include +#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 Specify device to open.\n"); + printf(" -c, --count Number of times to open/close.\n"); + printf(" -w, --wait Wait 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 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; }