Async API for GAPI
- minor cosmetic changes : comments, typos
This commit is contained in:
@@ -14,20 +14,22 @@
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
struct SumOfSum{
|
||||
//Main idea behind these tests is to have the same test script that is parameterized in order to test all setups (GCompiled vs apply, callback vs future).
|
||||
//So these differences are factored into devoted helper classes (mixins) which are then used by the common test script by help of CRTP.
|
||||
//Actual GAPI Computation with parameters to run on is mixed into test via CRTP as well.
|
||||
|
||||
struct SumOfSum2x2 {
|
||||
cv::GComputation sum_of_sum;
|
||||
SumOfSum() : sum_of_sum([]{
|
||||
SumOfSum2x2() : sum_of_sum([]{
|
||||
cv::GMat in;
|
||||
cv::GScalar out = cv::gapi::sum(in + in);
|
||||
return GComputation{in, out};
|
||||
})
|
||||
{}
|
||||
};
|
||||
|
||||
struct SumOfSum2x2 : SumOfSum {
|
||||
const cv::Size sz{2, 2};
|
||||
cv::Mat in_mat{sz, CV_8U, cv::Scalar(1)};
|
||||
cv::Scalar out;
|
||||
cv::Scalar out_sc;
|
||||
|
||||
cv::GCompiled compile(){
|
||||
return sum_of_sum.compile(descr_of(in_mat));
|
||||
@@ -46,11 +48,11 @@ struct SumOfSum2x2 : SumOfSum {
|
||||
}
|
||||
|
||||
cv::GRunArgsP out_args(){
|
||||
return cv::gout(out);
|
||||
return cv::gout(out_sc);
|
||||
}
|
||||
|
||||
void verify(){
|
||||
EXPECT_EQ(8, out[0]);
|
||||
EXPECT_EQ(8, out_sc[0]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -78,7 +80,7 @@ namespace {
|
||||
};
|
||||
}
|
||||
|
||||
struct ExceptionOnExecution {
|
||||
struct ExceptionOnExecution {
|
||||
cv::GComputation throwing_gcomp;
|
||||
ExceptionOnExecution() : throwing_gcomp([]{
|
||||
cv::GMat in;
|
||||
@@ -124,6 +126,7 @@ struct crtp_cast {
|
||||
}
|
||||
};
|
||||
|
||||
//Test Mixin, hiding details of callback based notification
|
||||
template<typename crtp_final_t>
|
||||
struct CallBack: crtp_cast<crtp_final_t> {
|
||||
std::atomic<bool> callback_called = {false};
|
||||
@@ -158,6 +161,7 @@ struct CallBack: crtp_cast<crtp_final_t> {
|
||||
}
|
||||
};
|
||||
|
||||
//Test Mixin, hiding details of future based notification
|
||||
template<typename crtp_final_t>
|
||||
struct Future: crtp_cast<crtp_final_t> {
|
||||
std::future<void> f;
|
||||
@@ -173,7 +177,7 @@ struct Future: crtp_cast<crtp_final_t> {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//Test Mixin, hiding details of using compiled GAPI object
|
||||
template<typename crtp_final_t>
|
||||
struct AsyncCompiled : crtp_cast<crtp_final_t>{
|
||||
|
||||
@@ -184,6 +188,7 @@ struct AsyncCompiled : crtp_cast<crtp_final_t>{
|
||||
}
|
||||
};
|
||||
|
||||
//Test Mixin, hiding details of calling apply (async_apply) on GAPI Computation object
|
||||
template<typename crtp_final_t>
|
||||
struct AsyncApply : crtp_cast<crtp_final_t> {
|
||||
|
||||
@@ -200,6 +205,7 @@ struct normal: ::testing::Test, case_t{};
|
||||
TYPED_TEST_CASE_P(normal);
|
||||
|
||||
TYPED_TEST_P(normal, basic){
|
||||
//Normal scenario: start function asynchronously and wait for the result, and verify it
|
||||
this->start_async(this->in_args(), this->out_args());
|
||||
this->wait_for_result();
|
||||
|
||||
@@ -215,6 +221,7 @@ struct exception: ::testing::Test, case_t{};
|
||||
TYPED_TEST_CASE_P(exception);
|
||||
|
||||
TYPED_TEST_P(exception, basic){
|
||||
//Exceptional scenario: start function asynchronously and make sure exception is passed to the user
|
||||
this->start_async(this->in_args(), this->out_args());
|
||||
EXPECT_THROW(this->wait_for_result(), gthrow_exception);
|
||||
}
|
||||
@@ -228,6 +235,7 @@ struct stress : ::testing::Test{};
|
||||
TYPED_TEST_CASE_P(stress);
|
||||
|
||||
TYPED_TEST_P(stress, test){
|
||||
//Some stress testing: use a number of threads to start a bunch of async requests
|
||||
const std::size_t request_per_thread = 10;
|
||||
const std::size_t number_of_threads = 4;
|
||||
|
||||
@@ -254,6 +262,7 @@ TYPED_TEST_P(stress, test){
|
||||
}
|
||||
REGISTER_TYPED_TEST_CASE_P(stress, test);
|
||||
|
||||
//little helpers to match up all combinations of setups
|
||||
template<typename compute_fixture_t,template <typename> class callback_or_future_t, template <typename> class compiled_or_apply_t>
|
||||
struct Case
|
||||
: compute_fixture_t,
|
||||
|
||||
Reference in New Issue
Block a user