2 /******************************************************************
4 * Copyright 2018 Samsung Electronics All Rights Reserved.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 ******************************************************************/
25 from ite.config import *
26 from ite.tc.analyzer import TCAnalyzer
27 from ite.tc.robot_analyzer import RobotTCAnalyzer
29 class TestSpecContainer:
34 for platform in TEST_PLATFORM:
35 self.data[platform] = dict()
37 for build_type in BUILD_TYPE:
38 self.data[platform][build_type] = dict()
40 for transport in TEST_TRANSPORT:
41 self.data[platform][build_type][transport] = dict()
43 for network in TEST_NETWORK:
44 self.data[platform][build_type][transport][network] = dict()
46 for tctype in TESTCASE_TYPES:
47 self.data[platform][build_type][transport][network][tctype] = dict()
49 for module in TESTSUITE_MODULES:
50 self.data[platform][build_type][transport][network][tctype][module] = dict()
53 def extract_api_testspec_bysuite(self, tctype, module, testfw, path):
54 analyzer = TCAnalyzer(testfw)
56 rootpath = os.path.normcase(path)
58 api_valid_convention = True
59 for path, dir, files in os.walk(rootpath):
61 filepath = os.path.join(path, fname)
62 if (os.path.isfile(filepath) == False):
65 if not (filepath.endswith('.cpp') or filepath.endswith('.c') or filepath.endswith('.java')):
68 testspec_dict, invalid_list = analyzer.analyze_tc_file(filepath, module)
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
75 for platform in testspec_dict.keys():
76 if not platform in self.data.keys():
77 print("=> Invalid Platform: " + platform)
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
90 return api_valid_convention
92 def extract_api_testspec_bytypes(self, module, testfw, path):
93 rootpath = os.path.normcase(path)
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
104 def extract_api_testspec_bytestfw(self, module, path):
105 rootpath = os.path.normcase(path)
107 api_valid_convention = True
108 for testfw in TESTFW_TYPES:
110 fw_dir = os.path.join(rootpath, testfw.lower())
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
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
136 return api_valid_convention
138 def extract_api_testspec_bymodule(self, path, module_filter):
139 rootpath = os.path.normcase(path)
141 api_valid_convention = True
142 for module in TESTSUITE_MODULES:
143 if not module_filter == '' and module.lower() != module_filter.lower():
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
151 return api_valid_convention
153 def extract_api_testspec(self, path, module_filter):
154 rootpath = os.path.normcase(path)
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
167 return api_valid_convention
169 def extract_sampleapp_testspec(self, path, module_filter):
170 rootpath = os.path.normcase(path)
172 analyzer = RobotTCAnalyzer()
173 api_valid_convention = True
174 for path, dir, files in os.walk(rootpath):
176 filepath = os.path.join(path, fname)
177 if (os.path.isfile(filepath) == False):
180 if not 'Iotivity_ComponentSampleApp' in fname:
183 if not filepath.endswith('.txt'):
186 test_data, invalid_list = analyzer.analyze_tc_file(filepath)
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
193 for platform, module, testspec in test_data:
194 if not platform in self.data:
195 print("=> Invalid Platform: " + platform)
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
203 return api_valid_convention