Skip to content

Commit b8af7c5

Browse files
committed
ts: update perf test
- use GTest tuple definitions instead of std::tr1 - use "const static" for cv::Size contants to reduce generated binary code - PERF_TEST_P() violates TEST_P() original semantic. Added PERF_TEST_P_() macro
1 parent 3f794cd commit b8af7c5

File tree

6 files changed

+81
-50
lines changed

6 files changed

+81
-50
lines changed

modules/ts/include/opencv2/ts.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
# define GTEST_USES_POSIX_RE 0
5959
#endif
6060

61-
#define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< std::tr1::tuple< __VA_ARGS__ > >
62-
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
61+
#define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< testing::tuple< __VA_ARGS__ > >
62+
#define GET_PARAM(k) testing::get< k >(GetParam())
6363

6464
namespace cvtest
6565
{
@@ -70,6 +70,13 @@ using namespace cv;
7070
using testing::Values;
7171
using testing::Combine;
7272

73+
// Tuple stuff from Google Tests
74+
using testing::get;
75+
using testing::make_tuple;
76+
using testing::tuple;
77+
using testing::tuple_size;
78+
using testing::tuple_element;
79+
7380

7481
class SkipTestException: public cv::Exception
7582
{

modules/ts/include/opencv2/ts/cuda_perf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ namespace perf
6262
#define CUDA_CHANNELS_1_3_4 testing::Values(MatCn(Gray), MatCn(BGR), MatCn(BGRA))
6363
#define CUDA_CHANNELS_1_3 testing::Values(MatCn(Gray), MatCn(BGR))
6464

65-
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
65+
#define GET_PARAM(k) testing::get< k >(GetParam())
6666

67-
#define DEF_PARAM_TEST(name, ...) typedef ::perf::TestBaseWithParam< std::tr1::tuple< __VA_ARGS__ > > name
67+
#define DEF_PARAM_TEST(name, ...) typedef ::perf::TestBaseWithParam< testing::tuple< __VA_ARGS__ > > name
6868
#define DEF_PARAM_TEST_1(name, param_type) typedef ::perf::TestBaseWithParam< param_type > name
6969

7070
DEF_PARAM_TEST_1(Sz, cv::Size);

modules/ts/include/opencv2/ts/ocl_perf.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ namespace ocl {
5252

5353
using namespace perf;
5454

55-
using std::tr1::get;
56-
using std::tr1::tuple;
57-
5855
#define OCL_PERF_STRATEGY PERF_STRATEGY_SIMPLE
5956

6057
#define OCL_PERF_TEST(fixture, name) SIMPLE_PERF_TEST(fixture, name)

modules/ts/include/opencv2/ts/ocl_test.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ struct CV_EXPORTS TSTestWithParam : public TestUtils, public ::testing::TestWith
325325
};
326326

327327
#undef PARAM_TEST_CASE
328-
#define PARAM_TEST_CASE(name, ...) struct name : public ::cvtest::ocl::TSTestWithParam< std::tr1::tuple< __VA_ARGS__ > >
328+
#define PARAM_TEST_CASE(name, ...) struct name : public ::cvtest::ocl::TSTestWithParam< testing::tuple< __VA_ARGS__ > >
329329

330330
#ifndef IMPLEMENT_PARAM_CLASS
331331
#define IMPLEMENT_PARAM_CLASS(name, type) \

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ namespace cvtest {
1212
void checkIppStatus();
1313
}
1414

15-
#define CV_TEST_INIT \
15+
#define CV__TEST_INIT \
1616
cv::ipp::setIppStatus(0); \
1717
cv::theRNG().state = cvtest::param_seed;
18-
#define CV_TEST_CLEANUP ::cvtest::checkIppStatus();
19-
#define CV_TEST_BODY_IMPL(name) \
18+
#define CV__TEST_CLEANUP ::cvtest::checkIppStatus();
19+
#define CV__TEST_BODY_IMPL(name) \
2020
{ \
2121
CV__TRACE_APP_FUNCTION_NAME(name); \
2222
try { \
23-
CV_TEST_INIT \
23+
CV__TEST_INIT \
2424
Body(); \
25-
CV_TEST_CLEANUP \
25+
CV__TEST_CLEANUP \
2626
} \
2727
catch (cvtest::SkipTestException& e) \
2828
{ \
@@ -54,7 +54,7 @@ void checkIppStatus();
5454
::testing::Test::TearDownTestCase, \
5555
new ::testing::internal::TestFactoryImpl<\
5656
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
57-
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() CV_TEST_BODY_IMPL( #test_case_name "_" #test_name ) \
57+
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() CV__TEST_BODY_IMPL( #test_case_name "_" #test_name ) \
5858
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::Body()
5959

6060
#undef TEST_F
@@ -80,17 +80,17 @@ void checkIppStatus();
8080
test_fixture::TearDownTestCase, \
8181
new ::testing::internal::TestFactoryImpl<\
8282
GTEST_TEST_CLASS_NAME_(test_fixture, test_name)>);\
83-
void GTEST_TEST_CLASS_NAME_(test_fixture, test_name)::TestBody() CV_TEST_BODY_IMPL( #test_fixture "_" #test_name ) \
83+
void GTEST_TEST_CLASS_NAME_(test_fixture, test_name)::TestBody() CV__TEST_BODY_IMPL( #test_fixture "_" #test_name ) \
8484
void GTEST_TEST_CLASS_NAME_(test_fixture, test_name)::Body()
8585

86-
#undef TEST_P
87-
#define TEST_P(test_case_name, test_name) \
86+
// Don't use directly
87+
#define CV__TEST_P(test_case_name, test_name, bodyMethodName, BODY_IMPL/*(name_str)*/) \
8888
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
8989
: public test_case_name { \
9090
public: \
9191
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
9292
private: \
93-
virtual void Body(); \
93+
virtual void bodyMethodName(); \
9494
virtual void TestBody(); \
9595
static int AddToRegistry() { \
9696
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
@@ -112,7 +112,10 @@ void checkIppStatus();
112112
int GTEST_TEST_CLASS_NAME_(test_case_name, \
113113
test_name)::gtest_registering_dummy_ = \
114114
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
115-
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() CV_TEST_BODY_IMPL( #test_case_name "_" #test_name ) \
116-
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::Body()
115+
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() BODY_IMPL( #test_case_name "_" #test_name ) \
116+
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::bodyMethodName()
117+
118+
#undef TEST_P
119+
#define TEST_P(test_case_name, test_name) CV__TEST_P(test_case_name, test_name, Body, CV__TEST_BODY_IMPL)
117120

118121
#endif // OPENCV_TS_EXT_HPP

modules/ts/include/opencv2/ts/ts_perf.hpp

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,49 @@
2727

2828
// declare major namespaces to avoid errors on unknown namespace
2929
namespace cv { namespace cuda {} namespace ocl {} }
30+
namespace cvtest { }
3031

3132
namespace perf
3233
{
34+
35+
// Tuple stuff from Google Tests
36+
using testing::get;
37+
using testing::make_tuple;
38+
using testing::tuple;
39+
using testing::tuple_size;
40+
using testing::tuple_element;
41+
3342
class TestBase;
3443

3544
/*****************************************************************************************\
3645
* Predefined typical frame sizes and typical test parameters *
3746
\*****************************************************************************************/
38-
const cv::Size szQVGA = cv::Size(320, 240);
39-
const cv::Size szVGA = cv::Size(640, 480);
40-
const cv::Size szSVGA = cv::Size(800, 600);
41-
const cv::Size szXGA = cv::Size(1024, 768);
42-
const cv::Size szSXGA = cv::Size(1280, 1024);
43-
const cv::Size szWQHD = cv::Size(2560, 1440);
44-
45-
const cv::Size sznHD = cv::Size(640, 360);
46-
const cv::Size szqHD = cv::Size(960, 540);
47-
const cv::Size sz240p = szQVGA;
48-
const cv::Size sz720p = cv::Size(1280, 720);
49-
const cv::Size sz1080p = cv::Size(1920, 1080);
50-
const cv::Size sz1440p = szWQHD;
51-
const cv::Size sz2160p = cv::Size(3840, 2160);//UHDTV1 4K
52-
const cv::Size sz4320p = cv::Size(7680, 4320);//UHDTV2 8K
53-
54-
const cv::Size sz3MP = cv::Size(2048, 1536);
55-
const cv::Size sz5MP = cv::Size(2592, 1944);
56-
const cv::Size sz2K = cv::Size(2048, 2048);
57-
58-
const cv::Size szODD = cv::Size(127, 61);
59-
60-
const cv::Size szSmall24 = cv::Size(24, 24);
61-
const cv::Size szSmall32 = cv::Size(32, 32);
62-
const cv::Size szSmall64 = cv::Size(64, 64);
63-
const cv::Size szSmall128 = cv::Size(128, 128);
47+
const static cv::Size szQVGA = cv::Size(320, 240);
48+
const static cv::Size szVGA = cv::Size(640, 480);
49+
const static cv::Size szSVGA = cv::Size(800, 600);
50+
const static cv::Size szXGA = cv::Size(1024, 768);
51+
const static cv::Size szSXGA = cv::Size(1280, 1024);
52+
const static cv::Size szWQHD = cv::Size(2560, 1440);
53+
54+
const static cv::Size sznHD = cv::Size(640, 360);
55+
const static cv::Size szqHD = cv::Size(960, 540);
56+
const static cv::Size sz240p = szQVGA;
57+
const static cv::Size sz720p = cv::Size(1280, 720);
58+
const static cv::Size sz1080p = cv::Size(1920, 1080);
59+
const static cv::Size sz1440p = szWQHD;
60+
const static cv::Size sz2160p = cv::Size(3840, 2160);//UHDTV1 4K
61+
const static cv::Size sz4320p = cv::Size(7680, 4320);//UHDTV2 8K
62+
63+
const static cv::Size sz3MP = cv::Size(2048, 1536);
64+
const static cv::Size sz5MP = cv::Size(2592, 1944);
65+
const static cv::Size sz2K = cv::Size(2048, 2048);
66+
67+
const static cv::Size szODD = cv::Size(127, 61);
68+
69+
const static cv::Size szSmall24 = cv::Size(24, 24);
70+
const static cv::Size szSmall32 = cv::Size(32, 32);
71+
const static cv::Size szSmall64 = cv::Size(64, 64);
72+
const static cv::Size szSmall128 = cv::Size(128, 128);
6473

6574
#define SZ_ALL_VGA ::testing::Values(::perf::szQVGA, ::perf::szVGA, ::perf::szSVGA)
6675
#define SZ_ALL_GA ::testing::Values(::perf::szQVGA, ::perf::szVGA, ::perf::szSVGA, ::perf::szXGA, ::perf::szSXGA)
@@ -492,7 +501,7 @@ class CV_EXPORTS TestBase: public ::testing::Test
492501

493502
template<typename T> class TestBaseWithParam: public TestBase, public ::testing::WithParamInterface<T> {};
494503

495-
typedef std::tr1::tuple<cv::Size, MatType> Size_MatType_t;
504+
typedef tuple<cv::Size, MatType> Size_MatType_t;
496505
typedef TestBaseWithParam<Size_MatType_t> Size_MatType;
497506

498507
/*****************************************************************************************\
@@ -514,6 +523,13 @@ CV_EXPORTS void PrintTo(const Size& sz, ::std::ostream* os);
514523
/*****************************************************************************************\
515524
* Macro definitions for performance tests *
516525
\*****************************************************************************************/
526+
527+
#define CV__PERF_TEST_BODY_IMPL(name) \
528+
{ \
529+
CV__TRACE_APP_FUNCTION_NAME("PERF_TEST: " name); \
530+
RunPerfTestBody(); \
531+
}
532+
517533
#define PERF_PROXY_NAMESPACE_NAME_(test_case_name, test_name) \
518534
test_case_name##_##test_name##_perf_namespace_proxy
519535

@@ -538,7 +554,7 @@ CV_EXPORTS void PrintTo(const Size& sz, ::std::ostream* os);
538554
protected:\
539555
virtual void PerfTestBody();\
540556
};\
541-
TEST_F(test_case_name, test_name){ CV_TRACE_REGION("PERF_TEST: " #test_case_name "_" #test_name); RunPerfTestBody(); }\
557+
TEST_F(test_case_name, test_name){ CV__PERF_TEST_BODY_IMPL(#test_case_name "_" #test_name); }\
542558
}\
543559
void PERF_PROXY_NAMESPACE_NAME_(test_case_name, test_name)::test_case_name::PerfTestBody()
544560

@@ -576,12 +592,20 @@ CV_EXPORTS void PrintTo(const Size& sz, ::std::ostream* os);
576592
protected:\
577593
virtual void PerfTestBody();\
578594
};\
579-
TEST_F(fixture, testname){ CV_TRACE_REGION("PERF_TEST: " #fixture "_" #testname); RunPerfTestBody(); }\
595+
TEST_F(fixture, testname){ CV__PERF_TEST_BODY_IMPL(#fixture "_" #testname); }\
580596
}\
581597
void PERF_PROXY_NAMESPACE_NAME_(fixture, testname)::fixture::PerfTestBody()
582598

583599
// Defines a parametrized performance test.
584600
//
601+
// @Note PERF_TEST_P() below violates behavior of original Google Tests - there is no tests instantiation in original TEST_P()
602+
// This macro is intended for usage with separate INSTANTIATE_TEST_CASE_P macro
603+
#define PERF_TEST_P_(test_case_name, test_name) CV__TEST_P(test_case_name, test_name, PerfTestBody, CV__PERF_TEST_BODY_IMPL)
604+
605+
// Defines a parametrized performance test.
606+
//
607+
// @Note Original TEST_P() macro doesn't instantiate tests with parameters. To keep original usage use PERF_TEST_P_() macro
608+
//
585609
// The first parameter is the name of the test fixture class, which
586610
// also doubles as the test case name. The second parameter is the
587611
// name of the test within the test case.
@@ -609,7 +633,7 @@ CV_EXPORTS void PrintTo(const Size& sz, ::std::ostream* os);
609633
protected:\
610634
virtual void PerfTestBody();\
611635
};\
612-
TEST_P(fixture##_##name, name /*perf*/){ CV_TRACE_REGION("PERF_TEST: " #fixture "_" #name); RunPerfTestBody(); }\
636+
CV__TEST_P(fixture##_##name, name, PerfTestBodyDummy, CV__PERF_TEST_BODY_IMPL){} \
613637
INSTANTIATE_TEST_CASE_P(/*none*/, fixture##_##name, params);\
614638
void fixture##_##name::PerfTestBody()
615639

0 commit comments

Comments
 (0)