Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/gapi/test/internal/gapi_int_recompilation_test.cpp
16344 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
//
5
// Copyright (C) 2018 Intel Corporation
6
7
8
#include "test_precomp.hpp"
9
#include "api/gcomputation_priv.hpp"
10
11
namespace opencv_test
12
{
13
14
TEST(GComputationCompile, NoRecompileWithSameMeta)
15
{
16
cv::GMat in;
17
cv::GComputation cc(in, in+in);
18
19
cv::Mat in_mat1 = cv::Mat::eye (32, 32, CV_8UC1);
20
cv::Mat in_mat2 = cv::Mat::zeros(32, 32, CV_8UC1);
21
cv::Mat out_mat;
22
23
cc.apply(in_mat1, out_mat);
24
auto comp1 = cc.priv().m_lastCompiled;
25
26
cc.apply(in_mat2, out_mat);
27
auto comp2 = cc.priv().m_lastCompiled;
28
29
// Both compiled objects are actually the same unique executable
30
EXPECT_EQ(&comp1.priv(), &comp2.priv());
31
}
32
33
TEST(GComputationCompile, NoRecompileWithWrongMeta)
34
{
35
cv::GMat in;
36
cv::GComputation cc(in, in+in);
37
38
cv::Mat in_mat1 = cv::Mat::eye (32, 32, CV_8UC1);
39
cv::Mat in_mat2 = cv::Mat::zeros(32, 32, CV_8UC1);
40
cv::Mat out_mat;
41
42
cc.apply(in_mat1, out_mat);
43
auto comp1 = cc.priv().m_lastCompiled;
44
45
EXPECT_THROW(cc.apply(cv::gin(cv::Scalar(128)), cv::gout(out_mat)), std::logic_error);
46
auto comp2 = cc.priv().m_lastCompiled;
47
48
// Both compiled objects are actually the same unique executable
49
EXPECT_EQ(&comp1.priv(), &comp2.priv());
50
}
51
52
TEST(GComputationCompile, RecompileWithDifferentMeta)
53
{
54
cv::GMat in;
55
cv::GComputation cc(in, in+in);
56
57
cv::Mat in_mat1 = cv::Mat::eye (32, 32, CV_8UC1);
58
cv::Mat in_mat2 = cv::Mat::zeros(64, 64, CV_32F);
59
cv::Mat out_mat;
60
61
cc.apply(in_mat1, out_mat);
62
auto comp1 = cc.priv().m_lastCompiled;
63
64
cc.apply(in_mat2, out_mat);
65
auto comp2 = cc.priv().m_lastCompiled;
66
67
// Both compiled objects are different
68
EXPECT_NE(&comp1.priv(), &comp2.priv());
69
}
70
71
} // opencv_test
72
73