1 Star 0 Fork 9

zhangjing/arkui-developer-test-tool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
build.py 6.34 KB
一键复制 编辑 原始数据 按行查看 历史
liyujie 提交于 2023-06-23 20:02 . add no-prebuild-sdk to build corperation
import os
import sys
import webbrowser
from logger import Logger
from utils import *
class TestSuiteHandler():
def __init__(self, build_target, fast_rebuild, command_execute: CommandExecute, code_path, device, coverage, llvm_gcov):
self.__build_target = build_target
self.__fast_rebuild = fast_rebuild
self.__command_execute = command_execute
self.__code_path = code_path
self.__device = device
self.__coverage = coverage
self.__llvm_gcov = llvm_gcov
def mkdir(self, path):
isExits = os.path.exists(path)
if not isExits:
os.makedirs(path)
Logger.info(f"{path} make successfully")
else:
Logger.info(f"{path} already exits")
def build_test_suite(self):
build_cmd = f"cd {self.__code_path}&&./build.sh --product-name rk3568 --ccache --no-prebuilt-sdk --build-target {self.__build_target}"
build_cmd = f"{build_cmd} --fast-rebuild" if self.__fast_rebuild else build_cmd
build_cmd = f"{build_cmd} --gn-args ace_engine_feature_enable_coverage=true" if self.__coverage else build_cmd
errlen = self.__command_execute.execute(build_cmd)
if errlen > 5:
Logger.error("build testsuite error")
sys.exit()
def copy_test_suite(self):
remote_path = f"{self.__code_path}/out/{self.__device}/tests/unittest/ace_engine/"
command = f"find {remote_path} -name {self.__build_target}"
result = self.__command_execute.execute_result(command)
if len(result) != 0:
self.mkdir("testsuites/")
local_file = f"testsuites/{self.__build_target}"
self.__command_execute.sftp_get(result[0].strip("\n"), local_file)
def run_test_suite(self):
command_execute("hdc shell hwclock --systohc")
command_execute("hdc shell rm -f /data/log/faultlog/*")
command_execute("hdc shell rm -f /data/log/faultlog/temp/*")
command_execute("hdc shell rm -f /data/log/faultlog/debug/*")
command_execute("hdc shell rm -f /data/log/faultlog/faultlogger/*")
command_execute("hdc shell hilog -w stop")
command_execute("hdc shell hilog -r")
command_execute("hdc shell rm -rf /data/test/")
command_execute("hdc shell mkdir -p /data/test/")
command_execute(
f"cd testsuites && hdc file send {self.__build_target} /data/test/")
gcov_prefiex_length = len(self.__code_path.split('/')) + 1
gcov_cmd = f"hdc shell cd /data/test/; rm -rf {self.__build_target}.xml; chmod +x *; GCOV_PREFIX=. GCOV_PREFIX_STRIP={gcov_prefiex_length} ./{self.__build_target}"
result = command_execute(gcov_cmd)
for line in result:
Logger.debug(line.strip("\n"))
def move_gcda(self):
command_execute("hdc shell mount -o rw,remount /")
result = command_execute("hdc shell find /data/test/obj", log=True)
if self.__coverage and result == "":
Logger.error(f"No coverage file gcda generated for {self.__build_target}")
sys.exit()
command_execute("hdc shell cd /data/test/; tar -zcf obj.tar.gz obj")
temp_path = "temp"
self.mkdir(temp_path)
command_execute("hdc file recv /data/test/obj.tar.gz temp/")
local_file = "temp/obj.tar.gz"
remote_file = f"{self.__code_path}/out/{self.__device}/obj.tar.gz"
self.__command_execute.sftp_put(local_file, remote_file)
device_path = f"{self.__code_path}/out/{self.__device}"
self.__command_execute.execute(
f"cd {device_path}/&&tar -zxf obj.tar.gz")
def generate_coverage(self):
ace_engine_path = f"{self.__code_path}/out/{self.__device}/obj/foundation/arkui/ace_engine"
cd_path = f"cd {ace_engine_path}"
base_path = f"{self.__code_path}/foundation/arkui/ace_engine"
sheild_dir = f"'*.h' '{base_path}/test/*' '{base_path}/adapter/*' '{self.__code_path}/prebuilts/*' '*/test/*'"
lcov_cmd1 = f"lcov -d . -o cov_ace_engine.info -c --gcov-tool {self.__llvm_gcov} --rc lcov_branch_coverage=1"
lcov_cmd2 = f"lcov -r cov_ace_engine.info {sheild_dir} -o cov_ace_engine.info --rc lcov_branch_coverage=1"
gen_html = f"genhtml -o result --ignore-errors source cov_ace_engine.info --branch-coverage"
self.__command_execute.execute(f"{cd_path} && {lcov_cmd1}")
self.__command_execute.execute(f"{cd_path} && {lcov_cmd2}")
self.__command_execute.execute(f"{cd_path} && {gen_html}")
self.__command_execute.execute(
f"{cd_path} && tar -czf result.tar.gz result")
remote_file = f"{ace_engine_path}/result.tar.gz"
self.mkdir("temp")
self.__command_execute.sftp_get(remote_file, "temp/result.tar.gz")
command_execute(f"tar -zxf temp\\result.tar.gz -C .\\")
def open_browser(self):
current_path = os.getcwd()
if os.path.exists("result/index.html"):
webbrowser.open(f"{current_path}/result/index.html")
@staticmethod
def process():
ssh_item, test_suite_item = read_config()
host = ssh_item["host"]
port = int(ssh_item["port"])
username = ssh_item["username"]
password = ssh_item["password"]
code_path = test_suite_item["path"]
device = test_suite_item["device"]
llvm_gcov = test_suite_item["gcov"]
args = read_argparse()
build_target = args.build_target
fast_rebuild = args.fast_rebuild
coverage = args.coverage
no_build = args.no_build
command_execute = CommandExecute(host, port, username, password)
test_suite_handler = TestSuiteHandler(build_target,
fast_rebuild,
command_execute,
code_path,
device,
coverage,
llvm_gcov)
if not no_build:
test_suite_handler.build_test_suite()
test_suite_handler.copy_test_suite()
test_suite_handler.run_test_suite()
if coverage:
test_suite_handler.move_gcda()
test_suite_handler.generate_coverage()
test_suite_handler.open_browser()
command_execute.close()
if __name__ == "__main__":
TestSuiteHandler.process()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/roumatine/arkui-developer-test-tool.git
[email protected]:roumatine/arkui-developer-test-tool.git
roumatine
arkui-developer-test-tool
arkui-developer-test-tool
master

搜索帮助