Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / Pad.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "GenModelTest.h"
18
19 TEST_F(GenModelTest, OneOp_Pad)
20 {
21   CircleGen cgen;
22   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
23   std::vector<int32_t> padding_data{0, 0, 1, 1, 1, 1, 0, 0};
24   uint32_t padding_buf = cgen.addBuffer(padding_data);
25   int padding = cgen.addTensor({{4, 2}, circle::TensorType::TensorType_INT32, padding_buf});
26   int out = cgen.addTensor({{1, 4, 4, 1}, circle::TensorType::TensorType_FLOAT32});
27
28   cgen.addOperatorPad({{in, padding}, {out}});
29   cgen.setInputsAndOutputs({in}, {out});
30   _context = std::make_unique<GenModelTestContext>(cgen.finish());
31   _context->addTestCase({{{1, 2, 3, 4}}, {{0, 0, 0, 0, 0, 1, 2, 0, 0, 3, 4, 0, 0, 0, 0, 0}}});
32   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
33
34   SUCCEED();
35 }
36
37 TEST_F(GenModelTest, neg_OneOp_Pad_InvalidPadRank)
38 {
39   CircleGen cgen;
40   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
41   std::vector<int32_t> padding_data{1, 1, 1, 1};
42   uint32_t padding_buf = cgen.addBuffer(padding_data);
43   int padding = cgen.addTensor({{4}, circle::TensorType::TensorType_INT32, padding_buf});
44   int out = cgen.addTensor({{1, 4, 4, 1}, circle::TensorType::TensorType_FLOAT32});
45
46   cgen.addOperatorPad({{in, padding}, {out}});
47   cgen.setInputsAndOutputs({in}, {out});
48
49   _context = std::make_unique<GenModelTestContext>(cgen.finish());
50   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
51   _context->setCompileFail();
52
53   SUCCEED();
54 }
55
56 TEST_F(GenModelTest, neg_OneOp_Pad_InvalidPadDim0)
57 {
58   CircleGen cgen;
59   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
60   std::vector<int32_t> padding_data{1, 1, 1, 1};
61   uint32_t padding_buf = cgen.addBuffer(padding_data);
62   int padding = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_INT32, padding_buf});
63   int out = cgen.addTensor({{1, 4, 4, 1}, circle::TensorType::TensorType_FLOAT32});
64
65   cgen.addOperatorPad({{in, padding}, {out}});
66   cgen.setInputsAndOutputs({in}, {out});
67
68   _context = std::make_unique<GenModelTestContext>(cgen.finish());
69   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
70   _context->setCompileFail();
71
72   SUCCEED();
73 }
74
75 TEST_F(GenModelTest, neg_OneOp_Pad_InvalidPadDim1)
76 {
77   CircleGen cgen;
78   int in = cgen.addTensor({{1, 1, 1, 1}, circle::TensorType::TensorType_FLOAT32});
79   std::vector<int32_t> padding_data{1, 1, 1, 1};
80   uint32_t padding_buf = cgen.addBuffer(padding_data);
81   int padding = cgen.addTensor({{4, 1}, circle::TensorType::TensorType_INT32, padding_buf});
82   int out = cgen.addTensor({{2, 2, 2, 2}, circle::TensorType::TensorType_FLOAT32});
83
84   cgen.addOperatorPad({{in, padding}, {out}});
85   cgen.setInputsAndOutputs({in}, {out});
86
87   _context = std::make_unique<GenModelTestContext>(cgen.finish());
88   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
89   _context->setCompileFail();
90
91   SUCCEED();
92 }