2015-12-21 04:48:23 +01:00
|
|
|
local ffi = require("ffi")
|
|
|
|
|
|
|
|
ffi.cdef[[
|
|
|
|
typedef struct timeval {
|
|
|
|
long tv_sec;
|
|
|
|
long tv_usec;
|
|
|
|
} timeval;
|
|
|
|
|
|
|
|
int gettimeofday(timeval *t, void *tzp);
|
2018-03-03 21:44:31 +01:00
|
|
|
|
|
|
|
typedef struct timespec {
|
|
|
|
long tv_sec;
|
|
|
|
long tv_nsec;
|
|
|
|
} timespec;
|
|
|
|
int clock_gettime(int clk_id, timespec *tp);
|
2015-12-21 04:48:23 +01:00
|
|
|
]]
|
|
|
|
|
2018-03-03 21:44:31 +01:00
|
|
|
function gettime()
|
|
|
|
local t = ffi.new("timeval")
|
|
|
|
ffi.C.gettimeofday(t, nil)
|
|
|
|
return tonumber(t.tv_sec) + tonumber(t.tv_usec) / 1000000.0
|
|
|
|
end
|
|
|
|
function monotime()
|
|
|
|
local ts = ffi.new("timespec")
|
|
|
|
ffi.C.clock_gettime(6, ts)
|
|
|
|
return tonumber(ts.tv_sec) + tonumber(ts.tv_nsec) / 1000000000.0
|
|
|
|
end
|
|
|
|
function sleep()
|
|
|
|
end
|
|
|
|
|
2015-12-21 04:48:23 +01:00
|
|
|
-- busted depends on luasocket just for gettime(), so just supply a definition
|
|
|
|
-- of that to avoid the dep
|
|
|
|
package.loaded['socket'] = {
|
2018-03-03 21:44:31 +01:00
|
|
|
gettime = gettime
|
|
|
|
}
|
|
|
|
package.loaded['system'] = {
|
|
|
|
gettime = gettime,
|
|
|
|
monotime = monotime,
|
|
|
|
sleep = sleep
|
2015-12-21 04:48:23 +01:00
|
|
|
}
|
|
|
|
|
2015-12-23 02:43:17 +01:00
|
|
|
package.loaded['term'] = {
|
|
|
|
isatty = function() return true end
|
|
|
|
}
|
|
|
|
|
2015-12-21 04:48:23 +01:00
|
|
|
require 'busted.runner'({ batch = true, standalone = false })
|