From 03bcfe4107eacaf38bd7bf708eda174602e4a985 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 12 Dec 2016 14:22:52 +0300 Subject: [PATCH] test: fix RNG problem in accuracy tests --- modules/ts/include/opencv2/ts.hpp | 4 +++- modules/ts/include/opencv2/ts/ts_ext.hpp | 4 +++- modules/ts/src/ts.cpp | 5 +++++ modules/ts/src/ts_perf.cpp | 1 - 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 28a071a565..c573905c6f 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -539,11 +539,13 @@ protected: } }; +extern uint64 param_seed; + struct CV_EXPORTS DefaultRngAuto { const uint64 old_state; - DefaultRngAuto() : old_state(cv::theRNG().state) { cv::theRNG().state = (uint64)-1; } + DefaultRngAuto() : old_state(cv::theRNG().state) { cv::theRNG().state = cvtest::param_seed; } ~DefaultRngAuto() { cv::theRNG().state = old_state; } DefaultRngAuto& operator=(const DefaultRngAuto&); diff --git a/modules/ts/include/opencv2/ts/ts_ext.hpp b/modules/ts/include/opencv2/ts/ts_ext.hpp index 781b61e4dd..05ccc63cc1 100644 --- a/modules/ts/include/opencv2/ts/ts_ext.hpp +++ b/modules/ts/include/opencv2/ts/ts_ext.hpp @@ -12,7 +12,9 @@ namespace cvtest { void checkIppStatus(); } -#define CV_TEST_INIT cv::ipp::setIppStatus(0); +#define CV_TEST_INIT \ + cv::ipp::setIppStatus(0); \ + cv::theRNG().state = cvtest::param_seed; #define CV_TEST_CLEANUP ::cvtest::checkIppStatus(); #define CV_TEST_BODY_IMPL \ { \ diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index c60e5d635a..b2763d4469 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -80,6 +80,8 @@ namespace cvtest { +uint64 param_seed = 0x12345678; // real value is passed via parseCustomOptions function + static std::string path_join(const std::string& prefix, const std::string& subpath) { CV_Assert(subpath.empty() || subpath[0] != '/'); @@ -695,6 +697,7 @@ void parseCustomOptions(int argc, char **argv) { const char * const command_line_keys = "{ ipp test_ipp_check |false |check whether IPP works without failures }" + "{ test_seed |809564 |seed for random numbers generator }" "{ h help |false |print help info }"; cv::CommandLineParser parser(argc, argv, command_line_keys); @@ -711,6 +714,8 @@ void parseCustomOptions(int argc, char **argv) #else test_ipp_check = false; #endif + + param_seed = parser.get("test_seed"); } diff --git a/modules/ts/src/ts_perf.cpp b/modules/ts/src/ts_perf.cpp index f4967748ee..84ce5d6a64 100644 --- a/modules/ts/src/ts_perf.cpp +++ b/modules/ts/src/ts_perf.cpp @@ -38,7 +38,6 @@ static double param_max_outliers; static double param_max_deviation; static unsigned int param_min_samples; static unsigned int param_force_samples; -static uint64 param_seed; static double param_time_limit; static int param_threads; static bool param_write_sanity;