From 166619598400397747c98d514781d65eba065c92 Mon Sep 17 00:00:00 2001 From: Andrey Golubev Date: Fri, 28 Jun 2019 17:59:52 +0300 Subject: [PATCH] Merge pull request #14922 from andrey-golubev:operators_tests_update_clean G-API: Align operators tests to new test model (#14922) * Align operators tests to new test model * Change init function in NotOperatorTest --- .../gapi/test/common/gapi_operators_tests.hpp | 10 ++-- .../test/common/gapi_operators_tests_inl.hpp | 30 ++-------- .../test/cpu/gapi_operators_tests_cpu.cpp | 57 ++++++++++--------- .../test/cpu/gapi_operators_tests_fluid.cpp | 54 ++++++++++-------- .../test/gpu/gapi_operators_tests_gpu.cpp | 57 ++++++++++--------- 5 files changed, 99 insertions(+), 109 deletions(-) diff --git a/modules/gapi/test/common/gapi_operators_tests.hpp b/modules/gapi/test/common/gapi_operators_tests.hpp index 9f53d36857..f773709a8a 100644 --- a/modules/gapi/test/common/gapi_operators_tests.hpp +++ b/modules/gapi/test/common/gapi_operators_tests.hpp @@ -61,7 +61,6 @@ struct g_api_ocv_pair_mat_mat { namespace { - //declare test cases for matrix and scalar operators g_api_ocv_pair_mat_scalar opPlus = {std::string{"operator+"}, [](cv::GMat in,cv::GScalar c){return in+c;}, @@ -184,9 +183,12 @@ g_api_ocv_pair_mat_mat opXor = {std::string{"operator^"}, [](const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out){cv::bitwise_xor(in1, in2, out);}}; } // anonymous namespace -struct MathOperatorMatScalarTest : public TestParams>{}; -struct MathOperatorMatMatTest : public TestParams>{}; -struct NotOperatorTest : public TestParams> {}; + +GAPI_TEST_FIXTURE(MathOperatorMatScalarTest, initMatsRandU, + FIXTURE_API(compare_f, g_api_ocv_pair_mat_scalar), 2, cmpF, op) +GAPI_TEST_FIXTURE(MathOperatorMatMatTest, initMatsRandU, + FIXTURE_API(compare_f, g_api_ocv_pair_mat_mat), 2, cmpF, op) +GAPI_TEST_FIXTURE(NotOperatorTest, initMatrixRandU, <>, 0) } // opencv_test #endif // OPENCV_GAPI_OPERATOR_TESTS_COMMON_HPP diff --git a/modules/gapi/test/common/gapi_operators_tests_inl.hpp b/modules/gapi/test/common/gapi_operators_tests_inl.hpp index 7ec702ae9b..44bcc9bc1b 100644 --- a/modules/gapi/test/common/gapi_operators_tests_inl.hpp +++ b/modules/gapi/test/common/gapi_operators_tests_inl.hpp @@ -14,15 +14,6 @@ namespace opencv_test { TEST_P(MathOperatorMatScalarTest, OperatorAccuracyTest ) { - compare_f cmpF; - g_api_ocv_pair_mat_scalar op; - int type = 0, dtype = 0; - cv::Size sz; - bool initOutMatr = false; - cv::GCompileArgs compile_args; - std::tie(cmpF, op, type, sz, dtype, initOutMatr, compile_args) = GetParam(); - initMatsRandU(type, sz, dtype, initOutMatr); - auto fun_gapi = op.g_api_function; auto fun_ocv = op.ocv_function ; @@ -33,7 +24,7 @@ TEST_P(MathOperatorMatScalarTest, OperatorAccuracyTest ) auto out = fun_gapi(in1, in2); cv::GComputation c(GIn(in1, in2), GOut(out)); - c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), getCompileArgs()); fun_ocv(in_mat1, sc, out_mat_ocv); @@ -46,15 +37,6 @@ TEST_P(MathOperatorMatScalarTest, OperatorAccuracyTest ) TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest ) { - compare_f cmpF; - g_api_ocv_pair_mat_mat op; - int type = 0, dtype = 0; - cv::Size sz; - bool initOutMatr = false; - cv::GCompileArgs compile_args; - std::tie(cmpF, op, type, sz, dtype, initOutMatr, compile_args) = GetParam(); - initMatsRandU(type, sz, dtype, initOutMatr); - auto fun_gapi = op.g_api_function; auto fun_ocv = op.ocv_function ; @@ -65,7 +47,7 @@ TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest ) auto out = fun_gapi(in1, in2); cv::GComputation c(GIn(in1, in2), GOut(out)); - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), getCompileArgs()); fun_ocv(in_mat1, in_mat2, out_mat_ocv); @@ -78,16 +60,12 @@ TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest ) TEST_P(NotOperatorTest, OperatorAccuracyTest) { - cv::Size sz_in = std::get<1>(GetParam()); - initMatrixRandU(std::get<0>(GetParam()), sz_in, std::get<0>(GetParam()), std::get<2>(GetParam())); - cv::GCompileArgs compile_args; - // G-API code ////////////////////////////////////////////////////////////// cv::GMat in; auto out = ~in; cv::GComputation c(in, out); - c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + c.apply(in_mat1, out_mat_gapi, getCompileArgs()); // OpenCV code ///////////////////////////////////////////////////////////// { @@ -96,7 +74,7 @@ TEST_P(NotOperatorTest, OperatorAccuracyTest) // Comparison ////////////////////////////////////////////////////////////// { EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); + EXPECT_EQ(out_mat_gapi.size(), sz); } } } // opencv_test diff --git a/modules/gapi/test/cpu/gapi_operators_tests_cpu.cpp b/modules/gapi/test/cpu/gapi_operators_tests_cpu.cpp index d19c338ee6..71d4af8275 100644 --- a/modules/gapi/test/cpu/gapi_operators_tests_cpu.cpp +++ b/modules/gapi/test/cpu/gapi_operators_tests_cpu.cpp @@ -9,65 +9,68 @@ #include "../common/gapi_operators_tests.hpp" #include -#define CORE_CPU cv::gapi::core::cpu::kernels() +namespace +{ + #define CORE_CPU [] () { return cv::compile_args(cv::gapi::core::cpu::kernels()); } +} // anonymous namespace namespace opencv_test { - // FIXME: CPU test runs are disabled since Fluid is an exclusive plugin now! INSTANTIATE_TEST_CASE_P(MathOperatorTestCPU, MathOperatorMatMatTest, - Combine(Values(AbsExact().to_compare_f()), - Values( opPlusM, opMinusM, opDivM, - opGreater, opLess, opGreaterEq, opLessEq, opEq, opNotEq), - Values(CV_8UC1, CV_16SC1, CV_32FC1), + Combine(Values(CV_8UC1, CV_16SC1, CV_32FC1), Values(cv::Size(1280, 720), - cv::Size(640, 480), - cv::Size(128, 128)), + cv::Size(640, 480), + cv::Size(128, 128)), Values(-1, CV_8U, CV_32F), -/*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_CPU)))); + testing::Bool(), + Values(CORE_CPU), + Values(AbsExact().to_compare_f()), + Values( opPlusM, opMinusM, opDivM, + opGreater, opLess, opGreaterEq, opLessEq, opEq, opNotEq))); INSTANTIATE_TEST_CASE_P(MathOperatorTestCPU, MathOperatorMatScalarTest, - Combine(Values(AbsExact().to_compare_f()), - Values( opPlus, opPlusR, opMinus, opMinusR, opMul, opMulR, // FIXIT avoid division by values near zero: opDiv, opDivR, - opGT, opLT, opGE, opLE, opEQ, opNE, - opGTR, opLTR, opGER, opLER, opEQR, opNER), - Values(CV_8UC1, CV_16SC1, CV_32FC1), + Combine(Values(CV_8UC1, CV_16SC1, CV_32FC1), Values(cv::Size(1280, 720), cv::Size(640, 480), cv::Size(128, 128)), Values(-1, CV_8U, CV_32F), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_CPU)))); + Values(CORE_CPU), + Values(AbsExact().to_compare_f()), + Values( opPlus, opPlusR, opMinus, opMinusR, opMul, opMulR, // FIXIT avoid division by values near zero: opDiv, opDivR, + opGT, opLT, opGE, opLE, opEQ, opNE, + opGTR, opLTR, opGER, opLER, opEQR, opNER))); INSTANTIATE_TEST_CASE_P(BitwiseOperatorTestCPU, MathOperatorMatMatTest, - Combine(Values(AbsExact().to_compare_f()), - Values( opAnd, opOr, opXor ), - Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(cv::Size(1280, 720), - cv::Size(640, 480), - cv::Size(128, 128)), + cv::Size(640, 480), + cv::Size(128, 128)), Values(-1), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_CPU)))); + Values(CORE_CPU), + Values(AbsExact().to_compare_f()), + Values( opAnd, opOr, opXor ))); INSTANTIATE_TEST_CASE_P(BitwiseOperatorTestCPU, MathOperatorMatScalarTest, - Combine(Values(AbsExact().to_compare_f()), - Values( opAND, opOR, opXOR, opANDR, opORR, opXORR ), - Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(cv::Size(1280, 720), cv::Size(640, 480), cv::Size(128, 128)), Values(-1), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_CPU)))); + Values(CORE_CPU), + Values(AbsExact().to_compare_f()), + Values( opAND, opOR, opXOR, opANDR, opORR, opXORR ))); INSTANTIATE_TEST_CASE_P(BitwiseNotOperatorTestCPU, NotOperatorTest, Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(cv::Size(1280, 720), cv::Size(640, 480), cv::Size(128, 128)), + Values(SAME_TYPE), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_CPU)))); + Values(CORE_CPU))); } diff --git a/modules/gapi/test/cpu/gapi_operators_tests_fluid.cpp b/modules/gapi/test/cpu/gapi_operators_tests_fluid.cpp index b3e54bb85a..bc55154f1c 100644 --- a/modules/gapi/test/cpu/gapi_operators_tests_fluid.cpp +++ b/modules/gapi/test/cpu/gapi_operators_tests_fluid.cpp @@ -8,65 +8,69 @@ #include "../test_precomp.hpp" #include "../common/gapi_operators_tests.hpp" -#define CORE_FLUID cv::gapi::core::fluid::kernels() +namespace +{ + #define CORE_FLUID [] () { return cv::compile_args(cv::gapi::core::fluid::kernels()); } +} // anonymous namespace namespace opencv_test { INSTANTIATE_TEST_CASE_P(MathOperatorTestFluid, MathOperatorMatMatTest, - Combine(Values(AbsExact().to_compare_f()), - Values( opPlusM, opMinusM, opDivM, - opGreater, opLess, opGreaterEq, opLessEq, opEq, opNotEq), - Values(CV_8UC1, CV_16SC1, CV_32FC1), + Combine(Values(CV_8UC1, CV_16SC1, CV_32FC1), Values(cv::Size(1280, 720), - cv::Size(640, 480), - cv::Size(128, 128)), + cv::Size(640, 480), + cv::Size(128, 128)), Values(-1, CV_8U, CV_32F), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_FLUID)))); + Values(CORE_FLUID), + Values(AbsExact().to_compare_f()), + Values( opPlusM, opMinusM, opDivM, + opGreater, opLess, opGreaterEq, opLessEq, opEq, opNotEq))); //FIXME: Some Mat/Scalar Fluid kernels are not there yet! INSTANTIATE_TEST_CASE_P(DISABLED_MathOperatorTestFluid, MathOperatorMatScalarTest, - Combine(Values(AbsExact().to_compare_f()), - Values( opPlus, opPlusR, opMinus, opMinusR, opMul, opMulR, // FIXIT avoid division by values near zero: opDiv, opDivR, - opGT, opLT, opGE, opLE, opEQ, opNE, - opGTR, opLTR, opGER, opLER, opEQR, opNER), - Values(CV_8UC1, CV_16SC1, CV_32FC1), + Combine(Values(CV_8UC1, CV_16SC1, CV_32FC1), Values(cv::Size(1280, 720), cv::Size(640, 480), cv::Size(128, 128)), Values(-1, CV_8U, CV_32F), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_FLUID)))); + Values(CORE_FLUID), + Values(AbsExact().to_compare_f()), + Values( opPlus, opPlusR, opMinus, opMinusR, opMul, opMulR, // FIXIT avoid division by values near zero: opDiv, opDivR, + opGT, opLT, opGE, opLE, opEQ, opNE, + opGTR, opLTR, opGER, opLER, opEQR, opNER))); INSTANTIATE_TEST_CASE_P(BitwiseOperatorTestFluid, MathOperatorMatMatTest, - Combine(Values(AbsExact().to_compare_f()), - Values( opAnd, opOr, opXor ), - Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(cv::Size(1280, 720), - cv::Size(640, 480), - cv::Size(128, 128)), + cv::Size(640, 480), + cv::Size(128, 128)), Values(-1), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_FLUID)))); + Values(CORE_FLUID), + Values(AbsExact().to_compare_f()), + Values( opAnd, opOr, opXor ))); //FIXME: Some Mat/Scalar Fluid kernels are not there yet! INSTANTIATE_TEST_CASE_P(DISABLED_BitwiseOperatorTestFluid, MathOperatorMatScalarTest, - Combine(Values(AbsExact().to_compare_f()), - Values( opAND, opOR, opXOR, opANDR, opORR, opXORR ), - Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(cv::Size(1280, 720), cv::Size(640, 480), cv::Size(128, 128)), Values(-1), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_FLUID)))); + Values(CORE_FLUID), + Values(AbsExact().to_compare_f()), + Values( opAND, opOR, opXOR, opANDR, opORR, opXORR ))); INSTANTIATE_TEST_CASE_P(BitwiseNotOperatorTestFluid, NotOperatorTest, Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(cv::Size(1280, 720), cv::Size(640, 480), cv::Size(128, 128)), + Values(SAME_TYPE), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_FLUID)))); + Values(CORE_FLUID))); } diff --git a/modules/gapi/test/gpu/gapi_operators_tests_gpu.cpp b/modules/gapi/test/gpu/gapi_operators_tests_gpu.cpp index 73b1c78f34..0e21019b06 100644 --- a/modules/gapi/test/gpu/gapi_operators_tests_gpu.cpp +++ b/modules/gapi/test/gpu/gapi_operators_tests_gpu.cpp @@ -8,64 +8,67 @@ #include "../test_precomp.hpp" #include "../common/gapi_operators_tests.hpp" -#define CORE_GPU cv::gapi::core::gpu::kernels() +namespace +{ + #define CORE_GPU [] () { return cv::compile_args(cv::gapi::core::gpu::kernels()); } +} // anonymous namespace namespace opencv_test { - INSTANTIATE_TEST_CASE_P(MathOperatorTestGPU, MathOperatorMatMatTest, - Combine(Values(Tolerance_FloatRel_IntAbs(1e-5, 2).to_compare_f()), - Values( opPlusM, opMinusM, opDivM, - opGreater, opLess, opGreaterEq, opLessEq, opEq, opNotEq), - Values(CV_8UC1, CV_16SC1, CV_32FC1), + Combine(Values(CV_8UC1, CV_16SC1, CV_32FC1), Values(cv::Size(1280, 720), - cv::Size(640, 480), - cv::Size(128, 128)), + cv::Size(640, 480), + cv::Size(128, 128)), Values(-1, CV_8U, CV_32F), -/*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_GPU)))); + testing::Bool(), + Values(CORE_GPU), + Values(Tolerance_FloatRel_IntAbs(1e-5, 2).to_compare_f()), + Values( opPlusM, opMinusM, opDivM, + opGreater, opLess, opGreaterEq, opLessEq, opEq, opNotEq))); INSTANTIATE_TEST_CASE_P(MathOperatorTestGPU, MathOperatorMatScalarTest, - Combine(Values(Tolerance_FloatRel_IntAbs(1e-4, 2).to_compare_f()), - Values( opPlus, opPlusR, opMinus, opMinusR, opMul, opMulR, // FIXIT avoid division by values near zero: opDiv, opDivR, - opGT, opLT, opGE, opLE, opEQ, opNE, - opGTR, opLTR, opGER, opLER, opEQR, opNER), - Values(CV_8UC1, CV_16SC1, CV_32FC1), + Combine(Values(CV_8UC1, CV_16SC1, CV_32FC1), Values(cv::Size(1280, 720), cv::Size(640, 480), cv::Size(128, 128)), Values(-1, CV_8U, CV_32F), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_GPU)))); + Values(CORE_GPU), + Values(Tolerance_FloatRel_IntAbs(1e-4, 2).to_compare_f()), + Values( opPlus, opPlusR, opMinus, opMinusR, opMul, opMulR, // FIXIT avoid division by values near zero: opDiv, opDivR, + opGT, opLT, opGE, opLE, opEQ, opNE, + opGTR, opLTR, opGER, opLER, opEQR, opNER))); INSTANTIATE_TEST_CASE_P(BitwiseOperatorTestGPU, MathOperatorMatMatTest, - Combine(Values(AbsExact().to_compare_f()), - Values( opAnd, opOr, opXor ), - Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(cv::Size(1280, 720), - cv::Size(640, 480), - cv::Size(128, 128)), + cv::Size(640, 480), + cv::Size(128, 128)), Values(-1), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_GPU)))); + Values(CORE_GPU), + Values(AbsExact().to_compare_f()), + Values( opAnd, opOr, opXor ))); INSTANTIATE_TEST_CASE_P(BitwiseOperatorTestGPU, MathOperatorMatScalarTest, - Combine(Values(AbsExact().to_compare_f()), - Values( opAND, opOR, opXOR, opANDR, opORR, opXORR ), - Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(cv::Size(1280, 720), cv::Size(640, 480), cv::Size(128, 128)), Values(-1), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_GPU)))); + Values(CORE_GPU), + Values(AbsExact().to_compare_f()), + Values( opAND, opOR, opXOR, opANDR, opORR, opXORR ))); INSTANTIATE_TEST_CASE_P(BitwiseNotOperatorTestGPU, NotOperatorTest, Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(cv::Size(1280, 720), cv::Size(640, 480), cv::Size(128, 128)), + Values(SAME_TYPE), /*init output matrices or not*/ testing::Bool(), - Values(cv::compile_args(CORE_GPU)))); + Values(CORE_GPU))); }