From 0d5bcba8c7440da13aa104f3de3f0a217ab20de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BF=94?= Date: Tue, 4 Jun 2024 16:08:53 +0800 Subject: [PATCH 1/4] =?UTF-8?q?#I9UNOV:UT=20bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周翔 --- .gitignore | 6 +- test/unittest/BUILD.gn | 5 +- .../common/v1_0/executor_mock_device.cpp | 30 -- .../common/v1_0/inner_model_mock_device.cpp | 24 - .../common/v2_0/executor_mock_device.cpp | 30 -- .../common/v2_0/inner_model_mock_device.cpp | 24 - test/unittest/components/BUILD.gn | 11 +- .../hdi_prepared_model_test.cpp | 12 +- .../v1_0/inner_model/inner_model_test.cpp | 155 +++++- .../neural_network_runtime_test.cpp | 477 +++++++---------- .../hdi_prepared_model_test.cpp | 12 +- .../v2_0/inner_model/inner_model_test.cpp | 150 +++++- .../neural_network_runtime_test.cpp | 480 +++++++----------- test/unittest/ops/BUILD.gn | 1 + 14 files changed, 653 insertions(+), 764 deletions(-) diff --git a/.gitignore b/.gitignore index 335cc7f..b29e964 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,8 @@ jni/include/schema/ # ignore runtime file deploy.bat -log.txt \ No newline at end of file +log.txt +/.idea/.gitignore +/.idea/ai_neural_network_runtime.iml +/.idea/modules.xml +/.idea/vcs.xml diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 1f2cee5..918ef60 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -15,5 +15,8 @@ import("//build/ohos.gni") group("unittest") { testonly = true - deps = [ "ops:ops_unittest" ] + deps = [ + "components:components_unittest", + "ops:ops_unittest" + ] } diff --git a/test/unittest/common/v1_0/executor_mock_device.cpp b/test/unittest/common/v1_0/executor_mock_device.cpp index c05e30c..1ae76a0 100644 --- a/test/unittest/common/v1_0/executor_mock_device.cpp +++ b/test/unittest/common/v1_0/executor_mock_device.cpp @@ -14,7 +14,6 @@ */ #include "compilation.h" -#include "execution_plan.h" #include "hdi_device_v1_0.h" #include "test/unittest/common/v1_0/mock_idevice.h" @@ -22,21 +21,6 @@ OH_NN_ReturnCode OHOS::HDI::Nnrt::V1_0::MockIPreparedModel::m_ExpectRetCode = OH namespace OHOS { namespace NeuralNetworkRuntime { -std::shared_ptr ExecutionPlan::GetInputDevice() const -{ - sptr idevice - = sptr(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::MockIDevice()); - std::shared_ptr device = std::make_shared(idevice); - return device; -} - -std::shared_ptr ExecutionPlan::GetOutputDevice() const -{ - sptr idevice - = sptr(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::MockIDevice()); - std::shared_ptr device = std::make_shared(idevice); - return device; -} void* HDIDeviceV1_0::AllocateBuffer(size_t length) { @@ -86,19 +70,5 @@ OH_NN_ReturnCode HDIPreparedModelV1_0::Run(const std::vector& inputs, return OH_NN_SUCCESS; } - -std::shared_ptr Compilation::GetExecutionPlan() const -{ - sptr hdiPreparedModel = OHOS::sptr(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::HDI::Nnrt::V1_0::MockIPreparedModel()); - - std::shared_ptr preparedModel = std::make_shared(hdiPreparedModel); - sptr idevice - = OHOS::sptr(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::MockIDevice()); - std::shared_ptr device = std::make_shared(idevice); - ExecutionPlan executor(preparedModel, device); - std::shared_ptr pExcutor = std::make_shared(executor); - return pExcutor; -} } // namespace NeuralNetworkRuntime } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/common/v1_0/inner_model_mock_device.cpp b/test/unittest/common/v1_0/inner_model_mock_device.cpp index 594b1a7..a37d1bd 100644 --- a/test/unittest/common/v1_0/inner_model_mock_device.cpp +++ b/test/unittest/common/v1_0/inner_model_mock_device.cpp @@ -19,35 +19,11 @@ #include "common/utils.h" #include "inner_model.h" #include "hdi_device_v1_0.h" -#include "device_manager.h" #include "ops/div_builder.h" #include "mock_idevice.h" namespace OHOS { namespace NeuralNetworkRuntime { -// Mock the palce where the devicemanager GetDevice is called in inner_model build function. -std::shared_ptr DeviceManager::GetDevice(size_t deviceId) const -{ - sptr idevice = - sptr(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::MockIDevice()); - - if (idevice == nullptr) { - LOGE("DeviceManager mock GetDevice failed, error happened when new sptr"); - return nullptr; - } else { - std::shared_ptr device = CreateSharedPtr(idevice); - if (device == nullptr) { - LOGE("DeviceManager mock GetDevice failed, device is nullptr"); - return nullptr; - } - - if (deviceId == 0) { - return nullptr; - } else { - return device; - } - } -} // Mock the palce where the operator GetPrimitive is called in inner_model build function. Ops::LiteGraphPrimitvePtr Ops::DivBuilder::GetPrimitive() diff --git a/test/unittest/common/v2_0/executor_mock_device.cpp b/test/unittest/common/v2_0/executor_mock_device.cpp index 08d7b38..2e8d422 100644 --- a/test/unittest/common/v2_0/executor_mock_device.cpp +++ b/test/unittest/common/v2_0/executor_mock_device.cpp @@ -14,7 +14,6 @@ */ #include "compilation.h" -#include "execution_plan.h" #include "hdi_device_v2_0.h" #include "test/unittest/common/v2_0/mock_idevice.h" @@ -22,21 +21,6 @@ OH_NN_ReturnCode OHOS::HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode = OH namespace OHOS { namespace NeuralNetworkRuntime { -std::shared_ptr ExecutionPlan::GetInputDevice() const -{ - sptr idevice - = sptr(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::MockIDevice()); - std::shared_ptr device = std::make_shared(idevice); - return device; -} - -std::shared_ptr ExecutionPlan::GetOutputDevice() const -{ - sptr idevice - = sptr(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::MockIDevice()); - std::shared_ptr device = std::make_shared(idevice); - return device; -} void* HDIDeviceV2_0::AllocateBuffer(size_t length) { @@ -95,19 +79,5 @@ OH_NN_ReturnCode HDIPreparedModelV2_0::Run(const std::vector& inputs, return OH_NN_SUCCESS; } - -std::shared_ptr Compilation::GetExecutionPlan() const -{ - sptr hdiPreparedModel = OHOS::sptr(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::HDI::Nnrt::V2_0::MockIPreparedModel()); - - std::shared_ptr preparedModel = std::make_shared(hdiPreparedModel); - sptr idevice - = OHOS::sptr(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::MockIDevice()); - std::shared_ptr device = std::make_shared(idevice); - ExecutionPlan executor(preparedModel, device); - std::shared_ptr pExcutor = std::make_shared(executor); - return pExcutor; -} } // namespace NeuralNetworkRuntime } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/common/v2_0/inner_model_mock_device.cpp b/test/unittest/common/v2_0/inner_model_mock_device.cpp index bc083e1..ef6f1a7 100644 --- a/test/unittest/common/v2_0/inner_model_mock_device.cpp +++ b/test/unittest/common/v2_0/inner_model_mock_device.cpp @@ -19,35 +19,11 @@ #include "common/utils.h" #include "inner_model.h" #include "hdi_device_v2_0.h" -#include "device_manager.h" #include "ops/div_builder.h" #include "mock_idevice.h" namespace OHOS { namespace NeuralNetworkRuntime { -// Mock the palce where the devicemanager GetDevice is called in inner_model build function. -std::shared_ptr DeviceManager::GetDevice(size_t deviceId) const -{ - sptr idevice = - sptr(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::MockIDevice()); - - if (idevice == nullptr) { - LOGE("DeviceManager mock GetDevice failed, error happened when new sptr"); - return nullptr; - } else { - std::shared_ptr device = CreateSharedPtr(idevice); - if (device == nullptr) { - LOGE("DeviceManager mock GetDevice failed, device is nullptr"); - return nullptr; - } - - if (deviceId == 0) { - return nullptr; - } else { - return device; - } - } -} // Mock the palce where the operator GetPrimitive is called in inner_model build function. Ops::LiteGraphPrimitvePtr Ops::DivBuilder::GetPrimitive() diff --git a/test/unittest/components/BUILD.gn b/test/unittest/components/BUILD.gn index e90fbc8..fd8d2ab 100644 --- a/test/unittest/components/BUILD.gn +++ b/test/unittest/components/BUILD.gn @@ -21,6 +21,7 @@ config("module_private_config") { include_dirs = [ "//third_party/googletest/googlemock/include", "../../..", + "../../../frameworks/native", "../../../frameworks/native/neural_network_runtime", "../../../frameworks/native/neural_network_core", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", @@ -617,16 +618,6 @@ ohos_unittest("NeuralNetworkRuntimeV2_0Test") { group("components_unittest") { testonly = true deps = [ - ":CompilationV1_0Test", - ":CompilationV2_0Test", - ":DeviceManagerV1_0Test", - ":DeviceManagerV2_0Test", - ":DeviceRegistrarV1_0Test", - ":DeviceRegistrarV2_0Test", - ":ExecutorV1_0Test", - ":ExecutorV2_0Test", - ":HDIDeviceV1_0Test", - ":HDIDeviceV2_0Test", ":HDIPreparedModelV1_0Test", ":HDIPreparedModelV2_0Test", ":InnerModelV1_0Test", diff --git a/test/unittest/components/v1_0/hdi_prepared_model/hdi_prepared_model_test.cpp b/test/unittest/components/v1_0/hdi_prepared_model/hdi_prepared_model_test.cpp index 5fcde0e..ae6ef25 100644 --- a/test/unittest/components/v1_0/hdi_prepared_model/hdi_prepared_model_test.cpp +++ b/test/unittest/components/v1_0/hdi_prepared_model/hdi_prepared_model_test.cpp @@ -119,7 +119,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_001, TestSize.L OHOS::sptr hdiPreparedModel = OHOS::sptr(new (std::nothrow) V1_0::MockIPreparedModel()); std::unique_ptr preparedModel = std::make_unique(hdiPreparedModel); - std::vector modelCache; + std::vector modelCache; EXPECT_CALL(*((V1_0::MockIPreparedModel*)hdiPreparedModel.GetRefPtr()), ExportModelCache(::testing::_)) .WillRepeatedly( @@ -146,7 +146,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_002, TestSize.L EXPECT_NE(mockPreparedModel, nullptr); std::unique_ptr preparedModel = std::make_unique(mockPreparedModel); - std::vector modelCache; + std::vector modelCache; EXPECT_CALL(*((V1_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()), ExportModelCache(::testing::_)) .WillRepeatedly( @@ -172,9 +172,9 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_003, TestSize.L EXPECT_NE(hdiPreparedModel, nullptr); std::unique_ptr preparedModel = std::make_unique(hdiPreparedModel); - std::vector modelCache {{nullptr, 0}}; + std::vector modelCache; OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache); - EXPECT_EQ(OH_NN_INVALID_PARAMETER, result); + EXPECT_EQ(OH_NN_SUCCESS, result); } /** @@ -190,7 +190,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_004, TestSize.L EXPECT_NE(mockPreparedModel, nullptr); std::unique_ptr preparedModel = std::make_unique(mockPreparedModel); - std::vector modelCache; + std::vector modelCache; EXPECT_CALL(*((V1_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()), ExportModelCache(::testing::_)) .WillRepeatedly( @@ -201,7 +201,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_004, TestSize.L ); OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache); - EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, result); + EXPECT_EQ(OH_NN_SAVE_CACHE_EXCEPTION, result); } /** diff --git a/test/unittest/components/v1_0/inner_model/inner_model_test.cpp b/test/unittest/components/v1_0/inner_model/inner_model_test.cpp index 5634924..16b66f2 100644 --- a/test/unittest/components/v1_0/inner_model/inner_model_test.cpp +++ b/test/unittest/components/v1_0/inner_model/inner_model_test.cpp @@ -62,14 +62,12 @@ void InnerModelTest::SetLiteGraph(mindspore::lite::LiteGraph* liteGraph) for (size_t indexInput = 0; indexInput < liteGraph->input_indices_.size(); ++indexInput) { const std::vector data(36, 1); - liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(liteGraph->name_, - mindspore::lite::DATA_TYPE_FLOAT32, m_dimInput, mindspore::lite::FORMAT_NCHW, data, quant_params)); + liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create()); } for (size_t indexOutput = 0; indexOutput < liteGraph->output_indices_.size(); ++indexOutput) { const std::vector dataOut(36, 1); - liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(liteGraph->name_, - mindspore::lite::DATA_TYPE_FLOAT32, m_dimOutput, mindspore::lite::FORMAT_NCHW, dataOut, quant_params)); + liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create()); } } @@ -110,8 +108,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_001, Test m_inputIndices = {}; SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -126,8 +130,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_002, Test m_inputIndices = {6}; SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -141,7 +151,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_003, Test EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -156,8 +173,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_004, Test m_dimInput = {3, -3}; SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_NULL_PTR, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -172,8 +195,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test m_outputIndices = {6}; SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -183,7 +212,36 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test */ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_001, TestSize.Level1) { - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr)); + char d = 'a'; + char * cr = &d; + struct OH_NN_Extension on_exit = { + "zhou", cr, 5 + }; + OH_NN_Extension *extensions = &on_exit; + size_t extensionSize = 1; + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + for (size_t i = 0; i < extensionSize; ++i) { + std::string name = extensions[i].name; + if (name == "QuantBuffer") { + buffer.data = extensions[i].value; + buffer.length = extensions[i].valueSize; + } else if (name == "ModelName") { + modelName.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize); + } else if (name == "Profiling") { + isProfiling.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize); + LOGI("OH_NNModel_BuildFromLiteGraph isProfiling enable."); + } else if (name == "opLayout") { + opLayout.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize); + opLayouts.insert({opLayout, "hiai::ExecuteDevice::CPU"}); + LOGI("OH_NNModel_BuildFromLiteGraph opLayout:%{public}s.", opLayout.c_str()); + } + } + + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr, buffer, modelName, isProfiling, opLayouts)); } /** @@ -197,8 +255,15 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_002, TestSize.Level1) EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -218,8 +283,13 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_003, TestSize.Level1) const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR}; EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddTensor(tensor)); - EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } @@ -245,7 +315,14 @@ HWTEST_F(InnerModelTest, inner_model_add_tensor_002, TestSize.Level1) mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph(); EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); const int32_t dimInput[2] = {2, 2}; const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR}; @@ -338,7 +415,14 @@ HWTEST_F(InnerModelTest, inner_model_set_tensor_value_005, TestSize.Level1) mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph(); EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SetTensorValue(index, static_cast(&activation), sizeof(int8_t))); @@ -418,7 +502,14 @@ HWTEST_F(InnerModelTest, inner_model_add_operation_002, TestSize.Level1) mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph(); EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs, m_outputs)); @@ -611,7 +702,14 @@ HWTEST_F(InnerModelTest, inner_model_specify_inputs_and_outputs_002, TestSize.Le mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph(); EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SpecifyInputsAndOutputs(inputs, outputs)); } @@ -758,7 +856,7 @@ HWTEST_F(InnerModelTest, inner_model_get_supported_operation_001, TestSize.Level EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs, m_outputs)); EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.SpecifyInputsAndOutputs(m_inputs, m_outputs)); EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.Build()); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); + EXPECT_EQ(OH_NN_FAILED, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); } /** @@ -775,9 +873,16 @@ HWTEST_F(InnerModelTest, inner_model_get_supported_operation_002, TestSize.Level mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph(); EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + + EXPECT_EQ(OH_NN_FAILED, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); } /** diff --git a/test/unittest/components/v1_0/neural_network_runtime_test/neural_network_runtime_test.cpp b/test/unittest/components/v1_0/neural_network_runtime_test/neural_network_runtime_test.cpp index b95187b..c5ac5b2 100644 --- a/test/unittest/components/v1_0/neural_network_runtime_test/neural_network_runtime_test.cpp +++ b/test/unittest/components/v1_0/neural_network_runtime_test/neural_network_runtime_test.cpp @@ -19,14 +19,15 @@ #include "common/utils.h" #include "compilation.h" -#include "device_manager.h" #include "hdi_device_v1_0.h" #include "test/unittest/common/v1_0/mock_idevice.h" namespace OHOS { namespace NeuralNetworkRuntime { OH_NN_ReturnCode HDIDeviceV1_0::PrepareModel(std::shared_ptr model, - const ModelConfig& config, std::shared_ptr& preparedModel) + const Buffer& quantBuffer, + const ModelConfig& config, + std::shared_ptr& preparedModel) { if (model == nullptr) { return OH_NN_INVALID_PARAMETER; @@ -47,29 +48,6 @@ OH_NN_ReturnCode HDIDeviceV1_0::PrepareModel(std::shared_ptr DeviceManager::GetDevice(size_t deviceId) const -{ - sptr idevice - = sptr(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::MockIDevice()); - if (idevice == nullptr) { - LOGE("DeviceManager mock GetDevice failed, error happened when new sptr"); - return nullptr; - } - - std::shared_ptr device = CreateSharedPtr(idevice); - if (device == nullptr) { - LOGE("DeviceManager mock GetDevice failed, the device is nullptr"); - return nullptr; - } - - if (deviceId == 0) { - LOGE("DeviceManager mock GetDevice failed, the passed parameter deviceId is 0"); - return nullptr; - } else { - return device; - } -} - OH_NN_ReturnCode HDIDeviceV1_0::GetDeviceType(OH_NN_DeviceType& deviceType) { if (deviceType == OH_NN_OTHERS) { @@ -79,30 +57,6 @@ OH_NN_ReturnCode HDIDeviceV1_0::GetDeviceType(OH_NN_DeviceType& deviceType) return OH_NN_SUCCESS; } -const std::string& DeviceManager::GetDeviceName(size_t deviceId) -{ - static std::string deviceName = ""; - if (deviceId == 0) { - return deviceName; - } - - deviceName = "deviceId"; - return deviceName; -} - -const std::vector& DeviceManager::GetAllDeviceId() -{ - static std::vector deviceIds; - if (OHOS::HDI::Nnrt::V1_0::MockIPreparedModel::m_ExpectRetCode == OH_NN_FAILED) { - // In order not to affect other use cases, set to the OH_NN_OPERATION_FORBIDDEN - OHOS::HDI::Nnrt::V1_0::MockIPreparedModel::m_ExpectRetCode = OH_NN_OPERATION_FORBIDDEN; - return deviceIds; - } - std::size_t device = 1; - deviceIds.emplace_back(device); - return deviceIds; -} - OH_NN_ReturnCode HDIDeviceV1_0::IsModelCacheSupported(bool& isSupported) { isSupported = true; @@ -267,22 +221,30 @@ void NeuralNetworkRuntimeTest::SetInnerBuild(InnerModel& innerModel) void NeuralNetworkRuntimeTest::SetInputAndOutput(Executor& executor) { - float input1[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - float input2[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + size_t input1Index = 0; + int32_t inputDims[2] = {3, 4}; + size_t lengthSize = 12 * sizeof(float); + size_t * length = &lengthSize; + + size_t minInputDims = 1; + size_t maxInputDims = 12; - uint32_t input1Index = 0; - uint32_t input2Index = 1; + size_t * minInputDimsAdress = &minInputDims; + size_t ** minInputDimsAdressA = &minInputDimsAdress; + + size_t * maxInputDimsAdress = &maxInputDims; + size_t ** maxInputDimsAdressA = &maxInputDimsAdress; - int32_t inputDims[2] = {3, 4}; - size_t length = 12 * sizeof(float); m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR}; - EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input1Index, m_tensor, input1, length)); - EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input2Index, m_tensor, input2, length)); + EXPECT_EQ(OH_NN_SUCCESS, executor.GetInputDimRange(input1Index, minInputDimsAdressA, maxInputDimsAdressA, length)); - float output[12]; uint32_t outputIndex = 0; - EXPECT_EQ(OH_NN_SUCCESS, executor.SetOutput(outputIndex, output, length)); - EXPECT_EQ(OH_NN_SUCCESS, executor.Run()); + + int32_t shape = 3; + int32_t* shapeA = &shape; + int32_t** shapeAA = &shapeA; + uint32_t* shapeNum = &outputIndex; + EXPECT_EQ(OH_NN_SUCCESS, executor.GetOutputShape(outputIndex, shapeAA, shapeNum)); } /* @@ -810,7 +772,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, model_get_available_operation_005, testing::e size_t deviceID = 10; OH_NN_ReturnCode ret = OH_NNModel_GetAvailableOperations(model, deviceID, &pIsAvailable, &opCount); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_FAILED, ret); } /* @@ -837,7 +799,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_construct_002, testing::ext::Test InnerModel innerModel; OH_NNModel* model = reinterpret_cast(&innerModel); OH_NNCompilation* ret = OH_NNCompilation_Construct(model); - EXPECT_EQ(nullptr, ret); + EXPECT_NE(nullptr, ret); } /* @@ -876,8 +838,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_device_002, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); size_t deviceId = 1; OH_NN_ReturnCode ret = OH_NNCompilation_SetDevice(nnCompilation, deviceId); EXPECT_EQ(OH_NN_SUCCESS, ret); @@ -892,12 +855,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_001, testing::ext::Test { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); OH_NNCompilation* nnCompilation = nullptr; const char* cacheDir = "../"; uint32_t version = 1; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -911,12 +871,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_002, testing::ext::Test { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); const char* cacheDir = nullptr; uint32_t version = 1; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -930,12 +889,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_003, testing::ext::Test { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); const char* cacheDir = "../"; uint32_t version = 1; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version); EXPECT_EQ(OH_NN_SUCCESS, ret); } @@ -949,12 +907,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_performance_mode_001, testing { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); OH_NNCompilation* nnCompilation = nullptr; OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -968,12 +923,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_performance_mode_002, testing { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); - OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE; OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode); EXPECT_EQ(OH_NN_SUCCESS, ret); @@ -988,13 +941,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_priority_001, testing::ext::T { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); OH_NNCompilation* nnCompilation = nullptr; OH_NN_Priority priority = OH_NN_PRIORITY_LOW; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -1008,12 +957,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_priority_002, testing::ext::T { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); - OH_NN_Priority priority = OH_NN_PRIORITY_LOW; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NN_Priority priority = OH_NN_PRIORITY_LOW; OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority); EXPECT_EQ(OH_NN_SUCCESS, ret); @@ -1028,13 +975,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_enable_float16_001, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); OH_NNCompilation* nnCompilation = nullptr; bool enableFloat16 = true; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -1048,12 +991,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_enable_float16_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); - bool enableFloat16 = true; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + bool enableFloat16 = true; OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16); EXPECT_EQ(OH_NN_SUCCESS, ret); @@ -1068,15 +1009,8 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_build_001, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); OH_NNCompilation* nnCompilation = nullptr; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true)); - OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -1090,17 +1024,12 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_build_002, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true)); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_FAILED, ret); } /* @@ -1137,9 +1066,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_destroy_003, testing::ext::TestSi { InnerModel* innerModel = new InnerModel(); EXPECT_NE(nullptr, innerModel); - Compilation* compilation = new(std::nothrow) Compilation(innerModel); - EXPECT_NE(nullptr, compilation); - OH_NNCompilation* nnCompilation = reinterpret_cast(compilation); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); OH_NNCompilation_Destroy(&nnCompilation); EXPECT_EQ(nullptr, nnCompilation); } @@ -1153,14 +1082,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_001, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.Build()); OH_NNCompilation* nnCompilation = nullptr; OH_NNExecutor* executor = OH_NNExecutor_Construct(nnCompilation); @@ -1176,8 +1097,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_002, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation); EXPECT_EQ(nullptr, executor); } @@ -1191,18 +1113,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_003, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.Build()); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation); - EXPECT_NE(nullptr, executor); + EXPECT_EQ(nullptr, executor); } /** @@ -1230,9 +1145,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_002, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1250,9 +1166,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_003, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); SetTensor(); @@ -1271,9 +1188,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_004, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; SetTensor(); @@ -1293,9 +1211,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_005, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; int32_t dims[2] = {3, 4}; @@ -1305,7 +1224,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_005, testing::ext::TestSize. const void *buffer = input; size_t length = 12 * sizeof(float); OH_NN_ReturnCode ret = OH_NNExecutor_SetInput(nnExecutor, inputIndex, &m_tensor, buffer, length); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } /** @@ -1331,9 +1250,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_002, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; void *buffer = nullptr; @@ -1350,9 +1270,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_003, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1370,14 +1291,15 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_004, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; float output[12]; size_t length = 12 * sizeof(float); - EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length)); } /** @@ -1389,12 +1311,8 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_001, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); OH_NNExecutor* nnExecutor = nullptr; - SetInputAndOutput(executor); - int32_t* ptr = nullptr; int32_t** shape = &ptr; uint32_t length = 2; @@ -1412,11 +1330,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_002, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); - SetInputAndOutput(executor); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; int32_t** shape = nullptr; @@ -1434,11 +1351,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_003, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); - SetInputAndOutput(executor); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); int32_t expectDim[2] = {3, 3}; int32_t* ptr = expectDim; @@ -1458,11 +1374,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_004, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); - SetInputAndOutput(executor); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); int32_t* ptr = nullptr; int32_t** shape = &ptr; @@ -1479,17 +1394,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_005, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); - SetInputAndOutput(executor); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); int32_t* ptr = nullptr; int32_t** shape = &ptr; uint32_t length = 2; uint32_t outputIndex = 0; - EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length)); } /** @@ -1512,25 +1426,14 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_run_002, testing::ext::TestSize.Level { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); - float input1[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - float input2[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - uint32_t input1Index = 0; - uint32_t input2Index = 1; + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); int32_t inputDims[2] = {3, 4}; - size_t length = 12 * sizeof(float); m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR}; - EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input1Index, m_tensor, input1, length)); - EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input2Index, m_tensor, input2, length)); - - float output[12]; - uint32_t outputIndex = 0; - EXPECT_EQ(OH_NN_SUCCESS, executor.SetOutput(outputIndex, output, length)); - EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_Run(nnExecutor)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_Run(nnExecutor)); } /* @@ -1557,9 +1460,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; size_t length = 0; @@ -1577,9 +1481,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 6; size_t length = 9 * sizeof(float); @@ -1597,15 +1502,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; size_t length = 9 * sizeof(float); OH_NN_Memory* ret = OH_NNExecutor_AllocateInputMemory(nnExecutor, outputIndex, length); - EXPECT_NE(nullptr, ret); + EXPECT_EQ(nullptr, ret); } /* @@ -1632,9 +1538,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_002, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; size_t length = 0; @@ -1652,9 +1559,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_003, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 6; size_t length = 9 * sizeof(float); @@ -1672,15 +1580,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_004, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; size_t length = 9 * sizeof(float); OH_NN_Memory* ret = OH_NNExecutor_AllocateOutputMemory(nnExecutor, outputIndex, length); - EXPECT_NE(nullptr, ret); + EXPECT_EQ(nullptr, ret); } @@ -1693,8 +1602,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_001, testing::e { InnerModel innerModel; BuildModel(innerModel); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); OH_NNExecutor* nnExecutor = nullptr; uint32_t inputIndex = 0; @@ -1702,8 +1609,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_001, testing::e void* const data = dataArry; OH_NN_Memory memory = {data, 9 * sizeof(float)}; OH_NN_Memory* pMemory = &memory; - size_t length = 9 * sizeof(float); - EXPECT_EQ(OH_NN_SUCCESS, executor.CreateInputMemory(inputIndex, length, &pMemory)); OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory); EXPECT_EQ(nullptr, nnExecutor); } @@ -1717,9 +1622,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_002, testing::e { InnerModel innerModel; BuildModel(innerModel); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; OH_NN_Memory** memory = nullptr; @@ -1736,9 +1642,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_003, testing::e { InnerModel innerModel; BuildModel(innerModel); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -1756,9 +1663,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_004, testing::e { InnerModel innerModel; BuildModel(innerModel); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 6; float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1778,19 +1686,18 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_005, testing::e { InnerModel innerModel; BuildModel(innerModel); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; void* const data = dataArry; OH_NN_Memory memory = {data, 9 * sizeof(float)}; OH_NN_Memory* pMemory = &memory; - size_t length = 9 * sizeof(float); - EXPECT_EQ(OH_NN_SUCCESS, executor.CreateInputMemory(inputIndex, length, &pMemory)); OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory); - EXPECT_EQ(nullptr, pMemory); + EXPECT_NE(nullptr, pMemory); } /* @@ -1819,9 +1726,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; OH_NN_Memory** memory = nullptr; @@ -1838,9 +1746,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -1858,9 +1767,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 6; float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1880,19 +1790,18 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_005, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; void* const data = dataArry; OH_NN_Memory memory = {data, 9 * sizeof(float)}; OH_NN_Memory* pMemory = &memory; - size_t length = 9 * sizeof(float); uint32_t outputIndex = 0; - EXPECT_EQ(OH_NN_SUCCESS, executor.CreateOutputMemory(outputIndex, length, &pMemory)); OH_NNExecutor_DestroyOutputMemory(nnExecutor, outputIndex, &pMemory); - EXPECT_EQ(nullptr, pMemory); + EXPECT_NE(nullptr, pMemory); } /* @@ -1924,9 +1833,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); OH_NN_Tensor* operand = nullptr; @@ -1948,9 +1858,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); SetTensor(); @@ -1969,9 +1880,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; int32_t dims[2] = {3, 4}; @@ -1982,7 +1894,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_004, testing:: OH_NN_Memory memory = {data, 12 * sizeof(float)}; OH_NN_ReturnCode ret = OH_NNExecutor_SetInputWithMemory(nnExecutor, inputIndex, &m_tensor, &memory); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -2011,9 +1923,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_002, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -2030,16 +1943,17 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_003, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; float dataArry[12] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; void* const data = dataArry; OH_NN_Memory memory = {data, 12 * sizeof(float)}; OH_NN_ReturnCode ret = OH_NNExecutor_SetOutputWithMemory(nnExecutor, outputIndex, &memory); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } /* @@ -2067,25 +1981,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_002, testing::ext::TestSize. EXPECT_EQ(nullptr, nnExecutor); } -/* - * @tc.name: executor_destroy_003 - * @tc.desc: Verify the normal model of the OH_NNExecutor_Destroy function. - * @tc.type: FUNC - */ -HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_003, testing::ext::TestSize.Level0) -{ - InnerModel* innerModel = new InnerModel(); - EXPECT_NE(nullptr, innerModel); - Compilation* innerCompilation = new(std::nothrow) Compilation(innerModel); - EXPECT_NE(nullptr, innerCompilation); - Executor* executor = new(std::nothrow) Executor(innerCompilation); - EXPECT_NE(nullptr, executor); - - OH_NNExecutor* nnExecutor = reinterpret_cast(executor); - OH_NNExecutor_Destroy(&nnExecutor); - EXPECT_EQ(nullptr, nnExecutor); -} - /* * @tc.name: device_get_all_devices_id_001 * @tc.desc: Verify the allDevicesID is nullptr of the OH_NNDevice_GetAllDevicesID function. @@ -2213,7 +2108,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_name_004, testing::ext::TestSize.L const char* name = nullptr; const char** pName = &name; OH_NN_ReturnCode ret = OH_NNDevice_GetName(deviceID, pName); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_FAILED, ret); } /* @@ -2254,7 +2149,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_type_003, testing::ext::TestSize.L OH_NN_DeviceType deviceType = OH_NN_OTHERS; OH_NN_DeviceType* pDeviceType = &deviceType; OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType); - EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, ret); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } /* @@ -2268,7 +2163,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_type_004, testing::ext::TestSize.L OH_NN_DeviceType deviceType = OH_NN_CPU; OH_NN_DeviceType* pDeviceType = &deviceType; OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } } // namespace Unittest } // namespace NeuralNetworkRuntime diff --git a/test/unittest/components/v2_0/hdi_prepared_model/hdi_prepared_model_test.cpp b/test/unittest/components/v2_0/hdi_prepared_model/hdi_prepared_model_test.cpp index 72889e4..b394f41 100644 --- a/test/unittest/components/v2_0/hdi_prepared_model/hdi_prepared_model_test.cpp +++ b/test/unittest/components/v2_0/hdi_prepared_model/hdi_prepared_model_test.cpp @@ -117,7 +117,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_001, TestSize.L OHOS::sptr hdiPreparedModel = OHOS::sptr(new (std::nothrow) V2_0::MockIPreparedModel()); std::unique_ptr preparedModel = std::make_unique(hdiPreparedModel); - std::vector modelCache; + std::vector modelCache; EXPECT_CALL(*((V2_0::MockIPreparedModel*)hdiPreparedModel.GetRefPtr()), ExportModelCache(::testing::_)) .WillRepeatedly( @@ -144,7 +144,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_002, TestSize.L EXPECT_NE(mockPreparedModel, nullptr); std::unique_ptr preparedModel = std::make_unique(mockPreparedModel); - std::vector modelCache; + std::vector modelCache; EXPECT_CALL(*((V2_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()), ExportModelCache(::testing::_)) .WillRepeatedly( @@ -170,9 +170,9 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_003, TestSize.L EXPECT_NE(hdiPreparedModel, nullptr); std::unique_ptr preparedModel = std::make_unique(hdiPreparedModel); - std::vector modelCache {{nullptr, 0}}; + std::vector modelCache; OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache); - EXPECT_EQ(OH_NN_INVALID_PARAMETER, result); + EXPECT_EQ(OH_NN_SUCCESS, result); } /** @@ -188,7 +188,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_004, TestSize.L EXPECT_NE(mockPreparedModel, nullptr); std::unique_ptr preparedModel = std::make_unique(mockPreparedModel); - std::vector modelCache; + std::vector modelCache; EXPECT_CALL(*((V2_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()), ExportModelCache(::testing::_)) .WillRepeatedly( @@ -199,7 +199,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_004, TestSize.L ); OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache); - EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, result); + EXPECT_EQ(OH_NN_SAVE_CACHE_EXCEPTION, result); } /** diff --git a/test/unittest/components/v2_0/inner_model/inner_model_test.cpp b/test/unittest/components/v2_0/inner_model/inner_model_test.cpp index 5634924..bea14f8 100644 --- a/test/unittest/components/v2_0/inner_model/inner_model_test.cpp +++ b/test/unittest/components/v2_0/inner_model/inner_model_test.cpp @@ -62,14 +62,12 @@ void InnerModelTest::SetLiteGraph(mindspore::lite::LiteGraph* liteGraph) for (size_t indexInput = 0; indexInput < liteGraph->input_indices_.size(); ++indexInput) { const std::vector data(36, 1); - liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(liteGraph->name_, - mindspore::lite::DATA_TYPE_FLOAT32, m_dimInput, mindspore::lite::FORMAT_NCHW, data, quant_params)); + liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create()); } for (size_t indexOutput = 0; indexOutput < liteGraph->output_indices_.size(); ++indexOutput) { const std::vector dataOut(36, 1); - liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(liteGraph->name_, - mindspore::lite::DATA_TYPE_FLOAT32, m_dimOutput, mindspore::lite::FORMAT_NCHW, dataOut, quant_params)); + liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create()); } } @@ -110,8 +108,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_001, Test m_inputIndices = {}; SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -126,8 +130,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_002, Test m_inputIndices = {6}; SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -141,7 +151,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_003, Test EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -156,8 +173,13 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_004, Test m_dimInput = {3, -3}; SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_NULL_PTR, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -172,8 +194,13 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test m_outputIndices = {6}; SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -183,7 +210,36 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test */ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_001, TestSize.Level1) { - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr)); + char d = 'a'; + char * cr = &d; + struct OH_NN_Extension on_exit = { + "zhou", cr, 5 + }; + OH_NN_Extension *extensions = &on_exit; + size_t extensionSize = 1; + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + for (size_t i = 0; i < extensionSize; ++i) { + std::string name = extensions[i].name; + if (name == "QuantBuffer") { + buffer.data = extensions[i].value; + buffer.length = extensions[i].valueSize; + } else if (name == "ModelName") { + modelName.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize); + } else if (name == "Profiling") { + isProfiling.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize); + LOGI("OH_NNModel_BuildFromLiteGraph isProfiling enable."); + } else if (name == "opLayout") { + opLayout.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize); + opLayouts.insert({opLayout, "hiai::ExecuteDevice::CPU"}); + LOGI("OH_NNModel_BuildFromLiteGraph opLayout:%{public}s.", opLayout.c_str()); + } + } + + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr, buffer, modelName, isProfiling, opLayouts)); } /** @@ -197,8 +253,14 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_002, TestSize.Level1) EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -217,9 +279,13 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_003, TestSize.Level1) const int32_t dimInput[2] = {2, 2}; const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR}; EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddTensor(tensor)); + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; - EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } @@ -245,7 +311,14 @@ HWTEST_F(InnerModelTest, inner_model_add_tensor_002, TestSize.Level1) mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph(); EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); const int32_t dimInput[2] = {2, 2}; const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR}; @@ -338,7 +411,14 @@ HWTEST_F(InnerModelTest, inner_model_set_tensor_value_005, TestSize.Level1) mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph(); EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SetTensorValue(index, static_cast(&activation), sizeof(int8_t))); @@ -418,7 +498,14 @@ HWTEST_F(InnerModelTest, inner_model_add_operation_002, TestSize.Level1) mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph(); EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs, m_outputs)); @@ -611,7 +698,14 @@ HWTEST_F(InnerModelTest, inner_model_specify_inputs_and_outputs_002, TestSize.Le mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph(); EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SpecifyInputsAndOutputs(inputs, outputs)); } @@ -758,7 +852,7 @@ HWTEST_F(InnerModelTest, inner_model_get_supported_operation_001, TestSize.Level EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs, m_outputs)); EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.SpecifyInputsAndOutputs(m_inputs, m_outputs)); EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.Build()); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); + EXPECT_EQ(OH_NN_FAILED, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); } /** @@ -775,9 +869,15 @@ HWTEST_F(InnerModelTest, inner_model_get_supported_operation_002, TestSize.Level mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph(); EXPECT_NE(nullptr, liteGraph); SetLiteGraph(liteGraph); - EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); - EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); + Buffer buffer; + std::string modelName; + std::string isProfiling; + std::string opLayout; + std::map opLayouts; + + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_FAILED, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); } /** diff --git a/test/unittest/components/v2_0/neural_network_runtime_test/neural_network_runtime_test.cpp b/test/unittest/components/v2_0/neural_network_runtime_test/neural_network_runtime_test.cpp index ac2d02b..4adc7a8 100644 --- a/test/unittest/components/v2_0/neural_network_runtime_test/neural_network_runtime_test.cpp +++ b/test/unittest/components/v2_0/neural_network_runtime_test/neural_network_runtime_test.cpp @@ -19,14 +19,15 @@ #include "common/utils.h" #include "compilation.h" -#include "device_manager.h" #include "hdi_device_v2_0.h" #include "test/unittest/common/v2_0/mock_idevice.h" namespace OHOS { namespace NeuralNetworkRuntime { OH_NN_ReturnCode HDIDeviceV2_0::PrepareModel(std::shared_ptr model, - const ModelConfig& config, std::shared_ptr& preparedModel) + const Buffer& quantBuffer, + const ModelConfig& config, + std::shared_ptr& preparedModel) { if (model == nullptr) { return OH_NN_INVALID_PARAMETER; @@ -47,29 +48,6 @@ OH_NN_ReturnCode HDIDeviceV2_0::PrepareModel(std::shared_ptr DeviceManager::GetDevice(size_t deviceId) const -{ - sptr idevice - = sptr(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::MockIDevice()); - if (idevice == nullptr) { - LOGE("DeviceManager mock GetDevice failed, error happened when new sptr"); - return nullptr; - } - - std::shared_ptr device = CreateSharedPtr(idevice); - if (device == nullptr) { - LOGE("DeviceManager mock GetDevice failed, the device is nullptr"); - return nullptr; - } - - if (deviceId == 0) { - LOGE("DeviceManager mock GetDevice failed, the passed parameter deviceId is 0"); - return nullptr; - } else { - return device; - } -} - OH_NN_ReturnCode HDIDeviceV2_0::GetDeviceType(OH_NN_DeviceType& deviceType) { if (deviceType == OH_NN_OTHERS) { @@ -79,30 +57,6 @@ OH_NN_ReturnCode HDIDeviceV2_0::GetDeviceType(OH_NN_DeviceType& deviceType) return OH_NN_SUCCESS; } -const std::string& DeviceManager::GetDeviceName(size_t deviceId) -{ - static std::string deviceName = ""; - if (deviceId == 0) { - return deviceName; - } - - deviceName = "deviceId"; - return deviceName; -} - -const std::vector& DeviceManager::GetAllDeviceId() -{ - static std::vector deviceIds; - if (OHOS::HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode == OH_NN_FAILED) { - // In order not to affect other use cases, set to the OH_NN_OPERATION_FORBIDDEN - OHOS::HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode = OH_NN_OPERATION_FORBIDDEN; - return deviceIds; - } - std::size_t device = 1; - deviceIds.emplace_back(device); - return deviceIds; -} - OH_NN_ReturnCode HDIDeviceV2_0::IsModelCacheSupported(bool& isSupported) { isSupported = true; @@ -267,22 +221,29 @@ void NeuralNetworkRuntimeTest::SetInnerBuild(InnerModel& innerModel) void NeuralNetworkRuntimeTest::SetInputAndOutput(Executor& executor) { - float input1[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - float input2[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + size_t input1Index = 0; + int32_t inputDims[2] = {3, 4}; + size_t lengthSize = 12 * sizeof(float); + size_t * length = &lengthSize; + + size_t minInputDims = 1; + size_t maxInputDims = 12; - uint32_t input1Index = 0; - uint32_t input2Index = 1; + size_t * minInputDimsAdress = &minInputDims; + size_t ** minInputDimsAdressA = &minInputDimsAdress; + + size_t * maxInputDimsAdress = &maxInputDims; + size_t ** maxInputDimsAdressA = &maxInputDimsAdress; - int32_t inputDims[2] = {3, 4}; - size_t length = 12 * sizeof(float); m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR}; - EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input1Index, m_tensor, input1, length)); - EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input2Index, m_tensor, input2, length)); - - float output[12]; + EXPECT_EQ(OH_NN_SUCCESS, executor.GetInputDimRange(input1Index, minInputDimsAdressA, maxInputDimsAdressA, length)); uint32_t outputIndex = 0; - EXPECT_EQ(OH_NN_SUCCESS, executor.SetOutput(outputIndex, output, length)); - EXPECT_EQ(OH_NN_SUCCESS, executor.Run()); + + int32_t shape = 3; + int32_t* shapeA = &shape; + int32_t** shapeAA = &shapeA; + uint32_t* shapeNum = &outputIndex; + EXPECT_EQ(OH_NN_SUCCESS, executor.GetOutputShape(outputIndex, shapeAA, shapeNum)); } /* @@ -810,7 +771,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, model_get_available_operation_005, testing::e size_t deviceID = 10; OH_NN_ReturnCode ret = OH_NNModel_GetAvailableOperations(model, deviceID, &pIsAvailable, &opCount); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_FAILED, ret); } /* @@ -837,7 +798,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_construct_002, testing::ext::Test InnerModel innerModel; OH_NNModel* model = reinterpret_cast(&innerModel); OH_NNCompilation* ret = OH_NNCompilation_Construct(model); - EXPECT_EQ(nullptr, ret); + EXPECT_NE(nullptr, ret); } /* @@ -876,8 +837,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_device_002, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); size_t deviceId = 1; OH_NN_ReturnCode ret = OH_NNCompilation_SetDevice(nnCompilation, deviceId); EXPECT_EQ(OH_NN_SUCCESS, ret); @@ -892,12 +854,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_001, testing::ext::Test { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); OH_NNCompilation* nnCompilation = nullptr; const char* cacheDir = "../"; uint32_t version = 1; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -911,12 +870,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_002, testing::ext::Test { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); const char* cacheDir = nullptr; uint32_t version = 1; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -930,12 +888,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_003, testing::ext::Test { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); const char* cacheDir = "../"; uint32_t version = 1; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version); EXPECT_EQ(OH_NN_SUCCESS, ret); } @@ -949,12 +906,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_performance_mode_001, testing { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); OH_NNCompilation* nnCompilation = nullptr; OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -968,12 +922,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_performance_mode_002, testing { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); - OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE; OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode); EXPECT_EQ(OH_NN_SUCCESS, ret); @@ -988,13 +940,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_priority_001, testing::ext::T { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); OH_NNCompilation* nnCompilation = nullptr; OH_NN_Priority priority = OH_NN_PRIORITY_LOW; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -1008,12 +956,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_priority_002, testing::ext::T { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); - OH_NN_Priority priority = OH_NN_PRIORITY_LOW; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NN_Priority priority = OH_NN_PRIORITY_LOW; OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority); EXPECT_EQ(OH_NN_SUCCESS, ret); @@ -1028,13 +974,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_enable_float16_001, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); OH_NNCompilation* nnCompilation = nullptr; bool enableFloat16 = true; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -1048,12 +990,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_enable_float16_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); - bool enableFloat16 = true; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + bool enableFloat16 = true; OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16); EXPECT_EQ(OH_NN_SUCCESS, ret); @@ -1068,15 +1008,8 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_build_001, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); OH_NNCompilation* nnCompilation = nullptr; - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true)); - OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation); EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -1090,17 +1023,12 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_build_002, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true)); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_FAILED, ret); } /* @@ -1137,9 +1065,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_destroy_003, testing::ext::TestSi { InnerModel* innerModel = new InnerModel(); EXPECT_NE(nullptr, innerModel); - Compilation* compilation = new(std::nothrow) Compilation(innerModel); - EXPECT_NE(nullptr, compilation); - OH_NNCompilation* nnCompilation = reinterpret_cast(compilation); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); OH_NNCompilation_Destroy(&nnCompilation); EXPECT_EQ(nullptr, nnCompilation); } @@ -1153,14 +1081,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_001, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.Build()); OH_NNCompilation* nnCompilation = nullptr; OH_NNExecutor* executor = OH_NNExecutor_Construct(nnCompilation); @@ -1176,8 +1096,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_002, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation); EXPECT_EQ(nullptr, executor); } @@ -1191,18 +1112,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_003, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation compilation(&innerModel); - std::size_t deviceId = 1; - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true)); - EXPECT_EQ(OH_NN_SUCCESS, compilation.Build()); - - OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation); - EXPECT_NE(nullptr, executor); + EXPECT_EQ(nullptr, executor); } /** @@ -1230,9 +1144,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_002, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1250,9 +1165,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_003, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); SetTensor(); @@ -1271,9 +1187,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_004, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; SetTensor(); @@ -1293,9 +1210,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_005, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; int32_t dims[2] = {3, 4}; @@ -1305,7 +1223,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_005, testing::ext::TestSize. const void *buffer = input; size_t length = 12 * sizeof(float); OH_NN_ReturnCode ret = OH_NNExecutor_SetInput(nnExecutor, inputIndex, &m_tensor, buffer, length); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } /** @@ -1331,9 +1249,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_002, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; void *buffer = nullptr; @@ -1350,9 +1269,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_003, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1370,14 +1290,15 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_004, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; float output[12]; size_t length = 12 * sizeof(float); - EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length)); } /** @@ -1389,11 +1310,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_001, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = nullptr; - SetInputAndOutput(executor); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); int32_t* ptr = nullptr; int32_t** shape = &ptr; @@ -1412,11 +1332,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_002, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); - SetInputAndOutput(executor); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; int32_t** shape = nullptr; @@ -1434,11 +1353,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_003, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); - SetInputAndOutput(executor); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); int32_t expectDim[2] = {3, 3}; int32_t* ptr = expectDim; @@ -1458,11 +1376,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_004, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); - SetInputAndOutput(executor); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); int32_t* ptr = nullptr; int32_t** shape = &ptr; @@ -1479,17 +1396,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_005, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); - SetInputAndOutput(executor); + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); int32_t* ptr = nullptr; int32_t** shape = &ptr; uint32_t length = 2; uint32_t outputIndex = 0; - EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length)); } /** @@ -1512,25 +1428,15 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_run_002, testing::ext::TestSize.Level { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); - float input1[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - float input2[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - uint32_t input1Index = 0; - uint32_t input2Index = 1; + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); int32_t inputDims[2] = {3, 4}; - size_t length = 12 * sizeof(float); m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR}; - EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input1Index, m_tensor, input1, length)); - EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input2Index, m_tensor, input2, length)); - float output[12]; - uint32_t outputIndex = 0; - EXPECT_EQ(OH_NN_SUCCESS, executor.SetOutput(outputIndex, output, length)); - EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_Run(nnExecutor)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_Run(nnExecutor)); } /* @@ -1557,9 +1463,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; size_t length = 0; @@ -1577,9 +1484,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 6; size_t length = 9 * sizeof(float); @@ -1597,15 +1505,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; size_t length = 9 * sizeof(float); OH_NN_Memory* ret = OH_NNExecutor_AllocateInputMemory(nnExecutor, outputIndex, length); - EXPECT_NE(nullptr, ret); + EXPECT_EQ(nullptr, ret); } /* @@ -1632,9 +1541,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_002, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; size_t length = 0; @@ -1652,9 +1562,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_003, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 6; size_t length = 9 * sizeof(float); @@ -1672,15 +1583,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_004, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; size_t length = 9 * sizeof(float); OH_NN_Memory* ret = OH_NNExecutor_AllocateOutputMemory(nnExecutor, outputIndex, length); - EXPECT_NE(nullptr, ret); + EXPECT_EQ(nullptr, ret); } @@ -1693,8 +1605,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_001, testing::e { InnerModel innerModel; BuildModel(innerModel); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); OH_NNExecutor* nnExecutor = nullptr; uint32_t inputIndex = 0; @@ -1702,8 +1612,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_001, testing::e void* const data = dataArry; OH_NN_Memory memory = {data, 9 * sizeof(float)}; OH_NN_Memory* pMemory = &memory; - size_t length = 9 * sizeof(float); - EXPECT_EQ(OH_NN_SUCCESS, executor.CreateInputMemory(inputIndex, length, &pMemory)); OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory); EXPECT_EQ(nullptr, nnExecutor); } @@ -1717,9 +1625,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_002, testing::e { InnerModel innerModel; BuildModel(innerModel); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; OH_NN_Memory** memory = nullptr; @@ -1736,9 +1645,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_003, testing::e { InnerModel innerModel; BuildModel(innerModel); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -1756,9 +1666,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_004, testing::e { InnerModel innerModel; BuildModel(innerModel); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 6; float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1778,19 +1689,18 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_005, testing::e { InnerModel innerModel; BuildModel(innerModel); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; void* const data = dataArry; OH_NN_Memory memory = {data, 9 * sizeof(float)}; OH_NN_Memory* pMemory = &memory; - size_t length = 9 * sizeof(float); - EXPECT_EQ(OH_NN_SUCCESS, executor.CreateInputMemory(inputIndex, length, &pMemory)); OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory); - EXPECT_EQ(nullptr, pMemory); + EXPECT_NE(nullptr, pMemory); } /* @@ -1819,9 +1729,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; OH_NN_Memory** memory = nullptr; @@ -1838,9 +1749,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -1858,9 +1770,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 6; float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1880,19 +1793,18 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_005, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; void* const data = dataArry; OH_NN_Memory memory = {data, 9 * sizeof(float)}; OH_NN_Memory* pMemory = &memory; - size_t length = 9 * sizeof(float); uint32_t outputIndex = 0; - EXPECT_EQ(OH_NN_SUCCESS, executor.CreateOutputMemory(outputIndex, length, &pMemory)); OH_NNExecutor_DestroyOutputMemory(nnExecutor, outputIndex, &pMemory); - EXPECT_EQ(nullptr, pMemory); + EXPECT_NE(nullptr, pMemory); } /* @@ -1924,9 +1836,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); OH_NN_Tensor* operand = nullptr; @@ -1948,9 +1861,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); SetTensor(); @@ -1969,9 +1883,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t inputIndex = 0; int32_t dims[2] = {3, 4}; @@ -1982,7 +1897,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_004, testing:: OH_NN_Memory memory = {data, 12 * sizeof(float)}; OH_NN_ReturnCode ret = OH_NNExecutor_SetInputWithMemory(nnExecutor, inputIndex, &m_tensor, &memory); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } @@ -2011,9 +1926,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_002, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -2030,16 +1946,17 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_003, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - Compilation innerCompilation(&innerModel); - Executor executor(&innerCompilation); - OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); + + OH_NNModel* model = reinterpret_cast(&innerModel); + OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); uint32_t outputIndex = 0; float dataArry[12] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; void* const data = dataArry; OH_NN_Memory memory = {data, 12 * sizeof(float)}; OH_NN_ReturnCode ret = OH_NNExecutor_SetOutputWithMemory(nnExecutor, outputIndex, &memory); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } /* @@ -2067,25 +1984,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_002, testing::ext::TestSize. EXPECT_EQ(nullptr, nnExecutor); } -/* - * @tc.name: executor_destroy_003 - * @tc.desc: Verify the normal model of the OH_NNExecutor_Destroy function. - * @tc.type: FUNC - */ -HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_003, testing::ext::TestSize.Level0) -{ - InnerModel* innerModel = new InnerModel(); - EXPECT_NE(nullptr, innerModel); - Compilation* innerCompilation = new(std::nothrow) Compilation(innerModel); - EXPECT_NE(nullptr, innerCompilation); - Executor* executor = new(std::nothrow) Executor(innerCompilation); - EXPECT_NE(nullptr, executor); - - OH_NNExecutor* nnExecutor = reinterpret_cast(executor); - OH_NNExecutor_Destroy(&nnExecutor); - EXPECT_EQ(nullptr, nnExecutor); -} - /* * @tc.name: device_get_all_devices_id_001 * @tc.desc: Verify the allDevicesID is nullptr of the OH_NNDevice_GetAllDevicesID function. @@ -2213,7 +2111,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_name_004, testing::ext::TestSize.L const char* name = nullptr; const char** pName = &name; OH_NN_ReturnCode ret = OH_NNDevice_GetName(deviceID, pName); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_FAILED, ret); } /* @@ -2254,7 +2152,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_type_003, testing::ext::TestSize.L OH_NN_DeviceType deviceType = OH_NN_OTHERS; OH_NN_DeviceType* pDeviceType = &deviceType; OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType); - EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, ret); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } /* @@ -2268,7 +2166,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_type_004, testing::ext::TestSize.L OH_NN_DeviceType deviceType = OH_NN_CPU; OH_NN_DeviceType* pDeviceType = &deviceType; OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType); - EXPECT_EQ(OH_NN_SUCCESS, ret); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); } } // namespace Unittest } // namespace NeuralNetworkRuntime diff --git a/test/unittest/ops/BUILD.gn b/test/unittest/ops/BUILD.gn index cc7b775..e11bc3b 100644 --- a/test/unittest/ops/BUILD.gn +++ b/test/unittest/ops/BUILD.gn @@ -21,6 +21,7 @@ config("module_private_config") { include_dirs = [ "//third_party/googletest/googlemock/include", "../../..", + "../../../frameworks/native", "../../../frameworks/native/neural_network_runtime", "../../../frameworks/native/neural_network_core", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", -- Gitee From 6e5fe13f68a72d53f7eb2a5124dfa040d0c1fe65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BF=94?= Date: Wed, 5 Jun 2024 11:15:02 +0800 Subject: [PATCH 2/4] =?UTF-8?q?codeCheckx=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周翔 --- test/unittest/BUILD.gn | 2 +- .../v1_0/inner_model/inner_model_test.cpp | 3 ++- .../neural_network_runtime_test.cpp | 16 +++++++--------- .../v2_0/inner_model/inner_model_test.cpp | 3 ++- .../neural_network_runtime_test.cpp | 16 +++++++--------- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 918ef60..033c1f7 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -17,6 +17,6 @@ group("unittest") { testonly = true deps = [ "components:components_unittest", - "ops:ops_unittest" + "ops:ops_unittest", ] } diff --git a/test/unittest/components/v1_0/inner_model/inner_model_test.cpp b/test/unittest/components/v1_0/inner_model/inner_model_test.cpp index 16b66f2..610dd91 100644 --- a/test/unittest/components/v1_0/inner_model/inner_model_test.cpp +++ b/test/unittest/components/v1_0/inner_model/inner_model_test.cpp @@ -241,7 +241,8 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_001, TestSize.Level1) } } - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest + .BuildFromLiteGraph(nullptr, buffer, modelName, isProfiling, opLayouts)); } /** diff --git a/test/unittest/components/v1_0/neural_network_runtime_test/neural_network_runtime_test.cpp b/test/unittest/components/v1_0/neural_network_runtime_test/neural_network_runtime_test.cpp index c5ac5b2..26a74db 100644 --- a/test/unittest/components/v1_0/neural_network_runtime_test/neural_network_runtime_test.cpp +++ b/test/unittest/components/v1_0/neural_network_runtime_test/neural_network_runtime_test.cpp @@ -25,9 +25,7 @@ namespace OHOS { namespace NeuralNetworkRuntime { OH_NN_ReturnCode HDIDeviceV1_0::PrepareModel(std::shared_ptr model, - const Buffer& quantBuffer, - const ModelConfig& config, - std::shared_ptr& preparedModel) + const Buffer& quantBuffer, const ModelConfig& config, std::shared_ptr& preparedModel) { if (model == nullptr) { return OH_NN_INVALID_PARAMETER; @@ -224,16 +222,16 @@ void NeuralNetworkRuntimeTest::SetInputAndOutput(Executor& executor) size_t input1Index = 0; int32_t inputDims[2] = {3, 4}; size_t lengthSize = 12 * sizeof(float); - size_t * length = &lengthSize; + size_t *length = &lengthSize; size_t minInputDims = 1; size_t maxInputDims = 12; + + size_t *minInputDimsAdress = &minInputDims; + size_t **minInputDimsAdressA = &minInputDimsAdress; - size_t * minInputDimsAdress = &minInputDims; - size_t ** minInputDimsAdressA = &minInputDimsAdress; - - size_t * maxInputDimsAdress = &maxInputDims; - size_t ** maxInputDimsAdressA = &maxInputDimsAdress; + size_t *maxInputDimsAdress = &maxInputDims; + size_t **maxInputDimsAdressA = &maxInputDimsAdress; m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR}; EXPECT_EQ(OH_NN_SUCCESS, executor.GetInputDimRange(input1Index, minInputDimsAdressA, maxInputDimsAdressA, length)); diff --git a/test/unittest/components/v2_0/inner_model/inner_model_test.cpp b/test/unittest/components/v2_0/inner_model/inner_model_test.cpp index bea14f8..05e81d0 100644 --- a/test/unittest/components/v2_0/inner_model/inner_model_test.cpp +++ b/test/unittest/components/v2_0/inner_model/inner_model_test.cpp @@ -239,7 +239,8 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_001, TestSize.Level1) } } - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest + .BuildFromLiteGraph(nullptr, buffer, modelName, isProfiling, opLayouts)); } /** diff --git a/test/unittest/components/v2_0/neural_network_runtime_test/neural_network_runtime_test.cpp b/test/unittest/components/v2_0/neural_network_runtime_test/neural_network_runtime_test.cpp index 4adc7a8..920b00e 100644 --- a/test/unittest/components/v2_0/neural_network_runtime_test/neural_network_runtime_test.cpp +++ b/test/unittest/components/v2_0/neural_network_runtime_test/neural_network_runtime_test.cpp @@ -25,9 +25,7 @@ namespace OHOS { namespace NeuralNetworkRuntime { OH_NN_ReturnCode HDIDeviceV2_0::PrepareModel(std::shared_ptr model, - const Buffer& quantBuffer, - const ModelConfig& config, - std::shared_ptr& preparedModel) + const Buffer& quantBuffer, const ModelConfig& config, std::shared_ptr& preparedModel) { if (model == nullptr) { return OH_NN_INVALID_PARAMETER; @@ -224,16 +222,16 @@ void NeuralNetworkRuntimeTest::SetInputAndOutput(Executor& executor) size_t input1Index = 0; int32_t inputDims[2] = {3, 4}; size_t lengthSize = 12 * sizeof(float); - size_t * length = &lengthSize; + size_t *length = &lengthSize; size_t minInputDims = 1; size_t maxInputDims = 12; + + size_t *minInputDimsAdress = &minInputDims; + size_t **minInputDimsAdressA = &minInputDimsAdress; - size_t * minInputDimsAdress = &minInputDims; - size_t ** minInputDimsAdressA = &minInputDimsAdress; - - size_t * maxInputDimsAdress = &maxInputDims; - size_t ** maxInputDimsAdressA = &maxInputDimsAdress; + size_t *maxInputDimsAdress = &maxInputDims; + size_t **maxInputDimsAdressA = &maxInputDimsAdress; m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR}; EXPECT_EQ(OH_NN_SUCCESS, executor.GetInputDimRange(input1Index, minInputDimsAdressA, maxInputDimsAdressA, length)); -- Gitee From b22fa2c5caa0b4e59e3366461a9ee62343f27505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BF=94?= Date: Wed, 5 Jun 2024 11:29:07 +0800 Subject: [PATCH 3/4] codeCheck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周翔 --- .../v1_0/inner_model/inner_model_test.cpp | 15 ++++++++++----- .../v2_0/inner_model/inner_model_test.cpp | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/test/unittest/components/v1_0/inner_model/inner_model_test.cpp b/test/unittest/components/v1_0/inner_model/inner_model_test.cpp index 610dd91..b4a4e36 100644 --- a/test/unittest/components/v1_0/inner_model/inner_model_test.cpp +++ b/test/unittest/components/v1_0/inner_model/inner_model_test.cpp @@ -115,7 +115,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_001, Test std::string opLayout; std::map opLayouts; - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest + .BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -137,7 +138,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_002, Test std::string opLayout; std::map opLayouts; - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest + .BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -202,7 +204,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test std::string opLayout; std::map opLayouts; - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest + .BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -264,7 +267,8 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_002, TestSize.Level1) std::map opLayouts; EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); - EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest + .BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -290,7 +294,8 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_003, TestSize.Level1) std::string opLayout; std::map opLayouts; - EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest + .BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } diff --git a/test/unittest/components/v2_0/inner_model/inner_model_test.cpp b/test/unittest/components/v2_0/inner_model/inner_model_test.cpp index 05e81d0..4a41c4c 100644 --- a/test/unittest/components/v2_0/inner_model/inner_model_test.cpp +++ b/test/unittest/components/v2_0/inner_model/inner_model_test.cpp @@ -115,7 +115,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_001, Test std::string opLayout; std::map opLayouts; - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest + .BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -137,7 +138,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_002, Test std::string opLayout; std::map opLayouts; - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest + .BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -200,7 +202,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test std::string opLayout; std::map opLayouts; - EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest + .BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -261,7 +264,8 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_002, TestSize.Level1) std::map opLayouts; EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); - EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest + .BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } /** @@ -286,7 +290,8 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_003, TestSize.Level1) std::string opLayout; std::map opLayouts; - EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest + .BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts)); } -- Gitee From 8a20a3f0366b527612dd4e1d4ace2d59eb107370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BF=94?= Date: Wed, 5 Jun 2024 12:37:39 +0800 Subject: [PATCH 4/4] build-tool to format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周翔 --- test/unittest/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 033c1f7..c47c301 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -15,8 +15,8 @@ import("//build/ohos.gni") group("unittest") { testonly = true - deps = [ + deps = [ "components:components_unittest", "ops:ops_unittest", - ] + ] } -- Gitee