Skip to content

Commit

Permalink
add tests about crash issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaozg committed Aug 14, 2023
1 parent eac5451 commit 25cc517
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/manual-test-exit.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--come from https://github.com/luvit/luv/issues/599

-- run `lua manual-test-exit.lua || echo $?`
-- it shoud print `5`

local uv = require('luv')

local function setTimeout(callback, ms)
local timer = uv.new_timer()
timer:start(ms, 0, function()
timer:stop()
timer:close()
callback()
end)
return timer
end

setTimeout(function()
os.exit(5, true)
end, 1000)

uv.run()
4 changes: 4 additions & 0 deletions tests/manual-test-without-uv.run.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
local uv = require('luv')

local test = uv.new_pipe(false)
uv.close(test)
57 changes: 57 additions & 0 deletions tests/test-loop.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
return require('lib/tap')(function (test)

local function get_cmd()
local i=1
repeat
i=i-1
until not arg[i]
return arg[i+1]
end

local cmd = get_cmd()
local cwd = require('luv').cwd()
print("cmd: ", cmd)
print("cwd: ", cwd)

test("uv.loop_mode", function (print, p, expect, uv)
assert(uv.loop_mode() == nil)
local timer = uv.new_timer()
Expand All @@ -10,4 +23,48 @@ return require('lib/tap')(function (test)
end))
end)

test("issue #437, crash without uv.run", function (print, p, expect, uv)
local handle
local stdout = uv.new_pipe(false)

handle = uv.spawn(cmd, {
args = { "tests/manual-test-without-uv.run.lua" },
cwd = cwd,
stdio = {nil, stdout},
},
expect(function(status, signal)
print('#437', status, signal)
assert(status==0)
assert(signal==0)
handle:close()
end))

uv.read_start(stdout, expect(function (err, chunk)
p("stdout", {err=err,chunk=chunk})
uv.close(stdout)
end))
end)

test("issue #599, crash during calling os.exit", function (print, p, expect, uv)
local handle
local stdout = uv.new_pipe(false)

handle = uv.spawn(cmd, {
args = { "tests/manual-test-exit.lua" },
cwd = cwd,
stdio = {nil, stdout},
},
expect(function(status, signal)
print('#599', status, signal)
assert(status==5)
assert(signal==0)
handle:close()
end))

uv.read_start(stdout, expect(function (err, chunk)
p("stdout", {err=err,chunk=chunk})
uv.close(stdout)
end))
end)

end)

0 comments on commit 25cc517

Please sign in to comment.