Skip to content

Commit 5232ea1

Browse files
committed
ts(feature): add "--test_threads=<N>" command-line option
1 parent 2e33844 commit 5232ea1

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

modules/ts/include/opencv2/ts/ts_ext.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
namespace cvtest {
1212
void checkIppStatus();
1313
extern bool skipUnstableTests;
14+
extern int testThreads;
1415
}
1516

1617
#define CV__TEST_INIT \
1718
cv::ipp::setIppStatus(0); \
18-
cv::theRNG().state = cvtest::param_seed;
19+
cv::theRNG().state = cvtest::param_seed; \
20+
cv::setNumThreads(cvtest::testThreads);
1921
#define CV__TEST_CLEANUP ::cvtest::checkIppStatus();
2022
#define CV__TEST_BODY_IMPL(name) \
2123
{ \

modules/ts/src/ts.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,14 @@ void checkIppStatus()
695695
}
696696

697697
bool skipUnstableTests = false;
698+
int testThreads = 0;
698699

699700
void parseCustomOptions(int argc, char **argv)
700701
{
701702
const char * const command_line_keys =
702703
"{ ipp test_ipp_check |false |check whether IPP works without failures }"
703704
"{ test_seed |809564 |seed for random numbers generator }"
705+
"{ test_threads |-1 |the number of worker threads, if parallel execution is enabled}"
704706
"{ skip_unstable |false |skip unstable tests }"
705707
"{ h help |false |print help info }";
706708

@@ -721,6 +723,8 @@ void parseCustomOptions(int argc, char **argv)
721723

722724
param_seed = parser.get<unsigned int>("test_seed");
723725

726+
testThreads = parser.get<int>("test_threads");
727+
724728
skipUnstableTests = parser.get<bool>("skip_unstable");
725729
}
726730

modules/ts/src/ts_perf.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ static double param_max_deviation;
3939
static unsigned int param_min_samples;
4040
static unsigned int param_force_samples;
4141
static double param_time_limit;
42-
static int param_threads;
4342
static bool param_write_sanity;
4443
static bool param_verify_sanity;
4544
#ifdef CV_COLLECT_IMPL_DATA
@@ -1042,7 +1041,7 @@ void TestBase::Init(const std::vector<std::string> & availableImpls,
10421041
#ifdef HAVE_IPP
10431042
test_ipp_check = !args.get<bool>("perf_ipp_check") ? getenv("OPENCV_IPP_CHECK") != NULL : true;
10441043
#endif
1045-
param_threads = args.get<int>("perf_threads");
1044+
testThreads = args.get<int>("perf_threads");
10461045
#ifdef CV_COLLECT_IMPL_DATA
10471046
param_collect_impl = args.get<bool>("perf_collect_impl");
10481047
#endif
@@ -1160,7 +1159,7 @@ void TestBase::Init(const std::vector<std::string> & availableImpls,
11601159
void TestBase::RecordRunParameters()
11611160
{
11621161
::testing::Test::RecordProperty("cv_implementation", param_impl);
1163-
::testing::Test::RecordProperty("cv_num_threads", param_threads);
1162+
::testing::Test::RecordProperty("cv_num_threads", testThreads);
11641163

11651164
#ifdef HAVE_CUDA
11661165
if (param_impl == "cuda")
@@ -1851,8 +1850,8 @@ void TestBase::SetUp()
18511850
{
18521851
cv::theRNG().state = param_seed; // this rng should generate same numbers for each run
18531852

1854-
if (param_threads >= 0)
1855-
cv::setNumThreads(param_threads);
1853+
if (testThreads >= 0)
1854+
cv::setNumThreads(testThreads);
18561855
else
18571856
cv::setNumThreads(-1);
18581857

0 commit comments

Comments
 (0)