summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristian Rendina <[email protected]>2025-04-10 09:50:37 +0200
committerChristian Rendina <[email protected]>2025-04-10 09:50:37 +0200
commit78723913d76fb8b615df34541236b8ea588d30db (patch)
treeb6b6ff550e4a2f73d94c63a61876cec31a4b3ae3 /tests
parent2051c13f735a626f7b6fd8b98aa69f01fd9cef7e (diff)
parentfd49b7754c6709a87b5beb5526788bbc1a663965 (diff)
Merge branch 'dev' of https://github.com/xmake-io/xmake into dev
Diffstat (limited to 'tests')
-rw-r--r--tests/apis/rules_inject_deps/xmake.lua6
-rw-r--r--tests/apis/rules_order/xmake.lua20
-rw-r--r--tests/modules/async/run_callback.lua19
-rw-r--r--tests/modules/async/run_jobgraph.lua53
-rw-r--r--tests/modules/async/run_jobpool.lua28
-rw-r--r--tests/modules/graph/test.lua141
-rw-r--r--tests/modules/queue/test.lua35
-rw-r--r--tests/modules/scheduler/runjobs.lua43
-rw-r--r--tests/projects/c++/modules/hello_with_pch/src/hello.mpp10
-rw-r--r--tests/projects/c++/modules/hello_with_pch/src/main.cpp8
-rw-r--r--tests/projects/c++/modules/hello_with_pch/src/test.h1
-rw-r--r--tests/projects/c++/modules/hello_with_pch/xmake.lua7
-rw-r--r--tests/projects/c++/modules/test_pch.lua31
-rw-r--r--tests/projects/other/build_deps/xmake.lua6
-rw-r--r--tests/projects/other/merge_archive/xmake.lua3
-rw-r--r--tests/projects/other/merge_object/xmake.lua2
16 files changed, 355 insertions, 58 deletions
diff --git a/tests/apis/rules_inject_deps/xmake.lua b/tests/apis/rules_inject_deps/xmake.lua
index cf73449bb..880bcde32 100644
--- a/tests/apis/rules_inject_deps/xmake.lua
+++ b/tests/apis/rules_inject_deps/xmake.lua
@@ -1,10 +1,6 @@
rule("cppfront")
set_extensions(".cpp2")
- on_load(function (target)
- local rule = target:rule("c++.build"):clone()
- rule:add("deps", "cppfront", {order = true})
- target:rule_add(rule)
- end)
+ add_orders("cppfront", "c++.build")
on_build_file(function (target, sourcefile, opt)
print("build cppfront file")
local objectfile = target:objectfile(sourcefile:gsub("cpp2", "cpp"))
diff --git a/tests/apis/rules_order/xmake.lua b/tests/apis/rules_order/xmake.lua
index ea167dca9..e05dc7bd2 100644
--- a/tests/apis/rules_order/xmake.lua
+++ b/tests/apis/rules_order/xmake.lua
@@ -1,7 +1,15 @@
rule("markdown")
- add_deps("man", {order = true})
set_extensions(".md", ".markdown")
+ add_orders("man", "markdown")
+
+ before_build(function (target)
+ print("before_build: markdown")
+ end)
+ after_build(function (target)
+ print("after_build: markdown")
+ end)
+
before_build_file(function (target, sourcefile)
print("before_build_file: %s", sourcefile)
end)
@@ -14,6 +22,14 @@ rule("markdown")
rule("man")
set_extensions(".man")
+
+ before_build(function (target)
+ print("before_build: man")
+ end)
+ after_build(function (target)
+ print("after_build: man")
+ end)
+
before_build_file(function (target, sourcefile)
print("before_build_file: %s", sourcefile)
end)
@@ -26,7 +42,7 @@ rule("man")
target("test")
set_kind("binary")
- add_rules("markdown")
+ add_rules("markdown", "man")
add_files("src/*.c")
add_files("src/*.md")
add_files("src/*.man")
diff --git a/tests/modules/async/run_callback.lua b/tests/modules/async/run_callback.lua
new file mode 100644
index 000000000..21e75014b
--- /dev/null
+++ b/tests/modules/async/run_callback.lua
@@ -0,0 +1,19 @@
+import("core.base.scheduler")
+import("async.runjobs")
+
+function _jobfunc(index, total, opt)
+ print("%s: run job (%d/%d)", scheduler.co_running(), index, total)
+ local dt = os.mclock()
+ os.sleep(1000)
+ dt = os.mclock() - dt
+ print("%s: run job (%d/%d) end, progress: %s, dt: %d ms", scheduler.co_running(), index, total, opt.progress, dt)
+end
+
+function main()
+ print("==================================== test callback ====================================")
+ local t = os.mclock()
+ runjobs("test", _jobfunc, {total = 100, comax = 6, timeout = 1000, timer = function (running_jobs_indices)
+ print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ","))
+ end})
+end
+
diff --git a/tests/modules/async/run_jobgraph.lua b/tests/modules/async/run_jobgraph.lua
new file mode 100644
index 000000000..fe53a54c6
--- /dev/null
+++ b/tests/modules/async/run_jobgraph.lua
@@ -0,0 +1,53 @@
+import("core.base.scheduler")
+import("async.jobgraph")
+import("async.runjobs")
+
+function _jobfunc(index, total, opt)
+ print("%s: run job (%d/%d)", scheduler.co_running(), index, total)
+ local dt = os.mclock()
+ os.sleep(1000)
+ dt = os.mclock() - dt
+ print("%s: run job (%d/%d) end, progress: %s, dt: %d ms", scheduler.co_running(), index, total, opt.progress, dt)
+end
+
+function _test_basic()
+ print("==================================== test basic ====================================")
+ local jobs = jobgraph.new()
+ jobs:add("job/root", _jobfunc)
+ for i = 1, 3 do
+ jobs:add("job/" .. i, _jobfunc)
+ for j = 1, 50 do
+ jobs:add("job/" .. i .. "/" .. j, _jobfunc)
+ jobs:add_orders("job/" .. i .. "/" .. j, "job/" .. i, "job/root")
+ end
+ end
+ t = os.mclock()
+ runjobs("test", jobs, {comax = 6, timeout = 1000, timer = function (running_jobs_indices)
+ print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ","))
+ end})
+end
+
+function _test_group()
+ print("==================================== test group ====================================")
+ local jobs = jobgraph.new()
+ jobs:add("job/root", _jobfunc)
+ for i = 1, 3 do
+ jobs:add("job/" .. i, _jobfunc, {groups = "bar"})
+ jobs:group("foo", function ()
+ for j = 1, 50 do
+ jobs:add("job/" .. i .. "/" .. j, _jobfunc)
+ end
+ end)
+ end
+ jobs:add_orders("foo", "bar", "job/root")
+ t = os.mclock()
+ runjobs("test", jobs, {comax = 6, timeout = 1000, timer = function (running_jobs_indices)
+ print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ","))
+ end})
+end
+
+function main()
+ _test_basic()
+ _test_group()
+end
+
diff --git a/tests/modules/async/run_jobpool.lua b/tests/modules/async/run_jobpool.lua
new file mode 100644
index 000000000..5de54e36c
--- /dev/null
+++ b/tests/modules/async/run_jobpool.lua
@@ -0,0 +1,28 @@
+import("core.base.scheduler")
+import("private.async.jobpool")
+import("async.runjobs")
+
+function _jobfunc(index, total, opt)
+ print("%s: run job (%d/%d)", scheduler.co_running(), index, total)
+ local dt = os.mclock()
+ os.sleep(1000)
+ dt = os.mclock() - dt
+ print("%s: run job (%d/%d) end, progress: %s, dt: %d ms", scheduler.co_running(), index, total, opt.progress, dt)
+end
+
+function main()
+ print("==================================== test jobpool ====================================")
+ local jobs = jobpool.new()
+ local root = jobs:addjob("job/root", _jobfunc)
+ for i = 1, 3 do
+ local job = jobs:addjob("job/" .. i, _jobfunc, {rootjob = root})
+ for j = 1, 50 do
+ jobs:addjob("job/" .. i .. "/" .. j, _jobfunc, {rootjob = job})
+ end
+ end
+ t = os.mclock()
+ runjobs("test", jobs, {comax = 6, timeout = 1000, timer = function (running_jobs_indices)
+ print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ","))
+ end})
+end
+
diff --git a/tests/modules/graph/test.lua b/tests/modules/graph/test.lua
index 63095be12..fe1d63e8d 100644
--- a/tests/modules/graph/test.lua
+++ b/tests/modules/graph/test.lua
@@ -1,6 +1,6 @@
import("core.base.graph")
-function test_topological_sort(t)
+function test_topo_sort(t)
local edges = {
{0, 5},
{0, 2},
@@ -18,7 +18,7 @@ function test_topological_sort(t)
for _, e in ipairs(edges) do
dag:add_edge(e[1], e[2])
end
- local order_path = dag:topological_sort()
+ local order_path = dag:topo_sort()
local orders = {}
for i, v in ipairs(order_path) do
orders[v] = i
@@ -28,7 +28,7 @@ function test_topological_sort(t)
end
dag = dag:reverse()
- order_path = dag:topological_sort()
+ order_path = dag:topo_sort()
orders = {}
for i, v in ipairs(order_path) do
orders[v] = i
@@ -38,6 +38,138 @@ function test_topological_sort(t)
end
end
+function test_paritail_topo_sort(t)
+ local function partiail_topo_sort(dag)
+ dag:partial_topo_sort_reset()
+
+ local node, has_cycle
+ local order_vertices = {}
+ while true do
+ node, has_cycle = dag:partial_topo_sort_next()
+ if node then
+ table.insert(order_vertices, node)
+ dag:partial_topo_sort_remove(node)
+ else
+ if has_cycle then
+ raise("has cycle!")
+ end
+ break
+ end
+ end
+
+ return order_vertices, has_cycle
+ end
+
+ local edges = {
+ {0, 5},
+ {0, 2},
+ {0, 1},
+ {3, 6},
+ {3, 5},
+ {3, 4},
+ {5, 4},
+ {6, 4},
+ {6, 0},
+ {3, 2},
+ {1, 4},
+ {2, 9},
+ }
+ local dag = graph.new(true)
+ for _, e in ipairs(edges) do
+ dag:add_edge(e[1], e[2])
+ end
+ local order_path = partiail_topo_sort(dag)
+ local orders = {}
+ for i, v in ipairs(order_path) do
+ orders[v] = i
+ end
+ for _, e in ipairs(edges) do
+ t:require(orders[e[1]] < orders[e[2]])
+ end
+
+ dag = dag:reverse()
+ order_path = partiail_topo_sort(dag)
+ orders = {}
+ for i, v in ipairs(order_path) do
+ orders[v] = i
+ end
+ for _, e in ipairs(edges) do
+ t:require(orders[e[1]] > orders[e[2]])
+ end
+end
+
+function test_paritail_topo_sort_dynamic(t)
+ local function partiail_topo_sort(dag)
+ dag:partial_topo_sort_reset()
+
+ local node, has_cycle
+ local order_vertices = {}
+ local dynamic_adjust = false
+ while true do
+ node, has_cycle = dag:partial_topo_sort_next()
+ if node then
+ if not dynamic_adjust then
+ dag:add_edge(1, 4)
+ dag:remove_vertex(6)
+ end
+ table.insert(order_vertices, node)
+ dag:partial_topo_sort_remove(node)
+ if not dynamic_adjust then
+ dag:add_edge(2, 9)
+ dynamic_adjust = true
+ end
+ else
+ if has_cycle then
+ raise("has cycle!")
+ end
+ break
+ end
+ end
+
+ assert(#order_vertices == #dag:vertices(), "vertices count not matched, %d != %d", #order_vertices, #dag:vertices())
+ return order_vertices, has_cycle
+ end
+
+ local edges = {
+ {0, 5},
+ {0, 2},
+ {0, 1},
+ {3, 6},
+ {3, 5},
+ {3, 4},
+ {5, 4},
+ {6, 4},
+ {6, 0},
+ {3, 2},
+ }
+ local dag = graph.new(true)
+ for _, e in ipairs(edges) do
+ dag:add_edge(e[1], e[2])
+ end
+ local order_path = partiail_topo_sort(dag)
+ local orders = {}
+ for i, v in ipairs(order_path) do
+ orders[v] = i
+ end
+ edges = {
+ {0, 5},
+ {0, 2},
+ {0, 1},
+ -- {3, 6},
+ {3, 5},
+ {3, 4},
+ {5, 4},
+ -- {6, 4},
+ -- {6, 0},
+ {3, 2},
+ {1, 4},
+ {2, 9}
+ }
+ for _, e in ipairs(edges) do
+ t:require(orders[e[1]] < orders[e[2]])
+ end
+end
+
function test_find_cycle(t)
local edges = {
{9, 1},
@@ -52,5 +184,8 @@ function test_find_cycle(t)
end
local cycle = dag:find_cycle()
t:are_equal(cycle, {1, 6, 0})
+
+ local _, has_cycle = dag:topo_sort()
+ t:require(has_cycle)
end
diff --git a/tests/modules/queue/test.lua b/tests/modules/queue/test.lua
new file mode 100644
index 000000000..b577e04c9
--- /dev/null
+++ b/tests/modules/queue/test.lua
@@ -0,0 +1,35 @@
+import("core.base.queue")
+
+function test_push(t)
+ local d = queue.new()
+ d:push(1)
+ d:push(2)
+ d:push(3)
+ d:push(4)
+ d:push(5)
+ t:are_equal(d:first(), 1)
+ t:are_equal(d:last(), 5)
+ local idx = 1
+ for item in d:items() do
+ t:are_equal(item, idx)
+ idx = idx + 1
+ end
+end
+
+function test_pop(t)
+ local d = queue.new()
+ d:push(1)
+ d:push(2)
+ d:push(3)
+ d:push(4)
+ d:push(5)
+ d:pop()
+ t:are_equal(d:first(), 2)
+ t:are_equal(d:last(), 5)
+ local idx = 2
+ for item in d:items() do
+ t:are_equal(item, idx)
+ idx = idx + 1
+ end
+end
+
diff --git a/tests/modules/scheduler/runjobs.lua b/tests/modules/scheduler/runjobs.lua
deleted file mode 100644
index 4e2a98cc0..000000000
--- a/tests/modules/scheduler/runjobs.lua
+++ /dev/null
@@ -1,43 +0,0 @@
-import("core.base.scheduler")
-import("private.async.jobpool")
-import("async.runjobs")
-
-function _jobfunc(index, total, opt)
- print("%s: run job (%d/%d)", scheduler.co_running(), index, total)
- local dt = os.mclock()
- os.sleep(1000)
- dt = os.mclock() - dt
- print("%s: run job (%d/%d) end, progress: %s, dt: %d ms", scheduler.co_running(), index, total, opt.progress, dt)
-end
-
-function main()
-
- -- test callback
- print("==================================== test callback ====================================")
- local t = os.mclock()
- runjobs("test", _jobfunc, {total = 100, comax = 6, timeout = 1000, timer = function (running_jobs_indices)
- print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ","))
- end})
-
- -- test jobs
- print("==================================== test jobs ====================================")
- local jobs = jobpool.new()
- local root = jobs:addjob("job/root", function (index, total, opt)
- _jobfunc(index, total, opt)
- end)
- for i = 1, 3 do
- local job = jobs:addjob("job/" .. i, function (index, total, opt)
- _jobfunc(index, total, opt)
- end, {rootjob = root})
- for j = 1, 50 do
- jobs:addjob("job/" .. i .. "/" .. j, function (index, total, opt)
- _jobfunc(index, total, opt)
- end, {rootjob = job})
- end
- end
- t = os.mclock()
- runjobs("test", jobs, {comax = 6, timeout = 1000, timer = function (running_jobs_indices)
- print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ","))
- end})
-end
-
diff --git a/tests/projects/c++/modules/hello_with_pch/src/hello.mpp b/tests/projects/c++/modules/hello_with_pch/src/hello.mpp
new file mode 100644
index 000000000..124bd72bc
--- /dev/null
+++ b/tests/projects/c++/modules/hello_with_pch/src/hello.mpp
@@ -0,0 +1,10 @@
+module;
+#include <cstdio>
+
+export module hello;
+
+export namespace hello {
+ void say(const char* str) {
+ printf("%s\n", str);
+ }
+}
diff --git a/tests/projects/c++/modules/hello_with_pch/src/main.cpp b/tests/projects/c++/modules/hello_with_pch/src/main.cpp
new file mode 100644
index 000000000..739309dd4
--- /dev/null
+++ b/tests/projects/c++/modules/hello_with_pch/src/main.cpp
@@ -0,0 +1,8 @@
+#include "test.h"
+
+import hello;
+
+int main() {
+ hello::say("hello module!");
+ return 0;
+}
diff --git a/tests/projects/c++/modules/hello_with_pch/src/test.h b/tests/projects/c++/modules/hello_with_pch/src/test.h
new file mode 100644
index 000000000..d5a732287
--- /dev/null
+++ b/tests/projects/c++/modules/hello_with_pch/src/test.h
@@ -0,0 +1 @@
+#include <string>
diff --git a/tests/projects/c++/modules/hello_with_pch/xmake.lua b/tests/projects/c++/modules/hello_with_pch/xmake.lua
new file mode 100644
index 000000000..79ddb6b58
--- /dev/null
+++ b/tests/projects/c++/modules/hello_with_pch/xmake.lua
@@ -0,0 +1,7 @@
+add_rules("mode.release", "mode.debug")
+set_languages("c++20")
+
+target("hello")
+ set_kind("binary")
+ set_pcxxheader("src/test.h")
+ add_files("src/*.cpp", "src/*.mpp")
diff --git a/tests/projects/c++/modules/test_pch.lua b/tests/projects/c++/modules/test_pch.lua
new file mode 100644
index 000000000..98286c229
--- /dev/null
+++ b/tests/projects/c++/modules/test_pch.lua
@@ -0,0 +1,31 @@
+import("lib.detect.find_tool")
+import("core.base.semver")
+import("detect.sdks.find_vstudio")
+import("utils.ci.is_running", {alias = "ci_is_running"})
+
+function _build()
+ if ci_is_running() then
+ os.run("xmake -rvD")
+ else
+ os.run("xmake -r")
+ end
+ local outdata = os.iorun("xmake")
+ if outdata then
+ if outdata:find("compiling") or outdata:find("linking") or outdata:find("generating") then
+ raise("Modules incremental compilation does not work\n%s", outdata)
+ end
+ end
+end
+
+function main(t)
+ -- TODO c++ modules with pch does not work for gcc now.
+ if is_host("linux") then
+ local clang = find_tool("clang", {version = true})
+ if clang then
+ os.exec("xmake f --toolchain=clang -c --yes --policies=build.c++.modules.std:n,build.c++.clang.fallbackscanner")
+ _build()
+ end
+ else
+ _build()
+ end
+end
diff --git a/tests/projects/other/build_deps/xmake.lua b/tests/projects/other/build_deps/xmake.lua
index 5729b5c8f..b2324e3dd 100644
--- a/tests/projects/other/build_deps/xmake.lua
+++ b/tests/projects/other/build_deps/xmake.lua
@@ -4,7 +4,7 @@ target("dep1")
set_kind("static")
add_deps("dep3")
add_files("src/dep1.c")
- set_policy("build.across_targets_in_parallel", false)
+ set_policy("build.fence", true)
after_load(function (target)
os.rm(target:targetfile())
os.rm(target:dep("dep3"):targetfile())
@@ -21,7 +21,7 @@ target("dep2")
set_kind("static")
add_deps("dep3")
add_files("src/dep2.c")
- set_policy("build.across_targets_in_parallel", false)
+ set_policy("build.fence", true)
after_load(function (target)
os.rm(target:targetfile())
os.rm(target:dep("dep3"):targetfile())
@@ -38,7 +38,7 @@ target("dep3")
set_kind("static")
add_files("src/dep3.c")
add_deps("dep4", "dep5")
- set_policy("build.across_targets_in_parallel", false)
+ set_policy("build.fence", true)
after_load(function (target)
os.rm(target:targetfile())
os.rm(target:dep("dep4"):targetfile())
diff --git a/tests/projects/other/merge_archive/xmake.lua b/tests/projects/other/merge_archive/xmake.lua
index 11092dec9..7cf74471d 100644
--- a/tests/projects/other/merge_archive/xmake.lua
+++ b/tests/projects/other/merge_archive/xmake.lua
@@ -3,18 +3,19 @@ add_rules("mode.debug", "mode.release")
target("add")
set_kind("static")
add_files("src/add.c")
+ set_policy("build.fence", true)
set_targetdir("$(buildir)/merge_archive")
target("sub")
set_kind("static")
add_files("src/sub.c")
+ set_policy("build.fence", true)
set_targetdir("$(buildir)/merge_archive")
target("mul")
set_kind("static")
add_deps("add", "sub")
add_files("src/mul.c")
- set_policy("build.across_targets_in_parallel", false)
if is_plat("windows") then
add_files("$(buildir)/merge_archive/*.lib")
else
diff --git a/tests/projects/other/merge_object/xmake.lua b/tests/projects/other/merge_object/xmake.lua
index b8799a0b8..bbd7c1f98 100644
--- a/tests/projects/other/merge_object/xmake.lua
+++ b/tests/projects/other/merge_object/xmake.lua
@@ -1,9 +1,9 @@
add_rules("mode.debug", "mode.release")
-set_policy("build.across_targets_in_parallel", false)
target("merge_object")
set_kind("static")
add_files("src/interface.c")
+ set_policy("build.fence", true)
after_build_file(function (target, sourcefile)
os.cp(target:objectfile(sourcefile), "$(buildir)/merge_object/")
end)