From 0785e7cace5b9f80919c9ec80884e7fbdd8ccde8 Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sat, 1 Jun 2024 22:21:24 +0800 Subject: [PATCH 01/12] Use `xmake test` subcommand instead of test target --- .github/workflows/ci-xmake-linux.yml | 1 - .github/workflows/ci-xmake-macos.yml | 1 - .github/workflows/ci-xmake-windows.yml | 1 - bin/test_wasm | 4 +- xmake.lua | 108 ++++++------------------- 5 files changed, 25 insertions(+), 90 deletions(-) diff --git a/.github/workflows/ci-xmake-linux.yml b/.github/workflows/ci-xmake-linux.yml index 73ac43ad6..f92d7312e 100644 --- a/.github/workflows/ci-xmake-linux.yml +++ b/.github/workflows/ci-xmake-linux.yml @@ -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 diff --git a/.github/workflows/ci-xmake-macos.yml b/.github/workflows/ci-xmake-macos.yml index b80e10975..fa874961e 100644 --- a/.github/workflows/ci-xmake-macos.yml +++ b/.github/workflows/ci-xmake-macos.yml @@ -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 diff --git a/.github/workflows/ci-xmake-windows.yml b/.github/workflows/ci-xmake-windows.yml index ef4e37ae1..81349139c 100644 --- a/.github/workflows/ci-xmake-windows.yml +++ b/.github/workflows/ci-xmake-windows.yml @@ -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 diff --git a/bin/test_wasm b/bin/test_wasm index 7ffd8ab01..c799eb738 100755 --- a/bin/test_wasm +++ b/bin/test_wasm @@ -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] } diff --git a/xmake.lua b/xmake.lua index 432649102..33eb50627 100644 --- a/xmake.lua +++ b/xmake.lua @@ -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 @@ -390,16 +310,31 @@ if has_config("enable_tests") then packages = "doctest", defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"}) end - target("test_base")do + target("tests")do set_kind("object") 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") + 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") end @@ -408,6 +343,13 @@ if has_config("enable_tests") then 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") @@ -421,10 +363,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) From f2a3c32b80783c100c656d15002ca24f3781446f Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sat, 1 Jun 2024 22:52:21 +0800 Subject: [PATCH 02/12] avoid memory bug caused by xmake feature --- .github/workflows/ci-xmake-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-xmake-windows.yml b/.github/workflows/ci-xmake-windows.yml index 81349139c..333ce111c 100644 --- a/.github/workflows/ci-xmake-windows.yml +++ b/.github/workflows/ci-xmake-windows.yml @@ -34,7 +34,7 @@ jobs: steps: - uses: xmake-io/github-action-setup-xmake@v1 with: - xmake-version: v2.8.7 + xmake-version: v2.9.2 - name: update repo run: xmake repo -u - name: git crlf From 865b5c85d165891f2e4eac8f35db637d6f1f3675 Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sat, 1 Jun 2024 23:23:05 +0800 Subject: [PATCH 03/12] fix execution error on wasm --- xmake.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/xmake.lua b/xmake.lua index 33eb50627..913013853 100644 --- a/xmake.lua +++ b/xmake.lua @@ -337,6 +337,27 @@ if has_config("enable_tests") then 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) + node = os.getenv("EMSDK_NODE") + os.cd("$(buildir)/wasm/wasm32/$(mode)/") + print("> cd $(buildir)/wasm/wasm32/$(mode)/") + cmd = node .. " " .. testname .. ".js" + print("> " .. cmd) + local retval = try { + function () + os.exec(cmd) + return true + end, + catch { + function (errors) + return false + end + } + } + return retval; + end) end add_includedirs("$(buildir)/L1") add_includedirs(lolly_includedirs) From 6cde22671f0d551ce7a388078150719163b2f05a Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sat, 1 Jun 2024 23:48:25 +0800 Subject: [PATCH 04/12] remove library test on wasm --- .github/workflows/ci-xmake-wasm.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-xmake-wasm.yml b/.github/workflows/ci-xmake-wasm.yml index 6499ea4de..9eeba64a3 100644 --- a/.github/workflows/ci-xmake-wasm.yml +++ b/.github/workflows/ci-xmake-wasm.yml @@ -48,7 +48,7 @@ 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 @@ -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/*" From 388e8bdd97810154d6a57f7f5e4775f87919b55c Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sun, 2 Jun 2024 01:06:24 +0800 Subject: [PATCH 05/12] fix on wasm --- xmake.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xmake.lua b/xmake.lua index 913013853..2b16d4bd6 100644 --- a/xmake.lua +++ b/xmake.lua @@ -339,11 +339,11 @@ if has_config("enable_tests") 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) + on_test(function (target, opt) node = os.getenv("EMSDK_NODE") os.cd("$(buildir)/wasm/wasm32/$(mode)/") print("> cd $(buildir)/wasm/wasm32/$(mode)/") - cmd = node .. " " .. testname .. ".js" + cmd = node .. " " .. opt.name .. ".js" print("> " .. cmd) local retval = try { function () @@ -352,7 +352,7 @@ if has_config("enable_tests") then end, catch { function (errors) - return false + return false, errors end } } From e7ab7f08ee7ae969a2c3cef9ff11e602f0da83d0 Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sun, 2 Jun 2024 01:23:42 +0800 Subject: [PATCH 06/12] fix path issue --- .github/workflows/ci-xmake-windows.yml | 2 +- xmake.lua | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-xmake-windows.yml b/.github/workflows/ci-xmake-windows.yml index 333ce111c..659f8d5d9 100644 --- a/.github/workflows/ci-xmake-windows.yml +++ b/.github/workflows/ci-xmake-windows.yml @@ -34,7 +34,7 @@ jobs: steps: - uses: xmake-io/github-action-setup-xmake@v1 with: - xmake-version: v2.9.2 + xmake-version: v2.8.8 - name: update repo run: xmake repo -u - name: git crlf diff --git a/xmake.lua b/xmake.lua index 2b16d4bd6..572e11a04 100644 --- a/xmake.lua +++ b/xmake.lua @@ -341,9 +341,9 @@ if has_config("enable_tests") then set_values("wasm.preloadfiles", {"xmake.lua", "tests", "LICENSE"}) on_test(function (target, opt) node = os.getenv("EMSDK_NODE") - os.cd("$(buildir)/wasm/wasm32/$(mode)/") - print("> cd $(buildir)/wasm/wasm32/$(mode)/") - cmd = node .. " " .. opt.name .. ".js" + os.cd(target:targetdir()) + print("> cd " .. target:targetdir()) + cmd = node .. " " .. target:targetfile() print("> " .. cmd) local retval = try { function () From 232765865f510c9e942d7e8724356ae4abfa7b8d Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sun, 2 Jun 2024 12:32:07 +0800 Subject: [PATCH 07/12] select proper file to execute --- xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake.lua b/xmake.lua index 572e11a04..a94648712 100644 --- a/xmake.lua +++ b/xmake.lua @@ -343,7 +343,7 @@ if has_config("enable_tests") then node = os.getenv("EMSDK_NODE") os.cd(target:targetdir()) print("> cd " .. target:targetdir()) - cmd = node .. " " .. target:targetfile() + cmd = node .. " " .. path.join(target:targetdir(), target:basename() .. ".js") print("> " .. cmd) local retval = try { function () From ffe2cede6b045c69ba37bc7e31c3c542346284cb Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sun, 2 Jun 2024 12:32:32 +0800 Subject: [PATCH 08/12] upgrade version of xmake --- .github/workflows/ci-xmake-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-xmake-windows.yml b/.github/workflows/ci-xmake-windows.yml index 659f8d5d9..ac1978d7e 100644 --- a/.github/workflows/ci-xmake-windows.yml +++ b/.github/workflows/ci-xmake-windows.yml @@ -34,7 +34,7 @@ jobs: steps: - uses: xmake-io/github-action-setup-xmake@v1 with: - xmake-version: v2.8.8 + xmake-version: v2.8.9 - name: update repo run: xmake repo -u - name: git crlf From aff027a3196f57217c6373aa71f0041a95becd63 Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sun, 2 Jun 2024 13:39:48 +0800 Subject: [PATCH 09/12] fix missing file of wasm --- xmake.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xmake.lua b/xmake.lua index a94648712..6a73caa1a 100644 --- a/xmake.lua +++ b/xmake.lua @@ -311,7 +311,7 @@ if has_config("enable_tests") then defines = "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN"}) end target("tests")do - set_kind("object") + set_kind("binary") add_deps("liblolly") set_languages("c++17") set_policy("check.auto_ignore_flags", false) @@ -322,6 +322,8 @@ if has_config("enable_tests") then if is_plat("mingw") then add_packages("mingw-w64") + elseif is_plat("wasm") then + add_packages("emscripten") end add_packages("tbox") add_packages("doctest") From 8b680bd82f2ecb534758943d59017deefa500e34 Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sun, 2 Jun 2024 15:45:05 +0800 Subject: [PATCH 10/12] make path more robust --- xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake.lua b/xmake.lua index 6a73caa1a..d9a64708f 100644 --- a/xmake.lua +++ b/xmake.lua @@ -342,7 +342,7 @@ if has_config("enable_tests") then add_ldflags("-s DISABLE_EXCEPTION_CATCHING=0") set_values("wasm.preloadfiles", {"xmake.lua", "tests", "LICENSE"}) on_test(function (target, opt) - node = os.getenv("EMSDK_NODE") + node = path.splitenv(os.getenv("EMSDK_NODE"))[1] os.cd(target:targetdir()) print("> cd " .. target:targetdir()) cmd = node .. " " .. path.join(target:targetdir(), target:basename() .. ".js") From 2e55f0b0b24d7ecee424284e3af16106557ec441 Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sun, 2 Jun 2024 16:04:40 +0800 Subject: [PATCH 11/12] use node path added by xmake --- xmake.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xmake.lua b/xmake.lua index d9a64708f..908869ace 100644 --- a/xmake.lua +++ b/xmake.lua @@ -342,7 +342,8 @@ if has_config("enable_tests") then add_ldflags("-s DISABLE_EXCEPTION_CATCHING=0") set_values("wasm.preloadfiles", {"xmake.lua", "tests", "LICENSE"}) on_test(function (target, opt) - node = path.splitenv(os.getenv("EMSDK_NODE"))[1] + 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") From 8b6786bd752e7ff229eaad11907a2326a272a371 Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Sun, 2 Jun 2024 16:14:17 +0800 Subject: [PATCH 12/12] exclude shared library test on wasm --- .github/workflows/ci-xmake-wasm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-xmake-wasm.yml b/.github/workflows/ci-xmake-wasm.yml index 9eeba64a3..4c561957d 100644 --- a/.github/workflows/ci-xmake-wasm.yml +++ b/.github/workflows/ci-xmake-wasm.yml @@ -52,7 +52,7 @@ jobs: - 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: