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 "ops/lstm_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 LSTMBuilderTest : public OpsTest {
28 public:
29 void SetUp() override;
30 void TearDown() override;
31
32 protected:
33 void SaveBidirectional(OH_NN_DataType dataType,
34 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
35 void SaveHasBias(OH_NN_DataType dataType,
36 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
37 void SaveInputSize(OH_NN_DataType dataType,
38 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
39 void SaveHiddenSize(OH_NN_DataType dataType,
40 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
41 void SaveNumLayers(OH_NN_DataType dataType,
42 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
43 void SaveNumDirections(OH_NN_DataType dataType,
44 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
45 void SaveDropout(OH_NN_DataType dataType,
46 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
47 void SaveZoneoutCell(OH_NN_DataType dataType,
48 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
49 void SaveZoneoutHidden(OH_NN_DataType dataType,
50 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
51 void SaveProjSize(OH_NN_DataType dataType,
52 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type);
53 void SetInputTensor();
54 void SetOutputTensor();
55
56 protected:
57 LSTMBuilder m_builder;
58 std::vector<uint32_t> m_inputs {0, 1, 2, 3, 4, 5};
59 std::vector<uint32_t> m_outputs {7, 8, 9};
60 std::vector<uint32_t> m_params {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
61 std::vector<int32_t> m_inputDim {2, 2, 2};
62 std::vector<int32_t> m_inputXDim {2};
63 std::vector<int32_t> m_outputDim {2, 2};
64 std::vector<int32_t> m_outputYDim {2};
65 std::vector<int32_t> m_paramDim {};
66
67 std::shared_ptr<NNTensor> m_tensor {};
68 };
69
SetUp()70 void LSTMBuilderTest::SetUp() {}
71
TearDown()72 void LSTMBuilderTest::TearDown() {}
73
SaveBidirectional(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)74 void LSTMBuilderTest::SaveBidirectional(OH_NN_DataType dataType,
75 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
76 {
77 std::shared_ptr<NNTensor> bidirectionalTensor = TransToNNTensor(dataType, dim, quantParam, type);
78 bool* bidirectionalValue = new (std::nothrow) bool(false);
79 EXPECT_NE(nullptr, bidirectionalValue);
80 bidirectionalTensor->SetBuffer(bidirectionalValue, sizeof(bool));
81 m_allTensors.emplace_back(bidirectionalTensor);
82 }
83
SaveHasBias(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)84 void LSTMBuilderTest::SaveHasBias(OH_NN_DataType dataType,
85 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
86 {
87 std::shared_ptr<NNTensor> hasBiasTensor = TransToNNTensor(dataType, dim, quantParam, type);
88 bool* hasBiasValue = new (std::nothrow) bool(false);
89 EXPECT_NE(nullptr, hasBiasValue);
90 hasBiasTensor->SetBuffer(hasBiasValue, sizeof(bool));
91 m_allTensors.emplace_back(hasBiasTensor);
92 }
93
SaveInputSize(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)94 void LSTMBuilderTest::SaveInputSize(OH_NN_DataType dataType,
95 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
96 {
97 std::shared_ptr<NNTensor> inputSizeTensor = TransToNNTensor(dataType, dim, quantParam, type);
98 int64_t* inputSizeValue = new (std::nothrow) int64_t(0);
99 EXPECT_NE(nullptr, inputSizeValue);
100 inputSizeTensor->SetBuffer(inputSizeValue, sizeof(int64_t));
101 m_allTensors.emplace_back(inputSizeTensor);
102 }
103
SaveHiddenSize(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)104 void LSTMBuilderTest::SaveHiddenSize(OH_NN_DataType dataType,
105 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
106 {
107 std::shared_ptr<NNTensor> hiddenSizeTensor = TransToNNTensor(dataType, dim, quantParam, type);
108 int64_t* hiddenSizeValue = new (std::nothrow) int64_t(0);
109 EXPECT_NE(nullptr, hiddenSizeValue);
110 hiddenSizeTensor->SetBuffer(hiddenSizeValue, sizeof(int64_t));
111 m_allTensors.emplace_back(hiddenSizeTensor);
112 }
113
SaveNumLayers(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)114 void LSTMBuilderTest::SaveNumLayers(OH_NN_DataType dataType,
115 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
116 {
117 std::shared_ptr<NNTensor> numLayersTensor = TransToNNTensor(dataType, dim, quantParam, type);
118 int64_t* numLayersValue = new (std::nothrow) int64_t(0);
119 EXPECT_NE(nullptr, numLayersValue);
120 numLayersTensor->SetBuffer(numLayersValue, sizeof(int64_t));
121 m_allTensors.emplace_back(numLayersTensor);
122 }
123
SaveNumDirections(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)124 void LSTMBuilderTest::SaveNumDirections(OH_NN_DataType dataType,
125 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
126 {
127 std::shared_ptr<NNTensor> numDirectionsTensor = TransToNNTensor(dataType, dim, quantParam, type);
128 int64_t* numDirectionsValue = new (std::nothrow) int64_t(0);
129 EXPECT_NE(nullptr, numDirectionsValue);
130 numDirectionsTensor->SetBuffer(numDirectionsValue, sizeof(int64_t));
131 m_allTensors.emplace_back(numDirectionsTensor);
132 }
133
SaveDropout(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)134 void LSTMBuilderTest::SaveDropout(OH_NN_DataType dataType,
135 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
136 {
137 std::shared_ptr<NNTensor> dropoutTensor = TransToNNTensor(dataType, dim, quantParam, type);
138 float* dropoutValue = new (std::nothrow) float(0.0f);
139 EXPECT_NE(nullptr, dropoutValue);
140 dropoutTensor->SetBuffer(dropoutValue, sizeof(float));
141 m_allTensors.emplace_back(dropoutTensor);
142 }
143
SaveZoneoutCell(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)144 void LSTMBuilderTest::SaveZoneoutCell(OH_NN_DataType dataType,
145 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
146 {
147 std::shared_ptr<NNTensor> zoneoutCellTensor = TransToNNTensor(dataType, dim, quantParam, type);
148 float* zoneoutCellValue = new (std::nothrow) float(0.0f);
149 EXPECT_NE(nullptr, zoneoutCellValue);
150 zoneoutCellTensor->SetBuffer(zoneoutCellValue, sizeof(float));
151 m_allTensors.emplace_back(zoneoutCellTensor);
152 }
153
SaveZoneoutHidden(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)154 void LSTMBuilderTest::SaveZoneoutHidden(OH_NN_DataType dataType,
155 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
156 {
157 std::shared_ptr<NNTensor> zoneoutHiddenTensor = TransToNNTensor(dataType, dim, quantParam, type);
158 float* zoneoutHiddenValue = new (std::nothrow) float(0.0f);
159 EXPECT_NE(nullptr, zoneoutHiddenValue);
160 zoneoutHiddenTensor->SetBuffer(zoneoutHiddenValue, sizeof(float));
161 m_allTensors.emplace_back(zoneoutHiddenTensor);
162 }
163
SaveProjSize(OH_NN_DataType dataType,const std::vector<int32_t> & dim,const OH_NN_QuantParam * quantParam,OH_NN_TensorType type)164 void LSTMBuilderTest::SaveProjSize(OH_NN_DataType dataType,
165 const std::vector<int32_t> &dim, const OH_NN_QuantParam* quantParam, OH_NN_TensorType type)
166 {
167 std::shared_ptr<NNTensor> projSizeTensor = TransToNNTensor(dataType, dim, quantParam, type);
168 int64_t* projSizeValue = new (std::nothrow) int64_t(0.0f);
169 EXPECT_NE(nullptr, projSizeValue);
170 projSizeTensor->SetBuffer(projSizeValue, sizeof(int64_t));
171 m_allTensors.emplace_back(projSizeTensor);
172 }
173
SetInputTensor()174 void LSTMBuilderTest::SetInputTensor()
175 {
176 m_inputsIndex = m_inputs;
177 std::shared_ptr<NNTensor> inputTensor;
178 inputTensor = TransToNNTensor(OH_NN_FLOAT32, m_inputDim, nullptr, OH_NN_TENSOR);
179 m_allTensors.emplace_back(inputTensor);
180
181 std::shared_ptr<NNTensor> hxTensor;
182 hxTensor = TransToNNTensor(OH_NN_FLOAT32, m_inputXDim, nullptr, OH_NN_TENSOR);
183 m_allTensors.emplace_back(hxTensor);
184
185 std::shared_ptr<NNTensor> cxTensor;
186 cxTensor = TransToNNTensor(OH_NN_FLOAT32, m_inputXDim, nullptr, OH_NN_TENSOR);
187 m_allTensors.emplace_back(cxTensor);
188
189 std::shared_ptr<NNTensor> wihTensor;
190 wihTensor = TransToNNTensor(OH_NN_FLOAT32, m_inputXDim, nullptr, OH_NN_TENSOR);
191 m_allTensors.emplace_back(wihTensor);
192
193 std::shared_ptr<NNTensor> whhTensor;
194 whhTensor = TransToNNTensor(OH_NN_FLOAT32, m_inputXDim, nullptr, OH_NN_TENSOR);
195 m_allTensors.emplace_back(whhTensor);
196
197 std::shared_ptr<NNTensor> bihTensor;
198 bihTensor = TransToNNTensor(OH_NN_FLOAT32, m_inputXDim, nullptr, OH_NN_TENSOR);
199 m_allTensors.emplace_back(bihTensor);
200
201 std::shared_ptr<NNTensor> bhhTensor;
202 bhhTensor = TransToNNTensor(OH_NN_FLOAT32, m_inputXDim, nullptr, OH_NN_TENSOR);
203 m_allTensors.emplace_back(bhhTensor);
204 }
205
SetOutputTensor()206 void LSTMBuilderTest::SetOutputTensor()
207 {
208 m_outputsIndex = m_outputs;
209 std::shared_ptr<NNTensor> outputTensor;
210 outputTensor = TransToNNTensor(OH_NN_FLOAT32, m_outputDim, nullptr, OH_NN_TENSOR);
211 m_allTensors.emplace_back(outputTensor);
212
213 std::shared_ptr<NNTensor> hyTensor;
214 hyTensor = TransToNNTensor(OH_NN_FLOAT32, m_outputYDim, nullptr, OH_NN_TENSOR);
215 m_allTensors.emplace_back(hyTensor);
216
217 std::shared_ptr<NNTensor> cyTensor;
218 cyTensor = TransToNNTensor(OH_NN_FLOAT32, m_outputYDim, nullptr, OH_NN_TENSOR);
219 m_allTensors.emplace_back(cyTensor);
220 }
221
222 /**
223 * @tc.name: LSTM_build_001
224 * @tc.desc: Verify that the build function returns a successful message.
225 * @tc.type: FUNC
226 */
227 HWTEST_F(LSTMBuilderTest, LSTM_build_001, TestSize.Level1)
228 {
229 SetInputTensor();
230 SetOutputTensor();
231
232 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
233 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
234 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
235 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
236 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
237 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
238 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
239 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
240 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
241 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
242
243 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
244 EXPECT_EQ(OH_NN_SUCCESS, ret);
245 }
246
247 /**
248 * @tc.name: LSTM_build_002
249 * @tc.desc: Verify that the build function returns a failed message with true m_isBuild.
250 * @tc.type: FUNC
251 */
252 HWTEST_F(LSTMBuilderTest, LSTM_build_002, TestSize.Level1)
253 {
254 SetInputTensor();
255 SetOutputTensor();
256
257 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
258 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
259 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
260 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
261 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
262 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
263 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
264 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
265 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
266 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
267
268 EXPECT_EQ(OH_NN_SUCCESS, m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors));
269 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
270 EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, ret);
271 }
272
273 /**
274 * @tc.name: LSTM_build_003
275 * @tc.desc: Verify that the build function returns a failed message with invalided input.
276 * @tc.type: FUNC
277 */
278 HWTEST_F(LSTMBuilderTest, LSTM_build_003, TestSize.Level1)
279 {
280 m_inputs = {0, 1, 2, 3, 4, 5, 6};
281 m_outputs = {7, 8, 9};
282 m_params = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
283
284 SetInputTensor();
285 SetOutputTensor();
286
287 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
288 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
289 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
290 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
291 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
292 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
293 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
294 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
295 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
296 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
297
298 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
299 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
300 }
301
302 /**
303 * @tc.name: LSTM_build_004
304 * @tc.desc: Verify that the build function returns a failed message with invalided output.
305 * @tc.type: FUNC
306 */
307 HWTEST_F(LSTMBuilderTest, LSTM_build_004, TestSize.Level1)
308 {
309 m_outputs = {6, 7, 8, 9};
310 m_params = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
311
312 SetInputTensor();
313 SetOutputTensor();
314
315 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
316 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
317 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
318 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
319 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
320 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
321 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
322 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
323 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
324 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
325
326 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
327 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
328 }
329
330 /**
331 * @tc.name: LSTM_build_005
332 * @tc.desc: Verify that the build function returns a failed message with empty allTensor.
333 * @tc.type: FUNC
334 */
335 HWTEST_F(LSTMBuilderTest, LSTM_build_005, TestSize.Level1)
336 {
337 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputs, m_outputs, m_allTensors);
338 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
339 }
340
341 /**
342 * @tc.name: LSTM_build_006
343 * @tc.desc: Verify that the build function returns a failed message without output tensor.
344 * @tc.type: FUNC
345 */
346 HWTEST_F(LSTMBuilderTest, LSTM_build_006, TestSize.Level1)
347 {
348 SetInputTensor();
349
350 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputs, m_allTensors);
351 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
352 }
353
354 /**
355 * @tc.name: LSTM_build_007
356 * @tc.desc: Verify that the build function returns a failed message with invalid bidirectional's dataType.
357 * @tc.type: FUNC
358 */
359 HWTEST_F(LSTMBuilderTest, LSTM_build_007, TestSize.Level1)
360 {
361 SetInputTensor();
362 SetOutputTensor();
363
364 std::shared_ptr<NNTensor> bidirectionalTensor = TransToNNTensor(OH_NN_INT64, m_paramDim,
365 nullptr, OH_NN_LSTM_BIDIRECTIONAL);
366 int64_t* bidirectionalValue = new (std::nothrow) int64_t [1]{0};
367 EXPECT_NE(nullptr, bidirectionalValue);
368 bidirectionalTensor->SetBuffer(bidirectionalValue, sizeof(int64_t));
369 m_allTensors.emplace_back(bidirectionalTensor);
370 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
371 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
372 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
373 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
374 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
375 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
376 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
377 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
378 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
379
380 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
381 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
382 }
383
384 /**
385 * @tc.name: LSTM_build_008
386 * @tc.desc: Verify that the build function returns a failed message with invalid has_bias's dataType.
387 * @tc.type: FUNC
388 */
389 HWTEST_F(LSTMBuilderTest, LSTM_build_008, TestSize.Level1)
390 {
391 SetInputTensor();
392 SetOutputTensor();
393
394 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
395 std::shared_ptr<NNTensor> hasBiasTensor = TransToNNTensor(OH_NN_INT64, m_paramDim,
396 nullptr, OH_NN_LSTM_HAS_BIAS);
397 int64_t* hasBiasValue = new (std::nothrow) int64_t [1]{0};
398 EXPECT_NE(nullptr, hasBiasValue);
399 hasBiasTensor->SetBuffer(hasBiasValue, sizeof(int64_t));
400 m_allTensors.emplace_back(hasBiasTensor);
401 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
402 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
403 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
404 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
405 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
406 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
407 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
408 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
409
410 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
411 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
412 }
413
414 /**
415 * @tc.name: LSTM_build_009
416 * @tc.desc: Verify that the build function returns a failed message with invalid input_size's dataType.
417 * @tc.type: FUNC
418 */
419 HWTEST_F(LSTMBuilderTest, LSTM_build_009, TestSize.Level1)
420 {
421 SetInputTensor();
422 SetOutputTensor();
423
424 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
425 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
426 std::shared_ptr<NNTensor> inputSizeTensor = TransToNNTensor(OH_NN_FLOAT32, m_paramDim,
427 nullptr, OH_NN_LSTM_INPUT_SIZE);
__anon85ecba710102null428 float* inputSizeValue = new (std::nothrow) float [1]{0.0f};
429 EXPECT_NE(nullptr, inputSizeValue);
430 inputSizeTensor->SetBuffer(inputSizeValue, sizeof(float));
431 m_allTensors.emplace_back(inputSizeTensor);
432 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
433 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
434 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
435 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
436 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
437 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
438 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
439
440 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
441 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
442 }
443
444 /**
445 * @tc.name: LSTM_build_010
446 * @tc.desc: Verify that the build function returns a failed message with invalid hidden_size's dataType.
447 * @tc.type: FUNC
448 */
449 HWTEST_F(LSTMBuilderTest, LSTM_build_010, TestSize.Level1)
450 {
451 SetInputTensor();
452 SetOutputTensor();
453
454 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
455 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
456 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
457 std::shared_ptr<NNTensor> hiddenSizeTensor = TransToNNTensor(OH_NN_FLOAT32, m_paramDim,
458 nullptr, OH_NN_LSTM_HIDDEN_SIZE);
__anon85ecba710202null459 float* hiddenSizeValue = new (std::nothrow) float [1]{0.0f};
460 EXPECT_NE(nullptr, hiddenSizeValue);
461 hiddenSizeTensor->SetBuffer(hiddenSizeValue, sizeof(float));
462 m_allTensors.emplace_back(hiddenSizeTensor);
463 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
464 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
465 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
466 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
467 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
468 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
469
470 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
471 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
472 }
473
474 /**
475 * @tc.name: LSTM_build_011
476 * @tc.desc: Verify that the build function returns a failed message with invalid num_layers's dataType.
477 * @tc.type: FUNC
478 */
479 HWTEST_F(LSTMBuilderTest, LSTM_build_011, TestSize.Level1)
480 {
481 SetInputTensor();
482 SetOutputTensor();
483
484 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
485 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
486 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
487 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
488 std::shared_ptr<NNTensor> numLayersTensor = TransToNNTensor(OH_NN_FLOAT32, m_paramDim,
489 nullptr, OH_NN_LSTM_NUM_LAYERS);
__anon85ecba710302null490 float* numLayersValue = new (std::nothrow) float [1]{0.0f};
491 EXPECT_NE(nullptr, numLayersValue);
492 numLayersTensor->SetBuffer(numLayersValue, sizeof(float));
493 m_allTensors.emplace_back(numLayersTensor);
494 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
495 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
496 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
497 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
498 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
499
500 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
501 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
502 }
503
504 /**
505 * @tc.name: LSTM_build_012
506 * @tc.desc: Verify that the build function returns a failed message with invalid num_directions's dataType.
507 * @tc.type: FUNC
508 */
509 HWTEST_F(LSTMBuilderTest, LSTM_build_012, TestSize.Level1)
510 {
511 SetInputTensor();
512 SetOutputTensor();
513
514 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
515 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
516 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
517 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
518 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
519 std::shared_ptr<NNTensor> numDirectionsTensor = TransToNNTensor(OH_NN_FLOAT32, m_paramDim,
520 nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
__anon85ecba710402null521 float* numDirectionsValue = new (std::nothrow) float [1]{0.0f};
522 EXPECT_NE(nullptr, numDirectionsValue);
523 numDirectionsTensor->SetBuffer(numDirectionsValue, sizeof(float));
524 m_allTensors.emplace_back(numDirectionsTensor);
525 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
526 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
527 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
528 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
529
530 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
531 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
532 }
533
534 /**
535 * @tc.name: LSTM_build_013
536 * @tc.desc: Verify that the build function returns a failed message with invalid dropout's dataType.
537 * @tc.type: FUNC
538 */
539 HWTEST_F(LSTMBuilderTest, LSTM_build_013, TestSize.Level1)
540 {
541 SetInputTensor();
542 SetOutputTensor();
543
544 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
545 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
546 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
547 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
548 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
549 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
550 std::shared_ptr<NNTensor> dropoutTensor = TransToNNTensor(OH_NN_INT64, m_paramDim,
551 nullptr, OH_NN_LSTM_DROPOUT);
552 int64_t* dropoutValue = new (std::nothrow) int64_t [1]{0};
553 EXPECT_NE(nullptr, dropoutValue);
554 dropoutTensor->SetBuffer(dropoutValue, sizeof(int64_t));
555 m_allTensors.emplace_back(dropoutTensor);
556 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
557 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
558 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
559
560 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
561 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
562 }
563
564 /**
565 * @tc.name: LSTM_build_014
566 * @tc.desc: Verify that the build function returns a failed message with invalid zoneout_cell's dataType.
567 * @tc.type: FUNC
568 */
569 HWTEST_F(LSTMBuilderTest, LSTM_build_014, TestSize.Level1)
570 {
571 SetInputTensor();
572 SetOutputTensor();
573
574 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
575 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
576 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
577 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
578 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
579 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
580 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
581 std::shared_ptr<NNTensor> zoneoutCellTensor = TransToNNTensor(OH_NN_INT64, m_paramDim,
582 nullptr, OH_NN_LSTM_ZONEOUT_CELL);
583 int64_t* zoneoutCellValue = new (std::nothrow) int64_t [1]{0};
584 EXPECT_NE(nullptr, zoneoutCellValue);
585 zoneoutCellTensor->SetBuffer(zoneoutCellValue, sizeof(int64_t));
586 m_allTensors.emplace_back(zoneoutCellTensor);
587 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
588 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
589
590 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
591 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
592 }
593
594 /**
595 * @tc.name: LSTM_build_015
596 * @tc.desc: Verify that the build function returns a failed message with invalid zoneout_hidden's dataType.
597 * @tc.type: FUNC
598 */
599 HWTEST_F(LSTMBuilderTest, LSTM_build_015, TestSize.Level1)
600 {
601 SetInputTensor();
602 SetOutputTensor();
603
604 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
605 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
606 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
607 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
608 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
609 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
610 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
611 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
612 std::shared_ptr<NNTensor> zoneoutHiddenTensor = TransToNNTensor(OH_NN_INT64, m_paramDim,
613 nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
614 int64_t* zoneoutHiddenValue = new (std::nothrow) int64_t [1]{0};
615 EXPECT_NE(nullptr, zoneoutHiddenValue);
616 zoneoutHiddenTensor->SetBuffer(zoneoutHiddenValue, sizeof(int64_t));
617 m_allTensors.emplace_back(zoneoutHiddenTensor);
618 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
619
620 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
621 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
622 }
623
624 /**
625 * @tc.name: LSTM_build_016
626 * @tc.desc: Verify that the build function returns a failed message with invalid proj_size's dataType.
627 * @tc.type: FUNC
628 */
629 HWTEST_F(LSTMBuilderTest, LSTM_build_016, TestSize.Level1)
630 {
631 SetInputTensor();
632 SetOutputTensor();
633
634 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
635 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
636 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
637 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
638 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
639 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
640 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
641 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
642 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
643 std::shared_ptr<NNTensor> projSizeTensor = TransToNNTensor(OH_NN_FLOAT32, m_paramDim,
644 nullptr, OH_NN_LSTM_PROJ_SIZE);
__anon85ecba710502null645 float* projSizeValue = new (std::nothrow) float [1]{0.0f};
646 EXPECT_NE(nullptr, projSizeValue);
647 projSizeTensor->SetBuffer(projSizeValue, sizeof(float));
648 m_allTensors.emplace_back(projSizeTensor);
649
650 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
651 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
652 }
653
654 /**
655 * @tc.name: LSTM_build_017
656 * @tc.desc: Verify that the build function returns a failed message with passing invalid bidirectional param.
657 * @tc.type: FUNC
658 */
659 HWTEST_F(LSTMBuilderTest, LSTM_build_017, TestSize.Level1)
660 {
661 SetInputTensor();
662 SetOutputTensor();
663
664 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_MUL_ACTIVATION_TYPE);
665 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
666 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
667 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
668 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
669 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
670 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
671 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
672 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
673 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
674
675 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
676 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
677 }
678
679 /**
680 * @tc.name: LSTM_build_018
681 * @tc.desc: Verify that the build function returns a failed message with passing invalid has_bias param.
682 * @tc.type: FUNC
683 */
684 HWTEST_F(LSTMBuilderTest, LSTM_build_018, TestSize.Level1)
685 {
686 SetInputTensor();
687 SetOutputTensor();
688
689 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
690 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_MUL_ACTIVATION_TYPE);
691 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
692 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
693 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
694 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
695 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
696 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
697 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
698 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
699
700 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
701 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
702 }
703
704 /**
705 * @tc.name: LSTM_build_019
706 * @tc.desc: Verify that the build function returns a failed message with passing invalid input_size param.
707 * @tc.type: FUNC
708 */
709 HWTEST_F(LSTMBuilderTest, LSTM_build_019, TestSize.Level1)
710 {
711 SetInputTensor();
712 SetOutputTensor();
713
714 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
715 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
716 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_MUL_ACTIVATION_TYPE);
717 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
718 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
719 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
720 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
721 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
722 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
723 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
724
725 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
726 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
727 }
728
729 /**
730 * @tc.name: LSTM_build_020
731 * @tc.desc: Verify that the build function returns a failed message with passing invalid hidden_size param.
732 * @tc.type: FUNC
733 */
734 HWTEST_F(LSTMBuilderTest, LSTM_build_020, TestSize.Level1)
735 {
736 SetInputTensor();
737 SetOutputTensor();
738
739 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
740 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
741 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
742 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_MUL_ACTIVATION_TYPE);
743 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
744 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
745 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
746 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
747 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
748 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
749
750 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
751 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
752 }
753
754 /**
755 * @tc.name: LSTM_build_021
756 * @tc.desc: Verify that the build function returns a failed message with passing invalid num_layers param.
757 * @tc.type: FUNC
758 */
759 HWTEST_F(LSTMBuilderTest, LSTM_build_021, TestSize.Level1)
760 {
761 SetInputTensor();
762 SetOutputTensor();
763
764 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
765 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
766 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
767 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
768 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_MUL_ACTIVATION_TYPE);
769 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
770 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
771 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
772 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
773 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
774
775 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
776 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
777 }
778
779 /**
780 * @tc.name: LSTM_build_022
781 * @tc.desc: Verify that the build function returns a failed message with passing invalid num_directions param.
782 * @tc.type: FUNC
783 */
784 HWTEST_F(LSTMBuilderTest, LSTM_build_022, TestSize.Level1)
785 {
786 SetInputTensor();
787 SetOutputTensor();
788
789 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
790 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
791 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
792 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
793 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
794 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_MUL_ACTIVATION_TYPE);
795 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
796 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
797 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
798 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
799
800 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
801 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
802 }
803
804 /**
805 * @tc.name: LSTM_build_023
806 * @tc.desc: Verify that the build function returns a failed message with passing invalid dropout param.
807 * @tc.type: FUNC
808 */
809 HWTEST_F(LSTMBuilderTest, LSTM_build_023, TestSize.Level1)
810 {
811 SetInputTensor();
812 SetOutputTensor();
813
814 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
815 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
816 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
817 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
818 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
819 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
820 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_MUL_ACTIVATION_TYPE);
821 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
822 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
823 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
824
825 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
826 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
827 }
828
829 /**
830 * @tc.name: LSTM_build_024
831 * @tc.desc: Verify that the build function returns a failed message with passing invalid zoneout_cell param.
832 * @tc.type: FUNC
833 */
834 HWTEST_F(LSTMBuilderTest, LSTM_build_024, TestSize.Level1)
835 {
836 SetInputTensor();
837 SetOutputTensor();
838
839 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
840 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
841 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
842 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
843 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
844 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
845 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
846 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_MUL_ACTIVATION_TYPE);
847 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
848 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
849
850 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
851 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
852 }
853
854 /**
855 * @tc.name: LSTM_build_025
856 * @tc.desc: Verify that the build function returns a failed message with passing invalid zoneout_cell param.
857 * @tc.type: FUNC
858 */
859 HWTEST_F(LSTMBuilderTest, LSTM_build_025, TestSize.Level1)
860 {
861 SetInputTensor();
862 SetOutputTensor();
863
864 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
865 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
866 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
867 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
868 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
869 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
870 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
871 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_MUL_ACTIVATION_TYPE);
872 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
873 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
874
875 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
876 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
877 }
878
879 /**
880 * @tc.name: LSTM_build_026
881 * @tc.desc: Verify that the build function returns a failed message with passing invalid zoneout_hidden param.
882 * @tc.type: FUNC
883 */
884 HWTEST_F(LSTMBuilderTest, LSTM_build_026, TestSize.Level1)
885 {
886 SetInputTensor();
887 SetOutputTensor();
888
889 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
890 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
891 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
892 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
893 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
894 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
895 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
896 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
897 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_MUL_ACTIVATION_TYPE);
898 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
899
900 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
901 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
902 }
903
904 /**
905 * @tc.name: LSTM_build_027
906 * @tc.desc: Verify that the build function returns a failed message with passing invalid proj_size param.
907 * @tc.type: FUNC
908 */
909 HWTEST_F(LSTMBuilderTest, LSTM_build_027, TestSize.Level1)
910 {
911 SetInputTensor();
912 SetOutputTensor();
913
914 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
915 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
916 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
917 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
918 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
919 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
920 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
921 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
922 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
923 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_MUL_ACTIVATION_TYPE);
924
925 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
926 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
927 }
928
929 /**
930 * @tc.name: LSTM_build_028
931 * @tc.desc: Verify that the build function returns a failed message without set buffer for bidirectional.
932 * @tc.type: FUNC
933 */
934 HWTEST_F(LSTMBuilderTest, LSTM_build_028, TestSize.Level1)
935 {
936 SetInputTensor();
937 SetOutputTensor();
938
939 std::shared_ptr<NNTensor> bidirectionalTensor = TransToNNTensor(OH_NN_BOOL, m_paramDim,
940 nullptr, OH_NN_LSTM_BIDIRECTIONAL);
941 m_allTensors.emplace_back(bidirectionalTensor);
942 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
943 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
944 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
945 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
946 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
947 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
948 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
949 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
950 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
951
952 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
953 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
954 }
955
956 /**
957 * @tc.name: LSTM_build_029
958 * @tc.desc: Verify that the build function returns a failed message without set buffer for has_bias.
959 * @tc.type: FUNC
960 */
961 HWTEST_F(LSTMBuilderTest, LSTM_build_029, TestSize.Level1)
962 {
963 SetInputTensor();
964 SetOutputTensor();
965
966 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
967 std::shared_ptr<NNTensor> hasBiasTensor = TransToNNTensor(OH_NN_BOOL, m_paramDim,
968 nullptr, OH_NN_LSTM_HAS_BIAS);
969 m_allTensors.emplace_back(hasBiasTensor);
970 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
971 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
972 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
973 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
974 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
975 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
976 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
977 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
978
979 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
980 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
981 }
982
983 /**
984 * @tc.name: LSTM_build_030
985 * @tc.desc: Verify that the build function returns a failed message without set buffer for input_size.
986 * @tc.type: FUNC
987 */
988 HWTEST_F(LSTMBuilderTest, LSTM_build_030, TestSize.Level1)
989 {
990 SetInputTensor();
991 SetOutputTensor();
992
993 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
994 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
995 std::shared_ptr<NNTensor> inputSizeTensor = TransToNNTensor(OH_NN_INT64, m_paramDim,
996 nullptr, OH_NN_LSTM_INPUT_SIZE);
997 m_allTensors.emplace_back(inputSizeTensor);
998 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
999 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
1000 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
1001 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
1002 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
1003 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
1004 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
1005
1006 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
1007 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1008 }
1009
1010 /**
1011 * @tc.name: LSTM_build_031
1012 * @tc.desc: Verify that the build function returns a failed message without set buffer for hidden_size.
1013 * @tc.type: FUNC
1014 */
1015 HWTEST_F(LSTMBuilderTest, LSTM_build_031, TestSize.Level1)
1016 {
1017 SetInputTensor();
1018 SetOutputTensor();
1019
1020 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
1021 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
1022 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
1023 std::shared_ptr<NNTensor> hiddenSizeTensor = TransToNNTensor(OH_NN_INT64, m_paramDim,
1024 nullptr, OH_NN_LSTM_HIDDEN_SIZE);
1025 m_allTensors.emplace_back(hiddenSizeTensor);
1026 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
1027 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
1028 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
1029 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
1030 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
1031 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
1032
1033 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
1034 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1035 }
1036
1037 /**
1038 * @tc.name: LSTM_build_032
1039 * @tc.desc: Verify that the build function returns a failed message without set buffer for num_layers.
1040 * @tc.type: FUNC
1041 */
1042 HWTEST_F(LSTMBuilderTest, LSTM_build_032, TestSize.Level1)
1043 {
1044 SetInputTensor();
1045 SetOutputTensor();
1046
1047 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
1048 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
1049 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
1050 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
1051 std::shared_ptr<NNTensor> numLayersTensor = TransToNNTensor(OH_NN_INT64, m_paramDim,
1052 nullptr, OH_NN_LSTM_NUM_LAYERS);
1053 m_allTensors.emplace_back(numLayersTensor);
1054 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
1055 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
1056 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
1057 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
1058 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
1059
1060 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
1061 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1062 }
1063
1064 /**
1065 * @tc.name: LSTM_build_033
1066 * @tc.desc: Verify that the build function returns a failed message without set buffer for num_directions.
1067 * @tc.type: FUNC
1068 */
1069 HWTEST_F(LSTMBuilderTest, LSTM_build_033, TestSize.Level1)
1070 {
1071 SetInputTensor();
1072 SetOutputTensor();
1073
1074 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
1075 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
1076 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
1077 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
1078 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
1079 std::shared_ptr<NNTensor> numDirectionsTensor = TransToNNTensor(OH_NN_INT64, m_paramDim,
1080 nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
1081 m_allTensors.emplace_back(numDirectionsTensor);
1082 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
1083 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
1084 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
1085 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
1086
1087 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
1088 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1089 }
1090
1091 /**
1092 * @tc.name: LSTM_build_034
1093 * @tc.desc: Verify that the build function returns a failed message without set buffer for dropout.
1094 * @tc.type: FUNC
1095 */
1096 HWTEST_F(LSTMBuilderTest, LSTM_build_034, TestSize.Level1)
1097 {
1098 SetInputTensor();
1099 SetOutputTensor();
1100
1101 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
1102 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
1103 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
1104 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
1105 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
1106 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
1107 std::shared_ptr<NNTensor> dropoutTensor = TransToNNTensor(OH_NN_FLOAT32, m_paramDim,
1108 nullptr, OH_NN_LSTM_DROPOUT);
1109 m_allTensors.emplace_back(dropoutTensor);
1110 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
1111 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
1112 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
1113
1114 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
1115 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1116 }
1117
1118 /**
1119 * @tc.name: LSTM_build_035
1120 * @tc.desc: Verify that the build function returns a failed message without set buffer for zoneout_cell.
1121 * @tc.type: FUNC
1122 */
1123 HWTEST_F(LSTMBuilderTest, LSTM_build_035, TestSize.Level1)
1124 {
1125 SetInputTensor();
1126 SetOutputTensor();
1127
1128 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
1129 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
1130 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
1131 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
1132 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
1133 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
1134 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
1135 std::shared_ptr<NNTensor> zoneoutCellTensor = TransToNNTensor(OH_NN_FLOAT32, m_paramDim,
1136 nullptr, OH_NN_LSTM_ZONEOUT_CELL);
1137 m_allTensors.emplace_back(zoneoutCellTensor);
1138 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
1139 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
1140
1141 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
1142 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1143 }
1144
1145 /**
1146 * @tc.name: LSTM_build_036
1147 * @tc.desc: Verify that the build function returns a failed message without set buffer for zoneout_hidden.
1148 * @tc.type: FUNC
1149 */
1150 HWTEST_F(LSTMBuilderTest, LSTM_build_036, TestSize.Level1)
1151 {
1152 SetInputTensor();
1153 SetOutputTensor();
1154
1155 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
1156 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
1157 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
1158 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
1159 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
1160 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
1161 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
1162 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
1163 std::shared_ptr<NNTensor> zoneoutHiddenTensor = TransToNNTensor(OH_NN_FLOAT32, m_paramDim,
1164 nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
1165 m_allTensors.emplace_back(zoneoutHiddenTensor);
1166 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
1167
1168 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
1169 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1170 }
1171
1172 /**
1173 * @tc.name: LSTM_build_037
1174 * @tc.desc: Verify that the build function returns a failed message without set buffer for proj_size.
1175 * @tc.type: FUNC
1176 */
1177 HWTEST_F(LSTMBuilderTest, LSTM_build_037, TestSize.Level1)
1178 {
1179 SetInputTensor();
1180 SetOutputTensor();
1181
1182 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
1183 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
1184 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
1185 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
1186 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
1187 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
1188 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
1189 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
1190 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
1191 std::shared_ptr<NNTensor> projSizeTensor = TransToNNTensor(OH_NN_INT64, m_paramDim,
1192 nullptr, OH_NN_LSTM_PROJ_SIZE);
1193 m_allTensors.emplace_back(projSizeTensor);
1194
1195 OH_NN_ReturnCode ret = m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors);
1196 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
1197 }
1198
1199 /**
1200 * @tc.name: LSTM_getprimitive_001
1201 * @tc.desc: Verify that the getPrimitive function returns a successful message.
1202 * @tc.type: FUNC
1203 */
1204 HWTEST_F(LSTMBuilderTest, LSTM_getprimitive_001, TestSize.Level1)
1205 {
1206 SetInputTensor();
1207 SetOutputTensor();
1208
1209 SaveBidirectional(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_BIDIRECTIONAL);
1210 SaveHasBias(OH_NN_BOOL, m_paramDim, nullptr, OH_NN_LSTM_HAS_BIAS);
1211 SaveInputSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_INPUT_SIZE);
1212 SaveHiddenSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_HIDDEN_SIZE);
1213 SaveNumLayers(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_LAYERS);
1214 SaveNumDirections(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_NUM_DIRECTIONS);
1215 SaveDropout(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_DROPOUT);
1216 SaveZoneoutCell(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_CELL);
1217 SaveZoneoutHidden(OH_NN_FLOAT32, m_paramDim, nullptr, OH_NN_LSTM_ZONEOUT_HIDDEN);
1218 SaveProjSize(OH_NN_INT64, m_paramDim, nullptr, OH_NN_LSTM_PROJ_SIZE);
1219
1220 bool bidirectionalValue = false;
1221 bool hasBiasValue = false;
1222 int64_t inputSizeValue = 0;
1223 int64_t hiddenSizeValue = 0;
1224 int64_t numLayersValue = 0;
1225 int64_t numDirectionsValue = 0;
1226 float dropoutValue = 0.0f;
1227 float zoneoutCellValue = 0.0f;
1228 float zoneoutHiddenValue = 0.0f;
1229 int64_t projSizeValue = 0;
1230
1231 EXPECT_EQ(OH_NN_SUCCESS, m_builder.Build(m_params, m_inputsIndex, m_outputsIndex, m_allTensors));
1232 LiteGraphPrimitvePtr primitive = m_builder.GetPrimitive();
1233 LiteGraphPrimitvePtr expectPrimitive(nullptr, DestroyLiteGraphPrimitive);
1234 EXPECT_NE(expectPrimitive, primitive);
1235
1236 auto returnBidirectionalValue = mindspore::lite::MindIR_LSTM_GetBidirectional(primitive.get());
1237 EXPECT_EQ(returnBidirectionalValue, bidirectionalValue);
1238 auto returnHasBiasValue = mindspore::lite::MindIR_LSTM_GetHasBias(primitive.get());
1239 EXPECT_EQ(returnHasBiasValue, hasBiasValue);
1240 auto returnInputSizeValue = mindspore::lite::MindIR_LSTM_GetInputSize(primitive.get());
1241 EXPECT_EQ(returnInputSizeValue, inputSizeValue);
1242 auto returnHiddenSizeValue = mindspore::lite::MindIR_LSTM_GetHiddenSize(primitive.get());
1243 EXPECT_EQ(returnHiddenSizeValue, hiddenSizeValue);
1244 auto returnNumLayersValue = mindspore::lite::MindIR_LSTM_GetNumLayers(primitive.get());
1245 EXPECT_EQ(returnNumLayersValue, numLayersValue);
1246 auto returnNumDirectionsValue = mindspore::lite::MindIR_LSTM_GetNumDirections(primitive.get());
1247 EXPECT_EQ(returnNumDirectionsValue, numDirectionsValue);
1248 auto returnDropoutValue = mindspore::lite::MindIR_LSTM_GetDropout(primitive.get());
1249 EXPECT_EQ(returnDropoutValue, dropoutValue);
1250 auto returnZoneoutCellValue = mindspore::lite::MindIR_LSTM_GetZoneoutCell(primitive.get());
1251 EXPECT_EQ(returnZoneoutCellValue, zoneoutCellValue);
1252 auto returnZoneoutHiddenValue = mindspore::lite::MindIR_LSTM_GetZoneoutHidden(primitive.get());
1253 EXPECT_EQ(returnZoneoutHiddenValue, zoneoutHiddenValue);
1254 auto returnProjSizeValue = mindspore::lite::MindIR_LSTM_GetProjSize(primitive.get());
1255 EXPECT_EQ(returnProjSizeValue, projSizeValue);
1256 }
1257
1258 /**
1259 * @tc.name: LSTM_getprimitive_002
1260 * @tc.desc: Verify that the getPrimitive function returns a failed message without build.
1261 * @tc.type: FUNC
1262 */
1263 HWTEST_F(LSTMBuilderTest, LSTM_getprimitive_002, TestSize.Level1)
1264 {
1265 LiteGraphPrimitvePtr primitive = m_builder.GetPrimitive();
1266 LiteGraphPrimitvePtr expectPrimitive(nullptr, DestroyLiteGraphPrimitive);
1267 EXPECT_EQ(expectPrimitive, primitive);
1268 }
1269 }
1270 }
1271 }