From: Maksim Shabunin Date: Thu, 26 Jul 2018 13:27:47 +0000 (+0300) Subject: ts: test case list is printed after cmd line parsing, refactored X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~1^2~597^2~16^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=597db69151ea052dbc7b5927043101a11ace8818;p=platform%2Fupstream%2Fopencv.git ts: test case list is printed after cmd line parsing, refactored --- diff --git a/cmake/OpenCVCompilerOptimizations.cmake b/cmake/OpenCVCompilerOptimizations.cmake index 76f56ba..8beabef 100644 --- a/cmake/OpenCVCompilerOptimizations.cmake +++ b/cmake/OpenCVCompilerOptimizations.cmake @@ -700,12 +700,21 @@ macro(ocv_compiler_optimization_fill_cpu_config) list(APPEND __dispatch_modes ${CPU_DISPATCH_${OPT}_FORCE} ${OPT}) endforeach() list(REMOVE_DUPLICATES __dispatch_modes) - set(OPENCV_CPU_DISPATCH_DEFINITIONS_CONFIGMAKE "") foreach(OPT ${__dispatch_modes}) set(OPENCV_CPU_DISPATCH_DEFINITIONS_CONFIGMAKE "${OPENCV_CPU_DISPATCH_DEFINITIONS_CONFIGMAKE} #define CV_CPU_DISPATCH_COMPILE_${OPT} 1") endforeach() + set(OPENCV_CPU_DISPATCH_DEFINITIONS_CONFIGMAKE "${OPENCV_CPU_DISPATCH_DEFINITIONS_CONFIGMAKE} +\n\n#define CV_CPU_DISPATCH_FEATURES 0 \\") + foreach(OPT ${__dispatch_modes}) + if(NOT DEFINED CPU_${OPT}_FEATURE_ALIAS OR NOT "x${CPU_${OPT}_FEATURE_ALIAS}" STREQUAL "x") + set(OPENCV_CPU_DISPATCH_DEFINITIONS_CONFIGMAKE "${OPENCV_CPU_DISPATCH_DEFINITIONS_CONFIGMAKE} + , CV_CPU_${OPT} \\") + endif() + endforeach() + set(OPENCV_CPU_DISPATCH_DEFINITIONS_CONFIGMAKE "${OPENCV_CPU_DISPATCH_DEFINITIONS_CONFIGMAKE}\n") + set(OPENCV_CPU_CONTROL_DEFINITIONS_CONFIGMAKE "// AUTOGENERATED, DO NOT EDIT\n") foreach(OPT ${CPU_ALL_OPTIMIZATIONS}) if(NOT DEFINED CPU_${OPT}_FEATURE_ALIAS OR NOT "x${CPU_${OPT}_FEATURE_ALIAS}" STREQUAL "x") diff --git a/modules/core/include/opencv2/core/utility.hpp b/modules/core/include/opencv2/core/utility.hpp index 4888eae..a15bbff 100644 --- a/modules/core/include/opencv2/core/utility.hpp +++ b/modules/core/include/opencv2/core/utility.hpp @@ -457,6 +457,18 @@ Returns empty string if feature is not defined */ CV_EXPORTS_W String getHardwareFeatureName(int feature); +/** @brief Returns list of CPU features enabled during compilation. + +Returned value is a string containing space separated list of CPU features with following markers: + +- no markers - baseline features +- prefix `*` - features enabled in dispatcher +- suffix `?` - features enabled but not available in HW + +Example: `SSE SSE2 SSE3 *SSE4.1 *SSE4.2 *FP16 *AVX *AVX2 *AVX512-SKX?` +*/ +CV_EXPORTS std::string getCPUFeaturesLine(); + /** @brief Returns the number of logical CPUs available for the process. */ CV_EXPORTS_W int getNumberOfCPUs(); diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 41a589e..1ebd993 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -654,6 +654,27 @@ String getHardwareFeatureName(int feature) return name ? String(name) : String(); } +std::string getCPUFeaturesLine() +{ + const int features[] = { CV_CPU_BASELINE_FEATURES, CV_CPU_DISPATCH_FEATURES }; + const int sz = sizeof(features) / sizeof(features[0]); + std::string result; + std::string prefix; + for (int i = 1; i < sz; ++i) + { + if (features[i] == 0) + { + prefix = "*"; + continue; + } + if (i != 1) result.append(" "); + result.append(prefix); + result.append(getHWFeatureNameSafe(features[i])); + if (!checkHardwareSupport(features[i])) result.append("?"); + } + return result; +} + volatile bool useOptimizedFlag = true; void setUseOptimized( bool flag ) diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 3fbea89..4880b6c 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -379,10 +379,9 @@ struct TSParams class TS { -public: - // constructor(s) and destructor TS(); virtual ~TS(); +public: enum { @@ -484,9 +483,6 @@ public: SKIPPED=1 }; - // get file storage - CvFileStorage* get_file_storage(); - // get RNG to generate random input data for a test RNG& get_rng() { return rng; } @@ -629,9 +625,6 @@ struct DefaultRngAuto void fillGradient(Mat& img, int delta = 5); void smoothBorder(Mat& img, const Scalar& color, int delta = 3); -void printVersionInfo(bool useStdOut = true); - - // Utility functions void addDataSearchPath(const std::string& path); @@ -660,6 +653,13 @@ std::string findDataFile(const std::string& relative_path, bool required = true) */ std::string findDataDirectory(const std::string& relative_path, bool required = true); +// Test definitions + +class SystemInfoCollector : public testing::EmptyTestEventListener +{ +private: + virtual void OnTestProgramStart(const testing::UnitTest&); +}; #ifndef __CV_TEST_EXEC_ARGS #if defined(_MSC_VER) && (_MSC_VER <= 1400) @@ -671,15 +671,6 @@ std::string findDataDirectory(const std::string& relative_path, bool required = #endif #endif -#ifdef HAVE_OPENCL -namespace ocl { -void dumpOpenCLDevice(); -} -#define TEST_DUMP_OCL_INFO cvtest::ocl::dumpOpenCLDevice(); -#else -#define TEST_DUMP_OCL_INFO -#endif - void parseCustomOptions(int argc, char **argv); #define CV_TEST_INIT0_NOOP (void)0 @@ -696,8 +687,7 @@ int main(int argc, char **argv) \ ts->init(resourcesubdir); \ __CV_TEST_EXEC_ARGS(CV_TEST_INIT0_ ## INIT0) \ ::testing::InitGoogleTest(&argc, argv); \ - cvtest::printVersionInfo(); \ - TEST_DUMP_OCL_INFO \ + ::testing::UnitTest::GetInstance()->listeners().Append(new SystemInfoCollector); \ __CV_TEST_EXEC_ARGS(__VA_ARGS__) \ parseCustomOptions(argc, argv); \ } \ diff --git a/modules/ts/include/opencv2/ts/ts_perf.hpp b/modules/ts/include/opencv2/ts/ts_perf.hpp index e33850c..3a5f684 100644 --- a/modules/ts/include/opencv2/ts/ts_perf.hpp +++ b/modules/ts/include/opencv2/ts/ts_perf.hpp @@ -637,15 +637,6 @@ void PrintTo(const Size& sz, ::std::ostream* os); #endif #endif -#ifdef HAVE_OPENCL -namespace cvtest { namespace ocl { -void dumpOpenCLDevice(); -}} -#define TEST_DUMP_OCL_INFO cvtest::ocl::dumpOpenCLDevice(); -#else -#define TEST_DUMP_OCL_INFO -#endif - #define CV_PERF_TEST_MAIN_INTERNALS(modulename, impls, ...) \ CV_TRACE_FUNCTION(); \ @@ -654,11 +645,10 @@ void dumpOpenCLDevice(); ::perf::TestBase::Init(std::vector(impls, impls + sizeof impls / sizeof *impls), \ argc, argv); \ ::testing::InitGoogleTest(&argc, argv); \ - cvtest::printVersionInfo(); \ + ::testing::UnitTest::GetInstance()->listeners().Append(new cvtest::SystemInfoCollector); \ ::testing::Test::RecordProperty("cv_module_name", #modulename); \ ::perf::TestBase::RecordRunParameters(); \ __CV_TEST_EXEC_ARGS(__VA_ARGS__) \ - TEST_DUMP_OCL_INFO \ } \ return RUN_ALL_TESTS(); diff --git a/modules/ts/src/ocl_test.cpp b/modules/ts/src/ocl_test.cpp index 8eaa7e6..6d5ff26 100644 --- a/modules/ts/src/ocl_test.cpp +++ b/modules/ts/src/ocl_test.cpp @@ -43,25 +43,6 @@ #include "opencv2/ts/ocl_test.hpp" -#ifdef HAVE_OPENCL - -#define DUMP_CONFIG_PROPERTY(propertyName, propertyValue) \ - do { \ - std::stringstream ssName, ssValue;\ - ssName << propertyName;\ - ssValue << (propertyValue); \ - ::testing::Test::RecordProperty(ssName.str(), ssValue.str()); \ - } while (false) - -#define DUMP_MESSAGE_STDOUT(msg) \ - do { \ - std::cout << msg << std::endl; \ - } while (false) - -#include - -#endif // HAVE_OPENCL - namespace cvtest { namespace ocl { @@ -69,13 +50,6 @@ using namespace cv; int test_loop_times = 1; // TODO Read from command line / environment -#ifdef HAVE_OPENCL -void dumpOpenCLDevice() -{ - cv::dumpOpenCLInformation(); -} -#endif // HAVE_OPENCL - Mat TestUtils::readImage(const String &fileName, int flags) { return cv::imread(cvtest::TS::ptr()->get_data_path() + fileName, flags); diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index b1ea96b..fabfa1b 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -74,7 +74,26 @@ # include #endif +#ifdef HAVE_OPENCL +#define DUMP_CONFIG_PROPERTY(propertyName, propertyValue) \ + do { \ + std::stringstream ssName, ssValue;\ + ssName << propertyName;\ + ssValue << (propertyValue); \ + ::testing::Test::RecordProperty(ssName.str(), ssValue.str()); \ + } while (false) + +#define DUMP_MESSAGE_STDOUT(msg) \ + do { \ + std::cout << msg << std::endl; \ + } while (false) + +#include "opencv2/core/opencl/opencl_info.hpp" + +#endif // HAVE_OPENCL + +#include "opencv2/core/utility.hpp" #include "opencv_tests_config.hpp" namespace opencv_test { @@ -230,7 +249,6 @@ bool BaseTest::can_do_fast_forward() void BaseTest::safe_run( int start_from ) { CV_TRACE_FUNCTION(); - read_params( ts->get_file_storage() ); ts->update_context( 0, -1, true ); ts->update_context( this, -1, true ); @@ -552,8 +570,6 @@ void TS::set_gtest_status() } -CvFileStorage* TS::get_file_storage() { return 0; } - void TS::update_context( BaseTest* test, int test_case_idx, bool update_ts_context ) { if( current_test_info.test != test ) @@ -614,8 +630,11 @@ void TS::printf( int streams, const char* fmt, ... ) } -static TS ts; -TS* TS::ptr() { return &ts; } +TS* TS::ptr() +{ + static TS ts; + return &ts; +} void fillGradient(Mat& img, int delta) { @@ -866,6 +885,65 @@ std::string findDataDirectory(const std::string& relative_path, bool required) return findData(relative_path, required, true); } +inline static std::string getSnippetFromConfig(const std::string & start, const std::string & end) +{ + const std::string buildInfo = cv::getBuildInformation(); + size_t pos1 = buildInfo.find(start); + if (pos1 != std::string::npos) + { + pos1 += start.length(); + pos1 = buildInfo.find_first_not_of(" \t\n\r", pos1); + } + size_t pos2 = buildInfo.find(end, pos1); + if (pos2 != std::string::npos) + { + pos2 = buildInfo.find_last_not_of(" \t\n\r", pos2); + } + if (pos1 != std::string::npos && pos2 != std::string::npos && pos1 < pos2) + { + return buildInfo.substr(pos1, pos2 - pos1 + 1); + } + return std::string(); +} + +inline static void recordPropertyVerbose(const std::string & property, + const std::string & msg, + const std::string & value, + const std::string & build_value = std::string()) +{ + ::testing::Test::RecordProperty(property, value); + std::cout << msg << ": " << (value.empty() ? std::string("N/A") : value) << std::endl; + if (!build_value.empty()) + { + ::testing::Test::RecordProperty(property + "_build", build_value); + if (build_value != value) + std::cout << "WARNING: build value differs from runtime: " << build_value << endl; + } +} + +#ifdef _DEBUG +#define CV_TEST_BUILD_CONFIG "Debug" +#else +#define CV_TEST_BUILD_CONFIG "Release" +#endif + +void SystemInfoCollector::OnTestProgramStart(const testing::UnitTest&) +{ + std::cout << "CTEST_FULL_OUTPUT" << std::endl; // Tell CTest not to discard any output + recordPropertyVerbose("cv_version", "OpenCV version", cv::getVersionString(), CV_VERSION); + recordPropertyVerbose("cv_vcs_version", "OpenCV VCS version", getSnippetFromConfig("Version control:", "\n")); + recordPropertyVerbose("cv_build_type", "Build type", getSnippetFromConfig("Configuration:", "\n"), CV_TEST_BUILD_CONFIG); + recordPropertyVerbose("cv_compiler", "Compiler", getSnippetFromConfig("C++ Compiler:", "\n")); + recordPropertyVerbose("cv_parallel_framework", "Parallel framework", cv::currentParallelFramework()); + recordPropertyVerbose("cv_cpu_features", "CPU features", cv::getCPUFeaturesLine()); +#ifdef HAVE_IPP + recordPropertyVerbose("cv_ipp_version", "Intel(R) IPP version", cv::ipp::useIPP() ? cv::ipp::getIppVersion() : "disabled"); +#endif +#ifdef HAVE_OPENCL + cv::dumpOpenCLInformation(); +#endif +} + } //namespace cvtest /* End of file. */ diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index a5366bf..60c88a7 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -3,10 +3,6 @@ #include #include "opencv2/imgproc/types_c.h" -#ifdef HAVE_TEGRA_OPTIMIZATION -#include "tegra.hpp" -#endif - using namespace cv; namespace cvtest @@ -2977,149 +2973,6 @@ MatComparator::operator()(const char* expr1, const char* expr2, << "- " << expr2 << ":\n" << MatPart(m2part, border > 0 ? &loc : 0) << ".\n"; } -void printVersionInfo(bool useStdOut) -{ - // Tell CTest not to discard any output - if(useStdOut) std::cout << "CTEST_FULL_OUTPUT" << std::endl; - - ::testing::Test::RecordProperty("cv_version", CV_VERSION); - if(useStdOut) std::cout << "OpenCV version: " << CV_VERSION << std::endl; - - std::string buildInfo( cv::getBuildInformation() ); - - size_t pos1 = buildInfo.find("Version control"); - size_t pos2 = buildInfo.find('\n', pos1); - if(pos1 != std::string::npos && pos2 != std::string::npos) - { - size_t value_start = buildInfo.rfind(' ', pos2) + 1; - std::string ver( buildInfo.substr(value_start, pos2 - value_start) ); - ::testing::Test::RecordProperty("cv_vcs_version", ver); - if (useStdOut) std::cout << "OpenCV VCS version: " << ver << std::endl; - } - - pos1 = buildInfo.find("inner version"); - pos2 = buildInfo.find('\n', pos1); - if(pos1 != std::string::npos && pos2 != std::string::npos) - { - size_t value_start = buildInfo.rfind(' ', pos2) + 1; - std::string ver( buildInfo.substr(value_start, pos2 - value_start) ); - ::testing::Test::RecordProperty("cv_inner_vcs_version", ver); - if(useStdOut) std::cout << "Inner VCS version: " << ver << std::endl; - } - - const char * build_type = -#ifdef _DEBUG - "debug"; -#else - "release"; -#endif - - ::testing::Test::RecordProperty("cv_build_type", build_type); - if (useStdOut) std::cout << "Build type: " << build_type << std::endl; - - const char* parallel_framework = currentParallelFramework(); - - if (parallel_framework) { - ::testing::Test::RecordProperty("cv_parallel_framework", parallel_framework); - if (useStdOut) std::cout << "Parallel framework: " << parallel_framework << std::endl; - } - - std::string cpu_features; - -#if CV_POPCNT - if (checkHardwareSupport(CV_CPU_POPCNT)) cpu_features += " popcnt"; -#endif -#if CV_MMX - if (checkHardwareSupport(CV_CPU_MMX)) cpu_features += " mmx"; -#endif -#if CV_SSE - if (checkHardwareSupport(CV_CPU_SSE)) cpu_features += " sse"; -#endif -#if CV_SSE2 - if (checkHardwareSupport(CV_CPU_SSE2)) cpu_features += " sse2"; -#endif -#if CV_SSE3 - if (checkHardwareSupport(CV_CPU_SSE3)) cpu_features += " sse3"; -#endif -#if CV_SSSE3 - if (checkHardwareSupport(CV_CPU_SSSE3)) cpu_features += " ssse3"; -#endif -#if CV_SSE4_1 - if (checkHardwareSupport(CV_CPU_SSE4_1)) cpu_features += " sse4.1"; -#endif -#if CV_SSE4_2 - if (checkHardwareSupport(CV_CPU_SSE4_2)) cpu_features += " sse4.2"; -#endif -#if CV_AVX - if (checkHardwareSupport(CV_CPU_AVX)) cpu_features += " avx"; -#endif -#if CV_AVX2 - if (checkHardwareSupport(CV_CPU_AVX2)) cpu_features += " avx2"; -#endif -#if CV_FMA3 - if (checkHardwareSupport(CV_CPU_FMA3)) cpu_features += " fma3"; -#endif -#if CV_AVX_512F - if (checkHardwareSupport(CV_CPU_AVX_512F)) cpu_features += " avx-512f"; -#endif -#if CV_AVX_512BW - if (checkHardwareSupport(CV_CPU_AVX_512BW)) cpu_features += " avx-512bw"; -#endif -#if CV_AVX_512CD - if (checkHardwareSupport(CV_CPU_AVX_512CD)) cpu_features += " avx-512cd"; -#endif -#if CV_AVX_512DQ - if (checkHardwareSupport(CV_CPU_AVX_512DQ)) cpu_features += " avx-512dq"; -#endif -#if CV_AVX_512ER - if (checkHardwareSupport(CV_CPU_AVX_512ER)) cpu_features += " avx-512er"; -#endif -#if CV_AVX_512IFMA512 - if (checkHardwareSupport(CV_CPU_AVX_512IFMA512)) cpu_features += " avx-512ifma512"; -#endif -#if CV_AVX_512PF - if (checkHardwareSupport(CV_CPU_AVX_512PF)) cpu_features += " avx-512pf"; -#endif -#if CV_AVX_512VBMI - if (checkHardwareSupport(CV_CPU_AVX_512VBMI)) cpu_features += " avx-512vbmi"; -#endif -#if CV_AVX_512VL - if (checkHardwareSupport(CV_CPU_AVX_512VL)) cpu_features += " avx-512vl"; -#endif -#if CV_NEON - if (checkHardwareSupport(CV_CPU_NEON)) cpu_features += " neon"; -#endif -#if CV_FP16 - if (checkHardwareSupport(CV_CPU_FP16)) cpu_features += " fp16"; -#endif -#if CV_VSX - if (checkHardwareSupport(CV_CPU_VSX)) cpu_features += " VSX"; -#endif - - cpu_features.erase(0, 1); // erase initial space - - ::testing::Test::RecordProperty("cv_cpu_features", cpu_features); - if (useStdOut) std::cout << "CPU features: " << cpu_features << std::endl; - -#ifdef HAVE_TEGRA_OPTIMIZATION - const char * tegra_optimization = tegra::useTegra() && tegra::isDeviceSupported() ? "enabled" : "disabled"; - ::testing::Test::RecordProperty("cv_tegra_optimization", tegra_optimization); - if (useStdOut) std::cout << "Tegra optimization: " << tegra_optimization << std::endl; -#endif - -#ifdef HAVE_IPP - const char * ipp_optimization = cv::ipp::useIPP()? "enabled" : "disabled"; - ::testing::Test::RecordProperty("cv_ipp_optimization", ipp_optimization); - if (useStdOut) std::cout << "Intel(R) IPP optimization: " << ipp_optimization << std::endl; - - cv::String ippVer = cv::ipp::getIppVersion(); - ::testing::Test::RecordProperty("cv_ipp_version", ippVer); - if(useStdOut) std::cout << "Intel(R) IPP version: " << ippVer.c_str() << std::endl; -#endif -} - - - void threshold( const Mat& _src, Mat& _dst, double thresh, double maxval, int thresh_type ) {