diff --git a/frameworks/native/neural_network_runtime/hdi_device_v2_0.cpp b/frameworks/native/neural_network_runtime/hdi_device_v2_0.cpp index c65bb1414f92503a0d9734608c868d1873597513..66561243de16fc4bbadee64120ddf61863111caf 100644 --- a/frameworks/native/neural_network_runtime/hdi_device_v2_0.cpp +++ b/frameworks/native/neural_network_runtime/hdi_device_v2_0.cpp @@ -115,6 +115,11 @@ OH_NN_ReturnCode IsOfflineModel(std::shared_ptrprimitive_ == nullptr) { + LOGE("Find invalid node primitive in the model."); + return OH_NN_NULL_PTR; + } + const mindspore::lite::NodeType& nodeType = mindspore::lite::MindIR_Primitive_GetType(pNode->primitive_); if (nodeType == mindspore::lite::NodeType::NODE_TYPE_CUSTOM) { isOfflineModel = true; 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 2c20ee30dcf19b1334e08a26d1b676a789edc644..ca73fff6c950a6f3a54dc7a9d99888b33583da60 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 @@ -96,6 +96,11 @@ OHOS::HDI::Nnrt::V2_0::Model* MindIR_LiteGraph_To_Model(const LiteGraph* lite_gr return new (std::nothrow) OHOS::HDI::Nnrt::V2_0::Model(); } +void LiteGraphDeleter(mindspore::lite::LiteGraph* liteGraph) +{ + MindIR_LiteGraph_Destroy(&liteGraph); +} + void MindIR_Model_Destroy(OHOS::HDI::Nnrt::V2_0::Model** model) { if ((model != nullptr) && (*model != nullptr)) { @@ -123,7 +128,6 @@ void BuildLiteGraph(std::shared_ptr& model) model->name_ = "testGraph"; model->input_indices_ = {0}; model->output_indices_ = {1}; - model->all_tensors_ = {nullptr}; const std::vector quant_params {}; const std::vector data(DATA_NUM, DATA_VALUE); const std::vector dim = {DIM_NUM, DIM_NUM}; @@ -136,11 +140,11 @@ void BuildLiteGraph(std::shared_ptr& model) model->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create()); } - mindspore::lite::LiteGraph::Node node; - node.name_ = "testNode"; - mindspore::lite::LiteGraph::Node* testNode = &node; - model->all_nodes_.emplace_back(testNode); - model->all_nodes_.emplace_back(testNode); + mindspore::lite::LiteGraph::Node* node = new (std::nothrow) mindspore::lite::LiteGraph::Node(); + node->name_ = "testNode"; + auto activation_type = mindspore::lite::ACTIVATION_TYPE_NO_ACTIVATION; + node->primitive_ = mindspore::lite::MindIR_AddFusion_CreatePrimitive(activation_type); + model->all_nodes_.emplace_back(node); } class HDIDeviceTest : public testing::Test { @@ -601,7 +605,9 @@ HWTEST_F(HDIDeviceTest, hdidevice_getdevicestatus_005, TestSize.Level0) HWTEST_F(HDIDeviceTest, hdidevice_getsupportedoperation_001, TestSize.Level0) { std::vector ops {true}; - std::shared_ptr model = std::make_shared(); + std::shared_ptr model = + std::shared_ptr(new (std::nothrow) mindspore::lite::LiteGraph(), + mindspore::lite::LiteGraphDeleter); EXPECT_NE(nullptr, model); BuildLiteGraph(model);