cleaned-up UMat tests

This commit is contained in:
Ilya Lavrenov 2014-02-15 15:51:52 +04:00
parent 3542da7167
commit 4f36bc29d9
3 changed files with 40 additions and 156 deletions

View File

@ -15,127 +15,4 @@
#include "opencv2/core/private.hpp"
#define MWIDTH 256
#define MHEIGHT 256
#define MIN_VALUE 171
#define MAX_VALUE 357
#define RNG_SEED 123456
template <typename T>
struct TSTestWithParam : public ::testing::TestWithParam<T>
{
cv::RNG rng;
TSTestWithParam()
{
rng = cv::RNG(RNG_SEED);
}
int randomInt(int minVal, int maxVal)
{
return rng.uniform(minVal, maxVal);
}
double randomDouble(double minVal, double maxVal)
{
return rng.uniform(minVal, maxVal);
}
double randomDoubleLog(double minVal, double maxVal)
{
double logMin = log((double)minVal + 1);
double logMax = log((double)maxVal + 1);
double pow = rng.uniform(logMin, logMax);
double v = exp(pow) - 1;
CV_Assert(v >= minVal && (v < maxVal || (v == minVal && v == maxVal)));
return v;
}
cv::Size randomSize(int minVal, int maxVal)
{
#if 1
return cv::Size((int)randomDoubleLog(minVal, maxVal), (int)randomDoubleLog(minVal, maxVal));
#else
return cv::Size(randomInt(minVal, maxVal), randomInt(minVal, maxVal));
#endif
}
cv::Size randomSize(int minValX, int maxValX, int minValY, int maxValY)
{
#if 1
return cv::Size(randomDoubleLog(minValX, maxValX), randomDoubleLog(minValY, maxValY));
#else
return cv::Size(randomInt(minVal, maxVal), randomInt(minVal, maxVal));
#endif
}
cv::Scalar randomScalar(double minVal, double maxVal)
{
return cv::Scalar(randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal));
}
cv::Mat randomMat(cv::Size size, int type, double minVal, double maxVal, bool useRoi = false)
{
cv::RNG dataRng(rng.next());
return cvtest::randomMat(dataRng, size, type, minVal, maxVal, useRoi);
}
};
#define PARAM_TEST_CASE(name, ...) struct name : public TSTestWithParam< std::tr1::tuple< __VA_ARGS__ > >
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
#define UMAT_TEST_CHANNELS testing::Values(1, 2, 3, 4)
#define UMAT_TEST_SIZES testing::Values(cv::Size(1,1), cv::Size(1,128), cv::Size(128,1), cv::Size(128, 128), cv::Size(640,480), cv::Size(751,373), cv::Size(1200, 1200))
#define UMAT_TEST_DEPTH testing::Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F)
# define CORE_TEST_P(test_case_name, test_name) \
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : \
public test_case_name { \
public: \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() { } \
virtual void TestBody(); \
void CoreTestBody(); \
private: \
static int AddToRegistry() \
{ \
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
GetTestCasePatternHolder<test_case_name>(\
#test_case_name, __FILE__, __LINE__)->AddTestPattern(\
#test_case_name, \
#test_name, \
new ::testing::internal::TestMetaFactory< \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \
return 0; \
} \
\
static int gtest_registering_dummy_; \
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
}; \
\
int GTEST_TEST_CLASS_NAME_(test_case_name, \
test_name)::gtest_registering_dummy_ = \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
\
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() \
{ \
try \
{ \
CoreTestBody(); \
} \
catch (...) \
{ \
std::cout << "Something wrong in CoreTestBody running" << std::endl; \
throw; \
} \
} \
\
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::CoreTestBody()
#endif

View File

@ -40,20 +40,19 @@
//M*/
#include "test_precomp.hpp"
#include "opencv2/core/ocl.hpp"
#include "opencv2/ts/ocl_test.hpp"
using namespace cvtest;
using namespace testing;
using namespace cv;
#define EXPECT_MAT_NEAR(mat1, mat2, eps) \
{ \
ASSERT_EQ(mat1.type(), mat2.type()); \
ASSERT_EQ(mat1.size(), mat2.size()); \
EXPECT_LE(cv::norm(mat1, mat2), eps); \
}\
namespace cvtest {
namespace ocl {
////////////////////////////////////////////////////////////// Basic Tests /////////////////////////////////////////////////////////////////////
#define UMAT_TEST_SIZES testing::Values(cv::Size(1, 1), cv::Size(1,128), cv::Size(128, 1), \
cv::Size(128, 128), cv::Size(640, 480), cv::Size(751, 373), cv::Size(1200, 1200))
/////////////////////////////// Basic Tests ////////////////////////////////
PARAM_TEST_CASE(UMatBasicTests, int, int, Size, bool)
{
@ -66,6 +65,7 @@ PARAM_TEST_CASE(UMatBasicTests, int, int, Size, bool)
bool useRoi;
Size roi_size;
Rect roi;
virtual void SetUp()
{
depth = GET_PARAM(0);
@ -82,7 +82,7 @@ PARAM_TEST_CASE(UMatBasicTests, int, int, Size, bool)
}
};
CORE_TEST_P(UMatBasicTests, createUMat)
OCL_TEST_P(UMatBasicTests, createUMat)
{
if(useRoi)
{
@ -112,7 +112,7 @@ CORE_TEST_P(UMatBasicTests, createUMat)
ASSERT_EQ( ua.dims, 2);
}
CORE_TEST_P(UMatBasicTests, swap)
OCL_TEST_P(UMatBasicTests, swap)
{
Mat b = randomMat(size, type, -100, 100);
UMat ub;
@ -128,7 +128,7 @@ CORE_TEST_P(UMatBasicTests, swap)
EXPECT_MAT_NEAR(ud, ua, 0);
}
CORE_TEST_P(UMatBasicTests, base)
OCL_TEST_P(UMatBasicTests, base)
{
if(useRoi)
{
@ -167,7 +167,7 @@ CORE_TEST_P(UMatBasicTests, base)
ASSERT_EQ(ub.total(), total);
}
CORE_TEST_P(UMatBasicTests, copyTo)
OCL_TEST_P(UMatBasicTests, copyTo)
{
UMat roi_ua;
Mat roi_a;
@ -224,7 +224,7 @@ CORE_TEST_P(UMatBasicTests, copyTo)
}
}
CORE_TEST_P(UMatBasicTests, DISABLED_GetUMat)
OCL_TEST_P(UMatBasicTests, DISABLED_GetUMat)
{
if(useRoi)
{
@ -253,8 +253,8 @@ CORE_TEST_P(UMatBasicTests, DISABLED_GetUMat)
}
}
INSTANTIATE_TEST_CASE_P(UMat, UMatBasicTests, Combine(testing::Values(CV_8U), testing::Values(1, 2),
testing::Values(cv::Size(1,1), cv::Size(1,128), cv::Size(128,1), cv::Size(128, 128), cv::Size(640,480)), Bool() ) );
OCL_INSTANTIATE_TEST_CASE_P(UMat, UMatBasicTests, Combine(testing::Values(CV_8U), testing::Values(1, 2),
testing::Values(cv::Size(1, 1), cv::Size(1, 128), cv::Size(128, 1), cv::Size(128, 128), cv::Size(640, 480)), Bool()));
//////////////////////////////////////////////////////////////// Reshape ////////////////////////////////////////////////////////////////////////
@ -278,7 +278,7 @@ PARAM_TEST_CASE(UMatTestReshape, int, int, Size, bool)
}
};
CORE_TEST_P(UMatTestReshape, reshape)
OCL_TEST_P(UMatTestReshape, reshape)
{
a = randomMat(size,type, -100, 100);
a.copyTo(ua);
@ -342,7 +342,7 @@ CORE_TEST_P(UMatTestReshape, reshape)
}
}
INSTANTIATE_TEST_CASE_P(UMat, UMatTestReshape, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES, Bool() ));
OCL_INSTANTIATE_TEST_CASE_P(UMat, UMatTestReshape, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, UMAT_TEST_SIZES, Bool() ));
////////////////////////////////////////////////////////////////// ROI testing ///////////////////////////////////////////////////////////////
@ -364,7 +364,7 @@ PARAM_TEST_CASE(UMatTestRoi, int, int, Size)
}
};
CORE_TEST_P(UMatTestRoi, createRoi)
OCL_TEST_P(UMatTestRoi, createRoi)
{
int roi_shift_x = randomInt(0, size.width-1);
int roi_shift_y = randomInt(0, size.height-1);
@ -378,7 +378,7 @@ CORE_TEST_P(UMatTestRoi, createRoi)
EXPECT_MAT_NEAR(roi_a, roi_ua, 0);
}
CORE_TEST_P(UMatTestRoi, locateRoi)
OCL_TEST_P(UMatTestRoi, locateRoi)
{
int roi_shift_x = randomInt(0, size.width-1);
int roi_shift_y = randomInt(0, size.height-1);
@ -396,7 +396,7 @@ CORE_TEST_P(UMatTestRoi, locateRoi)
ASSERT_EQ(p, up);
}
CORE_TEST_P(UMatTestRoi, adjustRoi)
OCL_TEST_P(UMatTestRoi, adjustRoi)
{
int roi_shift_x = randomInt(0, size.width-1);
int roi_shift_y = randomInt(0, size.height-1);
@ -410,14 +410,14 @@ CORE_TEST_P(UMatTestRoi, adjustRoi)
int adjTop = randomInt(-(roi_ua.rows/2), (size.height-1)/2);
int adjBot = randomInt(-(roi_ua.rows/2), (size.height-1)/2);
roi_ua.adjustROI(adjTop, adjBot, adjLeft, adjRight);
roi_shift_x = max(0, roi.x-adjLeft);
roi_shift_y = max(0, roi.y-adjTop);
Rect new_roi( roi_shift_x, roi_shift_y, min(roi.width+adjRight+adjLeft, size.width-roi_shift_x), min(roi.height+adjBot+adjTop, size.height-roi_shift_y) );
roi_shift_x = std::max(0, roi.x-adjLeft);
roi_shift_y = std::max(0, roi.y-adjTop);
Rect new_roi( roi_shift_x, roi_shift_y, std::min(roi.width+adjRight+adjLeft, size.width-roi_shift_x), std::min(roi.height+adjBot+adjTop, size.height-roi_shift_y) );
UMat test_roi = UMat(ua, new_roi);
EXPECT_MAT_NEAR(roi_ua, test_roi, 0);
}
INSTANTIATE_TEST_CASE_P(UMat, UMatTestRoi, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES ));
OCL_INSTANTIATE_TEST_CASE_P(UMat, UMatTestRoi, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, UMAT_TEST_SIZES ));
/////////////////////////////////////////////////////////////// Size ////////////////////////////////////////////////////////////////////
@ -441,7 +441,7 @@ PARAM_TEST_CASE(UMatTestSizeOperations, int, int, Size, bool)
}
};
CORE_TEST_P(UMatTestSizeOperations, copySize)
OCL_TEST_P(UMatTestSizeOperations, copySize)
{
Size s = randomSize(1,300);
a = randomMat(size, type, -100, 100);
@ -466,7 +466,7 @@ CORE_TEST_P(UMatTestSizeOperations, copySize)
ASSERT_EQ(ua.size, ub.size);
}
INSTANTIATE_TEST_CASE_P(UMat, UMatTestSizeOperations, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES, Bool() ));
OCL_INSTANTIATE_TEST_CASE_P(UMat, UMatTestSizeOperations, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, UMAT_TEST_SIZES, Bool() ));
///////////////////////////////////////////////////////////////// UMat operations ////////////////////////////////////////////////////////////////////////////
@ -490,7 +490,7 @@ PARAM_TEST_CASE(UMatTestUMatOperations, int, int, Size, bool)
}
};
CORE_TEST_P(UMatTestUMatOperations, diag)
OCL_TEST_P(UMatTestUMatOperations, diag)
{
a = randomMat(size, type, -100, 100);
a.copyTo(ua);
@ -514,7 +514,7 @@ CORE_TEST_P(UMatTestUMatOperations, diag)
EXPECT_MAT_NEAR(ua.diag(), new_diag.t(), 0);
}
INSTANTIATE_TEST_CASE_P(UMat, UMatTestUMatOperations, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES, Bool() ));
OCL_INSTANTIATE_TEST_CASE_P(UMat, UMatTestUMatOperations, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, UMAT_TEST_SIZES, Bool()));
///////////////////////////////////////////////////////////////// OpenCL ////////////////////////////////////////////////////////////////////////////
@ -541,9 +541,7 @@ TEST(UMat, BufferPoolGrowing)
c->freeAllReservedBuffers();
}
else
{
std::cout << "Skipped, no OpenCL" << std::endl;
}
}
TEST(UMat, setOpenCL)
@ -586,3 +584,5 @@ TEST(UMat, setOpenCL)
// reset state to the previous one
cv::ocl::setUseOpenCL(useOCL);
}
} } // namespace cvtest::ocl

View File

@ -71,12 +71,19 @@ struct GetMatForRead<Mat>
{
static const Mat get(const Mat& m) { return m; }
};
template <>
struct GetMatForRead<UMat>
{
static const Mat get(const UMat& m) { return m.getMat(ACCESS_READ); }
};
template <>
struct GetMatForRead<MatExpr>
{
static const Mat get(const MatExpr& m) { return m; }
};
} // namespace traits
template <typename T>
@ -91,14 +98,14 @@ extern int test_loop_times;
#define EXPECT_MAT_NORM(mat, eps) \
{ \
EXPECT_LE(checkNorm(mat), eps) \
EXPECT_LE(TestUtils::checkNorm(mat), eps) \
}
#define EXPECT_MAT_NEAR(mat1, mat2, eps) \
{ \
ASSERT_EQ(mat1.type(), mat2.type()); \
ASSERT_EQ(mat1.size(), mat2.size()); \
EXPECT_LE(checkNorm(mat1, mat2), eps) \
EXPECT_LE(TestUtils::checkNorm(mat1, mat2), eps) \
<< "Size: " << mat1.size() << std::endl; \
}
@ -106,7 +113,7 @@ extern int test_loop_times;
{ \
ASSERT_EQ(mat1.type(), mat2.type()); \
ASSERT_EQ(mat1.size(), mat2.size()); \
EXPECT_LE(checkNormRelative(mat1, mat2), eps) \
EXPECT_LE(TestUtils::checkNormRelative(mat1, mat2), eps) \
<< "Size: " << mat1.size() << std::endl; \
}