9a48aa7e1c10aa6870ee69e9cd506c4bf3efbda0
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / Shape.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 // WORKAROUND Handle int32_t type input/output
20 TEST_F(GenModelTest, OneOp_Shape)
21 {
22   CircleGen cgen;
23   int in = cgen.addTensor({{1, 3, 3, 2}, circle::TensorType::TensorType_FLOAT32});
24   int out = cgen.addTensor({{4}, circle::TensorType::TensorType_INT32});
25
26   cgen.addOperatorShape({{in}, {out}}, circle::TensorType::TensorType_INT32);
27   cgen.setInputsAndOutputs({in}, {out});
28   _context = std::make_unique<GenModelTestContext>(cgen.finish());
29   _context->addTestCase(
30       TestCaseData{}
31           .addInput<float>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18})
32           .addOutput<int32_t>({1, 3, 3, 2}));
33   _context->setBackends({"cpu"});
34
35   SUCCEED();
36 }
37
38 TEST_F(GenModelTest, OneOp_Shape_Int64)
39 {
40   CircleGen cgen;
41   int in = cgen.addTensor({{1, 3, 3, 2}, circle::TensorType::TensorType_FLOAT32});
42   int out = cgen.addTensor({{1}, circle::TensorType::TensorType_INT64});
43
44   // TODO handle many type in addTestCase
45   cgen.addOperatorShape({{in}, {out}}, circle::TensorType::TensorType_INT64);
46   cgen.setInputsAndOutputs({in}, {out});
47   _context = std::make_unique<GenModelTestContext>(cgen.finish());
48   _context->addTestCase(
49       TestCaseData{}
50           .addInput<float>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18})
51           .addOutput<int64_t>({1, 3, 3, 2}));
52   _context->setBackends({"cpu"});
53
54   SUCCEED();
55 }
56
57 TEST_F(GenModelTest, neg_OneOp_Shape_OutType)
58 {
59   CircleGen cgen;
60   int in = cgen.addTensor({{1, 3, 3, 2}, circle::TensorType::TensorType_INT32});
61   int out = cgen.addTensor({{1}, circle::TensorType::TensorType_UINT8});
62
63   // TODO handle many type in addTestCase
64   cgen.addOperatorShape({{in}, {out}});
65   cgen.setInputsAndOutputs({in}, {out});
66   _context = std::make_unique<GenModelTestContext>(cgen.finish());
67   _context->expectFailModelLoad();
68
69   SUCCEED();
70 }