Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / nest / core / src / Module.test.cpp
1 /*
2  * Copyright (c) 2018 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 "nest/Module.h"
18
19 #include <gtest/gtest.h>
20
21 TEST(MODULE, create_var)
22 {
23   nest::Module m;
24
25   auto create = [](nest::Module &m) {
26     // This code will invoke 'VarContext &var(void)' method
27     return m.var().make();
28   };
29
30   auto check = [](const nest::Module &m) {
31     // This code will invoke 'const VarContext &var(void) const' method
32     ASSERT_EQ(1, m.var().count());
33   };
34
35   create(m);
36   check(m);
37 }
38
39 TEST(MODULE, create_domain)
40 {
41   nest::Module m;
42
43   auto create = [](nest::Module &m, std::initializer_list<uint32_t> dims) {
44     // This code will invoke 'DomainContext &domain(void)' method
45     return m.domain().make(dims);
46   };
47
48   auto check = [](const nest::Module &m) {
49     // This code will invoke 'const DomainContext &domain(void) const' method
50     ASSERT_EQ(1, m.domain().count());
51   };
52
53   create(m, {1, 3, 3});
54   check(m);
55 }
56
57 TEST(MODULE, push)
58 {
59   nest::Module m;
60
61   auto ifm = m.domain().make({1, 3, 3});
62
63   auto var_ch = m.var().make();
64   auto var_row = m.var().make();
65   auto var_col = m.var().make();
66
67   m.push(ifm(var_ch, var_row, var_col));
68
69   ASSERT_EQ(1, m.block().size());
70   ASSERT_NE(m.block().at(0)->asPush(), nullptr);
71 }
72
73 TEST(MODULE, ret)
74 {
75   nest::Module m;
76
77   auto ifm = m.domain().make({1});
78   auto ofm = m.domain().make({1});
79
80   auto ind = m.var().make();
81
82   m.push(ifm(ind));
83   m.ret(ofm(ind));
84
85   ASSERT_EQ(ofm.id(), m.ret().id());
86   ASSERT_EQ(1, m.ret().sub().rank());
87 }
88
89 TEST(MODULE, copy)
90 {
91   nest::Module orig;
92   nest::Module copy;
93
94   orig = copy;
95
96   orig.var().make();
97
98   ASSERT_EQ(0, copy.var().count());
99 }