Skip to content

Commit

Permalink
add mode asan,lsan,msan,tsan for test
Browse files Browse the repository at this point in the history
  • Loading branch information
linjinhai committed Dec 1, 2021
1 parent df608c4 commit a9ad514
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ vs2017
vs2019
vs2010
vs2013
vs2015
vs2015
cover_report
cover*.info
*.gcno
2 changes: 1 addition & 1 deletion hikyuu_cpp/hikyuu/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
target("hikyuu")
if is_mode("debug") then
if is_mode("debug", "coverage", "asan", "msan", "tsan", "lsan") then
set_kind("static")
else
set_kind("shared")
Expand Down
39 changes: 39 additions & 0 deletions hikyuu_cpp/unit_test/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
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")
set_kind("binary")
set_default(false)
Expand Down Expand Up @@ -43,6 +79,7 @@ target("unit-test")
-- add files
add_files("**.cpp")

after_run(coverage_report)
target_end()

target("small-test")
Expand Down Expand Up @@ -82,4 +119,6 @@ target("small-test")
-- add files
add_files("./hikyuu/hikyuu/**.cpp");
add_files("./hikyuu/test_main.cpp")

after_run(coverage_report)
target_end()
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def save_current_compile_info(compile_info):

def build_boost(mode):
""" 编译依赖的 boost 库 """
new_mode = 'release' if mode == 'release' else 'debug'
current_boost_root, current_boost_lib = get_boost_envrionment()
if current_boost_root == '' or current_boost_lib == '':
print("Can't get boost environment!")
Expand Down Expand Up @@ -230,7 +231,7 @@ def cli():
@click.option('-m',
'--mode',
default='release',
type=click.Choice(['release', 'debug']),
type=click.Choice(['release', 'debug', 'coverage', 'asan', 'tsan', 'msan', 'lsan']),
help='编译模式')
def build(verbose, mode, j):
""" 执行编译 """
Expand All @@ -245,7 +246,7 @@ def build(verbose, mode, j):
@click.option('-m',
'--mode',
default='release',
type=click.Choice(['release', 'debug']),
type=click.Choice(['release', 'debug', 'coverage', 'asan', 'msan', 'tsan', 'lsan']),
help='编译模式')
@click.option('-case', '--case', default='', help="执行指定的 TestCase")
def test(all, compile, verbose, mode, case, j):
Expand Down
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set_project("hikyuu")

add_rules("mode.debug", "mode.release")
if not is_plat("windows") then
add_rules("mode.coverage")
add_rules("mode.coverage", "mode.asan", "mode.msan", "mode.tsan", "mode.lsan")
end

-- version
Expand Down

0 comments on commit a9ad514

Please sign in to comment.