1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <vector> 17 #include <string> 18 #include <iostream> 19 #include "nncore_utils.h" 20 21 using namespace testing::ext; 22 using namespace OHOS::NeuralNetworkRuntime::Test; 23 class LSTMTest : public testing::Test {}; 24 25 struct LSTMModel1 { 26 const std::vector<int32_t> input_shape = {5, 2, 10}; 27 const std::vector<int32_t> wih_shape = {8, 10}; 28 const std::vector<int32_t> whh_shape = {8, 2}; 29 const std::vector<int32_t> bias_shape = {16}; 30 const std::vector<int32_t> hx_shape = {2, 2}; 31 const std::vector<int32_t> output_shape = {5, 2}; 32 33 float inputValue[5][2][10] = {1}; 34 float wihValue[8][10] = {1}; 35 float whhValue[8][2] = {1}; 36 float biasValue[16] = {1}; 37 float hxValue[2][2] = {1}; 38 float cxValue[2][2] = {1}; 39 40 int64_t inputSizeValue[1] = {10}; 41 int64_t hiddenSizeValue[1] = {2}; 42 int64_t numLayersValue[1] = {1}; 43 44 float outputValue[5][2] = {0}; 45 float hyValue[2][2] = {0}; 46 float cyValue[2][2] = {0}; 47 48 OHNNOperandTest input = {OH_NN_FLOAT32, OH_NN_TENSOR, input_shape, inputValue, 100*sizeof(float)}; 49 OHNNOperandTest wih = {OH_NN_FLOAT32, OH_NN_TENSOR, wih_shape, wihValue, 80*sizeof(float)}; 50 OHNNOperandTest whh = {OH_NN_FLOAT32, OH_NN_TENSOR, whh_shape, whhValue, 16*sizeof(float)}; 51 OHNNOperandTest bias = {OH_NN_FLOAT32, OH_NN_TENSOR, bias_shape, biasValue, 16*sizeof(float)}; 52 OHNNOperandTest hx = {OH_NN_FLOAT32, OH_NN_TENSOR, hx_shape, hxValue, 4*sizeof(float)}; 53 OHNNOperandTest cx = {OH_NN_FLOAT32, OH_NN_TENSOR, hx_shape, cxValue, 4*sizeof(float)}; 54 55 OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, output_shape, outputValue, 10*sizeof(float)}; 56 OHNNOperandTest hy = {OH_NN_FLOAT32, OH_NN_TENSOR, hx_shape, hyValue, 4*sizeof(float)}; 57 OHNNOperandTest cy = {OH_NN_FLOAT32, OH_NN_TENSOR, hx_shape, cyValue, 4*sizeof(float)}; 58 59 OHNNOperandTest inputSize = {OH_NN_INT64, OH_NN_LSTM_INPUT_SIZE, {1}, inputSizeValue, sizeof(int64_t)}; 60 OHNNOperandTest hiddenSize = {OH_NN_INT64, OH_NN_LSTM_HIDDEN_SIZE, {1}, hiddenSizeValue, sizeof(int64_t)}; 61 OHNNOperandTest numLayers = {OH_NN_INT64, OH_NN_LSTM_NUM_LAYERS, {1}, numLayersValue, sizeof(int64_t)}; 62 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_LSTM, 63 .operands = {input, wih, whh, bias, hx, cx, output, hy, 64 cy, inputSize, hiddenSize, numLayers}, 65 .paramIndices = {9, 10, 11}, 66 .inputIndices = {0, 1, 2, 3, 4, 5}, 67 .outputIndices = {6, 7, 8}}; 68 }; 69 70 /** 71 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Build_01 72 * @tc.desc: LSTMModel1模型build测试 73 * @tc.type: FUNC 74 */ 75 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Build_01, Function | MediumTest | Level1) 76 { 77 OH_NNModel *model = OH_NNModel_Construct(); 78 EXPECT_NE(nullptr, model); 79 80 LSTMModel1 lSTMModel; 81 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 82 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 83 84 OH_NNCompilation *compilation = OH_NNCompilation_Construct(model); 85 EXPECT_NE(nullptr, compilation); 86 87 OHNNCompileParam compileParam{ 88 .performanceMode = OH_NN_PERFORMANCE_HIGH, 89 .priority = OH_NN_PRIORITY_HIGH, 90 }; 91 EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam)); 92 93 OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation); 94 EXPECT_NE(nullptr, executor); 95 96 Free(model, compilation, executor); 97 } 98 99 /** 100 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Build_02 101 * @tc.desc: LSTMModel1模型输入Tensor+1进行build测试 102 * @tc.type: FUNC 103 */ 104 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Build_02, Function | MediumTest | Level2) 105 { 106 OH_NNModel *model = OH_NNModel_Construct(); 107 EXPECT_NE(nullptr, model); 108 109 LSTMModel1 lSTMModel; 110 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 111 graphArgs.operands = {lSTMModel.input, lSTMModel.input, lSTMModel.wih, lSTMModel.whh, lSTMModel.bias, lSTMModel.hx, 112 lSTMModel.cx, lSTMModel.output, lSTMModel.hy, lSTMModel.cy, lSTMModel.inputSize, 113 lSTMModel.hiddenSize, lSTMModel.numLayers}; 114 graphArgs.inputIndices = {0, 1, 2, 3, 4, 5, 6}; 115 graphArgs.outputIndices = {7, 8, 9}; 116 graphArgs.paramIndices = {10, 11, 12}; 117 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 118 119 Free(model, nullptr, nullptr); 120 } 121 122 /** 123 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Build_03 124 * @tc.desc: LSTMModel1模型输出Tensor+1进行build测试 125 * @tc.type: FUNC 126 */ 127 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Build_03, Function | MediumTest | Level2) 128 { 129 OH_NNModel *model = OH_NNModel_Construct(); 130 EXPECT_NE(nullptr, model); 131 132 LSTMModel1 lSTMModel; 133 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 134 graphArgs.operands = {lSTMModel.input, lSTMModel.wih, lSTMModel.whh, lSTMModel.bias, lSTMModel.hx, lSTMModel.cx, 135 lSTMModel.output, lSTMModel.output, lSTMModel.hy, lSTMModel.cy, lSTMModel.inputSize, 136 lSTMModel.hiddenSize, lSTMModel.numLayers}; 137 graphArgs.inputIndices = {0, 1, 2, 3, 4, 5}; 138 graphArgs.outputIndices = {6, 7, 8, 9}; 139 graphArgs.paramIndices = {10, 11, 12}; 140 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 141 142 Free(model, nullptr, nullptr); 143 } 144 145 /** 146 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Build_04 147 * @tc.desc: LSTMModel1模型传入非法参数进行build测试 148 * @tc.type: FUNC 149 */ 150 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Build_04, Function | MediumTest | Level2) 151 { 152 OH_NNModel *model = OH_NNModel_Construct(); 153 EXPECT_NE(nullptr, model); 154 155 LSTMModel1 lSTMModel; 156 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 157 158 int8_t activationValue = OH_NN_FUSED_NONE; 159 OHNNOperandTest activation = {OH_NN_INT8, OH_NN_ADD_ACTIVATIONTYPE, {}, &activationValue, sizeof(int8_t)}; 160 graphArgs.operands = {lSTMModel.input, lSTMModel.wih, lSTMModel.whh, lSTMModel.bias, lSTMModel.hx, 161 lSTMModel.cx, lSTMModel.output, lSTMModel.hy, lSTMModel.cy, lSTMModel.inputSize, 162 lSTMModel.hiddenSize, lSTMModel.numLayers, activation}; 163 graphArgs.paramIndices = {9, 10, 11, 12}; 164 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 165 166 Free(model, nullptr, nullptr); 167 } 168 169 /** 170 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_Finish_01 171 * @tc.desc: 模型构图,未添加操作数 172 * @tc.type: FUNC 173 */ 174 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_Finish_01, Function | MediumTest | Level2) 175 { 176 OH_NNModel *model = OH_NNModel_Construct(); 177 EXPECT_NE(nullptr, model); 178 179 OHNNGraphArgs graphArgs; 180 EXPECT_EQ(OH_NN_INVALID_PARAMETER, SingleModelBuildEndStep(model, graphArgs)); 181 182 Free(model, nullptr, nullptr); 183 } 184 185 /** 186 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_Finish_02 187 * @tc.desc: 模型构图,未设置输入输出 188 * @tc.type: FUNC 189 */ 190 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_Finish_02, Function | MediumTest | Level2) 191 { 192 OH_NNModel *model = OH_NNModel_Construct(); 193 EXPECT_NE(nullptr, model); 194 195 LSTMModel1 lSTMModel; 196 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 197 graphArgs.specifyIO = false; 198 EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, BuildSingleOpGraph(model, graphArgs)); 199 200 Free(model, nullptr, nullptr); 201 } 202 203 /** 204 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_Finish_03 205 * @tc.desc: 模型构图,设置输入输出,构图成功 206 * @tc.type: FUNC 207 */ 208 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_Finish_03, Function | MediumTest | Level1) 209 { 210 OH_NNModel *model = OH_NNModel_Construct(); 211 EXPECT_NE(nullptr, model); 212 213 LSTMModel1 lSTMModel; 214 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 215 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 216 217 Free(model, nullptr, nullptr); 218 } 219 220 /** 221 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_SetOperandValue_01 222 * @tc.desc: 设置操作数值,操作数不存在 223 * @tc.type: FUNC 224 */ 225 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_SetOperandValue_01, Function | MediumTest | Level2) 226 { 227 OH_NNModel *model = OH_NNModel_Construct(); 228 EXPECT_NE(nullptr, model); 229 230 LSTMModel1 lSTMModel; 231 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 232 233 NN_TensorDesc* tensorDesc = nullptr; 234 std::vector<NN_TensorDesc*> tensorDescVec; 235 236 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 237 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 238 tensorDesc = createTensorDesc(operandTem.shape.data(), 239 (uint32_t) operandTem.shape.size(), 240 operandTem.dataType, operandTem.format); 241 tensorDescVec.emplace_back(tensorDesc); 242 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 243 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 244 245 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 246 graphArgs.paramIndices.end()) { 247 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData( 248 model, 1000+i, operandTem.data, operandTem.length)); 249 } 250 } 251 252 FreeTensorDescVec(tensorDescVec); 253 Free(model, nullptr, nullptr); 254 } 255 256 /** 257 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_SetOperandValue_02 258 * @tc.desc: 设置操作数值,buufer为nullptr 259 * @tc.type: FUNC 260 */ 261 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_SetOperandValue_02, Function | MediumTest | Level2) 262 { 263 OH_NNModel *model = OH_NNModel_Construct(); 264 EXPECT_NE(nullptr, model); 265 266 LSTMModel1 lSTMModel; 267 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 268 269 NN_TensorDesc* tensorDesc = nullptr; 270 std::vector<NN_TensorDesc*> tensorDescVec; 271 272 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 273 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 274 tensorDesc = createTensorDesc(operandTem.shape.data(), 275 (uint32_t) operandTem.shape.size(), 276 operandTem.dataType, operandTem.format); 277 tensorDescVec.emplace_back(tensorDesc); 278 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 279 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 280 281 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 282 graphArgs.paramIndices.end()) { 283 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, i, nullptr, operandTem.length)); 284 } 285 } 286 287 FreeTensorDescVec(tensorDescVec); 288 Free(model, nullptr, nullptr); 289 } 290 291 /** 292 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_SetOperandValue_03 293 * @tc.desc: 设置操作数值,length为0 294 * @tc.type: FUNC 295 */ 296 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_SetOperandValue_03, Function | MediumTest | Level2) 297 { 298 OH_NNModel *model = OH_NNModel_Construct(); 299 EXPECT_NE(nullptr, model); 300 301 LSTMModel1 lSTMModel; 302 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 303 304 NN_TensorDesc* tensorDesc = nullptr; 305 std::vector<NN_TensorDesc*> tensorDescVec; 306 307 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 308 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 309 tensorDesc = createTensorDesc(operandTem.shape.data(), 310 (uint32_t) operandTem.shape.size(), 311 operandTem.dataType, operandTem.format); 312 tensorDescVec.emplace_back(tensorDesc); 313 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 314 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 315 316 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 317 graphArgs.paramIndices.end()) { 318 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 1000+i, operandTem.data, 0)); 319 } 320 } 321 322 FreeTensorDescVec(tensorDescVec); 323 Free(model, nullptr, nullptr); 324 } 325 326 /** 327 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_01 328 * @tc.desc: 设置输入输出,inputIndices为nullptr 329 * @tc.type: FUNC 330 */ 331 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_01, Function | MediumTest | Level2) 332 { 333 OH_NNModel *model = OH_NNModel_Construct(); 334 EXPECT_NE(nullptr, model); 335 336 LSTMModel1 lSTMModel; 337 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 338 graphArgs.specifyIO = false; 339 graphArgs.build = false; 340 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 341 342 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 343 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 344 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, nullptr, &outputIndices)); 345 346 Free(model, nullptr, nullptr); 347 } 348 349 /** 350 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_02 351 * @tc.desc: 设置输入输出,inputindices中data为nullptr 352 * @tc.type: FUNC 353 */ 354 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_02, Function | MediumTest | Level2) 355 { 356 OH_NNModel *model = OH_NNModel_Construct(); 357 EXPECT_NE(nullptr, model); 358 359 LSTMModel1 lSTMModel; 360 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 361 graphArgs.specifyIO = false; 362 graphArgs.build = false; 363 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 364 365 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 366 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 367 inputIndices.data = nullptr; 368 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 369 370 Free(model, nullptr, nullptr); 371 } 372 373 /** 374 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_03 375 * @tc.desc: 设置输入输出,inputindices中data对应序号不存在 376 * @tc.type: FUNC 377 */ 378 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_03, Function | MediumTest | Level2) 379 { 380 OH_NNModel *model = OH_NNModel_Construct(); 381 EXPECT_NE(nullptr, model); 382 383 LSTMModel1 lSTMModel; 384 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 385 graphArgs.specifyIO = false; 386 graphArgs.build = false; 387 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 388 389 graphArgs.inputIndices = {100000}; 390 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 391 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 392 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 393 394 Free(model, nullptr, nullptr); 395 } 396 397 /** 398 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_04 399 * @tc.desc: 设置输入输出,inputindices中size为0 400 * @tc.type: FUNC 401 */ 402 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_04, Function | MediumTest | Level2) 403 { 404 OH_NNModel *model = OH_NNModel_Construct(); 405 EXPECT_NE(nullptr, model); 406 407 LSTMModel1 lSTMModel; 408 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 409 graphArgs.specifyIO = false; 410 graphArgs.build = false; 411 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 412 413 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 414 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 415 inputIndices.size = 0; 416 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 417 418 Free(model, nullptr, nullptr); 419 } 420 421 /** 422 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_05 423 * @tc.desc: 设置输入输出,outputindices为nullptr 424 * @tc.type: FUNC 425 */ 426 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_05, Function | MediumTest | Level2) 427 { 428 OH_NNModel *model = OH_NNModel_Construct(); 429 EXPECT_NE(nullptr, model); 430 431 LSTMModel1 lSTMModel; 432 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 433 graphArgs.specifyIO = false; 434 graphArgs.build = false; 435 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 436 437 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 438 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 439 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, nullptr)); 440 441 Free(model, nullptr, nullptr); 442 } 443 444 /** 445 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_06 446 * @tc.desc: 设置输入输出,outputindices中data为nullptr 447 * @tc.type: FUNC 448 */ 449 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_06, Function | MediumTest | Level2) 450 { 451 OH_NNModel *model = OH_NNModel_Construct(); 452 EXPECT_NE(nullptr, model); 453 454 LSTMModel1 lSTMModel; 455 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 456 graphArgs.specifyIO = false; 457 graphArgs.build = false; 458 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 459 460 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 461 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 462 outputIndices.data = nullptr; 463 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 464 465 Free(model, nullptr, nullptr); 466 } 467 468 /** 469 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_07 470 * @tc.desc: 设置输入输出,outputindices中data对应序号不存在 471 * @tc.type: FUNC 472 */ 473 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_07, Function | MediumTest | Level2) 474 { 475 OH_NNModel *model = OH_NNModel_Construct(); 476 EXPECT_NE(nullptr, model); 477 478 LSTMModel1 lSTMModel; 479 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 480 graphArgs.specifyIO = false; 481 graphArgs.build = false; 482 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 483 484 graphArgs.outputIndices = {100000}; 485 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 486 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 487 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 488 489 Free(model, nullptr, nullptr); 490 } 491 492 /** 493 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_08 494 * @tc.desc: 设置输入输出,outputindices中size为0 495 * @tc.type: FUNC 496 */ 497 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_SpecifyInputsAndOutputs_08, Function | MediumTest | Level2) 498 { 499 OH_NNModel *model = OH_NNModel_Construct(); 500 EXPECT_NE(nullptr, model); 501 502 LSTMModel1 lSTMModel; 503 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 504 graphArgs.specifyIO = false; 505 graphArgs.build = false; 506 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 507 508 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 509 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 510 outputIndices.size = 0; 511 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 512 513 Free(model, nullptr, nullptr); 514 } 515 516 /** 517 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_01 518 * @tc.desc: 添加算子,paramindices为nullptr 519 * @tc.type: FUNC 520 */ 521 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_01, Function | MediumTest | Level2) 522 { 523 OH_NNModel *model = OH_NNModel_Construct(); 524 EXPECT_NE(nullptr, model); 525 526 LSTMModel1 lSTMModel; 527 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 528 graphArgs.addOperation = false; 529 graphArgs.specifyIO = false; 530 graphArgs.build = false; 531 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 532 533 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 534 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 535 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 536 nullptr, &inputIndices, &outputIndices)); 537 538 Free(model, nullptr, nullptr); 539 } 540 541 /** 542 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_02 543 * @tc.desc: 添加算子,paramindices中data为nullptr 544 * @tc.type: FUNC 545 */ 546 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_02, Function | MediumTest | Level2) 547 { 548 OH_NNModel *model = OH_NNModel_Construct(); 549 EXPECT_NE(nullptr, model); 550 551 LSTMModel1 lSTMModel; 552 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 553 graphArgs.addOperation = false; 554 graphArgs.specifyIO = false; 555 graphArgs.build = false; 556 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 557 558 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 559 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 560 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 561 paramIndices.data = nullptr; 562 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 563 ¶mIndices, &inputIndices, &outputIndices)); 564 565 Free(model, nullptr, nullptr); 566 } 567 568 /** 569 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_03 570 * @tc.desc: 添加算子,paramindices中data对应序号不存在 571 * @tc.type: FUNC 572 */ 573 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_03, Function | MediumTest | Level2) 574 { 575 OH_NNModel *model = OH_NNModel_Construct(); 576 EXPECT_NE(nullptr, model); 577 578 LSTMModel1 lSTMModel; 579 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 580 graphArgs.addOperation = false; 581 graphArgs.specifyIO = false; 582 graphArgs.build = false; 583 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 584 585 graphArgs.paramIndices = {100000}; 586 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 587 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 588 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 589 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 590 ¶mIndices, &inputIndices, &outputIndices)); 591 592 Free(model, nullptr, nullptr); 593 } 594 595 /** 596 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_04 597 * @tc.desc: 添加算子,paramindices中size为0 598 * @tc.type: FUNC 599 */ 600 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_04, Function | MediumTest | Level2) 601 { 602 OH_NNModel *model = OH_NNModel_Construct(); 603 EXPECT_NE(nullptr, model); 604 605 LSTMModel1 lSTMModel; 606 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 607 graphArgs.addOperation = false; 608 graphArgs.specifyIO = false; 609 graphArgs.build = false; 610 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 611 612 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 613 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 614 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 615 paramIndices.size = 0; 616 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 617 ¶mIndices, &inputIndices, &outputIndices)); 618 619 Free(model, nullptr, nullptr); 620 } 621 622 /** 623 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_05 624 * @tc.desc: 添加算子,inputindices为nullptr 625 * @tc.type: FUNC 626 */ 627 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_05, Function | MediumTest | Level2) 628 { 629 OH_NNModel *model = OH_NNModel_Construct(); 630 EXPECT_NE(nullptr, model); 631 632 LSTMModel1 lSTMModel; 633 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 634 graphArgs.addOperation = false; 635 graphArgs.specifyIO = false; 636 graphArgs.build = false; 637 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 638 639 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 640 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 641 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 642 ¶mIndices, nullptr, &outputIndices)); 643 644 Free(model, nullptr, nullptr); 645 } 646 647 /** 648 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_06 649 * @tc.desc: 添加算子,inputindices中data为nullptr 650 * @tc.type: FUNC 651 */ 652 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_06, Function | MediumTest | Level2) 653 { 654 OH_NNModel *model = OH_NNModel_Construct(); 655 EXPECT_NE(nullptr, model); 656 657 LSTMModel1 lSTMModel; 658 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 659 graphArgs.addOperation = false; 660 graphArgs.specifyIO = false; 661 graphArgs.build = false; 662 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 663 664 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 665 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 666 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 667 inputIndices.data = nullptr; 668 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 669 ¶mIndices, &inputIndices, &outputIndices)); 670 671 Free(model, nullptr, nullptr); 672 } 673 674 /** 675 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_07 676 * @tc.desc: 添加算子,inputindices中data对应序号不存在 677 * @tc.type: FUNC 678 */ 679 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_07, Function | MediumTest | Level2) 680 { 681 OH_NNModel *model = OH_NNModel_Construct(); 682 EXPECT_NE(nullptr, model); 683 684 LSTMModel1 lSTMModel; 685 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 686 graphArgs.addOperation = false; 687 graphArgs.specifyIO = false; 688 graphArgs.build = false; 689 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 690 691 graphArgs.inputIndices = {100000}; 692 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 693 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 694 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 695 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 696 ¶mIndices, &inputIndices, &outputIndices)); 697 698 Free(model, nullptr, nullptr); 699 } 700 701 /** 702 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_08 703 * @tc.desc: 添加算子,inputindices中size为0 704 * @tc.type: FUNC 705 */ 706 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_08, Function | MediumTest | Level2) 707 { 708 OH_NNModel *model = OH_NNModel_Construct(); 709 EXPECT_NE(nullptr, model); 710 711 LSTMModel1 lSTMModel; 712 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 713 graphArgs.addOperation = false; 714 graphArgs.specifyIO = false; 715 graphArgs.build = false; 716 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 717 718 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 719 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 720 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 721 inputIndices.size = 0; 722 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 723 ¶mIndices, &inputIndices, &outputIndices)); 724 725 Free(model, nullptr, nullptr); 726 } 727 728 /** 729 * @tc.number : SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_09 730 * @tc.desc: 添加算子,outputindices为nullptr 731 * @tc.type: FUNC 732 */ 733 HWTEST_F(LSTMTest, SUB_AI_NNRt_Func_North_LSTM_Model_AddOperation_09, Function | MediumTest | Level2) 734 { 735 OH_NNModel *model = OH_NNModel_Construct(); 736 EXPECT_NE(nullptr, model); 737 738 LSTMModel1 lSTMModel; 739 OHNNGraphArgs graphArgs = lSTMModel.graphArgs; 740 graphArgs.addOperation = false; 741 graphArgs.specifyIO = false; 742 graphArgs.build = false; 743 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 744 745 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 746 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 747 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(nullptr, graphArgs.operationType, 748 ¶mIndices, &inputIndices, nullptr)); 749 750 Free(model, nullptr, nullptr); 751 }