summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2023-12-28 18:52:35 +0800
committerGitHub <[email protected]>2023-12-28 18:52:35 +0800
commitda3b723be857e3a2fe4e229265caf6246db1f0dd (patch)
treec330648539432dcfd2df6e7582b789aaba74c272 /xmake
parentc68263277c8c25f5fe3a9bed275e09a96372d0a7 (diff)
parent945fa0908fbfed1f83020658e6fd9791bbc569b0 (diff)
Merge pull request #4545 from xmake-io/tests
Support to wait timeout for `xmake test`
Diffstat (limited to 'xmake')
-rw-r--r--xmake/actions/test/main.lua14
-rw-r--r--xmake/core/base/os.lua12
2 files changed, 22 insertions, 4 deletions
diff --git a/xmake/actions/test/main.lua b/xmake/actions/test/main.lua
index f61c6e1e0..a61e40966 100644
--- a/xmake/actions/test/main.lua
+++ b/xmake/actions/test/main.lua
@@ -55,7 +55,9 @@ function _do_test_target(target, opt)
local runargs = table.wrap(opt.runargs or target:get("runargs"))
local outfile = os.tmpfile()
local errfile = os.tmpfile()
- local ok, syserrors = os.execv(targetfile, runargs, {try = true, curdir = rundir, envs = envs, stdout = outfile, stderr = errfile})
+ local run_timeout = opt.run_timeout
+ local ok, syserrors = os.execv(targetfile, runargs, {try = true, timeout = run_timeout,
+ curdir = rundir, envs = envs, stdout = outfile, stderr = errfile})
local outdata = os.isfile(outfile) and io.readfile(outfile) or ""
if opt.trim_output then
outdata = outdata:trim()
@@ -65,7 +67,15 @@ function _do_test_target(target, opt)
errors = errdata or errors
if not errors or #errors == 0 then
if ok ~= nil then
- errors = string.format("%s\nrun failed, exit code: %d", outdata or "", ok)
+ errors = outdata or ""
+ if #errors > 0 then
+ errors = errors .. "\n"
+ end
+ if syserrors then
+ errors = errors .. string.format("run failed, exit code: %d, exit error: %s", ok, syserrors)
+ else
+ errors = errors .. string.format("run failed, exit code: %d", ok)
+ end
else
errors = string.format("run failed, exit error: %s", syserrors and syserrors or "unknown reason")
end
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 9bf835456..0cc3b4361 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -860,6 +860,7 @@ function os.execv(program, argv, opt)
-- open command
local ok = -1
+ local errors
local proc = process.openv(filename, argv or {}, openopt)
if proc ~= nil then
@@ -871,9 +872,16 @@ function os.execv(program, argv, opt)
-- wait process
if not opt.detach then
- local waitok, status = proc:wait(-1)
+ local waitok, status = proc:wait(opt.timeout or -1)
if waitok > 0 then
ok = status
+ elseif waitok == 0 and opt.timeout then
+ proc:kill()
+ waitok, status = proc:wait(-1)
+ if waitok > 0 then
+ ok = status
+ end
+ errors = "wait process timeout"
end
else
ok = 0
@@ -885,7 +893,7 @@ function os.execv(program, argv, opt)
-- cannot execute process
return nil, os.strerror()
end
- return ok
+ return ok, errors
end
-- run command and return output and error data