add mode asan,lsan,msan,tsan for test

This commit is contained in:
linjinhai 2021-12-02 00:07:09 +08:00
parent df608c43b0
commit a9ad514fb8
5 changed files with 48 additions and 5 deletions

5
.gitignore vendored
View File

@ -58,4 +58,7 @@ vs2017
vs2019 vs2019
vs2010 vs2010
vs2013 vs2013
vs2015 vs2015
cover_report
cover*.info
*.gcno

View File

@ -1,5 +1,5 @@
target("hikyuu") target("hikyuu")
if is_mode("debug") then if is_mode("debug", "coverage", "asan", "msan", "tsan", "lsan") then
set_kind("static") set_kind("static")
else else
set_kind("shared") set_kind("shared")

View File

@ -1,5 +1,41 @@
add_requires("doctest") add_requires("doctest")
function coverage_report(target)
if is_mode("coverage") and not is_plat("windows") and not (linuxos.name() == "ubuntu" and linuxos.version():lt("20.0")) then
-- 如需分支覆盖,须在下面 lcov, genhtml 命令后都加入: --rc lcov_branch_coverage=1
print("Processing coverage info ...")
if not os.isfile("cover-init.info") then
-- 初始化并创建基准数据文件
os.run("lcov -c -i -d ./ -o cover-init.info")
end
-- 移除之前的结果,否则容易出错
os.tryrm('cover.info')
os.tryrm('cover-total.info')
-- 收集当前测试文件运行后产生的覆盖率文件
os.run("lcov -c -d ./ -o cover.info")
-- 合并基准数据和执行测试文件后生成的覆盖率数据
os.exec("lcov -a cover-init.info -a cover.info -o cover-total.info")
-- 删除统计信息中如下的代码或文件,支持正则
os.run("lcov --remove cover-total.info '*/usr/include/*' \
'*/usr/lib/*' '*/usr/lib64/*' '*/usr/local/include/*' '*/usr/local/lib/*' '*/usr/local/lib64/*' \
'*/test/*' '*/.xmake*' '*/boost/*' '*/ffmpeg/*' \
'*/cpp/yihua/ocr_module/clipper.*' -o cover-final.info")
-- 生成的html及相关文件的目录名称--legend 简单的统计信息说明
os.exec("genhtml -o cover_report --legend --title 'yhsdk' --prefix=" .. os.projectdir() .. " cover-final.info")
-- 生成 sonar 可读取报告
if is_plat("linux") then
os.run("gcovr -r . -e cpp/test -e 'cpp/yihua/ocr_module/clipper.*' --xml -o coverage.xml")
end
end
end
target("unit-test") target("unit-test")
set_kind("binary") set_kind("binary")
set_default(false) set_default(false)
@ -43,6 +79,7 @@ target("unit-test")
-- add files -- add files
add_files("**.cpp") add_files("**.cpp")
after_run(coverage_report)
target_end() target_end()
target("small-test") target("small-test")
@ -82,4 +119,6 @@ target("small-test")
-- add files -- add files
add_files("./hikyuu/hikyuu/**.cpp"); add_files("./hikyuu/hikyuu/**.cpp");
add_files("./hikyuu/test_main.cpp") add_files("./hikyuu/test_main.cpp")
after_run(coverage_report)
target_end() target_end()

View File

@ -99,6 +99,7 @@ def save_current_compile_info(compile_info):
def build_boost(mode): def build_boost(mode):
""" 编译依赖的 boost 库 """ """ 编译依赖的 boost 库 """
new_mode = 'release' if mode == 'release' else 'debug'
current_boost_root, current_boost_lib = get_boost_envrionment() current_boost_root, current_boost_lib = get_boost_envrionment()
if current_boost_root == '' or current_boost_lib == '': if current_boost_root == '' or current_boost_lib == '':
print("Can't get boost environment!") print("Can't get boost environment!")
@ -230,7 +231,7 @@ def cli():
@click.option('-m', @click.option('-m',
'--mode', '--mode',
default='release', default='release',
type=click.Choice(['release', 'debug']), type=click.Choice(['release', 'debug', 'coverage', 'asan', 'tsan', 'msan', 'lsan']),
help='') help='')
def build(verbose, mode, j): def build(verbose, mode, j):
""" 执行编译 """ """ 执行编译 """
@ -245,7 +246,7 @@ def build(verbose, mode, j):
@click.option('-m', @click.option('-m',
'--mode', '--mode',
default='release', default='release',
type=click.Choice(['release', 'debug']), type=click.Choice(['release', 'debug', 'coverage', 'asan', 'msan', 'tsan', 'lsan']),
help='') help='')
@click.option('-case', '--case', default='', help="执行指定的 TestCase") @click.option('-case', '--case', default='', help="执行指定的 TestCase")
def test(all, compile, verbose, mode, case, j): def test(all, compile, verbose, mode, case, j):

View File

@ -5,7 +5,7 @@ set_project("hikyuu")
add_rules("mode.debug", "mode.release") add_rules("mode.debug", "mode.release")
if not is_plat("windows") then if not is_plat("windows") then
add_rules("mode.coverage") add_rules("mode.coverage", "mode.asan", "mode.msan", "mode.tsan", "mode.lsan")
end end
-- version -- version