Path: blob/master/modules/gapi/test/internal/gapi_int_backend_tests.cpp
16345 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3//4// Copyright (C) 2018 Intel Corporation567#include "test_precomp.hpp"8#include "gapi_mock_kernels.hpp"910#include "compiler/gmodel.hpp"11#include "compiler/gcompiler.hpp"1213namespace opencv_test {1415namespace {1617struct MockMeta18{19static const char* name() { return "MockMeta"; }20};2122class GMockBackendImpl final: public cv::gapi::GBackend::Priv23{24virtual void unpackKernel(ade::Graph &,25const ade::NodeHandle &,26const cv::GKernelImpl &) override27{28// Do nothing here29}3031virtual EPtr compile(const ade::Graph &,32const cv::GCompileArgs &,33const std::vector<ade::NodeHandle> &) const override34{35// Do nothing here as well36return {};37}3839virtual void addBackendPasses(ade::ExecutionEngineSetupContext &ectx) override40{41ectx.addPass("transform", "set_mock_meta", [](ade::passes::PassContext &ctx) {42ade::TypedGraph<MockMeta> me(ctx.graph);43for (const auto &nh : me.nodes())44{45me.metadata(nh).set(MockMeta{});46}47});48}49};5051static cv::gapi::GBackend mock_backend(std::make_shared<GMockBackendImpl>());5253GAPI_OCV_KERNEL(MockFoo, I::Foo)54{55static void run(const cv::Mat &, cv::Mat &) { /*Do nothing*/ }56static cv::gapi::GBackend backend() { return mock_backend; } // FIXME: Must be removed57};5859} // anonymous namespace6061TEST(GBackend, CustomPassesExecuted)62{63cv::GMat in;64cv::GMat out = I::Foo::on(in);65cv::GComputation c(in, out);6667// Prepare compilation parameters manually68const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::Size(32,32)});69const auto pkg = cv::gapi::kernels<MockFoo>();7071// Directly instantiate G-API graph compiler and run partial compilation72cv::gimpl::GCompiler compiler(c, {in_meta}, cv::compile_args(pkg));73cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();74compiler.runPasses(*graph);7576// Inspect the graph and verify the metadata written by Mock backend77ade::TypedGraph<MockMeta> me(*graph);78EXPECT_LT(0u, static_cast<std::size_t>(me.nodes().size()));79for (const auto &nh : me.nodes())80{81EXPECT_TRUE(me.metadata(nh).contains<MockMeta>());82}83}8485} // namespace opencv_test868788