[Tarantool-patches] [PATCH v2 luajit 17/26] test: enable <ffi_new.lua> in LuaJIT-tests
Sergey Kaplun
skaplun at tarantool.org
Mon Jan 29 13:45:17 MSK 2024
This patch changes `dofile()` (which uses an unreliable relative file
path and mutates `_G` with global functions to be defined) to the
corresponding require of the helper function. It adds groups with the
names of subtests and enables the test in <index>. It renames structures
typedefs to avoid conflicts with cdef in other tests. The GC threshold
is increased since all tests run in a single process, so the number of
GC objects is greater.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_new.lua | 50 +++++++++++++--------------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_new.lua b/test/LuaJIT-tests/lib/ffi/ffi_new.lua
index 9cdbd538..e5b19053 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_new.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_new.lua
@@ -1,37 +1,37 @@
local ffi = require("ffi")
local bit = require("bit")
-dofile("../common/ffi_util.inc")
+local fails = require("common.fails")
ffi.cdef([[
-typedef struct { int a,b,c; } foo1_t;
-typedef int foo2_t[?];
+typedef struct { int a,b,c; } foo1_new_t;
+typedef int foo2_new_t[?];
void *malloc(size_t size);
void free(void *ptr);
]])
-do
- assert(ffi.sizeof("foo1_t") == 12)
- local cd = ffi.new("foo1_t")
+do --- foo1_new_t
+ assert(ffi.sizeof("foo1_new_t") == 12)
+ local cd = ffi.new("foo1_new_t")
assert(ffi.sizeof(cd) == 12)
- local foo1_t = ffi.typeof("foo1_t")
- assert(ffi.sizeof(foo1_t) == 12)
- cd = foo1_t()
+ local foo1_new_t = ffi.typeof("foo1_new_t")
+ assert(ffi.sizeof(foo1_new_t) == 12)
+ cd = foo1_new_t()
assert(ffi.sizeof(cd) == 12)
end
-do
- assert(ffi.sizeof("foo2_t", 3) == 12)
- local cd = ffi.new("foo2_t", 3)
+do --- foo2_new_t
+ assert(ffi.sizeof("foo2_new_t", 3) == 12)
+ local cd = ffi.new("foo2_new_t", 3)
assert(ffi.sizeof(cd) == 12)
- local foo2_t = ffi.typeof("foo2_t")
- fails(ffi.sizeof, foo2_t)
- assert(ffi.sizeof(foo2_t, 3) == 12)
- cd = foo2_t(3)
+ local foo2_new_t = ffi.typeof("foo2_new_t")
+ fails(ffi.sizeof, foo2_new_t)
+ assert(ffi.sizeof(foo2_new_t, 3) == 12)
+ cd = foo2_new_t(3)
assert(ffi.sizeof(cd) == 12)
end
-do
+do --- byte to int cast
local tpi = ffi.typeof("int")
local tpb = ffi.typeof("uint8_t")
local t = {}
@@ -42,7 +42,7 @@ do
assert(x == 199*257 + 1)
end
-do
+do --- aligned structure GC
local oc = collectgarbage("count")
for al=0,15 do
local align = 2^al -- 1, 2, 4, ..., 32768
@@ -54,17 +54,17 @@ do
end
end
local nc = collectgarbage("count")
- assert(nc < oc + 3000, "GC step missing for ffi.new")
+ assert(nc < oc * 10, "GC step missing for ffi.new")
end
-do
+do --- VLA
local t = {}
for i=1,100 do t[i] = ffi.new("int[?]", i) end
assert(ffi.sizeof(t[100]) == 400)
for i=0,99 do assert(t[100][i] == 0) end
end
-do
+do --- VLS
local t = {}
local ct = ffi.typeof("struct { double x; int y[?];}")
for i=1,100 do t[i] = ct(i) end
@@ -72,7 +72,7 @@ do
for i=0,99 do assert(t[100].y[i] == 0) end
end
-do
+do --- aligned(16) structure exit from trace
local ct = ffi.typeof("struct __attribute__((aligned(16))) { int x; }")
local y
for i=1,200 do
@@ -82,7 +82,7 @@ do
assert(bit.band(ffi.cast("intptr_t", ffi.cast("void *", y)), 15) == 0)
end
-do
+do --- cdata resurrecting
local q
local p = ffi.gc(ffi.new("int[1]"), function(x) q = x end)
p = nil
@@ -93,13 +93,13 @@ do
assert(q == nil)
end
-do
+do --- GC malloc free
local p = ffi.gc(ffi.C.malloc(2^20), ffi.C.free)
p = nil
collectgarbage()
end
-do
+do --- test lua_close() cleanup
local p = ffi.gc(ffi.new("int[1]"), function(x) assert(type(x) == "cdata") end)
-- test for lua_close() cleanup.
end
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 338a6930..e6c1fd0f 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -15,6 +15,7 @@ ffi_jit_call.lua
ffi_jit_conv.lua
ffi_lex_number.lua
ffi_metatype.lua
+ffi_new.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
More information about the Tarantool-patches
mailing list