Skip to content

Commit

Permalink
[IE Myriad] Added MockICore to fix graph transformer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-kud committed Jul 17, 2020
1 parent 7b65736 commit 2ef870c
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (C) 2018-2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <gmock/gmock.h>
#include "ie_icore.hpp"

using namespace InferenceEngine;

class MockICore : public ICore {
public:
MOCK_QUALIFIED_METHOD0(GetTaskExecutor, const, std::shared_ptr<ITaskExecutor>());

MOCK_QUALIFIED_METHOD2(ReadNetwork, const, CNNNetwork(const std::string&, const Blob::CPtr&));
MOCK_QUALIFIED_METHOD2(ReadNetwork, const, CNNNetwork(const std::string&, const std::string&));

MOCK_METHOD3(LoadNetwork, ExecutableNetwork(
const CNNNetwork&, const std::string&, const std::map<std::string, std::string>&));

MOCK_METHOD3(ImportNetwork, ExecutableNetwork(
std::istream&, const std::string&, const std::map<std::string, std::string>&));

MOCK_QUALIFIED_METHOD3(QueryNetwork, const, QueryNetworkResult(
const ICNNNetwork&, const std::string&, const std::map<std::string, std::string>&));

MOCK_QUALIFIED_METHOD2(GetMetric, const, Parameter(const std::string&, const std::string&));

~MockICore() = default;
};
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void GraphTransformerTest::SetUp() {
consoleOutput());

stageBuilder = std::make_shared<StageBuilder>();
frontEnd = std::make_shared<FrontEnd>(stageBuilder);
frontEnd = std::make_shared<FrontEnd>(stageBuilder, &_mockCore);
backEnd = std::make_shared<BackEnd>();
passManager = std::make_shared<PassManager>(stageBuilder, backEnd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#pragma once

#include <list>

#include <gtest/gtest.h>

#include <vpu/compile_env.hpp>
#include <vpu/model/stage.hpp>
#include <vpu/model/model.hpp>
Expand All @@ -12,9 +16,7 @@
#include <vpu/backend/backend.hpp>
#include <vpu/utils/ie_helpers.hpp>

#include <gtest/gtest.h>

#include <list>
#include <unit_test_utils/mocks/cpp_interfaces/interface/mock_icore.hpp>

namespace vpu {

Expand Down Expand Up @@ -144,6 +146,7 @@ class GraphTransformerTest : public ::testing::Test {
TestModel CreateTestModel();

private:
MockICore _mockCore;
Logger::Ptr _log;
std::list<ModelPtr> _models;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <ngraph/op/util/attr_types.hpp>
#include <ngraph_functions/subgraph_builders.hpp>

#include <mock_icore.hpp>

using namespace ::testing;
using namespace vpu;
using namespace InferenceEngine;
Expand Down Expand Up @@ -50,11 +52,12 @@ class VPUBlobReaderHeaderTests: public TestsCommon, public testing::WithParamInt

CompilationConfig compileConfig;
auto log = std::make_shared<Logger>("GraphCompiler", LogLevel::None, consoleOutput());
_compiledGraph = compileNetwork(_network, Platform::MYRIAD_X, compileConfig, log);
_compiledGraph = compileNetwork(_network, Platform::MYRIAD_X, compileConfig, log, &_mockCore);
}

CNNNetwork _network;
CompiledGraph::Ptr _compiledGraph;
MockICore _mockCore;
};

TEST_P(VPUBlobReaderHeaderTests, canReadCorrectMagicNumber) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "gt_functional_tests.hpp"

#include <functional_test_utils/plugin_cache.hpp>
#include <vpu/utils/logger.hpp>
#include <vpu/compile_env.hpp>
#include <vpu/graph_transformer_internal.hpp>
Expand All @@ -19,7 +20,7 @@ void graphTransformerFunctionalTests::SetUp() {
vpuLayersTests::SetUp();

_stageBuilder = std::make_shared<StageBuilder>();
_frontEnd = std::make_shared<FrontEnd>(_stageBuilder);
_frontEnd = std::make_shared<FrontEnd>(_stageBuilder, &_mockCore);
_backEnd = std::make_shared<BackEnd>();
_passManager = std::make_shared<PassManager>(_stageBuilder, _backEnd);
_platform = CheckMyriadX() ? Platform::MYRIAD_X : Platform::MYRIAD_2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <vpu/middleend/pass_manager.hpp>
#include <vpu/frontend/frontend.hpp>
#include "mock_icore.hpp"

class graphTransformerFunctionalTests : public vpuLayersTests {
protected:
Expand All @@ -29,6 +30,7 @@ class graphTransformerFunctionalTests : public vpuLayersTests {
vpu::CompilationConfig _compilationConfig;
vpu::StageBuilder::Ptr _stageBuilder;
vpu::Data _dataIntermediate;
MockICore _mockCore;

private:
vpu::Platform _platform = vpu::Platform::MYRIAD_X;
Expand Down
4 changes: 2 additions & 2 deletions inference-engine/tests_deprecated/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ endfunction()

add_helpers(${TARGET_NAME})

target_link_libraries(${TARGET_NAME} PUBLIC commonTestUtils)
target_link_libraries(${TARGET_NAME} PUBLIC commonTestUtils gmock gtest)

add_helpers(${TARGET_NAME}_s USE_STATIC_IE)

target_link_libraries(${TARGET_NAME}_s PUBLIC commonTestUtils_s)
target_link_libraries(${TARGET_NAME}_s PUBLIC commonTestUtils_s gmock gtest)

if (ENABLE_DATA)
add_dependencies(${TARGET_NAME} data)
Expand Down
31 changes: 31 additions & 0 deletions inference-engine/tests_deprecated/helpers/mock_icore.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (C) 2018-2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <gmock/gmock.h>
#include "ie_icore.hpp"

using namespace InferenceEngine;

class MockICore : public ICore {
public:
MOCK_QUALIFIED_METHOD0(GetTaskExecutor, const, std::shared_ptr<ITaskExecutor>());

MOCK_QUALIFIED_METHOD2(ReadNetwork, const, CNNNetwork(const std::string&, const Blob::CPtr&));
MOCK_QUALIFIED_METHOD2(ReadNetwork, const, CNNNetwork(const std::string&, const std::string&));

MOCK_METHOD3(LoadNetwork, ExecutableNetwork(
const CNNNetwork&, const std::string&, const std::map<std::string, std::string>&));

MOCK_METHOD3(ImportNetwork, ExecutableNetwork(
std::istream&, const std::string&, const std::map<std::string, std::string>&));

MOCK_QUALIFIED_METHOD3(QueryNetwork, const, QueryNetworkResult(
const ICNNNetwork&, const std::string&, const std::map<std::string, std::string>&));

MOCK_QUALIFIED_METHOD2(GetMetric, const, Parameter(const std::string&, const std::string&));

~MockICore() = default;
};
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void GraphTransformerTest::SetUp() {
consoleOutput());

stageBuilder = std::make_shared<StageBuilder>();
frontEnd = std::make_shared<FrontEnd>(stageBuilder);
frontEnd = std::make_shared<FrontEnd>(stageBuilder, &_mockCore);
backEnd = std::make_shared<BackEnd>();
passManager = std::make_shared<PassManager>(stageBuilder, backEnd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <vpu/middleend/pass_manager.hpp>
#include <vpu/backend/backend.hpp>

#include "mock_icore.h"

namespace vpu {

template <class Cont, class Cond>
Expand Down Expand Up @@ -196,6 +198,7 @@ class GraphTransformerTest : public TestsCommon {
TestModel CreateTestModel(const DataDesc& dataDesc);

private:
MockICore _mockCore;
Logger::Ptr _log;
std::list<ModelPtr> _models;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2018-2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <gmock/gmock.h>
#include "ie_icore.hpp"

class MockICore : public InferenceEngine::ICore {
public:
MOCK_QUALIFIED_METHOD0(GetTaskExecutor, const, std::shared_ptr<InferenceEngine::ITaskExecutor>());

MOCK_QUALIFIED_METHOD2(ReadNetwork, const, InferenceEngine::CNNNetwork(const std::string&, const InferenceEngine::Blob::CPtr&));
MOCK_QUALIFIED_METHOD2(ReadNetwork, const, InferenceEngine::CNNNetwork(const std::string&, const std::string&));

MOCK_METHOD3(LoadNetwork, InferenceEngine::ExecutableNetwork(
const InferenceEngine::CNNNetwork&, const std::string&, const std::map<std::string, std::string>&));

MOCK_METHOD3(ImportNetwork, InferenceEngine::ExecutableNetwork(
std::istream&, const std::string&, const std::map<std::string, std::string>&));

MOCK_QUALIFIED_METHOD3(QueryNetwork, const, InferenceEngine::QueryNetworkResult(
const InferenceEngine::ICNNNetwork&, const std::string&, const std::map<std::string, std::string>&));

MOCK_QUALIFIED_METHOD2(GetMetric, const, InferenceEngine::Parameter(const std::string&, const std::string&));

~MockICore() = default;
};

0 comments on commit 2ef870c

Please sign in to comment.