Skip to content

Commit

Permalink
[2_9] Use xmake test subcommand instead of test target
Browse files Browse the repository at this point in the history
* Use `xmake test` subcommand instead of test target

* avoid memory bug caused by xmake feature

* fix execution error on wasm

* remove library test on wasm

* fix on wasm

* fix path issue

* select proper file to execute

* upgrade version of xmake

* fix missing file of wasm

* make path more robust

* use node path added by xmake

* exclude shared library test on  wasm
  • Loading branch information
jingkaimori authored Jun 2, 2024
1 parent 1e93ae7 commit 9d4e025
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 95 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci-xmake-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ jobs:
run: xmake build --yes -vD
- name: test
run: |
xmake run --yes -vD --group=tests
xmake test -vD
- name: benchmark
run: xmake run --yes --group=bench
1 change: 0 additions & 1 deletion .github/workflows/ci-xmake-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ jobs:
run: xmake build --yes -vD
- name: test
run: |
xmake run --yes -vD --group=tests
xmake test -vD
- name: benchmark
run: xmake run --yes --group=bench
6 changes: 3 additions & 3 deletions .github/workflows/ci-xmake-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ jobs:
${{ github.workspace }}/build/.build_cache
key: ${{ runner.os }}-wasm-${{ hashFiles('**/xmake.lua') }}
- name: config
run: xmake config --yes -p wasm -vD
run: xmake config --yes -p wasm -vD --enable_tests=true
- name: build
run: xmake build --yes -vD
- name: test
run: elvish bin/test_wasm
run: elvish bin/test_wasm "tests/*"
windowsbuild:
runs-on: windows-2019
env:
Expand Down Expand Up @@ -84,5 +84,5 @@ jobs:
- name: build
run: xmake build --yes -vD
- name: test
run: elvish bin/test_wasm
run: elvish bin/test_wasm "tests/*"

3 changes: 1 addition & 2 deletions .github/workflows/ci-xmake-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
steps:
- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: v2.8.7
xmake-version: v2.8.9
- name: update repo
run: xmake repo -u
- name: git crlf
Expand All @@ -55,7 +55,6 @@ jobs:
run: xmake build --yes -vD
- name: test
run: |
xmake run --yes -vD --group=tests
xmake test -vD
- name: benchmark
run: xmake run --yes --group=bench
4 changes: 2 additions & 2 deletions bin/test_wasm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if $platform:is-windows {


if (== (count $args) 0) {
xmake run
xmake test
} else {
xmake run $args[0]
xmake test $args[0]
}
134 changes: 48 additions & 86 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,86 +206,6 @@ end

local mingw_copied = false

function add_test_target(filepath)
local testname = path.basename(filepath)
target(testname) do
set_group("tests")
add_deps("test_base")
set_languages("c++17")
set_policy("check.auto_ignore_flags", false)
set_exceptions("cxx")

if is_plat("mingw") then
add_packages("mingw-w64")
end
add_packages("tbox")
add_packages("doctest")

if is_plat("linux") then
add_syslinks("stdc++", "m")
end

if is_plat("windows") then
set_encodings("utf-8")
add_ldflags("/LTCG")
end

if is_plat("windows") or is_plat("mingw") then
add_syslinks("secur32", "shell32")
end

add_includedirs("$(buildir)/L1")
add_includedirs(lolly_includedirs)
add_includedirs("tests")
add_forceincludes(path.absolute("$(buildir)/L1/config.h"))
add_files(filepath)

if is_plat("wasm") then
add_cxxflags("-s DISABLE_EXCEPTION_CATCHING=0")
set_values("wasm.preloadfiles", {"xmake.lua", "tests", "LICENSE"})
add_ldflags("-s DISABLE_EXCEPTION_CATCHING=0")
on_run(function (target)
node = os.getenv("EMSDK_NODE")
os.cd("$(buildir)/wasm/wasm32/$(mode)/")
print("> cd $(buildir)/wasm/wasm32/$(mode)/")
cmd = node .. " " .. testname .. ".js"
print("> " .. cmd)
os.exec(cmd)
end)
end

if is_plat("linux", "macosx") then
on_run(function (target)
cmd = "$(buildir)/$(plat)/$(arch)/$(mode)/" .. testname
print("> " .. cmd)
os.exec(cmd)
end)
end

if is_plat("windows") or (is_plat ("mingw") and is_host ("windows")) then
on_run(function (target)
cmd = "$(buildir)/$(plat)/$(arch)/$(mode)/" .. testname .. ".exe"
print("> " .. cmd)
os.exec(cmd)
end)
end

if is_plat("mingw") and is_host("linux") then
on_run(function (target)
cmd = "wine $(buildir)/mingw/x86_64/$(mode)/" .. testname .. ".exe"
print("> " .. cmd)
if not mingw_copied then
mingw_copied = true
os.cp("/usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll", "$(buildir)/mingw/x86_64/$(mode)/")
os.cp("/usr/lib/gcc/x86_64-w64-mingw32/10-win32/libgcc_s_seh-1.dll", "$(buildir)/mingw/x86_64/$(mode)/")
os.cp("/usr/lib/gcc/x86_64-w64-mingw32/10-win32/libstdc++-6.dll", "$(buildir)/mingw/x86_64/$(mode)/")
end
os.exec(cmd)
end)
end
end
end

function add_bench_target(filepath)
local benchname = path.basename(filepath)
target(benchname) do
Expand Down Expand Up @@ -390,24 +310,70 @@ if has_config("enable_tests") then
packages = "doctest",
defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"})
end
target("test_base")do
set_kind("object")
target("tests")do
set_kind("binary")
add_deps("liblolly")
set_languages("c++17")
set_policy("check.auto_ignore_flags", false)
set_exceptions("cxx")
if not is_plat("wasm") then
set_rundir("$(projectdir)")
end

if is_plat("mingw") then
add_packages("mingw-w64")
elseif is_plat("wasm") then
add_packages("emscripten")
end
add_packages("tbox")
add_packages("doctest")

if is_plat("linux") then
add_syslinks("stdc++", "m")
elseif is_plat("windows") or is_plat("mingw") then
add_syslinks("secur32", "shell32")
end

if is_plat("windows") then
set_encodings("utf-8")
add_ldflags("/LTCG")
elseif is_plat("wasm") then
add_cxxflags("-s DISABLE_EXCEPTION_CATCHING=0")
add_ldflags("-s DISABLE_EXCEPTION_CATCHING=0")
set_values("wasm.preloadfiles", {"xmake.lua", "tests", "LICENSE"})
on_test(function (target, opt)
node_table = path.splitenv(os.getenv("EMSDK_NODE"))
node = node_table[table.maxn(node_table)]
os.cd(target:targetdir())
print("> cd " .. target:targetdir())
cmd = node .. " " .. path.join(target:targetdir(), target:basename() .. ".js")
print("> " .. cmd)
local retval = try {
function ()
os.exec(cmd)
return true
end,
catch {
function (errors)
return false, errors
end
}
}
return retval;
end)
end
add_includedirs("$(buildir)/L1")
add_includedirs(lolly_includedirs)
add_includedirs("tests")
add_forceincludes(path.absolute("$(buildir)/L1/config.h"))
add_files("tests/a_tbox_main.cpp")

local cpp_tests_on_all_plat = os.files("tests/**_test.cpp|**/shared_lib_test.cpp")
for _, testfile in ipairs(cpp_tests_on_all_plat) do
add_tests(path.basename(testfile), {
kind = "binary",
files = testfile})
end
end
target("bench_base")do
set_kind("object")
Expand All @@ -421,10 +387,6 @@ if has_config("enable_tests") then
add_files("bench/nanobench.cpp")
end

cpp_tests_on_all_plat = os.files("tests/**_test.cpp|**/shared_lib_test.cpp")
for _, filepath in ipairs(cpp_tests_on_all_plat) do
add_test_target (filepath)
end
cpp_bench_on_all_plat = os.files("bench/**_bench.cpp")
for _, filepath in ipairs(cpp_bench_on_all_plat) do
add_bench_target (filepath)
Expand Down

0 comments on commit 9d4e025

Please sign in to comment.