1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
-- OSX specific tests
local function init(S)
local helpers = require "syscall.helpers"
local types = S.types
local c = S.c
local abi = S.abi
local bit = require "syscall.bit"
local ffi = require "ffi"
local t, pt, s = types.t, types.pt, types.s
local assert = helpers.assert
local function fork_assert(cond, err, ...) -- if we have forked we need to fail in main thread not fork
if not cond then
print(tostring(err))
print(debug.traceback())
S.exit("failure")
end
if cond == true then return ... end
return cond, ...
end
local function assert_equal(...)
collectgarbage("collect") -- force gc, to test for bugs
return assert_equals(...)
end
local teststring = "this is a test string"
local size = 512
local buf = t.buffer(size)
local tmpfile = "XXXXYYYYZZZ4521" .. S.getpid()
local tmpfile2 = "./666666DDDDDFFFF" .. S.getpid()
local tmpfile3 = "MMMMMTTTTGGG" .. S.getpid()
local longfile = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" .. S.getpid()
local efile = "./tmpexXXYYY" .. S.getpid() .. ".sh"
local largeval = math.pow(2, 33) -- larger than 2^32 for testing
local mqname = "ljsyscallXXYYZZ" .. S.getpid()
local clean = function()
S.rmdir(tmpfile)
S.unlink(tmpfile)
S.unlink(tmpfile2)
S.unlink(tmpfile3)
S.unlink(longfile)
S.unlink(efile)
end
local test = {}
test.time = {
-- example of how to emulate clock_gettime() https://gist.github.com/jbenet/1087739
test_clock_get_time = function()
local clock = assert(S.host_get_clock_service(S.mach_host_self(), "CALENDAR"))
local mts = assert(S.clock_get_time(clock))
assert(S.mach_port_deallocate(nil, clock)) -- TODO this should be gc
end
}
return test
end
return {init = init}
|