From b33f3bb2ccf37e2687136baacc5c0391c4f97f7d Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 23 Dec 2014 17:43:14 +0300 Subject: [PATCH] refactor CV_CUDA_TEST_MAIN, use CV_TEST_MAIN for it use CV_CUDA_TEST_MAIN for opencv_test_core to initialize CUDA device information --- modules/core/test/test_main.cpp | 10 +++++ modules/ts/include/opencv2/ts.hpp | 2 +- modules/ts/include/opencv2/ts/cuda_test.hpp | 49 +-------------------- modules/ts/src/cuda_test.cpp | 27 ++++++++++++ 4 files changed, 40 insertions(+), 48 deletions(-) diff --git a/modules/core/test/test_main.cpp b/modules/core/test/test_main.cpp index d5400e20f..5ddfb7234 100644 --- a/modules/core/test/test_main.cpp +++ b/modules/core/test/test_main.cpp @@ -7,4 +7,14 @@ #include "test_precomp.hpp" +#ifndef HAVE_CUDA + CV_TEST_MAIN("cv") + +#else + +#include "opencv2/ts/cuda_test.hpp" + +CV_CUDA_TEST_MAIN("cv") + +#endif diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 209cb2915..c1b68a0c0 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -569,10 +569,10 @@ void parseCustomOptions(int argc, char **argv); #define CV_TEST_MAIN(resourcesubdir, ...) \ int main(int argc, char **argv) \ { \ + __CV_TEST_EXEC_ARGS(__VA_ARGS__) \ cvtest::TS::ptr()->init(resourcesubdir); \ ::testing::InitGoogleTest(&argc, argv); \ cvtest::printVersionInfo(); \ - __CV_TEST_EXEC_ARGS(__VA_ARGS__) \ TEST_DUMP_OCL_INFO \ parseCustomOptions(argc, argv); \ return RUN_ALL_TESTS(); \ diff --git a/modules/ts/include/opencv2/ts/cuda_test.hpp b/modules/ts/include/opencv2/ts/cuda_test.hpp index 049021b54..b225ab179 100644 --- a/modules/ts/include/opencv2/ts/cuda_test.hpp +++ b/modules/ts/include/opencv2/ts/cuda_test.hpp @@ -340,6 +340,7 @@ namespace cvtest CV_EXPORTS void dumpImage(const std::string& fileName, const cv::Mat& image); CV_EXPORTS void showDiff(cv::InputArray gold, cv::InputArray actual, double eps); + CV_EXPORTS void parseCudaDeviceOptions(int argc, char **argv); CV_EXPORTS void printCudaInfo(); } @@ -351,53 +352,7 @@ namespace cv { namespace cuda #ifdef HAVE_CUDA #define CV_CUDA_TEST_MAIN(resourcesubdir) \ - int main(int argc, char* argv[]) \ - { \ - try \ - { \ - cv::CommandLineParser cmd(argc, argv, \ - "{ h help ? | | Print help}" \ - "{ i info | | Print information about system and exit }" \ - "{ device | -1 | Device on which tests will be executed (-1 means all devices) }" \ - ); \ - if (cmd.has("help")) \ - { \ - cmd.printMessage(); \ - return 0; \ - } \ - cvtest::printCudaInfo(); \ - if (cmd.has("info")) \ - { \ - return 0; \ - } \ - int device = cmd.get("device"); \ - if (device < 0) \ - { \ - cvtest::DeviceManager::instance().loadAll(); \ - std::cout << "Run tests on all supported devices \n" << std::endl; \ - } \ - else \ - { \ - cvtest::DeviceManager::instance().load(device); \ - cv::cuda::DeviceInfo info(device); \ - std::cout << "Run tests on device " << device << " [" << info.name() << "] \n" << std::endl; \ - } \ - cvtest::TS::ptr()->init( resourcesubdir ); \ - testing::InitGoogleTest(&argc, argv); \ - return RUN_ALL_TESTS(); \ - } \ - catch (const std::exception& e) \ - { \ - std::cerr << e.what() << std::endl; \ - return -1; \ - } \ - catch (...) \ - { \ - std::cerr << "Unknown error" << std::endl; \ - return -1; \ - } \ - return 0; \ - } + CV_TEST_MAIN(resourcesubdir, cvtest::parseCudaDeviceOptions(argc, argv), cvtest::printCudaInfo()) #else // HAVE_CUDA diff --git a/modules/ts/src/cuda_test.cpp b/modules/ts/src/cuda_test.cpp index 7552be8ca..a48e0a087 100644 --- a/modules/ts/src/cuda_test.cpp +++ b/modules/ts/src/cuda_test.cpp @@ -190,6 +190,33 @@ namespace cvtest } } + void parseCudaDeviceOptions(int argc, char **argv) + { + cv::CommandLineParser cmd(argc, argv, + "{ cuda_device | -1 | CUDA device on which tests will be executed (-1 means all devices) }" + "{ h help | false | Print help info }" + ); + + if (cmd.has("help")) + { + std::cout << "\nAvailable options besides google test option: \n"; + cmd.printMessage(); + } + + int device = cmd.get("cuda_device"); + if (device < 0) + { + cvtest::DeviceManager::instance().loadAll(); + std::cout << "Run tests on all supported CUDA devices \n" << std::endl; + } + else + { + cvtest::DeviceManager::instance().load(device); + cv::cuda::DeviceInfo info(device); + std::cout << "Run tests on CUDA device " << device << " [" << info.name() << "] \n" << std::endl; + } + } + ////////////////////////////////////////////////////////////////////// // Additional assertion