diff --git a/src/inference/tests/functional/CMakeLists.txt b/src/inference/tests/functional/CMakeLists.txt index 9e57a7b7959..3d8fff5339b 100644 --- a/src/inference/tests/functional/CMakeLists.txt +++ b/src/inference/tests/functional/CMakeLists.txt @@ -64,6 +64,7 @@ ov_add_test_target( funcTestUtils INCLUDES $/src + ADD_CLANG_FORMAT LABELS OV ) diff --git a/src/inference/tests/functional/async_infer_request_test.cpp b/src/inference/tests/functional/async_infer_request_test.cpp index 06a913506d7..27caea81331 100644 --- a/src/inference/tests/functional/async_infer_request_test.cpp +++ b/src/inference/tests/functional/async_infer_request_test.cpp @@ -11,7 +11,6 @@ using namespace std; using namespace InferenceEngine; using namespace InferenceEngine::details; - TEST(InferRequestCPPTests, throwsOnUninitializedSetBlob) { InferRequest req; ASSERT_THROW(req.SetBlob({}, {}), InferenceEngine::NotAllocated); diff --git a/src/inference/tests/functional/blob_copy_test.cpp b/src/inference/tests/functional/blob_copy_test.cpp index a5fa12286df..1aac2b7840a 100644 --- a/src/inference/tests/functional/blob_copy_test.cpp +++ b/src/inference/tests/functional/blob_copy_test.cpp @@ -3,12 +3,11 @@ // #include - -#include -#include - #include + #include +#include +#include using namespace ::testing; using namespace InferenceEngine; @@ -16,61 +15,64 @@ using namespace InferenceEngine; using ChannelNum = size_t; using BatchNum = size_t; using PrecisionType = InferenceEngine::Precision::ePrecision; -using IsInterleaved = bool; // true = interleaved, false = deinterleaved. -using Dims = std::vector; // dimensions are in the form of (N x C x D1 x D2 ... Dn), so Dims is vector (D1 x D2 ... Dn) +using IsInterleaved = bool; // true = interleaved, false = deinterleaved. +using Dims = + std::vector; // dimensions are in the form of (N x C x D1 x D2 ... Dn), so Dims is vector (D1 x D2 ... Dn) namespace { InferenceEngine::Layout setLayout(IsInterleaved isInterleaved, int dimsSize) { if (dimsSize == 3) { - return (isInterleaved) ? InferenceEngine::Layout::NDHWC : InferenceEngine::Layout::NCDHW; + return (isInterleaved) ? InferenceEngine::Layout::NDHWC : InferenceEngine::Layout::NCDHW; } else if (dimsSize == 2) { - return (isInterleaved) ? InferenceEngine::Layout::NHWC : InferenceEngine::Layout::NCHW; + return (isInterleaved) ? InferenceEngine::Layout::NHWC : InferenceEngine::Layout::NCHW; } IE_THROW() << "Can't set layout"; } // Support only for 4d and 5d blobs -SizeVector SetDimVector(BatchNum batchNum, ChannelNum channelNum, Dims dims) { +SizeVector SetDimVector(BatchNum batchNum, ChannelNum channelNum, Dims dims) { if (dims.size() == 2) { - return SizeVector{ batchNum, channelNum, dims[0], dims[1] }; + return SizeVector{batchNum, channelNum, dims[0], dims[1]}; } else if (dims.size() == 3) { - return SizeVector{ batchNum, channelNum, dims[0], dims[1], dims[2] }; + return SizeVector{batchNum, channelNum, dims[0], dims[1], dims[2]}; } IE_THROW() << "Can't set dimVector"; } // For FP16 and Q78 precision we use int16_t type -InferenceEngine::Blob::Ptr createBlob(InferenceEngine::Precision precision, SizeVector dimsVector, InferenceEngine::Layout layout) { +InferenceEngine::Blob::Ptr createBlob(InferenceEngine::Precision precision, + SizeVector dimsVector, + InferenceEngine::Layout layout) { InferenceEngine::TensorDesc tensorDesc(precision, dimsVector, layout); switch (precision) { - case InferenceEngine::Precision::FP32: - return make_shared_blob(tensorDesc); - case InferenceEngine::Precision::FP64: - return make_shared_blob(tensorDesc); - case InferenceEngine::Precision::FP16: - case InferenceEngine::Precision::I16: - case InferenceEngine::Precision::Q78: - return make_shared_blob(tensorDesc); - case InferenceEngine::Precision::I32: - return make_shared_blob(tensorDesc); - case InferenceEngine::Precision::U32: - return make_shared_blob(tensorDesc); - case InferenceEngine::Precision::I64: - return make_shared_blob(tensorDesc); - case InferenceEngine::Precision::U64: - return make_shared_blob(tensorDesc); - case InferenceEngine::Precision::U16: - return make_shared_blob(tensorDesc); - case InferenceEngine::Precision::I4: - case InferenceEngine::Precision::I8: - case InferenceEngine::Precision::BIN: - return make_shared_blob(tensorDesc); - case InferenceEngine::Precision::U4: - case InferenceEngine::Precision::U8: - return make_shared_blob(tensorDesc); - default: - IE_THROW() << "Unsupported precision"; + case InferenceEngine::Precision::FP32: + return make_shared_blob(tensorDesc); + case InferenceEngine::Precision::FP64: + return make_shared_blob(tensorDesc); + case InferenceEngine::Precision::FP16: + case InferenceEngine::Precision::I16: + case InferenceEngine::Precision::Q78: + return make_shared_blob(tensorDesc); + case InferenceEngine::Precision::I32: + return make_shared_blob(tensorDesc); + case InferenceEngine::Precision::U32: + return make_shared_blob(tensorDesc); + case InferenceEngine::Precision::I64: + return make_shared_blob(tensorDesc); + case InferenceEngine::Precision::U64: + return make_shared_blob(tensorDesc); + case InferenceEngine::Precision::U16: + return make_shared_blob(tensorDesc); + case InferenceEngine::Precision::I4: + case InferenceEngine::Precision::I8: + case InferenceEngine::Precision::BIN: + return make_shared_blob(tensorDesc); + case InferenceEngine::Precision::U4: + case InferenceEngine::Precision::U8: + return make_shared_blob(tensorDesc); + default: + IE_THROW() << "Unsupported precision"; } } @@ -87,30 +89,32 @@ size_t GenerateRandom(size_t elem) { // dims is the blob shape, e.g. {1, 3, 640, 480} // random index[i] lays between 0 and dims[i]-1 SizeVector GenerateRandomVector(SizeVector dims) { - SizeVector idx(dims.size()); + SizeVector idx(dims.size()); - for (auto i = 0; i < dims.size(); ++i) { - idx[i] = GenerateRandom(dims[i]); - } - return idx; + for (auto i = 0; i < dims.size(); ++i) { + idx[i] = GenerateRandom(dims[i]); + } + return idx; } - -void PrintParams(InferenceEngine::Layout layout, SizeVector dims, std::string blobType, InferenceEngine::Precision precision) { - std::cout < 0 ? ", ": "") << dims[i]; +void PrintParams(InferenceEngine::Layout layout, + SizeVector dims, + std::string blobType, + InferenceEngine::Precision precision) { + std::cout << blobType << "Blob params: " << layout << ", precision: " << precision << ", dims: {"; + for (int i = 0; i < dims.size(); i++) { + std::cout << (i > 0 ? ", " : "") << dims[i]; } std::cout << "}" << std::endl; } // For FP16 and Q78 precision we use int16_t type -template +template void FillBlobRandom(Blob::Ptr& inputBlob) { srand(1); auto inputBlobData = inputBlob->buffer().as(); for (size_t i = 0; i < inputBlob->size(); i++) { - inputBlobData[i] = (T) (GenerateRandom(RAND_MAX) / static_cast(RAND_MAX) * 100); + inputBlobData[i] = (T)(GenerateRandom(RAND_MAX) / static_cast(RAND_MAX) * 100); } } @@ -118,37 +122,36 @@ void FillBlobRandom(Blob::Ptr& inputBlob) { void FillBlob(Blob::Ptr& inputBlob) { auto precision = inputBlob->getTensorDesc().getPrecision(); switch (precision) { - case InferenceEngine::Precision::FP32: - return FillBlobRandom(inputBlob); - case InferenceEngine::Precision::FP64: - return FillBlobRandom(inputBlob); - case InferenceEngine::Precision::FP16: - case InferenceEngine::Precision::I16: - case InferenceEngine::Precision::Q78: - return FillBlobRandom(inputBlob); - case InferenceEngine::Precision::I32: - return FillBlobRandom(inputBlob); - case InferenceEngine::Precision::U32: - return FillBlobRandom(inputBlob); - case InferenceEngine::Precision::I64: - return FillBlobRandom(inputBlob); - case InferenceEngine::Precision::U64: - return FillBlobRandom(inputBlob); - case InferenceEngine::Precision::U16: - return FillBlobRandom(inputBlob); - case InferenceEngine::Precision::I4: - case InferenceEngine::Precision::I8: - case InferenceEngine::Precision::BIN: - return FillBlobRandom(inputBlob); - case InferenceEngine::Precision::U4: - case InferenceEngine::Precision::U8: - return FillBlobRandom(inputBlob); - default: - IE_THROW() << "Cant fill blob with \"" << precision << "\" precision\n"; + case InferenceEngine::Precision::FP32: + return FillBlobRandom(inputBlob); + case InferenceEngine::Precision::FP64: + return FillBlobRandom(inputBlob); + case InferenceEngine::Precision::FP16: + case InferenceEngine::Precision::I16: + case InferenceEngine::Precision::Q78: + return FillBlobRandom(inputBlob); + case InferenceEngine::Precision::I32: + return FillBlobRandom(inputBlob); + case InferenceEngine::Precision::U32: + return FillBlobRandom(inputBlob); + case InferenceEngine::Precision::I64: + return FillBlobRandom(inputBlob); + case InferenceEngine::Precision::U64: + return FillBlobRandom(inputBlob); + case InferenceEngine::Precision::U16: + return FillBlobRandom(inputBlob); + case InferenceEngine::Precision::I4: + case InferenceEngine::Precision::I8: + case InferenceEngine::Precision::BIN: + return FillBlobRandom(inputBlob); + case InferenceEngine::Precision::U4: + case InferenceEngine::Precision::U8: + return FillBlobRandom(inputBlob); + default: + IE_THROW() << "Cant fill blob with \"" << precision << "\" precision\n"; } } - template T GetElem(Blob::Ptr& blob, SizeVector idx) { T* src = blob->buffer().as() + blob->getTensorDesc().getBlockingDesc().getOffsetPadding(); @@ -188,17 +191,17 @@ bool IsCorrectBlobCopy_Impl(Blob::Ptr& srcBlob, Blob::Ptr& dstBlob) { EXPECT_TRUE(srcBlob->size() == dstBlob->size()); int experimentsNum = SetExperimentsNum(srcBlob->size()); int errorsCount = 0; - for ( ; experimentsNum > 0; --experimentsNum) { + for (; experimentsNum > 0; --experimentsNum) { SizeVector randomElemIdx = GenerateRandomVector(srcBlob->getTensorDesc().getDims()); auto srcElem = GetElem(srcBlob, randomElemIdx); auto dstElem = GetElem(dstBlob, randomElemIdx); if (srcElem != dstElem) { - if (errorsCount < 10) { - errorsCount++; - std::cout << "ERROR: srcElem = " << srcElem << ", dstElem = " << dstElem << std::endl; - } else { - errorsCount++; - } + if (errorsCount < 10) { + errorsCount++; + std::cout << "ERROR: srcElem = " << srcElem << ", dstElem = " << dstElem << std::endl; + } else { + errorsCount++; + } } } if (errorsCount > 0) { @@ -207,42 +210,42 @@ bool IsCorrectBlobCopy_Impl(Blob::Ptr& srcBlob, Blob::Ptr& dstBlob) { return errorsCount == 0; } - bool IsCorrectBlobCopy(Blob::Ptr& srcBlob, Blob::Ptr& dstBlob) { switch (srcBlob->getTensorDesc().getPrecision()) { - case InferenceEngine::Precision::FP32: - return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); - case InferenceEngine::Precision::FP64: - return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); - case InferenceEngine::Precision::FP16: - case InferenceEngine::Precision::I16: - case InferenceEngine::Precision::Q78: - return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); - case InferenceEngine::Precision::I32: - return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); - case InferenceEngine::Precision::U32: - return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); - case InferenceEngine::Precision::I64: - return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); - case InferenceEngine::Precision::U64: - return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); - case InferenceEngine::Precision::U16: - return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); - case InferenceEngine::Precision::I4: - case InferenceEngine::Precision::I8: - case InferenceEngine::Precision::BIN: - return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); - case InferenceEngine::Precision::U4: - case InferenceEngine::Precision::U8: - return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); - default: - return false; + case InferenceEngine::Precision::FP32: + return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); + case InferenceEngine::Precision::FP64: + return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); + case InferenceEngine::Precision::FP16: + case InferenceEngine::Precision::I16: + case InferenceEngine::Precision::Q78: + return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); + case InferenceEngine::Precision::I32: + return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); + case InferenceEngine::Precision::U32: + return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); + case InferenceEngine::Precision::I64: + return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); + case InferenceEngine::Precision::U64: + return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); + case InferenceEngine::Precision::U16: + return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); + case InferenceEngine::Precision::I4: + case InferenceEngine::Precision::I8: + case InferenceEngine::Precision::BIN: + return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); + case InferenceEngine::Precision::U4: + case InferenceEngine::Precision::U8: + return IsCorrectBlobCopy_Impl(srcBlob, dstBlob); + default: + return false; } } } // namespace -using BlobCopyTest = ::testing::TestWithParam >; +using BlobCopyTest = + ::testing::TestWithParam>; TEST_P(BlobCopyTest, BlobCopy) { IsInterleaved srcIsInterleaved = get<0>(GetParam()); @@ -269,11 +272,13 @@ TEST_P(BlobCopyTest, BlobCopy) { FillBlob(srcBlob); - auto start = std::chrono::high_resolution_clock::now(); + auto start = std::chrono::high_resolution_clock::now(); blob_copy(srcBlob, dstBlob); - auto finish = std::chrono::high_resolution_clock::now(); + auto finish = std::chrono::high_resolution_clock::now(); - std::cout << "Blob_copy execution time : " << std::chrono::duration_cast(finish - start).count() << " micros" << std::endl; + std::cout << "Blob_copy execution time : " + << std::chrono::duration_cast(finish - start).count() << " micros" + << std::endl; ASSERT_TRUE(IsCorrectBlobCopy(srcBlob, dstBlob)) << "'blob_copy' function is not correct"; } @@ -282,24 +287,28 @@ namespace { // is interleaved srcBlob? std::vector BlobCopy_srcLayoutParam = { - true, false, + true, + false, }; // is interleaved dstBlob? std::vector BlobCopy_dstLayoutParam = { - false, true, + false, + true, }; std::vector BlobCopy_BatchNum = { - 1, 3, + 1, + 3, }; -std::vector BlobCopy_ChannelNum = { - 3, 7, +std::vector BlobCopy_ChannelNum = { + 3, + 7, }; std::vector BlobCopy_Dims = { - {{10, 20, 30}}, - {{60, 80}}, + {{10, 20, 30}}, + {{60, 80}}, }; // The 'blob_copy(4/5)_d' function is a template with the parameter-list @@ -308,25 +317,26 @@ std::vector BlobCopy_Dims = { // U8 is used for cases with the following accuracy: U8, I8 // Cases with other precision are not supported std::vector BlobCopy_PrecisionParams = { - InferenceEngine::Precision::FP32, - InferenceEngine::Precision::FP16, - InferenceEngine::Precision::U8, - InferenceEngine::Precision::I8, - InferenceEngine::Precision::U16, - InferenceEngine::Precision::I16, - InferenceEngine::Precision::U32, - InferenceEngine::Precision::I32, + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16, + InferenceEngine::Precision::U8, + InferenceEngine::Precision::I8, + InferenceEngine::Precision::U16, + InferenceEngine::Precision::I16, + InferenceEngine::Precision::U32, + InferenceEngine::Precision::I32, }; } // namespace -INSTANTIATE_TEST_SUITE_P(accuracy, BlobCopyTest, - ::testing::Combine(::testing::ValuesIn(BlobCopy_srcLayoutParam), - ::testing::ValuesIn(BlobCopy_dstLayoutParam), - ::testing::ValuesIn(BlobCopy_BatchNum), - ::testing::ValuesIn(BlobCopy_ChannelNum), - ::testing::ValuesIn(BlobCopy_Dims), - ::testing::ValuesIn(BlobCopy_PrecisionParams))); +INSTANTIATE_TEST_SUITE_P(accuracy, + BlobCopyTest, + ::testing::Combine(::testing::ValuesIn(BlobCopy_srcLayoutParam), + ::testing::ValuesIn(BlobCopy_dstLayoutParam), + ::testing::ValuesIn(BlobCopy_BatchNum), + ::testing::ValuesIn(BlobCopy_ChannelNum), + ::testing::ValuesIn(BlobCopy_Dims), + ::testing::ValuesIn(BlobCopy_PrecisionParams))); namespace { @@ -335,8 +345,9 @@ bool IsEqualBlobCopy_Impl(Blob::Ptr& ref, Blob::Ptr& dst) { EXPECT_TRUE(ref->size() == dst->size()); auto refData = ref->buffer().as(); auto dstData = dst->buffer().as(); - return (std::equal(dstData, dstData + dst->size(), refData, - [](T left, T right) { return left == right; })); + return (std::equal(dstData, dstData + dst->size(), refData, [](T left, T right) { + return left == right; + })); } bool IsEqualBlobCopy(Blob::Ptr& srcBlob, Blob::Ptr& dstBlob) { @@ -424,7 +435,6 @@ void copy3DBlobsAllBytesWithReLayoutWrapper(const Blob::Ptr& srcLayoutBlob, Blob } } - std::vector BlobCopySetLayout_Dims = { {{1, 10, 10}}, {{2, 100, 100}}, @@ -468,7 +478,7 @@ TEST_P(BlobCopySetLayoutTest, BlobCopyWithNCHW_To_NHWC_After_setLayout) { ASSERT_TRUE(IsEqualBlobCopy(ref, dst)) << "'blob_copy' after setLayout function is not correct"; } -INSTANTIATE_TEST_SUITE_P(accuracy, BlobCopySetLayoutTest, - ::testing::Combine(::testing::ValuesIn(BlobCopySetLayout_Dims), - ::testing::ValuesIn(BlobCopySetLayout_Precisions))); - +INSTANTIATE_TEST_SUITE_P(accuracy, + BlobCopySetLayoutTest, + ::testing::Combine(::testing::ValuesIn(BlobCopySetLayout_Dims), + ::testing::ValuesIn(BlobCopySetLayout_Precisions))); diff --git a/src/inference/tests/functional/caching_test.cpp b/src/inference/tests/functional/caching_test.cpp index 4119b1cc53e..d66eb045a6a 100644 --- a/src/inference/tests/functional/caching_test.cpp +++ b/src/inference/tests/functional/caching_test.cpp @@ -2,40 +2,36 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include -#include -#include -#include #include +#include -#include "ie_core.hpp" -#include "ngraph/function.hpp" -#include "ie_metric_helpers.hpp" -#include "openvino/core/model.hpp" -#include "openvino/op/logical_not.hpp" +#include +#include +#include +#include +#include +#include +#include -#include "openvino/util/file_util.hpp" -#include "ie_remote_context.hpp" -#include "cpp_interfaces/interface/ie_iexecutable_network_internal.hpp" -#include "cpp_interfaces/interface/ie_iplugin_internal.hpp" - -#include "common_test_utils/unicode_utils.hpp" #include "common_test_utils/file_utils.hpp" #include "common_test_utils/test_constants.hpp" - +#include "common_test_utils/unicode_utils.hpp" +#include "cpp/ie_plugin.hpp" +#include "cpp_interfaces/interface/ie_iexecutable_network_internal.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" +#include "cpp_interfaces/interface/ie_iplugin_internal.hpp" #include "functional_test_utils/test_model/test_model.hpp" - +#include "ie_core.hpp" +#include "ie_metric_helpers.hpp" +#include "ie_remote_context.hpp" +#include "ngraph/function.hpp" +#include "openvino/core/model.hpp" +#include "openvino/op/logical_not.hpp" +#include "openvino/util/file_util.hpp" +#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp" +#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp" #include "unit_test_utils/mocks/mock_iexecutable_network.hpp" #include "unit_test_utils/mocks/mock_iinfer_request.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp" -#include "cpp/ie_plugin.hpp" - -#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" using namespace InferenceEngine; using namespace ::testing; @@ -43,34 +39,33 @@ using namespace InferenceEngine::details; using namespace std::placeholders; using namespace std::chrono; -enum class TestLoadType { - ECNN, - EContext, - EModelName -}; +enum class TestLoadType { ECNN, EContext, EModelName }; using TestParam = std::tuple; // GCC4.8 limitation: have to specify type of each element in list static const std::vector loadVariants = { - TestParam { TestLoadType::ECNN, std::string("ByCNNNetwork"), false }, - TestParam { TestLoadType::EContext, std::string("ByRemoteContext"), true }, - TestParam { TestLoadType::EModelName, std::string("ByModelName"), false }, + TestParam{TestLoadType::ECNN, std::string("ByCNNNetwork"), false}, + TestParam{TestLoadType::EContext, std::string("ByRemoteContext"), true}, + TestParam{TestLoadType::EModelName, std::string("ByModelName"), false}, }; -static const std::vector cacheFolders { +static const std::vector cacheFolders{ std::string("testCache"), }; -std::string getTestCaseName(const testing::TestParamInfo> &obj) { +std::string getTestCaseName(const testing::TestParamInfo>& obj) { return std::get<1>(std::get<0>(obj.param)) + "_" + std::get<1>(obj.param); } class MockRemoteContext : public RemoteContext { std::string m_name; + public: - MockRemoteContext(std::string name): m_name(std::move(name)) {} - std::string getDeviceName() const noexcept override { return m_name; } + MockRemoteContext(std::string name) : m_name(std::move(name)) {} + std::string getDeviceName() const noexcept override { + return m_name; + } MOCK_METHOD2(CreateBlob, RemoteBlob::Ptr(const TensorDesc&, const ParamMap&)); MOCK_CONST_METHOD0(getParams, ParamMap()); }; @@ -81,7 +76,7 @@ public: ~MockCachingInferencePluginBase() = default; ov::SoPtr LoadNetwork(const std::string& modelPath, - const std::map& config) override { + const std::map& config) override { // In GTEST, it is not possible to call base implementation inside of mocked class // Thus, we define a proxy callback and will use // EXPECT_CALL(OnLoadNetworkFromFile) instead of EXPECT_CALL(LoadNetwork) @@ -97,24 +92,28 @@ public: MockCachingInferencePlugin() = default; ~MockCachingInferencePlugin() = default; - MOCK_METHOD2(LoadExeNetworkImpl, std::shared_ptr(const CNNNetwork& network, - const std::map& config)); + MOCK_METHOD2(LoadExeNetworkImpl, + std::shared_ptr(const CNNNetwork& network, + const std::map& config)); - MOCK_METHOD3(LoadExeNetworkImpl, std::shared_ptr(const CNNNetwork& network, - const RemoteContext::Ptr& context, - const std::map& config)); + MOCK_METHOD3(LoadExeNetworkImpl, + std::shared_ptr(const CNNNetwork& network, + const RemoteContext::Ptr& context, + const std::map& config)); MOCK_CONST_METHOD0(OnLoadNetworkFromFile, void(void)); - MOCK_METHOD2(ImportNetwork, IExecutableNetworkInternal::Ptr(std::istream& networkModel, - const std::map& config)); + MOCK_METHOD2(ImportNetwork, + IExecutableNetworkInternal::Ptr(std::istream& networkModel, + const std::map& config)); - MOCK_METHOD3(ImportNetwork, IExecutableNetworkInternal::Ptr(std::istream& networkModel, - const RemoteContext::Ptr& context, - const std::map& config)); + MOCK_METHOD3(ImportNetwork, + IExecutableNetworkInternal::Ptr(std::istream& networkModel, + const RemoteContext::Ptr& context, + const std::map& config)); - MOCK_CONST_METHOD2(QueryNetwork, QueryNetworkResult(const CNNNetwork& network, - const std::map& config)); + MOCK_CONST_METHOD2(QueryNetwork, + QueryNetworkResult(const CNNNetwork& network, const std::map& config)); MOCK_CONST_METHOD2(GetMetric, Parameter(const std::string& name, const std::map& options)); MOCK_METHOD1(SetConfig, void(const std::map& options)); @@ -144,8 +143,12 @@ public: // IExecutableNetworkInternal::Export(networkModel); // } - void set_model(const std::shared_ptr& model) { m_model = model->clone(); } - const std::shared_ptr& get_model() const { return m_model; } + void set_model(const std::shared_ptr& model) { + m_model = model->clone(); + } + const std::shared_ptr& get_model() const { + return m_model; + } void SetPointerToPlugin(const IInferencePlugin::Ptr& plugin) override { std::lock_guard guard(m_pluginMutex); @@ -156,8 +159,9 @@ public: //------------------------------------------------------ class MkDirGuard { std::string m_dir; + public: - explicit MkDirGuard(std::string dir = std::string()): m_dir(std::move(dir)) { + explicit MkDirGuard(std::string dir = std::string()) : m_dir(std::move(dir)) { if (!m_dir.empty()) { CommonTestUtils::createDirectory(m_dir); } @@ -184,28 +188,28 @@ public: std::string deviceToLoad = "mock"; std::shared_ptr mockPlugin; std::vector> networks; - std::mutex mock_creation_mutex; // Internal gmock object registration is not thread-safe + std::mutex mock_creation_mutex; // Internal gmock object registration is not thread-safe using ExeNetCallback = std::function; std::vector m_post_mock_net_callbacks = {}; std::unique_ptr m_dirCreator; - TestLoadType m_type = TestLoadType::ECNN; - std::string m_cacheDir; + TestLoadType m_type = TestLoadType::ECNN; + std::string m_cacheDir; using LoadFunction = std::function; - using LoadFunctionWithCfg = std::function &)>; - LoadFunction m_testFunction; - LoadFunctionWithCfg m_testFunctionWithCfg; - bool m_remoteContext = false; + using LoadFunctionWithCfg = std::function&)>; + LoadFunction m_testFunction; + LoadFunctionWithCfg m_testFunctionWithCfg; + bool m_remoteContext = false; using CNNCallback = std::function; - CNNCallback m_cnnCallback = nullptr; + CNNCallback m_cnnCallback = nullptr; std::map m_inputs_map; std::map m_outputs_map; - using CheckConfigCb = std::function &)>; + using CheckConfigCb = std::function&)>; CheckConfigCb m_checkConfigCb = nullptr; static std::string get_mock_engine_path() { std::string mockEngineName("mock_engine"); return ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), - mockEngineName + IE_BUILD_POSTFIX); + mockEngineName + IE_BUILD_POSTFIX); } static std::string generateTestFilePrefix() { @@ -240,50 +244,52 @@ public: const OutputsDataMap& outputs_map) { auto mock = std::make_shared(); ConstInputsDataMap inputMap; - for (const auto &input_item : inputs_map) { + for (const auto& input_item : inputs_map) { inputMap.insert({input_item.first, input_item.second}); } ConstOutputsDataMap outputMap; - for (const auto &output_item : outputs_map) { + for (const auto& output_item : outputs_map) { outputMap.insert({output_item.first, output_item.second}); } EXPECT_CALL(*mock, GetInputsInfo()).Times(AnyNumber()).WillRepeatedly(Return(inputMap)); EXPECT_CALL(*mock, GetOutputsInfo()).Times(AnyNumber()).WillRepeatedly(Return(outputMap)); - EXPECT_CALL(*mock, GetConfig(ov::enable_profiling.name())).Times(AnyNumber()).WillRepeatedly(Return(Parameter{PluginConfigParams::NO})); - EXPECT_CALL(*mock, GetMetric(METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS))).Times(AnyNumber()).WillRepeatedly(Return(Parameter{1u})); + EXPECT_CALL(*mock, GetConfig(ov::enable_profiling.name())) + .Times(AnyNumber()) + .WillRepeatedly(Return(Parameter{PluginConfigParams::NO})); + EXPECT_CALL(*mock, GetMetric(METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS))) + .Times(AnyNumber()) + .WillRepeatedly(Return(Parameter{1u})); EXPECT_CALL(*mock, GetExecGraphInfo()).Times(AnyNumber()).WillRepeatedly(Return([] { - ngraph::ParameterVector parameters; - parameters.push_back(std::make_shared( - ov::element::f32, ov::Shape{1, 3, 8, 8})); - auto notOp = std::make_shared(parameters.back()); - ngraph::ResultVector results; - results.push_back(std::make_shared(notOp)); - return std::make_shared(results, parameters, "empty_function"); - } ())); + ngraph::ParameterVector parameters; + parameters.push_back(std::make_shared(ov::element::f32, ov::Shape{1, 3, 8, 8})); + auto notOp = std::make_shared(parameters.back()); + ngraph::ResultVector results; + results.push_back(std::make_shared(notOp)); + return std::make_shared(results, parameters, "empty_function"); + }())); auto ptr = std::make_shared(); EXPECT_CALL(*ptr, SetCallback(_)).Times(AnyNumber()); EXPECT_CALL(*mock, CreateInferRequest()).Times(AnyNumber()).WillRepeatedly(Return(ptr)); - - EXPECT_CALL(*mock, GetMetric(METRIC_KEY(NETWORK_NAME))).Times(AnyNumber()) - .WillRepeatedly(Return("mock_net")); - EXPECT_CALL(*mock, GetMetric(METRIC_KEY(SUPPORTED_METRICS))).Times(AnyNumber()) - .WillRepeatedly(Invoke([&](const std::string &) { - std::vector res; - res.emplace_back(METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS)); - res.emplace_back(METRIC_KEY(NETWORK_NAME)); - return res; - })); - EXPECT_CALL(*mock, GetMetric(ov::supported_properties.name())).Times(AnyNumber()) - .WillRepeatedly(Return(std::vector{ - ov::supported_properties.name(), - ov::optimal_number_of_infer_requests.name(), - ov::model_name.name()})); + EXPECT_CALL(*mock, GetMetric(METRIC_KEY(NETWORK_NAME))).Times(AnyNumber()).WillRepeatedly(Return("mock_net")); + EXPECT_CALL(*mock, GetMetric(METRIC_KEY(SUPPORTED_METRICS))) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([&](const std::string&) { + std::vector res; + res.emplace_back(METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS)); + res.emplace_back(METRIC_KEY(NETWORK_NAME)); + return res; + })); + EXPECT_CALL(*mock, GetMetric(ov::supported_properties.name())) + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{ov::supported_properties.name(), + ov::optimal_number_of_infer_requests.name(), + ov::model_name.name()})); EXPECT_CALL(*mock, setNetworkInputs(_)).Times(AnyNumber()); EXPECT_CALL(*mock, setNetworkOutputs(_)).Times(AnyNumber()); mock->setNetworkInputs(copyInfo(inputs_map)); mock->setNetworkOutputs(copyInfo(outputs_map)); - ON_CALL(*mock, Export(_)).WillByDefault(Invoke([name] (std::ostream& s) { + ON_CALL(*mock, Export(_)).WillByDefault(Invoke([name](std::ostream& s) { s << name; s << ' '; })); @@ -315,31 +321,38 @@ public: Core ie; injectProxyEngine(mockPlugin.get()); ie.RegisterPlugin(ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), deviceName); + std::string("mock_engine") + IE_BUILD_POSTFIX), + deviceName); func(ie); ie.UnregisterPlugin(deviceName); } LoadFunction getLoadFunction(TestLoadType type) const { switch (type) { - case TestLoadType::ECNN: - return [&](Core& ie) { return performReadAndLoad(ie); }; - case TestLoadType::EContext: - return [&](Core& ie) { return performReadAndLoadWithContext(ie); }; - case TestLoadType::EModelName: - return [&](Core& ie) { return performLoadByName(ie); }; + case TestLoadType::ECNN: + return [&](Core& ie) { + return performReadAndLoad(ie); + }; + case TestLoadType::EContext: + return [&](Core& ie) { + return performReadAndLoadWithContext(ie); + }; + case TestLoadType::EModelName: + return [&](Core& ie) { + return performLoadByName(ie); + }; } return nullptr; } LoadFunctionWithCfg getLoadFunctionWithCfg(TestLoadType type) const { switch (type) { - case TestLoadType::ECNN: - return std::bind(&CachingTest::performReadAndLoad, this, _1, _2); - case TestLoadType::EContext: - return std::bind(&CachingTest::performReadAndLoadWithContext, this, _1, _2); - case TestLoadType::EModelName: - return std::bind(&CachingTest::performLoadByName, this, _1, _2); + case TestLoadType::ECNN: + return std::bind(&CachingTest::performReadAndLoad, this, _1, _2); + case TestLoadType::EContext: + return std::bind(&CachingTest::performReadAndLoadWithContext, this, _1, _2); + case TestLoadType::EModelName: + return std::bind(&CachingTest::performLoadByName, this, _1, _2); } return nullptr; } @@ -350,158 +363,156 @@ public: ExecutableNetwork performReadAndLoad(Core& ie, const std::map& config = {}) const { auto cnnNetwork = ie.ReadNetwork(modelName); - if (m_cnnCallback) m_cnnCallback(cnnNetwork); + if (m_cnnCallback) + m_cnnCallback(cnnNetwork); return ie.LoadNetwork(cnnNetwork, deviceToLoad, config); } - ExecutableNetwork performReadAndLoadWithContext(Core& ie, const std::map& config = {}) const { + ExecutableNetwork performReadAndLoadWithContext(Core& ie, + const std::map& config = {}) const { auto cnnNetwork = ie.ReadNetwork(modelName); EXPECT_CALL(*mockPlugin, GetDefaultContext(_)).Times(AnyNumber()); auto context = ie.GetDefaultContext(deviceToLoad); - if (m_cnnCallback) m_cnnCallback(cnnNetwork); + if (m_cnnCallback) + m_cnnCallback(cnnNetwork); return ie.LoadNetwork(cnnNetwork, context, config); } private: template std::function make_std_function(const std::string& functionName) { - std::function ptr(reinterpret_cast( - ov::util::get_symbol(sharedObjectLoader, functionName.c_str()))); + std::function ptr(reinterpret_cast(ov::util::get_symbol(sharedObjectLoader, functionName.c_str()))); return ptr; } void setupMock(MockCachingInferencePlugin& plugin) { - ON_CALL(plugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)). - WillByDefault(Invoke([&](const std::string &, const std::map &) { - std::vector res; - res.emplace_back(METRIC_KEY(IMPORT_EXPORT_SUPPORT)); - res.emplace_back(METRIC_KEY(DEVICE_ARCHITECTURE)); - return res; - })); - ON_CALL(plugin, GetMetric(ov::supported_properties.name(), _)). - WillByDefault(Invoke([&](const std::string &, const std::map &) { - return std::vector{ - ov::supported_properties.name(), - METRIC_KEY(IMPORT_EXPORT_SUPPORT), - ov::device::capabilities.name(), - ov::device::architecture.name()}; - })); + ON_CALL(plugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) + .WillByDefault(Invoke([&](const std::string&, const std::map&) { + std::vector res; + res.emplace_back(METRIC_KEY(IMPORT_EXPORT_SUPPORT)); + res.emplace_back(METRIC_KEY(DEVICE_ARCHITECTURE)); + return res; + })); + ON_CALL(plugin, GetMetric(ov::supported_properties.name(), _)) + .WillByDefault(Invoke([&](const std::string&, const std::map&) { + return std::vector{ov::supported_properties.name(), + METRIC_KEY(IMPORT_EXPORT_SUPPORT), + ov::device::capabilities.name(), + ov::device::architecture.name()}; + })); - ON_CALL(plugin, GetMetric(METRIC_KEY(OPTIMIZATION_CAPABILITIES), _)). - WillByDefault(Return(std::vector())); + ON_CALL(plugin, GetMetric(METRIC_KEY(OPTIMIZATION_CAPABILITIES), _)) + .WillByDefault(Return(std::vector())); - ON_CALL(plugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)). - WillByDefault(Return(true)); + ON_CALL(plugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).WillByDefault(Return(true)); - ON_CALL(plugin, GetMetric(ov::device::capabilities.name(), _)). - WillByDefault(Invoke([&](const std::string &, const std::map &) { - return decltype(ov::device::capabilities)::value_type{ - ov::device::capability::EXPORT_IMPORT - }; + ON_CALL(plugin, GetMetric(ov::device::capabilities.name(), _)) + .WillByDefault(Invoke([&](const std::string&, const std::map&) { + return decltype(ov::device::capabilities)::value_type{ov::device::capability::EXPORT_IMPORT}; + })); + + ON_CALL(plugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) + .WillByDefault(Invoke([&](const std::string&, const std::map&) { + std::vector res; + res.emplace_back("SomeConfig"); + return res; + })); + + ON_CALL(plugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)) + .WillByDefault(Invoke([&](const std::string&, const std::map&) { + return "mock"; + })); + + ON_CALL(plugin, ImportNetwork(_, _, _)) + .WillByDefault(Invoke( + [&](std::istream& istr, const RemoteContext::Ptr&, const std::map& config) { + if (m_checkConfigCb) { + m_checkConfigCb(config); + } + std::string name; + istr >> name; + char space; + istr.read(&space, 1); + std::lock_guard lock(mock_creation_mutex); + return createMockIExecutableNet({}, m_inputs_map[name], m_outputs_map[name]); })); - ON_CALL(plugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)). - WillByDefault(Invoke([&](const std::string &, const std::map &) { - std::vector res; - res.emplace_back("SomeConfig"); - return res; - })); + ON_CALL(plugin, ImportNetwork(_, _)) + .WillByDefault(Invoke([&](std::istream& istr, const std::map& config) { + if (m_checkConfigCb) { + m_checkConfigCb(config); + } + std::string name; + istr >> name; + char space; + istr.read(&space, 1); + std::lock_guard lock(mock_creation_mutex); + return createMockIExecutableNet({}, m_inputs_map[name], m_outputs_map[name]); + })); - ON_CALL(plugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)). - WillByDefault(Invoke([&](const std::string &, const std::map &) { - return "mock"; - })); + ON_CALL(plugin, LoadExeNetworkImpl(_, _, _)) + .WillByDefault(Invoke([&](const CNNNetwork& cnn, + const RemoteContext::Ptr&, + const std::map& config) { + if (m_checkConfigCb) { + m_checkConfigCb(config); + } + std::lock_guard lock(mock_creation_mutex); + std::string name = cnn.getFunction()->get_friendly_name(); + m_inputs_map[name] = cnn.getInputsInfo(); + m_outputs_map[name] = cnn.getOutputsInfo(); + auto exe_net = createMockIExecutableNet(cnn.getFunction()->get_friendly_name(), + m_inputs_map[name], + m_outputs_map[name]); + exe_net->set_model(cnn.getFunction()); + for (const auto& cb : m_post_mock_net_callbacks) { + cb(*exe_net); + } + networks.push_back(exe_net); + return exe_net; + })); - ON_CALL(plugin, ImportNetwork(_, _, _)). - WillByDefault(Invoke([&](std::istream &istr, const RemoteContext::Ptr&, - const std::map &config) { - if (m_checkConfigCb) { - m_checkConfigCb(config); - } - std::string name; - istr >> name; - char space; - istr.read(&space, 1); - std::lock_guard lock(mock_creation_mutex); - return createMockIExecutableNet({}, m_inputs_map[name], m_outputs_map[name]); - })); + ON_CALL(plugin, LoadExeNetworkImpl(_, _)) + .WillByDefault(Invoke([&](const CNNNetwork& cnn, const std::map& config) { + if (m_checkConfigCb) { + m_checkConfigCb(config); + } + std::string name = cnn.getFunction()->get_friendly_name(); + std::lock_guard lock(mock_creation_mutex); + m_inputs_map[name] = cnn.getInputsInfo(); + m_outputs_map[name] = cnn.getOutputsInfo(); + auto exe_net = createMockIExecutableNet(cnn.getFunction()->get_friendly_name(), + m_inputs_map[name], + m_outputs_map[name]); + exe_net->set_model(cnn.getFunction()); + for (const auto& cb : m_post_mock_net_callbacks) { + cb(*exe_net); + } + networks.push_back(exe_net); + return exe_net; + })); - ON_CALL(plugin, ImportNetwork(_, _)). - WillByDefault(Invoke([&](std::istream &istr, const std::map &config) { - if (m_checkConfigCb) { - m_checkConfigCb(config); - } - std::string name; - istr >> name; - char space; - istr.read(&space, 1); - std::lock_guard lock(mock_creation_mutex); - return createMockIExecutableNet({}, m_inputs_map[name], m_outputs_map[name]); - })); - - ON_CALL(plugin, LoadExeNetworkImpl(_, _, _)). - WillByDefault(Invoke([&](const CNNNetwork & cnn, const RemoteContext::Ptr&, - const std::map &config) { - if (m_checkConfigCb) { - m_checkConfigCb(config); - } - std::lock_guard lock(mock_creation_mutex); - std::string name = cnn.getFunction()->get_friendly_name(); - m_inputs_map[name] = cnn.getInputsInfo(); - m_outputs_map[name] = cnn.getOutputsInfo(); - auto exe_net = createMockIExecutableNet(cnn.getFunction()->get_friendly_name(), - m_inputs_map[name], - m_outputs_map[name]); - exe_net->set_model(cnn.getFunction()); - for (const auto& cb : m_post_mock_net_callbacks) { - cb(*exe_net); - } - networks.push_back(exe_net); - return exe_net; - })); - - ON_CALL(plugin, LoadExeNetworkImpl(_, _)). - WillByDefault(Invoke([&](const CNNNetwork & cnn, - const std::map &config) { - if (m_checkConfigCb) { - m_checkConfigCb(config); - } - std::string name = cnn.getFunction()->get_friendly_name(); - std::lock_guard lock(mock_creation_mutex); - m_inputs_map[name] = cnn.getInputsInfo(); - m_outputs_map[name] = cnn.getOutputsInfo(); - auto exe_net = createMockIExecutableNet(cnn.getFunction()->get_friendly_name(), - m_inputs_map[name], - m_outputs_map[name]); - exe_net->set_model(cnn.getFunction()); - for (const auto& cb : m_post_mock_net_callbacks) { - cb(*exe_net); - } - networks.push_back(exe_net); - return exe_net; - })); - - ON_CALL(plugin, GetDefaultContext(_)). - WillByDefault(Invoke([&](const ParamMap &) { + ON_CALL(plugin, GetDefaultContext(_)).WillByDefault(Invoke([&](const ParamMap&) { return std::make_shared(deviceToLoad); })); - ON_CALL(plugin, QueryNetwork(_, _)). - WillByDefault(Invoke([&](const CNNNetwork &network, const std::map&) { - QueryNetworkResult res; - auto function = network.getFunction(); - EXPECT_TRUE(function); + ON_CALL(plugin, QueryNetwork(_, _)) + .WillByDefault(Invoke([&](const CNNNetwork& network, const std::map&) { + QueryNetworkResult res; + auto function = network.getFunction(); + EXPECT_TRUE(function); - for (auto &&node : function->get_ops()) { - res.supportedLayersMap.emplace(node->get_friendly_name(), deviceName); - } - return res; - })); + for (auto&& node : function->get_ops()) { + res.supportedLayersMap.emplace(node->get_friendly_name(), deviceName); + } + return res; + })); - EXPECT_CALL(plugin, SetConfig(_)).Times(AnyNumber()).WillRepeatedly( - Invoke([](const std::map&) { - throw InferenceEngine::NotImplemented("Not implemented"); - })); + EXPECT_CALL(plugin, SetConfig(_)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([](const std::map&) { + throw InferenceEngine::NotImplemented("Not implemented"); + })); } }; @@ -519,7 +530,7 @@ TEST_P(CachingTest, TestLoad) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -532,9 +543,9 @@ TEST_P(CachingTest, TestLoad) { EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(!m_remoteContext ? 1 : 0); for (auto& net : networks) { - EXPECT_CALL(*net, Export(_)).Times(0); // No more 'Export' for existing networks + EXPECT_CALL(*net, Export(_)).Times(0); // No more 'Export' for existing networks } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -557,7 +568,7 @@ TEST_P(CachingTest, TestLoad_by_device_name) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}, "mock"); m_testFunction(ie); }); @@ -570,9 +581,9 @@ TEST_P(CachingTest, TestLoad_by_device_name) { EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(!m_remoteContext ? 1 : 0); for (auto& net : networks) { - EXPECT_CALL(*net, Export(_)).Times(0); // No more 'Export' for existing networks + EXPECT_CALL(*net, Export(_)).Times(0); // No more 'Export' for existing networks } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}, "mock"); m_testFunction(ie); }); @@ -587,31 +598,31 @@ TEST_P(CachingTest, TestLoadCustomImportExport) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); - ON_CALL(*mockPlugin, ImportNetwork(_, _, _)). - WillByDefault(Invoke([&](std::istream& s, const RemoteContext::Ptr&, - const std::map &) { - char a[sizeof(customData)]; - s.read(a, sizeof(customData)); - EXPECT_EQ(memcmp(a, customData, sizeof(customData)), 0); - std::string name; - s >> name; - std::lock_guard lock(mock_creation_mutex); - return createMockIExecutableNet({}, m_inputs_map[name], m_outputs_map[name]); - })); + ON_CALL(*mockPlugin, ImportNetwork(_, _, _)) + .WillByDefault( + Invoke([&](std::istream& s, const RemoteContext::Ptr&, const std::map&) { + char a[sizeof(customData)]; + s.read(a, sizeof(customData)); + EXPECT_EQ(memcmp(a, customData, sizeof(customData)), 0); + std::string name; + s >> name; + std::lock_guard lock(mock_creation_mutex); + return createMockIExecutableNet({}, m_inputs_map[name], m_outputs_map[name]); + })); - ON_CALL(*mockPlugin, ImportNetwork(_, _)). - WillByDefault(Invoke([&](std::istream &s, const std::map &) { - char a[sizeof(customData)]; - s.read(a, sizeof(customData)); - EXPECT_EQ(memcmp(a, customData, sizeof(customData)), 0); - std::string name; - s >> name; - std::lock_guard lock(mock_creation_mutex); - return createMockIExecutableNet({}, m_inputs_map[name], m_outputs_map[name]); - })); + ON_CALL(*mockPlugin, ImportNetwork(_, _)) + .WillByDefault(Invoke([&](std::istream& s, const std::map&) { + char a[sizeof(customData)]; + s.read(a, sizeof(customData)); + EXPECT_EQ(memcmp(a, customData, sizeof(customData)), 0); + std::string name; + s >> name; + std::lock_guard lock(mock_creation_mutex); + return createMockIExecutableNet({}, m_inputs_map[name], m_outputs_map[name]); + })); m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { - ON_CALL(net, Export(_)).WillByDefault(Invoke([&] (std::ostream& s) { + ON_CALL(net, Export(_)).WillByDefault(Invoke([&](std::ostream& s) { s.write(customData, sizeof(customData)); s << net.get_model()->get_friendly_name(); })); @@ -625,7 +636,7 @@ TEST_P(CachingTest, TestLoadCustomImportExport) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -637,9 +648,9 @@ TEST_P(CachingTest, TestLoadCustomImportExport) { EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(!m_remoteContext ? 1 : 0); for (auto& net : networks) { - EXPECT_CALL(*net, Export(_)).Times(0); // No 'Export' for existing networks + EXPECT_CALL(*net, Export(_)).Times(0); // No 'Export' for existing networks } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -655,27 +666,26 @@ TEST_P(CachingTest, TestChangeLoadConfig) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(ov::caching_properties.name(), _)).Times(AnyNumber()); - ON_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)). - WillByDefault(Invoke([&](const std::string &, const std::map &) { - return std::vector{ - ov::supported_properties.name(), - METRIC_KEY(IMPORT_EXPORT_SUPPORT), - ov::device::capabilities.name(), - ov::device::architecture.name(), - ov::caching_properties.name()}; - })); - ON_CALL(*mockPlugin, GetMetric(ov::caching_properties.name(), _)). - WillByDefault(Invoke([&](const std::string &, const std::map &) { - std::vector res; - res.push_back(ov::PropertyName(CUSTOM_KEY, ov::PropertyMutability::RO)); - return decltype(ov::caching_properties)::value_type(res); - })); - ON_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)). - WillByDefault(Invoke([&](const std::string &, const std::map &) { - std::vector res; - res.push_back(ov::caching_properties.name()); - return res; - })); + ON_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) + .WillByDefault(Invoke([&](const std::string&, const std::map&) { + return std::vector{ov::supported_properties.name(), + METRIC_KEY(IMPORT_EXPORT_SUPPORT), + ov::device::capabilities.name(), + ov::device::architecture.name(), + ov::caching_properties.name()}; + })); + ON_CALL(*mockPlugin, GetMetric(ov::caching_properties.name(), _)) + .WillByDefault(Invoke([&](const std::string&, const std::map&) { + std::vector res; + res.push_back(ov::PropertyName(CUSTOM_KEY, ov::PropertyMutability::RO)); + return decltype(ov::caching_properties)::value_type(res); + })); + ON_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) + .WillByDefault(Invoke([&](const std::string&, const std::map&) { + std::vector res; + res.push_back(ov::caching_properties.name()); + return res; + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 1 : 0); @@ -684,7 +694,7 @@ TEST_P(CachingTest, TestChangeLoadConfig) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunctionWithCfg(ie, {{CUSTOM_KEY, "0"}}); }); @@ -698,7 +708,7 @@ TEST_P(CachingTest, TestChangeLoadConfig) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunctionWithCfg(ie, {{CUSTOM_KEY, "1"}}); }); @@ -712,10 +722,10 @@ TEST_P(CachingTest, TestChangeLoadConfig_With_Cache_Dir_inline) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); - ON_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)). - WillByDefault(Invoke([&](const std::string &, const std::map &) { - return std::vector{}; - })); + ON_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) + .WillByDefault(Invoke([&](const std::string&, const std::map&) { + return std::vector{}; + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 1 : 0); @@ -724,7 +734,7 @@ TEST_P(CachingTest, TestChangeLoadConfig_With_Cache_Dir_inline) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { m_testFunctionWithCfg(ie, {{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); }); } @@ -735,9 +745,9 @@ TEST_P(CachingTest, TestChangeLoadConfig_With_Cache_Dir_inline) { EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(!m_remoteContext ? 1 : 0); for (auto& net : networks) { - EXPECT_CALL(*net, Export(_)).Times(0); // No more 'Export' for existing networks + EXPECT_CALL(*net, Export(_)).Times(0); // No more 'Export' for existing networks } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { m_testFunctionWithCfg(ie, {{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); }); EXPECT_EQ(networks.size(), 1); @@ -758,7 +768,7 @@ TEST_P(CachingTest, TestNoCacheEnabled) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(0); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { m_testFunction(ie); }); } @@ -769,10 +779,12 @@ TEST_P(CachingTest, TestNoCacheSupported) { EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)) - .Times(AnyNumber()).WillRepeatedly(Return(false)); + .Times(AnyNumber()) + .WillRepeatedly(Return(false)); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)).Times(AnyNumber()). - WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{})); + EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)) + .Times(AnyNumber()) + .WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{})); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); @@ -783,7 +795,7 @@ TEST_P(CachingTest, TestNoCacheSupported) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(0); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -792,10 +804,12 @@ TEST_P(CachingTest, TestNoCacheSupported) { TEST_P(CachingTest, TestNoCacheMetricSupported) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)).Times(AnyNumber()) - .WillRepeatedly(Return(std::vector{})); + EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) - .Times(AnyNumber()).WillRepeatedly(Return(std::vector{})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).Times(0); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(0); EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)).Times(0); @@ -808,7 +822,7 @@ TEST_P(CachingTest, TestNoCacheMetricSupported) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(0); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -818,10 +832,12 @@ TEST_P(CachingTest, TestNoCacheMetricSupported) { /// \brief If device doesn't support 'cache_dir' or 'import_export' - setting cache_dir is ignored TEST_P(CachingTest, TestNoCacheMetricSupported_by_device_name) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)).Times(AnyNumber()) - .WillRepeatedly(Return(std::vector{})); + EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) - .Times(AnyNumber()).WillRepeatedly(Return(std::vector{})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).Times(0); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(0); EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)).Times(0); @@ -834,7 +850,7 @@ TEST_P(CachingTest, TestNoCacheMetricSupported_by_device_name) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(0); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}, "mock"); m_testFunction(ie); }); @@ -843,27 +859,28 @@ TEST_P(CachingTest, TestNoCacheMetricSupported_by_device_name) { TEST_P(CachingTest, TestNoCacheMetric_hasCacheDirConfig) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) - .Times(AnyNumber()).WillRepeatedly( - Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{ - ov::supported_properties.name(), ov::cache_dir.name()})); - EXPECT_CALL(*mockPlugin, SetConfig(_)).Times(AtLeast(1)).WillRepeatedly( - Invoke([](const std::map& config) { - ASSERT_GT(config.count(CONFIG_KEY(CACHE_DIR)), 0); - })); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{ov::supported_properties.name(), ov::cache_dir.name()})); + EXPECT_CALL(*mockPlugin, SetConfig(_)) + .Times(AtLeast(1)) + .WillRepeatedly(Invoke([](const std::map& config) { + ASSERT_GT(config.count(CONFIG_KEY(CACHE_DIR)), 0); + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, OnLoadNetworkFromFile()).Times(m_type == TestLoadType::EModelName ? 1 : 0); - ASSERT_NO_THROW( - testLoad([&](Core &ie) { - ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); - m_testFunction(ie); - })); + ASSERT_NO_THROW(testLoad([&](Core& ie) { + ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); + m_testFunction(ie); + })); } } @@ -873,22 +890,22 @@ TEST_P(CachingTest, TestNoCacheMetric_hasCacheDirConfig_inline) { EXPECT_NE(config.count(CONFIG_KEY(CACHE_DIR)), 0); }; EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) - .Times(AnyNumber()).WillRepeatedly( - Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{ - ov::supported_properties.name(), ov::cache_dir.name()})); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{ov::supported_properties.name(), ov::cache_dir.name()})); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, OnLoadNetworkFromFile()).Times(m_type == TestLoadType::EModelName ? 1 : 0); - ASSERT_NO_THROW( - testLoad([&](Core &ie) { - m_testFunctionWithCfg(ie, {{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); - })); + ASSERT_NO_THROW(testLoad([&](Core& ie) { + m_testFunctionWithCfg(ie, {{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); + })); } } @@ -899,101 +916,106 @@ TEST_P(CachingTest, TestNoCacheMetric_hasCacheDirConfig_by_device_name) { EXPECT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); }; EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) - .Times(AnyNumber()).WillRepeatedly( - Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{ - ov::supported_properties.name(), ov::cache_dir.name()})); - EXPECT_CALL(*mockPlugin, SetConfig(_)).Times(AtLeast(1)).WillRepeatedly( - Invoke([](const std::map& config) { - ASSERT_GT(config.count(CONFIG_KEY(CACHE_DIR)), 0); - })); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{ov::supported_properties.name(), ov::cache_dir.name()})); + EXPECT_CALL(*mockPlugin, SetConfig(_)) + .Times(AtLeast(1)) + .WillRepeatedly(Invoke([](const std::map& config) { + ASSERT_GT(config.count(CONFIG_KEY(CACHE_DIR)), 0); + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, OnLoadNetworkFromFile()).Times(m_type == TestLoadType::EModelName ? 1 : 0); - ASSERT_NO_THROW( - testLoad([&](Core &ie) { - ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}, "mock"); - m_testFunction(ie); - })); + ASSERT_NO_THROW(testLoad([&](Core& ie) { + ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}, "mock"); + m_testFunction(ie); + })); } } TEST_P(CachingTest, TestCacheEnabled_noConfig) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) - .Times(AnyNumber()).WillRepeatedly( - Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{})); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{})); EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{ - ov::supported_properties.name()})); - EXPECT_CALL(*mockPlugin, SetConfig(_)).Times(AnyNumber()).WillRepeatedly( - Invoke([](const std::map& config) { - ASSERT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); - })); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{ov::supported_properties.name()})); + EXPECT_CALL(*mockPlugin, SetConfig(_)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([](const std::map& config) { + ASSERT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, OnLoadNetworkFromFile()).Times(m_type == TestLoadType::EModelName ? 1 : 0); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); } } - TEST_P(CachingTest, TestNoCacheMetric_configThrow) { m_checkConfigCb = [](const std::map& config) { EXPECT_NE(config.count(CONFIG_KEY(CACHE_DIR)), 0); }; EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) - .Times(AnyNumber()).WillRepeatedly( - Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{ - ov::supported_properties.name(), ov::cache_dir.name()})); - EXPECT_CALL(*mockPlugin, SetConfig(_)).Times(AtLeast(1)).WillRepeatedly( - Invoke([](const std::map& config) { - ASSERT_GT(config.count(CONFIG_KEY(CACHE_DIR)), 0); - throw InferenceEngine::GeneralError("Error occurred"); - })); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{ov::supported_properties.name(), ov::cache_dir.name()})); + EXPECT_CALL(*mockPlugin, SetConfig(_)) + .Times(AtLeast(1)) + .WillRepeatedly(Invoke([](const std::map& config) { + ASSERT_GT(config.count(CONFIG_KEY(CACHE_DIR)), 0); + throw InferenceEngine::GeneralError("Error occurred"); + })); - ASSERT_ANY_THROW( - testLoad([&](Core &ie) { - ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); - m_testFunction(ie); - })); + ASSERT_ANY_THROW(testLoad([&](Core& ie) { + ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); + m_testFunction(ie); + })); } TEST_P(CachingTest, TestNoCacheEnabled_cacheDirConfig) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) - .Times(AnyNumber()).WillRepeatedly( - Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{ - ov::supported_properties.name(), ov::cache_dir.name()})); - EXPECT_CALL(*mockPlugin, SetConfig(_)).Times(AnyNumber()).WillRepeatedly( - Invoke([](const std::map& config) { - ASSERT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); - })); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{ov::supported_properties.name(), ov::cache_dir.name()})); + EXPECT_CALL(*mockPlugin, SetConfig(_)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([](const std::map& config) { + ASSERT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(0); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { m_testFunction(ie); }); } @@ -1013,7 +1035,7 @@ TEST_P(CachingTest, TestLoadChangeCacheDir) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -1029,7 +1051,7 @@ TEST_P(CachingTest, TestLoadChangeCacheDir) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), newCacheDir}}); m_testFunction(ie); }); @@ -1043,16 +1065,17 @@ TEST_P(CachingTest, TestLoadChangeCacheDirOneCore) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, SetConfig(_)).Times(AnyNumber()).WillRepeatedly( - Invoke([](const std::map& config) { - ASSERT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); - })); + EXPECT_CALL(*mockPlugin, SetConfig(_)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([](const std::map& config) { + ASSERT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 2 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 2 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(0); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); @@ -1078,16 +1101,17 @@ TEST_P(CachingTest, TestLoadChangeCacheDirOneCore_overwrite_device_dir) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, SetConfig(_)).Times(AnyNumber()).WillRepeatedly( - Invoke([](const std::map& config) { - ASSERT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); - })); + EXPECT_CALL(*mockPlugin, SetConfig(_)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([](const std::map& config) { + ASSERT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 2 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 2 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(0); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); @@ -1105,30 +1129,33 @@ TEST_P(CachingTest, TestLoadChangeCacheDirOneCore_overwrite_device_dir) { } } -/// \brief Change CACHE_DIR during working with same 'Core' object for device which supports 'CACHE_DIR' config, not import_export -/// Expectation is that SetConfig for plugin will be called 2 times - with appropriate cache_dir values +/// \brief Change CACHE_DIR during working with same 'Core' object for device which supports 'CACHE_DIR' config, not +/// import_export Expectation is that SetConfig for plugin will be called 2 times - with appropriate cache_dir values TEST_P(CachingTest, TestLoadChangeCacheDirOneCore_SupportsCacheDir_NoImportExport) { m_checkConfigCb = [](const std::map& config) { EXPECT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); }; EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) - .Times(AnyNumber()).WillRepeatedly(Return(std::vector{ - ov::supported_properties.name(), ov::cache_dir.name()})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{ov::supported_properties.name(), ov::cache_dir.name()})); EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) - .Times(AnyNumber()).WillRepeatedly( - Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); - EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)).Times(AnyNumber()). - WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{METRIC_KEY(SUPPORTED_CONFIG_KEYS)})); + EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)) + .Times(AnyNumber()) + .WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); std::string set_cache_dir = {}; - EXPECT_CALL(*mockPlugin, SetConfig(_)).Times(AtLeast(2)).WillRepeatedly( - Invoke([&](const std::map& config) { - ASSERT_NE(config.count(CONFIG_KEY(CACHE_DIR)), 0); - set_cache_dir = config.at(CONFIG_KEY(CACHE_DIR)); - })); + EXPECT_CALL(*mockPlugin, SetConfig(_)) + .Times(AtLeast(2)) + .WillRepeatedly(Invoke([&](const std::map& config) { + ASSERT_NE(config.count(CONFIG_KEY(CACHE_DIR)), 0); + set_cache_dir = config.at(CONFIG_KEY(CACHE_DIR)); + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 2 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 2 : 0); @@ -1138,7 +1165,7 @@ TEST_P(CachingTest, TestLoadChangeCacheDirOneCore_SupportsCacheDir_NoImportExpor m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(0); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); EXPECT_EQ(set_cache_dir, m_cacheDir); @@ -1159,16 +1186,17 @@ TEST_P(CachingTest, TestLoadChangeCacheDirOneCore_by_device_name) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, SetConfig(_)).Times(AnyNumber()).WillRepeatedly( - Invoke([](const std::map& config) { - ASSERT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); - })); + EXPECT_CALL(*mockPlugin, SetConfig(_)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([](const std::map& config) { + ASSERT_EQ(config.count(CONFIG_KEY(CACHE_DIR)), 0); + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 2 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 2 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(0); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); @@ -1190,27 +1218,31 @@ TEST_P(CachingTest, TestLoadChangeCacheDirOneCore_by_device_name) { /// Verifies that no 'export' is called and cache_dir is propagated to set_config TEST_P(CachingTest, TestLoadChangeCacheDirOneCore_by_device_name_supports_cache_dir) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) - .Times(AtLeast(1)).WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); - EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)).Times(AnyNumber()) - .WillRepeatedly(Return(std::vector{ - ov::cache_dir.name()})); + .Times(AtLeast(1)) + .WillRepeatedly(Return(std::vector{CONFIG_KEY(CACHE_DIR)})); + EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{ov::cache_dir.name()})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).Times(AnyNumber()) - .WillRepeatedly(Return(false)); - EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)).Times(AnyNumber()). - WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{})); + EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)) + .Times(AnyNumber()) + .WillRepeatedly(Return(false)); + EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)) + .Times(AnyNumber()) + .WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, SetConfig(_)).Times(AtLeast(2)).WillRepeatedly( - Invoke([](const std::map& config) { - ASSERT_GT(config.count(CONFIG_KEY(CACHE_DIR)), 0); - })); + EXPECT_CALL(*mockPlugin, SetConfig(_)) + .Times(AtLeast(2)) + .WillRepeatedly(Invoke([](const std::map& config) { + ASSERT_GT(config.count(CONFIG_KEY(CACHE_DIR)), 0); + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 2 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 2 : 0); EXPECT_CALL(*mockPlugin, OnLoadNetworkFromFile()).Times(m_type == TestLoadType::EModelName ? 2 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(0); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(0); }); @@ -1242,7 +1274,7 @@ TEST_P(CachingTest, TestClearCacheDir) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); ie.SetConfig({{CONFIG_KEY(CACHE_DIR), ""}}); m_testFunction(ie); @@ -1265,7 +1297,7 @@ TEST_P(CachingTest, TestChangeOtherConfig) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); ie.SetConfig({{"someKey", "someValue"}}); m_testFunction(ie); @@ -1289,7 +1321,7 @@ TEST_P(CachingTest, TestChangeCacheDirFailure) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -1304,7 +1336,7 @@ TEST_P(CachingTest, TestChangeCacheDirFailure) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); EXPECT_ANY_THROW(ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir + "/" + longName}})); m_testFunction(ie); @@ -1330,7 +1362,7 @@ TEST_P(CachingTest, TestCacheDirCreateRecursive) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { EXPECT_NO_THROW(ie.SetConfig({{CONFIG_KEY(CACHE_DIR), newCacheDir3}})); EXPECT_NO_THROW(m_testFunction(ie)); }); @@ -1345,15 +1377,16 @@ TEST_P(CachingTest, TestDeviceArchitecture) { EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()) - .WillRepeatedly(Invoke([&](const std::string&, const std::map& options) { - auto id = options.at("DEVICE_ID").as(); - if (std::stoi(id) < 10) { - return "mock_first_architecture"; - } else { - return "mock_another_architecture"; - } - })); + EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([&](const std::string&, const std::map& options) { + auto id = options.at("DEVICE_ID").as(); + if (std::stoi(id) < 10) { + return "mock_first_architecture"; + } else { + return "mock_another_architecture"; + } + })); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 1 : 0); @@ -1362,7 +1395,7 @@ TEST_P(CachingTest, TestDeviceArchitecture) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { deviceToLoad = "mock.0"; ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); @@ -1377,7 +1410,7 @@ TEST_P(CachingTest, TestDeviceArchitecture) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { deviceToLoad = "mock.1"; ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); @@ -1391,7 +1424,7 @@ TEST_P(CachingTest, TestDeviceArchitecture) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { deviceToLoad = "mock.50"; ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); @@ -1406,7 +1439,7 @@ TEST_P(CachingTest, TestDeviceArchitecture) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { deviceToLoad = "mock.51"; ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); @@ -1416,18 +1449,20 @@ TEST_P(CachingTest, TestDeviceArchitecture) { TEST_P(CachingTest, TestNoDeviceArchitecture) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)).Times(AnyNumber()) - .WillRepeatedly(Invoke([&] (const std::string&, const std::map&) { - return std::vector{ov::device::capabilities.name()}; - })); - EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)).Times(AnyNumber()) - .WillRepeatedly(Invoke([&] (const std::string&, const std::map&) { - return std::vector{METRIC_KEY(IMPORT_EXPORT_SUPPORT)}; - })); + EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([&](const std::string&, const std::map&) { + return std::vector{ov::device::capabilities.name()}; + })); + EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([&](const std::string&, const std::map&) { + return std::vector{METRIC_KEY(IMPORT_EXPORT_SUPPORT)}; + })); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)).Times(AnyNumber()). - WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{ - ov::device::capability::EXPORT_IMPORT})); + EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)) + .Times(AnyNumber()) + .WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{ov::device::capability::EXPORT_IMPORT})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(0); { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); @@ -1437,7 +1472,7 @@ TEST_P(CachingTest, TestNoDeviceArchitecture) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { deviceToLoad = "mock.0"; ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); @@ -1452,7 +1487,7 @@ TEST_P(CachingTest, TestNoDeviceArchitecture) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { deviceToLoad = "mock.50"; ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); @@ -1474,7 +1509,7 @@ TEST_P(CachingTest, TestThrowOnExport) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1).WillOnce(Throw(1)); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); EXPECT_ANY_THROW(m_testFunction(ie)); }); @@ -1497,7 +1532,7 @@ TEST_P(CachingTest, TestThrowOnImport) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -1516,12 +1551,12 @@ TEST_P(CachingTest, TestThrowOnImport) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); EXPECT_NO_THROW(m_testFunction(ie)); }); } - { // Step 3: same load, cache is re-created on export on step 2 and shall be successfully imported now + { // Step 3: same load, cache is re-created on export on step 2 and shall be successfully imported now EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(m_remoteContext ? 1 : 0); @@ -1529,7 +1564,7 @@ TEST_P(CachingTest, TestThrowOnImport) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); EXPECT_NO_THROW(m_testFunction(ie)); }); @@ -1550,7 +1585,7 @@ TEST_P(CachingTest, TestNetworkModified) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -1574,13 +1609,13 @@ TEST_P(CachingTest, TestNetworkModified) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); } m_post_mock_net_callbacks.pop_back(); - { // Step 3: same load, should be ok now + { // Step 3: same load, should be ok now EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(m_remoteContext ? 1 : 0); @@ -1588,7 +1623,7 @@ TEST_P(CachingTest, TestNetworkModified) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -1610,7 +1645,7 @@ TEST_P(CachingTest, TestCacheFileCorrupted) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { EXPECT_NO_THROW(ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}})); EXPECT_NO_THROW(m_testFunction(ie)); }); @@ -1623,7 +1658,7 @@ TEST_P(CachingTest, TestCacheFileCorrupted) { } } m_post_mock_net_callbacks.pop_back(); - { // Step 2. Cache is corrupted, will be silently removed + { // Step 2. Cache is corrupted, will be silently removed EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); @@ -1631,12 +1666,12 @@ TEST_P(CachingTest, TestCacheFileCorrupted) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { EXPECT_NO_THROW(ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}})); EXPECT_NO_THROW(m_testFunction(ie)); }); } - { // Step 3: same load, should be ok now due to re-creation of cache + { // Step 3: same load, should be ok now due to re-creation of cache EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(m_remoteContext ? 1 : 0); @@ -1644,7 +1679,7 @@ TEST_P(CachingTest, TestCacheFileCorrupted) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { EXPECT_NO_THROW(ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}})); EXPECT_NO_THROW(m_testFunction(ie)); }); @@ -1666,7 +1701,7 @@ TEST_P(CachingTest, TestCacheFileOldVersion) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { EXPECT_NO_THROW(ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}})); EXPECT_NO_THROW(m_testFunction(ie)); }); @@ -1687,14 +1722,14 @@ TEST_P(CachingTest, TestCacheFileOldVersion) { if (index != std::string::npos) { content.replace(index, buildNum.size(), zeroBuild); } else { - return; // skip test + return; // skip test } std::ofstream out(fileName, std::ios_base::binary); out.write(content.c_str(), static_cast(content.size())); } } m_post_mock_net_callbacks.pop_back(); - { // Step 2. Build number mismatch, cache will be silently removed + { // Step 2. Build number mismatch, cache will be silently removed EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 1 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); @@ -1702,13 +1737,13 @@ TEST_P(CachingTest, TestCacheFileOldVersion) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { EXPECT_NO_THROW(ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}})); EXPECT_NO_THROW(m_testFunction(ie)); }); } m_post_mock_net_callbacks.pop_back(); - { // Step 3: same load, should be ok now due to re-creation of cache + { // Step 3: same load, should be ok now due to re-creation of cache EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(m_remoteContext ? 1 : 0); @@ -1716,7 +1751,7 @@ TEST_P(CachingTest, TestCacheFileOldVersion) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { EXPECT_NO_THROW(ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}})); EXPECT_NO_THROW(m_testFunction(ie)); }); @@ -1726,16 +1761,19 @@ TEST_P(CachingTest, TestCacheFileOldVersion) { #if defined(ENABLE_HETERO) TEST_P(CachingTest, LoadHetero_NoCacheMetric) { EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS), _)) - .Times(AnyNumber()).WillRepeatedly(Return(std::vector{})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{})); EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(SUPPORTED_METRICS), _)) - .Times(AnyNumber()).WillRepeatedly(Return(std::vector{})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{})); EXPECT_CALL(*mockPlugin, GetMetric(ov::supported_properties.name(), _)) - .Times(AnyNumber()).WillRepeatedly(Return(std::vector{})); + .Times(AnyNumber()) + .WillRepeatedly(Return(std::vector{})); // Hetero supports Import/Export, but mock plugin does not deviceToLoad = CommonTestUtils::DEVICE_HETERO + std::string(":mock.1,mock.2"); if (m_remoteContext) { - return; // skip the remote Context test for Hetero plugin + return; // skip the remote Context test for Hetero plugin } for (int i = 0; i < 2; i++) { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(0); @@ -1745,7 +1783,7 @@ TEST_P(CachingTest, LoadHetero_NoCacheMetric) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); networks.clear(); @@ -1758,7 +1796,7 @@ TEST_P(CachingTest, LoadHetero_OneDevice) { EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); deviceToLoad = CommonTestUtils::DEVICE_HETERO + std::string(":mock"); if (m_remoteContext) { - return; // skip the remote Context test for Hetero plugin + return; // skip the remote Context test for Hetero plugin } { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(0); @@ -1768,7 +1806,7 @@ TEST_P(CachingTest, LoadHetero_OneDevice) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -1784,7 +1822,7 @@ TEST_P(CachingTest, LoadHetero_OneDevice) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); networks.clear(); @@ -1797,7 +1835,7 @@ TEST_P(CachingTest, LoadHetero_TargetFallbackFromCore) { EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); deviceToLoad = CommonTestUtils::DEVICE_HETERO; if (m_remoteContext) { - return; // skip the remote Context test for Hetero plugin + return; // skip the remote Context test for Hetero plugin } { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(0); @@ -1807,7 +1845,7 @@ TEST_P(CachingTest, LoadHetero_TargetFallbackFromCore) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); ie.SetConfig({{"TARGET_FALLBACK", "mock"}}, CommonTestUtils::DEVICE_HETERO); m_testFunction(ie); @@ -1824,7 +1862,7 @@ TEST_P(CachingTest, LoadHetero_TargetFallbackFromCore) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); ie.SetConfig({{"TARGET_FALLBACK", "mock"}}, CommonTestUtils::DEVICE_HETERO); m_testFunction(ie); @@ -1836,46 +1874,47 @@ TEST_P(CachingTest, LoadHetero_TargetFallbackFromCore) { TEST_P(CachingTest, LoadHetero_MultiArchs) { EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()).WillRepeatedly( - Invoke([&](const CNNNetwork &network, const std::map &config) { - QueryNetworkResult res; - auto function = network.getFunction(); - EXPECT_TRUE(function); + EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([&](const CNNNetwork& network, const std::map& config) { + QueryNetworkResult res; + auto function = network.getFunction(); + EXPECT_TRUE(function); - auto id = config.at("DEVICE_ID"); - bool supportsRelu = std::stoi(id) < 10; + auto id = config.at("DEVICE_ID"); + bool supportsRelu = std::stoi(id) < 10; - for (auto &&node : function->get_ops()) { - std::string nodeType = node->get_type_name(); - if ((nodeType == "Relu" && supportsRelu) || - (nodeType != "Relu" && !supportsRelu)) { - res.supportedLayersMap.emplace(node->get_friendly_name(), deviceName + "." + id); - } + for (auto&& node : function->get_ops()) { + std::string nodeType = node->get_type_name(); + if ((nodeType == "Relu" && supportsRelu) || (nodeType != "Relu" && !supportsRelu)) { + res.supportedLayersMap.emplace(node->get_friendly_name(), deviceName + "." + id); } - return res; - })); - EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()) - .WillRepeatedly(Invoke([&](const std::string &, const std::map &options) { - auto id = options.at("DEVICE_ID").as(); - if (std::stoi(id) < 10) { - return "mock_first_architecture"; - } else { - return "mock_another_architecture"; - } - })); + } + return res; + })); + EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([&](const std::string&, const std::map& options) { + auto id = options.at("DEVICE_ID").as(); + if (std::stoi(id) < 10) { + return "mock_first_architecture"; + } else { + return "mock_another_architecture"; + } + })); deviceToLoad = CommonTestUtils::DEVICE_HETERO + std::string(":mock.1,mock.51"); if (m_remoteContext) { - return; // skip the remote Context test for Hetero plugin + return; // skip the remote Context test for Hetero plugin } { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(0); - EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(AtLeast(2)); // for .1 and for .51 + EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(AtLeast(2)); // for .1 and for .51 EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(0); m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(AtLeast(1)); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -1888,11 +1927,11 @@ TEST_P(CachingTest, LoadHetero_MultiArchs) { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); - EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(AtLeast(2)); // for .2 and for .52 + EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(AtLeast(2)); // for .2 and for .52 for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -1907,7 +1946,7 @@ TEST_P(CachingTest, LoadHetero_MultiArchs) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(AtLeast(1)); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); networks.clear(); @@ -1918,18 +1957,19 @@ TEST_P(CachingTest, LoadHetero_MultiArchs) { TEST_P(CachingTest, LoadHetero_MultiArchs_TargetFallback_FromCore) { EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()) - .WillRepeatedly(Invoke([&](const std::string &, const std::map &options) { - auto id = options.at("DEVICE_ID").as(); - if (std::stoi(id) < 10) { - return "mock_first_architecture"; - } else { - return "mock_another_architecture"; - } - })); + EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([&](const std::string&, const std::map& options) { + auto id = options.at("DEVICE_ID").as(); + if (std::stoi(id) < 10) { + return "mock_first_architecture"; + } else { + return "mock_another_architecture"; + } + })); deviceToLoad = CommonTestUtils::DEVICE_HETERO; if (m_remoteContext) { - return; // skip the remote Context test for Hetero plugin + return; // skip the remote Context test for Hetero plugin } { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(0); @@ -1939,7 +1979,7 @@ TEST_P(CachingTest, LoadHetero_MultiArchs_TargetFallback_FromCore) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); ie.SetConfig({{"TARGET_FALLBACK", "mock.1"}}, CommonTestUtils::DEVICE_HETERO); m_testFunction(ie); @@ -1954,7 +1994,7 @@ TEST_P(CachingTest, LoadHetero_MultiArchs_TargetFallback_FromCore) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{"TARGET_FALLBACK", "mock.1"}}, CommonTestUtils::DEVICE_HETERO); ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); @@ -1968,7 +2008,7 @@ TEST_P(CachingTest, LoadHetero_MultiArchs_TargetFallback_FromCore) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(1); }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{"TARGET_FALLBACK", "mock.51"}}, CommonTestUtils::DEVICE_HETERO); ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); @@ -1976,18 +2016,18 @@ TEST_P(CachingTest, LoadHetero_MultiArchs_TargetFallback_FromCore) { }); } } -#endif //define(ENABLE_HETERO) +#endif // define(ENABLE_HETERO) #if defined(ENABLE_AUTO) -//AUTO-DEVICE test -//Single device +// AUTO-DEVICE test +// Single device TEST_P(CachingTest, LoadAUTO_OneDevice) { const auto TEST_COUNT = 2; EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); if (m_remoteContext) { - return; // skip the remote Context test for Auto plugin + return; // skip the remote Context test for Auto plugin } int index = 0; m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { @@ -2000,22 +2040,22 @@ TEST_P(CachingTest, LoadAUTO_OneDevice) { deviceToLoad += ":mock.0"; EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(TEST_COUNT - index - 1); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(index); - ASSERT_NO_THROW(testLoad([&](Core &ie) { + ASSERT_NO_THROW(testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), cacheDir}}); m_testFunction(ie); })); } std::cout << "Caching LoadAuto Test completed. Tried " << index << " times" << std::endl; } -//AUTO-DEVICE test -//load network with config +// AUTO-DEVICE test +// load network with config TEST_P(CachingTest, LoadAUTOWithConfig) { const auto TEST_COUNT = 2; EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); if (m_remoteContext) { - return; // skip the remote Context test for Auto plugin + return; // skip the remote Context test for Auto plugin } int index = 0; m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { @@ -2028,30 +2068,32 @@ TEST_P(CachingTest, LoadAUTOWithConfig) { deviceToLoad += ":mock.0"; EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(TEST_COUNT - index - 1); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(index); - ASSERT_NO_THROW(testLoad([&](Core &ie) { + ASSERT_NO_THROW(testLoad([&](Core& ie) { m_testFunctionWithCfg(ie, {{CONFIG_KEY(CACHE_DIR), cacheDir}}); })); } std::cout << "Caching LoadAuto Test completed. Tried " << index << " times" << std::endl; } -//Single device not support import/export +// Single device not support import/export TEST_P(CachingTest, LoadAUTO_OneDeviceNoImportExport) { EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)) - .Times(AnyNumber()).WillRepeatedly(Return(false)); - EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)).Times(AnyNumber()). - WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{})); + .Times(AnyNumber()) + .WillRepeatedly(Return(false)); + EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)) + .Times(AnyNumber()) + .WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{})); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); if (m_remoteContext) { - return; // skip the remote Context test for Auto plugin + return; // skip the remote Context test for Auto plugin } EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 2 : 0); EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 2 : 0); EXPECT_CALL(*mockPlugin, OnLoadNetworkFromFile()).Times(m_type == TestLoadType::EModelName ? 2 : 0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(0); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, Export(_)).Times(0); }); @@ -2076,7 +2118,7 @@ TEST_P(CachingTest, LoadMulti_race) { EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); if (m_remoteContext) { - return; // skip the remote Context test for Multi plugin + return; // skip the remote Context test for Multi plugin } int index = 0; auto start = high_resolution_clock::now(); @@ -2086,7 +2128,7 @@ TEST_P(CachingTest, LoadMulti_race) { do { std::string cacheDir = m_cacheDir + std::to_string(index); MkDirGuard guard(cacheDir); - int devCount = 1 + index % (TEST_DEVICE_MAX_COUNT - 1); // try dynamic number of devices from 1 to max + int devCount = 1 + index % (TEST_DEVICE_MAX_COUNT - 1); // try dynamic number of devices from 1 to max deviceToLoad = CommonTestUtils::DEVICE_MULTI; deviceToLoad += ":mock.0"; for (int i = 1; i < devCount; i++) { @@ -2097,7 +2139,7 @@ TEST_P(CachingTest, LoadMulti_race) { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(1); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(devCount - 1); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), cacheDir}}); ASSERT_NO_THROW(m_testFunction(ie)); }); @@ -2116,7 +2158,7 @@ TEST_P(CachingTest, LoadMultiWithConfig_race) { EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); if (m_remoteContext) { - return; // skip the remote Context test for Multi plugin + return; // skip the remote Context test for Multi plugin } int index = 0; auto start = high_resolution_clock::now(); @@ -2126,7 +2168,7 @@ TEST_P(CachingTest, LoadMultiWithConfig_race) { do { std::string cacheDir = m_cacheDir + std::to_string(index); MkDirGuard guard(cacheDir); - int devCount = 1 + index % (TEST_DEVICE_MAX_COUNT - 1); // try dynamic number of devices from 1 to max + int devCount = 1 + index % (TEST_DEVICE_MAX_COUNT - 1); // try dynamic number of devices from 1 to max deviceToLoad = CommonTestUtils::DEVICE_MULTI; deviceToLoad += ":mock.0"; for (int i = 1; i < devCount; i++) { @@ -2137,7 +2179,7 @@ TEST_P(CachingTest, LoadMultiWithConfig_race) { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(1); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(devCount - 1); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ASSERT_NO_THROW(m_testFunctionWithCfg(ie, {{CONFIG_KEY(CACHE_DIR), cacheDir}})); }); index++; @@ -2149,17 +2191,18 @@ TEST_P(CachingTest, LoadMultiWithConfig_race) { // Test loading of devices with different architectures // In case of sporadic failures - increase 'TEST_DEVICE_MAX_COUNT' 100x times for better reproducibility TEST_P(CachingTest, LoadMulti_Archs) { - const auto TEST_DEVICE_MAX_COUNT = 30; // Shall be >= 2 + const auto TEST_DEVICE_MAX_COUNT = 30; // Shall be >= 2 EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); - EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()) - .WillRepeatedly(Invoke([&](const std::string &, const std::map &options) { - auto id = options.at("DEVICE_ID").as(); - auto i = std::stoi(id) / 2; - return "mock_architecture" + std::to_string(i); - })); + EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)) + .Times(AnyNumber()) + .WillRepeatedly(Invoke([&](const std::string&, const std::map& options) { + auto id = options.at("DEVICE_ID").as(); + auto i = std::stoi(id) / 2; + return "mock_architecture" + std::to_string(i); + })); if (m_remoteContext) { - return; // skip the remote Context test for Multi plugin + return; // skip the remote Context test for Multi plugin } deviceToLoad = CommonTestUtils::DEVICE_MULTI; @@ -2175,17 +2218,18 @@ TEST_P(CachingTest, LoadMulti_Archs) { EXPECT_CALL(*mockPlugin, OnLoadNetworkFromFile()).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); - EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(TEST_DEVICE_MAX_COUNT / 2) - .WillRepeatedly(Invoke([&](std::istream &s, const std::map &) { - std::string name; - s >> name; - std::lock_guard lock(mock_creation_mutex); - return createMockIExecutableNet({}, m_inputs_map[name], m_outputs_map[name]); - })); + EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)) + .Times(TEST_DEVICE_MAX_COUNT / 2) + .WillRepeatedly(Invoke([&](std::istream& s, const std::map&) { + std::string name; + s >> name; + std::lock_guard lock(mock_creation_mutex); + return createMockIExecutableNet({}, m_inputs_map[name], m_outputs_map[name]); + })); m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { - EXPECT_CALL(net, Export(_)).Times(1); // each net will be exported once + EXPECT_CALL(net, Export(_)).Times(1); // each net will be exported once }); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); m_testFunction(ie); }); @@ -2196,12 +2240,14 @@ TEST_P(CachingTest, LoadMulti_Archs) { // Test loading of devices which don't support caching // In case of sporadic failures - increase 'TEST_DEVICE_MAX_COUNT' 100x times for better reproducibility TEST_P(CachingTest, LoadMulti_NoCachingOnDevice) { - const auto TEST_DEVICE_MAX_COUNT = 100; // Looks enough to catch potential race conditions + const auto TEST_DEVICE_MAX_COUNT = 100; // Looks enough to catch potential race conditions EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)) - .Times(AnyNumber()).WillRepeatedly(Return(Parameter{false})); + .Times(AnyNumber()) + .WillRepeatedly(Return(Parameter{false})); EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)) - .Times(AnyNumber()).WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{})); + .Times(AnyNumber()) + .WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{})); EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); @@ -2209,15 +2255,15 @@ TEST_P(CachingTest, LoadMulti_NoCachingOnDevice) { InputInfo inpInfo; inpInfo.setInputData(inData); InputInfo::CPtr cptr = std::make_shared(inpInfo); - ConstInputsDataMap inputMap {{"Param_1", cptr}}; + ConstInputsDataMap inputMap{{"Param_1", cptr}}; CDataPtr dataptr = std::make_shared("Reshape_2", Precision::FP32); - ConstOutputsDataMap outputMap {{"Reshape_2", dataptr}}; + ConstOutputsDataMap outputMap{{"Reshape_2", dataptr}}; m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { EXPECT_CALL(net, GetInputsInfo()).Times(AnyNumber()).WillRepeatedly(Return(inputMap)); EXPECT_CALL(net, GetOutputsInfo()).Times(AnyNumber()).WillRepeatedly(Return(outputMap)); }); if (m_remoteContext) { - return; // skip the remote Context test for Multi plugin + return; // skip the remote Context test for Multi plugin } deviceToLoad = CommonTestUtils::DEVICE_MULTI; @@ -2237,7 +2283,7 @@ TEST_P(CachingTest, LoadMulti_NoCachingOnDevice) { for (auto& net : networks) { EXPECT_CALL(*net, Export(_)).Times(0); } - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); ExecutableNetwork exeNet; exeNet = m_testFunction(ie); @@ -2248,18 +2294,18 @@ TEST_P(CachingTest, LoadMulti_NoCachingOnDevice) { }); } } -#endif //defined(ENABLE_AUTO) +#endif // defined(ENABLE_AUTO) #if defined(ENABLE_AUTO_BATCH) -//BATCH-DEVICE test -//load network with config +// BATCH-DEVICE test +// load network with config TEST_P(CachingTest, LoadBATCHWithConfig) { const auto TEST_COUNT = 2; EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); if (m_remoteContext) { - return; // skip the remote Context test for Auto plugin + return; // skip the remote Context test for Auto plugin } int index = 0; m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { @@ -2272,13 +2318,13 @@ TEST_P(CachingTest, LoadBATCHWithConfig) { deviceToLoad += ":mock.0"; EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(TEST_COUNT - index - 1); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(index); - ASSERT_NO_THROW(testLoad([&](Core &ie) { + ASSERT_NO_THROW(testLoad([&](Core& ie) { m_testFunctionWithCfg(ie, {{CONFIG_KEY(CACHE_DIR), cacheDir}}); })); } std::cout << "Caching LoadAuto Test completed. Tried " << index << " times" << std::endl; } -#endif //defined(ENABLE_AUTO_BATCH) +#endif // defined(ENABLE_AUTO_BATCH) // In case of sporadic failures - increase 'TEST_DURATION_MS' 100x times for better reproducibility TEST_P(CachingTest, Load_threads) { @@ -2288,7 +2334,7 @@ TEST_P(CachingTest, Load_threads) { EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); if (m_remoteContext) { - return; // skip the remote Context test for Multi plugin + return; // skip the remote Context test for Multi plugin } auto start = high_resolution_clock::now(); int index = 0; @@ -2302,11 +2348,13 @@ TEST_P(CachingTest, Load_threads) { EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(1); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(THREADS_COUNT - 1); - testLoad([&](Core &ie) { + testLoad([&](Core& ie) { ie.SetConfig({{CONFIG_KEY(CACHE_DIR), cacheDir}}); std::vector threads; for (int i = 0; i < THREADS_COUNT; i++) { - threads.emplace_back(([&]() { m_testFunction(ie); })); + threads.emplace_back(([&]() { + m_testFunction(ie); + })); } for (int i = 0; i < THREADS_COUNT; i++) { threads[i].join(); @@ -2318,9 +2366,8 @@ TEST_P(CachingTest, Load_threads) { } #if defined(ENABLE_OV_IR_FRONTEND) -INSTANTIATE_TEST_SUITE_P(CachingTest, CachingTest, - ::testing::Combine( - ::testing::ValuesIn(loadVariants), - ::testing::ValuesIn(cacheFolders)), - getTestCaseName); -#endif //defined(ENABLE_OV_IR_FRONTEND) +INSTANTIATE_TEST_SUITE_P(CachingTest, + CachingTest, + ::testing::Combine(::testing::ValuesIn(loadVariants), ::testing::ValuesIn(cacheFolders)), + getTestCaseName); +#endif // defined(ENABLE_OV_IR_FRONTEND) \ No newline at end of file diff --git a/src/inference/tests/functional/caseless_tests.cpp b/src/inference/tests/functional/caseless_tests.cpp index 8a46141956e..2eb79ea0539 100644 --- a/src/inference/tests/functional/caseless_tests.cpp +++ b/src/inference/tests/functional/caseless_tests.cpp @@ -3,7 +3,9 @@ // #include + #include + #include "caseless.hpp" #include "debug.h" @@ -39,7 +41,7 @@ TEST_F(CaselessTests, canFindCaslessInMap) { } TEST_F(CaselessTests, canFindCaslessInUnordered) { - caseless_unordered_map storage = { + caseless_unordered_map storage = { {"Abc", 1}, {"bC", 2}, {"AbcD", 3}, diff --git a/src/inference/tests/functional/cnn_network_test.cpp b/src/inference/tests/functional/cnn_network_test.cpp index d9a3648ff51..d0fe20c2890 100644 --- a/src/inference/tests/functional/cnn_network_test.cpp +++ b/src/inference/tests/functional/cnn_network_test.cpp @@ -3,11 +3,13 @@ // #include + +#include + #include "cpp/ie_cnn_network.h" #include "inference_engine.hpp" #include "openvino/opsets/opset.hpp" #include "openvino/pass/serialize.hpp" -#include #include "openvino/util/file_util.hpp" using namespace InferenceEngine; @@ -82,13 +84,13 @@ static std::shared_ptr CNNNetworkTests_create_model() { auto param1 = std::make_shared(ov::element::f32, ov::PartialShape::dynamic()); param1->set_friendly_name("p1_friendly"); param1->output(0).set_names({"p1_1", "p1_2"}); - auto param2 = std::make_shared(ov::element::f32, ov::PartialShape {-1, 3, 224, 224}); + auto param2 = std::make_shared(ov::element::f32, ov::PartialShape{-1, 3, 224, 224}); param2->set_friendly_name("p2_friendly"); param2->output(0).set_names({"p2_1", "p2_2"}); - auto param3 = std::make_shared(ov::element::f32, ov::PartialShape {1, 3, 224, 224}); + auto param3 = std::make_shared(ov::element::f32, ov::PartialShape{1, 3, 224, 224}); param3->set_friendly_name("p3_friendly"); param3->output(0).set_names({"p3_1", "p3_2"}); - return std::make_shared(ov::OutputVector {param1, param2, param3}, + return std::make_shared(ov::OutputVector{param1, param2, param3}, ov::ParameterVector{param1, param2, param3}); } @@ -151,12 +153,15 @@ protected: std::string modelName = "CNNNetworkTests_LoadFromFileTest.xml"; std::string weightsName = "CNNNetworkTests_LoadFromFileTest.bin"; InferenceEngine::Core core; + public: void SetUp() override { std::shared_ptr model = CNNNetworkTests_create_model(); ov::pass::Serialize(modelName, weightsName).run_on_model(model); - ASSERT_NO_THROW(core.RegisterPlugin(ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), "mock")); + ASSERT_NO_THROW( + core.RegisterPlugin(ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), + std::string("mock_engine") + IE_BUILD_POSTFIX), + "mock")); } void TearDown() override { @@ -179,5 +184,4 @@ TEST_F(CNNNetworkTests_LoadFromFileTest, throwsHasDynamicInputs_fromPath) { EXPECT_TRUE(std::string(e.what()).find("p3_2") == std::string::npos) << e.what(); } } -#endif //defined(ENABLE_OV_IR_FRONTEND) - +#endif // defined(ENABLE_OV_IR_FRONTEND) diff --git a/src/inference/tests/functional/cnn_ngraph_impl_tests.cpp b/src/inference/tests/functional/cnn_ngraph_impl_tests.cpp index 870a9840660..231987a2c0d 100644 --- a/src/inference/tests/functional/cnn_ngraph_impl_tests.cpp +++ b/src/inference/tests/functional/cnn_ngraph_impl_tests.cpp @@ -2,46 +2,44 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - -#include -#include -#include -#include -#include -#include -#include - #include -#include -#include -#include +#include #include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include -#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include +#include +#include -#include "common_test_utils/file_utils.hpp" +#include "cnn_network_ngraph_impl.hpp" #include "common_test_utils/common_utils.hpp" +#include "common_test_utils/file_utils.hpp" #include "ie_precision.hpp" #include "transformations/rt_info/primitives_priority_attribute.hpp" -#include "cnn_network_ngraph_impl.hpp" using namespace testing; using namespace InferenceEngine; @@ -107,10 +105,17 @@ TEST(CNNNGraphImplTests, TestNMS5OutputNames) { auto max_output_boxes_per_class = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{}, {10}); auto iou_threshold = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.75}); auto score_threshold = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.7}); - auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold, - ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER, true); + auto nms = std::make_shared( + boxes, + scores, + max_output_boxes_per_class, + iou_threshold, + score_threshold, + ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER, + true); nms->set_friendly_name("nms"); - f = std::make_shared(ngraph::OutputVector{nms->output(0), nms->output(1), nms->output(2)}, ngraph::ParameterVector{boxes, scores}); + f = std::make_shared(ngraph::OutputVector{nms->output(0), nms->output(1), nms->output(2)}, + ngraph::ParameterVector{boxes, scores}); } InferenceEngine::CNNNetwork cnnNet(f); @@ -286,7 +291,8 @@ TEST(CNNNGraphImplTests, TestSetBatchScalar) { TEST(CNNNGraphImplTests, TestGetBatchDynamic) { std::shared_ptr ngraph; { - auto param = std::make_shared(ngraph::element::Type_t::f32, ngraph::PartialShape{5, ngraph::Dimension::dynamic()}); + auto param = std::make_shared(ngraph::element::Type_t::f32, + ngraph::PartialShape{5, ngraph::Dimension::dynamic()}); auto relu = std::make_shared(param); auto result = std::make_shared(relu); ngraph = std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{param}); @@ -300,7 +306,8 @@ TEST(CNNNGraphImplTests, TestGetBatchDynamic) { TEST(CNNNGraphImplTests, TestSetBatchDynamic) { std::shared_ptr ngraph; { - auto param = std::make_shared(ngraph::element::Type_t::f32, ngraph::PartialShape::dynamic()); + auto param = + std::make_shared(ngraph::element::Type_t::f32, ngraph::PartialShape::dynamic()); auto relu = std::make_shared(param); auto result = std::make_shared(relu); ngraph = std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{param}); @@ -314,7 +321,8 @@ TEST(CNNNGraphImplTests, TestSetBatchDynamic) { TEST(CNNNGraphImplTests, TestDoesChangePrecisionsWithNewAPI) { std::shared_ptr ngraph; { - auto param = std::make_shared(ngraph::element::Type_t::f16, ngraph::PartialShape::dynamic()); + auto param = + std::make_shared(ngraph::element::Type_t::f16, ngraph::PartialShape::dynamic()); auto relu = std::make_shared(param); auto result = std::make_shared(relu); ngraph = std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{param}); @@ -322,13 +330,15 @@ TEST(CNNNGraphImplTests, TestDoesChangePrecisionsWithNewAPI) { // new OpenVINO 2.0 { - auto ngraphImpl = std::make_shared(ngraph, - std::vector{}, true); + auto ngraphImpl = std::make_shared( + ngraph, + std::vector{}, + true); InferenceEngine::CNNNetwork cnnNet(ngraphImpl); ASSERT_EQ(InferenceEngine::Precision::FP16, - cnnNet.getInputsInfo().begin()->second->getTensorDesc().getPrecision()); + cnnNet.getInputsInfo().begin()->second->getTensorDesc().getPrecision()); ASSERT_EQ(InferenceEngine::Precision::FP16, - cnnNet.getOutputsInfo().begin()->second->getTensorDesc().getPrecision()); + cnnNet.getOutputsInfo().begin()->second->getTensorDesc().getPrecision()); } // current API @@ -336,9 +346,9 @@ TEST(CNNNGraphImplTests, TestDoesChangePrecisionsWithNewAPI) { auto ngraphImpl = std::make_shared(ngraph); InferenceEngine::CNNNetwork cnnNet(ngraphImpl); ASSERT_EQ(InferenceEngine::Precision::FP32, - cnnNet.getInputsInfo().begin()->second->getTensorDesc().getPrecision()); + cnnNet.getInputsInfo().begin()->second->getTensorDesc().getPrecision()); ASSERT_EQ(InferenceEngine::Precision::FP32, - cnnNet.getOutputsInfo().begin()->second->getTensorDesc().getPrecision()); + cnnNet.getOutputsInfo().begin()->second->getTensorDesc().getPrecision()); } } @@ -737,13 +747,13 @@ TEST(CNNNGraphImplTests, ReadMeanImageFromCNNNetReader) { )V0G0N"; InferenceEngine::Core core; - size_t hwSize = 22*22; - size_t dataSize = hwSize*3; + size_t hwSize = 22 * 22; + size_t dataSize = hwSize * 3; Blob::Ptr weights = make_shared_blob(TensorDesc(Precision::FP32, {dataSize}, Layout::C)); weights->allocate(); { auto lockData = weights->buffer(); - float *dataPtr = lockData.as(); + float* dataPtr = lockData.as(); for (size_t i = 0; i < dataSize; ++i) { dataPtr[i] = 1; @@ -753,7 +763,7 @@ TEST(CNNNGraphImplTests, ReadMeanImageFromCNNNetReader) { auto f = network.getFunction(); std::shared_ptr f_ref; - auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 22, 22}); + auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 22, 22}); { auto mean_image = ngraph::opset1::Constant::create(ngraph::element::f32, ngraph::Shape{3, 22, 22}, {1}); auto sub = std::make_shared(data, mean_image); @@ -837,15 +847,16 @@ TEST(CNNNGraphImplTests, ReadMeanValueFromCNNNetReader) { std::shared_ptr f_ref; { auto data = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 3, 22, 22}); - auto mean_image = ngraph::opset1::Constant::create(ngraph::element::f32, ngraph::Shape{3, 1, 1}, {1.1, 2.2, 3.3}); + auto mean_image = + ngraph::opset1::Constant::create(ngraph::element::f32, ngraph::Shape{3, 1, 1}, {1.1, 2.2, 3.3}); auto sub = std::make_shared(data, mean_image); auto relu = std::make_shared(sub); f_ref = std::make_shared(ngraph::NodeVector{relu}, ngraph::ParameterVector{data}); } const auto fc = FunctionsComparator::with_default() - .enable(FunctionsComparator::ATTRIBUTES) - .enable(FunctionsComparator::CONST_VALUES); + .enable(FunctionsComparator::ATTRIBUTES) + .enable(FunctionsComparator::CONST_VALUES); const auto res = fc.compare(f, f_ref); EXPECT_TRUE(res.valid) << res.message; } @@ -871,8 +882,7 @@ TEST(CNNNGraphImplTests, CanChangeInputPrecision) { const auto inputsInfo = cnnNet.getInputsInfo(); - ASSERT_EQ(inputsInfo.at("input")->getPrecision(), Precision::FP32) - << "FP32 is default presision"; + ASSERT_EQ(inputsInfo.at("input")->getPrecision(), Precision::FP32) << "FP32 is default presision"; } { SCOPED_TRACE("Manually set input precision"); @@ -886,8 +896,8 @@ TEST(CNNNGraphImplTests, CanChangeInputPrecision) { SCOPED_TRACE("Convert to old format"); // convert to old representation - convertedNetwork = InferenceEngine::CNNNetwork( - std::make_shared(cnnNet)); + convertedNetwork = + InferenceEngine::CNNNetwork(std::make_shared(cnnNet)); } { SCOPED_TRACE("After conversion"); @@ -895,7 +905,7 @@ TEST(CNNNGraphImplTests, CanChangeInputPrecision) { const auto inputsInfo = convertedNetwork.getInputsInfo(); ASSERT_EQ(inputsInfo.at("input")->getPrecision(), Precision::FP16) - << "Manually set presision should be left unchanged"; + << "Manually set presision should be left unchanged"; } } @@ -920,8 +930,7 @@ TEST(CNNNGraphImplTests, CanChangeInputLayout) { const auto inputsInfo = cnnNet.getInputsInfo(); - ASSERT_EQ(inputsInfo.at("input")->getLayout(), Layout::NCHW) - << "NCHW is default layout"; + ASSERT_EQ(inputsInfo.at("input")->getLayout(), Layout::NCHW) << "NCHW is default layout"; } { SCOPED_TRACE("Manually set input layout"); @@ -935,16 +944,15 @@ TEST(CNNNGraphImplTests, CanChangeInputLayout) { SCOPED_TRACE("Convert to old format"); // convert to old representation - convertedNetwork = InferenceEngine::CNNNetwork( - std::make_shared(cnnNet)); + convertedNetwork = + InferenceEngine::CNNNetwork(std::make_shared(cnnNet)); } { SCOPED_TRACE("After conversion"); const auto inputsInfo = convertedNetwork.getInputsInfo(); - ASSERT_EQ(inputsInfo.at("input")->getLayout(), Layout::NHWC) - << "Manually set layout should be left unchanged"; + ASSERT_EQ(inputsInfo.at("input")->getLayout(), Layout::NHWC) << "Manually set layout should be left unchanged"; } } @@ -969,8 +977,7 @@ TEST(CNNNGraphImplTests, CanChangeOutputPrecision) { const auto outputsInfo = cnnNet.getOutputsInfo(); - ASSERT_EQ(outputsInfo.at("output")->getPrecision(), Precision::FP32) - << "FP32 is default presision"; + ASSERT_EQ(outputsInfo.at("output")->getPrecision(), Precision::FP32) << "FP32 is default presision"; } { SCOPED_TRACE("Manually set output precision"); @@ -984,8 +991,8 @@ TEST(CNNNGraphImplTests, CanChangeOutputPrecision) { SCOPED_TRACE("Convert to old format"); // convert to old representation - convertedNetwork = InferenceEngine::CNNNetwork( - std::make_shared(cnnNet)); + convertedNetwork = + InferenceEngine::CNNNetwork(std::make_shared(cnnNet)); } { SCOPED_TRACE("After conversion"); @@ -993,7 +1000,7 @@ TEST(CNNNGraphImplTests, CanChangeOutputPrecision) { const auto outputsInfo = convertedNetwork.getOutputsInfo(); ASSERT_EQ(outputsInfo.at("output")->getPrecision(), Precision::FP16) - << "Manually set presision should be left unchanged"; + << "Manually set presision should be left unchanged"; } } @@ -1018,8 +1025,7 @@ TEST(CNNNGraphImplTests, CanChangeOutputLayout) { const auto outputsInfo = cnnNet.getOutputsInfo(); - ASSERT_EQ(outputsInfo.at("output")->getLayout(), Layout::NCHW) - << "NCHW is default layout"; + ASSERT_EQ(outputsInfo.at("output")->getLayout(), Layout::NCHW) << "NCHW is default layout"; } { SCOPED_TRACE("Manually set output layout"); @@ -1033,8 +1039,8 @@ TEST(CNNNGraphImplTests, CanChangeOutputLayout) { SCOPED_TRACE("Convert to old format"); // convert to old representation - convertedNetwork = InferenceEngine::CNNNetwork( - std::make_shared(cnnNet)); + convertedNetwork = + InferenceEngine::CNNNetwork(std::make_shared(cnnNet)); } { SCOPED_TRACE("After conversion"); @@ -1042,7 +1048,7 @@ TEST(CNNNGraphImplTests, CanChangeOutputLayout) { const auto outputsInfo = convertedNetwork.getOutputsInfo(); ASSERT_EQ(outputsInfo.at("output")->getLayout(), Layout::NHWC) - << "Manually set layout should be left unchanged"; + << "Manually set layout should be left unchanged"; } } @@ -1068,8 +1074,9 @@ TEST(CNNNGraphImplTests, CanSetBatchReadValue) { std::shared_ptr ngraph; { auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 2}); - auto constant = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 2}, - std::vector{1, 2}); + auto constant = std::make_shared(ngraph::element::f32, + ngraph::Shape{1, 2}, + std::vector{1, 2}); auto read_value = std::make_shared(constant, "variable_id"); auto assign = std::make_shared(read_value, "variable_id"); @@ -1469,7 +1476,7 @@ TEST(CNNNGraphImplTests, AddOutputToExperimentalOp) { } TEST(CNNNGraphImplTests, SaveOriginalResultNameForMultiOutputOp) { - std::string model = R"V0G0N( + std::string model = R"V0G0N( @@ -1630,7 +1637,7 @@ TEST(CNNNGraphImplTests, SaveOriginalResultNameForMultiOutputOp) { data->allocate(); { auto lockData = data->buffer(); - float *dataPtr = lockData.as(); + float* dataPtr = lockData.as(); for (size_t i = 0; i < 4; ++i) { dataPtr[i] = 0; @@ -1657,7 +1664,7 @@ TEST(CNNNGraphImplTests, SaveOriginalResultNameForMultiOutputOp) { } TEST(CNNNGraphImplTests, SaveOriginalResultNameForMultiOutputOpOpset6) { - std::string model = R"V0G0N( + std::string model = R"V0G0N( @@ -1818,7 +1825,7 @@ TEST(CNNNGraphImplTests, SaveOriginalResultNameForMultiOutputOpOpset6) { data->allocate(); { auto lockData = data->buffer(); - float *dataPtr = lockData.as(); + float* dataPtr = lockData.as(); for (size_t i = 0; i < 4; ++i) { dataPtr[i] = 0; @@ -1856,8 +1863,14 @@ TEST(CNNNGraphImplTests, CheckUniqueNames) { auto max_output_boxes_per_class = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{}, {10}); auto iou_threshold = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.75}); auto score_threshold = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.7}); - auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold, - ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER, true); + auto nms = std::make_shared( + boxes, + scores, + max_output_boxes_per_class, + iou_threshold, + score_threshold, + ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER, + true); auto result1 = std::make_shared(nms->output(0)); result1->set_friendly_name("result1"); @@ -1866,7 +1879,8 @@ TEST(CNNNGraphImplTests, CheckUniqueNames) { auto result3 = std::make_shared(nms->output(2)); result3->set_friendly_name("result3"); nms->set_friendly_name("nms"); - f = std::make_shared(ngraph::ResultVector{result1, result2, result3}, ngraph::ParameterVector{boxes, scores}); + f = std::make_shared(ngraph::ResultVector{result1, result2, result3}, + ngraph::ParameterVector{boxes, scores}); } ASSERT_NO_THROW(InferenceEngine::CNNNetwork{f}); @@ -1882,8 +1896,14 @@ TEST(CNNNGraphImplTests, CheckNonUniqueParameterName) { auto max_output_boxes_per_class = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{}, {10}); auto iou_threshold = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.75}); auto score_threshold = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.7}); - auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold, - ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER, true); + auto nms = std::make_shared( + boxes, + scores, + max_output_boxes_per_class, + iou_threshold, + score_threshold, + ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER, + true); auto result1 = std::make_shared(nms->output(0)); result1->set_friendly_name("result1"); @@ -1892,7 +1912,8 @@ TEST(CNNNGraphImplTests, CheckNonUniqueParameterName) { auto result3 = std::make_shared(nms->output(2)); result3->set_friendly_name("result3"); nms->set_friendly_name("nms"); - f = std::make_shared(ngraph::ResultVector{result1, result2, result3}, ngraph::ParameterVector{boxes, scores}); + f = std::make_shared(ngraph::ResultVector{result1, result2, result3}, + ngraph::ParameterVector{boxes, scores}); } ASSERT_THROW(InferenceEngine::CNNNetwork{f}, InferenceEngine::Exception); @@ -1908,8 +1929,14 @@ TEST(CNNNGraphImplTests, CheckNonUniqueResultName) { auto max_output_boxes_per_class = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{}, {10}); auto iou_threshold = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.75}); auto score_threshold = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.7}); - auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold, - ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER, true); + auto nms = std::make_shared( + boxes, + scores, + max_output_boxes_per_class, + iou_threshold, + score_threshold, + ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER, + true); auto result1 = std::make_shared(nms->output(0)); result1->set_friendly_name("result1"); @@ -1918,7 +1945,8 @@ TEST(CNNNGraphImplTests, CheckNonUniqueResultName) { auto result3 = std::make_shared(nms->output(2)); result3->set_friendly_name("result3"); nms->set_friendly_name("nms"); - f = std::make_shared(ngraph::ResultVector{result1, result2, result3}, ngraph::ParameterVector{boxes, scores}); + f = std::make_shared(ngraph::ResultVector{result1, result2, result3}, + ngraph::ParameterVector{boxes, scores}); } ASSERT_THROW(InferenceEngine::CNNNetwork{f}, InferenceEngine::Exception); @@ -1934,18 +1962,24 @@ TEST(CNNNGraphImplTests, CheckNonUniqueNewResultName) { auto max_output_boxes_per_class = ngraph::opset5::Constant::create(ngraph::element::i64, ngraph::Shape{}, {10}); auto iou_threshold = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.75}); auto score_threshold = ngraph::opset5::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.7}); - auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold, - ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER, true); + auto nms = std::make_shared( + boxes, + scores, + max_output_boxes_per_class, + iou_threshold, + score_threshold, + ngraph::opset5::NonMaxSuppression::BoxEncodingType::CORNER, + true); auto result1 = std::make_shared(nms->output(0)); result1->set_friendly_name("result1"); auto result3 = std::make_shared(nms->output(2)); result3->set_friendly_name("result3"); nms->set_friendly_name("nms"); - f = std::make_shared(ngraph::ResultVector{result1, result3}, ngraph::ParameterVector{boxes, scores}); + f = std::make_shared(ngraph::ResultVector{result1, result3}, + ngraph::ParameterVector{boxes, scores}); } - CNNNetwork cnnNet; ASSERT_NO_THROW(cnnNet = InferenceEngine::CNNNetwork{f}); ASSERT_THROW(cnnNet.addOutput("nms", 1), InferenceEngine::Exception); @@ -1960,7 +1994,8 @@ TEST(CNNNGraphImplTests, RemoveLoopDanglingParametersIfConcatEmptyTensor) { auto a = std::make_shared(ov::element::f32, ov::Shape{2, 2}); auto ai = std::make_shared(ov::element::f32, ov::Shape{2, 2}); auto b = std::make_shared(ov::element::f32, ov::Shape{2}); - auto b_broadcast = std::make_shared(b, ov::opset8::Constant::create(ngraph::element::i64, {2}, {0, 2})); + auto b_broadcast = + std::make_shared(b, ov::opset8::Constant::create(ngraph::element::i64, {2}, {0, 2})); auto bi = std::make_shared(ov::element::f32, ov::Shape{0, 2}); { auto concat = std::make_shared(ov::NodeVector{ai, bi}, 0); diff --git a/src/inference/tests/functional/core_threading.cpp b/src/inference/tests/functional/core_threading.cpp index dbfc0ce178e..225f549cb5f 100644 --- a/src/inference/tests/functional/core_threading.cpp +++ b/src/inference/tests/functional/core_threading.cpp @@ -2,27 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include +#include #include -#include "openvino/util/file_util.hpp" -#include -#include +#include +#include #include #include - -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include + +#include "openvino/util/file_util.hpp" #ifdef __GLIBC__ -#include -#if __GLIBC_MINOR__ >= 34 - #define OV_TEST_GLIBC_VERSION_GREATER_2_34 -#endif +# include +# if __GLIBC_MINOR__ >= 34 +# define OV_TEST_GLIBC_VERSION_GREATER_2_34 +# endif #endif class CoreThreadingTests : public ::testing::Test { @@ -38,7 +38,8 @@ public: testName += testInfo->name(); testName = std::to_string(std::hash()(testName)); std::stringstream ss; - auto ts = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()); + auto ts = std::chrono::duration_cast( + std::chrono::high_resolution_clock::now().time_since_epoch()); ss << testName << "_" << std::this_thread::get_id() << "_" << ts.count(); testName = ss.str(); return testName; @@ -59,27 +60,27 @@ public: const unsigned int threadsNum = 8) { std::vector threads(threadsNum); - for (auto & thread : threads) { - thread = std::thread([&](){ + for (auto& thread : threads) { + thread = std::thread([&]() { for (unsigned int i = 0; i < iterations; ++i) { func(); } }); } - for (auto & thread : threads) { + for (auto& thread : threads) { if (thread.joinable()) thread.join(); } } - void safeAddExtension(InferenceEngine::Core & ie) { + void safeAddExtension(InferenceEngine::Core& ie) { try { auto extension = std::make_shared( ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), - std::string("template_extension") + IE_BUILD_POSTFIX)); + std::string("template_extension") + IE_BUILD_POSTFIX)); ie.AddExtension(extension); - } catch (const InferenceEngine::Exception & ex) { + } catch (const InferenceEngine::Exception& ex) { ASSERT_STR_CONTAINS(ex.what(), "name: custom_opset. Opset"); } } @@ -89,12 +90,13 @@ public: TEST_F(CoreThreadingTests, SetConfigPluginDoesNotExist) { InferenceEngine::Core ie; std::map localConfig = { - { CONFIG_KEY(PERF_COUNT), InferenceEngine::PluginConfigParams::YES } - }; + {CONFIG_KEY(PERF_COUNT), InferenceEngine::PluginConfigParams::YES}}; - runParallel([&] () { - ie.SetConfig(localConfig); - }, 10000); + runParallel( + [&]() { + ie.SetConfig(localConfig); + }, + 10000); } // TODO: CVS-68982 @@ -104,13 +106,16 @@ TEST_F(CoreThreadingTests, SetConfigPluginDoesNotExist) { TEST_F(CoreThreadingTests, RegisterPlugin) { InferenceEngine::Core ie; std::atomic index{0}; - runParallel([&] () { - const std::string deviceName = std::to_string(index++); - ie.RegisterPlugin(ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX), deviceName); - ie.GetVersions(deviceName); - ie.UnregisterPlugin(deviceName); - }, 4000); + runParallel( + [&]() { + const std::string deviceName = std::to_string(index++); + ie.RegisterPlugin(ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), + std::string("mock_engine") + IE_BUILD_POSTFIX), + deviceName); + ie.GetVersions(deviceName); + ie.UnregisterPlugin(deviceName); + }, + 4000); } // tested function: RegisterPlugins @@ -118,7 +123,7 @@ TEST_F(CoreThreadingTests, RegisterPlugins) { InferenceEngine::Core ie; std::atomic index{0}; - auto getPluginXml = [&] () -> std::tuple { + auto getPluginXml = [&]() -> std::tuple { std::string indexStr = std::to_string(index++); std::string pluginsXML = "test_plugins" + indexStr + ".xml"; std::ofstream file(pluginsXML); @@ -140,38 +145,42 @@ TEST_F(CoreThreadingTests, RegisterPlugins) { return std::tie(pluginsXML, indexStr); }; - runParallel([&] () { - std::string fileName, deviceName; - std::tie(fileName, deviceName) = getPluginXml(); - ie.RegisterPlugins(fileName); - ie.GetVersions(deviceName); - ASSERT_EQ(0, std::remove(fileName.c_str())); - }, 1000); + runParallel( + [&]() { + std::string fileName, deviceName; + std::tie(fileName, deviceName) = getPluginXml(); + ie.RegisterPlugins(fileName); + ie.GetVersions(deviceName); + ASSERT_EQ(0, std::remove(fileName.c_str())); + }, + 1000); } -#endif // !OPENVINO_STATIC_LIBRARY +#endif // !OPENVINO_STATIC_LIBRARY // tested function: GetAvailableDevices, UnregisterPlugin // TODO: some initialization (e.g. thread/dlopen) sporadically fails during such stress-test scenario TEST_F(CoreThreadingTests, GetAvailableDevices) { - #ifndef OV_TEST_GLIBC_VERSION_GREATER_2_34 - GTEST_SKIP(); - #endif +#ifndef OV_TEST_GLIBC_VERSION_GREATER_2_34 + GTEST_SKIP(); +#endif InferenceEngine::Core ie; - runParallel([&] () { - std::vector devices = ie.GetAvailableDevices(); + runParallel( + [&]() { + std::vector devices = ie.GetAvailableDevices(); - // unregister all the devices - for (auto && deviceName : devices) { - try { - ie.UnregisterPlugin(deviceName); - } catch (const InferenceEngine::Exception & ex) { - // if several threads unload plugin at once, the first thread does this - // while all others will throw an exception that plugin is not registered - ASSERT_STR_CONTAINS(ex.what(), "name is not registered in the"); + // unregister all the devices + for (auto&& deviceName : devices) { + try { + ie.UnregisterPlugin(deviceName); + } catch (const InferenceEngine::Exception& ex) { + // if several threads unload plugin at once, the first thread does this + // while all others will throw an exception that plugin is not registered + ASSERT_STR_CONTAINS(ex.what(), "name is not registered in the"); + } } - } - }, 30); + }, + 30); } #if defined(ENABLE_OV_IR_FRONTEND) @@ -180,9 +189,12 @@ TEST_F(CoreThreadingTests, ReadNetwork) { InferenceEngine::Core ie; auto network = ie.ReadNetwork(modelName, weightsName); - runParallel([&] () { - safeAddExtension(ie); - (void)ie.ReadNetwork(modelName, weightsName); - }, 100, 12); + runParallel( + [&]() { + safeAddExtension(ie); + (void)ie.ReadNetwork(modelName, weightsName); + }, + 100, + 12); } -#endif //defined(ENABLE_OV_IR_FRONTEND) +#endif // defined(ENABLE_OV_IR_FRONTEND) diff --git a/src/inference/tests/functional/data_test.cpp b/src/inference/tests/functional/data_test.cpp index 4ffc2cf14cd..c9a3deb0ff0 100644 --- a/src/inference/tests/functional/data_test.cpp +++ b/src/inference/tests/functional/data_test.cpp @@ -2,9 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include - +#include #include using namespace ::testing; @@ -22,9 +21,9 @@ protected: class BlockingDescTest : public BlockingDesc { public: - BlockingDescTest(const SizeVector &blocked_dims, const SizeVector &order) : BlockingDesc(blocked_dims, order) {} + BlockingDescTest(const SizeVector& blocked_dims, const SizeVector& order) : BlockingDesc(blocked_dims, order) {} - void fillDescTest(const SizeVector &blocked_dims, const SizeVector &order) { + void fillDescTest(const SizeVector& blocked_dims, const SizeVector& order) { fillDesc(blocked_dims, order); } }; @@ -93,7 +92,7 @@ TEST_F(DataTests, canSetNotEmptyDimsForBlockingDescNCHW) { } TEST_F(DataTests, setPrecision) { - Data data(data_name, { Precision::FP32, emptyDims, Layout::NCHW }); + Data data(data_name, {Precision::FP32, emptyDims, Layout::NCHW}); EXPECT_EQ(Precision::FP32, data.getPrecision()); EXPECT_EQ(Precision::FP32, data.getTensorDesc().getPrecision()); diff --git a/src/inference/tests/functional/debug_tests.cpp b/src/inference/tests/functional/debug_tests.cpp index 1e4f2228ba8..59f1f93dd9a 100644 --- a/src/inference/tests/functional/debug_tests.cpp +++ b/src/inference/tests/functional/debug_tests.cpp @@ -3,9 +3,11 @@ // #include -#include "debug.h" + #include +#include "debug.h" + using DebugTests = ::testing::Test; TEST_F(DebugTests, tolowerWorksWithEmptyString) { diff --git a/src/inference/tests/functional/executable_network.cpp b/src/inference/tests/functional/executable_network.cpp index f672519fb25..2730d1e7506 100644 --- a/src/inference/tests/functional/executable_network.cpp +++ b/src/inference/tests/functional/executable_network.cpp @@ -3,6 +3,7 @@ // #include + #include using namespace ::testing; diff --git a/src/inference/tests/functional/ie_precision_test.cpp b/src/inference/tests/functional/ie_precision_test.cpp index 0b2a818d575..004e2c11953 100644 --- a/src/inference/tests/functional/ie_precision_test.cpp +++ b/src/inference/tests/functional/ie_precision_test.cpp @@ -2,11 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include +#include #include -#include +#include using Precision = InferenceEngine::Precision; @@ -30,7 +30,7 @@ TEST_F(PrecisionTests, ShowsCorrectPrecisionNames) { EXPECT_STREQ(Precision(Precision::U8).name(), "U8"); EXPECT_STREQ(Precision(Precision::MIXED).name(), "MIXED"); EXPECT_STREQ(Precision(Precision::UNSPECIFIED).name(), "UNSPECIFIED"); - EXPECT_STREQ(Precision(static_cast(-3)).name(), "UNSPECIFIED"); + EXPECT_STREQ(Precision(static_cast(-3)).name(), "UNSPECIFIED"); EXPECT_STREQ(Precision(1, "Custom Name").name(), "Custom Name"); } @@ -94,7 +94,7 @@ TEST_F(PrecisionTests, is_float) { EXPECT_FALSE(Precision(Precision::U8).is_float()); EXPECT_FALSE(Precision(Precision::MIXED).is_float()); EXPECT_FALSE(Precision(10).is_float()); - EXPECT_FALSE(Precision(static_cast(-3)).is_float()); + EXPECT_FALSE(Precision(static_cast(-3)).is_float()); EXPECT_FALSE(Precision(Precision::UNSPECIFIED).is_float()); } @@ -115,7 +115,7 @@ TEST_F(PrecisionTests, constructFromSTR) { EXPECT_EQ(Precision(Precision::U4), Precision::FromStr("U4")); EXPECT_EQ(Precision(Precision::U8), Precision::FromStr("U8")); EXPECT_EQ(Precision(Precision::MIXED), Precision::FromStr("MIXED")); - EXPECT_EQ(Precision(static_cast(-3)), Precision::FromStr("UNSPECIFIED")); + EXPECT_EQ(Precision(static_cast(-3)), Precision::FromStr("UNSPECIFIED")); EXPECT_EQ(Precision(Precision::UNSPECIFIED), Precision::FromStr("UNSPECIFIED")); } @@ -141,14 +141,13 @@ TEST_F(PrecisionTests, canCompareCustomPrecisions) { EXPECT_TRUE(p5 == p); } - TEST_F(PrecisionTests, canUseInIfs) { Precision p; EXPECT_TRUE(!p); p = Precision::FP32; EXPECT_FALSE(!p); EXPECT_TRUE(p); - p = Precision(static_cast(-3)); + p = Precision(static_cast(-3)); EXPECT_TRUE(!p); } diff --git a/src/inference/tests/functional/local_test.cpp b/src/inference/tests/functional/local_test.cpp index 6685ac9a35d..7beca57064d 100644 --- a/src/inference/tests/functional/local_test.cpp +++ b/src/inference/tests/functional/local_test.cpp @@ -3,7 +3,9 @@ // #include + #include + #include "ngraph/ops.hpp" using namespace ::testing; @@ -215,9 +217,9 @@ class LocaleTests : public ::testing::Test { protected: void SetUp() override { - originalLocale = setlocale(LC_ALL, nullptr); + originalLocale = setlocale(LC_ALL, nullptr); } - void TearDown() override { + void TearDown() override { setlocale(LC_ALL, originalLocale.c_str()); } @@ -231,7 +233,7 @@ protected: auto funcs = net.getFunction(); - for (const auto & op : funcs->get_ops()) { + for (const auto& op : funcs->get_ops()) { if (!isLSTM) { if (op->get_friendly_name() == "output") { const auto roi = std::dynamic_pointer_cast(op); @@ -285,4 +287,4 @@ TEST_F(LocaleTests, DISABLED_WithUSLocaleCPP) { testBody(); std::locale::global(prev); } -#endif //defined(ENABLE_OV_IR_FRONTEND) +#endif // defined(ENABLE_OV_IR_FRONTEND) diff --git a/src/inference/tests/functional/matmul_sr_tests.cpp b/src/inference/tests/functional/matmul_sr_tests.cpp index 8168997f670..dffdeff0745 100644 --- a/src/inference/tests/functional/matmul_sr_tests.cpp +++ b/src/inference/tests/functional/matmul_sr_tests.cpp @@ -4,14 +4,13 @@ #include -#include -#include -#include - -#include -#include #include +#include +#include +#include +#include #include +#include #include #include @@ -32,7 +31,8 @@ struct ReshapeMatMulTestCase { reshape_map new_shapes; }; -class SmartReshapeMatMulTests : public CommonTestUtils::TestsCommon, public testing::WithParamInterface> { +class SmartReshapeMatMulTests : public CommonTestUtils::TestsCommon, + public testing::WithParamInterface> { public: void SetUp() override { const auto& test_case = std::get<0>(GetParam()); @@ -44,15 +44,21 @@ public: auto input_B = std::make_shared(ngraph::element::f32, test_case.B_shape); input_B->set_friendly_name("input_B"); - auto reshape_pattern = std::make_shared( - ngraph::element::i64, ngraph::Shape{test_case.reshape_pattern.size()}, test_case.reshape_pattern); + auto reshape_pattern = + std::make_shared(ngraph::element::i64, + ngraph::Shape{test_case.reshape_pattern.size()}, + test_case.reshape_pattern); reshape_pattern->set_friendly_name("reshape_pattern"); - auto reshape = std::make_shared(test_case.reshape_is_A_input ? input_A : input_B, reshape_pattern, true); + auto reshape = std::make_shared(test_case.reshape_is_A_input ? input_A : input_B, + reshape_pattern, + true); reshape->set_friendly_name("reshape"); - auto mat_mul = std::make_shared(test_case.reshape_is_A_input ? reshape->output(0) : input_A->output(0), - test_case.reshape_is_A_input ? input_B->output(0) : reshape->output(0), - test_case.transpose_a, test_case.transpose_b); + auto mat_mul = std::make_shared( + test_case.reshape_is_A_input ? reshape->output(0) : input_A->output(0), + test_case.reshape_is_A_input ? input_B->output(0) : reshape->output(0), + test_case.transpose_a, + test_case.transpose_b); reshape->set_friendly_name("matmul"); auto result = std::make_shared(mat_mul); @@ -62,15 +68,17 @@ public: } InferenceEngine::details::CNNNetworkNGraphImpl network(ngraph); - const auto & resp = network.reshape(test_case.new_shapes, nullptr); + const auto& resp = network.reshape(test_case.new_shapes, nullptr); ASSERT_EQ(resp, StatusCode::OK); } }; -TEST_P(SmartReshapeMatMulTests, ReshapeMatMul) { -} +TEST_P(SmartReshapeMatMulTests, ReshapeMatMul) {} -INSTANTIATE_TEST_SUITE_P(NGraph, SmartReshapeMatMulTests, testing::Values( +INSTANTIATE_TEST_SUITE_P( + NGraph, + SmartReshapeMatMulTests, + testing::Values( ReshapeMatMulTestCase{true, {1, 20, 30}, {30, 40}, {20, -1}, false, false, {{"input_A", {2, 20, 30}}}}, ReshapeMatMulTestCase{true, {1, 20, 30}, {40, 30}, {20, -1}, false, true, {{"input_A", {2, 20, 30}}}}, ReshapeMatMulTestCase{true, {1, 30, 20}, {30, 20}, {-1, 20}, true, false, {{"input_A", {2, 30, 20}}}}, @@ -273,13 +281,15 @@ TEST(SmartReshapeTransposeMatMulTests, TransposeBothMatMulWithAttrFuse) { std::shared_ptr f(nullptr), f_ref(nullptr); { auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{2, 3, 2}); - auto split_A = std::make_shared(data_A, - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); + auto split_A = std::make_shared( + data_A, + ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), + ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{2, 3, 5}); - auto split_B = std::make_shared(data_B, - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); + auto split_B = std::make_shared( + data_B, + ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), + ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); auto order = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{3}, {0, 2, 1}); auto transpose_A = std::make_shared(split_A->output(0), order); auto transpose_B = std::make_shared(split_B->output(1), order); @@ -294,13 +304,15 @@ TEST(SmartReshapeTransposeMatMulTests, TransposeBothMatMulWithAttrFuse) { } { auto data_A = std::make_shared(ngraph::element::f32, ngraph::Shape{2, 3, 2}); - auto split_A = std::make_shared(data_A, - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); + auto split_A = std::make_shared( + data_A, + ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), + ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); auto data_B = std::make_shared(ngraph::element::f32, ngraph::Shape{2, 3, 5}); - auto split_B = std::make_shared(data_B, - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), - ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); + auto split_B = std::make_shared( + data_B, + ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {0}), + ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{2}, {1, 1})); auto matmul = std::make_shared(split_A->output(0), split_B->output(1), true, false); f_ref = std::make_shared(ngraph::NodeVector{matmul}, ngraph::ParameterVector{data_A, data_B}); } diff --git a/src/inference/tests/functional/ngraph_reshape_tests.cpp b/src/inference/tests/functional/ngraph_reshape_tests.cpp index f7ac4b36fcc..2635b78fac3 100644 --- a/src/inference/tests/functional/ngraph_reshape_tests.cpp +++ b/src/inference/tests/functional/ngraph_reshape_tests.cpp @@ -2,33 +2,31 @@ // SPDX-License-Identifier: Apache-2.0 // +#include #include -#include -#include -#include -#include #include -#include -#include +#include +#include #include - +#include #include -#include +#include #include -#include +#include #include +#include #include #include #include -#include +#include +#include +#include -#include - -#include "common_test_utils/test_common.hpp" +#include "common_test_utils/common_utils.hpp" #include "common_test_utils/data_utils.hpp" #include "common_test_utils/file_utils.hpp" -#include "common_test_utils/common_utils.hpp" +#include "common_test_utils/test_common.hpp" #include "ie_common.h" #include "openvino/core/partial_shape.hpp" #include "openvino/core/shape.hpp" @@ -156,13 +154,15 @@ TEST_F(NGraphReshapeTests, CNNReshapeSpatialReLUWithoutCloneFunction) { ASSERT_EQ(cnnNetwork.getInputsInfo()["data"]->getInputData()->getDims(), (SizeVector{1, 3, 25, 25})); } -class CustomTestOp: public ngraph::op::Op { +class CustomTestOp : public ngraph::op::Op { public: OPENVINO_OP("CustomTestLayer", "test_extension"); CustomTestOp() = default; - CustomTestOp(const ngraph::Output& arg, bool test1, int64_t test2): - Op({arg}), test1(test1), test2(test2) { + CustomTestOp(const ngraph::Output& arg, bool test1, int64_t test2) + : Op({arg}), + test1(test1), + test2(test2) { constructor_validate_and_infer_types(); } @@ -352,15 +352,15 @@ TEST_F(NGraphReshapeTests, ReshapeNewIRWithNewExtension2) { SizeVector outDims = output["activation"]->getTensorDesc().getDims(); ASSERT_EQ(outDims, refAfterReshape); } -#endif //defined(ENABLE_OV_IR_FRONTEND) +#endif // defined(ENABLE_OV_IR_FRONTEND) class BadExtension : public InferenceEngine::IExtension { public: BadExtension() {} - void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override {}; + void GetVersion(const InferenceEngine::Version*& versionInfo) const noexcept override{}; - void Unload() noexcept override {}; + void Unload() noexcept override{}; std::map getOpSets() override { static std::map opsets; @@ -395,8 +395,8 @@ TEST_F(NGraphReshapeTests, TestInterpParameters) { auto interp = std::make_shared(inp, out_shape, attrs); auto output = std::make_shared(interp); - auto ngraph_function = std::make_shared(ngraph::ResultVector{output}, - ngraph::ParameterVector{inp}); + auto ngraph_function = + std::make_shared(ngraph::ResultVector{output}, ngraph::ParameterVector{inp}); CNNNetwork cnn(ngraph_function); std::map inShape; diff --git a/src/inference/tests/functional/ov_compiled_model_test.cpp b/src/inference/tests/functional/ov_compiled_model_test.cpp index 7230a989fd8..8941b9fff55 100644 --- a/src/inference/tests/functional/ov_compiled_model_test.cpp +++ b/src/inference/tests/functional/ov_compiled_model_test.cpp @@ -3,6 +3,7 @@ // #include + #include #include diff --git a/src/inference/tests/functional/ov_extension_test.cpp b/src/inference/tests/functional/ov_extension_test.cpp index 8d22afd2909..495d7f7595f 100644 --- a/src/inference/tests/functional/ov_extension_test.cpp +++ b/src/inference/tests/functional/ov_extension_test.cpp @@ -353,4 +353,4 @@ TEST_F(OVExtensionTests, load_old_extension) { TEST_F(OVExtensionTests, load_incorrect_extension) { EXPECT_THROW(core.add_extension(getIncorrectExtensionPath()), ov::Exception); } -#endif //defined(ENABLE_OV_IR_FRONTEND) +#endif // defined(ENABLE_OV_IR_FRONTEND) diff --git a/src/inference/tests/functional/ov_infer_request_test.cpp b/src/inference/tests/functional/ov_infer_request_test.cpp index f76503cc90d..3f95f08f759 100644 --- a/src/inference/tests/functional/ov_infer_request_test.cpp +++ b/src/inference/tests/functional/ov_infer_request_test.cpp @@ -6,9 +6,9 @@ #include #include +#include #include #include -#include using namespace ::testing; using namespace std; @@ -85,7 +85,6 @@ TEST(InferRequestOVTests, throwsOnUninitializedSetRemoteTensor) { ASSERT_THROW(req.set_tensor(ov::Output(), remote_tensor), ov::Exception); } - TEST(InferRequestOVTests, throwsOnGetCompiledModel) { ov::InferRequest req; ASSERT_THROW(req.get_compiled_model(), ov::Exception); diff --git a/src/inference/tests/functional/ov_shared_object_test.cpp b/src/inference/tests/functional/ov_shared_object_test.cpp index bfd82d9747a..bb4a0625daf 100644 --- a/src/inference/tests/functional/ov_shared_object_test.cpp +++ b/src/inference/tests/functional/ov_shared_object_test.cpp @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // +#include #include -#include -#include "openvino/util/shared_object.hpp" -#include "common_test_utils/file_utils.hpp" #include +#include "common_test_utils/file_utils.hpp" +#include "openvino/util/shared_object.hpp" + using namespace ::testing; using namespace std; @@ -19,7 +20,7 @@ protected: std::string("mock_engine") + IE_BUILD_POSTFIX); } - void loadDll(const string &libraryName) { + void loadDll(const string& libraryName) { shared_object = ov::util::load_shared_object(libraryName.c_str()); } std::shared_ptr shared_object; @@ -27,7 +28,8 @@ protected: using CreateF = void(std::shared_ptr&); std::function make_std_function(const std::string& functionName) { - std::function ptr(reinterpret_cast(ov::util::get_symbol(shared_object, functionName.c_str()))); + std::function ptr( + reinterpret_cast(ov::util::get_symbol(shared_object, functionName.c_str()))); return ptr; } }; diff --git a/src/inference/tests/functional/pre_allocator_test.cpp b/src/inference/tests/functional/pre_allocator_test.cpp index 51d6005b94f..94ac99ceed0 100644 --- a/src/inference/tests/functional/pre_allocator_test.cpp +++ b/src/inference/tests/functional/pre_allocator_test.cpp @@ -4,16 +4,17 @@ #include -#include "ie_allocator.hpp" -#include "details/ie_pre_allocator.hpp" #include +#include "details/ie_pre_allocator.hpp" +#include "ie_allocator.hpp" + using namespace ::testing; using namespace std; using namespace InferenceEngine; -class PreallocatorTests: public ::testing::Test { - protected: +class PreallocatorTests : public ::testing::Test { +protected: std::vector mybuf; void SetUp() override { @@ -24,10 +25,10 @@ class PreallocatorTests: public ::testing::Test { }; TEST_F(PreallocatorTests, canAccessPreAllocatedMemory) { - void * handle = allocator->alloc(3); - float * ptr = reinterpret_cast(allocator->lock(handle)); + void* handle = allocator->alloc(3); + float* ptr = reinterpret_cast(allocator->lock(handle)); - mybuf = { 1.1f, 2.2f, 3.3f }; + mybuf = {1.1f, 2.2f, 3.3f}; ASSERT_EQ(ptr, &*mybuf.begin()); ASSERT_EQ(ptr[0], 1.1f); @@ -36,12 +37,12 @@ TEST_F(PreallocatorTests, canAccessPreAllocatedMemory) { } TEST_F(PreallocatorTests, canNotAllocateMoreMemory) { - //large block such as 10k will result in nullptr - EXPECT_EQ(nullptr, allocator->lock(allocator->alloc(10* sizeof(float) + 1))); - EXPECT_NE(nullptr, allocator->lock(allocator->alloc(10* sizeof(float)))); + // large block such as 10k will result in nullptr + EXPECT_EQ(nullptr, allocator->lock(allocator->alloc(10 * sizeof(float) + 1))); + EXPECT_NE(nullptr, allocator->lock(allocator->alloc(10 * sizeof(float)))); } TEST_F(PreallocatorTests, canNotLockWrongHandle) { - void * handle = allocator->alloc(3); + void* handle = allocator->alloc(3); EXPECT_EQ(nullptr, allocator->lock(1 + reinterpret_cast(handle))); } diff --git a/src/inference/tests/functional/preprocess_test.cpp b/src/inference/tests/functional/preprocess_test.cpp index e6b6d32e743..c8ec11a9828 100644 --- a/src/inference/tests/functional/preprocess_test.cpp +++ b/src/inference/tests/functional/preprocess_test.cpp @@ -3,6 +3,7 @@ // #include + #include using namespace std; @@ -12,23 +13,22 @@ using PreProcessTests = ::testing::Test; TEST_F(PreProcessTests, throwsOnSettingNullMeanImage) { InferenceEngine::PreProcessInfo info; info.init(1); - ASSERT_THROW(info.setMeanImage(InferenceEngine::Blob::Ptr(nullptr)), - InferenceEngine::Exception); + ASSERT_THROW(info.setMeanImage(InferenceEngine::Blob::Ptr(nullptr)), InferenceEngine::Exception); } TEST_F(PreProcessTests, throwsOnSetting2DMeanImage) { InferenceEngine::PreProcessInfo info; info.init(1); - InferenceEngine::Blob::Ptr blob(new InferenceEngine::TBlob({ InferenceEngine::Precision::FP32, - {1, 1}, InferenceEngine::Layout::HW})); + InferenceEngine::Blob::Ptr blob( + new InferenceEngine::TBlob({InferenceEngine::Precision::FP32, {1, 1}, InferenceEngine::Layout::HW})); ASSERT_THROW(info.setMeanImage(blob), InferenceEngine::Exception); } TEST_F(PreProcessTests, throwsOnSettingWrongSizeMeanImage) { InferenceEngine::PreProcessInfo info; info.init(1); - InferenceEngine::TBlob::Ptr blob(new InferenceEngine::TBlob({ InferenceEngine::Precision::FP32, - { 2, 1, 1 }, InferenceEngine::Layout::CHW })); + InferenceEngine::TBlob::Ptr blob( + new InferenceEngine::TBlob({InferenceEngine::Precision::FP32, {2, 1, 1}, InferenceEngine::Layout::CHW})); blob->allocate(); ASSERT_THROW(info.setMeanImage(blob), InferenceEngine::Exception); } @@ -36,8 +36,8 @@ TEST_F(PreProcessTests, throwsOnSettingWrongSizeMeanImage) { TEST_F(PreProcessTests, noThrowWithCorrectSizeMeanImage) { InferenceEngine::PreProcessInfo info; info.init(2); - InferenceEngine::TBlob::Ptr blob(new InferenceEngine::TBlob({ InferenceEngine::Precision::FP32, - { 2, 1, 1 }, InferenceEngine::Layout::CHW })); + InferenceEngine::TBlob::Ptr blob( + new InferenceEngine::TBlob({InferenceEngine::Precision::FP32, {2, 1, 1}, InferenceEngine::Layout::CHW})); blob->allocate(); ASSERT_NO_THROW(info.setMeanImage(blob)); } diff --git a/src/inference/tests/functional/response_buffer_test.cpp b/src/inference/tests/functional/response_buffer_test.cpp index 10a3542d419..23934f58e6b 100644 --- a/src/inference/tests/functional/response_buffer_test.cpp +++ b/src/inference/tests/functional/response_buffer_test.cpp @@ -3,6 +3,7 @@ // #include + #include "description_buffer.hpp" using namespace std; diff --git a/src/inference/tests/functional/shared_object_loader_test.cpp b/src/inference/tests/functional/shared_object_loader_test.cpp index e7f496e5ad1..0251b60795a 100644 --- a/src/inference/tests/functional/shared_object_loader_test.cpp +++ b/src/inference/tests/functional/shared_object_loader_test.cpp @@ -2,25 +2,26 @@ // SPDX-License-Identifier: Apache-2.0 // +#include #include -#include -#include "openvino/util/shared_object.hpp" -#include "common_test_utils/file_utils.hpp" #include +#include "common_test_utils/file_utils.hpp" +#include "openvino/util/shared_object.hpp" + using namespace std; using namespace InferenceEngine; using namespace InferenceEngine::details; -class SharedObjectLoaderTests: public ::testing::Test { +class SharedObjectLoaderTests : public ::testing::Test { protected: std::string get_mock_engine_name() { return FileUtils::makePluginLibraryName(CommonTestUtils::getExecutableDirectory(), - std::string("mock_engine") + IE_BUILD_POSTFIX); + std::string("mock_engine") + IE_BUILD_POSTFIX); } - void loadDll(const string &libraryName) { + void loadDll(const string& libraryName) { sharedObjectLoader = ov::util::load_shared_object(libraryName.c_str()); } std::shared_ptr sharedObjectLoader; @@ -28,14 +29,14 @@ protected: using CreateF = void(std::shared_ptr&); std::function make_std_function(const std::string& functionName) { - std::function ptr(reinterpret_cast( - ov::util::get_symbol(sharedObjectLoader, functionName.c_str()))); + std::function ptr( + reinterpret_cast(ov::util::get_symbol(sharedObjectLoader, functionName.c_str()))); return ptr; } }; -typedef void*(*PluginEngineCreateFunc)(void); -typedef void(*PluginEngineDestoryFunc)(void *); +typedef void* (*PluginEngineCreateFunc)(void); +typedef void (*PluginEngineDestoryFunc)(void*); TEST_F(SharedObjectLoaderTests, canLoadExistedPlugin) { loadDll(get_mock_engine_name()); diff --git a/src/inference/tests/functional/skip_tests_config.cpp b/src/inference/tests/functional/skip_tests_config.cpp index 6c67fa4844e..f49f4daa2c2 100644 --- a/src/inference/tests/functional/skip_tests_config.cpp +++ b/src/inference/tests/functional/skip_tests_config.cpp @@ -2,11 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include - #include "functional_test_utils/skip_tests_config.hpp" +#include +#include + std::vector disabledTestPatterns() { return {}; } diff --git a/src/inference/tests/functional/task_executor_tests.cpp b/src/inference/tests/functional/task_executor_tests.cpp index ec8d247258b..75b22d930ee 100644 --- a/src/inference/tests/functional/task_executor_tests.cpp +++ b/src/inference/tests/functional/task_executor_tests.cpp @@ -2,15 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include - #include +#include +#include #include +#include #include #include -#include -#include using namespace ::testing; using namespace std; @@ -28,18 +27,22 @@ TEST_P(TaskExecutorTests, canCreateTaskExecutor) { EXPECT_NO_THROW(makeExecutor()); } -template +template static std::future async(E& executor, F&& f) { auto p = std::make_shared>(f); auto future = p->get_future(); - executor->run([p] {(*p)();}); + executor->run([p] { + (*p)(); + }); return future; } TEST_P(TaskExecutorTests, canRunCustomFunction) { auto taskExecutor = GetParam()(); int i = 0; - auto f = async(taskExecutor, [&i] { i++; }); + auto f = async(taskExecutor, [&i] { + i++; + }); f.wait(); ASSERT_NO_THROW(f.get()); } @@ -48,10 +51,16 @@ TEST_P(TaskExecutorTests, canRun2FunctionsOneByOne) { auto taskExecutor = GetParam()(); std::mutex m; int i = 0; - auto f1 = async(taskExecutor, [&]() {std::unique_lock l{m}; i += 1; }); + auto f1 = async(taskExecutor, [&]() { + std::unique_lock l{m}; + i += 1; + }); f1.wait(); ASSERT_NO_THROW(f1.get()); - auto f2 = async(taskExecutor, [&]() {std::unique_lock l{m}; i *= 2; }); + auto f2 = async(taskExecutor, [&]() { + std::unique_lock l{m}; + i *= 2; + }); f2.wait(); ASSERT_NO_THROW(f2.get()); @@ -73,10 +82,12 @@ TEST_P(TaskExecutorTests, canRunMultipleTasksWithExceptionInside) { std::vector> futures; for (int i = 0; i < MAX_NUMBER_OF_TASKS_IN_QUEUE; i++) { - futures.emplace_back(async(taskExecutor, [] { throw std::bad_alloc(); })); + futures.emplace_back(async(taskExecutor, [] { + throw std::bad_alloc(); + })); } - for (auto &f : futures) { + for (auto& f : futures) { f.wait(); EXPECT_THROW(f.get(), std::bad_alloc); } @@ -94,16 +105,25 @@ TEST_P(TaskExecutorTests, canRunMultipleTasksFromMultipleThreads) { auto p = std::make_shared>([&] { for (int k = 0; k < NUM_INTERNAL_ITERATIONS; k++) { ++sharedVar; - }}); + } + }); futures.emplace_back(p->get_future()); - auto task = [p] {(*p)();}; - threads.emplace_back([task, taskExecutor] {taskExecutor->run(std::move(task));}); + auto task = [p] { + (*p)(); + }; + threads.emplace_back([task, taskExecutor] { + taskExecutor->run(std::move(task)); + }); } - for (auto&& f : futures) f.wait(); - for (auto&& f : futures) ASSERT_NO_THROW(f.get()); + for (auto&& f : futures) + f.wait(); + for (auto&& f : futures) + ASSERT_NO_THROW(f.get()); ASSERT_EQ(THREAD_NUMBER * NUM_INTERNAL_ITERATIONS, sharedVar); - for (auto&& thread : threads) if (thread.joinable()) thread.join(); + for (auto&& thread : threads) + if (thread.joinable()) + thread.join(); } TEST_P(TaskExecutorTests, executorNotReleasedUntilTasksAreDone) { @@ -115,15 +135,18 @@ TEST_P(TaskExecutorTests, executorNotReleasedUntilTasksAreDone) { { auto taskExecutor = GetParam()(); for (int i = 0; i < MAX_NUMBER_OF_TASKS_IN_QUEUE; i++) { - auto p = std::make_shared>( - [&] { - // intentionally block task for launching tasks after calling dtor for TaskExecutor - std::unique_lock lock(mutex_block_emulation); - cv_block_emulation.wait(lock, [&isBlocked] { return isBlocked; }); - ++sharedVar; - }); + auto p = std::make_shared>([&] { + // intentionally block task for launching tasks after calling dtor for TaskExecutor + std::unique_lock lock(mutex_block_emulation); + cv_block_emulation.wait(lock, [&isBlocked] { + return isBlocked; + }); + ++sharedVar; + }); futures.emplace_back(p->get_future()); - auto task = [p] {(*p)();}; + auto task = [p] { + (*p)(); + }; taskExecutor->run(std::move(task)); } } @@ -132,7 +155,7 @@ TEST_P(TaskExecutorTests, executorNotReleasedUntilTasksAreDone) { std::lock_guard lock{mutex_block_emulation}; isBlocked = false; } - for (auto &f : futures) { + for (auto& f : futures) { cv_block_emulation.notify_all(); f.wait(); } @@ -160,12 +183,16 @@ TEST_P(ASyncTaskExecutorTests, startAsyncIsNotBlockedByAnotherTask) { cv_task_started.notify_all(); // intentionally block task for test purpose std::unique_lock lock(mutex_block_emulation); - cv_block_emulation.wait(lock, [&isBlocked] { return !isBlocked; }); + cv_block_emulation.wait(lock, [&isBlocked] { + return !isBlocked; + }); }); async(taskExecutor, [&] { std::unique_lock lock(mutex_task_started); - cv_task_started.wait(lock, [&isStarted] { return isStarted; }); + cv_task_started.wait(lock, [&isStarted] { + return isStarted; + }); }); { @@ -176,12 +203,12 @@ TEST_P(ASyncTaskExecutorTests, startAsyncIsNotBlockedByAnotherTask) { } TEST_P(ASyncTaskExecutorTests, runAndWaitDoesNotOwnTasks) { - std::shared_ptr sharedCounter(this, [] (ASyncTaskExecutorTests*) {}); + std::shared_ptr sharedCounter(this, [](ASyncTaskExecutorTests*) {}); auto taskExecutor = GetParam()(); std::atomic_int useCount = {0}; std::vector tasks = {[sharedCounter, &useCount] { - useCount = sharedCounter.use_count(); - }}; + useCount = sharedCounter.use_count(); + }}; sharedCounter.reset(); taskExecutor->runAndWait(tasks); ASSERT_EQ(1, useCount); @@ -193,25 +220,33 @@ static auto Executors = ::testing::Values( [] { auto streams = getNumberOfCPUCores(); auto threads = parallel_get_max_threads(); - return std::make_shared(IStreamsExecutor::Config{"TestCPUStreamsExecutor", - streams, threads/streams, IStreamsExecutor::ThreadBindingType::NONE}); + return std::make_shared( + IStreamsExecutor::Config{"TestCPUStreamsExecutor", + streams, + threads / streams, + IStreamsExecutor::ThreadBindingType::NONE}); }, [] { auto streams = getNumberOfLogicalCPUCores(true); auto threads = parallel_get_max_threads(); - return std::make_shared(IStreamsExecutor::Config{"TestCPUStreamsExecutor", - streams, threads/streams, IStreamsExecutor::ThreadBindingType::NONE}); + return std::make_shared( + IStreamsExecutor::Config{"TestCPUStreamsExecutor", + streams, + threads / streams, + IStreamsExecutor::ThreadBindingType::NONE}); }, [] { auto streams = getNumberOfLogicalCPUCores(false); auto threads = parallel_get_max_threads(); - return std::make_shared(IStreamsExecutor::Config{"TestCPUStreamsExecutor", - streams, threads/streams, IStreamsExecutor::ThreadBindingType::NONE}); + return std::make_shared( + IStreamsExecutor::Config{"TestCPUStreamsExecutor", + streams, + threads / streams, + IStreamsExecutor::ThreadBindingType::NONE}); }, [] { return std::make_shared(); - } -); + }); INSTANTIATE_TEST_SUITE_P(TaskExecutorTests, TaskExecutorTests, Executors); @@ -219,24 +254,29 @@ static auto AsyncExecutors = ::testing::Values( [] { auto streams = getNumberOfCPUCores(); auto threads = parallel_get_max_threads(); - return std::make_shared(IStreamsExecutor::Config{"TestCPUStreamsExecutor", - streams, threads/streams, IStreamsExecutor::ThreadBindingType::NONE}); + return std::make_shared( + IStreamsExecutor::Config{"TestCPUStreamsExecutor", + streams, + threads / streams, + IStreamsExecutor::ThreadBindingType::NONE}); }, [] { auto streams = getNumberOfLogicalCPUCores(true); auto threads = parallel_get_max_threads(); - return std::make_shared(IStreamsExecutor::Config{"TestCPUStreamsExecutor", - streams, threads/streams, IStreamsExecutor::ThreadBindingType::NONE}); + return std::make_shared( + IStreamsExecutor::Config{"TestCPUStreamsExecutor", + streams, + threads / streams, + IStreamsExecutor::ThreadBindingType::NONE}); }, [] { auto streams = getNumberOfLogicalCPUCores(false); auto threads = parallel_get_max_threads(); - return std::make_shared(IStreamsExecutor::Config{"TestCPUStreamsExecutor", - streams, threads/streams, IStreamsExecutor::ThreadBindingType::NONE}); - } -); + return std::make_shared( + IStreamsExecutor::Config{"TestCPUStreamsExecutor", + streams, + threads / streams, + IStreamsExecutor::ThreadBindingType::NONE}); + }); INSTANTIATE_TEST_SUITE_P(ASyncTaskExecutorTests, ASyncTaskExecutorTests, AsyncExecutors); - - - diff --git a/src/inference/tests/functional/tensor_desc_test.cpp b/src/inference/tests/functional/tensor_desc_test.cpp index 4bbec58122f..40bfcb3f509 100644 --- a/src/inference/tests/functional/tensor_desc_test.cpp +++ b/src/inference/tests/functional/tensor_desc_test.cpp @@ -3,12 +3,11 @@ // #include - -#include -#include - -#include #include +#include + +#include +#include using namespace ::testing; using namespace std; @@ -17,7 +16,7 @@ using namespace InferenceEngine; using TensorDescTests = ::testing::Test; TEST_F(TensorDescTests, CreateBlobWithIncorrectLayout) { - ASSERT_THROW(make_shared_blob({ Precision::FP32, {1, 3, 32}, Layout::NC }), Exception); + ASSERT_THROW(make_shared_blob({Precision::FP32, {1, 3, 32}, Layout::NC}), Exception); } TEST_F(TensorDescTests, CreateBlockedBlobNCHW) { @@ -94,7 +93,7 @@ TEST_F(TensorDescTests, SetLayout) { TEST_F(TensorDescTests, setDimsForBLOCKED) { TensorDesc desc(Precision::FP32, {1, 2, 3, 4, 5, 6}, Layout::BLOCKED); - SizeVector newDims {7, 7, 7, 7, 7, 7}; + SizeVector newDims{7, 7, 7, 7, 7, 7}; desc.setDims(newDims); EXPECT_EQ(desc.getDims(), newDims); EXPECT_EQ(desc.getBlockingDesc().getBlockDims(), newDims); @@ -103,7 +102,7 @@ TEST_F(TensorDescTests, setDimsForBLOCKED) { TEST_F(TensorDescTests, setDimsForNHWC) { TensorDesc desc(Precision::FP32, {1, 2, 3, 4}, Layout::NHWC); auto refOrder = desc.getBlockingDesc().getOrder(); - SizeVector newDims {7, 7, 7, 7}; + SizeVector newDims{7, 7, 7, 7}; desc.setDims(newDims); EXPECT_EQ(desc.getDims(), newDims); EXPECT_EQ(desc.getLayout(), Layout::NHWC); diff --git a/src/inference/tests/unit/CMakeLists.txt b/src/inference/tests/unit/CMakeLists.txt index 82e6662ca24..d780922ad70 100644 --- a/src/inference/tests/unit/CMakeLists.txt +++ b/src/inference/tests/unit/CMakeLists.txt @@ -32,6 +32,7 @@ ov_add_test_target( LINK_LIBRARIES unitTestUtils INCLUDES + ADD_CLANG_FORMAT LABELS OV ) diff --git a/src/inference/tests/unit/ie_blob_test.cpp b/src/inference/tests/unit/ie_blob_test.cpp index eb506722701..bb3545381a5 100644 --- a/src/inference/tests/unit/ie_blob_test.cpp +++ b/src/inference/tests/unit/ie_blob_test.cpp @@ -2,19 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include #include +#include +#include #include "unit_test_utils/mocks/mock_allocator.hpp" #ifdef _WIN32 -#define UNUSED +# define UNUSED #else -#define UNUSED __attribute__((unused)) +# define UNUSED __attribute__((unused)) #endif -class BlobTests: public ::testing::Test { +class BlobTests : public ::testing::Test { protected: std::shared_ptr createMockAllocator() { return std::shared_ptr(new MockAllocator()); @@ -29,21 +29,21 @@ TEST_F(BlobTests, TBlobThrowsIfPtrForPreAllocatorIsNullPtr) { // Testing TBlob(const TensorDesc& tensorDesc, const std::std::shared_ptr& alloc) TEST_F(BlobTests, TBlobThrowsIfAllocatorIsNullPtr) { - ASSERT_THROW(InferenceEngine::TBlob( - {InferenceEngine::Precision::FP32, {1}, InferenceEngine::C}, std::shared_ptr()), - InferenceEngine::Exception); + ASSERT_THROW(InferenceEngine::TBlob({InferenceEngine::Precision::FP32, {1}, InferenceEngine::C}, + std::shared_ptr()), + InferenceEngine::Exception); } - TEST_F(BlobTests, canCreateBlobUsingDefaultAllocator) { InferenceEngine::SizeVector v = {1, 2, 3}; auto allocator = createMockAllocator(); - EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))).WillRepeatedly(testing::Return(reinterpret_cast(1))); + EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))) + .WillRepeatedly(testing::Return(reinterpret_cast(1))); EXPECT_CALL(*allocator.get(), free(::testing::_)).Times(1); { - InferenceEngine::TBlob blob({ InferenceEngine::Precision::FP32, v, InferenceEngine::CHW }, + InferenceEngine::TBlob blob({InferenceEngine::Precision::FP32, v, InferenceEngine::CHW}, std::dynamic_pointer_cast(allocator)); blob.allocate(); } @@ -53,32 +53,32 @@ TEST_F(BlobTests, secondAllocateWontMemLeak) { InferenceEngine::SizeVector v = {1, 2, 3}; auto allocator = createMockAllocator(); - EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))).Times(2).WillRepeatedly(testing::Return(reinterpret_cast(1))); + EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))) + .Times(2) + .WillRepeatedly(testing::Return(reinterpret_cast(1))); EXPECT_CALL(*allocator.get(), free(::testing::_)).Times(2).WillRepeatedly(testing::Return(true)); { - InferenceEngine::TBlob blob({ InferenceEngine::Precision::FP32, v, InferenceEngine::CHW }, + InferenceEngine::TBlob blob({InferenceEngine::Precision::FP32, v, InferenceEngine::CHW}, std::dynamic_pointer_cast(allocator)); blob.allocate(); blob.allocate(); } } - TEST_F(BlobTests, doesNotUnlockIfLockFailed) { InferenceEngine::SizeVector v = {1, 2, 3}; auto allocator = createMockAllocator(); - EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))).WillRepeatedly(testing::Return(reinterpret_cast(1))); + EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))) + .WillRepeatedly(testing::Return(reinterpret_cast(1))); EXPECT_CALL(*allocator.get(), lock(reinterpret_cast(1), InferenceEngine::LOCK_FOR_WRITE)).Times(1); EXPECT_CALL(*allocator.get(), free(::testing::_)).Times(1); - InferenceEngine::TBlob blob({ InferenceEngine::Precision::FP32, v, InferenceEngine::CHW }, + InferenceEngine::TBlob blob({InferenceEngine::Precision::FP32, v, InferenceEngine::CHW}, std::dynamic_pointer_cast(allocator)); blob.allocate(); - { - float UNUSED *ptr = blob.data(); - } + { float UNUSED* ptr = blob.data(); } } TEST_F(BlobTests, canAccessDataUsingAllocator) { @@ -87,38 +87,41 @@ TEST_F(BlobTests, canAccessDataUsingAllocator) { float data[] = {5.f, 6.f, 7.f}; - EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))).WillRepeatedly(testing::Return(reinterpret_cast(1))); - EXPECT_CALL(*allocator.get(), lock(reinterpret_cast(1), InferenceEngine::LOCK_FOR_WRITE)).WillRepeatedly(testing::Return(data)); + EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))) + .WillRepeatedly(testing::Return(reinterpret_cast(1))); + EXPECT_CALL(*allocator.get(), lock(reinterpret_cast(1), InferenceEngine::LOCK_FOR_WRITE)) + .WillRepeatedly(testing::Return(data)); EXPECT_CALL(*allocator.get(), unlock(reinterpret_cast(1))).Times(1); EXPECT_CALL(*allocator.get(), free(::testing::_)).Times(1); - InferenceEngine::TBlob blob({ InferenceEngine::Precision::FP32, v, InferenceEngine::CHW }, + InferenceEngine::TBlob blob({InferenceEngine::Precision::FP32, v, InferenceEngine::CHW}, std::dynamic_pointer_cast(allocator)); blob.allocate(); { - float *ptr = blob.data(); - ASSERT_EQ(ptr[2] , 7); + float* ptr = blob.data(); + ASSERT_EQ(ptr[2], 7); } } - TEST_F(BlobTests, canLockReadOnlyDataForRead) { InferenceEngine::SizeVector v = {1, 2, 3}; auto allocator = createMockAllocator(); float data[] = {5, 6, 7}; - EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))).WillRepeatedly(testing::Return(reinterpret_cast(1))); - EXPECT_CALL(*allocator.get(), lock(::testing::_, InferenceEngine::LOCK_FOR_READ)).WillRepeatedly(testing::Return(data)); + EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))) + .WillRepeatedly(testing::Return(reinterpret_cast(1))); + EXPECT_CALL(*allocator.get(), lock(::testing::_, InferenceEngine::LOCK_FOR_READ)) + .WillRepeatedly(testing::Return(data)); EXPECT_CALL(*allocator.get(), free(::testing::_)).Times(1); EXPECT_CALL(*allocator.get(), unlock(reinterpret_cast(1))).Times(1); - InferenceEngine::TBlob blob({ InferenceEngine::Precision::FP32, v, InferenceEngine::CHW }, + InferenceEngine::TBlob blob({InferenceEngine::Precision::FP32, v, InferenceEngine::CHW}, std::dynamic_pointer_cast(allocator)); blob.allocate(); - const float *ptr = blob.readOnly(); - ASSERT_EQ(ptr[2] , 7); + const float* ptr = blob.readOnly(); + ASSERT_EQ(ptr[2], 7); } TEST_F(BlobTests, canAccessDataUsingBufferBaseMethod) { @@ -127,17 +130,19 @@ TEST_F(BlobTests, canAccessDataUsingBufferBaseMethod) { float data[] = {5, 6, 7}; - EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))).WillRepeatedly(testing::Return(reinterpret_cast(1))); - EXPECT_CALL(*allocator.get(), lock(::testing::_, InferenceEngine::LOCK_FOR_WRITE)).WillRepeatedly(testing::Return(data)); + EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(float))) + .WillRepeatedly(testing::Return(reinterpret_cast(1))); + EXPECT_CALL(*allocator.get(), lock(::testing::_, InferenceEngine::LOCK_FOR_WRITE)) + .WillRepeatedly(testing::Return(data)); EXPECT_CALL(*allocator.get(), unlock(reinterpret_cast(1))).Times(1); EXPECT_CALL(*allocator.get(), free(::testing::_)).Times(1); - InferenceEngine::TBlob blob({ InferenceEngine::Precision::FP32, v, InferenceEngine::CHW }, + InferenceEngine::TBlob blob({InferenceEngine::Precision::FP32, v, InferenceEngine::CHW}, std::dynamic_pointer_cast(allocator)); blob.allocate(); auto buffer = blob.rwmap(); - const float *ptr = buffer.as(); - ASSERT_EQ(ptr[2] , 7); + const float* ptr = buffer.as(); + ASSERT_EQ(ptr[2], 7); } TEST_F(BlobTests, canMoveFromTBlobWithSameType) { @@ -146,30 +151,32 @@ TEST_F(BlobTests, canMoveFromTBlobWithSameType) { uint8_t data[] = {5, 6}; - EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(uint8_t))).WillRepeatedly(testing::Return(reinterpret_cast(1))); - EXPECT_CALL(*allocator.get(), lock(::testing::_, InferenceEngine::LOCK_FOR_WRITE)).WillRepeatedly(testing::Return(data)); + EXPECT_CALL(*allocator.get(), alloc(1 * 2 * 3 * sizeof(uint8_t))) + .WillRepeatedly(testing::Return(reinterpret_cast(1))); + EXPECT_CALL(*allocator.get(), lock(::testing::_, InferenceEngine::LOCK_FOR_WRITE)) + .WillRepeatedly(testing::Return(data)); EXPECT_CALL(*allocator.get(), unlock(reinterpret_cast(1))).Times(1); EXPECT_CALL(*allocator.get(), free(::testing::_)).Times(1); - InferenceEngine::TBlob blob({ InferenceEngine::Precision::U8, v, InferenceEngine::CHW }, - std::dynamic_pointer_cast(allocator)); + InferenceEngine::TBlob blob({InferenceEngine::Precision::U8, v, InferenceEngine::CHW}, + std::dynamic_pointer_cast(allocator)); blob.allocate(); - InferenceEngine::TBlob newBlob(std::move(blob)); + InferenceEngine::TBlob newBlob(std::move(blob)); auto buffer = newBlob.rwmap(); - uint8_t *ptr = buffer.as (); - ASSERT_EQ(ptr[0] , data[0]); + uint8_t* ptr = buffer.as(); + ASSERT_EQ(ptr[0], data[0]); } TEST_F(BlobTests, saveDimsAndSizeAfterMove) { InferenceEngine::SizeVector v = {1, 2, 3}; auto allocator = createMockAllocator(); - InferenceEngine::TBlob blob({ InferenceEngine::Precision::U8, v, InferenceEngine::CHW }, - std::dynamic_pointer_cast(allocator)); + InferenceEngine::TBlob blob({InferenceEngine::Precision::U8, v, InferenceEngine::CHW}, + std::dynamic_pointer_cast(allocator)); - InferenceEngine::TBlob newBlob(std::move(blob)); + InferenceEngine::TBlob newBlob(std::move(blob)); ASSERT_EQ(newBlob.size(), 1 * 2 * 3); ASSERT_EQ(newBlob.getTensorDesc().getDims()[0], 1); @@ -179,7 +186,7 @@ TEST_F(BlobTests, saveDimsAndSizeAfterMove) { TEST_F(BlobTests, canCopyBlob) { InferenceEngine::SizeVector v = {1, 3}; - InferenceEngine::TBlob blob({ InferenceEngine::Precision::U8, v, InferenceEngine::HW }); + InferenceEngine::TBlob blob({InferenceEngine::Precision::U8, v, InferenceEngine::HW}); blob.allocate(); blob.data()[0] = 1; blob.data()[1] = 2; @@ -187,20 +194,20 @@ TEST_F(BlobTests, canCopyBlob) { InferenceEngine::TBlob blob2(blob); - ASSERT_EQ(blob2.getTensorDesc().getDims().size(), blob.getTensorDesc().getDims().size()); - ASSERT_EQ(blob2.getTensorDesc().getDims()[0], blob.getTensorDesc().getDims()[0]); - ASSERT_EQ(blob2.getTensorDesc().getDims()[1], blob.getTensorDesc().getDims()[1]); - ASSERT_EQ(blob2.size(), blob.size()); - ASSERT_EQ(blob2.data()[0], blob.data()[0]); - ASSERT_EQ(blob2.data()[1], blob.data()[1]); - ASSERT_EQ(blob2.data()[2], blob.data()[2]); + ASSERT_EQ(blob2.getTensorDesc().getDims().size(), blob.getTensorDesc().getDims().size()); + ASSERT_EQ(blob2.getTensorDesc().getDims()[0], blob.getTensorDesc().getDims()[0]); + ASSERT_EQ(blob2.getTensorDesc().getDims()[1], blob.getTensorDesc().getDims()[1]); + ASSERT_EQ(blob2.size(), blob.size()); + ASSERT_EQ(blob2.data()[0], blob.data()[0]); + ASSERT_EQ(blob2.data()[1], blob.data()[1]); + ASSERT_EQ(blob2.data()[2], blob.data()[2]); } TEST_F(BlobTests, canCompareToNullPtrWithoutDereferencing) { InferenceEngine::SizeVector v = {1, 2, 3}; auto allocator = createMockAllocator(); - InferenceEngine::TBlob blob({ InferenceEngine::Precision::U8, v, InferenceEngine::CHW }, + InferenceEngine::TBlob blob({InferenceEngine::Precision::U8, v, InferenceEngine::CHW}, std::dynamic_pointer_cast(allocator)); ASSERT_TRUE(blob.readOnly() == nullptr); @@ -213,35 +220,36 @@ TEST_F(BlobTests, canCompareToNullPtrWithoutDereferencing) { } TEST_F(BlobTests, canCreateBlob) { - InferenceEngine::SizeVector size = { 1, 1, 1 }; - InferenceEngine::TBlob blob({ InferenceEngine::Precision::FP32, size, InferenceEngine::CHW }); + InferenceEngine::SizeVector size = {1, 1, 1}; + InferenceEngine::TBlob blob({InferenceEngine::Precision::FP32, size, InferenceEngine::CHW}); ASSERT_NE(blob.size(), 0); ASSERT_EQ(blob.rwmap(), nullptr); } TEST_F(BlobTests, canAllocateBlob) { - InferenceEngine::SizeVector size = { 1, 1, 1 }; - InferenceEngine::TBlob blob({ InferenceEngine::Precision::FP32, size, InferenceEngine::CHW }); + InferenceEngine::SizeVector size = {1, 1, 1}; + InferenceEngine::TBlob blob({InferenceEngine::Precision::FP32, size, InferenceEngine::CHW}); blob.allocate(); float* buffer = static_cast(blob.data()); ASSERT_NE(buffer, nullptr); } TEST_F(BlobTests, canDeallocateBlob) { - InferenceEngine::SizeVector size = { 1, 1, 1 }; - InferenceEngine::TBlob blob({ InferenceEngine::Precision::FP32, size, InferenceEngine::CHW }); + InferenceEngine::SizeVector size = {1, 1, 1}; + InferenceEngine::TBlob blob({InferenceEngine::Precision::FP32, size, InferenceEngine::CHW}); blob.allocate(); blob.deallocate(); ASSERT_EQ(nullptr, blob.data().as()); } TEST_F(BlobTests, canCreateBlobWithoutDims) { - InferenceEngine::TBlob blob(InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, InferenceEngine::NCHW)); + InferenceEngine::TBlob blob( + InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, InferenceEngine::NCHW)); ASSERT_EQ(blob.getTensorDesc().getDims().size(), 0); } TEST_F(BlobTests, canReadDataFromConstBlob) { - InferenceEngine::TBlob blob({ InferenceEngine::Precision::FP32, { 1, 1, 1 }, InferenceEngine::CHW }); + InferenceEngine::TBlob blob({InferenceEngine::Precision::FP32, {1, 1, 1}, InferenceEngine::CHW}); blob.allocate(); blob.data()[0] = 1.0f; InferenceEngine::TBlob const blob2 = blob; @@ -250,15 +258,15 @@ TEST_F(BlobTests, canReadDataFromConstBlob) { } TEST_F(BlobTests, canMakeSharedBlob) { - InferenceEngine::SizeVector size = { 1, 1, 1 }; + InferenceEngine::SizeVector size = {1, 1, 1}; InferenceEngine::TBlob::Ptr blob1 = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, InferenceEngine::NCHW)); - InferenceEngine::TBlob::Ptr blob2 = InferenceEngine::make_shared_blob( - { InferenceEngine::Precision::FP32, size, InferenceEngine::CHW }); - InferenceEngine::TBlob::Ptr blob3 - = InferenceEngine::make_shared_blob({ InferenceEngine::Precision::FP32, { 0 }, InferenceEngine::C }); - InferenceEngine::TBlob::Ptr blob4 = InferenceEngine::make_shared_blob( - { InferenceEngine::Precision::FP32, size, InferenceEngine::HWC }); + InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, InferenceEngine::NCHW)); + InferenceEngine::TBlob::Ptr blob2 = + InferenceEngine::make_shared_blob({InferenceEngine::Precision::FP32, size, InferenceEngine::CHW}); + InferenceEngine::TBlob::Ptr blob3 = + InferenceEngine::make_shared_blob({InferenceEngine::Precision::FP32, {0}, InferenceEngine::C}); + InferenceEngine::TBlob::Ptr blob4 = + InferenceEngine::make_shared_blob({InferenceEngine::Precision::FP32, size, InferenceEngine::HWC}); ASSERT_EQ(blob1->size(), 0); ASSERT_EQ(blob2->size(), 1); ASSERT_EQ(blob3->size(), 0); @@ -296,7 +304,9 @@ TEST_F(BlobTests, DISABLED_canUseLockedMemoryAsRvalueReference) { std::vector dump; std::vector v({1.0f, 2.0f, 3.0f}); auto blob = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, InferenceEngine::C), &v[0], v.size()); + InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, InferenceEngine::C), + &v[0], + v.size()); for (auto e : *blob) { dump.push_back(e); } @@ -312,7 +322,8 @@ TEST_F(BlobTests, canCreateBlobOnExistedMemory) { float input[] = {0.1f, 0.2f, 0.3f}; { auto b = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, {1, 2}, InferenceEngine::HW), input); + InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, {1, 2}, InferenceEngine::HW), + input); auto i = b->begin(); ASSERT_NEAR(*i, 0.1, 0.00001); i++; @@ -324,11 +335,10 @@ TEST_F(BlobTests, canCreateBlobOnExistedMemory) { } } - // SetShape TEST_F(BlobTests, canSetShape) { auto b = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, {1, 2, 3}, InferenceEngine::ANY)); + InferenceEngine::TensorDesc(InferenceEngine::Precision::FP32, {1, 2, 3}, InferenceEngine::ANY)); b->allocate(); ASSERT_NO_THROW(b->setShape({4, 5, 6})); @@ -340,14 +350,12 @@ TEST_F(BlobTests, canSetShape) { ASSERT_EQ(newDims[2], 6); } - - TEST_F(BlobTests, canModifyDataInRangedFor) { InferenceEngine::SizeVector v = {1, 2, 3}; - InferenceEngine::TBlob blob({ InferenceEngine::Precision::I32, v, InferenceEngine::CHW }); + InferenceEngine::TBlob blob({InferenceEngine::Precision::I32, v, InferenceEngine::CHW}); blob.allocate(); - for (auto & data : blob) { + for (auto& data : blob) { data = 5; } @@ -360,11 +368,15 @@ TEST_F(BlobTests, makeRoiBlobNchw) { // we create main blob with NCHW layout. We will crop ROI from this blob. InferenceEngine::SizeVector dims = {1, 3, 6, 5}; // RGB picture of size (WxH) = 5x6 InferenceEngine::Blob::Ptr blob = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NCHW)); + InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NCHW)); blob->allocate(); // create ROI blob based on the already created blob - InferenceEngine::ROI roi = {0, 2, 1, 2, 4}; // cropped picture with: id = 0, (x,y) = (2,1), sizeX (W) = 2, sizeY (H) = 4 + InferenceEngine::ROI roi = {0, + 2, + 1, + 2, + 4}; // cropped picture with: id = 0, (x,y) = (2,1), sizeX (W) = 2, sizeY (H) = 4 InferenceEngine::Blob::Ptr roiBlob = make_shared_blob(blob, roi); // check that BlockingDesc is constructed properly for the ROI blob @@ -382,11 +394,15 @@ TEST_F(BlobTests, makeRoiBlobNhwc) { // we create main blob with NHWC layout. We will crop ROI from this blob. InferenceEngine::SizeVector dims = {1, 3, 4, 8}; // RGB picture of size (WxH) = 8x4 InferenceEngine::Blob::Ptr blob = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NHWC)); + InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NHWC)); blob->allocate(); // create ROI blob based on the already created blob - InferenceEngine::ROI roi = {0, 3, 2, 5, 2}; // cropped picture with: id = 0, (x,y) = (3,2), sizeX (W) = 5, sizeY (H) = 2 + InferenceEngine::ROI roi = {0, + 3, + 2, + 5, + 2}; // cropped picture with: id = 0, (x,y) = (3,2), sizeX (W) = 5, sizeY (H) = 2 InferenceEngine::Blob::Ptr roiBlob = make_shared_blob(blob, roi); // check that BlockingDesc is constructed properly for the ROI blob @@ -404,11 +420,15 @@ TEST_F(BlobTests, makeRoiBlobWrongSize) { // we create main blob with NCHW layout. We will crop ROI from this blob. InferenceEngine::SizeVector dims = {1, 3, 4, 4}; // RGB picture of size (WxH) = 4x4 InferenceEngine::Blob::Ptr blob = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NCHW)); + InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NCHW)); blob->allocate(); // try to create ROI blob with wrong size - InferenceEngine::ROI roi = {0, 1, 1, 4, 4}; // cropped picture with: id = 0, (x,y) = (1,1), sizeX (W) = 4, sizeY (H) = 4 + InferenceEngine::ROI roi = {0, + 1, + 1, + 4, + 4}; // cropped picture with: id = 0, (x,y) = (1,1), sizeX (W) = 4, sizeY (H) = 4 ASSERT_THROW(make_shared_blob(blob, roi), InferenceEngine::Exception); } @@ -416,13 +436,9 @@ TEST_F(BlobTests, readRoiBlob) { // Create original Blob const auto origDesc = - InferenceEngine::TensorDesc( - InferenceEngine::Precision::I32, - {1, 3, 4, 8}, - InferenceEngine::NCHW); + InferenceEngine::TensorDesc(InferenceEngine::Precision::I32, {1, 3, 4, 8}, InferenceEngine::NCHW); - const auto origBlob = - InferenceEngine::make_shared_blob(origDesc); + const auto origBlob = InferenceEngine::make_shared_blob(origDesc); origBlob->allocate(); // Fill the original Blob @@ -468,14 +484,17 @@ TEST_F(BlobTests, makeRangeRoiBlobNchw) { // we create main blob with NCHW layout. We will crop ROI from this blob. InferenceEngine::SizeVector dims = {1, 3, 6, 5}; // RGB picture of size (WxH) = 5x6 InferenceEngine::Blob::Ptr blob = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NCHW)); + InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NCHW)); blob->allocate(); // create ROI blob based on the already created blob - InferenceEngine::ROI roi = {0, 2, 1, 2, 4}; // cropped picture with: id = 0, (x,y) = (2,1), sizeX (W) = 2, sizeY (H) = 4 - InferenceEngine::Blob::Ptr roiBlob = make_shared_blob(blob, - {0, 0, roi.posY, roi.posX}, - {1, 3, roi.posY + roi.sizeY, roi.posX + roi.sizeX}); + InferenceEngine::ROI roi = {0, + 2, + 1, + 2, + 4}; // cropped picture with: id = 0, (x,y) = (2,1), sizeX (W) = 2, sizeY (H) = 4 + InferenceEngine::Blob::Ptr roiBlob = + make_shared_blob(blob, {0, 0, roi.posY, roi.posX}, {1, 3, roi.posY + roi.sizeY, roi.posX + roi.sizeX}); // check that BlockingDesc is constructed properly for the ROI blob InferenceEngine::SizeVector refDims = {1, 3, 4, 2}; @@ -492,14 +511,17 @@ TEST_F(BlobTests, makeRangeRoiBlobNhwc) { // we create main blob with NHWC layout. We will crop ROI from this blob. InferenceEngine::SizeVector dims = {1, 3, 4, 8}; // RGB picture of size (WxH) = 8x4 InferenceEngine::Blob::Ptr blob = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NHWC)); + InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NHWC)); blob->allocate(); // create ROI blob based on the already created blob - InferenceEngine::ROI roi = {0, 3, 2, 5, 2}; // cropped picture with: id = 0, (x,y) = (3,2), sizeX (W) = 5, sizeY (H) = 2 - InferenceEngine::Blob::Ptr roiBlob = make_shared_blob(blob, - {0, 0, roi.posY, roi.posX}, - {1, 3, roi.posY + roi.sizeY, roi.posX + roi.sizeX}); + InferenceEngine::ROI roi = {0, + 3, + 2, + 5, + 2}; // cropped picture with: id = 0, (x,y) = (3,2), sizeX (W) = 5, sizeY (H) = 2 + InferenceEngine::Blob::Ptr roiBlob = + make_shared_blob(blob, {0, 0, roi.posY, roi.posX}, {1, 3, roi.posY + roi.sizeY, roi.posX + roi.sizeX}); // check that BlockingDesc is constructed properly for the ROI blob InferenceEngine::SizeVector refDims = {1, 2, 5, 3}; @@ -516,27 +538,26 @@ TEST_F(BlobTests, makeRangeRoiBlobWrongSize) { // we create main blob with NCHW layout. We will crop ROI from this blob. InferenceEngine::SizeVector dims = {1, 3, 4, 4}; // RGB picture of size (WxH) = 4x4 InferenceEngine::Blob::Ptr blob = InferenceEngine::make_shared_blob( - InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NCHW)); + InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, dims, InferenceEngine::NCHW)); blob->allocate(); // try to create ROI blob with wrong size - InferenceEngine::ROI roi = {0, 1, 1, 4, 4}; // cropped picture with: id = 0, (x,y) = (1,1), sizeX (W) = 4, sizeY (H) = 4 - ASSERT_THROW(make_shared_blob(blob, - {0, 0, roi.posY, roi.posX}, - {1, 3, roi.posY + roi.sizeY, roi.posX + roi.sizeX}), InferenceEngine::Exception); + InferenceEngine::ROI roi = {0, + 1, + 1, + 4, + 4}; // cropped picture with: id = 0, (x,y) = (1,1), sizeX (W) = 4, sizeY (H) = 4 + ASSERT_THROW(make_shared_blob(blob, {0, 0, roi.posY, roi.posX}, {1, 3, roi.posY + roi.sizeY, roi.posX + roi.sizeX}), + InferenceEngine::Exception); } TEST_F(BlobTests, readRangeRoiBlob) { // Create original Blob const auto origDesc = - InferenceEngine::TensorDesc( - InferenceEngine::Precision::I32, - {1, 3, 4, 8}, - InferenceEngine::NCHW); + InferenceEngine::TensorDesc(InferenceEngine::Precision::I32, {1, 3, 4, 8}, InferenceEngine::NCHW); - const auto origBlob = - InferenceEngine::make_shared_blob(origDesc); + const auto origBlob = InferenceEngine::make_shared_blob(origDesc); origBlob->allocate(); // Fill the original Blob @@ -555,9 +576,8 @@ TEST_F(BlobTests, readRangeRoiBlob) { const auto roi = InferenceEngine::ROI(0, 4, 2, 4, 2); - const auto roiBlob = InferenceEngine::as(origBlob->createROI( - {0, 0, roi.posY, roi.posX}, - {1, 3, roi.posY + roi.sizeY, roi.posX + roi.sizeX})); + const auto roiBlob = InferenceEngine::as( + origBlob->createROI({0, 0, roi.posY, roi.posX}, {1, 3, roi.posY + roi.sizeY, roi.posX + roi.sizeX})); ASSERT_NE(nullptr, roiBlob); // Read ROI Blob diff --git a/src/inference/tests/unit/ie_compilation_context_test.cpp b/src/inference/tests/unit/ie_compilation_context_test.cpp index 4c9b79047c3..0874387cff8 100644 --- a/src/inference/tests/unit/ie_compilation_context_test.cpp +++ b/src/inference/tests/unit/ie_compilation_context_test.cpp @@ -2,22 +2,22 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include -#include -#include -#include -#include "compilation_context.hpp" -#include "ngraph/function.hpp" -#include "ngraph/ops.hpp" -#include "ngraph/variant.hpp" -#include "ngraph/opsets/opset6.hpp" -#include "transformations/rt_info/fused_names_attribute.hpp" -#include "transformations/rt_info/primitives_priority_attribute.hpp" -#include "cpp/ie_cnn_network.h" +#include +#include +#include +#include #include "common_test_utils/test_constants.hpp" +#include "compilation_context.hpp" +#include "cpp/ie_cnn_network.h" +#include "ngraph/function.hpp" +#include "ngraph/ops.hpp" +#include "ngraph/opsets/opset6.hpp" +#include "ngraph/variant.hpp" +#include "transformations/rt_info/fused_names_attribute.hpp" +#include "transformations/rt_info/primitives_priority_attribute.hpp" using namespace InferenceEngine; using namespace ngraph; @@ -40,9 +40,12 @@ static std::string generateTestFilePrefix() { class FileGuard { std::string m_fileName; + public: - explicit FileGuard(std::string name): m_fileName(std::move(name)) {} - ~FileGuard() { std::remove(m_fileName.c_str()); } + explicit FileGuard(std::string name) : m_fileName(std::move(name)) {} + ~FileGuard() { + std::remove(m_fileName.c_str()); + } }; class NetworkContext_CalcFileInfoTests : public Test { @@ -98,9 +101,8 @@ TEST_F(NetworkContext_CalcFileInfoTests, ExistingDiffFiles) { TEST_F(NetworkContext_CalcFileInfoTests, ExistingFile_sameAbsPath) { std::string file1 = m_fileName; std::string file2 = std::string(".") + CommonTestUtils::FileSeparator + m_fileName; - ASSERT_EQ(NetworkCompilationContext::calculateFileInfo(file1), - NetworkCompilationContext::calculateFileInfo(file2)) << - "Hash of [" << file1 << "] is not equal to hash of [" << file2 << "]"; + ASSERT_EQ(NetworkCompilationContext::calculateFileInfo(file1), NetworkCompilationContext::calculateFileInfo(file2)) + << "Hash of [" << file1 << "] is not equal to hash of [" << file2 << "]"; } TEST_F(NetworkContext_CalcFileInfoTests, DateModified) { @@ -172,35 +174,29 @@ static void checkCustomRt(const std::function& emptyCb, const std::function& nameCb) { auto net1 = createNetwork(); auto net2 = createNetwork(); - auto & op1 = net1.getFunction()->get_ops().front()->get_rt_info(); - auto & op2 = net2.getFunction()->get_ops().front()->get_rt_info(); + auto& op1 = net1.getFunction()->get_ops().front()->get_rt_info(); + auto& op2 = net2.getFunction()->get_ops().front()->get_rt_info(); emptyCb(op2); - ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); emptyCb(op1); - ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); nameCb(op1, "test"); - ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); nameCb(op2, "test"); - ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); nameCb(op1, "test2"); - ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); } TEST(NetworkContext_CNNNetwork, HashOfSame) { auto net1 = createNetwork(); auto net2 = createNetwork(); - ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); } TEST(NetworkContext_CNNNetwork, HashWithConfig) { @@ -216,17 +212,15 @@ TEST(NetworkContext_CNNNetwork, HashWithPrimitivesPriority) { auto net1 = createNetwork(); auto net2 = createNetwork(); auto net3 = createNetwork(); - auto & op2 = net2.getFunction()->get_ops().front()->get_rt_info(); + auto& op2 = net2.getFunction()->get_ops().front()->get_rt_info(); op2[ov::PrimitivesPriority::get_type_info_static()] = ov::PrimitivesPriority("testPriority"); - auto & op3 = net3.getFunction()->get_ops().front()->get_rt_info(); + auto& op3 = net3.getFunction()->get_ops().front()->get_rt_info(); op3["PrimitivesPriority"] = "testPriority"; - ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); - ASSERT_EQ(NetworkCompilationContext::computeHash(net2, {}), - NetworkCompilationContext::computeHash(net3, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(net2, {}), NetworkCompilationContext::computeHash(net3, {})); } TEST(NetworkContext_CNNNetwork, HashWithFusedNames) { @@ -253,17 +247,15 @@ TEST(NetworkContext_CNNNetwork, HashWithAffinity) { auto net1 = createNetwork(); auto net2 = createNetwork(); auto net3 = createNetwork(); - auto & op2 = net2.getFunction()->get_ops().front()->get_rt_info(); + auto& op2 = net2.getFunction()->get_ops().front()->get_rt_info(); op2["affinity"] = "testAffinity"; - auto & op3 = net3.getFunction()->get_ops().front()->get_rt_info(); + auto& op3 = net3.getFunction()->get_ops().front()->get_rt_info(); op3["affinity"] = "testAffinity"; - ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); - ASSERT_EQ(NetworkCompilationContext::computeHash(net2, {}), - NetworkCompilationContext::computeHash(net3, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(net2, {}), NetworkCompilationContext::computeHash(net3, {})); } TEST(NetworkContext_CNNNetwork, HashWithFutureRt_string) { @@ -271,20 +263,18 @@ TEST(NetworkContext_CNNNetwork, HashWithFutureRt_string) { auto net2 = createNetwork(); auto net3 = createNetwork(); - auto & op1 = net1.getFunction()->get_ops().front()->get_rt_info(); + auto& op1 = net1.getFunction()->get_ops().front()->get_rt_info(); op1["someFutureKey"] = "hello"; - auto & op2 = net2.getFunction()->get_ops().front()->get_rt_info(); + auto& op2 = net2.getFunction()->get_ops().front()->get_rt_info(); op2["someFutureKey"] = "hello"; - auto & op3 = net3.getFunction()->get_ops().front()->get_rt_info(); + auto& op3 = net3.getFunction()->get_ops().front()->get_rt_info(); op3["someFutureKey"] = "olleh"; - ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); - ASSERT_NE(NetworkCompilationContext::computeHash(net2, {}), - NetworkCompilationContext::computeHash(net3, {})); + ASSERT_NE(NetworkCompilationContext::computeHash(net2, {}), NetworkCompilationContext::computeHash(net3, {})); } TEST(NetworkContext_CNNNetwork, HashWithFutureRt_int64) { @@ -292,20 +282,18 @@ TEST(NetworkContext_CNNNetwork, HashWithFutureRt_int64) { auto net2 = createNetwork(); auto net3 = createNetwork(); - auto & op1 = net1.getFunction()->get_ops().front()->get_rt_info(); + auto& op1 = net1.getFunction()->get_ops().front()->get_rt_info(); op1["someFutureKey"] = int64_t(42); - auto & op2 = net2.getFunction()->get_ops().front()->get_rt_info(); + auto& op2 = net2.getFunction()->get_ops().front()->get_rt_info(); op2["someFutureKey"] = int64_t(42); - auto & op3 = net3.getFunction()->get_ops().front()->get_rt_info(); + auto& op3 = net3.getFunction()->get_ops().front()->get_rt_info(); op3["someFutureKey"] = int64_t(43); - ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); - ASSERT_NE(NetworkCompilationContext::computeHash(net2, {}), - NetworkCompilationContext::computeHash(net3, {})); + ASSERT_NE(NetworkCompilationContext::computeHash(net2, {}), NetworkCompilationContext::computeHash(net3, {})); } TEST(NetworkContext_CNNNetwork, HashWithLayout) { @@ -321,20 +309,15 @@ TEST(NetworkContext_CNNNetwork, HashWithLayout) { fun5->get_results()[0]->set_layout(ov::Layout()); auto net5 = CNNNetwork(fun5); - EXPECT_EQ(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + EXPECT_EQ(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); - EXPECT_NE(NetworkCompilationContext::computeHash(net2, {}), - NetworkCompilationContext::computeHash(net3, {})); + EXPECT_NE(NetworkCompilationContext::computeHash(net2, {}), NetworkCompilationContext::computeHash(net3, {})); - EXPECT_NE(NetworkCompilationContext::computeHash(net3, {}), - NetworkCompilationContext::computeHash(net3_1, {})); + EXPECT_NE(NetworkCompilationContext::computeHash(net3, {}), NetworkCompilationContext::computeHash(net3_1, {})); - EXPECT_NE(NetworkCompilationContext::computeHash(net3, {}), - NetworkCompilationContext::computeHash(net4, {})); + EXPECT_NE(NetworkCompilationContext::computeHash(net3, {}), NetworkCompilationContext::computeHash(net4, {})); - EXPECT_EQ(NetworkCompilationContext::computeHash(net4, {}), - NetworkCompilationContext::computeHash(net5, {})); + EXPECT_EQ(NetworkCompilationContext::computeHash(net4, {}), NetworkCompilationContext::computeHash(net5, {})); } TEST(NetworkContext_CNNNetwork, HashWithTensorNames) { @@ -361,11 +344,9 @@ TEST(NetworkContext_CNNNetwork, HashWithTensorNames) { auto net2 = CNNNetwork(fun2); auto net3 = CNNNetwork(fun3); - ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); - ASSERT_NE(NetworkCompilationContext::computeHash(net2, {}), - NetworkCompilationContext::computeHash(net3, {})); + ASSERT_NE(NetworkCompilationContext::computeHash(net2, {}), NetworkCompilationContext::computeHash(net3, {})); } TEST(NetworkContext_CNNNetwork, HashWithDifferentResults) { @@ -374,15 +355,13 @@ TEST(NetworkContext_CNNNetwork, HashWithDifferentResults) { net2.getFunction()->remove_result(net2.getFunction()->get_results().front()); auto net3 = createNetwork(); net3.getFunction()->remove_result(net3.getFunction()->get_results().front()); - ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); - ASSERT_EQ(NetworkCompilationContext::computeHash(net2, {}), - NetworkCompilationContext::computeHash(net3, {})); + ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(net2, {}), NetworkCompilationContext::computeHash(net3, {})); } TEST(NetworkContext_CNNNetwork, HashWithDifferentMeanValues) { auto updatePreprocess = [&](CNNNetwork& cnnNet) { - auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess(); + auto& preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess(); preProcess.init(3); preProcess[0]->stdScale = 2; preProcess[1]->stdScale = 3; @@ -397,10 +376,8 @@ TEST(NetworkContext_CNNNetwork, HashWithDifferentMeanValues) { updatePreprocess(net2); auto net3 = createNetwork(); updatePreprocess(net3); - ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), - NetworkCompilationContext::computeHash(net2, {})); - ASSERT_EQ(NetworkCompilationContext::computeHash(net2, {}), - NetworkCompilationContext::computeHash(net3, {})); + ASSERT_NE(NetworkCompilationContext::computeHash(net1, {}), NetworkCompilationContext::computeHash(net2, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(net2, {}), NetworkCompilationContext::computeHash(net3, {})); } // Verify all internal hash calculations are thread-safe (like ngraph::function serialization) @@ -455,11 +432,9 @@ TEST(NetworkContext_ModelName, HashOfExistingFile) { std::ofstream os(file1); os << "test"; } - ASSERT_EQ(NetworkCompilationContext::computeHash(file1, {}), - NetworkCompilationContext::computeHash(file1, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(file1, {}), NetworkCompilationContext::computeHash(file1, {})); - ASSERT_EQ(NetworkCompilationContext::computeHash(file1, {}), - NetworkCompilationContext::computeHash(file2, {})); + ASSERT_EQ(NetworkCompilationContext::computeHash(file1, {}), NetworkCompilationContext::computeHash(file2, {})); ASSERT_NE(NetworkCompilationContext::computeHash(file1, {{"key", "value"}}), NetworkCompilationContext::computeHash(file2, {})); diff --git a/src/inference/tests/unit/ie_compound_blob_test.cpp b/src/inference/tests/unit/ie_compound_blob_test.cpp index aa1d8230185..f8d8e21da9b 100644 --- a/src/inference/tests/unit/ie_compound_blob_test.cpp +++ b/src/inference/tests/unit/ie_compound_blob_test.cpp @@ -2,10 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include -#include +#include + #include +#include using namespace ::testing; using namespace std; @@ -138,8 +139,7 @@ TEST(BlobConversionTests, blobSharesOwnershipOnCast) { TEST_F(CompoundBlobTests, cannotCreateCompoundBlobFromNullptr) { Blob::Ptr valid = make_shared_blob(TensorDesc(Precision::U8, {1, 3, 4, 4}, NCHW)); - EXPECT_THROW(make_shared_blob(std::vector({valid, nullptr})), - InferenceEngine::Exception); + EXPECT_THROW(make_shared_blob(std::vector({valid, nullptr})), InferenceEngine::Exception); } TEST_F(CompoundBlobTests, canCreateEmptyCompoundBlob) { @@ -174,7 +174,7 @@ TEST_F(CompoundBlobTests, cannotCreateCompoundBlobFromCompoundBlob) { verifyCompoundBlob(_test_blob); EXPECT_THROW(make_shared_blob(std::vector({blob, _test_blob})), - InferenceEngine::Exception); + InferenceEngine::Exception); } TEST_F(CompoundBlobTests, compoundBlobHoldsCorrectDataInCorrectOrder) { @@ -202,7 +202,7 @@ TEST_F(CompoundBlobTests, compoundBlobHoldsCorrectDataInCorrectOrder) { MemoryBlob::Ptr mb = as(blob); ASSERT_NE(nullptr, mb); auto lm = mb->rwmap(); - EXPECT_EQ(static_cast(i + MAGIC_NUMBER), lm.as()[0]); + EXPECT_EQ(static_cast(i + MAGIC_NUMBER), lm.as()[0]); } } @@ -220,9 +220,9 @@ TEST_F(CompoundBlobTests, compoundBlobHoldsReferencesToBlobs) { CompoundBlob::Ptr compound_blob = as(_test_blob); Blob::Ptr b0 = compound_blob->getBlob(0); MemoryBlob::CPtr mb0 = as(b0); - EXPECT_EQ(12, mb0->rmap().as()[0]); + EXPECT_EQ(12, mb0->rmap().as()[0]); blob->rwmap().as()[0] = 34; - EXPECT_EQ(34, mb0->rmap().as()[0]); + EXPECT_EQ(34, mb0->rmap().as()[0]); } TEST_F(CompoundBlobTests, compoundBlobHoldsValidDataWhenUnderlyingBlobIsDestroyed) { @@ -242,38 +242,32 @@ TEST_F(CompoundBlobTests, compoundBlobHoldsValidDataWhenUnderlyingBlobIsDestroye ASSERT_NE(nullptr, compound_blob->getBlob(0)); MemoryBlob::CPtr mb0 = as(compound_blob->getBlob(0)); ASSERT_NE(nullptr, mb0); - EXPECT_EQ(stored_value, mb0->rmap().as()[0]); + EXPECT_EQ(stored_value, mb0->rmap().as()[0]); } TEST_F(NV12BlobTests, cannotCreateNV12BlobFromNullptrBlobs) { Blob::Ptr valid = make_shared_blob(TensorDesc(Precision::U8, {1, 1, 4, 4}, NHWC)); - EXPECT_THROW(make_shared_blob(valid, nullptr), - InferenceEngine::Exception); - EXPECT_THROW(make_shared_blob(nullptr, valid), - InferenceEngine::Exception); + EXPECT_THROW(make_shared_blob(valid, nullptr), InferenceEngine::Exception); + EXPECT_THROW(make_shared_blob(nullptr, valid), InferenceEngine::Exception); } TEST_F(NV12BlobTests, cannotCreateNV12BlobFromCompoundBlobs) { Blob::Ptr blob = make_shared_blob(TensorDesc(Precision::U8, {1, 1, 4, 4}, NHWC)); auto cblob = make_shared_blob(std::vector({blob})); - EXPECT_THROW(make_shared_blob(cblob, blob), - InferenceEngine::Exception); - EXPECT_THROW(make_shared_blob(blob, cblob), - InferenceEngine::Exception); + EXPECT_THROW(make_shared_blob(cblob, blob), InferenceEngine::Exception); + EXPECT_THROW(make_shared_blob(blob, cblob), InferenceEngine::Exception); } TEST_F(NV12BlobTests, cannotCreateNV12BlobFromPlanesWithDifferentElementSize) { Blob::Ptr blob_u8 = make_shared_blob(TensorDesc(Precision::U8, {1, 1, 4, 4}, NHWC)); Blob::Ptr blob_float = make_shared_blob(TensorDesc(Precision::FP32, {1, 2, 2, 2}, NHWC)); - EXPECT_THROW(make_shared_blob(blob_u8, blob_float), - InferenceEngine::Exception); + EXPECT_THROW(make_shared_blob(blob_u8, blob_float), InferenceEngine::Exception); } TEST_F(NV12BlobTests, cannotCreateNV12BlobFromPlanesWithNonU8Precision) { Blob::Ptr float_y_blob = make_shared_blob(TensorDesc(Precision::FP32, {1, 1, 4, 4}, NHWC)); Blob::Ptr float_uv_blob = make_shared_blob(TensorDesc(Precision::FP32, {1, 2, 2, 2}, NHWC)); - EXPECT_THROW(make_shared_blob(float_y_blob, float_uv_blob), - InferenceEngine::Exception); + EXPECT_THROW(make_shared_blob(float_y_blob, float_uv_blob), InferenceEngine::Exception); } TEST_F(NV12BlobTests, cannotCreateNV12BlobFromPlanesWithInconsistentBatchSize) { @@ -324,9 +318,9 @@ TEST_F(NV12BlobTests, canCreateNV12BlobFromTwoPlanes) { } TEST_F(NV12BlobTests, canCreateNV12BlobFromTwoMovedPlanes) { - NV12Blob::Ptr nv12_blob = make_shared_blob( - make_shared_blob(TensorDesc(Precision::U8, {1, 1, 6, 8}, NHWC)), - make_shared_blob(TensorDesc(Precision::U8, {1, 2, 3, 4}, NHWC))); + NV12Blob::Ptr nv12_blob = + make_shared_blob(make_shared_blob(TensorDesc(Precision::U8, {1, 1, 6, 8}, NHWC)), + make_shared_blob(TensorDesc(Precision::U8, {1, 2, 3, 4}, NHWC))); verifyCompoundBlob(nv12_blob); } @@ -342,10 +336,10 @@ TEST_F(I420BlobTests, canCreateI420BlobFromThreePlanes) { } TEST_F(I420BlobTests, canCreateI420BlobFromThreeMovedPlanes) { - I420Blob::Ptr i420_blob = make_shared_blob( - make_shared_blob(TensorDesc(Precision::U8, {1, 1, 6, 8}, NHWC)), - make_shared_blob(TensorDesc(Precision::U8, {1, 1, 3, 4}, NHWC)), - make_shared_blob(TensorDesc(Precision::U8, {1, 1, 3, 4}, NHWC))); + I420Blob::Ptr i420_blob = + make_shared_blob(make_shared_blob(TensorDesc(Precision::U8, {1, 1, 6, 8}, NHWC)), + make_shared_blob(TensorDesc(Precision::U8, {1, 1, 3, 4}, NHWC)), + make_shared_blob(TensorDesc(Precision::U8, {1, 1, 3, 4}, NHWC))); verifyCompoundBlob(i420_blob); } @@ -360,7 +354,7 @@ TEST_F(I420BlobTests, cannotCreateI420BlobFromCompoundBlobs) { Blob::Ptr u_blob = make_shared_blob(TensorDesc(Precision::U8, {1, 1, 3, 4}, NHWC)); Blob::Ptr v_blob = make_shared_blob(TensorDesc(Precision::U8, {1, 1, 3, 4}, NHWC)); - auto make_cblob = [](Blob::Ptr const& b){ + auto make_cblob = [](Blob::Ptr const& b) { return make_shared_blob(std::vector({b})); }; @@ -369,13 +363,13 @@ TEST_F(I420BlobTests, cannotCreateI420BlobFromCompoundBlobs) { auto c_v_blob = make_cblob(v_blob); using ie_exception_t = InferenceEngine::Exception; - EXPECT_THROW(make_shared_blob(c_y_blob, u_blob, v_blob), ie_exception_t); - EXPECT_THROW(make_shared_blob(y_blob, c_u_blob, v_blob), ie_exception_t); - EXPECT_THROW(make_shared_blob(y_blob, u_blob, c_v_blob), ie_exception_t); + EXPECT_THROW(make_shared_blob(c_y_blob, u_blob, v_blob), ie_exception_t); + EXPECT_THROW(make_shared_blob(y_blob, c_u_blob, v_blob), ie_exception_t); + EXPECT_THROW(make_shared_blob(y_blob, u_blob, c_v_blob), ie_exception_t); } TEST_F(I420BlobTests, cannotCreateI420BlobFromPlanesWithDifferentElementSize) { - Blob::Ptr y_blob_u8 = make_shared_blob(TensorDesc(Precision::U8, {1, 1, 4, 4}, NHWC)); + Blob::Ptr y_blob_u8 = make_shared_blob(TensorDesc(Precision::U8, {1, 1, 4, 4}, NHWC)); Blob::Ptr u_blob_float = make_shared_blob(TensorDesc(Precision::FP32, {1, 1, 2, 2}, NHWC)); Blob::Ptr v_blob_float = make_shared_blob(TensorDesc(Precision::FP32, {1, 1, 2, 2}, NHWC)); @@ -423,5 +417,3 @@ TEST_F(I420BlobTests, cannotCreateI420BlobFromPlanesWithWrongHeightRatio) { EXPECT_THROW(make_shared_blob(y_blob, u_blob, v_blob), InferenceEngine::Exception); EXPECT_THROW(make_shared_blob(y_blob, v_blob, u_blob), InferenceEngine::Exception); } - - diff --git a/src/inference/tests/unit/ie_exception_test.cpp b/src/inference/tests/unit/ie_exception_test.cpp index cbfc0fb8678..879a50ca20b 100644 --- a/src/inference/tests/unit/ie_exception_test.cpp +++ b/src/inference/tests/unit/ie_exception_test.cpp @@ -2,9 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include #include +#include + +#include #include "ie_common.h" @@ -25,7 +26,6 @@ TEST(ExceptionTests, CanDefineExceptionContent) { ASSERT_STREQ(exception.what(), ""); } - #ifndef NDEBUG TEST(ExceptionTests, ExceptionShowsCorrectMessageDebugVersion) { std::string message = "exception"; @@ -33,9 +33,8 @@ TEST(ExceptionTests, ExceptionShowsCorrectMessageDebugVersion) { try { lineNum = __LINE__ + 1; IE_THROW() << message; - } - catch (InferenceEngine::Exception &iex) { - std::string ref_message = std::string {"\n"} + __FILE__ + ":" + std::to_string(lineNum) + " " + message; + } catch (InferenceEngine::Exception& iex) { + std::string ref_message = std::string{"\n"} + __FILE__ + ":" + std::to_string(lineNum) + " " + message; ASSERT_STREQ(iex.what(), ref_message.c_str()); } } @@ -44,8 +43,7 @@ TEST(ExceptionTests, ExceptionShowsCorrectMessageReleaseVersion) { std::string message = "exception"; try { IE_THROW() << message; - } - catch (InferenceEngine::Exception &iex) { + } catch (InferenceEngine::Exception& iex) { std::string ref_message = message; ASSERT_STREQ(iex.what(), ref_message.c_str()); } @@ -56,7 +54,7 @@ TEST(ExceptionTests, ExceptionCanBeCaughtAsStandard) { ASSERT_THROW(IE_THROW(), std::exception); } -#ifdef NDEBUG // disabled for debug as macros calls assert() +#ifdef NDEBUG // disabled for debug as macros calls assert() TEST(ExceptionTests, ExceptionWithAssertThrowsNothingIfTrue) { ASSERT_NO_THROW(IE_ASSERT(true) << "shouldn't assert if true"); } diff --git a/src/inference/tests/unit/ie_executable_network_test.cpp b/src/inference/tests/unit/ie_executable_network_test.cpp index 01e77a29835..001e61f9312 100644 --- a/src/inference/tests/unit/ie_executable_network_test.cpp +++ b/src/inference/tests/unit/ie_executable_network_test.cpp @@ -2,28 +2,29 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "cpp/ie_executable_network.hpp" + #include +#include + #include #include -#include "cpp/ie_executable_network.hpp" #include "cpp/ie_executable_network_base.hpp" #include "cpp/ie_plugin.hpp" - -#include "unit_test_utils/mocks/mock_iexecutable_network.hpp" -#include "unit_test_utils/mocks/mock_iinfer_request.hpp" #include "unit_test_utils/mocks/cpp_interfaces/impl/mock_inference_plugin_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp" -#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_ivariable_state_internal.hpp" #include "unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp" +#include "unit_test_utils/mocks/cpp_interfaces/interface/mock_ivariable_state_internal.hpp" +#include "unit_test_utils/mocks/mock_iexecutable_network.hpp" +#include "unit_test_utils/mocks/mock_iinfer_request.hpp" using testing::_; using testing::MatcherCast; -using testing::Throw; using testing::Ref; using testing::Return; using testing::SetArgReferee; +using testing::Throw; // TODO: add tests for the next methods: // 1. void Export(const std::string& modelFileName) @@ -34,13 +35,12 @@ using testing::SetArgReferee; // 7. Parameter GetMetric(const std::string& name) const // 8. RemoteContext::Ptr GetContext() - class ExecutableNetworkTests : public ::testing::Test { protected: std::shared_ptr mockIExeNet; - ov::SoPtr exeNetwork; - MockIInferencePlugin* mockIPlugin; - InferencePlugin plugin; + ov::SoPtr exeNetwork; + MockIInferencePlugin* mockIPlugin; + InferencePlugin plugin; void TearDown() override { mockIExeNet.reset(); @@ -58,37 +58,36 @@ protected: }; TEST_F(ExecutableNetworkTests, GetOutputsInfoThrowsIfReturnErr) { - EXPECT_CALL(*mockIExeNet.get(), GetOutputsInfo()) - .Times(1) - .WillOnce(Throw(InferenceEngine::GeneralError{""})); + EXPECT_CALL(*mockIExeNet.get(), GetOutputsInfo()).Times(1).WillOnce(Throw(InferenceEngine::GeneralError{""})); ASSERT_THROW(exeNetwork->GetOutputsInfo(), InferenceEngine::Exception); } TEST_F(ExecutableNetworkTests, GetOutputsInfo) { InferenceEngine::ConstOutputsDataMap data; - EXPECT_CALL(*mockIExeNet.get(), GetOutputsInfo()).Times(1).WillRepeatedly(Return(InferenceEngine::ConstOutputsDataMap{})); + EXPECT_CALL(*mockIExeNet.get(), GetOutputsInfo()) + .Times(1) + .WillRepeatedly(Return(InferenceEngine::ConstOutputsDataMap{})); ASSERT_NO_THROW(data = exeNetwork->GetOutputsInfo()); ASSERT_EQ(data, InferenceEngine::ConstOutputsDataMap{}); } TEST_F(ExecutableNetworkTests, GetInputsInfoThrowsIfReturnErr) { - EXPECT_CALL(*mockIExeNet.get(), GetInputsInfo()) - .Times(1) - .WillOnce(Throw(InferenceEngine::GeneralError{""})); + EXPECT_CALL(*mockIExeNet.get(), GetInputsInfo()).Times(1).WillOnce(Throw(InferenceEngine::GeneralError{""})); ASSERT_THROW(exeNetwork->GetInputsInfo(), InferenceEngine::Exception); } TEST_F(ExecutableNetworkTests, GetInputsInfo) { - EXPECT_CALL(*mockIExeNet.get(), GetInputsInfo()).Times(1).WillRepeatedly(Return(InferenceEngine::ConstInputsDataMap{})); + EXPECT_CALL(*mockIExeNet.get(), GetInputsInfo()) + .Times(1) + .WillRepeatedly(Return(InferenceEngine::ConstInputsDataMap{})); InferenceEngine::ConstInputsDataMap info; ASSERT_NO_THROW(info = exeNetwork->GetInputsInfo()); ASSERT_EQ(info, InferenceEngine::ConstInputsDataMap{}); } - class ExecutableNetworkWithIInferReqTests : public ExecutableNetworkTests { protected: std::shared_ptr mockIInferReq_p; @@ -119,9 +118,7 @@ TEST_F(ExecutableNetworkWithIInferReqTests, QueryStateThrowsIfReturnErr) { EXPECT_CALL(*mockIExeNet.get(), CreateInferRequest()).WillOnce(Return(mockIInferReq_p)); IInferRequestInternal::Ptr actualInferReq; ASSERT_NO_THROW(actualInferReq = exeNetwork->CreateInferRequest()); - EXPECT_CALL(*mockIInferReq_p.get(), QueryState()) - .Times(1) - .WillOnce(Throw(InferenceEngine::GeneralError{""})); + EXPECT_CALL(*mockIInferReq_p.get(), QueryState()).Times(1).WillOnce(Throw(InferenceEngine::GeneralError{""})); EXPECT_THROW(actualInferReq->QueryState(), InferenceEngine::Exception); } @@ -131,8 +128,8 @@ TEST_F(ExecutableNetworkWithIInferReqTests, QueryState) { ASSERT_NO_THROW(actualInferReq = exeNetwork->CreateInferRequest()); auto mockIMemState_p = std::make_shared(); EXPECT_CALL(*mockIInferReq_p.get(), QueryState()) - .Times(1) - .WillOnce(Return(std::vector>(1, mockIMemState_p))); + .Times(1) + .WillOnce(Return(std::vector>(1, mockIMemState_p))); std::vector MemState_v; EXPECT_NO_THROW(MemState_v = actualInferReq->QueryState()); EXPECT_EQ(MemState_v.size(), 1); diff --git a/src/inference/tests/unit/ie_executor_manager_tests.cpp b/src/inference/tests/unit/ie_executor_manager_tests.cpp index dadbdada3fe..b8526be485c 100644 --- a/src/inference/tests/unit/ie_executor_manager_tests.cpp +++ b/src/inference/tests/unit/ie_executor_manager_tests.cpp @@ -3,6 +3,7 @@ // #include + #include using namespace ::testing; diff --git a/src/inference/tests/unit/ie_extension_test.cpp b/src/inference/tests/unit/ie_extension_test.cpp index 12675f118ea..7fecd6dbb34 100644 --- a/src/inference/tests/unit/ie_extension_test.cpp +++ b/src/inference/tests/unit/ie_extension_test.cpp @@ -2,17 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include - -#include #include +#include +#include +#include #include +#include -#include "common_test_utils/test_common.hpp" #include "common_test_utils/file_utils.hpp" +#include "common_test_utils/test_common.hpp" using namespace InferenceEngine; @@ -20,7 +19,7 @@ using ExtensionTests = ::testing::Test; std::string getExtensionPath() { return FileUtils::makePluginLibraryName(CommonTestUtils::getExecutableDirectory(), - std::string("template_extension") + IE_BUILD_POSTFIX); + std::string("template_extension") + IE_BUILD_POSTFIX); } #ifndef OPENVINO_STATIC_LIBRARY @@ -41,8 +40,7 @@ TEST(ExtensionTests, testGetImplTypes) { TEST(ExtensionTests, testGetImplTypesThrowsIfNgraphNodeIsNullPtr) { IExtensionPtr extension = std::make_shared(getExtensionPath()); - ASSERT_THROW(extension->getImplTypes(std::shared_ptr ()), - InferenceEngine::Exception); + ASSERT_THROW(extension->getImplTypes(std::shared_ptr()), InferenceEngine::Exception); } TEST(ExtensionTests, testGetImplementation) { @@ -54,8 +52,7 @@ TEST(ExtensionTests, testGetImplementation) { TEST(ExtensionTests, testGetImplementationThrowsIfNgraphNodeIsNullPtr) { IExtensionPtr extension = std::make_shared(getExtensionPath()); - ASSERT_THROW(extension->getImplementation(std::shared_ptr (), ""), - InferenceEngine::Exception); + ASSERT_THROW(extension->getImplementation(std::shared_ptr(), ""), InferenceEngine::Exception); } -#endif // OPENVINO_STATIC_LIBRARY +#endif // OPENVINO_STATIC_LIBRARY diff --git a/src/inference/tests/unit/ie_locked_memory_test.cpp b/src/inference/tests/unit/ie_locked_memory_test.cpp index 6142b88a98a..82eb8430043 100644 --- a/src/inference/tests/unit/ie_locked_memory_test.cpp +++ b/src/inference/tests/unit/ie_locked_memory_test.cpp @@ -3,6 +3,7 @@ // #include + #include "unit_test_utils/mocks/mock_allocator.hpp" using namespace InferenceEngine; @@ -12,11 +13,12 @@ TEST(LockedMemoryTest, canUnlockMemoryAfterUsage) { std::unique_ptr allocator(new MockAllocator()); char array[] = {1, 2, 3}; - EXPECT_CALL(*allocator.get(), lock(reinterpret_cast(1), _)).WillRepeatedly(Return(reinterpret_cast(array))); + EXPECT_CALL(*allocator.get(), lock(reinterpret_cast(1), _)) + .WillRepeatedly(Return(reinterpret_cast(array))); EXPECT_CALL(*allocator.get(), unlock(_)).Times(1); { auto x = LockedMemory(allocator.get(), reinterpret_cast(1), 1); - //force locking of memory + // force locking of memory auto t = x[0]; (void)t; } @@ -26,11 +28,12 @@ TEST(LockedMemoryTest, canReadFromLockedMemory) { std::unique_ptr allocator(new MockAllocator()); char array[] = {1, 2, 3, 4, 5}; - EXPECT_CALL(*allocator.get(), lock(reinterpret_cast(1), _)).WillRepeatedly(Return(reinterpret_cast(array))); + EXPECT_CALL(*allocator.get(), lock(reinterpret_cast(1), _)) + .WillRepeatedly(Return(reinterpret_cast(array))); EXPECT_CALL(*allocator.get(), unlock(_)).Times(1); { auto x = LockedMemory(allocator.get(), reinterpret_cast(1), 0); - //we are getting first element + // we are getting first element ASSERT_EQ(1, x[0]); } } @@ -39,12 +42,13 @@ TEST(LockedMemoryTest, canWriteToLockedMemory) { std::unique_ptr allocator(new MockAllocator()); char array[] = {1, 2, 3, 4, 5}; - EXPECT_CALL(*allocator.get(), lock(reinterpret_cast(1), _)).WillRepeatedly(Return(reinterpret_cast(array))); + EXPECT_CALL(*allocator.get(), lock(reinterpret_cast(1), _)) + .WillRepeatedly(Return(reinterpret_cast(array))); EXPECT_CALL(*allocator.get(), unlock(_)).Times(1); { auto x = LockedMemory(allocator.get(), reinterpret_cast(1), 0); - //we are getting first element + // we are getting first element ASSERT_EQ(std::distance(array, &x[0]), 0); x[0] = 5; } diff --git a/src/inference/tests/unit/memory_solver_test.cpp b/src/inference/tests/unit/memory_solver_test.cpp index ba6b6eac14a..9c839e64956 100644 --- a/src/inference/tests/unit/memory_solver_test.cpp +++ b/src/inference/tests/unit/memory_solver_test.cpp @@ -2,49 +2,54 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "memory_solver.hpp" + #include #include -#include "memory_solver.hpp" +#include using Box = MemorySolver::Box; - TEST(MemSolverTest, CanConstruct) { - { // Empty vector + { // Empty vector MemorySolver ms(std::vector{}); } - { // vector with default Box + { // vector with default Box MemorySolver ms(std::vector{{}}); } - { // vector with Box with non-default Box + { // vector with Box with non-default Box MemorySolver ms(std::vector{{1, 3, 3}}); } - { // vector with Box with size == 0 + { // vector with Box with size == 0 MemorySolver ms(std::vector{{0, 0, 0}}); } - { // vector with Box with finish == -1 + { // vector with Box with finish == -1 MemorySolver ms(std::vector{{3, -1, 6}}); } // TODO: enable after implement TODO from memory_solver.hpp#L66 -// { // vector with Box with negative values -// MemorySolver ms(std::vector {{-5, -5, -5, -5}}); -// } + // { // vector with Box with negative values + // MemorySolver ms(std::vector {{-5, -5, -5, -5}}); + // } } +// | +// | ____ ____ +// | __|____||____| +// |__|____||____|_____ +// 0 1 2 3 4 TEST(MemSolverTest, GetOffset) { int n = 0; - std::vector boxes{ // | - {n, ++n, 2, 0}, // | ____ ____ - {n, ++n, 2, 1}, // | __|____||____| - {n, ++n, 2, 2}, // |__|____||____|_____ - {n, ++n, 2, 3}, // 0 1 2 3 4 + std::vector boxes{ + {n, ++n, 2, 0}, + {n, ++n, 2, 1}, + {n, ++n, 2, 2}, + {n, ++n, 2, 3}, }; MemorySolver ms(boxes); @@ -56,13 +61,18 @@ TEST(MemSolverTest, GetOffset) { EXPECT_EQ(ms.getOffset(2) + ms.getOffset(3), 2); } +// | +// | ____ ____ +// | __|____||____| +// |__|____||____|_____ +// 0 1 2 3 4 TEST(MemSolverTest, GetOffsetThrowException) { int n = 0, id = 0; - std::vector boxes{ // | - {n, ++n, 2, id++}, // | ____ ____ - {n, ++n, 2, id++}, // | __|____||____| - {n, ++n, 2, id++}, // |__|____||____|_____ - {n, ++n, 2, id++}, // 0 1 2 3 4 + std::vector boxes{ + {n, ++n, 2, id++}, + {n, ++n, 2, id++}, + {n, ++n, 2, id++}, + {n, ++n, 2, id++}, }; MemorySolver ms(boxes); @@ -71,13 +81,18 @@ TEST(MemSolverTest, GetOffsetThrowException) { EXPECT_THROW(ms.getOffset(100), InferenceEngine::Exception); } +// | +// | ____ +// | __|____|__ +// |__|____||____|__ +// 0 1 2 3 TEST(MemSolverTest, LinearAndEven) { int n = 0; - std::vector boxes{ // | - {n, ++n, 2}, // | ____ - {n, ++n, 2}, // | __|____|__ - {n, ++n, 2}, // |__|____||____|__ - }; // 0 1 2 3 + std::vector boxes{ + {n, ++n, 2}, + {n, ++n, 2}, + {n, ++n, 2}, + }; MemorySolver ms(boxes); EXPECT_EQ(ms.solve(), 4); @@ -85,13 +100,18 @@ TEST(MemSolverTest, LinearAndEven) { EXPECT_EQ(ms.maxTopDepth(), 2); } +// | ____ +// | |____|__ +// | ____ | | +// |__|____||____|__ +// 0 1 2 3 TEST(MemSolverTest, LinearAndNotEven) { int n = 0; - std::vector boxes{ // | ____ - {n, ++n, 2}, // | |____|__ - {n, ++n, 2}, // | ____ | | - {n, ++n, 3}, // |__|____||____|__ - }; // 0 1 2 3 + std::vector boxes{ + {n, ++n, 2}, + {n, ++n, 2}, + {n, ++n, 3}, + }; MemorySolver ms(boxes); EXPECT_EQ(ms.solve(), 5); @@ -99,14 +119,18 @@ TEST(MemSolverTest, LinearAndNotEven) { EXPECT_EQ(ms.maxTopDepth(), 2); } - +// | _______ +// | |_______|_____ +// | _______ | | +// |__|_______|___|_______|__ +// 2 3 4 5 6 7 8 TEST(MemSolverTest, LinearWithEmptyExecIndexes) { int n = 2; - std::vector boxes{ // | _______ - {n, n += 2, 2}, // | |_______|_____ - {n, n += 2, 2}, // | _______ | | - {n, n += 2, 3}, // |__|_______|___|_______|__ - }; // 2 3 4 5 6 7 8 + std::vector boxes{ + {n, n += 2, 2}, + {n, n += 2, 2}, + {n, n += 2, 3}, + }; MemorySolver ms(boxes); EXPECT_EQ(ms.solve(), 5); @@ -114,12 +138,17 @@ TEST(MemSolverTest, LinearWithEmptyExecIndexes) { EXPECT_EQ(ms.maxTopDepth(), 2); } +// | __________ +// | ____ |_3________| +// | |_4__|_____ | | +// |__|_2________||_1__|___ +// 2 3 4 5 6 7 8 TEST(MemSolverTest, DISABLED_Unefficiency) { - std::vector boxes{ // | __________ - {6, 7, 3}, // | ____ |_3________| - {2, 5, 2}, // | |_4__|_____ | | - {5, 8, 2}, // |__|_2________||_1__|___ - {2, 3, 2}, // 2 3 4 5 6 7 8 + std::vector boxes{ + {6, 7, 3}, + {2, 5, 2}, + {5, 8, 2}, + {2, 3, 2}, }; MemorySolver ms(boxes); @@ -128,12 +157,17 @@ TEST(MemSolverTest, DISABLED_Unefficiency) { EXPECT_EQ(ms.maxTopDepth(), 2); } +// | __________ +// | ____ |_3________| +// | |_4__|_____ | | +// |__|_2________||_1__|___ +// 2 3 4 5 6 7 8 TEST(MemSolverTest, OverlappingBoxes) { - std::vector boxes{ // | __________ - {6, 7, 4}, // | ____ |_3________| - {2, 5, 3}, // | |_4__|_____ | | - {5, 8, 2}, // |__|_2________||_1__|___ - {2, 3, 2}, // 2 3 4 5 6 7 8 + std::vector boxes{ + {6, 7, 4}, + {2, 5, 3}, + {5, 8, 2}, + {2, 3, 2}, }; MemorySolver ms(boxes); @@ -142,13 +176,19 @@ TEST(MemSolverTest, OverlappingBoxes) { EXPECT_EQ(ms.maxTopDepth(), 2); } +// | ____ +// | |____| ____ +// | |____|__ +// | ____ |_______| +// |__|____|___|_|_________ +// 0 1 2 3 4 5 6 TEST(MemSolverTest, EndOnSeveralBegins) { - std::vector boxes{ // | ____ - {0, 1, 2}, // | |____| ____ - {1, 2, 2}, // | |____|__ - {3, 3, 2}, // | ____ |_______| - {3, 5, 2}, // |__|____|___|_|_________ - {3, 4, 2}, // 0 1 2 3 4 5 6 + std::vector boxes{ + {0, 1, 2}, + {1, 2, 2}, + {3, 3, 2}, + {3, 5, 2}, + {3, 4, 2}, }; MemorySolver ms(boxes); @@ -157,13 +197,19 @@ TEST(MemSolverTest, EndOnSeveralBegins) { EXPECT_EQ(ms.maxTopDepth(), 3); } +// | _____________ +// | |_____________>> +// | |____|__ +// | ____ |_______>> +// |__|____|___|_|_________ +// 0 1 2 3 4 5 6 TEST(MemSolverTest, ToEndBoxes) { - std::vector boxes{ // | _____________ - {0, 1, 2}, // | |_____________>> - {1, -1, 2}, // | |____|__ - {3, 3, 2}, // | ____ |_______>> - {3, -1, 2}, // |__|____|___|_|_________ - {3, 4, 2}, // 0 1 2 3 4 5 6 + std::vector boxes{ + {0, 1, 2}, + {1, -1, 2}, + {3, 3, 2}, + {3, -1, 2}, + {3, 4, 2}, }; MemorySolver ms(boxes); @@ -172,13 +218,19 @@ TEST(MemSolverTest, ToEndBoxes) { EXPECT_EQ(ms.maxTopDepth(), 4); } +// | _ +// | ____ |_>> +// | |____|__ +// | ____ |_______| +// |__|____|___|_|_________ +// 0 1 2 3 4 5 6 TEST(MemSolverTest, LastAndToEndBox) { - std::vector boxes{ // | _ - {0, 1, 2}, // | ____ |_>> - {6, -1, 2}, // | |____|__ - {3, 3, 2}, // | ____ |_______| - {3, 5, 2}, // |__|____|___|_|_________ - {3, 4, 2}, // 0 1 2 3 4 5 6 + std::vector boxes{ + {0, 1, 2}, + {6, -1, 2}, + {3, 3, 2}, + {3, 5, 2}, + {3, 4, 2}, }; MemorySolver ms(boxes); @@ -189,33 +241,34 @@ TEST(MemSolverTest, LastAndToEndBox) { TEST(MemSolverTest, OptimalAlexnet) { std::vector> shapes{ - {3, 227, 227}, // in - {96, 55, 55}, // conv1 - {96, 55, 55}, // relu1 - {96, 55, 55}, // norm1 - {96, 27, 27}, // pool1 - {256, 27, 27}, // conv2 - {256, 27, 27}, // relu2 - {256, 27, 27}, // norm2 - {256, 13, 13}, // pool2 - {384, 13, 13}, // conv3 - {384, 13, 13}, // relu3 - {384, 13, 13}, // conv4 - {384, 13, 13}, // relu4 - {256, 13, 13}, // conv5 - {256, 13, 13}, // relu5 - {256, 6, 6}, // pool5 - {1, 1, 4069}, // fc6 - {1, 1, 4069}, // relu6 - {1, 1, 4069}, // fc7 - {1, 1, 4069}, // relu7 - {1, 1, 1000}, // fc8 - {1, 1, 1000}, // loss + {3, 227, 227}, // in + {96, 55, 55}, // conv1 + {96, 55, 55}, // relu1 + {96, 55, 55}, // norm1 + {96, 27, 27}, // pool1 + {256, 27, 27}, // conv2 + {256, 27, 27}, // relu2 + {256, 27, 27}, // norm2 + {256, 13, 13}, // pool2 + {384, 13, 13}, // conv3 + {384, 13, 13}, // relu3 + {384, 13, 13}, // conv4 + {384, 13, 13}, // relu4 + {256, 13, 13}, // conv5 + {256, 13, 13}, // relu5 + {256, 6, 6}, // pool5 + {1, 1, 4069}, // fc6 + {1, 1, 4069}, // relu6 + {1, 1, 4069}, // fc7 + {1, 1, 4069}, // relu7 + {1, 1, 1000}, // fc8 + {1, 1, 1000}, // loss }; int n = 0; std::vector boxes; - for (const auto &sh : shapes) boxes.push_back({n, ++n, sh[0] * sh[1] * sh[2]}); + for (const auto& sh : shapes) + boxes.push_back({n, ++n, sh[0] * sh[1] * sh[2]}); // For linear topology bottom score is reachable minRequired == maxDepth MemorySolver ms(boxes); @@ -223,13 +276,19 @@ TEST(MemSolverTest, OptimalAlexnet) { EXPECT_EQ(ms.maxTopDepth(), 2); } +// | _____________ +// | _____|___1_________| +// | |_2_____| ____ +// | | | | | +// |__|_3__|______|_3__|___ +// 2 3 4 5 6 7 8 TEST(MemSolverTest, NoOverlapping) { - int n = 0; // | _____________ - std::vector boxes{ // | _____|___1_________| - {4, 8, 1, n++}, // | |_2_____| ____ - {6, 7, 3, n++}, // | | | | | - {2, 3, 3, n++}, // |__|_3__|______|_3__|___ - {2, 4, 2, n++}, // 2 3 4 5 6 7 8 + int n = 0; + std::vector boxes{ + {4, 8, 1, n++}, + {6, 7, 3, n++}, + {2, 3, 3, n++}, + {2, 4, 2, n++}, }; MemorySolver ms(boxes); @@ -240,8 +299,8 @@ TEST(MemSolverTest, NoOverlapping) { auto no_overlap = [&](Box box1, Box box2) -> bool { int off1 = ms.getOffset(box1.id); int off2 = ms.getOffset(box2.id); - return box1.finish < box2.start || box1.start > box2.finish || - off1 + box1.size <= off2 || off1 >= off2 + box2.size; + return box1.finish < box2.start || box1.start > box2.finish || off1 + box1.size <= off2 || + off1 >= off2 + box2.size; }; for (int i = 0; i < n; i++) @@ -249,13 +308,19 @@ TEST(MemSolverTest, NoOverlapping) { ASSERT_TRUE(no_overlap(boxes[i], boxes[j])) << "Box overlapping is detected"; } +// | _______ +// | |_2_____|__ +// | ____ | | +// | __|_1__| | | +// |__|_1__|______|_3__|___ +// 2 3 4 5 6 7 8 TEST(MemSolverTest, BestSolution1) { - int n = 0; // | _______ - std::vector boxes{ // | |_2_____|__ - {2, 3, 1, n++}, // | ____ | | - {3, 4, 1, n++}, // | __|_1__| | | - {4, 6, 2, n++}, // |__|_1__|______|_3__|___ - {6, 7, 3, n++}, // 2 3 4 5 6 7 8 + int n = 0; + std::vector boxes{ + {2, 3, 1, n++}, + {3, 4, 1, n++}, + {4, 6, 2, n++}, + {6, 7, 3, n++}, }; MemorySolver ms(boxes); @@ -264,12 +329,11 @@ TEST(MemSolverTest, BestSolution1) { auto no_overlap = [&](Box box1, Box box2) -> bool { int off1 = ms.getOffset(box1.id); int off2 = ms.getOffset(box2.id); - return box1.finish < box2.start || box1.start > box2.finish || - off1 + box1.size <= off2 || off1 >= off2 + box2.size; + return box1.finish < box2.start || box1.start > box2.finish || off1 + box1.size <= off2 || + off1 >= off2 + box2.size; }; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) ASSERT_TRUE(no_overlap(boxes[i], boxes[j])) << "Box overlapping is detected"; } - diff --git a/src/inference/tests/unit/precision_utils_test.cpp b/src/inference/tests/unit/precision_utils_test.cpp index 31f387e7198..24e946d96ed 100644 --- a/src/inference/tests/unit/precision_utils_test.cpp +++ b/src/inference/tests/unit/precision_utils_test.cpp @@ -23,7 +23,8 @@ TEST_F(PrecisionUtilsTests, FP32ToFP16PositiveInfinity) { } TEST_F(PrecisionUtilsTests, FP32ToFP16NegativeInfinity) { - const auto fp16ConvertedInf = InferenceEngine::PrecisionUtils::f32tof16(-1 * std::numeric_limits::infinity()); + const auto fp16ConvertedInf = + InferenceEngine::PrecisionUtils::f32tof16(-1 * std::numeric_limits::infinity()); ASSERT_EQ(fp16ConvertedInf, negativeInf); } @@ -43,6 +44,7 @@ TEST_F(PrecisionUtilsTests, FP32ToFP16MaximumValue) { } TEST_F(PrecisionUtilsTests, FP32ToFP16LowestValue) { - const auto fp16ConvertedLowestValue = InferenceEngine::PrecisionUtils::f32tof16(std::numeric_limits::lowest()); + const auto fp16ConvertedLowestValue = + InferenceEngine::PrecisionUtils::f32tof16(std::numeric_limits::lowest()); ASSERT_EQ(fp16ConvertedLowestValue, lowestNumber); } diff --git a/src/inference/tests/unit/saturated_cast_test.cpp b/src/inference/tests/unit/saturated_cast_test.cpp index 28ddee7ecca..50a79d7766a 100644 --- a/src/inference/tests/unit/saturated_cast_test.cpp +++ b/src/inference/tests/unit/saturated_cast_test.cpp @@ -3,14 +3,14 @@ // #include -#include "common_test_utils/test_common.hpp" -#include "precision_utils.h" +#include "common_test_utils/test_common.hpp" #include "ie_precision.hpp" +#include "precision_utils.h" #ifdef USE_OPENCV -#include +# include using namespace InferenceEngine; diff --git a/src/inference/tests/unit/system_allocator_test.cpp b/src/inference/tests/unit/system_allocator_test.cpp index 053dc7188cc..d5bbabdef21 100644 --- a/src/inference/tests/unit/system_allocator_test.cpp +++ b/src/inference/tests/unit/system_allocator_test.cpp @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "system_allocator.hpp" + #include +#include + #include "common_test_utils/test_common.hpp" -#include "system_allocator.hpp" - using namespace InferenceEngine; -class SystemAllocatorReleaseTests : public CommonTestUtils::TestsCommon { -}; +class SystemAllocatorReleaseTests : public CommonTestUtils::TestsCommon {}; class SystemAllocatorTests : public CommonTestUtils::TestsCommon { protected: @@ -34,30 +34,31 @@ protected: } std::unique_ptr allocator; + public: }; TEST_F(SystemAllocatorTests, canAllocate) { - void *handle0 = allocator->alloc(0); - void *handle1 = allocator->alloc(100); + void* handle0 = allocator->alloc(0); + void* handle1 = allocator->alloc(100); EXPECT_NE(handle0, nullptr); EXPECT_NE(handle1, nullptr); - delete[] reinterpret_cast(handle0); - delete[] reinterpret_cast(handle1); + delete[] reinterpret_cast(handle0); + delete[] reinterpret_cast(handle1); } TEST_F(SystemAllocatorTests, canFree) { EXPECT_TRUE(allocator->free(nullptr)); - void *handle0 = reinterpret_cast(new char[0]); - void *handle1 = reinterpret_cast(new char[100]); + void* handle0 = reinterpret_cast(new char[0]); + void* handle1 = reinterpret_cast(new char[100]); EXPECT_TRUE(allocator->free(handle0)); EXPECT_TRUE(allocator->free(handle1)); } TEST_F(SystemAllocatorTests, canLockAndUnlockAllocatedMemory) { // large block such as 10k will result in sigsegv if not allocated - void *handle = allocator->alloc(10000); - char *ptr = reinterpret_cast(allocator->lock(handle)); + void* handle = allocator->alloc(10000); + char* ptr = reinterpret_cast(allocator->lock(handle)); ptr[9999] = 11; EXPECT_EQ(ptr[9999], 11); allocator->unlock(ptr);