• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "executor_test.h"
17 
18 #include "common/scoped_trace.h"
19 #include "frameworks/native/compilation.h"
20 #include "frameworks/native/inner_model.h"
21 #include "test/unittest/common/v2_0/mock_idevice.h"
22 
23 using namespace OHOS::NeuralNetworkRuntime;
24 using namespace OHOS::NeuralNetworkRuntime::Ops;
25 using namespace OHOS::HDI::Nnrt::V2_0;
26 using namespace OHOS::HiviewDFX;
27 
28 namespace OHOS {
29 namespace NeuralNetworkRuntime {
30 namespace UnitTest {
31 using NNTensorPtr = std::shared_ptr<NNTensor>;
32 
BuildLiteGraph(const std::vector<int32_t> dim,const std::vector<int32_t> dimOut)33 MSLITE::LiteGraph* ExecutorTest::BuildLiteGraph(const std::vector<int32_t> dim, const std::vector<int32_t> dimOut)
34 {
35     MSLITE::LiteGraph* liteGraph = new (std::nothrow) MSLITE::LiteGraph();
36     if (liteGraph == nullptr) {
37         LOGE("liteGraph build failed");
38         return nullptr;
39     }
40     liteGraph->name_ = "testGraph";
41     liteGraph->input_indices_.emplace_back(0);
42     liteGraph->output_indices_.emplace_back(1);
43     const std::vector<MSLITE::QuantParam> quant_params;
44 
45     for (size_t indexInput = 0; indexInput < liteGraph->input_indices_.size(); ++indexInput) {
46         const std::vector<uint8_t> data(36, 1);
47         void* liteGraphTensor1 = MSLITE::MindIR_Tensor_Create(liteGraph->name_,
48             MSLITE::DATA_TYPE_FLOAT32, dim, MSLITE::FORMAT_NCHW, data, quant_params);
49         liteGraph->all_tensors_.emplace_back(liteGraphTensor1);
50     }
51 
52     for (size_t indexOutput = 0; indexOutput < liteGraph->output_indices_.size(); ++indexOutput) {
53         const std::vector<uint8_t> dataOut(36, 1);
54         void* liteGraphTensor2 = MSLITE::MindIR_Tensor_Create(liteGraph->name_,
55             MSLITE::DATA_TYPE_FLOAT32, dimOut, MSLITE::FORMAT_NCHW, dataOut, quant_params);
56         liteGraph->all_tensors_.emplace_back(liteGraphTensor2);
57     }
58 
59     return liteGraph;
60 }
61 
SetTensor(OH_NN_DataType dataType,uint32_t dimensionCount,const int32_t * dimensions,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)62 OH_NN_Tensor ExecutorTest::SetTensor(OH_NN_DataType dataType, uint32_t dimensionCount, const int32_t *dimensions,
63     const OH_NN_QuantParam *quantParam, OH_NN_TensorType type)
64 {
65     OH_NN_Tensor tensor;
66     tensor.dataType = dataType;
67     tensor.dimensionCount = dimensionCount;
68     tensor.dimensions = dimensions;
69     tensor.quantParam = quantParam;
70     tensor.type = type;
71 
72     return tensor;
73 }
74 
75 /*
76  * @tc.name: executor_set_input_001
77  * @tc.desc: Verify that the SetInput function returns a successful message.
78  * @tc.type: FUNC
79  */
80 HWTEST_F(ExecutorTest, executor_set_input_001, testing::ext::TestSize.Level0)
81 {
82     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
83     InnerModel innerModel;
84     innerModel.BuildFromLiteGraph(liteGraphTest);
85     Compilation compilation(&innerModel);
86     Executor executorTest(&compilation);
87 
88     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
89     void* buffer = m_dataArry;
90     size_t length = 9 * sizeof(float);
91 
92     OH_NN_ReturnCode ret = executorTest.SetInput(m_index, tensor, buffer, length);
93     EXPECT_EQ(OH_NN_SUCCESS, ret);
94 }
95 
96 /*
97  * @tc.name: executor_set_input_002
98  * @tc.desc: Verify that the SetInput function returns a failed message with out-of-range index.
99  * @tc.type: FUNC
100  */
101 HWTEST_F(ExecutorTest, executor_set_input_002, testing::ext::TestSize.Level0)
102 {
103     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
104     InnerModel innerModel;
105     innerModel.BuildFromLiteGraph(liteGraphTest);
106     Compilation compilation(&innerModel);
107     Executor executorTest(&compilation);
108 
109     m_index = 6;
110     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
111     size_t length = 9 * sizeof(float);
112     void* buffer = m_dataArry;
113 
114     OH_NN_ReturnCode ret = executorTest.SetInput(m_index, tensor, buffer, length);
115     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
116 }
117 
118 /*
119  * @tc.name: executor_set_input_003
120  * @tc.desc: Verify that the SetInput function returns a failed message with dynamic shape.
121  * @tc.type: FUNC
122  */
123 HWTEST_F(ExecutorTest, executor_set_input_003, testing::ext::TestSize.Level0)
124 {
125     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
126     InnerModel innerModel;
127     innerModel.BuildFromLiteGraph(liteGraphTest);
128     Compilation compilation(&innerModel);
129     Executor executorTest(&compilation);
130 
131     const int dim = -1;
132     m_dimensionCount = 1;
133     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, &dim, nullptr, OH_NN_TENSOR);
134     size_t length = 1 * sizeof(float);
135     float data = 0;
136     void* buffer = &data;
137 
138     OH_NN_ReturnCode ret = executorTest.SetInput(m_index, tensor, buffer, length);
139     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
140 }
141 
142 /*
143  * @tc.name: executor_set_input_004
144  * @tc.desc: Verify that the SetInput function returns a failed message with invalid tensor's dataType.
145  * @tc.type: FUNC
146  */
147 HWTEST_F(ExecutorTest, executor_set_input_004, testing::ext::TestSize.Level0)
148 {
149     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
150     InnerModel innerModel;
151     innerModel.BuildFromLiteGraph(liteGraphTest);
152     Compilation compilation(&innerModel);
153     Executor executorTest(&compilation);
154 
155     OH_NN_Tensor tensor = SetTensor(OH_NN_INT64, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
156     void* buffer = m_dataArry;
157     size_t length = 9 * sizeof(float);
158 
159     OH_NN_ReturnCode ret = executorTest.SetInput(m_index, tensor, buffer, length);
160     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
161 }
162 
163 /*
164  * @tc.name: executor_set_input_005
165  * @tc.desc: Verify that the SetInput function returns a failed message with invalid length.
166  * @tc.type: FUNC
167  */
168 HWTEST_F(ExecutorTest, executor_set_input_005, testing::ext::TestSize.Level0)
169 {
170     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
171     InnerModel innerModel;
172     innerModel.BuildFromLiteGraph(liteGraphTest);
173     Compilation compilation(&innerModel);
174     Executor executorTest(&compilation);
175 
176 
177     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
178     size_t length = 1 * sizeof(float);
179     void* buffer = m_dataArry;
180 
181     OH_NN_ReturnCode ret = executorTest.SetInput(m_index, tensor, buffer, length);
182     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
183 }
184 
185 /*
186  * @tc.name: executor_set_input_006
187  * @tc.desc: Verify that the SetInput function returns a failed message with allocating buffer is unsuccessfully.
188  * @tc.type: FUNC
189  */
190 HWTEST_F(ExecutorTest, executor_set_input_006, testing::ext::TestSize.Level0)
191 {
192     HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode = OH_NN_INVALID_PARAMETER;
193     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
194     InnerModel innerModel;
195     innerModel.BuildFromLiteGraph(liteGraphTest);
196     Compilation compilation(&innerModel);
197     Executor executorTest(&compilation);
198 
199     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
200     void* buffer = m_dataArry;
201     size_t length = 9 * sizeof(float);
202 
203     OH_NN_ReturnCode ret = executorTest.SetInput(m_index, tensor, buffer, length);
204     EXPECT_EQ(OH_NN_MEMORY_ERROR, ret);
205 }
206 
207 /*
208  * @tc.name: executor_set_input_007
209  * @tc.desc: Verify that the SetInput function returns a failed message with empty buffer.
210  * @tc.type: FUNC
211  */
212 HWTEST_F(ExecutorTest, executor_set_input_007, testing::ext::TestSize.Level0)
213 {
214     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
215     InnerModel innerModel;
216     innerModel.BuildFromLiteGraph(liteGraphTest);
217     Compilation compilation(&innerModel);
218     Executor executorTest(&compilation);
219 
220     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
221     void* buffer = nullptr;
222     size_t length = 9 * sizeof(float);
223 
224     OH_NN_ReturnCode ret = executorTest.SetInput(m_index, tensor, buffer, length);
225     EXPECT_EQ(OH_NN_MEMORY_ERROR, ret);
226 }
227 
228 /*
229  * @tc.name: executor_set_input_008
230  * @tc.desc: Verify that the SetInput function returns a successful message with dataLength <= curBufferLength.
231  * @tc.type: FUNC
232  */
233 HWTEST_F(ExecutorTest, executor_set_input_008, testing::ext::TestSize.Level0)
234 {
235     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
236     InnerModel innerModel;
237     innerModel.BuildFromLiteGraph(liteGraphTest);
238     Compilation compilation(&innerModel);
239     Executor executorTest(&compilation);
240 
241     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
242     float dataArry[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
243     void* buffer = dataArry;
244     size_t length = 9 * sizeof(float);
245 
246     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetInput(m_index, tensor, buffer, length));
247 
248     float expectArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
249     void* expectBuffer = expectArry;
250     OH_NN_ReturnCode ret = executorTest.SetInput(m_index, tensor, expectBuffer, length);
251     EXPECT_EQ(OH_NN_SUCCESS, ret);
252 }
253 
254 /*
255  * @tc.name: executor_set_input_009
256  * @tc.desc: Verify that the SetInput function returns a failed message with length less than dataLength.
257  * @tc.type: FUNC
258  */
259 HWTEST_F(ExecutorTest, executor_set_input_009, testing::ext::TestSize.Level0)
260 {
261     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
262     InnerModel innerModel;
263     innerModel.BuildFromLiteGraph(liteGraphTest);
264     Compilation compilation(&innerModel);
265     Executor executorTest(&compilation);
266 
267     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
268     void* const data = m_dataArry;
269     OH_NN_Memory memory = {data, 9 * sizeof(float)};
270 
271     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetInputFromMemory(m_index, tensor, memory));
272 
273     float expectData = 0;
274     void* buffer = &expectData;
275     size_t length = 1 * sizeof(float);
276 
277     OH_NN_ReturnCode ret = executorTest.SetInput(m_index, tensor, buffer, length);
278     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
279 }
280 
281 /*
282  * @tc.name: executor_set_input_010
283  * @tc.desc: Verify that the SetInput function returns a failed message with BuildFromOHNNTensor unsuccessfully.
284  * @tc.type: FUNC
285  */
286 HWTEST_F(ExecutorTest, executor_set_input_010, testing::ext::TestSize.Level0)
287 {
288     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
289     InnerModel innerModel;
290     innerModel.BuildFromLiteGraph(liteGraphTest);
291     Compilation compilation(&innerModel);
292     Executor executorTest(&compilation);
293 
294     m_dimensionCount = 0;
295     OH_NN_Tensor tensor = SetTensor(OH_NN_UNKNOWN, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
296     void* buffer = m_dataArry;
297     size_t length = 9 * sizeof(float);
298 
299     OH_NN_ReturnCode ret = executorTest.SetInput(m_index, tensor, buffer, length);
300     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
301 }
302 
303 /*
304  * @tc.name: executor_set_input_011
305  * @tc.desc: Verify that the SetInput function returns a successful message with dataLength <= curBufferLength.
306  * @tc.type: FUNC
307  */
308 HWTEST_F(ExecutorTest, executor_set_input_011, testing::ext::TestSize.Level0)
309 {
310     const std::vector<int32_t> expectDim = {3, -1};
311     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(expectDim, m_dimOut);
312     InnerModel innerModel;
313     innerModel.BuildFromLiteGraph(liteGraphTest);
314     Compilation compilation(&innerModel);
315     Executor executorTest(&compilation);
316 
317     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
318     void* buffer = m_dataArry;
319     size_t length = 9 * sizeof(float);
320     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetInput(m_index, tensor, buffer, length));
321 
322     const int32_t testDim[2] = {3, 5};
323     OH_NN_Tensor expectTensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, testDim, nullptr, OH_NN_TENSOR);
324     size_t expectLength = 15 * sizeof(float);
325     float expectArry[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
326     void* expectBuffer = expectArry;
327     OH_NN_ReturnCode ret = executorTest.SetInput(m_index, expectTensor, expectBuffer, expectLength);
328     EXPECT_EQ(OH_NN_SUCCESS, ret);
329 }
330 
331 /*
332  * @tc.name: executor_set_input_from_memory_001
333  * @tc.desc: Verify that the SetInputFromMemory function returns a successful message.
334  * @tc.type: FUNC
335  */
336 HWTEST_F(ExecutorTest, executor_set_input_from_memory_001, testing::ext::TestSize.Level0)
337 {
338     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
339     InnerModel innerModel;
340     innerModel.BuildFromLiteGraph(liteGraphTest);
341     Compilation compilation(&innerModel);
342     Executor executorTest(&compilation);
343 
344     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
345     void* const data = m_dataArry;
346     OH_NN_Memory memory = {data, 9 * sizeof(float)};
347 
348     OH_NN_ReturnCode ret = executorTest.SetInputFromMemory(m_index, tensor, memory);
349     EXPECT_EQ(OH_NN_SUCCESS, ret);
350 }
351 
352 /*
353  * @tc.name: executor_set_input_from_memory_002
354  * @tc.desc: Verify that the SetInputFromMemory function returns a failed message with out-of-range index.
355  * @tc.type: FUNC
356  */
357 HWTEST_F(ExecutorTest, executor_set_input_from_memory_002, testing::ext::TestSize.Level0)
358 {
359     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
360     InnerModel innerModel;
361     innerModel.BuildFromLiteGraph(liteGraphTest);
362     Compilation compilation(&innerModel);
363     Executor executorTest(&compilation);
364 
365     m_index = 6;
366     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
367     void* const data = m_dataArry;
368     OH_NN_Memory memory = {data, 9 * sizeof(float)};
369 
370     OH_NN_ReturnCode ret = executorTest.SetInputFromMemory(m_index, tensor, memory);
371     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
372 }
373 
374 /*
375  * @tc.name: executor_set_input_from_memory_003
376  * @tc.desc: Verify that the SetInputFromMemory function returns a failed message with dynamic shape.
377  * @tc.type: FUNC
378  */
379 HWTEST_F(ExecutorTest, executor_set_input_from_memory_003, testing::ext::TestSize.Level0)
380 {
381     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
382     InnerModel innerModel;
383     innerModel.BuildFromLiteGraph(liteGraphTest);
384     Compilation compilation(&innerModel);
385     Executor executorTest(&compilation);
386 
387     const int dim = -1;
388     OH_NN_Tensor tensor;
389     tensor.dataType = OH_NN_FLOAT32;
390     tensor.dimensionCount = 1;
391     tensor.dimensions = &dim;
392     tensor.quantParam = nullptr;
393     tensor.type = OH_NN_TENSOR;
394     float value = 0;
395     void* const data = &value;
396     OH_NN_Memory memory = {data, 1 * sizeof(float)};
397 
398     OH_NN_ReturnCode ret = executorTest.SetInputFromMemory(m_index, tensor, memory);
399     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
400 }
401 
402 /*
403  * @tc.name: executor_set_input_from_memory_004
404  * @tc.desc: Verify that the SetInputFromMemory function returns a failed message with invalid tensor's dataType.
405  * @tc.type: FUNC
406  */
407 HWTEST_F(ExecutorTest, executor_set_input_from_memory_004, testing::ext::TestSize.Level0)
408 {
409     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
410     InnerModel innerModel;
411     innerModel.BuildFromLiteGraph(liteGraphTest);
412     Compilation compilation(&innerModel);
413     Executor executorTest(&compilation);
414 
415     OH_NN_Tensor tensor = SetTensor(OH_NN_INT64, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
416     void* const data = m_dataArry;
417     OH_NN_Memory memory = {data, 9 * sizeof(float)};
418 
419     OH_NN_ReturnCode ret = executorTest.SetInputFromMemory(m_index, tensor, memory);
420     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
421 }
422 
423 /*
424  * @tc.name: executor_set_input_from_memory_005
425  * @tc.desc: Verify that the SetInput function returns a failed message with invalid memory.length.
426  * @tc.type: FUNC
427  */
428 HWTEST_F(ExecutorTest, executor_set_input_from_memory_005, testing::ext::TestSize.Level0)
429 {
430     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
431     InnerModel innerModel;
432     innerModel.BuildFromLiteGraph(liteGraphTest);
433     Compilation compilation(&innerModel);
434     Executor executorTest(&compilation);
435 
436     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
437     void* const data = m_dataArry;
438     OH_NN_Memory memory = {data, 1 * sizeof(float)};
439 
440     OH_NN_ReturnCode ret = executorTest.SetInputFromMemory(m_index, tensor, memory);
441     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
442 }
443 
444 /*
445  * @tc.name: executor_set_output_001
446  * @tc.desc: Verify that the SetOutput function returns a successful message.
447  * @tc.type: FUNC
448  */
449 HWTEST_F(ExecutorTest, executor_set_output_001, testing::ext::TestSize.Level0)
450 {
451     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
452     InnerModel innerModel;
453     innerModel.BuildFromLiteGraph(liteGraphTest);
454     Compilation compilation(&innerModel);
455     Executor executorTest(&compilation);
456 
457     size_t length = 9 * sizeof(float);
458     void* buffer = m_dataArry;
459 
460     OH_NN_ReturnCode ret = executorTest.SetOutput(m_index, buffer, length);
461     EXPECT_EQ(OH_NN_SUCCESS, ret);
462 }
463 
464 /*
465  * @tc.name: executor_set_output_002
466  * @tc.desc: Verify that the SetOutput function returns a failed message with out-of-range index.
467  * @tc.type: FUNC
468  */
469 HWTEST_F(ExecutorTest, executor_set_output_002, testing::ext::TestSize.Level0)
470 {
471     InnerModel innerModel;
472     Compilation compilation(&innerModel);
473     Executor executorTest(&compilation);
474 
475     m_index = 6;
476     size_t length = 9 * sizeof(float);
477     void* buffer = m_dataArry;
478 
479     OH_NN_ReturnCode ret = executorTest.SetOutput(m_index, buffer, length);
480     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
481 }
482 
483 /*
484  * @tc.name: executor_set_output_003
485  * @tc.desc: Verify that the SetOutput function returns a failed message with invalid length.
486  * @tc.type: FUNC
487  */
488 HWTEST_F(ExecutorTest, executor_set_output_003, testing::ext::TestSize.Level0)
489 {
490     InnerModel innerModel;
491     Compilation compilation(&innerModel);
492     Executor executorTest(&compilation);
493 
494     size_t length = 2 * sizeof(float);
495     void* buffer = m_dataArry;
496 
497     OH_NN_ReturnCode ret = executorTest.SetOutput(m_index, buffer, length);
498     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
499 }
500 
501 /*
502  * @tc.name: executor_set_output_004
503  * @tc.desc: Verify that the SetOutput function returns a failed message with allocating buffer is failed.
504  * @tc.type: FUNC
505  */
506 HWTEST_F(ExecutorTest, executor_set_output_004, testing::ext::TestSize.Level0)
507 {
508     HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode = OH_NN_INVALID_PARAMETER;
509     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
510     InnerModel innerModel;
511     innerModel.BuildFromLiteGraph(liteGraphTest);
512     Compilation compilation(&innerModel);
513     Executor executorTest(&compilation);
514 
515     size_t length = 9 * sizeof(float);
516     void* buffer = m_dataArry;
517 
518     OH_NN_ReturnCode ret = executorTest.SetOutput(m_index, buffer, length);
519     EXPECT_EQ(OH_NN_MEMORY_ERROR, ret);
520 }
521 
522 /*
523  * @tc.name: executor_set_output_005
524  * @tc.desc: Verify that the SetOutput function returns a successful message.
525  * @tc.type: FUNC
526  */
527 HWTEST_F(ExecutorTest, executor_set_output_005, testing::ext::TestSize.Level0)
528 {
529     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
530     InnerModel innerModel;
531     innerModel.BuildFromLiteGraph(liteGraphTest);
532     Compilation compilation(&innerModel);
533     Executor executorTest(&compilation);
534 
535     void* const data = m_dataArry;
536     OH_NN_Memory memory = {data, 9 * sizeof(float)};
537     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetOutputFromMemory(m_index, memory));
538 
539     size_t length = 1 * sizeof(float);
540     float expectData = 0;
541     void* buffer = &expectData;
542     OH_NN_ReturnCode ret = executorTest.SetOutput(m_index, buffer, length);
543     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
544 }
545 
546 /*
547  * @tc.name: executor_set_output_006
548  * @tc.desc: Verify that the SetOutput function returns a successful message with length <= curBufferLength.
549  * @tc.type: FUNC
550  */
551 HWTEST_F(ExecutorTest, executor_set_output_006, testing::ext::TestSize.Level0)
552 {
553     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
554     InnerModel innerModel;
555     innerModel.BuildFromLiteGraph(liteGraphTest);
556     Compilation compilation(&innerModel);
557     Executor executorTest(&compilation);
558 
559     size_t length = 9 * sizeof(float);
560     void* buffer = m_dataArry;
561     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetOutput(m_index, buffer, length));
562 
563     float expectDataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
564     void* expectBuffer = expectDataArry;
565     OH_NN_ReturnCode ret = executorTest.SetOutput(m_index, expectBuffer, length);
566     EXPECT_EQ(OH_NN_SUCCESS, ret);
567 }
568 
569 /*
570  * @tc.name: executor_set_output_007
571  * @tc.desc: Verify that the SetOutput function returns a successful message with length > curBufferLength.
572  * @tc.type: FUNC
573  */
574 HWTEST_F(ExecutorTest, executor_set_output_007, testing::ext::TestSize.Level0)
575 {
576     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
577     InnerModel innerModel;
578     innerModel.BuildFromLiteGraph(liteGraphTest);
579     Compilation compilation(&innerModel);
580     Executor executorTest(&compilation);
581 
582     size_t length = 9 * sizeof(float);
583     void* buffer = m_dataArry;
584     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetOutput(m_index, buffer, length));
585 
586     size_t expectLength = 15 * sizeof(float);
587     float expectDataArry[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
588     void* expectBuffer = expectDataArry;
589     OH_NN_ReturnCode ret = executorTest.SetOutput(m_index, expectBuffer, expectLength);
590     EXPECT_EQ(OH_NN_SUCCESS, ret);
591 }
592 
593 /*
594  * @tc.name: executor_set_output_from_memory_001
595  * @tc.desc: Verify that the SetOutputFromMemory function returns a successful message.
596  * @tc.type: FUNC
597  */
598 HWTEST_F(ExecutorTest, executor_set_output_from_memory_001, testing::ext::TestSize.Level0)
599 {
600     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
601     InnerModel innerModel;
602     innerModel.BuildFromLiteGraph(liteGraphTest);
603     Compilation compilation(&innerModel);
604     Executor executorTest(&compilation);
605 
606     void* const data = m_dataArry;
607     OH_NN_Memory memory = {data, 9 * sizeof(float)};
608 
609     OH_NN_ReturnCode ret = executorTest.SetOutputFromMemory(m_index, memory);
610     EXPECT_EQ(OH_NN_SUCCESS, ret);
611 }
612 
613 /*
614  * @tc.name: executor_set_output_from_memory_002
615  * @tc.desc: Verify that the SetOutputFromMemory function returns a failed message with out-of-range index.
616  * @tc.type: FUNC
617  */
618 HWTEST_F(ExecutorTest, executor_set_output_from_memory_002, testing::ext::TestSize.Level0)
619 {
620     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
621     InnerModel innerModel;
622     innerModel.BuildFromLiteGraph(liteGraphTest);
623     Compilation compilation(&innerModel);
624     Executor executorTest(&compilation);
625 
626     m_index = 6;
627     void* const data = m_dataArry;
628     OH_NN_Memory memory = {data, 9 * sizeof(float)};
629 
630     OH_NN_ReturnCode ret = executorTest.SetOutputFromMemory(m_index, memory);
631     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
632 }
633 
634 /*
635  * @tc.name: executor_set_output_from_memory_003
636  * @tc.desc: Verify that the SetOutputFromMemory function returns a failed message with invalid memory.length.
637  * @tc.type: FUNC
638  */
639 HWTEST_F(ExecutorTest, executor_set_output_from_memory_003, testing::ext::TestSize.Level0)
640 {
641     InnerModel innerModel;
642     Compilation compilation(&innerModel);
643     Executor executorTest(&compilation);
644 
645     void* const data = m_dataArry;
646     OH_NN_Memory memory = {data, 0};
647 
648     OH_NN_ReturnCode ret = executorTest.SetOutputFromMemory(m_index, memory);
649     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
650 }
651 
652 /*
653  * @tc.name: executor_set_output_from_memory_004
654  * @tc.desc: Verify that the SetOutputFromMemory function returns a failed message with memory.length < dataLength.
655  * @tc.type: FUNC
656  */
657 HWTEST_F(ExecutorTest, executor_set_output_from_memory_004, testing::ext::TestSize.Level0)
658 {
659     const std::vector<int32_t> expectDim = {4, 4};
660     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, expectDim);
661     InnerModel innerModel;
662     innerModel.BuildFromLiteGraph(liteGraphTest);
663     Compilation compilation(&innerModel);
664     Executor executorTest(&compilation);
665 
666     void* const data = m_dataArry;
667     OH_NN_Memory memory = {data, 9 * sizeof(float)};
668 
669     OH_NN_ReturnCode ret = executorTest.SetOutputFromMemory(m_index, memory);
670     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
671 }
672 
673 /*
674  * @tc.name: executor_set_output_from_memory_005
675  * @tc.desc: Verify that the SetOutputFromMemory function returns a successful message.
676  * @tc.type: FUNC
677  */
678 HWTEST_F(ExecutorTest, executor_set_output_from_memory_005, testing::ext::TestSize.Level0)
679 {
680     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
681     InnerModel innerModel;
682     innerModel.BuildFromLiteGraph(liteGraphTest);
683     Compilation compilation(&innerModel);
684     Executor executorTest(&compilation);
685 
686     size_t length = 9 * sizeof(float);
687     void* buffer = m_dataArry;
688 
689     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetOutput(m_index, buffer, length));
690     void* const data = m_dataArry;
691     OH_NN_Memory memory = {data, 9 * sizeof(float)};
692 
693     OH_NN_ReturnCode ret = executorTest.SetOutputFromMemory(m_index, memory);
694     EXPECT_EQ(OH_NN_SUCCESS, ret);
695 }
696 
697 /*
698  * @tc.name: executor_get_output_dimensions_001
699  * @tc.desc: Verify that the GetOutputShape function returns a successful message.
700  * @tc.type: FUNC
701  */
702 HWTEST_F(ExecutorTest, executor_get_output_dimensions_001, testing::ext::TestSize.Level0)
703 {
704     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
705     InnerModel innerModel;
706     innerModel.BuildFromLiteGraph(liteGraphTest);
707     Compilation compilation(&innerModel);
708     Executor executorTest(&compilation);
709 
710     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
711     size_t length = 9 * sizeof(float);
712     void* buffer = m_dataArry;
713 
714     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetInput(m_index, tensor, buffer, length));
715     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetOutput(m_index, buffer, length));
716     EXPECT_EQ(OH_NN_SUCCESS, executorTest.Run());
717 
718     int32_t expectDim[2] = {3, 3};
719     int32_t* ptr = expectDim;
720     int32_t** dimensions = &ptr;
721     uint32_t dimensionCount = 2;
722 
723     OH_NN_ReturnCode ret = executorTest.GetOutputShape(m_index, dimensions, dimensionCount);
724     EXPECT_EQ(OH_NN_SUCCESS, ret);
725 }
726 
727 /*
728  * @tc.name: executor_get_output_dimensions_002
729  * @tc.desc: Verify that the GetOutputShape function returns a failed message without run.
730  * @tc.type: FUNC
731  */
732 HWTEST_F(ExecutorTest, executor_get_output_dimensions_002, testing::ext::TestSize.Level0)
733 {
734     size_t length = 9 * sizeof(float);
735     void* buffer = m_dataArry;
736     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
737     InnerModel innerModel;
738     innerModel.BuildFromLiteGraph(liteGraphTest);
739     Compilation compilation(&innerModel);
740     Executor executorTest(&compilation);
741 
742     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
743 
744     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetInput(m_index, tensor, buffer, length));
745     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetOutput(m_index, buffer, length));
746 
747     int32_t testDim[2] = {3, 3};
748     int32_t* ptr = testDim;
749     int32_t** dimensions = &ptr;
750     uint32_t dimensionCount = 2;
751 
752     OH_NN_ReturnCode ret = executorTest.GetOutputShape(m_index, dimensions, dimensionCount);
753     EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, ret);
754 }
755 
756 /*
757  * @tc.name: executor_get_output_dimensions_003
758  * @tc.desc: Verify that the GetOutputShape function returns a failed message with out-of-range index.
759  * @tc.type: FUNC
760  */
761 HWTEST_F(ExecutorTest, executor_get_output_dimensions_003, testing::ext::TestSize.Level0)
762 {
763     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
764     InnerModel innerModel;
765     innerModel.BuildFromLiteGraph(liteGraphTest);
766     Compilation compilation(&innerModel);
767     Executor executorTest(&compilation);
768 
769     void* buffer = m_dataArry;
770     size_t length = 9 * sizeof(float);
771     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
772 
773     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetInput(m_index, tensor, buffer, length));
774     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetOutput(m_index, buffer, length));
775     EXPECT_EQ(OH_NN_SUCCESS, executorTest.Run());
776 
777     uint32_t testIndex = 6;
778     int32_t testDim[2] = {3, 3};
779     int32_t* ptr = testDim;
780     int32_t** dimensions = &ptr;
781     uint32_t dimensionCount = 2;
782 
783     OH_NN_ReturnCode ret = executorTest.GetOutputShape(testIndex, dimensions, dimensionCount);
784     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
785 }
786 
787 /*
788  * @tc.name: executor_create_input_memory_001
789  * @tc.desc: Verify that the CreateInputMemory function returns a successful message.
790  * @tc.type: FUNC
791  */
792 HWTEST_F(ExecutorTest, executor_create_input_memory_001, testing::ext::TestSize.Level0)
793 {
794     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
795     InnerModel innerModel;
796     innerModel.BuildFromLiteGraph(liteGraphTest);
797     Compilation compilation(&innerModel);
798     Executor executorTest(&compilation);
799 
800     OH_NN_Memory** memory = nullptr;
801     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
802     void* const data = dataArry;
803     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
804     OH_NN_Memory* ptr = &memoryPtr;
805     memory = &ptr;
806     size_t length = 9 * sizeof(float);
807 
808     OH_NN_ReturnCode ret = executorTest.CreateInputMemory(m_index, length, memory);
809     EXPECT_EQ(OH_NN_SUCCESS, ret);
810 }
811 
812 /*
813  * @tc.name: executor_create_input_memory_002
814  * @tc.desc: Verify that the CreateInputMemory function returns a failed message with out-of-range index.
815  * @tc.type: FUNC
816  */
817 HWTEST_F(ExecutorTest, executor_create_input_memory_002, testing::ext::TestSize.Level0)
818 {
819     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
820     InnerModel innerModel;
821     innerModel.BuildFromLiteGraph(liteGraphTest);
822     Compilation compilation(&innerModel);
823     Executor executorTest(&compilation);
824 
825     size_t length = 9 * sizeof(float);
826     OH_NN_Memory** memory = nullptr;
827     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
828     void* const data = dataArry;
829     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
830     OH_NN_Memory* ptr = &memoryPtr;
831     memory = &ptr;
832 
833     m_index = 6;
834     OH_NN_ReturnCode ret = executorTest.CreateInputMemory(m_index, length, memory);
835     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
836 }
837 
838 /*
839  * @tc.name: executor_create_input_memory_003
840  * @tc.desc: Verify that the CreateInputMemory function returns a failed message with allocating buffer unsuccessfully.
841  * @tc.type: FUNC
842  */
843 HWTEST_F(ExecutorTest, executor_create_input_memory_003, testing::ext::TestSize.Level0)
844 {
845     InnerModel innerModel;
846     HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode = OH_NN_INVALID_PARAMETER;
847     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
848     innerModel.BuildFromLiteGraph(liteGraphTest);
849     Compilation compilation(&innerModel);
850     Executor executorTest(&compilation);
851 
852     size_t length = 9 * sizeof(float);
853     OH_NN_Memory** memory = nullptr;
854     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
855     void* const data = dataArry;
856     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
857     OH_NN_Memory* ptr = &memoryPtr;
858     memory = &ptr;
859 
860     OH_NN_ReturnCode ret = executorTest.CreateInputMemory(m_index, length, memory);
861     EXPECT_EQ(OH_NN_MEMORY_ERROR, ret);
862 }
863 
864 /*
865  * @tc.name: executor_destroy_input_memory_001
866  * @tc.desc: Verify that the DestroyInputMemory function returns a successful message.
867  * @tc.type: FUNC
868  */
869 HWTEST_F(ExecutorTest, executor_destroy_input_memory_001, testing::ext::TestSize.Level0)
870 {
871     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
872     InnerModel innerModel;
873     innerModel.BuildFromLiteGraph(liteGraphTest);
874     Compilation compilation(&innerModel);
875     Executor executorTest(&compilation);
876 
877     size_t length = 9 * sizeof(float);
878     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
879     void* const data = dataArry;
880     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
881     OH_NN_Memory* ptr = &memoryPtr;
882     OH_NN_Memory** memory = &ptr;
883 
884     EXPECT_EQ(OH_NN_SUCCESS, executorTest.CreateInputMemory(m_index, length, memory));
885     OH_NN_ReturnCode ret = executorTest.DestroyInputMemory(m_index, memory);
886     EXPECT_EQ(OH_NN_SUCCESS, ret);
887 }
888 
889 /*
890  * @tc.name: executor_destroy_input_memory_002
891  * @tc.desc: Verify that the DestroyInputMemory function returns a failed message with out-of-range index.
892  * @tc.type: FUNC
893  */
894 HWTEST_F(ExecutorTest, executor_destroy_input_memory_002, testing::ext::TestSize.Level0)
895 {
896     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
897     InnerModel innerModel;
898     innerModel.BuildFromLiteGraph(liteGraphTest);
899     Compilation compilation(&innerModel);
900     Executor executorTest(&compilation);
901 
902     size_t length = 9 * sizeof(float);
903     OH_NN_Memory** memory = nullptr;
904     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
905     void* const data = dataArry;
906     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
907     OH_NN_Memory* ptr = &memoryPtr;
908     memory = &ptr;
909 
910     uint32_t testIndex = 6;
911     EXPECT_EQ(OH_NN_SUCCESS, executorTest.CreateInputMemory(m_index, length, memory));
912     OH_NN_ReturnCode ret = executorTest.DestroyInputMemory(testIndex, memory);
913     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
914 }
915 
916 /*
917  * @tc.name: executor_destroy_input_memory_003
918  * @tc.desc: Verify that the DestroyInputMemory function returns a failed message without creating memory.
919  * @tc.type: FUNC
920  */
921 HWTEST_F(ExecutorTest, executor_destroy_input_memory_003, testing::ext::TestSize.Level0)
922 {
923     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
924     InnerModel innerModel;
925     innerModel.BuildFromLiteGraph(liteGraphTest);
926     Compilation compilation(&innerModel);
927     Executor executorTest(&compilation);
928 
929     OH_NN_Memory** memory = nullptr;
930     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
931     void* const data = dataArry;
932     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
933     OH_NN_Memory* ptr = &memoryPtr;
934     memory = &ptr;
935 
936     OH_NN_ReturnCode ret = executorTest.DestroyInputMemory(m_index, memory);
937     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
938 }
939 
940 /*
941  * @tc.name: executor_destroy_input_memory_004
942  * @tc.desc: Verify that the DestroyInputMemory function returns a failed message with invalid memory.data.
943  * @tc.type: FUNC
944  */
945 HWTEST_F(ExecutorTest, executor_destroy_input_memory_004, testing::ext::TestSize.Level0)
946 {
947     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
948     InnerModel innerModel;
949     innerModel.BuildFromLiteGraph(liteGraphTest);
950     Compilation compilation(&innerModel);
951     Executor executorTest(&compilation);
952 
953     size_t length = 9 * sizeof(float);
954     OH_NN_Memory** memory = nullptr;
955     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
956     void* const data = dataArry;
957     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
958     OH_NN_Memory* ptr = &memoryPtr;
959     memory = &ptr;
960 
961     EXPECT_EQ(OH_NN_SUCCESS, executorTest.CreateInputMemory(m_index, length, memory));
962 
963     float arry[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
964     void* const expectData = arry;
965     OH_NN_Memory mptr = {expectData, 9 * sizeof(float)};
966     OH_NN_Memory* expectPtr = &mptr;
967     OH_NN_Memory** expectMemory = &expectPtr;
968 
969     OH_NN_ReturnCode ret = executorTest.DestroyInputMemory(m_index, expectMemory);
970     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
971 }
972 
973 /*
974  * @tc.name: executor_create_output_memory_001
975  * @tc.desc: Verify that the CreateOutputMemory function returns a successful message.
976  * @tc.type: FUNC
977  */
978 HWTEST_F(ExecutorTest, executor_create_output_memory_001, testing::ext::TestSize.Level0)
979 {
980     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
981     InnerModel innerModel;
982     innerModel.BuildFromLiteGraph(liteGraphTest);
983     Compilation compilation(&innerModel);
984     Executor executorTest(&compilation);
985 
986     size_t length = 9 * sizeof(float);
987     OH_NN_Memory** memory = nullptr;
988     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
989     void* const data = dataArry;
990     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
991     OH_NN_Memory* ptr = &memoryPtr;
992     memory = &ptr;
993 
994     OH_NN_ReturnCode ret = executorTest.CreateOutputMemory(m_index, length, memory);
995     EXPECT_EQ(OH_NN_SUCCESS, ret);
996 }
997 
998 /*
999  * @tc.name: executor_create_output_memory_002
1000  * @tc.desc:  Verify that the CreateOutputMemory function returns a failed message with out-of-range index.
1001  * @tc.type: FUNC
1002  */
1003 HWTEST_F(ExecutorTest, executor_create_output_memory_002, testing::ext::TestSize.Level0)
1004 {
1005     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
1006     InnerModel innerModel;
1007     innerModel.BuildFromLiteGraph(liteGraphTest);
1008     Compilation compilation(&innerModel);
1009     Executor executorTest(&compilation);
1010 
1011     m_index = 6;
1012     size_t length = 9 * sizeof(float);
1013     OH_NN_Memory** memory = nullptr;
1014     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
1015     void* const data = dataArry;
1016     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
1017     OH_NN_Memory* ptr = &memoryPtr;
1018     memory = &ptr;
1019 
1020     OH_NN_ReturnCode ret = executorTest.CreateOutputMemory(m_index, length, memory);
1021     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1022 }
1023 
1024 /*
1025  * @tc.name: executor_create_output_memory_003
1026  * @tc.desc: Verify that the CreateOutputMemory function returns a failed message with allocating buffer unsuccessfully.
1027  * @tc.type: FUNC
1028  */
1029 HWTEST_F(ExecutorTest, executor_create_output_memory_003, testing::ext::TestSize.Level0)
1030 {
1031     HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode = OH_NN_INVALID_PARAMETER;
1032     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
1033     InnerModel innerModel;
1034     innerModel.BuildFromLiteGraph(liteGraphTest);
1035     Compilation compilation(&innerModel);
1036     Executor executorTest(&compilation);
1037 
1038     size_t length = 9 * sizeof(float);
1039     OH_NN_Memory** memory = nullptr;
1040     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
1041     void* const data = dataArry;
1042     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
1043     OH_NN_Memory* ptr = &memoryPtr;
1044     memory = &ptr;
1045 
1046     OH_NN_ReturnCode ret = executorTest.CreateOutputMemory(m_index, length, memory);
1047     EXPECT_EQ(OH_NN_MEMORY_ERROR, ret);
1048 }
1049 
1050 /*
1051  * @tc.name: executor_destroy_output_memory_001
1052  * @tc.desc: Verify that the DestroyOutputMemory function returns a successful message.
1053  * @tc.type: FUNC
1054  */
1055 HWTEST_F(ExecutorTest, executor_destroy_output_memory_001, testing::ext::TestSize.Level0)
1056 {
1057     InnerModel innerModel;
1058     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
1059     innerModel.BuildFromLiteGraph(liteGraphTest);
1060     Compilation compilation(&innerModel);
1061     Executor executorTest(&compilation);
1062 
1063     size_t length = 9 * sizeof(float);
1064     OH_NN_Memory** memory = nullptr;
1065     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
1066     void* const data = dataArry;
1067     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
1068     OH_NN_Memory* ptr = &memoryPtr;
1069     memory = &ptr;
1070 
1071     EXPECT_EQ(OH_NN_SUCCESS, executorTest.CreateOutputMemory(m_index, length, memory));
1072     OH_NN_ReturnCode ret = executorTest.DestroyOutputMemory(m_index, memory);
1073     EXPECT_EQ(OH_NN_SUCCESS, ret);
1074 }
1075 
1076 /*
1077  * @tc.name: executor_destroy_output_memory_002
1078  * @tc.desc: Verify that the DestroyOutputMemory function returns a failed message with out-of-range index.
1079  * @tc.type: FUNC
1080  */
1081 HWTEST_F(ExecutorTest, executor_destroy_output_memory_002, testing::ext::TestSize.Level0)
1082 {
1083     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
1084     InnerModel innerModel;
1085     innerModel.BuildFromLiteGraph(liteGraphTest);
1086     Compilation compilation(&innerModel);
1087     Executor executorTest(&compilation);
1088 
1089     uint32_t testIndex = 6;
1090     size_t length = 9 * sizeof(float);
1091     OH_NN_Memory** memory = nullptr;
1092     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
1093     void* const data = dataArry;
1094     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
1095     OH_NN_Memory* ptr = &memoryPtr;
1096     memory = &ptr;
1097 
1098     EXPECT_EQ(OH_NN_SUCCESS, executorTest.CreateOutputMemory(m_index, length, memory));
1099     OH_NN_ReturnCode ret = executorTest.DestroyOutputMemory(testIndex, memory);
1100     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1101 }
1102 
1103 /*
1104  * @tc.name: executor_destroy_output_memory_003
1105  * @tc.desc: Verify that the DestroyOutputMemory function returns a failed message without creating memory.
1106  * @tc.type: FUNC
1107  */
1108 HWTEST_F(ExecutorTest, executor_destroy_output_memory_003, testing::ext::TestSize.Level0)
1109 {
1110     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
1111     InnerModel innerModel;
1112     innerModel.BuildFromLiteGraph(liteGraphTest);
1113     Compilation compilation(&innerModel);
1114     Executor executorTest(&compilation);
1115 
1116     OH_NN_Memory** memory = nullptr;
1117     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
1118     void* const data = dataArry;
1119     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
1120     OH_NN_Memory* ptr = &memoryPtr;
1121     memory = &ptr;
1122 
1123     OH_NN_ReturnCode ret = executorTest.DestroyOutputMemory(m_index, memory);
1124     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1125 }
1126 
1127 /*
1128  * @tc.name: executor_destroy_output_memory_004
1129  * @tc.desc: Verify that the DestroyOutputMemory function returns a failed message with invalid memory.data.
1130  * @tc.type: FUNC
1131  */
1132 HWTEST_F(ExecutorTest, executor_destroy_output_memory_004, testing::ext::TestSize.Level0)
1133 {
1134     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
1135     InnerModel innerModel;
1136     innerModel.BuildFromLiteGraph(liteGraphTest);
1137     Compilation compilation(&innerModel);
1138     Executor executorTest(&compilation);
1139 
1140     size_t length = 9 * sizeof(float);
1141     OH_NN_Memory** memory = nullptr;
1142     float dataArry[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
1143     void* const data = dataArry;
1144     OH_NN_Memory memoryPtr = {data, 9 * sizeof(float)};
1145     OH_NN_Memory* ptr = &memoryPtr;
1146     memory = &ptr;
1147 
1148     EXPECT_EQ(OH_NN_SUCCESS, executorTest.CreateOutputMemory(m_index, length, memory));
1149 
1150     float arry[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1151     void* const expectData = arry;
1152     OH_NN_Memory mptr = {expectData, 9 * sizeof(float)};
1153     OH_NN_Memory* expectPtr = &mptr;
1154     OH_NN_Memory** expectMemory = &expectPtr;
1155 
1156     OH_NN_ReturnCode ret = executorTest.DestroyOutputMemory(m_index, expectMemory);
1157     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1158 }
1159 
1160 /*
1161  * @tc.name: executor_run_test_001
1162  * @tc.desc: Verify that the Run function returns a successful message.
1163  * @tc.type: FUNC
1164  */
1165 HWTEST_F(ExecutorTest, executor_run_test_001, testing::ext::TestSize.Level0)
1166 {
1167     HiviewDFX::HiTraceId traceId = HiTraceChain::Begin("executor_run_test_001", HITRACE_FLAG_TP_INFO);
1168     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
1169     InnerModel innerModel;
1170     innerModel.BuildFromLiteGraph(liteGraphTest);
1171     Compilation compilation(&innerModel);
1172     Executor executorTest(&compilation);
1173 
1174     size_t length = 9 * sizeof(float);
1175     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
1176     void* buffer = m_dataArry;
1177 
1178     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetInput(m_index, tensor, buffer, length));
1179     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetOutput(m_index, buffer, length));
1180     OH_NN_ReturnCode ret = executorTest.Run();
1181     HiTraceChain::End(traceId);
1182     EXPECT_EQ(OH_NN_SUCCESS, ret);
1183 }
1184 
1185 /*
1186  * @tc.name: executor_run_test_002
1187  * @tc.desc: Verify that the DestroyOutputMemory function returns a failed message without SetInput.
1188  * @tc.type: FUNC
1189  */
1190 HWTEST_F(ExecutorTest, executor_run_test_002, testing::ext::TestSize.Level0)
1191 {
1192     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
1193     InnerModel innerModel;
1194     innerModel.BuildFromLiteGraph(liteGraphTest);
1195     Compilation compilation(&innerModel);
1196     Executor executorTest(&compilation);
1197 
1198     OH_NN_ReturnCode ret = executorTest.Run();
1199     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1200 }
1201 
1202 /*
1203  * @tc.name: executor_run_test_003
1204  * @tc.desc: Verify that the DestroyOutputMemory function returns a failed message without SetOutput.
1205  * @tc.type: FUNC
1206  */
1207 HWTEST_F(ExecutorTest, executor_run_test_003, testing::ext::TestSize.Level0)
1208 {
1209     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
1210     InnerModel innerModel;
1211     innerModel.BuildFromLiteGraph(liteGraphTest);
1212     Compilation compilation(&innerModel);
1213     Executor executorTest(&compilation);
1214 
1215     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
1216     void* buffer = m_dataArry;
1217     size_t length = 9 * sizeof(float);
1218 
1219     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetInput(m_index, tensor, buffer, length));
1220     OH_NN_ReturnCode ret = executorTest.Run();
1221     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1222 }
1223 
1224 /*
1225  * @tc.name: executor_run_test_004
1226  * @tc.desc: Verify that the DestroyOutputMemory function returns a failed message with failed executionPlan.Run.
1227  * @tc.type: FUNC
1228  */
1229 HWTEST_F(ExecutorTest, executor_run_test_004, testing::ext::TestSize.Level0)
1230 {
1231     HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode = OH_NN_FAILED;
1232     const MSLITE::LiteGraph* liteGraphTest = BuildLiteGraph(m_dim, m_dimOut);
1233     InnerModel innerModel;
1234     innerModel.BuildFromLiteGraph(liteGraphTest);
1235     Compilation compilation(&innerModel);
1236     Executor executorTest(&compilation);
1237 
1238     OH_NN_Tensor tensor = SetTensor(OH_NN_FLOAT32, m_dimensionCount, m_dimArry, nullptr, OH_NN_TENSOR);
1239     void* buffer = m_dataArry;
1240     size_t length = 9 * sizeof(float);
1241 
1242     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetInput(m_index, tensor, buffer, length));
1243     EXPECT_EQ(OH_NN_SUCCESS, executorTest.SetOutput(m_index, buffer, length));
1244     OH_NN_ReturnCode ret = executorTest.Run();
1245     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1246 }
1247 } // namespace UnitTest
1248 } // namespace NeuralNetworkRuntime
1249 } // namespace OHOS