import os
import subprocess
def sub_command(command):
proc = subprocess.Popen(command, shell=True)
try:
proc.communicate()
except subprocess.TimeoutExpired:
proc.kill()
proc.terminate()
def install_tool(home_path):
coverage_sh = os.path.join(
home_path, "test/testfwk/developer_test/local_coverage/automate_execute/coverage.sh")
sub_command("chmod +x %s" % coverage_sh)
sub_command(coverage_sh)
def update_lcovrc():
print("修改/etc/lcovrc文件中:lcov_branch_coverage=0为lcov_branch_coverage=1")
subprocess.call(["sudo", "echo", ""])
file_path = "/etc/lcovrc"
os.chmod(file_path, 0o777)
with open(file_path, "r", encoding="utf-8") as f:
txt = f.read()
txt = txt.replace("lcov_branch_coverage = 0", "lcov_branch_coverage = 1")
with open(file_path, "w", encoding="utf-8") as f1:
f1.write(txt)
if __name__ == '__main__':
current_path = os.getcwd()
root_path = current_path.split("/test/testfwk/developer_test")[0]
if os.geteuid() == 0:
install_tool(root_path)
update_lcovrc()
else:
print("当前用户不是root用户,请在root用户下执行该脚本,因为lcov只能在root下安装,"
"且需要修改/etc/lcovrc文件,其他用户没有权限修改,会导致分支覆盖率无法生成!")