Skip to content

Commit

Permalink
Merge pull request #4947 from xmake-io/runjobs
Browse files Browse the repository at this point in the history
Improve runjobs
  • Loading branch information
waruqi authored Apr 9, 2024
2 parents 15af62b + 19b6700 commit c729be0
Show file tree
Hide file tree
Showing 14 changed files with 471 additions and 186 deletions.
162 changes: 162 additions & 0 deletions tests/modules/list/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import("core.base.list")

function test_push(t)
local d = list.new()
d:push({v = 1})
d:push({v = 2})
d:push({v = 3})
d:push({v = 4})
d:push({v = 5})
t:are_equal(d:first().v, 1)
t:are_equal(d:last().v, 5)
local idx = 1
for item in d:items() do
t:are_equal(item.v, idx)
idx = idx + 1
end
end

function test_insert(t)
local d = list.new()
local v3 = {v = 3}
d:insert({v = 1})
d:insert({v = 2})
d:insert(v3)
d:insert({v = 5})
d:insert({v = 4}, v3)
t:are_equal(d:first().v, 1)
t:are_equal(d:last().v, 5)
local idx = 1
for item in d:items() do
t:are_equal(item.v, idx)
idx = idx + 1
end
end

function test_remove(t)
local d = list.new()
local v3 = {v = 3}
d:insert({v = 1})
d:insert({v = 2})
d:insert(v3)
d:insert({v = 3})
d:insert({v = 4})
d:insert({v = 5})
d:remove(v3)
t:are_equal(d:first().v, 1)
t:are_equal(d:last().v, 5)
local idx = 1
for item in d:items() do
t:are_equal(item.v, idx)
idx = idx + 1
end
end

function test_remove_first(t)
local d = list.new()
d:push({v = 1})
d:push({v = 2})
d:push({v = 3})
d:push({v = 4})
d:push({v = 5})
d:remove_first()
t:are_equal(d:first().v, 2)
t:are_equal(d:last().v, 5)
local idx = 2
for item in d:items() do
t:are_equal(item.v, idx)
idx = idx + 1
end
end

function test_remove_last(t)
local d = list.new()
d:push({v = 1})
d:push({v = 2})
d:push({v = 3})
d:push({v = 4})
d:push({v = 5})
d:remove_last()
t:are_equal(d:first().v, 1)
t:are_equal(d:last().v, 4)
local idx = 1
for item in d:items() do
t:are_equal(item.v, idx)
idx = idx + 1
end
end

function test_for_remove(t)
local d = list.new()
d:push({v = 1})
d:push({v = 2})
d:push({v = 3})
d:push({v = 4})
d:push({v = 5})
t:are_equal(d:first().v, 1)
t:are_equal(d:last().v, 5)
local idx = 1
local item = d:first()
while item ~= nil do
local next = d:next(item)
t:are_equal(item.v, idx)
d:remove(item)
item = next
idx = idx + 1
end
t:require(d:empty())
end

function test_rfor_remove(t)
local d = list.new()
d:push({v = 1})
d:push({v = 2})
d:push({v = 3})
d:push({v = 4})
d:push({v = 5})
t:are_equal(d:first().v, 1)
t:are_equal(d:last().v, 5)
local idx = 5
local item = d:last()
while item ~= nil do
local prev = d:prev(item)
t:are_equal(item.v, idx)
d:remove(item)
item = prev
idx = idx - 1
end
t:require(d:empty())
end

function test_insert_first(t)
local d = list.new()
d:push({v = 2})
d:push({v = 3})
d:push({v = 4})
d:push({v = 5})
d:insert_first({v = 1})
t:are_equal(d:first().v, 1)
t:are_equal(d:last().v, 5)
local idx = 1
for item in d:items() do
t:are_equal(item.v, idx)
idx = idx + 1
end
end

function test_insert_last(t)
local d = list.new()
d:push({v = 1})
d:push({v = 2})
d:push({v = 3})
d:push({v = 4})
d:insert_last({v = 5})
t:are_equal(d:first().v, 1)
t:are_equal(d:last().v, 5)
local idx = 1
for item in d:items() do
t:are_equal(item.v, idx)
idx = idx + 1
end
end

4 changes: 2 additions & 2 deletions tests/modules/table/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function test_unwrap(t)
end

function test_orderkeys(t)
-- sort by modulo 2 then from the smallest to largest
-- sort by modulo 2 then from the smallest to largest
local f = function(a, b)
if a % 2 == 0 and b % 2 ~= 0 then
return true
Expand All @@ -40,7 +40,7 @@ function test_orderkeys(t)
end
return a < b
end

t:are_equal(table.orderkeys({[2] = 2, [1] = 1, [4] = 4, [3] = 3}, f), {2, 4, 1, 3})
t:are_equal(table.orderkeys({[1] = 1, [2] = 2, [3] = 3, [4] = 4}), {1, 2 , 3, 4})
end
3 changes: 3 additions & 0 deletions tests/projects/other/parallel_build/1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main(int argv, char** argv) {
return 0;
}
31 changes: 31 additions & 0 deletions tests/projects/other/parallel_build/2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Make this object complex and cost longer compile time...
#include <algorithm>
#include <any>
#include <bitset>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <optional>
#include <queue>
#include <string>
#include <unordered_map>
#include <variant>
#include <vector>

int main(int argc, char** argv) {
using Type = std::variant<int8_t, uint8_t, int16_t, uint16_t, int32_t,
uint32_t, int64_t, uint64_t, double, float>;
Type a, b, c;
a = 5;
b = 3.0;
c = 4.0f;
double r;
std::visit([&](auto a, auto b, auto c) { r = a + b + c; }, a, b, c);
std::visit([&](auto a, auto b, auto c) { r = a + b - c; }, a, b, c);
std::visit([&](auto a, auto b, auto c) { r = a - b - c; }, a, b, c);
std::visit([&](auto a, auto b, auto c) { r = (a + b + c) * 2; }, a, b, c);
std::visit([&](auto a, auto b, auto c) { r = (a + b - c) * 3; }, a, b, c);
return 0;
}
13 changes: 13 additions & 0 deletions tests/projects/other/parallel_build/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- These targets should compiled and linked concurrently.
add_rules("mode.release", "mode.debug", "mode.releasedbg")
set_policy("build.ccache", false)

target("first")
set_kind("binary")
add_files("1.cpp")
set_languages("clatest", "cxx20")

target("second")
set_kind("binary")
add_files("2.cpp")
set_languages("clatest", "cxx20")
5 changes: 0 additions & 5 deletions tests/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ end

-- run test with the given name
function _run_test_filter(name)

local tests = {}
local root = path.absolute(os.scriptdir())
-- find the test script
for _, script in ipairs(os.files(path.join(root, "**", name, "**", "test.lua"))) do
if not script:find(".xmake", 1, true) then
table.insert(tests, path.absolute(script))
Expand Down Expand Up @@ -55,9 +53,6 @@ function _run_test_filter(name)
end
end

-- main entry
function main(name)

-- run the given test
return _run_test_filter(name or "/")
end
11 changes: 7 additions & 4 deletions tests/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ function main(script)
end,
catch
{
function (error)
if not error:find("aborting because of ") then
context:print_error(error, v, "unhandled error")
function (errors)
if errors then
errors = tostring(errors)
end
if errors and not errors:find("aborting because of ") then
context:print_error(errors, v, "unhandled error")
else
raise(error)
raise(errors)
end
end
}
Expand Down
Loading

0 comments on commit c729be0

Please sign in to comment.