From 71991d9f7105bddc9a78184aaaa1809dd4feb3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BF=94?= <897956360@qq.com> Date: Mon, 3 Jun 2024 20:10:14 +0800 Subject: [PATCH 1/5] =?UTF-8?q?UT=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 +- test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn | 1 + test/fuzztest/hdinnrtops_fuzzer/BUILD.gn | 1 + .../hdinnrtpreparedmodel_fuzzer/BUILD.gn | 1 + test/system_test/BUILD.gn | 1 + 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 + 18 files changed, 659 insertions(+), 764 deletions(-) diff --git a/.gitignore b/.gitignore index 335cc7f..d6e85f2 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,10 @@ 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/misc.xml +/.idea/modules.xml +/.idea/vcs.xml +/cmake-build-debug/CMakeFiles/clion-Debug-log.txt diff --git a/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn index d14bd87..bd02f08 100644 --- a/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn @@ -29,6 +29,7 @@ ohos_fuzztest("HdiNnrtDeviceFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", + "--coverage", ] sources = [ "hdinnrtdevice_fuzzer.cpp" ] diff --git a/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn index daf1abf..e39cc8d 100644 --- a/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("HdiNnrtOpsFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", + "--coverage", ] configs = [ "../../../config:coverage_flags" ] diff --git a/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn index 99a094e..26e0891 100644 --- a/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn @@ -29,6 +29,7 @@ ohos_fuzztest("HdiNnrtPreparedModelFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", + "--coverage", ] sources = [ "hdinnrtpreparedmodel_fuzzer.cpp" ] diff --git a/test/system_test/BUILD.gn b/test/system_test/BUILD.gn index 4a6d305..be3c384 100644 --- a/test/system_test/BUILD.gn +++ b/test/system_test/BUILD.gn @@ -29,6 +29,7 @@ config("system_test_config") { "-Wall", "-Wextra", "-Werror", + "--coverage", ] } 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 4a239c256c3128b7b276f985d42d9879f0df1551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BF=94?= Date: Tue, 4 Jun 2024 15:29:04 +0800 Subject: [PATCH 2/5] msg --- test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn | 1 - test/fuzztest/hdinnrtops_fuzzer/BUILD.gn | 1 - test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn | 1 - test/system_test/BUILD.gn | 1 - 4 files changed, 4 deletions(-) diff --git a/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn index bd02f08..d14bd87 100644 --- a/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn @@ -29,7 +29,6 @@ ohos_fuzztest("HdiNnrtDeviceFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", - "--coverage", ] sources = [ "hdinnrtdevice_fuzzer.cpp" ] diff --git a/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn index e39cc8d..daf1abf 100644 --- a/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn @@ -33,7 +33,6 @@ ohos_fuzztest("HdiNnrtOpsFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", - "--coverage", ] configs = [ "../../../config:coverage_flags" ] diff --git a/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn index 26e0891..99a094e 100644 --- a/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn @@ -29,7 +29,6 @@ ohos_fuzztest("HdiNnrtPreparedModelFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", - "--coverage", ] sources = [ "hdinnrtpreparedmodel_fuzzer.cpp" ] diff --git a/test/system_test/BUILD.gn b/test/system_test/BUILD.gn index be3c384..4a6d305 100644 --- a/test/system_test/BUILD.gn +++ b/test/system_test/BUILD.gn @@ -29,7 +29,6 @@ config("system_test_config") { "-Wall", "-Wextra", "-Werror", - "--coverage", ] } -- Gitee From 322a45bb51c0f46ee3c9d8260208e19757d4ca3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BF=94?= Date: Tue, 4 Jun 2024 15:29:04 +0800 Subject: [PATCH 3/5] msg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ÖÏ # Please enter the commit message for your changes. Lines starting --- test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn | 1 - test/fuzztest/hdinnrtops_fuzzer/BUILD.gn | 1 - test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn | 1 - test/system_test/BUILD.gn | 1 - 4 files changed, 4 deletions(-) diff --git a/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn index bd02f08..d14bd87 100644 --- a/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn @@ -29,7 +29,6 @@ ohos_fuzztest("HdiNnrtDeviceFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", - "--coverage", ] sources = [ "hdinnrtdevice_fuzzer.cpp" ] diff --git a/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn index e39cc8d..daf1abf 100644 --- a/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn @@ -33,7 +33,6 @@ ohos_fuzztest("HdiNnrtOpsFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", - "--coverage", ] configs = [ "../../../config:coverage_flags" ] diff --git a/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn index 26e0891..99a094e 100644 --- a/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn @@ -29,7 +29,6 @@ ohos_fuzztest("HdiNnrtPreparedModelFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", - "--coverage", ] sources = [ "hdinnrtpreparedmodel_fuzzer.cpp" ] diff --git a/test/system_test/BUILD.gn b/test/system_test/BUILD.gn index be3c384..4a6d305 100644 --- a/test/system_test/BUILD.gn +++ b/test/system_test/BUILD.gn @@ -29,7 +29,6 @@ config("system_test_config") { "-Wall", "-Wextra", "-Werror", - "--coverage", ] } -- Gitee From 2b4b9cdb14faa5430e4a4ea9d656aec0b2ac3845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BF=94?= Date: Tue, 4 Jun 2024 07:44:45 +0000 Subject: [PATCH 4/5] =?UTF-8?q?Revert=20"UT=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E4=BF=AE=E5=A4=8D"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 71991d9f7105bddc9a78184aaaa1809dd4feb3a6. --- .gitignore | 8 +- 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, 764 insertions(+), 655 deletions(-) diff --git a/.gitignore b/.gitignore index d6e85f2..335cc7f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,10 +17,4 @@ jni/include/schema/ # ignore runtime file deploy.bat -log.txt -/.idea/.gitignore -/.idea/ai_neural_network_runtime.iml -/.idea/misc.xml -/.idea/modules.xml -/.idea/vcs.xml -/cmake-build-debug/CMakeFiles/clion-Debug-log.txt +log.txt \ No newline at end of file diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 918ef60..1f2cee5 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -15,8 +15,5 @@ import("//build/ohos.gni") group("unittest") { testonly = true - deps = [ - "components:components_unittest", - "ops:ops_unittest" - ] + deps = [ "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 1ae76a0..c05e30c 100644 --- a/test/unittest/common/v1_0/executor_mock_device.cpp +++ b/test/unittest/common/v1_0/executor_mock_device.cpp @@ -14,6 +14,7 @@ */ #include "compilation.h" +#include "execution_plan.h" #include "hdi_device_v1_0.h" #include "test/unittest/common/v1_0/mock_idevice.h" @@ -21,6 +22,21 @@ 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) { @@ -70,5 +86,19 @@ 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 a37d1bd..594b1a7 100644 --- a/test/unittest/common/v1_0/inner_model_mock_device.cpp +++ b/test/unittest/common/v1_0/inner_model_mock_device.cpp @@ -19,11 +19,35 @@ #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 2e8d422..08d7b38 100644 --- a/test/unittest/common/v2_0/executor_mock_device.cpp +++ b/test/unittest/common/v2_0/executor_mock_device.cpp @@ -14,6 +14,7 @@ */ #include "compilation.h" +#include "execution_plan.h" #include "hdi_device_v2_0.h" #include "test/unittest/common/v2_0/mock_idevice.h" @@ -21,6 +22,21 @@ 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) { @@ -79,5 +95,19 @@ 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 ef6f1a7..bc083e1 100644 --- a/test/unittest/common/v2_0/inner_model_mock_device.cpp +++ b/test/unittest/common/v2_0/inner_model_mock_device.cpp @@ -19,11 +19,35 @@ #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 fd8d2ab..e90fbc8 100644 --- a/test/unittest/components/BUILD.gn +++ b/test/unittest/components/BUILD.gn @@ -21,7 +21,6 @@ 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", @@ -618,6 +617,16 @@ 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 ae6ef25..5fcde0e 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; + std::vector modelCache {{nullptr, 0}}; OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache); - EXPECT_EQ(OH_NN_SUCCESS, result); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, 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_SAVE_CACHE_EXCEPTION, result); + EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, 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 16b66f2..5634924 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,12 +62,14 @@ 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->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)); } 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->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)); } } @@ -108,14 +110,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_001, Test m_inputIndices = {}; SetLiteGraph(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)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); } /** @@ -130,14 +126,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_002, Test m_inputIndices = {6}; SetLiteGraph(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)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); } /** @@ -151,14 +141,7 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_003, Test EXPECT_NE(nullptr, liteGraph); SetLiteGraph(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_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); } /** @@ -173,14 +156,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_004, Test m_dimInput = {3, -3}; SetLiteGraph(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_NULL_PTR, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); } /** @@ -195,14 +172,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test m_outputIndices = {6}; SetLiteGraph(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)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); } /** @@ -212,36 +183,7 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test */ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_001, TestSize.Level1) { - 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)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr)); } /** @@ -255,15 +197,8 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_002, TestSize.Level1) EXPECT_NE(nullptr, liteGraph); SetLiteGraph(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)); + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph)); } /** @@ -283,13 +218,8 @@ 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)); - 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)); + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); } @@ -315,14 +245,7 @@ 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); - - 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_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); const int32_t dimInput[2] = {2, 2}; const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR}; @@ -415,14 +338,7 @@ 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); - - 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_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SetTensorValue(index, static_cast(&activation), sizeof(int8_t))); @@ -502,14 +418,7 @@ 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); - - 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_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs, m_outputs)); @@ -702,14 +611,7 @@ 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); - - 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_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SpecifyInputsAndOutputs(inputs, outputs)); } @@ -856,7 +758,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_FAILED, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); } /** @@ -873,16 +775,9 @@ 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)); - 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)); + EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, 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 c5ac5b2..b95187b 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,15 +19,14 @@ #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 Buffer& quantBuffer, - const ModelConfig& config, - std::shared_ptr& preparedModel) + const ModelConfig& config, std::shared_ptr& preparedModel) { if (model == nullptr) { return OH_NN_INVALID_PARAMETER; @@ -48,6 +47,29 @@ 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) { @@ -57,6 +79,30 @@ 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; @@ -221,30 +267,22 @@ void NeuralNetworkRuntimeTest::SetInnerBuild(InnerModel& innerModel) 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 minInputDims = 1; - size_t maxInputDims = 12; + 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 * minInputDimsAdress = &minInputDims; - size_t ** minInputDimsAdressA = &minInputDimsAdress; - - size_t * maxInputDimsAdress = &maxInputDims; - size_t ** maxInputDimsAdressA = &maxInputDimsAdress; + uint32_t input1Index = 0; + uint32_t input2Index = 1; + 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.GetInputDimRange(input1Index, minInputDimsAdressA, maxInputDimsAdressA, length)); + 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; - - 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)); + EXPECT_EQ(OH_NN_SUCCESS, executor.SetOutput(outputIndex, output, length)); + EXPECT_EQ(OH_NN_SUCCESS, executor.Run()); } /* @@ -772,7 +810,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_FAILED, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } /* @@ -799,7 +837,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_NE(nullptr, ret); + EXPECT_EQ(nullptr, ret); } /* @@ -838,9 +876,8 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_device_002, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + Compilation compilation(&innerModel); + OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); size_t deviceId = 1; OH_NN_ReturnCode ret = OH_NNCompilation_SetDevice(nnCompilation, deviceId); EXPECT_EQ(OH_NN_SUCCESS, ret); @@ -855,9 +892,12 @@ 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); } @@ -871,11 +911,12 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_002, testing::ext::Test { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + Compilation compilation(&innerModel); + OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); 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); } @@ -889,11 +930,12 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_003, testing::ext::Test { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + Compilation compilation(&innerModel); + OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); 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); } @@ -907,9 +949,12 @@ 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); } @@ -923,11 +968,13 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_performance_mode_002, testing { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + 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_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode); EXPECT_EQ(OH_NN_SUCCESS, ret); } @@ -941,9 +988,13 @@ 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); } @@ -957,11 +1008,13 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_priority_002, testing::ext::T { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + 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_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority); EXPECT_EQ(OH_NN_SUCCESS, ret); } @@ -975,9 +1028,13 @@ 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); } @@ -991,11 +1048,13 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_enable_float16_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + 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_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16); EXPECT_EQ(OH_NN_SUCCESS, ret); } @@ -1009,8 +1068,15 @@ 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); } @@ -1024,12 +1090,17 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + 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_FAILED, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } /* @@ -1066,9 +1137,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_destroy_003, testing::ext::TestSi { InnerModel* innerModel = new InnerModel(); EXPECT_NE(nullptr, innerModel); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + Compilation* compilation = new(std::nothrow) Compilation(innerModel); + EXPECT_NE(nullptr, compilation); + OH_NNCompilation* nnCompilation = reinterpret_cast(compilation); OH_NNCompilation_Destroy(&nnCompilation); EXPECT_EQ(nullptr, nnCompilation); } @@ -1082,6 +1153,14 @@ 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); @@ -1097,9 +1176,8 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_002, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + Compilation compilation(&innerModel); + OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation); EXPECT_EQ(nullptr, executor); } @@ -1113,11 +1191,18 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_003, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); + Compilation compilation(&innerModel); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + 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_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation); - EXPECT_EQ(nullptr, executor); + EXPECT_NE(nullptr, executor); } /** @@ -1145,10 +1230,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_002, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1166,10 +1250,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_003, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); SetTensor(); @@ -1188,10 +1271,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_004, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; SetTensor(); @@ -1211,10 +1293,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_005, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; int32_t dims[2] = {3, 4}; @@ -1224,7 +1305,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_INVALID_PARAMETER, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } /** @@ -1250,10 +1331,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_002, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; void *buffer = nullptr; @@ -1270,10 +1350,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_003, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1291,15 +1370,14 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_004, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; float output[12]; size_t length = 12 * sizeof(float); - EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length)); + EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length)); } /** @@ -1311,8 +1389,12 @@ 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; @@ -1330,10 +1412,11 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + SetInputAndOutput(executor); uint32_t outputIndex = 0; int32_t** shape = nullptr; @@ -1351,10 +1434,11 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + SetInputAndOutput(executor); int32_t expectDim[2] = {3, 3}; int32_t* ptr = expectDim; @@ -1374,10 +1458,11 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + SetInputAndOutput(executor); int32_t* ptr = nullptr; int32_t** shape = &ptr; @@ -1394,16 +1479,17 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + SetInputAndOutput(executor); int32_t* ptr = nullptr; int32_t** shape = &ptr; uint32_t length = 2; uint32_t outputIndex = 0; - EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length)); + EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length)); } /** @@ -1426,14 +1512,25 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + 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; 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_INVALID_PARAMETER, OH_NNExecutor_Run(nnExecutor)); + 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)); } /* @@ -1460,10 +1557,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; size_t length = 0; @@ -1481,10 +1577,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 6; size_t length = 9 * sizeof(float); @@ -1502,16 +1597,15 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; size_t length = 9 * sizeof(float); OH_NN_Memory* ret = OH_NNExecutor_AllocateInputMemory(nnExecutor, outputIndex, length); - EXPECT_EQ(nullptr, ret); + EXPECT_NE(nullptr, ret); } /* @@ -1538,10 +1632,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_002, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; size_t length = 0; @@ -1559,10 +1652,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_003, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 6; size_t length = 9 * sizeof(float); @@ -1580,16 +1672,15 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_004, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; size_t length = 9 * sizeof(float); OH_NN_Memory* ret = OH_NNExecutor_AllocateOutputMemory(nnExecutor, outputIndex, length); - EXPECT_EQ(nullptr, ret); + EXPECT_NE(nullptr, ret); } @@ -1602,6 +1693,8 @@ 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; @@ -1609,6 +1702,8 @@ 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); } @@ -1622,10 +1717,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_002, testing::e { InnerModel innerModel; BuildModel(innerModel); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; OH_NN_Memory** memory = nullptr; @@ -1642,10 +1736,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_003, testing::e { InnerModel innerModel; BuildModel(innerModel); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -1663,10 +1756,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_004, testing::e { InnerModel innerModel; BuildModel(innerModel); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 6; float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1686,18 +1778,19 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_005, testing::e { InnerModel innerModel; BuildModel(innerModel); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); 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_NE(nullptr, pMemory); + EXPECT_EQ(nullptr, pMemory); } /* @@ -1726,10 +1819,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; OH_NN_Memory** memory = nullptr; @@ -1746,10 +1838,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -1767,10 +1858,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 6; float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1790,18 +1880,19 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_005, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); 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_NE(nullptr, pMemory); + EXPECT_EQ(nullptr, pMemory); } /* @@ -1833,10 +1924,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); OH_NN_Tensor* operand = nullptr; @@ -1858,10 +1948,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); SetTensor(); @@ -1880,10 +1969,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; int32_t dims[2] = {3, 4}; @@ -1894,7 +1982,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_INVALID_PARAMETER, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } @@ -1923,10 +2011,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_002, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -1943,17 +2030,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_003, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); 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_INVALID_PARAMETER, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } /* @@ -1981,6 +2067,25 @@ 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. @@ -2108,7 +2213,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_FAILED, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } /* @@ -2149,7 +2254,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_INVALID_PARAMETER, ret); + EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, ret); } /* @@ -2163,7 +2268,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_INVALID_PARAMETER, ret); + EXPECT_EQ(OH_NN_SUCCESS, 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 b394f41..72889e4 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; + std::vector modelCache {{nullptr, 0}}; OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache); - EXPECT_EQ(OH_NN_SUCCESS, result); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, 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_SAVE_CACHE_EXCEPTION, result); + EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, 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 bea14f8..5634924 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,12 +62,14 @@ 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->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)); } 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->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)); } } @@ -108,14 +110,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_001, Test m_inputIndices = {}; SetLiteGraph(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)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); } /** @@ -130,14 +126,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_002, Test m_inputIndices = {6}; SetLiteGraph(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)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); } /** @@ -151,14 +141,7 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_003, Test EXPECT_NE(nullptr, liteGraph); SetLiteGraph(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_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); } /** @@ -173,13 +156,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_004, Test m_dimInput = {3, -3}; SetLiteGraph(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_NULL_PTR, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); } /** @@ -194,13 +172,8 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test m_outputIndices = {6}; SetLiteGraph(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)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); } /** @@ -210,36 +183,7 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test */ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_001, TestSize.Level1) { - 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)); + EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr)); } /** @@ -253,14 +197,8 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_002, TestSize.Level1) EXPECT_NE(nullptr, liteGraph); SetLiteGraph(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)); + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph)); } /** @@ -279,13 +217,9 @@ 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, buffer, modelName, isProfiling, opLayouts)); + EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph)); + mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph); } @@ -311,14 +245,7 @@ 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); - - 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_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); const int32_t dimInput[2] = {2, 2}; const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR}; @@ -411,14 +338,7 @@ 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); - - 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_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SetTensorValue(index, static_cast(&activation), sizeof(int8_t))); @@ -498,14 +418,7 @@ 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); - - 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_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs, m_outputs)); @@ -698,14 +611,7 @@ 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); - - 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_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph)); EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SpecifyInputsAndOutputs(inputs, outputs)); } @@ -852,7 +758,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_FAILED, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); + EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount)); } /** @@ -869,15 +775,9 @@ 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)); - 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)); + EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, 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 4adc7a8..ac2d02b 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,15 +19,14 @@ #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 Buffer& quantBuffer, - const ModelConfig& config, - std::shared_ptr& preparedModel) + const ModelConfig& config, std::shared_ptr& preparedModel) { if (model == nullptr) { return OH_NN_INVALID_PARAMETER; @@ -48,6 +47,29 @@ 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) { @@ -57,6 +79,30 @@ 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; @@ -221,29 +267,22 @@ void NeuralNetworkRuntimeTest::SetInnerBuild(InnerModel& innerModel) 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 minInputDims = 1; - size_t maxInputDims = 12; + 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 * minInputDimsAdress = &minInputDims; - size_t ** minInputDimsAdressA = &minInputDimsAdress; - - size_t * maxInputDimsAdress = &maxInputDims; - size_t ** maxInputDimsAdressA = &maxInputDimsAdress; + uint32_t input1Index = 0; + uint32_t input2Index = 1; + 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.GetInputDimRange(input1Index, minInputDimsAdressA, maxInputDimsAdressA, length)); - uint32_t outputIndex = 0; + EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input1Index, m_tensor, input1, length)); + EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input2Index, m_tensor, input2, length)); - 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)); + float output[12]; + uint32_t outputIndex = 0; + EXPECT_EQ(OH_NN_SUCCESS, executor.SetOutput(outputIndex, output, length)); + EXPECT_EQ(OH_NN_SUCCESS, executor.Run()); } /* @@ -771,7 +810,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_FAILED, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } /* @@ -798,7 +837,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_NE(nullptr, ret); + EXPECT_EQ(nullptr, ret); } /* @@ -837,9 +876,8 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_device_002, testing::ext::Tes { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + Compilation compilation(&innerModel); + OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); size_t deviceId = 1; OH_NN_ReturnCode ret = OH_NNCompilation_SetDevice(nnCompilation, deviceId); EXPECT_EQ(OH_NN_SUCCESS, ret); @@ -854,9 +892,12 @@ 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); } @@ -870,11 +911,12 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_002, testing::ext::Test { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + Compilation compilation(&innerModel); + OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); 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); } @@ -888,11 +930,12 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_003, testing::ext::Test { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + Compilation compilation(&innerModel); + OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); 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); } @@ -906,9 +949,12 @@ 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); } @@ -922,11 +968,13 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_performance_mode_002, testing { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + 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_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode); EXPECT_EQ(OH_NN_SUCCESS, ret); } @@ -940,9 +988,13 @@ 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); } @@ -956,11 +1008,13 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_priority_002, testing::ext::T { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + 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_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority); EXPECT_EQ(OH_NN_SUCCESS, ret); } @@ -974,9 +1028,13 @@ 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); } @@ -990,11 +1048,13 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_enable_float16_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + 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_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16); EXPECT_EQ(OH_NN_SUCCESS, ret); } @@ -1008,8 +1068,15 @@ 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); } @@ -1023,12 +1090,17 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + 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_FAILED, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } /* @@ -1065,9 +1137,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_destroy_003, testing::ext::TestSi { InnerModel* innerModel = new InnerModel(); EXPECT_NE(nullptr, innerModel); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + Compilation* compilation = new(std::nothrow) Compilation(innerModel); + EXPECT_NE(nullptr, compilation); + OH_NNCompilation* nnCompilation = reinterpret_cast(compilation); OH_NNCompilation_Destroy(&nnCompilation); EXPECT_EQ(nullptr, nnCompilation); } @@ -1081,6 +1153,14 @@ 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); @@ -1096,9 +1176,8 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_002, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + Compilation compilation(&innerModel); + OH_NNCompilation* nnCompilation = reinterpret_cast(&compilation); OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation); EXPECT_EQ(nullptr, executor); } @@ -1112,11 +1191,18 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_003, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); + Compilation compilation(&innerModel); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); + 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_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation); - EXPECT_EQ(nullptr, executor); + EXPECT_NE(nullptr, executor); } /** @@ -1144,10 +1230,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_002, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1165,10 +1250,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_003, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); SetTensor(); @@ -1187,10 +1271,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_004, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; SetTensor(); @@ -1210,10 +1293,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_005, testing::ext::TestSize. { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; int32_t dims[2] = {3, 4}; @@ -1223,7 +1305,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_INVALID_PARAMETER, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } /** @@ -1249,10 +1331,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_002, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; void *buffer = nullptr; @@ -1269,10 +1350,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_003, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1290,15 +1370,14 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_004, testing::ext::TestSize { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; float output[12]; size_t length = 12 * sizeof(float); - EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length)); + EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length)); } /** @@ -1310,10 +1389,11 @@ 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; - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + SetInputAndOutput(executor); int32_t* ptr = nullptr; int32_t** shape = &ptr; @@ -1332,10 +1412,11 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + SetInputAndOutput(executor); uint32_t outputIndex = 0; int32_t** shape = nullptr; @@ -1353,10 +1434,11 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + SetInputAndOutput(executor); int32_t expectDim[2] = {3, 3}; int32_t* ptr = expectDim; @@ -1376,10 +1458,11 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + SetInputAndOutput(executor); int32_t* ptr = nullptr; int32_t** shape = &ptr; @@ -1396,16 +1479,17 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + SetInputAndOutput(executor); int32_t* ptr = nullptr; int32_t** shape = &ptr; uint32_t length = 2; uint32_t outputIndex = 0; - EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length)); + EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length)); } /** @@ -1428,15 +1512,25 @@ 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); - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + 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; 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_INVALID_PARAMETER, OH_NNExecutor_Run(nnExecutor)); + 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)); } /* @@ -1463,10 +1557,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; size_t length = 0; @@ -1484,10 +1577,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 6; size_t length = 9 * sizeof(float); @@ -1505,16 +1597,15 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; size_t length = 9 * sizeof(float); OH_NN_Memory* ret = OH_NNExecutor_AllocateInputMemory(nnExecutor, outputIndex, length); - EXPECT_EQ(nullptr, ret); + EXPECT_NE(nullptr, ret); } /* @@ -1541,10 +1632,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_002, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; size_t length = 0; @@ -1562,10 +1652,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_003, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 6; size_t length = 9 * sizeof(float); @@ -1583,16 +1672,15 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_004, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; size_t length = 9 * sizeof(float); OH_NN_Memory* ret = OH_NNExecutor_AllocateOutputMemory(nnExecutor, outputIndex, length); - EXPECT_EQ(nullptr, ret); + EXPECT_NE(nullptr, ret); } @@ -1605,6 +1693,8 @@ 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; @@ -1612,6 +1702,8 @@ 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); } @@ -1625,10 +1717,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_002, testing::e { InnerModel innerModel; BuildModel(innerModel); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; OH_NN_Memory** memory = nullptr; @@ -1645,10 +1736,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_003, testing::e { InnerModel innerModel; BuildModel(innerModel); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -1666,10 +1756,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_004, testing::e { InnerModel innerModel; BuildModel(innerModel); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 6; float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1689,18 +1778,19 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_005, testing::e { InnerModel innerModel; BuildModel(innerModel); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); 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_NE(nullptr, pMemory); + EXPECT_EQ(nullptr, pMemory); } /* @@ -1729,10 +1819,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; OH_NN_Memory** memory = nullptr; @@ -1749,10 +1838,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -1770,10 +1858,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 6; float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8}; @@ -1793,18 +1880,19 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_005, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); 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_NE(nullptr, pMemory); + EXPECT_EQ(nullptr, pMemory); } /* @@ -1836,10 +1924,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_002, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); OH_NN_Tensor* operand = nullptr; @@ -1861,10 +1948,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_003, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); SetTensor(); @@ -1883,10 +1969,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_004, testing:: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t inputIndex = 0; int32_t dims[2] = {3, 4}; @@ -1897,7 +1982,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_INVALID_PARAMETER, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } @@ -1926,10 +2011,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_002, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); uint32_t outputIndex = 0; OH_NN_Memory* memory = nullptr; @@ -1946,17 +2030,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_003, testing: { InnerModel innerModel; EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel)); - - OH_NNModel* model = reinterpret_cast(&innerModel); - OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model); - OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation); + Compilation innerCompilation(&innerModel); + Executor executor(&innerCompilation); + OH_NNExecutor* nnExecutor = reinterpret_cast(&executor); 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_INVALID_PARAMETER, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } /* @@ -1984,6 +2067,25 @@ 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. @@ -2111,7 +2213,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_FAILED, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } /* @@ -2152,7 +2254,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_INVALID_PARAMETER, ret); + EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, ret); } /* @@ -2166,7 +2268,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_INVALID_PARAMETER, ret); + EXPECT_EQ(OH_NN_SUCCESS, ret); } } // namespace Unittest } // namespace NeuralNetworkRuntime diff --git a/test/unittest/ops/BUILD.gn b/test/unittest/ops/BUILD.gn index e11bc3b..cc7b775 100644 --- a/test/unittest/ops/BUILD.gn +++ b/test/unittest/ops/BUILD.gn @@ -21,7 +21,6 @@ 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 89635bc6ae0fddb80d8b5ae88d445a199da4b5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=BF=94?= Date: Tue, 4 Jun 2024 07:45:36 +0000 Subject: [PATCH 5/5] Revert "msg" This reverts commit 4a239c256c3128b7b276f985d42d9879f0df1551. --- test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn | 1 + test/fuzztest/hdinnrtops_fuzzer/BUILD.gn | 1 + test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn | 1 + test/system_test/BUILD.gn | 1 + 4 files changed, 4 insertions(+) diff --git a/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn index d14bd87..bd02f08 100644 --- a/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtdevice_fuzzer/BUILD.gn @@ -29,6 +29,7 @@ ohos_fuzztest("HdiNnrtDeviceFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", + "--coverage", ] sources = [ "hdinnrtdevice_fuzzer.cpp" ] diff --git a/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn index daf1abf..e39cc8d 100644 --- a/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtops_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("HdiNnrtOpsFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", + "--coverage", ] configs = [ "../../../config:coverage_flags" ] diff --git a/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn b/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn index 99a094e..26e0891 100644 --- a/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn +++ b/test/fuzztest/hdinnrtpreparedmodel_fuzzer/BUILD.gn @@ -29,6 +29,7 @@ ohos_fuzztest("HdiNnrtPreparedModelFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", + "--coverage", ] sources = [ "hdinnrtpreparedmodel_fuzzer.cpp" ] diff --git a/test/system_test/BUILD.gn b/test/system_test/BUILD.gn index 4a6d305..be3c384 100644 --- a/test/system_test/BUILD.gn +++ b/test/system_test/BUILD.gn @@ -29,6 +29,7 @@ config("system_test_config") { "-Wall", "-Wextra", "-Werror", + "--coverage", ] } -- Gitee