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 ScatterNdTest : public testing::Test {}; 24 25 struct ScatterNdModel1 { 26 const std::vector<int32_t> indices_shape = {2, 1}; 27 const std::vector<int32_t> updates_shape = {2}; 28 const std::vector<int32_t> shape_shape = {1}; 29 const std::vector<int32_t> output_shape = {3}; 30 float indicesValue[2][1] = {{0}, {2}}; 31 float updatesValue[2] = {1, 3}; 32 float shapeValue[1] = {3}; 33 float outputValue[3] = {0}; 34 35 OHNNOperandTest indices = {OH_NN_FLOAT32, OH_NN_TENSOR, indices_shape, indicesValue, 4*sizeof(float)}; 36 OHNNOperandTest updates = {OH_NN_FLOAT32, OH_NN_TENSOR, updates_shape, updatesValue, 2*sizeof(float)}; 37 OHNNOperandTest shape = {OH_NN_FLOAT32, OH_NN_TENSOR, shape_shape, shapeValue, sizeof(float)}; 38 OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, output_shape, outputValue, 3*sizeof(float)}; 39 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SCATTER_ND, 40 .operands = {indices, updates, shape, output}, 41 .paramIndices = {}, 42 .inputIndices = {0, 1, 2}, 43 .outputIndices = {3}}; 44 }; 45 46 struct ScatterNdModel2 { 47 const std::vector<int32_t> indices_shape = {2, 2}; 48 const std::vector<int32_t> updates_shape = {2}; 49 const std::vector<int32_t> shape_shape = {2}; 50 const std::vector<int32_t> output_shape = {3}; 51 float indicesValue[2][2] = {{1, 0}, {0, 1}}; 52 float updatesValue[2] = {4, 5}; 53 float shapeValue[2] = {2, 2}; 54 float outputValue[2][2] = {0}; 55 56 OHNNOperandTest indices = {OH_NN_FLOAT32, OH_NN_TENSOR, indices_shape, indicesValue, 4*sizeof(float)}; 57 OHNNOperandTest updates = {OH_NN_FLOAT32, OH_NN_TENSOR, updates_shape, updatesValue, 2*sizeof(float)}; 58 OHNNOperandTest shape = {OH_NN_FLOAT32, OH_NN_TENSOR, shape_shape, shapeValue, 2*sizeof(float)}; 59 OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, output_shape, outputValue, 4*sizeof(float)}; 60 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SCATTER_ND, 61 .operands = {indices, updates, shape, output}, 62 .paramIndices = {}, 63 .inputIndices = {0, 1, 2}, 64 .outputIndices = {3}}; 65 }; 66 67 struct ScatterNdModel3 { 68 const std::vector<int32_t> indices_shape = {2, 2}; 69 const std::vector<int32_t> updates_shape = {2, 2}; 70 const std::vector<int32_t> shape_shape = {2}; 71 const std::vector<int32_t> output_shape = {2, 2}; 72 float indicesValue[2][2] = {{0, 1}, {1, 0}}; 73 float updatesValue[2][2] = {{6, 7}, {8, 9}}; 74 float shapeValue[2] = {2, 2}; 75 float outputValue[2][2] = {0}; 76 77 OHNNOperandTest indices = {OH_NN_FLOAT32, OH_NN_TENSOR, indices_shape, indicesValue, 4*sizeof(float)}; 78 OHNNOperandTest updates = {OH_NN_FLOAT32, OH_NN_TENSOR, updates_shape, updatesValue, 4*sizeof(float)}; 79 OHNNOperandTest shape = {OH_NN_FLOAT32, OH_NN_TENSOR, shape_shape, shapeValue, 2*sizeof(float)}; 80 OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, output_shape, outputValue, 4*sizeof(float)}; 81 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SCATTER_ND, 82 .operands = {indices, updates, shape, output}, 83 .paramIndices = {}, 84 .inputIndices = {0, 1, 2}, 85 .outputIndices = {3}}; 86 }; 87 88 struct ScatterNdModel4 { 89 const std::vector<int32_t> indices_shape = {2, 3}; 90 const std::vector<int32_t> updates_shape = {2}; 91 const std::vector<int32_t> shape_shape = {3}; 92 const std::vector<int32_t> output_shape = {2, 2, 2}; 93 float indicesValue[2][3] = {{0, 0, 1}, {1, 1, 0}}; 94 float updatesValue[2] = {10, 11}; 95 float shapeValue[3] = {2, 2, 2}; 96 float outputValue[2][2][2] = {0}; 97 98 OHNNOperandTest indices = {OH_NN_FLOAT32, OH_NN_TENSOR, indices_shape, indicesValue, 6*sizeof(float)}; 99 OHNNOperandTest updates = {OH_NN_FLOAT32, OH_NN_TENSOR, updates_shape, updatesValue, 2*sizeof(float)}; 100 OHNNOperandTest shape = {OH_NN_FLOAT32, OH_NN_TENSOR, shape_shape, shapeValue, 3*sizeof(float)}; 101 OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, output_shape, outputValue, 8*sizeof(float)}; 102 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SCATTER_ND, 103 .operands = {indices, updates, shape, output}, 104 .paramIndices = {}, 105 .inputIndices = {0, 1, 2}, 106 .outputIndices = {3}}; 107 }; 108 109 /** 110 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Build_01 111 * @tc.desc: ScatterNdModel1模型build测试 112 * @tc.type: FUNC 113 */ 114 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Build_01, Function | MediumTest | Level1) 115 { 116 OH_NNModel *model = OH_NNModel_Construct(); 117 EXPECT_NE(nullptr, model); 118 119 ScatterNdModel1 scatterNdModel; 120 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 121 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 122 123 OH_NNCompilation *compilation = OH_NNCompilation_Construct(model); 124 EXPECT_NE(nullptr, compilation); 125 126 OHNNCompileParam compileParam{ 127 .performanceMode = OH_NN_PERFORMANCE_HIGH, 128 .priority = OH_NN_PRIORITY_HIGH, 129 }; 130 EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam)); 131 132 OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation); 133 EXPECT_NE(nullptr, executor); 134 135 Free(model, compilation, executor); 136 } 137 138 /** 139 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Build_02 140 * @tc.desc: ScatterNdModel2模型build测试 141 * @tc.type: FUNC 142 */ 143 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Build_02, Function | MediumTest | Level1) 144 { 145 OH_NNModel *model = OH_NNModel_Construct(); 146 EXPECT_NE(nullptr, model); 147 148 ScatterNdModel2 scatterNdModel; 149 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 150 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 151 152 OH_NNCompilation *compilation = OH_NNCompilation_Construct(model); 153 EXPECT_NE(nullptr, compilation); 154 155 OHNNCompileParam compileParam{ 156 .performanceMode = OH_NN_PERFORMANCE_HIGH, 157 .priority = OH_NN_PRIORITY_HIGH, 158 }; 159 EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam)); 160 161 OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation); 162 EXPECT_NE(nullptr, executor); 163 164 Free(model, compilation, executor); 165 } 166 167 /** 168 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Build_03 169 * @tc.desc: ScatterNdModel3模型build测试 170 * @tc.type: FUNC 171 */ 172 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Build_03, Function | MediumTest | Level1) 173 { 174 OH_NNModel *model = OH_NNModel_Construct(); 175 EXPECT_NE(nullptr, model); 176 177 ScatterNdModel3 scatterNdModel; 178 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 179 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 180 181 OH_NNCompilation *compilation = OH_NNCompilation_Construct(model); 182 EXPECT_NE(nullptr, compilation); 183 184 OHNNCompileParam compileParam{ 185 .performanceMode = OH_NN_PERFORMANCE_HIGH, 186 .priority = OH_NN_PRIORITY_HIGH, 187 }; 188 EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam)); 189 190 OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation); 191 EXPECT_NE(nullptr, executor); 192 193 Free(model, compilation, executor); 194 } 195 196 /** 197 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Build_04 198 * @tc.desc: ScatterNdModel4模型build测试 199 * @tc.type: FUNC 200 */ 201 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Build_04, Function | MediumTest | Level1) 202 { 203 OH_NNModel *model = OH_NNModel_Construct(); 204 EXPECT_NE(nullptr, model); 205 206 ScatterNdModel4 scatterNdModel; 207 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 208 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 209 210 OH_NNCompilation *compilation = OH_NNCompilation_Construct(model); 211 EXPECT_NE(nullptr, compilation); 212 213 OHNNCompileParam compileParam{ 214 .performanceMode = OH_NN_PERFORMANCE_HIGH, 215 .priority = OH_NN_PRIORITY_HIGH, 216 }; 217 EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam)); 218 219 OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation); 220 EXPECT_NE(nullptr, executor); 221 222 Free(model, compilation, executor); 223 } 224 225 /** 226 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Build_05 227 * @tc.desc: ScatterNdModel1模型输入Tensor+1进行build测试 228 * @tc.type: FUNC 229 */ 230 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Build_05, Function | MediumTest | Level2) 231 { 232 OH_NNModel *model = OH_NNModel_Construct(); 233 EXPECT_NE(nullptr, model); 234 235 ScatterNdModel1 scatterNdModel; 236 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 237 graphArgs.operands = {scatterNdModel.indices, scatterNdModel.indices, scatterNdModel.updates, 238 scatterNdModel.shape, scatterNdModel.output}; 239 graphArgs.inputIndices = {0, 1, 2, 3}; 240 graphArgs.outputIndices = {4}; 241 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 242 243 Free(model, nullptr, nullptr); 244 } 245 246 /** 247 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Build_06 248 * @tc.desc: ScatterNdModel1模型输出Tensor+1进行build测试 249 * @tc.type: FUNC 250 */ 251 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Build_06, Function | MediumTest | Level2) 252 { 253 OH_NNModel *model = OH_NNModel_Construct(); 254 EXPECT_NE(nullptr, model); 255 256 ScatterNdModel1 scatterNdModel; 257 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 258 graphArgs.operands = {scatterNdModel.indices, scatterNdModel.updates, scatterNdModel.shape, 259 scatterNdModel.output, scatterNdModel.output}; 260 graphArgs.inputIndices = {0, 1, 2}; 261 graphArgs.outputIndices = {3, 4}; 262 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 263 264 Free(model, nullptr, nullptr); 265 } 266 267 /** 268 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Build_07 269 * @tc.desc: ScatterNdModel1模型传入非法参数进行build测试 270 * @tc.type: FUNC 271 */ 272 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Build_07, Function | MediumTest | Level2) 273 { 274 OH_NNModel *model = OH_NNModel_Construct(); 275 EXPECT_NE(nullptr, model); 276 277 ScatterNdModel1 scatterNdModel; 278 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 279 280 int8_t activationValue = OH_NN_FUSED_NONE; 281 OHNNOperandTest activation = {OH_NN_INT8, OH_NN_ADD_ACTIVATIONTYPE, {}, &activationValue, sizeof(int8_t)}; 282 graphArgs.operands = {scatterNdModel.indices, scatterNdModel.updates, scatterNdModel.shape, 283 scatterNdModel.output, activation}; 284 graphArgs.paramIndices = {4}; 285 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 286 287 Free(model, nullptr, nullptr); 288 } 289 290 /** 291 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_Finish_01 292 * @tc.desc: 模型构图,未添加操作数 293 * @tc.type: FUNC 294 */ 295 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_Finish_01, Function | MediumTest | Level2) 296 { 297 OH_NNModel *model = OH_NNModel_Construct(); 298 EXPECT_NE(nullptr, model); 299 300 OHNNGraphArgs graphArgs; 301 EXPECT_EQ(OH_NN_INVALID_PARAMETER, SingleModelBuildEndStep(model, graphArgs)); 302 303 Free(model, nullptr, nullptr); 304 } 305 306 /** 307 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_Finish_02 308 * @tc.desc: 模型构图,未设置输入输出 309 * @tc.type: FUNC 310 */ 311 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_Finish_02, Function | MediumTest | Level2) 312 { 313 OH_NNModel *model = OH_NNModel_Construct(); 314 EXPECT_NE(nullptr, model); 315 316 ScatterNdModel1 scatterNdModel; 317 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 318 graphArgs.specifyIO = false; 319 EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, BuildSingleOpGraph(model, graphArgs)); 320 321 Free(model, nullptr, nullptr); 322 } 323 324 /** 325 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_Finish_03 326 * @tc.desc: 模型构图,设置输入输出,构图成功 327 * @tc.type: FUNC 328 */ 329 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_Finish_03, Function | MediumTest | Level1) 330 { 331 OH_NNModel *model = OH_NNModel_Construct(); 332 EXPECT_NE(nullptr, model); 333 334 ScatterNdModel1 scatterNdModel; 335 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 336 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 337 338 Free(model, nullptr, nullptr); 339 } 340 341 /** 342 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_SetOperandValue_01 343 * @tc.desc: 设置操作数值,操作数不存在 344 * @tc.type: FUNC 345 */ 346 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_SetOperandValue_01, Function | MediumTest | Level2) 347 { 348 OH_NNModel *model = OH_NNModel_Construct(); 349 EXPECT_NE(nullptr, model); 350 351 ScatterNdModel1 scatterNdModel; 352 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 353 354 NN_TensorDesc* tensorDesc = nullptr; 355 std::vector<NN_TensorDesc*> tensorDescVec; 356 357 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 358 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 359 tensorDesc = createTensorDesc(operandTem.shape.data(), 360 (uint32_t) operandTem.shape.size(), 361 operandTem.dataType, operandTem.format); 362 tensorDescVec.emplace_back(tensorDesc); 363 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 364 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 365 366 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 367 graphArgs.paramIndices.end()) { 368 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData( 369 model, 1000+i, operandTem.data, operandTem.length)); 370 } 371 } 372 373 FreeTensorDescVec(tensorDescVec); 374 Free(model, nullptr, nullptr); 375 } 376 377 /** 378 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_SetOperandValue_02 379 * @tc.desc: 设置操作数值,buufer为nullptr 380 * @tc.type: FUNC 381 */ 382 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_SetOperandValue_02, Function | MediumTest | Level2) 383 { 384 OH_NNModel *model = OH_NNModel_Construct(); 385 EXPECT_NE(nullptr, model); 386 387 ScatterNdModel1 scatterNdModel; 388 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 389 390 NN_TensorDesc* tensorDesc = nullptr; 391 std::vector<NN_TensorDesc*> tensorDescVec; 392 393 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 394 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 395 tensorDesc = createTensorDesc(operandTem.shape.data(), 396 (uint32_t) operandTem.shape.size(), 397 operandTem.dataType, operandTem.format); 398 tensorDescVec.emplace_back(tensorDesc); 399 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 400 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 401 402 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 403 graphArgs.paramIndices.end()) { 404 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, i, nullptr, operandTem.length)); 405 } 406 } 407 408 FreeTensorDescVec(tensorDescVec); 409 Free(model, nullptr, nullptr); 410 } 411 412 /** 413 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_SetOperandValue_03 414 * @tc.desc: 设置操作数值,length为0 415 * @tc.type: FUNC 416 */ 417 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_SetOperandValue_03, Function | MediumTest | Level2) 418 { 419 OH_NNModel *model = OH_NNModel_Construct(); 420 EXPECT_NE(nullptr, model); 421 422 ScatterNdModel1 scatterNdModel; 423 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 424 425 NN_TensorDesc* tensorDesc = nullptr; 426 std::vector<NN_TensorDesc*> tensorDescVec; 427 428 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 429 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 430 tensorDesc = createTensorDesc(operandTem.shape.data(), 431 (uint32_t) operandTem.shape.size(), 432 operandTem.dataType, operandTem.format); 433 tensorDescVec.emplace_back(tensorDesc); 434 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 435 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 436 437 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 438 graphArgs.paramIndices.end()) { 439 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 1000+i, operandTem.data, 0)); 440 } 441 } 442 443 FreeTensorDescVec(tensorDescVec); 444 Free(model, nullptr, nullptr); 445 } 446 447 /** 448 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_01 449 * @tc.desc: 设置输入输出,inputIndices为nullptr 450 * @tc.type: FUNC 451 */ 452 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_01, 453 Function | MediumTest | Level2) 454 { 455 OH_NNModel *model = OH_NNModel_Construct(); 456 EXPECT_NE(nullptr, model); 457 458 ScatterNdModel1 scatterNdModel; 459 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 460 graphArgs.specifyIO = false; 461 graphArgs.build = false; 462 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 463 464 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 465 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 466 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, nullptr, &outputIndices)); 467 468 Free(model, nullptr, nullptr); 469 } 470 471 /** 472 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_02 473 * @tc.desc: 设置输入输出,inputindices中data为nullptr 474 * @tc.type: FUNC 475 */ 476 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_02, 477 Function | MediumTest | Level2) 478 { 479 OH_NNModel *model = OH_NNModel_Construct(); 480 EXPECT_NE(nullptr, model); 481 482 ScatterNdModel1 scatterNdModel; 483 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 484 graphArgs.specifyIO = false; 485 graphArgs.build = false; 486 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 487 488 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 489 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 490 inputIndices.data = nullptr; 491 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 492 493 Free(model, nullptr, nullptr); 494 } 495 496 /** 497 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_03 498 * @tc.desc: 设置输入输出,inputindices中data对应序号不存在 499 * @tc.type: FUNC 500 */ 501 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_03, 502 Function | MediumTest | Level2) 503 { 504 OH_NNModel *model = OH_NNModel_Construct(); 505 EXPECT_NE(nullptr, model); 506 507 ScatterNdModel1 scatterNdModel; 508 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 509 graphArgs.specifyIO = false; 510 graphArgs.build = false; 511 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 512 513 graphArgs.inputIndices = {100000}; 514 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 515 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 516 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 517 518 Free(model, nullptr, nullptr); 519 } 520 521 /** 522 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_04 523 * @tc.desc: 设置输入输出,inputindices中size为0 524 * @tc.type: FUNC 525 */ 526 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_04, 527 Function | MediumTest | Level2) 528 { 529 OH_NNModel *model = OH_NNModel_Construct(); 530 EXPECT_NE(nullptr, model); 531 532 ScatterNdModel1 scatterNdModel; 533 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 534 graphArgs.specifyIO = false; 535 graphArgs.build = false; 536 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 537 538 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 539 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 540 inputIndices.size = 0; 541 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 542 543 Free(model, nullptr, nullptr); 544 } 545 546 /** 547 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_05 548 * @tc.desc: 设置输入输出,outputindices为nullptr 549 * @tc.type: FUNC 550 */ 551 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_05, 552 Function | MediumTest | Level2) 553 { 554 OH_NNModel *model = OH_NNModel_Construct(); 555 EXPECT_NE(nullptr, model); 556 557 ScatterNdModel1 scatterNdModel; 558 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 559 graphArgs.specifyIO = false; 560 graphArgs.build = false; 561 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 562 563 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 564 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 565 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, nullptr)); 566 567 Free(model, nullptr, nullptr); 568 } 569 570 /** 571 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_06 572 * @tc.desc: 设置输入输出,outputindices中data为nullptr 573 * @tc.type: FUNC 574 */ 575 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_06, 576 Function | MediumTest | Level2) 577 { 578 OH_NNModel *model = OH_NNModel_Construct(); 579 EXPECT_NE(nullptr, model); 580 581 ScatterNdModel1 scatterNdModel; 582 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 583 graphArgs.specifyIO = false; 584 graphArgs.build = false; 585 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 586 587 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 588 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 589 outputIndices.data = nullptr; 590 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 591 592 Free(model, nullptr, nullptr); 593 } 594 595 /** 596 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_07 597 * @tc.desc: 设置输入输出,outputindices中data对应序号不存在 598 * @tc.type: FUNC 599 */ 600 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_07, 601 Function | MediumTest | Level2) 602 { 603 OH_NNModel *model = OH_NNModel_Construct(); 604 EXPECT_NE(nullptr, model); 605 606 ScatterNdModel1 scatterNdModel; 607 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 608 graphArgs.specifyIO = false; 609 graphArgs.build = false; 610 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 611 612 graphArgs.outputIndices = {100000}; 613 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 614 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 615 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 616 617 Free(model, nullptr, nullptr); 618 } 619 620 /** 621 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_08 622 * @tc.desc: 设置输入输出,outputindices中size为0 623 * @tc.type: FUNC 624 */ 625 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_SpecifyInputsAndOutputs_08, 626 Function | MediumTest | Level2) 627 { 628 OH_NNModel *model = OH_NNModel_Construct(); 629 EXPECT_NE(nullptr, model); 630 631 ScatterNdModel1 scatterNdModel; 632 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 633 graphArgs.specifyIO = false; 634 graphArgs.build = false; 635 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 636 637 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 638 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 639 outputIndices.size = 0; 640 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 641 642 Free(model, nullptr, nullptr); 643 } 644 645 /** 646 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_01 647 * @tc.desc: 添加算子,paramindices为nullptr 648 * @tc.type: FUNC 649 */ 650 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_01, Function | MediumTest | Level2) 651 { 652 OH_NNModel *model = OH_NNModel_Construct(); 653 EXPECT_NE(nullptr, model); 654 655 ScatterNdModel1 scatterNdModel; 656 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 657 graphArgs.addOperation = false; 658 graphArgs.specifyIO = false; 659 graphArgs.build = false; 660 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 661 662 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 663 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 664 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 665 nullptr, &inputIndices, &outputIndices)); 666 667 Free(model, nullptr, nullptr); 668 } 669 670 /** 671 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_02 672 * @tc.desc: 添加算子,paramindices中data为nullptr 673 * @tc.type: FUNC 674 */ 675 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_02, Function | MediumTest | Level2) 676 { 677 OH_NNModel *model = OH_NNModel_Construct(); 678 EXPECT_NE(nullptr, model); 679 680 ScatterNdModel1 scatterNdModel; 681 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 682 graphArgs.addOperation = false; 683 graphArgs.specifyIO = false; 684 graphArgs.build = false; 685 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 686 687 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 688 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 689 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 690 paramIndices.data = nullptr; 691 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType, 692 ¶mIndices, &inputIndices, &outputIndices)); 693 694 Free(model, nullptr, nullptr); 695 } 696 697 /** 698 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_03 699 * @tc.desc: 添加算子,paramindices中data对应序号不存在 700 * @tc.type: FUNC 701 */ 702 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_03, Function | MediumTest | Level2) 703 { 704 OH_NNModel *model = OH_NNModel_Construct(); 705 EXPECT_NE(nullptr, model); 706 707 ScatterNdModel1 scatterNdModel; 708 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 709 graphArgs.addOperation = false; 710 graphArgs.specifyIO = false; 711 graphArgs.build = false; 712 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 713 714 graphArgs.paramIndices = {100000}; 715 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 716 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 717 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 718 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 719 ¶mIndices, &inputIndices, &outputIndices)); 720 721 Free(model, nullptr, nullptr); 722 } 723 724 /** 725 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_04 726 * @tc.desc: 添加算子,paramindices中size为0 727 * @tc.type: FUNC 728 */ 729 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_04, Function | MediumTest | Level2) 730 { 731 OH_NNModel *model = OH_NNModel_Construct(); 732 EXPECT_NE(nullptr, model); 733 734 ScatterNdModel1 scatterNdModel; 735 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 736 graphArgs.addOperation = false; 737 graphArgs.specifyIO = false; 738 graphArgs.build = false; 739 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 740 741 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 742 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 743 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 744 paramIndices.size = 0; 745 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType, 746 ¶mIndices, &inputIndices, &outputIndices)); 747 748 Free(model, nullptr, nullptr); 749 } 750 751 /** 752 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_05 753 * @tc.desc: 添加算子,inputindices为nullptr 754 * @tc.type: FUNC 755 */ 756 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_05, Function | MediumTest | Level2) 757 { 758 OH_NNModel *model = OH_NNModel_Construct(); 759 EXPECT_NE(nullptr, model); 760 761 ScatterNdModel1 scatterNdModel; 762 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 763 graphArgs.addOperation = false; 764 graphArgs.specifyIO = false; 765 graphArgs.build = false; 766 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 767 768 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 769 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 770 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 771 ¶mIndices, nullptr, &outputIndices)); 772 773 Free(model, nullptr, nullptr); 774 } 775 776 /** 777 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_06 778 * @tc.desc: 添加算子,inputindices中data为nullptr 779 * @tc.type: FUNC 780 */ 781 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_06, Function | MediumTest | Level2) 782 { 783 OH_NNModel *model = OH_NNModel_Construct(); 784 EXPECT_NE(nullptr, model); 785 786 ScatterNdModel1 scatterNdModel; 787 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 788 graphArgs.addOperation = false; 789 graphArgs.specifyIO = false; 790 graphArgs.build = false; 791 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 792 793 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 794 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 795 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 796 inputIndices.data = nullptr; 797 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 798 ¶mIndices, &inputIndices, &outputIndices)); 799 800 Free(model, nullptr, nullptr); 801 } 802 803 /** 804 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_07 805 * @tc.desc: 添加算子,inputindices中data对应序号不存在 806 * @tc.type: FUNC 807 */ 808 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_07, Function | MediumTest | Level2) 809 { 810 OH_NNModel *model = OH_NNModel_Construct(); 811 EXPECT_NE(nullptr, model); 812 813 ScatterNdModel1 scatterNdModel; 814 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 815 graphArgs.addOperation = false; 816 graphArgs.specifyIO = false; 817 graphArgs.build = false; 818 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 819 820 graphArgs.inputIndices = {100000}; 821 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 822 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 823 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 824 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 825 ¶mIndices, &inputIndices, &outputIndices)); 826 827 Free(model, nullptr, nullptr); 828 } 829 830 /** 831 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_08 832 * @tc.desc: 添加算子,inputindices中size为0 833 * @tc.type: FUNC 834 */ 835 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_08, Function | MediumTest | Level2) 836 { 837 OH_NNModel *model = OH_NNModel_Construct(); 838 EXPECT_NE(nullptr, model); 839 840 ScatterNdModel1 scatterNdModel; 841 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 842 graphArgs.addOperation = false; 843 graphArgs.specifyIO = false; 844 graphArgs.build = false; 845 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 846 847 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 848 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 849 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 850 inputIndices.size = 0; 851 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 852 ¶mIndices, &inputIndices, &outputIndices)); 853 854 Free(model, nullptr, nullptr); 855 } 856 857 /** 858 * @tc.number : SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_09 859 * @tc.desc: 添加算子,outputindices为nullptr 860 * @tc.type: FUNC 861 */ 862 HWTEST_F(ScatterNdTest, SUB_AI_NNRt_Func_North_ScatterNd_Model_AddOperation_09, Function | MediumTest | Level2) 863 { 864 OH_NNModel *model = OH_NNModel_Construct(); 865 EXPECT_NE(nullptr, model); 866 867 ScatterNdModel1 scatterNdModel; 868 OHNNGraphArgs graphArgs = scatterNdModel.graphArgs; 869 graphArgs.addOperation = false; 870 graphArgs.specifyIO = false; 871 graphArgs.build = false; 872 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 873 874 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 875 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 876 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(nullptr, graphArgs.operationType, 877 ¶mIndices, &inputIndices, nullptr)); 878 879 Free(model, nullptr, nullptr); 880 }