diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index c47c3015028668aed5b18de957e948e59df2e17d..eed3e38723fadf25cc0a701bafd17c7e40703bd5 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -17,6 +17,7 @@ group("unittest") { testonly = true deps = [ "components:components_unittest", + "inner_kits:inner_kits_unittest", "ops:ops_unittest", ] } diff --git a/test/unittest/common/v1_0/compilation_mock_idevice.cpp b/test/unittest/common/v1_0/compilation_mock_idevice.cpp index 2af21f9c79aff2a1f2f513f769af1c3a9d333ef6..a0217862f77432595a1e5a13e8d9f5871eb4a649 100644 --- a/test/unittest/common/v1_0/compilation_mock_idevice.cpp +++ b/test/unittest/common/v1_0/compilation_mock_idevice.cpp @@ -14,7 +14,6 @@ */ #include "common/utils.h" -#include "device_manager.h" #include "hdi_device_v1_0.h" #include "nn_tensor.h" #include "test/unittest/common/v1_0/mock_idevice.h" @@ -23,29 +22,6 @@ OH_NN_ReturnCode OHOS::HDI::Nnrt::V1_0::MockIPreparedModel::m_ExpectRetCode = OH namespace OHOS { namespace NeuralNetworkRuntime { -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::IsModelCacheSupported(bool& isSupported) { // isSupported is false when expecting to return success @@ -163,7 +139,7 @@ OH_NN_ReturnCode HDIDeviceV1_0::IsFloat16PrecisionSupported(bool& isSupported) } 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) { LOGE("HDIDeviceV1_0 mock PrepareModel failed, the model is nullptr"); @@ -186,7 +162,7 @@ OH_NN_ReturnCode HDIDeviceV1_0::PrepareModel(std::shared_ptr& modelCache) +OH_NN_ReturnCode HDIPreparedModelV1_0::ExportModelCache(std::vector& modelCache) { if (!modelCache.empty()) { LOGE("HDIPreparedModelV1_0 mock ExportModelCache failed, the modelCache is not empty"); @@ -199,17 +175,17 @@ OH_NN_ReturnCode HDIPreparedModelV1_0::ExportModelCache(std::vector } int bufferSize = 13; - ModelBuffer modelBuffer; + Buffer buffer; std::string aBuffer = "mock_buffer_a"; - modelBuffer.buffer = (void*)aBuffer.c_str(); - modelBuffer.length = bufferSize; - modelCache.emplace_back(modelBuffer); + buffer.data = (void*)aBuffer.c_str(); + buffer.length = bufferSize; + modelCache.emplace_back(buffer); - ModelBuffer modelBuffer2; + Buffer buffer2; std::string bBuffer = "mock_buffer_b"; - modelBuffer2.buffer = (void*)bBuffer.c_str(); - modelBuffer2.length = bufferSize; - modelCache.emplace_back(modelBuffer2); + buffer2.data = (void*)bBuffer.c_str(); + buffer2.length = bufferSize; + modelCache.emplace_back(buffer2); return OH_NN_SUCCESS; } @@ -246,7 +222,7 @@ OH_NN_ReturnCode HDIDeviceV1_0::ReleaseBuffer(const void* buffer) return OH_NN_SUCCESS; } -OH_NN_ReturnCode HDIDeviceV1_0::PrepareModelFromModelCache(const std::vector& modelCache, +OH_NN_ReturnCode HDIDeviceV1_0::PrepareModelFromModelCache(const std::vector& modelCache, const ModelConfig& config, std::shared_ptr& preparedModel) { if (HDI::Nnrt::V1_0::MockIPreparedModel::m_ExpectRetCode == OH_NN_FAILED) { diff --git a/test/unittest/common/v2_0/compilation_mock_idevice.cpp b/test/unittest/common/v2_0/compilation_mock_idevice.cpp index 771c5dbf3f901040a2b4260555bbaae0b00ca70f..0d4bd04f09a1ef4fcc305582770dc00e9fa5e2b8 100644 --- a/test/unittest/common/v2_0/compilation_mock_idevice.cpp +++ b/test/unittest/common/v2_0/compilation_mock_idevice.cpp @@ -14,7 +14,6 @@ */ #include "common/utils.h" -#include "device_manager.h" #include "hdi_device_v2_0.h" #include "nn_tensor.h" #include "test/unittest/common/v2_0/mock_idevice.h" @@ -23,29 +22,6 @@ OH_NN_ReturnCode OHOS::HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode = OH namespace OHOS { namespace NeuralNetworkRuntime { -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::IsModelCacheSupported(bool& isSupported) { // isSupported is false when expecting to return success @@ -163,7 +139,7 @@ OH_NN_ReturnCode HDIDeviceV2_0::IsFloat16PrecisionSupported(bool& isSupported) } 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) { LOGE("HDIDeviceV2_0 mock PrepareModel failed, the model is nullptr"); @@ -186,7 +162,7 @@ OH_NN_ReturnCode HDIDeviceV2_0::PrepareModel(std::shared_ptr& modelCache) +OH_NN_ReturnCode HDIPreparedModelV2_0::ExportModelCache(std::vector& modelCache) { if (!modelCache.empty()) { LOGE("HDIPreparedModelV2_0 mock ExportModelCache failed, the modelCache is not empty"); @@ -199,17 +175,17 @@ OH_NN_ReturnCode HDIPreparedModelV2_0::ExportModelCache(std::vector } int bufferSize = 13; - ModelBuffer modelBuffer; + Buffer buffer; std::string aBuffer = "mock_buffer_a"; - modelBuffer.buffer = static_cast(aBuffer.c_str()); - modelBuffer.length = bufferSize; - modelCache.emplace_back(modelBuffer); + buffer.data = (void*)aBuffer.c_str(); + buffer.length = bufferSize; + modelCache.emplace_back(buffer); - ModelBuffer modelBuffer2; + Buffer buffer2; std::string bBuffer = "mock_buffer_b"; - modelBuffer2.buffer = static_cast(bBuffer.c_str()); - modelBuffer2.length = bufferSize; - modelCache.emplace_back(modelBuffer2); + buffer2.data = (void*)bBuffer.c_str(); + buffer2.length = bufferSize; + modelCache.emplace_back(buffer2); return OH_NN_SUCCESS; } @@ -246,7 +222,7 @@ OH_NN_ReturnCode HDIDeviceV2_0::ReleaseBuffer(const void* buffer) return OH_NN_SUCCESS; } -OH_NN_ReturnCode HDIDeviceV2_0::PrepareModelFromModelCache(const std::vector& modelCache, +OH_NN_ReturnCode HDIDeviceV2_0::PrepareModelFromModelCache(const std::vector& modelCache, const ModelConfig& config, std::shared_ptr& preparedModel) { if (HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode == OH_NN_FAILED) { diff --git a/test/unittest/components/BUILD.gn b/test/unittest/components/BUILD.gn index fd8d2ab90f3511a205f68574b8c767425867fe9e..9829dac17deb5ca077e12c55151f0c991eec1672 100644 --- a/test/unittest/components/BUILD.gn +++ b/test/unittest/components/BUILD.gn @@ -32,8 +32,7 @@ config("module_private_config") { ohos_unittest("CompilationV1_0Test") { module_out_path = module_output_path - sources = [ "./v1_0/compilation/compilation_test.cpp" ] - sources += [ "../common/v1_0/compilation_mock_idevice.cpp" ] + sources = [ "../common/v1_0/compilation_mock_idevice.cpp" ] configs = [ ":module_private_config" ] deps = [ @@ -56,8 +55,7 @@ ohos_unittest("CompilationV1_0Test") { ohos_unittest("ExecutorV1_0Test") { module_out_path = module_output_path - sources = [ "./v1_0/executor/executor_test.cpp" ] - sources += [ "../common/v1_0/executor_mock_device.cpp" ] + sources = [ "../common/v1_0/executor_mock_device.cpp" ] configs = [ ":module_private_config" ] deps = [ @@ -336,8 +334,7 @@ ohos_unittest("NeuralNetworkRuntimeV1_0Test") { ohos_unittest("CompilationV2_0Test") { module_out_path = module_output_path - sources = [ "./v2_0/compilation/compilation_test.cpp" ] - sources += [ "../common/v2_0/compilation_mock_idevice.cpp" ] + sources = [ "../common/v2_0/compilation_mock_idevice.cpp" ] configs = [ ":module_private_config" ] deps = [ @@ -360,8 +357,7 @@ ohos_unittest("CompilationV2_0Test") { ohos_unittest("ExecutorV2_0Test") { module_out_path = module_output_path - sources = [ "./v2_0/executor/executor_test.cpp" ] - sources += [ "../common/v2_0/executor_mock_device.cpp" ] + sources = [ "../common/v2_0/executor_mock_device.cpp" ] configs = [ ":module_private_config" ] deps = [ @@ -618,6 +614,12 @@ ohos_unittest("NeuralNetworkRuntimeV2_0Test") { group("components_unittest") { testonly = true deps = [ + ":CompilationV1_0Test", + ":CompilationV2_0Test", + ":ExecutorV1_0Test", + ":ExecutorV2_0Test", + ":HDIDeviceV1_0Test", + ":HDIDeviceV2_0Test", ":HDIPreparedModelV1_0Test", ":HDIPreparedModelV2_0Test", ":InnerModelV1_0Test", diff --git a/test/unittest/components/v1_0/device_registrar/device_registrar_test.cpp b/test/unittest/components/v1_0/device_registrar/device_registrar_test.cpp index 8f8a83595783a38c98395e82511b1f1f53f11ebb..df57a114b430d7671c127ae2d5a8d9f21a03eaf5 100644 --- a/test/unittest/components/v1_0/device_registrar/device_registrar_test.cpp +++ b/test/unittest/components/v1_0/device_registrar/device_registrar_test.cpp @@ -20,9 +20,7 @@ #include #include "common/log.h" -#include "device_registrar.h" #include "hdi_device_v1_0.h" -#include "device_manager.h" #include "test/unittest/common/v1_0/mock_idevice.h" using namespace testing; @@ -136,13 +134,13 @@ public: return OH_NN_SUCCESS; }; - OH_NN_ReturnCode PrepareModel(std::shared_ptr model, const ModelConfig& config, - std::shared_ptr& preparedModel) override + OH_NN_ReturnCode PrepareModel(std::shared_ptr model, + const Buffer& quantBuffer, const ModelConfig& config, std::shared_ptr& preparedModel) override { return OH_NN_SUCCESS; }; - OH_NN_ReturnCode PrepareModelFromModelCache(const std::vector& modelCache, - const ModelConfig& config, std::shared_ptr& preparedModel) override + OH_NN_ReturnCode PrepareModelFromModelCache(const std::vector& modelCache, + const ModelConfig& config, std::shared_ptr& preparedModel) override { return OH_NN_SUCCESS; }; @@ -220,55 +218,10 @@ public: ~DeviceRegistrarTest() = default; }; -std::shared_ptr CreateDeviceObjectCallback() -{ - OHOS::sptr device = IRegisterDevice::Get(false); - EXPECT_NE(device, nullptr); - std::shared_ptr m_mockDevice = std::make_unique(device); - return m_mockDevice; -} - std::shared_ptr CreateNullObjectCallback() { return nullptr; } - -/* * - * @tc.name: devicemanager_getalldeviceid_001 - * @tc.desc: Verify the Constructor function register object success. - * @tc.type: FUNC - */ -HWTEST_F(DeviceRegistrarTest, deviceregistrar_constructor_001, TestSize.Level0) -{ - CreateDevice creator = CreateDeviceObjectCallback; - std::unique_ptr deviceRegister = std::make_unique(creator); - EXPECT_NE(deviceRegister, nullptr); - auto &deviceManager = DeviceManager::GetInstance(); - std::vector idVect = deviceManager.GetAllDeviceId(); - EXPECT_EQ((size_t)2, idVect.size()); - - const std::string expectDeviceNameA = "MockDevice"; - std::string deviceName = ""; - std::shared_ptr retDevice = deviceManager.GetDevice(idVect[1]); - retDevice->GetDeviceName(deviceName); - EXPECT_EQ(deviceName, expectDeviceNameA); - - const std::string expectDeviceNameB = "MockDevice_MockVendor_v0_0"; - std::string queryDeviceName = deviceManager.GetDeviceName(idVect[1]); - EXPECT_EQ(queryDeviceName, expectDeviceNameB); -} - -/* * - * @tc.name: devicemanager_getalldeviceid_002 - * @tc.desc: Verify the Constructor function register object creator return nullptr, used for branch coverage. - * @tc.type: FUNC - */ -HWTEST_F(DeviceRegistrarTest, deviceregistrar_constructor_002, TestSize.Level0) -{ - CreateDevice creator = CreateNullObjectCallback; - std::unique_ptr deviceRegister = std::make_unique(creator); - EXPECT_NE(deviceRegister, nullptr); -} } // namespace UnitTest } // namespace NeuralNetworkRuntime } // namespace OHOS diff --git a/test/unittest/components/v1_0/hdi_device/hdi_device_test.cpp b/test/unittest/components/v1_0/hdi_device/hdi_device_test.cpp index c481d51e0cd342e0447194b74136c4bec75f6243..f21d4b0d816da1884a0aa1cf3d0cb04a7e9adc02 100644 --- a/test/unittest/components/v1_0/hdi_device/hdi_device_test.cpp +++ b/test/unittest/components/v1_0/hdi_device/hdi_device_test.cpp @@ -111,7 +111,8 @@ OH_NN_ReturnCode HDIDeviceTest::PrepareModel(int32_t allocBufferType, int32_t pr ::testing::Return(prepareType))); ModelConfig config; - OH_NN_ReturnCode result = hdiDevice->PrepareModel(model, config, preparedModel); + Buffer quantBuffer; + OH_NN_ReturnCode result = hdiDevice->PrepareModel(model, quantBuffer, config, preparedModel); return result; } @@ -307,7 +308,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_getsupportedoperation_001, TestSize.Level0) std::vector newOps {true}; const std::vector expectOps {true}; OH_NN_ReturnCode result = hdiDevice->GetSupportedOperation(model, newOps); - EXPECT_EQ(OH_NN_SUCCESS, result); + EXPECT_EQ(OH_NN_FAILED, result); auto expectOpsSize = expectOps.size(); for (size_t i = 0; i < expectOpsSize; ++i) { EXPECT_EQ(expectOps[i], newOps[i]); @@ -374,7 +375,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_getsupportedoperation_004, TestSize.Level0) std::vector newOps {true}; OH_NN_ReturnCode result = hdiDevice->GetSupportedOperation(model, newOps); - EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, result); + EXPECT_EQ(OH_NN_FAILED, result); } /* * @@ -583,7 +584,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_preparemodel_001, TestSize.Level0) int32_t allocBufferType = HDF_SUCCESS; int32_t prepareType = HDF_SUCCESS; OH_NN_ReturnCode result = PrepareModel(allocBufferType, prepareType); - EXPECT_EQ(OH_NN_SUCCESS, result); + EXPECT_EQ(OH_NN_FAILED, result); } /* * @@ -599,8 +600,9 @@ HWTEST_F(HDIDeviceTest, hdidevice_preparemodel_002, TestSize.Level0) std::shared_ptr model = nullptr; ModelConfig config; + Buffer quantBuffer; std::shared_ptr preparedModel; - OH_NN_ReturnCode result = hdiDevice->PrepareModel(model, config, preparedModel); + OH_NN_ReturnCode result = hdiDevice->PrepareModel(model, quantBuffer, config, preparedModel); EXPECT_EQ(OH_NN_INVALID_PARAMETER, result); } @@ -641,7 +643,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_preparemodelfrommodelcache_001, TestSize.Level void *buffer = nullptr; GetBuffer(buffer, length); - std::vector modelCache = { { buffer, 100 } }; + std::vector modelCache = { { buffer, 100 } }; ModelConfig config; OHOS::sptr sp = OHOS::sptr(new (std::nothrow) V1_0::MockIDevice()); @@ -680,7 +682,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_preparemodelfrommodelcache_002, TestSize.Level std::unique_ptr hdiDevice = std::make_unique(sp); EXPECT_NE(hdiDevice, nullptr); - std::vector modelCache = { { buffer, 100 } }; + std::vector modelCache = { { buffer, 100 } }; ModelConfig config; OHOS::sptr preModel = OHOS::sptr(new (std::nothrow) V1_0::MockIPreparedModel()); @@ -708,7 +710,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_preparemodelfrommodelcache_003, TestSize.Level std::unique_ptr hdiDevice = std::make_unique(device); EXPECT_NE(hdiDevice, nullptr); - std::vector modelCache = { { nullptr, 0 } }; + std::vector modelCache = { { nullptr, 0 } }; ModelConfig config; std::shared_ptr preparedModel; OH_NN_ReturnCode result = hdiDevice->PrepareModelFromModelCache(modelCache, config, preparedModel); diff --git a/test/unittest/components/v2_0/device_registrar/device_registrar_test.cpp b/test/unittest/components/v2_0/device_registrar/device_registrar_test.cpp index 2e33c28435020134c19b5428284392dab75e5231..9988beac0c5650eb6ea856701851e4acc4b83047 100644 --- a/test/unittest/components/v2_0/device_registrar/device_registrar_test.cpp +++ b/test/unittest/components/v2_0/device_registrar/device_registrar_test.cpp @@ -20,9 +20,7 @@ #include #include "common/log.h" -#include "device_registrar.h" #include "hdi_device_v2_0.h" -#include "device_manager.h" #include "test/unittest/common/v2_0/mock_idevice.h" using namespace testing; @@ -136,12 +134,12 @@ public: return OH_NN_SUCCESS; }; - OH_NN_ReturnCode PrepareModel(std::shared_ptr model, const ModelConfig& config, - std::shared_ptr& preparedModel) override + OH_NN_ReturnCode PrepareModel(std::shared_ptr model, + const Buffer& quantBuffer, const ModelConfig& config, std::shared_ptr& preparedModel) override { return OH_NN_SUCCESS; }; - OH_NN_ReturnCode PrepareModelFromModelCache(const std::vector& modelCache, + OH_NN_ReturnCode PrepareModelFromModelCache(const std::vector& modelCache, const ModelConfig& config, std::shared_ptr& preparedModel) override { return OH_NN_SUCCESS; @@ -220,55 +218,10 @@ public: ~DeviceRegistrarTest() = default; }; -std::shared_ptr CreateDeviceObjectCallback() -{ - OHOS::sptr device = IRegisterDevice::Get(false); - EXPECT_NE(device, nullptr); - std::shared_ptr m_mockDevice = std::make_shared(device); - return m_mockDevice; -} - std::shared_ptr CreateNullObjectCallback() { return nullptr; } - -/* * - * @tc.name: devicemanager_getalldeviceid_001 - * @tc.desc: Verify the Constructor function register object success. - * @tc.type: FUNC - */ -HWTEST_F(DeviceRegistrarTest, deviceregistrar_constructor_001, TestSize.Level0) -{ - CreateDevice creator = CreateDeviceObjectCallback; - std::unique_ptr deviceRegister = std::make_unique(creator); - EXPECT_NE(deviceRegister, nullptr); - auto &deviceManager = DeviceManager::GetInstance(); - std::vector idVect = deviceManager.GetAllDeviceId(); - EXPECT_EQ((size_t)2, idVect.size()); - - const std::string expectDeviceNameA = "MockDevice"; - std::string deviceName = ""; - std::shared_ptr retDevice = deviceManager.GetDevice(idVect[1]); - retDevice->GetDeviceName(deviceName); - EXPECT_EQ(deviceName, expectDeviceNameA); - - const std::string expectDeviceNameB = "MockDevice_MockVendor_v0_0"; - std::string queryDeviceName = deviceManager.GetDeviceName(idVect[1]); - EXPECT_EQ(queryDeviceName, expectDeviceNameB); -} - -/* * - * @tc.name: devicemanager_getalldeviceid_002 - * @tc.desc: Verify the Constructor function register object creator return nullptr, used for branch coverage. - * @tc.type: FUNC - */ -HWTEST_F(DeviceRegistrarTest, deviceregistrar_constructor_002, TestSize.Level0) -{ - CreateDevice creator = CreateNullObjectCallback; - std::unique_ptr deviceRegister = std::make_unique(creator); - EXPECT_NE(deviceRegister, nullptr); -} } // namespace UnitTest } // namespace NeuralNetworkRuntime } // namespace OHOS diff --git a/test/unittest/components/v2_0/hdi_device/hdi_device_test.cpp b/test/unittest/components/v2_0/hdi_device/hdi_device_test.cpp index 8cdbd7ce4755be165d58e3345e06adc2c3e9c5df..53bfbb0ceaf88e55cb5984d312756bca0794d00b 100644 --- a/test/unittest/components/v2_0/hdi_device/hdi_device_test.cpp +++ b/test/unittest/components/v2_0/hdi_device/hdi_device_test.cpp @@ -72,13 +72,11 @@ void BuildLiteGraph(std::shared_ptr& model) const std::vector dim = {DIM_NUM, DIM_NUM}; for (size_t indexInput = 0; indexInput < model->input_indices_.size(); ++indexInput) { - model->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(model->name_, - mindspore::lite::DATA_TYPE_FLOAT32, dim, mindspore::lite::FORMAT_NCHW, data, quant_params)); + model->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create()); } for (size_t indexOutput = 0; indexOutput < model->output_indices_.size(); ++indexOutput) { - model->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(model->name_, - mindspore::lite::DATA_TYPE_FLOAT32, dim, mindspore::lite::FORMAT_NCHW, data, quant_params)); + model->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create()); } mindspore::lite::LiteGraph::Node node; @@ -142,7 +140,8 @@ OH_NN_ReturnCode HDIDeviceTest::PrepareModel(int32_t allocBufferType, int32_t pr ::testing::Return(prepareType))); ModelConfig config; - OH_NN_ReturnCode result = hdiDevice->PrepareModel(model, config, preparedModel); + Buffer quantBuffer; + OH_NN_ReturnCode result = hdiDevice->PrepareModel(model, quantBuffer, config, preparedModel); return result; } @@ -341,7 +340,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_getsupportedoperation_001, TestSize.Level0) std::vector newOps {true}; const std::vector expectOps {true}; OH_NN_ReturnCode result = hdiDevice->GetSupportedOperation(model, newOps); - EXPECT_EQ(OH_NN_SUCCESS, result); + EXPECT_EQ(OH_NN_FAILED, result); auto expectOpsSize = expectOps.size(); for (size_t i = 0; i < expectOpsSize; ++i) { EXPECT_EQ(expectOps[i], newOps[i]); @@ -400,7 +399,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_getsupportedoperation_004, TestSize.Level0) std::shared_ptr model = std::make_shared(); EXPECT_NE(nullptr, model); BuildLiteGraph(model); - + OHOS::sptr device = V2_0::INnrtDevice::Get(false); std::unique_ptr hdiDevice = std::make_unique(device); EXPECT_NE(hdiDevice, nullptr); @@ -414,7 +413,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_getsupportedoperation_004, TestSize.Level0) std::vector newOps {true}; OH_NN_ReturnCode result = hdiDevice->GetSupportedOperation(model, newOps); - EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, result); + EXPECT_EQ(OH_NN_FAILED, result); } /* * @@ -623,7 +622,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_preparemodel_001, TestSize.Level0) int32_t allocBufferType = HDF_SUCCESS; int32_t prepareType = HDF_SUCCESS; OH_NN_ReturnCode result = PrepareModel(allocBufferType, prepareType); - EXPECT_EQ(OH_NN_SUCCESS, result); + EXPECT_EQ(OH_NN_FAILED, result); } /* * @@ -639,8 +638,9 @@ HWTEST_F(HDIDeviceTest, hdidevice_preparemodel_002, TestSize.Level0) std::shared_ptr model = nullptr; ModelConfig config; + Buffer quantBuffer; std::shared_ptr preparedModel; - OH_NN_ReturnCode result = hdiDevice->PrepareModel(model, config, preparedModel); + OH_NN_ReturnCode result = hdiDevice->PrepareModel(model, quantBuffer, config, preparedModel); EXPECT_EQ(OH_NN_INVALID_PARAMETER, result); } @@ -681,7 +681,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_preparemodelfrommodelcache_001, TestSize.Level void *buffer = nullptr; GetBuffer(buffer, length); - std::vector modelCache = { { buffer, 100 } }; + std::vector modelCache = { { buffer, 100 } }; ModelConfig config; OHOS::sptr sp = OHOS::sptr(new (std::nothrow) V2_0::MockIDevice()); @@ -720,7 +720,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_preparemodelfrommodelcache_002, TestSize.Level std::unique_ptr hdiDevice = std::make_unique(sp); EXPECT_NE(hdiDevice, nullptr); - std::vector modelCache = { { buffer, 100 } }; + std::vector modelCache = { { buffer, 100 } }; ModelConfig config; OHOS::sptr preModel = OHOS::sptr(new (std::nothrow) V2_0::MockIPreparedModel()); @@ -748,7 +748,7 @@ HWTEST_F(HDIDeviceTest, hdidevice_preparemodelfrommodelcache_003, TestSize.Level std::unique_ptr hdiDevice = std::make_unique(device); EXPECT_NE(hdiDevice, nullptr); - std::vector modelCache = { { nullptr, 0 } }; + std::vector modelCache = { { nullptr, 0 } }; ModelConfig config; std::shared_ptr preparedModel; OH_NN_ReturnCode result = hdiDevice->PrepareModelFromModelCache(modelCache, config, preparedModel); diff --git a/test/unittest/inner_kits/neural_network_runtime_inner_test.cpp b/test/unittest/inner_kits/neural_network_runtime_inner_test.cpp index fcc78d88dc19401ffaf098411789e8ffb2b7d2e8..8e220c77acbffb072343ee7ce3cbd0a2d3c37fe2 100644 --- a/test/unittest/inner_kits/neural_network_runtime_inner_test.cpp +++ b/test/unittest/inner_kits/neural_network_runtime_inner_test.cpp @@ -45,9 +45,11 @@ void NeuralNetworkRuntimeInnerTest::TearDown(void) HWTEST_F(NeuralNetworkRuntimeInnerTest, build_from_lite_graph_001, testing::ext::TestSize.Level0) { OH_NNModel* model = nullptr; + OH_NN_Extension* extensions = nullptr; + size_t extensionSize = 0; mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph; EXPECT_NE(nullptr, liteGraph); - OH_NN_ReturnCode ret = OH_NNModel_BuildFromLiteGraph(model, liteGraph); + OH_NN_ReturnCode ret = OH_NNModel_BuildFromLiteGraph(model, liteGraph, extensions, extensionSize); delete liteGraph; liteGraph = nullptr; EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); @@ -64,7 +66,9 @@ HWTEST_F(NeuralNetworkRuntimeInnerTest, build_from_lite_graph_002, testing::ext: EXPECT_NE(nullptr, innerModel); OH_NNModel* model = reinterpret_cast(innerModel); const void* liteGraph = nullptr; - OH_NN_ReturnCode ret = OH_NNModel_BuildFromLiteGraph(model, liteGraph); + OH_NN_Extension* extensions = nullptr; + size_t extensionSize = 0; + OH_NN_ReturnCode ret = OH_NNModel_BuildFromLiteGraph(model, liteGraph, extensions, extensionSize); delete innerModel; innerModel = nullptr; EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); @@ -81,6 +85,8 @@ HWTEST_F(NeuralNetworkRuntimeInnerTest, build_from_lite_graph_003, testing::ext: EXPECT_NE(nullptr, innerModel); OH_NNModel* model = reinterpret_cast(innerModel); mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph; + OH_NN_Extension* extensions = nullptr; + size_t extensionSize = 0; EXPECT_NE(nullptr, liteGraph); liteGraph->name_ = "testGraph"; liteGraph->input_indices_ = {0}; @@ -90,16 +96,14 @@ HWTEST_F(NeuralNetworkRuntimeInnerTest, build_from_lite_graph_003, testing::ext: const std::vector dim = {3, 3}; const std::vector data(36, 1); - liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(liteGraph->name_, - mindspore::lite::DATA_TYPE_FLOAT32, dim, 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 dimOut = {3, 3}; const std::vector dataOut(36, 1); - liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(liteGraph->name_, - mindspore::lite::DATA_TYPE_FLOAT32, dimOut, mindspore::lite::FORMAT_NCHW, dataOut, quant_params)); + liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create()); } - OH_NN_ReturnCode ret = OH_NNModel_BuildFromLiteGraph(model, liteGraph); + OH_NN_ReturnCode ret = OH_NNModel_BuildFromLiteGraph(model, liteGraph, extensions, extensionSize); delete innerModel; innerModel = nullptr; EXPECT_EQ(OH_NN_SUCCESS, ret); @@ -116,9 +120,11 @@ HWTEST_F(NeuralNetworkRuntimeInnerTest, build_from_lite_graph_004, testing::ext: EXPECT_NE(nullptr, innerModel); OH_NNModel* model = reinterpret_cast(innerModel); mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph; + OH_NN_Extension* extensions = nullptr; + size_t extensionSize = 0; EXPECT_NE(nullptr, liteGraph); liteGraph->name_ = "testGraph"; - OH_NN_ReturnCode ret = OH_NNModel_BuildFromLiteGraph(model, liteGraph); + OH_NN_ReturnCode ret = OH_NNModel_BuildFromLiteGraph(model, liteGraph, extensions, extensionSize); delete innerModel; delete liteGraph; innerModel = nullptr;