mirror of
https://gitee.com/openharmony/xts_tools
synced 2024-11-26 17:40:54 +00:00
commit
39afcb912a
95
ci/generate_accurate_targets.py
Normal file
95
ci/generate_accurate_targets.py
Normal file
@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
class TestSuite:
|
||||
|
||||
def __init__(self, xts_root_dir):
|
||||
self._xts_root_dir = xts_root_dir
|
||||
self._components_mapping_ts = self._generate_dict_of_component_mapping_testsuite()
|
||||
self._dir_mapping_ts = self._generate_dict_of_directory_mapping_testsuite()
|
||||
|
||||
def _generate_dict_of_component_mapping_testsuite(self):
|
||||
return {}
|
||||
|
||||
def _generate_dict_of_directory_mapping_testsuite(self):
|
||||
return {}
|
||||
|
||||
def get_testsuites_of_component(self, component_name):
|
||||
return self._components_mapping_ts.get(component_name)
|
||||
|
||||
# 查找文件所属用例
|
||||
def get_testsuite_of_file(self, file_name):
|
||||
return None
|
||||
|
||||
|
||||
class AccurateTarget:
|
||||
|
||||
def __init__(self, xts_root_dir, change_info_file):
|
||||
self._xts_root_dir = xts_root_dir
|
||||
self._code_root_dir = os.path.realpath(os.path.join(xts_root_dir, "../../.."))
|
||||
self._change_info_file = change_info_file
|
||||
self._testsuite = None
|
||||
|
||||
def _get_change_info(self):
|
||||
return {}
|
||||
|
||||
def _set_testsuite(self):
|
||||
self._testsuite = TestSuite(self._xts_root_dir)
|
||||
|
||||
# 测试套件仓修改
|
||||
def _get_targets_from_testcase_change(self):
|
||||
return 0, {'111', '222'}
|
||||
|
||||
# 部件仓修改
|
||||
def _get_targets_from_component_change(self):
|
||||
return 0, {'111', '333'}
|
||||
|
||||
# 接口仓/编译框架仓变化
|
||||
def _get_targets_from_if_change(self):
|
||||
# 变更文件,在白名单范围内,编译白名单的目标
|
||||
# 变更文件,不在白名单范围内,全量编译测试套
|
||||
return 0, {'111', '333'}
|
||||
|
||||
def get_targets(self):
|
||||
func_list = [
|
||||
self._get_targets_from_testcase_change, self._get_targets_from_testcase_change,
|
||||
self._get_targets_from_if_change
|
||||
]
|
||||
|
||||
target = set()
|
||||
for i in func_list:
|
||||
retcode, m = i()
|
||||
if retcode:
|
||||
return retcode, []
|
||||
target = target.union(m)
|
||||
return 0, list(target)
|
||||
|
||||
|
||||
def generate(xts_root_dir, change_info_file, build_target):
|
||||
print("{}:{}: build_target={}".format(__file__, sys._getframe().f_lineno, build_target))
|
||||
if not os.path.exists(change_info_file):
|
||||
print("warning: {} not exist".format(change_info_file))
|
||||
return 0, build_target
|
||||
|
||||
obj = AccurateTarget(xts_root_dir, change_info_file)
|
||||
accurate_targets = obj.get_targets()
|
||||
|
||||
return 0, accurate_targets
|
@ -23,111 +23,108 @@ import json5
|
||||
|
||||
class HvigorChecker:
|
||||
|
||||
def __init__(self, suite_name):
|
||||
self._current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
self._suite_name = suite_name
|
||||
self._xts_root_dir = os.path.realpath(os.path.join(self._current_dir, '../..', suite_name))
|
||||
print("_xts_root_dir={}".format(self._xts_root_dir))
|
||||
def __init__(self, suite_name):
|
||||
self._current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
self._suite_name = suite_name
|
||||
self._xts_root_dir = os.path.realpath(os.path.join(self._current_dir, '../..', suite_name))
|
||||
|
||||
def get_file_md5(self, file_path):
|
||||
hash_md5 = hashlib.md5()
|
||||
with open(file_path, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(4096), b""):
|
||||
hash_md5.update(chunk)
|
||||
return hash_md5.hexdigest()
|
||||
def get_file_md5(self, file_path):
|
||||
hash_md5 = hashlib.md5()
|
||||
with open(file_path, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(4096), b""):
|
||||
hash_md5.update(chunk)
|
||||
return hash_md5.hexdigest()
|
||||
|
||||
def get_hvigor_version(self, json_file):
|
||||
with open(json_file, 'r') as f:
|
||||
data = json5.load(f)
|
||||
return data.get('hvigorVersion')
|
||||
return "0.0.0"
|
||||
def get_hvigor_version(self, json_file):
|
||||
with open(json_file, 'r') as f:
|
||||
data = json5.load(f)
|
||||
return data.get('hvigorVersion')
|
||||
|
||||
def output_unmatched_project(self, prject_list, filename):
|
||||
print("")
|
||||
print("Error: The {} in the following directory does not meet the requirements:".format(filename))
|
||||
for prj in prject_list:
|
||||
print(prj[0], prj[1])
|
||||
def output_unmatched_project(self, prject_list, filename):
|
||||
print("")
|
||||
print("Error: The {} in the following directory does not meet the requirements:".format(filename))
|
||||
for prj in prject_list:
|
||||
print(prj[0], prj[1])
|
||||
|
||||
def check_hvigor_wrapper_js(self, hvigor_prj_list):
|
||||
unmatch_info = []
|
||||
baseline_file = os.path.join(self._current_dir, 'hvigor-wrapper.js')
|
||||
baseline_md5 = self.get_file_md5(os.path.join(baseline_file))
|
||||
for dir in hvigor_prj_list:
|
||||
filename = os.path.join(dir, 'hvigor', 'hvigor-wrapper.js')
|
||||
md5 = self.get_file_md5(filename)
|
||||
if md5 != baseline_md5:
|
||||
unmatch_info.append((md5, filename))
|
||||
def check_hvigor_wrapper_js(self, hvigor_prj_list):
|
||||
unmatch_info = []
|
||||
baseline_file = os.path.join(self._current_dir, 'hvigor-wrapper.js')
|
||||
baseline_md5 = self.get_file_md5(os.path.join(baseline_file))
|
||||
for dir in hvigor_prj_list:
|
||||
filename = os.path.join(dir, 'hvigor', 'hvigor-wrapper.js')
|
||||
md5 = self.get_file_md5(filename)
|
||||
if md5 != baseline_md5:
|
||||
unmatch_info.append((md5, filename))
|
||||
|
||||
if len(unmatch_info):
|
||||
self.output_unmatched_project(unmatch_info, 'hvigor-wrapper.js')
|
||||
print('Please copy from {}'.format(baseline_file))
|
||||
return False
|
||||
return True
|
||||
if len(unmatch_info):
|
||||
self.output_unmatched_project(unmatch_info, 'hvigor-wrapper.js')
|
||||
print('Please copy from {}'.format(baseline_file))
|
||||
return False
|
||||
return True
|
||||
|
||||
def check_hvigor_version(self, hvigor_prj_list):
|
||||
unmatch_prj_list = []
|
||||
baseline_version = '4.0.5'
|
||||
for dir in hvigor_prj_list:
|
||||
filename = os.path.join(dir, 'hvigor', 'hvigor-config.json5')
|
||||
version = self.get_hvigor_version(filename)
|
||||
if version != baseline_version:
|
||||
unmatch_prj_list.append((version, filename))
|
||||
def check_hvigor_version(self, hvigor_prj_list):
|
||||
unmatch_prj_list = []
|
||||
baseline_version = '4.0.5'
|
||||
for dir in hvigor_prj_list:
|
||||
filename = os.path.join(dir, 'hvigor', 'hvigor-config.json5')
|
||||
version = self.get_hvigor_version(filename)
|
||||
if version != baseline_version:
|
||||
unmatch_prj_list.append((version, filename))
|
||||
|
||||
if len(unmatch_prj_list):
|
||||
self.output_unmatched_project(unmatch_prj_list, 'hvigor-config.json5')
|
||||
print("Plesse use {}".format(baseline_version))
|
||||
return False
|
||||
return True
|
||||
if len(unmatch_prj_list):
|
||||
self.output_unmatched_project(unmatch_prj_list, 'hvigor-config.json5')
|
||||
print("Plesse use {}".format(baseline_version))
|
||||
return False
|
||||
return True
|
||||
|
||||
def check_hvigorw_bat(self, hvigor_prj_list):
|
||||
unmatch_info = []
|
||||
baseline_file = os.path.join(self._current_dir, 'hvigorw.bat')
|
||||
baseline_md5 = self.get_file_md5(os.path.join(baseline_file))
|
||||
for dir in hvigor_prj_list:
|
||||
filename = os.path.join(dir, 'hvigorw.bat')
|
||||
md5 = self.get_file_md5(filename)
|
||||
if md5 != baseline_md5:
|
||||
unmatch_info.append((md5, filename))
|
||||
def check_hvigorw_bat(self, hvigor_prj_list):
|
||||
unmatch_info = []
|
||||
baseline_file = os.path.join(self._current_dir, 'hvigorw.bat')
|
||||
baseline_md5 = self.get_file_md5(os.path.join(baseline_file))
|
||||
for dir in hvigor_prj_list:
|
||||
filename = os.path.join(dir, 'hvigorw.bat')
|
||||
md5 = self.get_file_md5(filename)
|
||||
if md5 != baseline_md5:
|
||||
unmatch_info.append((md5, filename))
|
||||
|
||||
if len(unmatch_info):
|
||||
self.output_unmatched_project(unmatch_info, 'hvigorw.bat')
|
||||
print('Please copy from {}'.format(baseline_file))
|
||||
return False
|
||||
return True
|
||||
if len(unmatch_info):
|
||||
self.output_unmatched_project(unmatch_info, 'hvigorw.bat')
|
||||
print('Please copy from {}'.format(baseline_file))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_hvigor_prject_list(self):
|
||||
hvigor_prj_list = []
|
||||
for root, dirs, files in os.walk(self._xts_root_dir):
|
||||
if '.cxx' in dirs:
|
||||
dirs.remove('.cxx')
|
||||
for dir in dirs:
|
||||
if dir == 'hvigor':
|
||||
hvigor_prj_list.append(root)
|
||||
return hvigor_prj_list
|
||||
def get_hvigor_prject_list(self):
|
||||
hvigor_prj_list = []
|
||||
for root, dirs, files in os.walk(self._xts_root_dir):
|
||||
if '.cxx' in dirs:
|
||||
dirs.remove('.cxx')
|
||||
for dir in dirs:
|
||||
if dir == 'hvigor':
|
||||
hvigor_prj_list.append(root)
|
||||
return hvigor_prj_list
|
||||
|
||||
|
||||
def main():
|
||||
suite_name = ""
|
||||
if 'XTS_SUITENAME' in os.environ:
|
||||
suite_name = os.environ.get('XTS_SUITENAME')
|
||||
elif 'xts_suitename' in os.environ:
|
||||
suite_name = os.environ.get('xts_suitename')
|
||||
else :
|
||||
suite_name = sys.argv[1]
|
||||
suite_name = ""
|
||||
if 'XTS_SUITENAME' in os.environ:
|
||||
suite_name = os.environ.get('XTS_SUITENAME')
|
||||
elif 'xts_suitename' in os.environ:
|
||||
suite_name = os.environ.get('xts_suitename')
|
||||
else:
|
||||
suite_name = sys.argv[1]
|
||||
|
||||
obj = HvigorChecker(suite_name)
|
||||
obj = HvigorChecker(suite_name)
|
||||
|
||||
hvigor_prj_list = obj.get_hvigor_prject_list()
|
||||
hvigor_prj_list = obj.get_hvigor_prject_list()
|
||||
|
||||
js_valid = obj.check_hvigor_wrapper_js(hvigor_prj_list)
|
||||
json_valid = obj.check_hvigor_version(hvigor_prj_list)
|
||||
bat_valid = obj.check_hvigorw_bat(hvigor_prj_list)
|
||||
js_valid = obj.check_hvigor_wrapper_js(hvigor_prj_list)
|
||||
json_valid = obj.check_hvigor_version(hvigor_prj_list)
|
||||
bat_valid = obj.check_hvigorw_bat(hvigor_prj_list)
|
||||
|
||||
if not js_valid or not json_valid or not bat_valid:
|
||||
return 1
|
||||
return 0
|
||||
if not js_valid or not json_valid or not bat_valid:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
sys.exit(main())
|
||||
|
Loading…
Reference in New Issue
Block a user