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 "ops/fullconnection_builder.h"
17 
18 #include "ops_test.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 using namespace OHOS::NeuralNetworkRuntime::Ops;
23 
24 namespace OHOS {
25 namespace NeuralNetworkRuntime {
26 namespace UnitTest {
27 class FullConnectionAxisBuilderTest : public OpsTest {
28 public:
29     void SetUp();
30     void TearDown();
31 
32     void SetInputToAlltensor();
33     void SetActivation(OH_NN_DataType dataType,
34         const std::vector<int32_t> &dim,  const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
35     void SetAxis(OH_NN_DataType dataType,
36         const std::vector<int32_t> &dim,  const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
37     void SetUseAxis(OH_NN_DataType dataType,
38         const std::vector<int32_t> &dim,  const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
39     void SetHasBias(OH_NN_DataType dataType,
40         const std::vector<int32_t> &dim,  const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
41 
42 public:
43     FullConnectionBuilder m_builder;
44     std::vector<uint32_t> m_inputs {0, 1, 2};
45     std::vector<uint32_t> m_outputs {3};
46     std::vector<uint32_t> m_params {4, 5, 6, 7};
47     std::vector<int32_t> m_output_dim {2, 2};
48     std::vector<int32_t> m_param_dim {};
49 };
50 
SetUp()51 void FullConnectionAxisBuilderTest::SetUp() {}
52 
TearDown()53 void FullConnectionAxisBuilderTest::TearDown() {}
54 
SetInputToAlltensor()55 void FullConnectionAxisBuilderTest::SetInputToAlltensor()
56 {
57     std::vector<int32_t> m_input_dim{2, 2};
58     std::vector<int32_t> biasDim{2};
59     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_FLOAT32, m_input_dim, nullptr, OH_NN_TENSOR);
60     m_allTensors.emplace_back(tensor);
61     int32_t weightNum = 4;
62     int32_t biasNum = 2;
63     tensor = TransToNNTensor(OH_NN_FLOAT32, m_input_dim, nullptr, OH_NN_TENSOR);
64     float* valueWeight = new (std::nothrow) float[4]{1, 1, 1, 1};
65     EXPECT_NE(nullptr, valueWeight);
66     tensor->SetBuffer(valueWeight, weightNum * sizeof(float));
67     m_allTensors.emplace_back(tensor);
68 
69     tensor = TransToNNTensor(OH_NN_FLOAT32, biasDim, nullptr, OH_NN_TENSOR);
70     float* valueBias = new (std::nothrow) float[2]{0, 0};
71     EXPECT_NE(nullptr, valueBias);
72     tensor->SetBuffer(valueBias, biasNum * sizeof(float));
73     m_allTensors.emplace_back(tensor);
74 }
75 
SetActivation(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)76 void FullConnectionAxisBuilderTest::SetActivation(OH_NN_DataType dataType,
77     const std::vector<int32_t> &dim,  const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
78 {
79     std::shared_ptr<NNTensor> tensor = TransToNNTensor(dataType, dim, quantParam, type);
80     int8_t* activationValue = new (std::nothrow) int8_t(0);
81     EXPECT_NE(nullptr, activationValue);
82 
83     tensor->SetBuffer(activationValue, sizeof(int8_t));
84     m_allTensors.emplace_back(tensor);
85 }
86 
SetAxis(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)87 void FullConnectionAxisBuilderTest::SetAxis(OH_NN_DataType dataType,
88     const std::vector<int32_t> &dim,  const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
89 {
90     std::shared_ptr<NNTensor> tensor = TransToNNTensor(dataType, dim, quantParam, type);
91     int64_t* axisValue = new (std::nothrow) int64_t(0);
92     EXPECT_NE(nullptr, axisValue);
93 
94     tensor->SetBuffer(axisValue, sizeof(int64_t));
95     m_allTensors.emplace_back(tensor);
96 }
97 
SetUseAxis(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)98 void FullConnectionAxisBuilderTest::SetUseAxis(OH_NN_DataType dataType,
99     const std::vector<int32_t> &dim,  const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
100 {
101     std::shared_ptr<NNTensor> tensor = TransToNNTensor(dataType, dim, quantParam, type);
102     bool* useAxisValue = new (std::nothrow) bool (true);
103     EXPECT_NE(nullptr, useAxisValue);
104 
105     tensor->SetBuffer(useAxisValue, sizeof(bool));
106     m_allTensors.emplace_back(tensor);
107 }
108 
SetHasBias(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)109 void FullConnectionAxisBuilderTest::SetHasBias(OH_NN_DataType dataType,
110     const std::vector<int32_t> &dim,  const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
111 {
112     std::shared_ptr<NNTensor> tensor = TransToNNTensor(dataType, dim, quantParam, type);
113     bool* hasBiasValue = new (std::nothrow) bool (true);
114     EXPECT_NE(nullptr, hasBiasValue);
115 
116     tensor->SetBuffer(hasBiasValue, sizeof(bool));
117     m_allTensors.emplace_back(tensor);
118 }
119 
120 /**
121  * @tc.name: fullconnection_build_axis_001
122  * @tc.desc: Verify the behavior of the build function
123  * @tc.type: FUNC
124  */
125 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_001, TestSize.Level1)
126 {
127     m_inputsIndex = m_inputs;
128     m_paramsIndex = m_params;
129     SetInputToAlltensor();
130     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
131 
132     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
133     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
134     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
135     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
136 
137     EXPECT_EQ(OH_NN_SUCCESS, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
138 }
139 
140 /**
141  * @tc.name: fullconnection_build_axis_002
142  * @tc.desc: Verify the behavior of the build function
143  * @tc.type: FUNC
144  */
145 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_002, TestSize.Level1)
146 {
147     m_inputsIndex = m_inputs;
148     m_paramsIndex = m_params;
149     SetInputToAlltensor();
150     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
151 
152     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
153     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
154     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
155     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
156 
157     EXPECT_EQ(OH_NN_SUCCESS, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
158     EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
159 }
160 
161 /**
162  * @tc.name: fullconnection_build_axis_003
163  * @tc.desc: Verify the missing output of the build function
164  * @tc.type: FUNC
165  */
166 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_003, TestSize.Level1)
167 {
168     m_outputs = {};
169     m_inputsIndex = m_inputs;
170     m_paramsIndex = m_params;
171     SetInputToAlltensor();
172     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
173 
174     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
175     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
176     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
177     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
178 
179     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
180 }
181 
182 /**
183  * @tc.name: fullconnection_build_axis_004
184  * @tc.desc: Verify the inputIndex out of bounds of the build function
185  * @tc.type: FUNC
186  */
187 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_004, TestSize.Level1)
188 {
189     m_inputs = {0, 1, 8};
190     m_inputsIndex = m_inputs;
191     m_paramsIndex = m_params;
192     SetInputToAlltensor();
193     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
194 
195     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
196     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
197     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
198     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
199 
200     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
201 }
202 
203 /**
204  * @tc.name: fullconnection_build_axis_005
205  * @tc.desc: Verify the invalid axis of the build function
206  * @tc.type: FUNC
207  */
208 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_005, TestSize.Level1)
209 {
210     m_inputsIndex = m_inputs;
211     m_paramsIndex = m_params;
212     SetInputToAlltensor();
213     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
214 
215     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_INT32, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
216     int32_t *axisValueTest = new (std::nothrow) int32_t(0);
217     EXPECT_NE(nullptr, axisValueTest);
218     tensor->SetBuffer(axisValueTest, sizeof(int32_t));
219     m_allTensors.emplace_back(tensor);
220     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
221     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
222     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
223 
224     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
225 }
226 
227 /**
228  * @tc.name: fullconnection_build_axis_006
229  * @tc.desc: Verify the behavior of the build function
230  * @tc.type: FUNC
231  */
232 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_006, TestSize.Level1)
233 {
234     m_inputsIndex = m_inputs;
235     m_paramsIndex = m_params;
236     SetInputToAlltensor();
237     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
238 
239     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
240     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_INT32, m_param_dim, nullptr,
241         OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
242     int32_t *activationValue = new (std::nothrow) int32_t(0);
243     EXPECT_NE(nullptr, activationValue);
244     tensor->SetBuffer(activationValue, sizeof(int32_t));
245     m_allTensors.emplace_back(tensor);
246     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
247     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
248 
249     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
250 }
251 
252 /**
253  * @tc.name: fullconnection_build_axis_007
254  * @tc.desc: Verify the behavior of the build function
255  * @tc.type: FUNC
256  */
257 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_007, TestSize.Level1)
258 {
259     m_inputsIndex = m_inputs;
260     m_paramsIndex = m_params;
261     SetInputToAlltensor();
262     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
263 
264     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
265     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
266     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_INT32, m_param_dim, nullptr,
267         OH_NN_FULL_CONNECTION_USE_AXIS);
268     int32_t *useAxisValue = new (std::nothrow) int32_t(1);
269     EXPECT_NE(nullptr, useAxisValue);
270     tensor->SetBuffer(useAxisValue, sizeof(int32_t));
271     m_allTensors.emplace_back(tensor);
272     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
273 
274     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
275 }
276 
277 /**
278  * @tc.name: fullconnection_build_axis_008
279  * @tc.desc: Verify the behavior of the build function
280  * @tc.type: FUNC
281  */
282 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_008, TestSize.Level1)
283 {
284     m_inputsIndex = m_inputs;
285     m_paramsIndex = m_params;
286     SetInputToAlltensor();
287     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
288 
289     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
290     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
291     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
292     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_INT32, m_param_dim, nullptr,
293         OH_NN_FULL_CONNECTION_HAS_BIAS);
294     int32_t *hasBiasValue = new (std::nothrow) int32_t(1);
295     EXPECT_NE(nullptr, hasBiasValue);
296     tensor->SetBuffer(hasBiasValue, sizeof(int32_t));
297     m_allTensors.emplace_back(tensor);
298 
299     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
300 }
301 
302 /**
303  * @tc.name: fullconnection_build_axis_009
304  * @tc.desc: Verify the behavior of the build function
305  * @tc.type: FUNC
306  */
307 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_009, TestSize.Level1)
308 {
309     std::vector<int32_t> paramDimTest = {2};
310     m_inputsIndex = m_inputs;
311     m_paramsIndex = m_params;
312 
313     SetInputToAlltensor();
314     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
315 
316     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_INT64, paramDimTest, nullptr,
317         OH_NN_FULL_CONNECTION_AXIS);
318     int64_t *axisValueTest = new (std::nothrow) int64_t[2]{0, 0};
319     EXPECT_NE(nullptr, axisValueTest);
320     tensor->SetBuffer(axisValueTest, 2 * sizeof(int64_t));
321     m_allTensors.emplace_back(tensor);
322     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
323     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
324     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
325 
326     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
327 }
328 
329 /**
330  * @tc.name: fullconnection_build_axis_010
331  * @tc.desc: Verify the behavior of the build function
332  * @tc.type: FUNC
333  */
334 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_010, TestSize.Level1)
335 {
336     std::vector<int32_t> paramDimTest = {2};
337     m_inputsIndex = m_inputs;
338     m_paramsIndex = m_params;
339     SetInputToAlltensor();
340     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
341 
342     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
343     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_INT8, paramDimTest, nullptr,
344         OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
345     int8_t *activationValue = new (std::nothrow) int8_t[2]{0, 0};
346     EXPECT_NE(nullptr, activationValue);
347     tensor->SetBuffer(activationValue, 2 * sizeof(int8_t));
348     m_allTensors.emplace_back(tensor);
349     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
350     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
351 
352     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
353 }
354 
355 /**
356  * @tc.name: fullconnection_build_axis_011
357  * @tc.desc: Verify the behavior of the build function
358  * @tc.type: FUNC
359  */
360 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_011, TestSize.Level1)
361 {
362     std::vector<int32_t> paramDimTest = {2};
363     m_inputsIndex = m_inputs;
364     m_paramsIndex = m_params;
365     SetInputToAlltensor();
366     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
367 
368     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
369     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
370     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_BOOL, paramDimTest, nullptr,
371         OH_NN_FULL_CONNECTION_USE_AXIS);
__anon13a4d4630302null372     bool *useAxisValue = new (std::nothrow) bool[2] {true, true};
373     EXPECT_NE(nullptr, useAxisValue);
374     tensor->SetBuffer(useAxisValue, 2 * sizeof(int8_t));
375     m_allTensors.emplace_back(tensor);
376     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
377 
378     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
379 }
380 
381 /**
382  * @tc.name: fullconnection_build_axis_012
383  * @tc.desc: Verify the behavior of the build function
384  * @tc.type: FUNC
385  */
386 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_012, TestSize.Level1)
387 {
388     std::vector<int32_t> paramDimTest = {2};
389     m_inputsIndex = m_inputs;
390     m_paramsIndex = m_params;
391     SetInputToAlltensor();
392     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
393 
394     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
395     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
396     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
397     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_BOOL, paramDimTest, nullptr,
398         OH_NN_FULL_CONNECTION_HAS_BIAS);
__anon13a4d4630402null399     bool *hasBiasValue = new (std::nothrow) bool[2] {true, true};
400     EXPECT_NE(nullptr, hasBiasValue);
401     tensor->SetBuffer(hasBiasValue, 2 * sizeof(bool));
402     m_allTensors.emplace_back(tensor);
403 
404     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
405 }
406 
407 /**
408  * @tc.name: fullconnection_build_axis_013
409  * @tc.desc: Verify the fullconnection without set axis of the build function
410  * @tc.type: FUNC
411  */
412 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_013, TestSize.Level1)
413 {
414     m_inputsIndex = m_inputs;
415     m_paramsIndex = m_params;
416 
417     SetInputToAlltensor();
418     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
419 
420     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
421     m_allTensors.emplace_back(tensor);
422     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
423     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
424     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
425 
426     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
427 }
428 
429 /**
430  * @tc.name: fullconnection_build_axis_014
431  * @tc.desc: Verify the fullconnection without set activation of the build function
432  * @tc.type: FUNC
433  */
434 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_014, TestSize.Level1)
435 {
436     m_inputsIndex = m_inputs;
437     m_paramsIndex = m_params;
438 
439     SetInputToAlltensor();
440     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
441 
442     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
443     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_INT8, m_param_dim, nullptr,
444         OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
445     m_allTensors.emplace_back(tensor);
446     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
447     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
448 
449     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
450 }
451 
452 /**
453  * @tc.name: fullconnection_build_axis_015
454  * @tc.desc: Verify the fullconnection without set activation of the build function
455  * @tc.type: FUNC
456  */
457 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_015, TestSize.Level1)
458 {
459     m_inputsIndex = m_inputs;
460     m_paramsIndex = m_params;
461 
462     SetInputToAlltensor();
463     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
464 
465     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
466     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
467     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_BOOL, m_param_dim, nullptr,
468         OH_NN_FULL_CONNECTION_USE_AXIS);
469     m_allTensors.emplace_back(tensor);
470     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
471 
472     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
473 }
474 
475 /**
476  * @tc.name: fullconnection_build_axis_016
477  * @tc.desc: Verify the fullconnection without set activation of the build function
478  * @tc.type: FUNC
479  */
480 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_016, TestSize.Level1)
481 {
482     m_inputsIndex = m_inputs;
483     m_paramsIndex = m_params;
484 
485     SetInputToAlltensor();
486     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
487 
488     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
489     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
490     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
491     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_BOOL, m_param_dim, nullptr,
492         OH_NN_FULL_CONNECTION_HAS_BIAS);
493     m_allTensors.emplace_back(tensor);
494 
495     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
496 }
497 
498 /**
499  * @tc.name: fullconnection_build_axis_017
500  * @tc.desc: Verify the behavior of the build function
501  * @tc.type: FUNC
502  */
503 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_build_axis_017, TestSize.Level1)
504 {
505     m_inputsIndex = m_inputs;
506     m_paramsIndex = m_params;
507     SetInputToAlltensor();
508     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
509 
510     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
511     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
512     std::shared_ptr<NNTensor> tensor = TransToNNTensor(OH_NN_BOOL, m_param_dim, nullptr,
513         OH_NN_FULL_CONNECTION_USE_AXIS);
514     bool *useAxisValue = new (std::nothrow) bool(false);
515     EXPECT_NE(nullptr, useAxisValue);
516     tensor->SetBuffer(useAxisValue, sizeof(bool));
517     m_allTensors.emplace_back(tensor);
518     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
519 
520     EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
521 }
522 
523 /**
524  * @tc.name: fullconnection_getprimitive_axis_001
525  * @tc.desc: Verify the behavior of the GetPrimitive function
526  * @tc.type: FUNC
527  */
528 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_getprimitive_axis_001, TestSize.Level1)
529 {
530     m_inputsIndex = m_inputs;
531     m_paramsIndex = m_params;
532     SetInputToAlltensor();
533     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
534 
535     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
536     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
537     SetUseAxis(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_USE_AXIS);
538     SetHasBias(OH_NN_BOOL, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_HAS_BIAS);
539 
540     EXPECT_EQ(OH_NN_SUCCESS, m_builder.Build(m_paramsIndex, m_inputsIndex, m_outputsIndex, m_allTensors));
541 
542     LiteGraphTensorPtr primitive = m_builder.GetPrimitive();
543     LiteGraphTensorPtr expectPrimitive = {nullptr, DestroyLiteGraphPrimitive};
544     EXPECT_NE(expectPrimitive, primitive);
545 
546     int returnValue = mindspore::lite::MindIR_FullConnection_GetAxis(primitive.get());
547     EXPECT_EQ(returnValue, 0);
548     bool activationReturn = mindspore::lite::MindIR_FullConnection_GetActivationType(primitive.get());
549     EXPECT_EQ(activationReturn, 0);
550     bool useAxisReturn = mindspore::lite::MindIR_FullConnection_GetUseAxis(primitive.get());
551     EXPECT_EQ(useAxisReturn, true);
552     bool hasBiasReturn = mindspore::lite::MindIR_FullConnection_GetHasBias(primitive.get());
553     EXPECT_EQ(hasBiasReturn, true);
554 }
555 
556 /**
557  * @tc.name: fullconnection_getprimitive_axis_002
558  * @tc.desc: Verify the behavior of the GetPrimitive function
559  * @tc.type: FUNC
560  */
561 HWTEST_F(FullConnectionAxisBuilderTest, fullconnection_getprimitive_axis_002, TestSize.Level1)
562 {
563     m_inputsIndex = m_inputs;
564     m_paramsIndex = m_params;
565     SetInputToAlltensor();
566 
567     SaveOutputTensor(m_outputs, OH_NN_FLOAT32, m_output_dim, nullptr);
568     SetAxis(OH_NN_INT64, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_AXIS);
569     SetActivation(OH_NN_INT8, m_param_dim, nullptr, OH_NN_FULL_CONNECTION_ACTIVATIONTYPE);
570 
571     LiteGraphTensorPtr primitive = m_builder.GetPrimitive();
572     LiteGraphTensorPtr expectPrimitive = {nullptr, DestroyLiteGraphPrimitive};
573     EXPECT_EQ(expectPrimitive, primitive);
574 }
575 } // namespace UnitTest
576 } // namespace NeuralNetworkRuntime
577 } // namespace OHOS