From: Krzysztof Bruniecki Date: Fri, 13 Nov 2020 13:32:26 +0000 (+0100) Subject: Create u-tests for RESULT_NOT_READY and INFER_NOT_STARTED (GNA QoS) (#3102) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dc2ac0fb9e6cccb6f88fc9156e7a0d784538c244;p=platform%2Fupstream%2Fdldt.git Create u-tests for RESULT_NOT_READY and INFER_NOT_STARTED (GNA QoS) (#3102) * Create tests for RESULT_NOT_READY and INFER_NOT_STARTED (GNA QoS) * Suppress deprecated definition errors * Fix warning --- diff --git a/inference-engine/src/gna_plugin/gna_device.cpp b/inference-engine/src/gna_plugin/gna_device.cpp index 963a1c3..133db7a 100644 --- a/inference-engine/src/gna_plugin/gna_device.cpp +++ b/inference-engine/src/gna_plugin/gna_device.cpp @@ -75,7 +75,7 @@ void GNADeviceHelper::propagateSync(const uint32_t requestConfigId, Gna2Accelera } uint32_t GNADeviceHelper::propagate(const uint32_t requestConfigId, Gna2AccelerationMode gna2AccelerationMode) { - uint32_t reqId; + uint32_t reqId{}; if (gna2AccelerationMode == Gna2AccelerationModeHardware && detectedGnaDevVersion == Gna2DeviceVersionSoftwareEmulation) { gnawarn() << "GNA Device not detected, consider using other mode of acceleration"; diff --git a/inference-engine/src/gna_plugin/gna_infer_request.hpp b/inference-engine/src/gna_plugin/gna_infer_request.hpp index fcdc92b..c2a2d0c 100644 --- a/inference-engine/src/gna_plugin/gna_infer_request.hpp +++ b/inference-engine/src/gna_plugin/gna_infer_request.hpp @@ -8,12 +8,14 @@ #include #include +#include "cpp_interfaces/impl/ie_infer_async_request_internal.hpp" #include "cpp_interfaces/impl/ie_infer_request_internal.hpp" #include "gna_plugin.hpp" namespace GNAPluginNS { class GNAInferRequest : public InferenceEngine::AsyncInferRequestInternal { + protected: std::shared_ptr plg; uint32_t inferRequestIdx = -1; diff --git a/inference-engine/tests/unit/gna/gna_api_stub.cpp b/inference-engine/tests/unit/gna/gna_api_stub.cpp index fb35cf8..cfc3381 100644 --- a/inference-engine/tests/unit/gna/gna_api_stub.cpp +++ b/inference-engine/tests/unit/gna/gna_api_stub.cpp @@ -129,6 +129,9 @@ GNA2_API enum Gna2Status Gna2RequestEnqueue( GNA2_API enum Gna2Status Gna2RequestWait( uint32_t requestId, uint32_t timeoutMilliseconds) { + if (current != nullptr) { + return current->Gna2RequestWait(requestId, timeoutMilliseconds); + } return Gna2StatusSuccess; } diff --git a/inference-engine/tests/unit/gna/gna_mock_api.hpp b/inference-engine/tests/unit/gna/gna_mock_api.hpp index d94c8c1..d67e26c 100644 --- a/inference-engine/tests/unit/gna/gna_mock_api.hpp +++ b/inference-engine/tests/unit/gna/gna_mock_api.hpp @@ -80,5 +80,8 @@ public: uint32_t sizeRequested, uint32_t * sizeGranted, void ** memoryAddress)); + MOCK_METHOD2(Gna2RequestWait, Gna2Status( + uint32_t requestId, + uint32_t timeoutMilliseconds)); #endif }; diff --git a/inference-engine/tests/unit/gna/gna_wait_test.cpp b/inference-engine/tests/unit/gna/gna_wait_test.cpp new file mode 100644 index 0000000..57d940b --- /dev/null +++ b/inference-engine/tests/unit/gna/gna_wait_test.cpp @@ -0,0 +1,69 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#if GNA_LIB_VER == 2 + +#include + +#include + +// to suppress deprecated definition errors +#define IMPLEMENT_INFERENCE_ENGINE_PLUGIN +#include "gna_infer_request.hpp" +#include "gna_mock_api.hpp" + +using GNAPluginNS::GNAPlugin; +using GNAPluginNS::GNAInferRequest; +using ::testing::Return; +using ::testing::_; + +class GNAWaitTest : public ::testing::Test { +}; + +class GNAPluginForGNAWaitTest : public GNAPlugin { + public: + // Prepare underlining object to enable GNAInferRequest::Wait() working + GNAPluginForGNAWaitTest() { + InferenceEngine::TensorDesc td{ InferenceEngine::Precision::FP32, {}, InferenceEngine::Layout::HW }; + auto fakeInfo = std::make_shared(); + auto fakePtr = std::make_shared("fakeName", td); + fakeInfo->setInputData(fakePtr); + outputsDataMap["fakeOut"] = fakePtr; + inputsDataMap["fakeIn"] = fakeInfo; + gnaRequestConfigToRequestIdMap.push_back({ 0, 0, {} }); + InitGNADevice(); + } +}; + +class GNAInferRequestForGNAWaitTest : public GNAInferRequest { + public: + // Prepare underlining object to enable Wait() working + GNAInferRequestForGNAWaitTest(std::shared_ptr plugin) : GNAInferRequest{ + plugin, + plugin->GetInputs(), + plugin->GetOutputs() } { + inferRequestIdx = 0; + } +}; + +TEST_F(GNAWaitTest, ReturnsGna2StatusDriverQoSTimeoutExceeded) { + GNACppApi enableMocks; + EXPECT_CALL(enableMocks, Gna2RequestWait(_, _)). + Times(1). + WillOnce(Return(Gna2StatusDriverQoSTimeoutExceeded)); + auto plugin = std::make_shared(); + GNAInferRequestForGNAWaitTest inferRequest{ plugin }; + ASSERT_EQ(InferenceEngine::INFER_NOT_STARTED, inferRequest.Wait(0)); +} + +TEST_F(GNAWaitTest, ReturnsGna2StatusWarningDeviceBusy) { + GNACppApi enableMocks; + EXPECT_CALL(enableMocks, Gna2RequestWait(_, _)). + Times(1). + WillOnce(Return(Gna2StatusWarningDeviceBusy)); + auto plugin = std::make_shared(); + GNAInferRequestForGNAWaitTest inferRequest{ plugin }; + ASSERT_EQ(InferenceEngine::RESULT_NOT_READY, inferRequest.Wait(0)); +} +#endif