2010-11-18 13:27:55 +00:00
|
|
|
-- common testing environment
|
|
|
|
require("posix")
|
|
|
|
|
|
|
|
-- escape codes to colorize output on terminal
|
|
|
|
local c1="\027[47;34m"
|
|
|
|
local c0="\027[0m"
|
|
|
|
|
|
|
|
---
|
|
|
|
-- writes colorized
|
|
|
|
--
|
|
|
|
function cwriteln(...)
|
|
|
|
io.write(c1, ...)
|
|
|
|
io.write(c0, "\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
-----
|
|
|
|
-- creates a tmp directory
|
|
|
|
function mktempd()
|
2010-11-19 10:38:21 +00:00
|
|
|
local f = io.popen('mktemp -d --tmpdir ltest.XXX', 'r')
|
2010-11-18 13:27:55 +00:00
|
|
|
local s = f:read('*a')
|
|
|
|
f:close()
|
|
|
|
s = s:gsub('[\n\r]+', ' ')
|
|
|
|
s = s:match("^%s*(.-)%s*$")
|
|
|
|
return s
|
|
|
|
end
|
|
|
|
|
|
|
|
-----
|
|
|
|
-- spawns a subprocess.
|
|
|
|
--
|
2010-11-18 16:33:48 +00:00
|
|
|
-- @returns the processes pid
|
|
|
|
--
|
2010-11-18 13:27:55 +00:00
|
|
|
function spawn(...)
|
2010-11-18 16:59:50 +00:00
|
|
|
args = {...}
|
|
|
|
cwriteln("spawning: ", table.concat(args, " "))
|
2010-11-18 13:27:55 +00:00
|
|
|
local pid = posix.fork()
|
|
|
|
if pid < 0 then
|
|
|
|
cwriteln("Error, failed fork!")
|
|
|
|
os.exit(-1)
|
|
|
|
end
|
2010-11-18 16:59:50 +00:00
|
|
|
if pid == 0 then
|
2010-11-18 13:27:55 +00:00
|
|
|
posix.exec(...)
|
|
|
|
-- should not return
|
|
|
|
cwriteln("Error, failed to spawn: ", ...)
|
|
|
|
os.exit(-1);
|
|
|
|
end
|
|
|
|
return pid
|
|
|
|
end
|
|
|
|
|