Skip to content

Commit

Permalink
Fixed creation of C++ wrappers from old API (openvinotoolkit#5805)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov authored and yekruglov committed Jun 7, 2021
1 parent 8d7411f commit ce81838
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace InferenceEngine {

#define EXEC_NET_CALL_STATEMENT(...) \
if (_impl == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; \
if (_impl == nullptr) IE_THROW(NotAllocated) << "ExecutableNetwork was not initialized."; \
try { \
__VA_ARGS__; \
} catch(...) {details::Rethrow();}
Expand All @@ -27,10 +27,14 @@ IE_SUPPRESS_DEPRECATED_START

ExecutableNetwork::ExecutableNetwork(IExecutableNetwork::Ptr exec,
std::shared_ptr<details::SharedObjectLoader> splg)
: _so(*splg), _impl(), actual(exec) {
: _so(), _impl(), actual(exec) {
if (splg) {
_so = *splg;
}

// plg can be null, but not the actual
if (actual == nullptr)
IE_THROW() << "ExecutableNetwork was not initialized.";
IE_THROW(NotAllocated) << "ExecutableNetwork was not initialized.";
}

ConstOutputsDataMap ExecutableNetwork::GetOutputsInfo() const {
Expand Down
10 changes: 7 additions & 3 deletions inference-engine/src/inference_engine/cpp/ie_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace InferenceEngine {

#define INFER_REQ_CALL_STATEMENT(...) \
if (_impl == nullptr) IE_THROW() << "Inference Request is not initialized"; \
if (_impl == nullptr) IE_THROW(NotAllocated) << "Inference Request is not initialized"; \
try { \
__VA_ARGS__ \
} catch(...) {details::Rethrow();}
Expand All @@ -31,10 +31,14 @@ IE_SUPPRESS_DEPRECATED_START

InferRequest::InferRequest(IInferRequest::Ptr request,
std::shared_ptr<details::SharedObjectLoader> splg)
: _so(*splg), _impl(), actual(request) {
: _so(), _impl(), actual(request) {
if (splg) {
_so = *splg;
}

// plg can be null, but not the actual
if (actual == nullptr)
IE_THROW() << "InferRequest was not initialized.";
IE_THROW(NotAllocated) << "InferRequest was not initialized.";
}

void InferRequest::SetBlob(const std::string& name, const Blob::Ptr& data) {
Expand Down
10 changes: 7 additions & 3 deletions inference-engine/src/inference_engine/cpp/ie_variable_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "exception2status.hpp"

#define VARIABLE_CALL_STATEMENT(...) \
if (_impl == nullptr) IE_THROW() << "VariableState was not initialized."; \
if (_impl == nullptr) IE_THROW(NotAllocated) << "VariableState was not initialized."; \
try { \
__VA_ARGS__; \
} catch(...) {details::Rethrow();}
Expand All @@ -26,10 +26,14 @@ IE_SUPPRESS_DEPRECATED_START

VariableState::VariableState(std::shared_ptr<IVariableState> state,
std::shared_ptr<details::SharedObjectLoader> splg)
: _so(*splg), _impl(), actual(state) {
: _so(), _impl(), actual(state) {
if (splg) {
_so = *splg;
}

// plg can be null, but not the actual
if (actual == nullptr)
IE_THROW() << "VariableState was not initialized.";
IE_THROW(NotAllocated) << "VariableState was not initialized.";
}

Blob::CPtr VariableState::GetLastState() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,84 +5,98 @@
#include <gtest/gtest.h>

#include <cpp/ie_infer_request.hpp>
#include "unit_test_utils/mocks/mock_iinfer_request.hpp"

using namespace ::testing;
using namespace std;
using namespace InferenceEngine;
using namespace InferenceEngine::details;

IE_SUPPRESS_DEPRECATED_START

TEST(InferRequestCPPTests, throwsOnUninitialized) {
std::shared_ptr<IInferRequest> ptr;
ASSERT_THROW(InferRequest req(ptr), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, nothrowOnInitialized) {
std::shared_ptr<IInferRequest> ptr = std::make_shared<MockIInferRequest>();
ASSERT_NO_THROW(InferRequest req(ptr));
}

IE_SUPPRESS_DEPRECATED_END

TEST(InferRequestCPPTests, throwsOnUninitializedSetBlob) {
InferRequest req;
ASSERT_THROW(req.SetBlob({}, {}), InferenceEngine::Exception);
ASSERT_THROW(req.SetBlob({}, {}), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, throwsOnUninitializedGetBlob) {
InferRequest req;
ASSERT_THROW(req.GetBlob({}), InferenceEngine::Exception);
ASSERT_THROW(req.GetBlob({}), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, throwsOnUninitializedSetBlobPreproc) {
InferRequest req;
ASSERT_THROW(req.SetBlob({}, {}, {}), InferenceEngine::Exception);
ASSERT_THROW(req.SetBlob({}, {}, {}), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, throwsOnUninitializedGetPreProcess) {
InferRequest req;
ASSERT_THROW(req.GetPreProcess({}), InferenceEngine::Exception);
ASSERT_THROW(req.GetPreProcess({}), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, throwsOnUninitializedInfer) {
InferRequest req;
ASSERT_THROW(req.Infer(), InferenceEngine::Exception);
ASSERT_THROW(req.Infer(), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, throwsOnUninitializedGetPerformanceCounts) {
InferRequest req;
ASSERT_THROW(req.GetPerformanceCounts(), InferenceEngine::Exception);
ASSERT_THROW(req.GetPerformanceCounts(), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, throwsOnUninitializedSetInput) {
InferRequest req;
ASSERT_THROW(req.SetInput({{}}), InferenceEngine::Exception);
ASSERT_THROW(req.SetInput({{}}), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, throwsOnUninitializedSetOutput) {
InferRequest req;
ASSERT_THROW(req.SetOutput({{}}), InferenceEngine::Exception);
ASSERT_THROW(req.SetOutput({{}}), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, throwsOnUninitializedSetBatch) {
InferRequest req;
ASSERT_THROW(req.SetBatch({}), InferenceEngine::Exception);
ASSERT_THROW(req.SetBatch({}), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, throwsOnUninitializedStartAsync) {
InferRequest req;
ASSERT_THROW(req.StartAsync(), InferenceEngine::Exception);
ASSERT_THROW(req.StartAsync(), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, throwsOnUninitializedWait) {
InferRequest req;
ASSERT_THROW(req.Wait({}), InferenceEngine::Exception);
ASSERT_THROW(req.Wait({}), InferenceEngine::NotAllocated);
}

TEST(InferRequestCPPTests, throwsOnUninitializedSetCompletionCallback) {
InferRequest req;
std::function<void(InferRequest, StatusCode)> f;
ASSERT_THROW(req.SetCompletionCallback(f), InferenceEngine::Exception);
ASSERT_THROW(req.SetCompletionCallback(f), InferenceEngine::NotAllocated);
}

IE_SUPPRESS_DEPRECATED_START

TEST(InferRequestCPPTests, throwsOnUninitializedCast) {
InferRequest req;
ASSERT_THROW((void)static_cast<IInferRequest::Ptr>(req), InferenceEngine::Exception);
ASSERT_THROW((void)static_cast<IInferRequest::Ptr>(req), InferenceEngine::NotAllocated);
}

IE_SUPPRESS_DEPRECATED_END

TEST(InferRequestCPPTests, throwsOnUninitializedQueryState) {
InferRequest req;
ASSERT_THROW(req.QueryState(), InferenceEngine::Exception);
ASSERT_THROW(req.QueryState(), InferenceEngine::NotAllocated);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@

#include <gtest/gtest.h>
#include <cpp/ie_executable_network.hpp>
#include "unit_test_utils/mocks/mock_iexecutable_network.hpp"

using namespace ::testing;
using namespace std;
using namespace InferenceEngine;
using namespace InferenceEngine::details;

IE_SUPPRESS_DEPRECATED_START

TEST(ExecutableNetworkTests, throwsOnUninitialized) {
std::shared_ptr<IExecutableNetwork> ptr;
ASSERT_THROW(ExecutableNetwork req(ptr), InferenceEngine::NotAllocated);
}

TEST(ExecutableNetworkTests, nothrowOnInitialized) {
std::shared_ptr<IExecutableNetwork> ptr = std::make_shared<MockIExecutableNetwork>();
ASSERT_NO_THROW(ExecutableNetwork req(ptr));
}

IE_SUPPRESS_DEPRECATED_END

TEST(ExecutableNetworkTests, throwsOnUninitializedGetOutputsInfo) {
ExecutableNetwork exec;
ASSERT_THROW(exec.GetOutputsInfo(), InferenceEngine::Exception);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <gtest/gtest.h>

#include <cpp/ie_infer_request.hpp>
#include "unit_test_utils/mocks/mock_ie_ivariable_state.hpp"

using namespace ::testing;
using namespace std;
using namespace InferenceEngine;
using namespace InferenceEngine::details;

IE_SUPPRESS_DEPRECATED_START

TEST(VariableStateCPPTests, throwsOnUninitialized) {
std::shared_ptr<IVariableState> ptr;
ASSERT_THROW(VariableState var(ptr), InferenceEngine::NotAllocated);
}

TEST(VariableStateCPPTests, nothrowOnInitialized) {
std::shared_ptr<IVariableState> ptr = std::make_shared<MockIVariableState>();
ASSERT_NO_THROW(VariableState var(ptr));
}

TEST(VariableStateCPPTests, throwsOnUninitializedGetLastState) {
VariableState req;
ASSERT_THROW(req.GetLastState(), InferenceEngine::NotAllocated);
}

IE_SUPPRESS_DEPRECATED_END

TEST(VariableStateCPPTests, throwsOnUninitializedReset) {
VariableState req;
ASSERT_THROW(req.Reset(), InferenceEngine::NotAllocated);
}

TEST(VariableStateCPPTests, throwsOnUninitializedGetname) {
VariableState req;
ASSERT_THROW(req.GetName(), InferenceEngine::NotAllocated);
}

TEST(VariableStateCPPTests, throwsOnUninitializedGetState) {
VariableState req;
ASSERT_THROW(req.GetState(), InferenceEngine::NotAllocated);
}

TEST(VariableStateCPPTests, throwsOnUninitializedSetState) {
VariableState req;
Blob::Ptr blob;
ASSERT_THROW(req.SetState(blob), InferenceEngine::NotAllocated);
}

0 comments on commit ce81838

Please sign in to comment.