From bc0e563092afd062dee9d33c53a5045fcafff260 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 8 Apr 2013 15:11:48 +0400 Subject: [PATCH] CV_GPU_TEST_MAIN macros --- modules/gpuarithm/test/test_main.cpp | 77 +----------------------------- modules/gpucodec/test/test_main.cpp | 2 +- modules/gpufilters/test/test_main.cpp | 77 +----------------------------- modules/ts/include/opencv2/ts/gpu_test.hpp | 64 +++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 153 deletions(-) diff --git a/modules/gpuarithm/test/test_main.cpp b/modules/gpuarithm/test/test_main.cpp index c37a85c..eea3d7c 100644 --- a/modules/gpuarithm/test/test_main.cpp +++ b/modules/gpuarithm/test/test_main.cpp @@ -42,79 +42,4 @@ #include "test_precomp.hpp" -#ifdef HAVE_CUDA - -using namespace std; -using namespace cv; -using namespace cv::gpu; -using namespace cvtest; -using namespace testing; - -int main(int argc, char** argv) -{ - try - { - const std::string keys = - "{ 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) }" - ; - - CommandLineParser cmd(argc, (const char**)argv, keys); - - if (cmd.has("help")) - { - cmd.printMessage(); - return 0; - } - - printCudaInfo(); - - if (cmd.has("info")) - { - return 0; - } - - int device = cmd.get("device"); - if (device < 0) - { - DeviceManager::instance().loadAll(); - - cout << "Run tests on all supported devices \n" << endl; - } - else - { - DeviceManager::instance().load(device); - - DeviceInfo info(device); - cout << "Run tests on device " << device << " [" << info.name() << "] \n" << endl; - } - - TS::ptr()->init("gpu"); - InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); - } - catch (const exception& e) - { - cerr << e.what() << endl; - return -1; - } - catch (...) - { - cerr << "Unknown error" << endl; - return -1; - } - - return 0; -} - -#else // HAVE_CUDA - -int main() -{ - printf("OpenCV was built without CUDA support\n"); - return 0; -} - -#endif // HAVE_CUDA +CV_GPU_TEST_MAIN("gpu") diff --git a/modules/gpucodec/test/test_main.cpp b/modules/gpucodec/test/test_main.cpp index 958adfe..eea3d7c 100644 --- a/modules/gpucodec/test/test_main.cpp +++ b/modules/gpucodec/test/test_main.cpp @@ -42,4 +42,4 @@ #include "test_precomp.hpp" -CV_TEST_MAIN("gpu") +CV_GPU_TEST_MAIN("gpu") diff --git a/modules/gpufilters/test/test_main.cpp b/modules/gpufilters/test/test_main.cpp index c37a85c..eea3d7c 100644 --- a/modules/gpufilters/test/test_main.cpp +++ b/modules/gpufilters/test/test_main.cpp @@ -42,79 +42,4 @@ #include "test_precomp.hpp" -#ifdef HAVE_CUDA - -using namespace std; -using namespace cv; -using namespace cv::gpu; -using namespace cvtest; -using namespace testing; - -int main(int argc, char** argv) -{ - try - { - const std::string keys = - "{ 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) }" - ; - - CommandLineParser cmd(argc, (const char**)argv, keys); - - if (cmd.has("help")) - { - cmd.printMessage(); - return 0; - } - - printCudaInfo(); - - if (cmd.has("info")) - { - return 0; - } - - int device = cmd.get("device"); - if (device < 0) - { - DeviceManager::instance().loadAll(); - - cout << "Run tests on all supported devices \n" << endl; - } - else - { - DeviceManager::instance().load(device); - - DeviceInfo info(device); - cout << "Run tests on device " << device << " [" << info.name() << "] \n" << endl; - } - - TS::ptr()->init("gpu"); - InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); - } - catch (const exception& e) - { - cerr << e.what() << endl; - return -1; - } - catch (...) - { - cerr << "Unknown error" << endl; - return -1; - } - - return 0; -} - -#else // HAVE_CUDA - -int main() -{ - printf("OpenCV was built without CUDA support\n"); - return 0; -} - -#endif // HAVE_CUDA +CV_GPU_TEST_MAIN("gpu") diff --git a/modules/ts/include/opencv2/ts/gpu_test.hpp b/modules/ts/include/opencv2/ts/gpu_test.hpp index 1a2caf7..b4c6e7b 100644 --- a/modules/ts/include/opencv2/ts/gpu_test.hpp +++ b/modules/ts/include/opencv2/ts/gpu_test.hpp @@ -43,6 +43,7 @@ #ifndef __OPENCV_GPU_TEST_UTILITY_HPP__ #define __OPENCV_GPU_TEST_UTILITY_HPP__ +#include #include "opencv2/core.hpp" #include "opencv2/core/gpumat.hpp" #include "opencv2/highgui.hpp" @@ -345,4 +346,67 @@ namespace cv { namespace gpu CV_EXPORTS void PrintTo(const DeviceInfo& info, std::ostream* os); }} +#ifdef HAVE_CUDA + +#define CV_GPU_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::gpu::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; \ + } + +#else // HAVE_CUDA + +#define CV_GPU_TEST_MAIN(resourcesubdir) \ + int main() \ + { \ + printf("OpenCV was built without CUDA support\n"); \ + return 0; \ + } + +#endif // HAVE_CUDA + + #endif // __OPENCV_GPU_TEST_UTILITY_HPP__ -- 2.7.4