diff --git a/host/libraries/libbladeRF_test/CMakeLists.txt b/host/libraries/libbladeRF_test/CMakeLists.txt index 491c59f7..8bfd317d 100644 --- a/host/libraries/libbladeRF_test/CMakeLists.txt +++ b/host/libraries/libbladeRF_test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.9) add_subdirectory(test_async) add_subdirectory(test_bootloader_recovery) @@ -23,3 +23,4 @@ add_subdirectory(test_unused_sync) add_subdirectory(test_version) add_subdirectory(test_digital_loopback) add_subdirectory(test_interleaver) +add_subdirectory(test_general) diff --git a/host/libraries/libbladeRF_test/test_general/CMakeLists.txt b/host/libraries/libbladeRF_test/test_general/CMakeLists.txt new file mode 100644 index 00000000..1b752f0d --- /dev/null +++ b/host/libraries/libbladeRF_test/test_general/CMakeLists.txt @@ -0,0 +1,37 @@ +project(libbladeRF_test_general + VERSION 3.9 + LANGUAGES CXX) + +include(GoogleTest) +enable_testing() + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip +) +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +set(INCLUDES + ${libbladeRF_SOURCE_DIR}/include + ${libbladeRF_SOURCE_DIR}/src + ${BLADERF_HOST_COMMON_INCLUDE_DIRS} +) +include_directories(${INCLUDES}) + +set(SRC + src/main.cxx + ${BLADERF_HOST_COMMON_SOURCE_DIR}/log.c + ${BLADERF_HOST_COMMON_SOURCE_DIR}/conversions.c +) +add_executable(${PROJECT_NAME} ${SRC}) + +target_link_libraries( + ${PROJECT_NAME} + libbladerf_shared + gtest_main +) + +gtest_discover_tests(${PROJECT_NAME}) diff --git a/host/libraries/libbladeRF_test/test_general/src/main.cxx b/host/libraries/libbladeRF_test/test_general/src/main.cxx new file mode 100644 index 00000000..379facc9 --- /dev/null +++ b/host/libraries/libbladeRF_test/test_general/src/main.cxx @@ -0,0 +1,89 @@ +/* + * This file is part of the bladeRF project: + * http://www.github.com/nuand/bladeRF + * + * Copyright (C) 2023 Nuand LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "conversions.h" +#include "log.h" +#include +#include +#include +#include +#include +#include + +#define TEST_BLADERF device +int status = 0; + +TEST(TEST_BLADERF, open) { + status = std::system("./output/libbladeRF_test_open"); + ASSERT_EQ(0, status); +} + +#define OPTARG "v:h" +static struct option long_options[] = { + { "verbosity", required_argument, NULL, 'v' }, + { "help", no_argument, NULL, 'h' }, + { NULL, 0, NULL, 0 }, +}; + +int main(int argc, char** argv) { + bool ok = true; + int opt = 0; + int opt_ind = 0; + bladerf_log_level log_level; + + while (opt != -1) { + opt = getopt_long(argc, argv, OPTARG, long_options, &opt_ind); + + switch (opt) { + case 'v': + log_level = str2loglevel(optarg, &ok); + if (!ok) { + fprintf(stderr, "Invalid log level: %s\n", optarg); + return EXIT_FAILURE; + } + bladerf_log_set_verbosity(log_level); + break; + + case 'h': + printf("Usage: %s [options]\n", argv[0]); + printf(" -v, --verbosity Set libbladeRF verbosity level.\n"); + printf(" -h, --help Show this text.\n"); + printf("\n"); + printf(" --gtest_list_tests List all available tests without running them.\n"); + printf(" --gtest_filter= Run only the tests matching the filter.\n"); + printf(" Example filters: \"libbladeRF*\", \"hdl*\", \"synthesis*\"\n"); + printf(" --gtest_also_run_disabled_tests Run only the tests matching the filter.\n"); + printf(" --gtest_output=\"json\" Generates JSON report of test run.\n"); + printf("\n"); + return EXIT_SUCCESS; + + default: + break; + } + } + + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/host/libraries/libbladeRF_test/test_open/src/main.c b/host/libraries/libbladeRF_test/test_open/src/main.c index 02004ce7..f49a69c4 100644 --- a/host/libraries/libbladeRF_test/test_open/src/main.c +++ b/host/libraries/libbladeRF_test/test_open/src/main.c @@ -100,6 +100,7 @@ int main(int argc, char *argv[]) if (status != 0) { fprintf(stderr, "Failed to open device: %s\n", bladerf_strerror(status)); + return EXIT_FAILURE; } else { usleep(wait); bladerf_close(dev); @@ -108,5 +109,5 @@ int main(int argc, char *argv[]) } - return 0; + return EXIT_SUCCESS; }