Merge test folder of test branch
[iotivity.git] / test / test_manager / ite / tc / container.py
1 '''
2 /******************************************************************
3 *
4 * Copyright 2018 Samsung Electronics All Rights Reserved.
5 *
6 *
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 ******************************************************************/
21 '''
22
23 import os
24
25 from ite.config import *
26 from ite.tc.analyzer import TCAnalyzer
27 from ite.tc.robot_analyzer import RobotTCAnalyzer
28
29 class TestSpecContainer:
30
31     def __init__(self):
32         self.data = dict()
33
34         for platform in TEST_PLATFORM:
35             self.data[platform] = dict()
36
37             for build_type in BUILD_TYPE:
38                 self.data[platform][build_type] = dict()
39
40                 for transport in TEST_TRANSPORT:
41                     self.data[platform][build_type][transport] = dict()
42
43                     for network in TEST_NETWORK:
44                         self.data[platform][build_type][transport][network] = dict()
45
46                         for tctype in TESTCASE_TYPES:
47                             self.data[platform][build_type][transport][network][tctype] = dict()
48
49                             for module in TESTSUITE_MODULES:
50                                 self.data[platform][build_type][transport][network][tctype][module] = dict()
51
52
53     def extract_api_testspec_bysuite(self, tctype, module, testfw, path):
54         analyzer = TCAnalyzer(testfw)
55
56         rootpath = os.path.normcase(path)
57
58         api_valid_convention = True
59         for path, dir, files in os.walk(rootpath):
60             for fname in files:
61                 filepath = os.path.join(path, fname)
62                 if (os.path.isfile(filepath) == False):
63                     continue
64
65                 if not (filepath.endswith('.cpp') or filepath.endswith('.c') or filepath.endswith('.java')):
66                     continue
67
68                 testspec_dict, invalid_list = analyzer.analyze_tc_file(filepath, module)
69
70                 for invalid in invalid_list:
71                     print("=> Invalid Test Case : %s(%d), %s.%s, message:%s" %
72                           (filepath, invalid[0], invalid[1], invalid[2], invalid[3]))
73                     api_valid_convention = False
74
75                 for platform in testspec_dict.keys():
76                     if not platform in self.data.keys():
77                         print("=> Invalid Platform: " + platform)
78                         continue
79                     for build_type in testspec_dict[platform]:
80                         for transport in testspec_dict[platform][build_type].keys():
81                             #print (testspec_dict[platform][build_type][transport].items())
82                             for network, testspec_list in testspec_dict[platform][build_type][transport].items():
83                                 #print('line 77:', len(testspec_list), testspec_list)
84                                 for testspec in testspec_list:
85                                     #print (self.data[platform][build_type][transport][network][tctype][module])
86                                     if (not testspec.suite in self.data[platform][build_type][transport][network][tctype][module]):
87                                         self.data[platform][build_type][transport][network][tctype][module][testspec.suite] = dict()
88                                     self.data[platform][build_type][transport][network][tctype][module][testspec.suite][testspec.name] = testspec
89
90         return api_valid_convention
91
92     def extract_api_testspec_bytypes(self, module, testfw, path):
93         rootpath = os.path.normcase(path)
94
95         api_valid_convention = True
96 #        rootpath = os.path.join(rootpath, "src")
97         for tctype in TESTCASE_TYPES:
98             type_dir = os.path.join(rootpath, tctype.lower())
99             if (os.path.isdir(type_dir)):
100                 valid = self.extract_api_testspec_bysuite(tctype, module, testfw, type_dir)
101                 api_valid_convention = api_valid_convention and valid
102         return api_valid_convention
103
104     def extract_api_testspec_bytestfw(self, module, path):
105         rootpath = os.path.normcase(path)
106
107         api_valid_convention = True
108         for testfw in TESTFW_TYPES:
109
110             fw_dir = os.path.join(rootpath, testfw.lower())
111             tmp_dir = fw_dir
112
113             if (os.path.isdir(fw_dir)):
114                 if (testfw.lower() == "gtest"):
115                     for sdk_type in SDK_TYPES:
116                         sdk_fw_dir = os.path.join(tmp_dir, sdk_type.lower())
117                         if (os.path.isdir(sdk_fw_dir)):
118                             sdk_fw_dir = os.path.join(sdk_fw_dir, "src")
119                             valid = self.extract_api_testspec_bytypes(module, testfw, sdk_fw_dir)
120                             api_valid_convention = api_valid_convention and valid
121                     fw_dir = os.path.join(tmp_dir, "src")
122                     if (os.path.isdir(fw_dir)):
123                         valid = self.extract_api_testspec_bytypes(module, testfw, fw_dir)
124                         api_valid_convention = api_valid_convention and valid
125                 else:
126                     fw_dir = os.path.join(tmp_dir, "src")
127                     if (testfw.lower() == "junit"):
128                         fw_dir = os.path.join(fw_dir, "org")
129                         fw_dir = os.path.join(fw_dir, "iotivity")
130                         fw_dir = os.path.join(fw_dir, "test")
131                         fw_dir = os.path.join(fw_dir, module.lower())
132                         fw_dir = os.path.join(fw_dir, "tc")
133                     valid = self.extract_api_testspec_bytypes(module, testfw, fw_dir)
134                     api_valid_convention = api_valid_convention and valid
135
136         return api_valid_convention
137
138     def extract_api_testspec_bymodule(self, path, module_filter):
139         rootpath = os.path.normcase(path)
140
141         api_valid_convention = True
142         for module in TESTSUITE_MODULES:
143             if not module_filter == '' and module.lower() != module_filter.lower():
144                 continue
145
146             module_dir = os.path.join(rootpath, module.lower())
147             if (os.path.isdir(module_dir)):
148                 valid = self.extract_api_testspec_bytestfw(module, module_dir)
149                 api_valid_convention = api_valid_convention and valid
150
151         return api_valid_convention
152
153     def extract_api_testspec(self, path, module_filter):
154         rootpath = os.path.normcase(path)
155
156         api_valid_convention = True
157         if (os.path.isdir(rootpath)):
158             valid = self.extract_api_testspec_bymodule(rootpath, module_filter)
159 #            valid = self.extract_api_testspec_bymodule(tctype, type_dir, module_filter)
160             api_valid_convention = api_valid_convention and valid
161 #        for tctype in TESTCASE_TYPES:
162 #            type_dir = os.path.join(rootpath, tctype.lower())
163 #            if (os.path.isdir(type_dir)):
164 #                valid = self.extract_api_testspec_bymodule(tctype, type_dir, module_filter)
165 #                api_valid_convention = api_valid_convention and valid
166
167         return api_valid_convention
168
169     def extract_sampleapp_testspec(self, path, module_filter):
170         rootpath = os.path.normcase(path)
171
172         analyzer = RobotTCAnalyzer()
173         api_valid_convention = True
174         for path, dir, files in os.walk(rootpath):
175             for fname in files:
176                 filepath = os.path.join(path, fname)
177                 if (os.path.isfile(filepath) == False):
178                     continue
179
180                 if not 'Iotivity_ComponentSampleApp' in fname:
181                     continue
182
183                 if not filepath.endswith('.txt'):
184                     continue
185
186                 test_data, invalid_list = analyzer.analyze_tc_file(filepath)
187
188                 for invalid in invalid_list:
189                     print("=> Invalid Test Case : %s(%d), %s.%s, message:%s" %
190                           (filepath, invalid[0], invalid[1], invalid[2], invalid[3]))
191                     api_valid_convention = False
192
193                 for platform, module, testspec in test_data:
194                     if not platform in self.data:
195                         print("=> Invalid Platform: " + platform)
196                         continue
197
198                     for build_type in self.data[platform]:
199                         if (not testspec.suite in self.data[platform][build_type][NO_TRANSPORT][NO_NETWORK]['STC'][module]):
200                             self.data[platform][build_type][NO_TRANSPORT][NO_NETWORK]['STC'][module][testspec.suite] = dict()
201                         self.data[platform][build_type][NO_TRANSPORT][NO_NETWORK]['STC'][module][testspec.suite][testspec.name] = testspec
202
203         return api_valid_convention
204
205
206