* [Tarantool-patches] [PATCH luajit 01/25] test: prepare lauxilarily libs for LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-23 9:10 ` Sergey Bronnikov via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 02/25] test: separate LuaJIT helpers from ffi_util.inc Sergey Kaplun via Tarantool-patches
` (24 subsequent siblings)
25 siblings, 1 reply; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch adds rules to build C and C++ libs from the
<LuaJIT-tests/src/> directory. Also, it allows these libraries to be
loaded via `require()` (since `luaL_openlib()` evolves global state).
The name of "ctest" library is changed to "libctest" to allow it to be
loaded via both `ffi.load()` and `require()`.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/CMakeLists.txt | 29 +++++++++++++++++---
test/LuaJIT-tests/src/CMakeLists.txt | 40 ++++++++++++++++++++++++++++
test/LuaJIT-tests/src/ctest.c | 4 +--
test/LuaJIT-tests/test.lua | 7 +++--
4 files changed, 73 insertions(+), 7 deletions(-)
create mode 100644 test/LuaJIT-tests/src/CMakeLists.txt
diff --git a/test/LuaJIT-tests/CMakeLists.txt b/test/LuaJIT-tests/CMakeLists.txt
index 9cd76ee9..c52bcc71 100644
--- a/test/LuaJIT-tests/CMakeLists.txt
+++ b/test/LuaJIT-tests/CMakeLists.txt
@@ -1,12 +1,35 @@
# See the rationale in the root CMakeLists.txt
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
-add_custom_target(LuaJIT-tests DEPENDS ${LUAJIT_TEST_BINARY})
+add_subdirectory(src)
+
+add_custom_target(LuaJIT-tests
+ DEPENDS ${LUAJIT_TEST_BINARY} LuaJIT-tests-prepare
+)
+
+make_lua_path(LUA_CPATH
+ PATHS
+ ${CMAKE_CURRENT_BINARY_DIR}/src/?${CMAKE_SHARED_LIBRARY_SUFFIX}
+)
+
+set(LUAJIT_TESTS_ENV
+ "LUA_CPATH=\"${LUA_CPATH}\""
+)
+
+set(LD_LIBRARY_PATH "${CMAKE_CURRENT_BINARY_DIR}/src/:")
+
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+ list(APPEND LUAJIT_TESTS_ENV DYLD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
+else()
+ list(APPEND LUAJIT_TESTS_ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
+endif()
add_custom_command(TARGET LuaJIT-tests
COMMENT "Running LuaJIT-tests"
COMMAND
- ${LUAJIT_TEST_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua
- +slow +ffi +bit +jit
+ env
+ ${LUAJIT_TESTS_ENV}
+ ${LUAJIT_TEST_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua
+ +slow +ffi +bit +jit
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
diff --git a/test/LuaJIT-tests/src/CMakeLists.txt b/test/LuaJIT-tests/src/CMakeLists.txt
new file mode 100644
index 00000000..f07b3b6d
--- /dev/null
+++ b/test/LuaJIT-tests/src/CMakeLists.txt
@@ -0,0 +1,40 @@
+# See the rationale in the root CMakeLists.txt.
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
+
+# Build additional C/C++ libraries for tests.
+macro(BuildTestLib lib sources)
+ add_library(${lib} SHARED EXCLUDE_FROM_ALL ${sources})
+ target_include_directories(${lib} PRIVATE
+ ${LUAJIT_SOURCE_DIR}
+ )
+ set_target_properties(${lib} PROPERTIES
+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+ PREFIX ""
+ )
+ # XXX: The dynamic libraries are loaded with LuaJIT binary and
+ # use symbols from it. So it is totally OK to have unresolved
+ # symbols at build time.
+ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+ set_target_properties(${lib} PROPERTIES
+ LINK_FLAGS "-undefined dynamic_lookup"
+ )
+ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ # XXX: This is necessary mostly for openSUSE builds, see also
+ # https://bugzilla.suse.com/show_bug.cgi?id=1012388.
+ # Just strip out the linker flag to suppress this linker
+ # option.
+ string(REPLACE "-Wl,--no-undefined" ""
+ CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}"
+ )
+ endif()
+ list(APPEND TESTLIBS ${lib})
+endmacro()
+
+# Use `lib` prefix for loading via FFi and `require()`.
+BuildTestLib(libctest ctest.c)
+enable_language(CXX)
+BuildTestLib(cpptest cpptest.cpp)
+
+add_custom_target(LuaJIT-tests-prepare DEPENDS ${TESTLIBS})
+
+# vim: expandtab tabstop=2 shiftwidth=2
diff --git a/test/LuaJIT-tests/src/ctest.c b/test/LuaJIT-tests/src/ctest.c
index e99f2306..aa95b57b 100644
--- a/test/LuaJIT-tests/src/ctest.c
+++ b/test/LuaJIT-tests/src/ctest.c
@@ -332,8 +332,8 @@ static luaL_Reg ct_funcs[] = {
{NULL, NULL}
};
-LUA_API int luaopen_ctest(lua_State *L)
+LUA_API int luaopen_libctest(lua_State *L)
{
- luaL_register(L, "ctest", ct_funcs);
+ luaL_register(L, "libctest", ct_funcs);
return 1;
}
diff --git a/test/LuaJIT-tests/test.lua b/test/LuaJIT-tests/test.lua
index b064eff7..749a27e7 100644
--- a/test/LuaJIT-tests/test.lua
+++ b/test/LuaJIT-tests/test.lua
@@ -297,8 +297,11 @@ local function append_tree_to_plan(test_tree, opts, plan, prefix)
end
local function seal_globals()
- local sealed_mt = {__newindex = function()
- error("Tests should not mutate global state", 3)
+ local sealed_mt = {__newindex = function(_, k)
+ -- Allow to load C/C++ libraries for the test.
+ if k ~= "libctest" and k ~= "cpptest" then
+ error("Tests should not mutate global state", 3)
+ end
end}
local function seal(t)
if getmetatable(t) then return end
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 01/25] test: prepare lauxilarily libs for LuaJIT-tests
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 01/25] test: prepare lauxilarily libs for LuaJIT-tests Sergey Kaplun via Tarantool-patches
@ 2024-01-23 9:10 ` Sergey Bronnikov via Tarantool-patches
0 siblings, 0 replies; 45+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2024-01-23 9:10 UTC (permalink / raw)
To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches
Hi, Sergey!
thanks for the patch! see my comments below
Sergey
On 1/19/24 14:32, Sergey Kaplun wrote:
> This patch adds rules to build C and C++ libs from the
> <LuaJIT-tests/src/> directory. Also, it allows these libraries to be
> loaded via `require()` (since `luaL_openlib()` evolves global state).
> The name of "ctest" library is changed to "libctest" to allow it to be
> loaded via both `ffi.load()` and `require()`.
>
> Part of tarantool/tarantool#9398
> ---
> test/LuaJIT-tests/CMakeLists.txt | 29 +++++++++++++++++---
> test/LuaJIT-tests/src/CMakeLists.txt | 40 ++++++++++++++++++++++++++++
> test/LuaJIT-tests/src/ctest.c | 4 +--
> test/LuaJIT-tests/test.lua | 7 +++--
> 4 files changed, 73 insertions(+), 7 deletions(-)
> create mode 100644 test/LuaJIT-tests/src/CMakeLists.txt
>
> diff --git a/test/LuaJIT-tests/CMakeLists.txt b/test/LuaJIT-tests/CMakeLists.txt
> index 9cd76ee9..c52bcc71 100644
> --- a/test/LuaJIT-tests/CMakeLists.txt
> +++ b/test/LuaJIT-tests/CMakeLists.txt
> @@ -1,12 +1,35 @@
> # See the rationale in the root CMakeLists.txt
> cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
>
> -add_custom_target(LuaJIT-tests DEPENDS ${LUAJIT_TEST_BINARY})
> +add_subdirectory(src)
> +
> +add_custom_target(LuaJIT-tests
> + DEPENDS ${LUAJIT_TEST_BINARY} LuaJIT-tests-prepare
> +)
> +
> +make_lua_path(LUA_CPATH
> + PATHS
> + ${CMAKE_CURRENT_BINARY_DIR}/src/?${CMAKE_SHARED_LIBRARY_SUFFIX}
> +)
> +
> +set(LUAJIT_TESTS_ENV
> + "LUA_CPATH=\"${LUA_CPATH}\""
> +)
> +
> +set(LD_LIBRARY_PATH "${CMAKE_CURRENT_BINARY_DIR}/src/:")
> +
> +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
> + list(APPEND LUAJIT_TESTS_ENV DYLD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
> +else()
> + list(APPEND LUAJIT_TESTS_ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
> +endif()
>
> add_custom_command(TARGET LuaJIT-tests
> COMMENT "Running LuaJIT-tests"
> COMMAND
> - ${LUAJIT_TEST_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua
> - +slow +ffi +bit +jit
> + env
> + ${LUAJIT_TESTS_ENV}
> + ${LUAJIT_TEST_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua
> + +slow +ffi +bit +jit
> WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
> )
> diff --git a/test/LuaJIT-tests/src/CMakeLists.txt b/test/LuaJIT-tests/src/CMakeLists.txt
> new file mode 100644
> index 00000000..f07b3b6d
> --- /dev/null
> +++ b/test/LuaJIT-tests/src/CMakeLists.txt
> @@ -0,0 +1,40 @@
> +# See the rationale in the root CMakeLists.txt.
> +cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
> +
> +# Build additional C/C++ libraries for tests.
> +macro(BuildTestLib lib sources)
> + add_library(${lib} SHARED EXCLUDE_FROM_ALL ${sources})
> + target_include_directories(${lib} PRIVATE
> + ${LUAJIT_SOURCE_DIR}
> + )
> + set_target_properties(${lib} PROPERTIES
> + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
> + PREFIX ""
> + )
> + # XXX: The dynamic libraries are loaded with LuaJIT binary and
> + # use symbols from it. So it is totally OK to have unresolved
> + # symbols at build time.
> + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
> + set_target_properties(${lib} PROPERTIES
> + LINK_FLAGS "-undefined dynamic_lookup"
> + )
> + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
> + # XXX: This is necessary mostly for openSUSE builds, see also
> + # https://bugzilla.suse.com/show_bug.cgi?id=1012388.
> + # Just strip out the linker flag to suppress this linker
> + # option.
> + string(REPLACE "-Wl,--no-undefined" ""
> + CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}"
> + )
> + endif()
> + list(APPEND TESTLIBS ${lib})
> +endmacro()
> +
This macro duplicates the similar macro in BuildTestCLib in
tarantool-tests suite.
Why you don't want to generalize it and reuse in both suites?
> +# Use `lib` prefix for loading via FFi and `require()`.
Typo: FFi -> FFI
> +BuildTestLib(libctest ctest.c)
> +enable_language(CXX)
> +BuildTestLib(cpptest cpptest.cpp)
> +
> +add_custom_target(LuaJIT-tests-prepare DEPENDS ${TESTLIBS})
> +
> +# vim: expandtab tabstop=2 shiftwidth=2
> diff --git a/test/LuaJIT-tests/src/ctest.c b/test/LuaJIT-tests/src/ctest.c
> index e99f2306..aa95b57b 100644
> --- a/test/LuaJIT-tests/src/ctest.c
> +++ b/test/LuaJIT-tests/src/ctest.c
I would rename file to libctest.c or ltest.c (like Roberto do) to
highlight that it is a library.
> @@ -332,8 +332,8 @@ static luaL_Reg ct_funcs[] = {
> {NULL, NULL}
> };
>
> -LUA_API int luaopen_ctest(lua_State *L)
> +LUA_API int luaopen_libctest(lua_State *L)
> {
> - luaL_register(L, "ctest", ct_funcs);
> + luaL_register(L, "libctest", ct_funcs);
> return 1;
> }
> diff --git a/test/LuaJIT-tests/test.lua b/test/LuaJIT-tests/test.lua
> index b064eff7..749a27e7 100644
> --- a/test/LuaJIT-tests/test.lua
> +++ b/test/LuaJIT-tests/test.lua
> @@ -297,8 +297,11 @@ local function append_tree_to_plan(test_tree, opts, plan, prefix)
> end
>
> local function seal_globals()
> - local sealed_mt = {__newindex = function()
> - error("Tests should not mutate global state", 3)
> + local sealed_mt = {__newindex = function(_, k)
> + -- Allow to load C/C++ libraries for the test.
> + if k ~= "libctest" and k ~= "cpptest" then
> + error("Tests should not mutate global state", 3)
> + end
> end}
> local function seal(t)
> if getmetatable(t) then return end
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 02/25] test: separate LuaJIT helpers from ffi_util.inc
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 01/25] test: prepare lauxilarily libs for LuaJIT-tests Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-23 9:17 ` Sergey Bronnikov via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 03/25] test: enable <ffi_arith_ptr.lua> in LuaJIT-tests Sergey Kaplun via Tarantool-patches
` (23 subsequent siblings)
25 siblings, 1 reply; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch moves common helpers from <LuaJIT-tests/common/ffi_util.inc>
into separate files by analogy with <common/expect_error.lua>. The
`include()` helper isn't touched since it is used in system dependend
tests, which won't be modified for now.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/common/fails.lua | 3 +++
test/LuaJIT-tests/common/ffi/checkfail.lua | 10 +++++++++
test/LuaJIT-tests/common/ffi/checktypes.lua | 11 ++++++++++
test/LuaJIT-tests/common/ffi_util.inc | 23 ---------------------
4 files changed, 24 insertions(+), 23 deletions(-)
create mode 100644 test/LuaJIT-tests/common/fails.lua
create mode 100644 test/LuaJIT-tests/common/ffi/checkfail.lua
create mode 100644 test/LuaJIT-tests/common/ffi/checktypes.lua
diff --git a/test/LuaJIT-tests/common/fails.lua b/test/LuaJIT-tests/common/fails.lua
new file mode 100644
index 00000000..d555a2b5
--- /dev/null
+++ b/test/LuaJIT-tests/common/fails.lua
@@ -0,0 +1,3 @@
+return function(f, ...)
+ if pcall(f, ...) ~= false then error("failure expected", 2) end
+end
diff --git a/test/LuaJIT-tests/common/ffi/checkfail.lua b/test/LuaJIT-tests/common/ffi/checkfail.lua
new file mode 100644
index 00000000..60d8449a
--- /dev/null
+++ b/test/LuaJIT-tests/common/ffi/checkfail.lua
@@ -0,0 +1,10 @@
+local ffi = require("ffi")
+
+return function(t, f)
+ f = f or ffi.typeof
+ for i=1,1e9 do
+ local tp = t[i]
+ if not tp then break end
+ assert(pcall(f, tp) == false, tp)
+ end
+end
diff --git a/test/LuaJIT-tests/common/ffi/checktypes.lua b/test/LuaJIT-tests/common/ffi/checktypes.lua
new file mode 100644
index 00000000..6d748e3b
--- /dev/null
+++ b/test/LuaJIT-tests/common/ffi/checktypes.lua
@@ -0,0 +1,11 @@
+local ffi = require("ffi")
+
+return function(t)
+ for i=1,1e9,3 do
+ local tp = t[i+2]
+ if not tp then break end
+ local id = ffi.typeof(tp)
+ assert(ffi.sizeof(id) == t[i], tp)
+ assert(ffi.alignof(id) == t[i+1], tp)
+ end
+end
diff --git a/test/LuaJIT-tests/common/ffi_util.inc b/test/LuaJIT-tests/common/ffi_util.inc
index 1eee8dd9..9604d7b0 100644
--- a/test/LuaJIT-tests/common/ffi_util.inc
+++ b/test/LuaJIT-tests/common/ffi_util.inc
@@ -4,29 +4,6 @@
local ffi = require("ffi")
-function checkfail(t, f)
- f = f or ffi.typeof
- for i=1,1e9 do
- local tp = t[i]
- if not tp then break end
- assert(pcall(f, tp) == false, tp)
- end
-end
-
-function checktypes(t)
- for i=1,1e9,3 do
- local tp = t[i+2]
- if not tp then break end
- local id = ffi.typeof(tp)
- assert(ffi.sizeof(id) == t[i], tp)
- assert(ffi.alignof(id) == t[i+1], tp)
- end
-end
-
-function fails(f, ...)
- if pcall(f, ...) ~= false then error("failure expected", 2) end
-end
-
local incroot = os.getenv("INCROOT") or "/usr/include"
local cdefs = os.getenv("CDEFS") or ""
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 02/25] test: separate LuaJIT helpers from ffi_util.inc
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 02/25] test: separate LuaJIT helpers from ffi_util.inc Sergey Kaplun via Tarantool-patches
@ 2024-01-23 9:17 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:35 ` Sergey Kaplun via Tarantool-patches
0 siblings, 1 reply; 45+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2024-01-23 9:17 UTC (permalink / raw)
To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches
Hi, Sergey!
thanks for the patch!
On 1/19/24 14:32, Sergey Kaplun wrote:
> This patch moves common helpers from <LuaJIT-tests/common/ffi_util.inc>
> into separate files by analogy with <common/expect_error.lua>. The
Why do you need to move to separate files? What is an idea behind it?
> `include()` helper isn't touched since it is used in system dependend
> tests, which won't be modified for now.
>
> Part of tarantool/tarantool#9398
> ---
> test/LuaJIT-tests/common/fails.lua | 3 +++
> test/LuaJIT-tests/common/ffi/checkfail.lua | 10 +++++++++
> test/LuaJIT-tests/common/ffi/checktypes.lua | 11 ++++++++++
> test/LuaJIT-tests/common/ffi_util.inc | 23 ---------------------
> 4 files changed, 24 insertions(+), 23 deletions(-)
> create mode 100644 test/LuaJIT-tests/common/fails.lua
> create mode 100644 test/LuaJIT-tests/common/ffi/checkfail.lua
> create mode 100644 test/LuaJIT-tests/common/ffi/checktypes.lua
>
> diff --git a/test/LuaJIT-tests/common/fails.lua b/test/LuaJIT-tests/common/fails.lua
> new file mode 100644
> index 00000000..d555a2b5
> --- /dev/null
> +++ b/test/LuaJIT-tests/common/fails.lua
> @@ -0,0 +1,3 @@
> +return function(f, ...)
> + if pcall(f, ...) ~= false then error("failure expected", 2) end
> +end
> diff --git a/test/LuaJIT-tests/common/ffi/checkfail.lua b/test/LuaJIT-tests/common/ffi/checkfail.lua
> new file mode 100644
> index 00000000..60d8449a
> --- /dev/null
> +++ b/test/LuaJIT-tests/common/ffi/checkfail.lua
> @@ -0,0 +1,10 @@
> +local ffi = require("ffi")
> +
please add a comment with function's description
> +return function(t, f)
> + f = f or ffi.typeof
> + for i=1,1e9 do
> + local tp = t[i]
> + if not tp then break end
> + assert(pcall(f, tp) == false, tp)
> + end
> +end
> diff --git a/test/LuaJIT-tests/common/ffi/checktypes.lua b/test/LuaJIT-tests/common/ffi/checktypes.lua
> new file mode 100644
> index 00000000..6d748e3b
> --- /dev/null
> +++ b/test/LuaJIT-tests/common/ffi/checktypes.lua
> @@ -0,0 +1,11 @@
> +local ffi = require("ffi")
> +
please add a comment with function's description
> +return function(t)
> + for i=1,1e9,3 do
> + local tp = t[i+2]
> + if not tp then break end
> + local id = ffi.typeof(tp)
> + assert(ffi.sizeof(id) == t[i], tp)
> + assert(ffi.alignof(id) == t[i+1], tp)
Why test function contains asserts()? Wouldn't be better to return
false/true and raise assert in test itself?
same questions below
> + end
> +end
> diff --git a/test/LuaJIT-tests/common/ffi_util.inc b/test/LuaJIT-tests/common/ffi_util.inc
> index 1eee8dd9..9604d7b0 100644
> --- a/test/LuaJIT-tests/common/ffi_util.inc
> +++ b/test/LuaJIT-tests/common/ffi_util.inc
> @@ -4,29 +4,6 @@
>
> local ffi = require("ffi")
>
> -function checkfail(t, f)
> - f = f or ffi.typeof
> - for i=1,1e9 do
> - local tp = t[i]
> - if not tp then break end
> - assert(pcall(f, tp) == false, tp)
> - end
> -end
> -
> -function checktypes(t)
> - for i=1,1e9,3 do
> - local tp = t[i+2]
> - if not tp then break end
> - local id = ffi.typeof(tp)
> - assert(ffi.sizeof(id) == t[i], tp)
> - assert(ffi.alignof(id) == t[i+1], tp)
> - end
> -end
> -
> -function fails(f, ...)
> - if pcall(f, ...) ~= false then error("failure expected", 2) end
> -end
> -
> local incroot = os.getenv("INCROOT") or "/usr/include"
> local cdefs = os.getenv("CDEFS") or ""
What for these env variables need?
>
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 02/25] test: separate LuaJIT helpers from ffi_util.inc
2024-01-23 9:17 ` Sergey Bronnikov via Tarantool-patches
@ 2024-01-23 12:35 ` Sergey Kaplun via Tarantool-patches
0 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-23 12:35 UTC (permalink / raw)
To: Sergey Bronnikov; +Cc: tarantool-patches
Hi, Sergey!
Thanks for the review!
Added the comments to the fucntions and force-pushed the branch.
See also my answers below.
On 23.01.24, Sergey Bronnikov wrote:
> Hi, Sergey!
>
> thanks for the patch!
>
> On 1/19/24 14:32, Sergey Kaplun wrote:
> > This patch moves common helpers from <LuaJIT-tests/common/ffi_util.inc>
> > into separate files by analogy with <common/expect_error.lua>. The
> Why do you need to move to separate files? What is an idea behind it?
I suppose that this is "common" helpers with a bit different
functionality.
As mentioned I tried to respect the existed code style of the suite
here (i.e., it is done by analogy with <common/expect_error.lua>).
All of these files return just a single function to use inside a test.
> > `include()` helper isn't touched since it is used in system dependend
> > tests, which won't be modified for now.
> >
> > Part of tarantool/tarantool#9398
> > ---
> > test/LuaJIT-tests/common/fails.lua | 3 +++
> > test/LuaJIT-tests/common/ffi/checkfail.lua | 10 +++++++++
> > test/LuaJIT-tests/common/ffi/checktypes.lua | 11 ++++++++++
> > test/LuaJIT-tests/common/ffi_util.inc | 23 ---------------------
> > 4 files changed, 24 insertions(+), 23 deletions(-)
> > create mode 100644 test/LuaJIT-tests/common/fails.lua
> > create mode 100644 test/LuaJIT-tests/common/ffi/checkfail.lua
> > create mode 100644 test/LuaJIT-tests/common/ffi/checktypes.lua
> >
> > diff --git a/test/LuaJIT-tests/common/fails.lua b/test/LuaJIT-tests/common/fails.lua
> > new file mode 100644
> > index 00000000..d555a2b5
> > --- /dev/null
> > +++ b/test/LuaJIT-tests/common/fails.lua
> > @@ -0,0 +1,3 @@
> > +return function(f, ...)
> > + if pcall(f, ...) ~= false then error("failure expected", 2) end
> > +end
> > diff --git a/test/LuaJIT-tests/common/ffi/checkfail.lua b/test/LuaJIT-tests/common/ffi/checkfail.lua
> > new file mode 100644
> > index 00000000..60d8449a
> > --- /dev/null
> > +++ b/test/LuaJIT-tests/common/ffi/checkfail.lua
> > @@ -0,0 +1,10 @@
> > +local ffi = require("ffi")
> > +
> please add a comment with function's description
Added the following comment:
===================================================================
diff --git a/test/LuaJIT-tests/common/ffi/checkfail.lua b/test/LuaJIT-tests/common/ffi/checkfail.lua
index 60d8449a..d3ca74e8 100644
--- a/test/LuaJIT-tests/common/ffi/checkfail.lua
+++ b/test/LuaJIT-tests/common/ffi/checkfail.lua
@@ -1,5 +1,9 @@
local ffi = require("ffi")
+-- Checker that takes an array of strings that should represent
+-- different invalid CTypes (a more common pattern). Also, the
+-- second argument may be also the `loadstring` function to check
+-- invalid literals or `ffi.cdef` to check invalid C definitions.
return function(t, f)
f = f or ffi.typeof
for i=1,1e9 do
===================================================================
> > +return function(t, f)
> > + f = f or ffi.typeof
> > + for i=1,1e9 do
> > + local tp = t[i]
> > + if not tp then break end
> > + assert(pcall(f, tp) == false, tp)
> > + end
> > +end
> > diff --git a/test/LuaJIT-tests/common/ffi/checktypes.lua b/test/LuaJIT-tests/common/ffi/checktypes.lua
> > new file mode 100644
> > index 00000000..6d748e3b
> > --- /dev/null
> > +++ b/test/LuaJIT-tests/common/ffi/checktypes.lua
> > @@ -0,0 +1,11 @@
> > +local ffi = require("ffi")
> > +
> please add a comment with function's description
===================================================================
diff --git a/test/LuaJIT-tests/common/ffi/checktypes.lua b/test/LuaJIT-tests/common/ffi/checktypes.lua
index 6d748e3b..c995d667 100644
--- a/test/LuaJIT-tests/common/ffi/checktypes.lua
+++ b/test/LuaJIT-tests/common/ffi/checktypes.lua
@@ -1,5 +1,9 @@
local ffi = require("ffi")
+-- Checker that takes an array with the following each 3 elements:
+-- 1) Sizeof for the given C type to be checked.
+-- 2) Alignof for the given C type to be checked.
+-- 3) String representing the C type.
return function(t)
for i=1,1e9,3 do
local tp = t[i+2]
===================================================================
> > +return function(t)
> > + for i=1,1e9,3 do
> > + local tp = t[i+2]
> > + if not tp then break end
> > + local id = ffi.typeof(tp)
> > + assert(ffi.sizeof(id) == t[i], tp)
> > + assert(ffi.alignof(id) == t[i+1], tp)
>
> Why test function contains asserts()? Wouldn't be better to return
> false/true and raise assert in test itself?
I have no perporse to refactor the whole suite. Also, I suppose there
are much more to do ;). `expect_error()` raises the error to, so see no
differences here.
>
> same questions below
>
> > + end
> > +end
> > diff --git a/test/LuaJIT-tests/common/ffi_util.inc b/test/LuaJIT-tests/common/ffi_util.inc
> > index 1eee8dd9..9604d7b0 100644
> > --- a/test/LuaJIT-tests/common/ffi_util.inc
> > +++ b/test/LuaJIT-tests/common/ffi_util.inc
> > @@ -4,29 +4,6 @@
> >
> > local ffi = require("ffi")
> >
> > -function checkfail(t, f)
> > - f = f or ffi.typeof
> > - for i=1,1e9 do
> > - local tp = t[i]
> > - if not tp then break end
> > - assert(pcall(f, tp) == false, tp)
> > - end
> > -end
> > -
> > -function checktypes(t)
> > - for i=1,1e9,3 do
> > - local tp = t[i+2]
> > - if not tp then break end
> > - local id = ffi.typeof(tp)
> > - assert(ffi.sizeof(id) == t[i], tp)
> > - assert(ffi.alignof(id) == t[i+1], tp)
> > - end
> > -end
> > -
> > -function fails(f, ...)
> > - if pcall(f, ...) ~= false then error("failure expected", 2) end
> > -end
> > -
> > local incroot = os.getenv("INCROOT") or "/usr/include"
> > local cdefs = os.getenv("CDEFS") or ""
> What for these env variables need?
They are unused for now, since the function `include()` below is not
used anywhere.
The first one should be used as a sysroot for finding C includes, and the
second one as an additional C defines.
> >
--
Best regards,
Sergey Kaplun
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 03/25] test: enable <ffi_arith_ptr.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 01/25] test: prepare lauxilarily libs for LuaJIT-tests Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 02/25] test: separate LuaJIT helpers from ffi_util.inc Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-23 9:21 ` Sergey Bronnikov via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 04/25] test: enable <ffi_bitfield.lua> " Sergey Kaplun via Tarantool-patches
` (22 subsequent siblings)
25 siblings, 1 reply; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch changes `dofile()` to the corresponding `require()` of the
helper function. It adds test names and includes the test in <index>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_arith_ptr.lua | 13 ++++++-------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_arith_ptr.lua b/test/LuaJIT-tests/lib/ffi/ffi_arith_ptr.lua
index 8cf890c6..f7fac0d8 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_arith_ptr.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_arith_ptr.lua
@@ -1,6 +1,5 @@
local ffi = require("ffi")
-
-dofile("../common/ffi_util.inc")
+local fails = require("common.fails")
ffi.cdef[[
typedef struct { int a,b,c; } foo1_t;
@@ -9,7 +8,7 @@ void *malloc(size_t);
struct incomplete;
]]
-do
+do --- base pointer arithmetic and comparisons
local a = ffi.new("int[10]")
local p1 = a+0
p1[0] = 1;
@@ -61,7 +60,7 @@ do
assert(b - a == 5)
end
-do
+do --- pointer comparisons for different types
local p1 = ffi.cast("void *", 0)
local p2 = ffi.cast("int *", 1)
assert(p1 == p1)
@@ -71,7 +70,7 @@ do
assert(p2 ~= nil)
end
-do
+do --- pointer comparisons for functions
local f1 = ffi.C.free
local f2 = ffi.C.malloc
local p1 = ffi.cast("void *", f1)
@@ -84,7 +83,7 @@ do
fails(function(f1) return f1 + 1 end, f1)
end
-do
+do --- pointer arithmetic for structures
local s = ffi.new("foo1_t[10]")
local p1 = s+3
p1.a = 1; p1.b = 2; p1.c = 3
@@ -96,7 +95,7 @@ do
assert(p1 - p2 == -3)
end
-do
+do --- pointer arithmetic for structure with unknown size
local mem = ffi.new("int[1]")
local p = ffi.cast("struct incomplete *", mem)
fails(function(p) return p+1 end, p)
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 59e36dd8..7e046908 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -2,6 +2,7 @@ bit64.lua +luajit>=2.1
cdata_var.lua
copy_fill.lua
err.lua
+ffi_arith_ptr.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 03/25] test: enable <ffi_arith_ptr.lua> in LuaJIT-tests
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 03/25] test: enable <ffi_arith_ptr.lua> in LuaJIT-tests Sergey Kaplun via Tarantool-patches
@ 2024-01-23 9:21 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 13:10 ` Sergey Kaplun via Tarantool-patches
0 siblings, 1 reply; 45+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2024-01-23 9:21 UTC (permalink / raw)
To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches
Hi, Sergey!
thanks for the patch.
On 1/19/24 14:32, Sergey Kaplun wrote:
> This patch changes `dofile()` to the corresponding `require()` of the
> helper function. It adds test names and includes the test in <index>.
What for do you need replace `dofile()` with `require()`?
I believe it is important to say not only *what* commit do but also
*why* it do these changes.
<snipped>
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 03/25] test: enable <ffi_arith_ptr.lua> in LuaJIT-tests
2024-01-23 9:21 ` Sergey Bronnikov via Tarantool-patches
@ 2024-01-23 13:10 ` Sergey Kaplun via Tarantool-patches
0 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-23 13:10 UTC (permalink / raw)
To: Sergey Bronnikov; +Cc: tarantool-patches
Hi, Sergey!
Thanks for the review!
On 23.01.24, Sergey Bronnikov wrote:
> Hi, Sergey!
>
> thanks for the patch.
>
> On 1/19/24 14:32, Sergey Kaplun wrote:
> > This patch changes `dofile()` to the corresponding `require()` of the
> > helper function. It adds test names and includes the test in <index>.
>
> What for do you need replace `dofile()` with `require()`?
>
> I believe it is important to say not only *what* commit do but also
> *why* it do these changes.
I added the following note to all commits mentioned this change:
| (which uses an unreliable relative file path and mutates `_G` with
| global functions to be defined)
Branch is force-pushed.
>
> <snipped>
--
Best regards,
Sergey Kaplun
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 04/25] test: enable <ffi_bitfield.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (2 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 03/25] test: enable <ffi_arith_ptr.lua> in LuaJIT-tests Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 05/25] test: enable <ffi_call.lua> " Sergey Kaplun via Tarantool-patches
` (21 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch removes unused `dofile()`. Also, it names the only one test
as "misc" and includes the test in <index>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_bitfield.lua | 4 +---
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_bitfield.lua b/test/LuaJIT-tests/lib/ffi/ffi_bitfield.lua
index cd0b1815..fa74e45d 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_bitfield.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_bitfield.lua
@@ -1,8 +1,6 @@
local ffi = require("ffi")
-dofile("../common/ffi_util.inc")
-
-do
+do --- misc
local x = ffi.new([[
union {
uint32_t u;
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 7e046908..8d833107 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -3,6 +3,7 @@ cdata_var.lua
copy_fill.lua
err.lua
ffi_arith_ptr.lua
+ffi_bitfield.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 05/25] test: enable <ffi_call.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (3 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 04/25] test: enable <ffi_bitfield.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-23 9:32 ` Sergey Bronnikov via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 06/25] test: enable <ffi_callback.lua> " Sergey Kaplun via Tarantool-patches
` (20 subsequent siblings)
25 siblings, 1 reply; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch removes unused `dofile()`. Also, it uses the basename of the
ctest library to be loaded via ffi. It adds groups with names of
subtests and enables the test in <index>. Complex type is undefined on
Windows, so the correponding tests are not enabled for this platform.
Fastcalls are enabled only for the x86 architecture. Stdcalls are
enabled only for Windows on x86. Tests with calls with 10 arguments with
sizes less than 8 bits are dummy for M1. This suite lacks a mechanism to
skip subtests satisfying complicated conditions, so it is done manually
by the corresponding `if` check.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_call.lua | 180 +++++++++++++------------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 92 insertions(+), 89 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_call.lua b/test/LuaJIT-tests/lib/ffi/ffi_call.lua
index 1eb5e906..c362f3e0 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_call.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_call.lua
@@ -1,8 +1,5 @@
-
local ffi = require("ffi")
-dofile("../common/ffi_util.inc")
-
local tonumber = tonumber
ffi.cdef[[
@@ -73,81 +70,87 @@ double __stdcall stdcall_dd(double a, double b);
float __stdcall stdcall_ff(float a, float b);
]]
-local C = ffi.load("../clib/ctest")
+local C = ffi.load("ctest")
-assert(C.call_i(-42) == -41)
-assert(C.call_ii(-42, 17) == -42+17)
-assert(C.call_10i(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) == -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
+do --- call int enum double float args
+ assert(C.call_i(-42) == -41)
+ assert(C.call_ii(-42, 17) == -42+17)
-assert(C.call_ie(123) == 124)
+ assert(C.call_ie(123) == 124)
-assert(tonumber(C.call_ji(0x123456789LL, -17)) == tonumber(0x123456789LL-17))
-assert(tonumber(C.call_ij(-17, 0x123456789LL)) == tonumber(0x123456789LL-17))
-assert(tonumber(C.call_jj(-42, 17)) == -42+17)
-assert(tonumber(C.call_jj(0x123456789abcdef0LL, -0x789abcde99887766LL)) == tonumber(0x123456789abcdef0LL-0x789abcde99887766LL))
+ assert(tonumber(C.call_ji(0x123456789LL, -17)) == tonumber(0x123456789LL-17))
+ assert(tonumber(C.call_ij(-17, 0x123456789LL)) == tonumber(0x123456789LL-17))
+ assert(tonumber(C.call_jj(-42, 17)) == -42+17)
+ assert(tonumber(C.call_jj(0x123456789abcdef0LL, -0x789abcde99887766LL)) == tonumber(0x123456789abcdef0LL-0x789abcde99887766LL))
-assert(C.call_dd(12.5, -3.25) == 12.5-3.25)
-assert(C.call_10d(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x12345678, 338, -78901234.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x12345678+338-78901234.75)
+ assert(C.call_dd(12.5, -3.25) == 12.5-3.25)
-assert(C.call_ff(12.5, -3.25) == 12.5-3.25)
-assert(C.call_10f(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x123456, 338, -789012.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x123456+338-789012.75)
+ assert(C.call_ff(12.5, -3.25) == 12.5-3.25)
-assert(C.call_idifjd(-42, 17.125, 0x12345, -100.625, 12345678901234, -789012.75) == -42+17.125+0x12345-100.625+12345678901234-789012.75)
+ assert(C.call_idifjd(-42, 17.125, 0x12345, -100.625, 12345678901234, -789012.75) == -42+17.125+0x12345-100.625+12345678901234-789012.75)
+end
+
+do --- call 10 args
+ if not (jit.os == "OSX" and jit.arch == "arm64") then -- NYI
+ assert(C.call_10i(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) == -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
+ assert(C.call_10f(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x123456, 338, -789012.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x123456+338-789012.75)
+ end
+ assert(C.call_10d(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x12345678, 338, -78901234.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x12345678+338-78901234.75)
+end
-do
+do --- call pointer arg
local a = ffi.new("int[10]", -42)
assert(C.call_p_i(a) == -42+1)
assert(tonumber(ffi.cast("intptr_t", C.call_p_p(a+3))) == tonumber(ffi.cast("intptr_t", a+4)))
assert(C.call_pp_i(a+8, a+5) == 3)
end
--- vararg
-assert(C.call_ividi(-42, ffi.new("int", 17), 12.5, ffi.new("int", 131)) == -42+17+12.5+131)
+do --- vararg
+ assert(C.call_ividi(-42, ffi.new("int", 17), 12.5, ffi.new("int", 131)) == -42+17+12.5+131)
+end
-- complex
-if pcall(function() return C.call_dd_cd end) then
- do
- local c = C.call_dd_cd(12.5, -3.25)
- assert(c.re == 12.5 and c.im == -3.25*2)
- end
- do
- local c1 = ffi.new("complex", 12.5, -3.25)
- local cz = C.call_cd(c1)
- assert(cz.re == 12.5+1 and cz.im == -3.25-2)
- end
- do
- local c1 = ffi.new("complex", 12.5, -3.25)
- local c2 = ffi.new("complex", -17.125, 100.625)
- local cz = C.call_cdcd(c1, c2)
- assert(cz.re == 12.5-17.125 and cz.im == -3.25+100.625)
- end
+do --- dd_cd -windows
+ local c = C.call_dd_cd(12.5, -3.25)
+ assert(c.re == 12.5 and c.im == -3.25*2)
+end
+do --- cd -windows
+ local c1 = ffi.new("complex", 12.5, -3.25)
+ local cz = C.call_cd(c1)
+ assert(cz.re == 12.5+1 and cz.im == -3.25-2)
+end
+do --- cdcd -windows
+ local c1 = ffi.new("complex", 12.5, -3.25)
+ local c2 = ffi.new("complex", -17.125, 100.625)
+ local cz = C.call_cdcd(c1, c2)
+ assert(cz.re == 12.5-17.125 and cz.im == -3.25+100.625)
+end
- do
- local c = C.call_ff_cf(12.5, -3.25)
- assert(c.re == 12.5 and c.im == -3.25*2)
- end
- do
- local c1 = ffi.new("complex float", 12.5, -3.25)
- local cz = C.call_cf(c1)
- assert(cz.re == 12.5+1 and cz.im == -3.25-2)
- end
- do
- local c1 = ffi.new("complex float", 12.5, -3.25)
- local c2 = ffi.new("complex float", -17.125, 100.625)
- local cz = C.call_cfcf(c1, c2)
- assert(cz.re == 12.5-17.125 and cz.im == -3.25+100.625)
- end
+do --- ff_cf -windows
+ local c = C.call_ff_cf(12.5, -3.25)
+ assert(c.re == 12.5 and c.im == -3.25*2)
+end
+do --- cf -windows
+ local c1 = ffi.new("complex float", 12.5, -3.25)
+ local cz = C.call_cf(c1)
+ assert(cz.re == 12.5+1 and cz.im == -3.25-2)
+end
+do --- cfcf -windows
+ local c1 = ffi.new("complex float", 12.5, -3.25)
+ local c2 = ffi.new("complex float", -17.125, 100.625)
+ local cz = C.call_cfcf(c1, c2)
+ assert(cz.re == 12.5-17.125 and cz.im == -3.25+100.625)
end
-- structs
-do
+do --- s_ii
local s1 = ffi.new("s_ii", -42, 17)
local sz = C.call_sii(s1)
assert(s1.x == -42 and s1.y == 17)
assert(sz.x == -42 and sz.y == 17)
end
-do
+do --- s_jj
local s1 = ffi.new("s_jj", 0x123456789abcdef0LL, -0x789abcde99887766LL)
local sz = C.call_sjj(s1)
assert(s1.x == 0x123456789abcdef0LL)
@@ -156,28 +159,28 @@ do
assert(sz.y == -0x789abcde99887766LL)
end
-do
+do --- s_ff
local s1 = ffi.new("s_ff", 12.5, -3.25)
local sz = C.call_sff(s1)
assert(s1.x == 12.5 and s1.y == -3.25)
assert(sz.x == 12.5 and sz.y == -3.25)
end
-do
+do --- s_dd
local s1 = ffi.new("s_dd", 12.5, -3.25)
local sz = C.call_sdd(s1)
assert(s1.x == 12.5 and s1.y == -3.25)
assert(sz.x == 12.5 and sz.y == -3.25)
end
-do
+do --- s_8i
local s1 = ffi.new("s_8i", -42, 17, 12345, 9987, -100, 11, 51, 0x12345678)
local sz = C.call_s8i(s1)
assert(s1.a+s1.b+s1.c+s1.d+s1.e+s1.f+s1.g+s1.h == -42+17+12345+9987-100+11+51+0x12345678)
assert(sz.a+sz.b+sz.c+sz.d+sz.e+sz.f+sz.g+sz.h == -42+17+12345+9987-100+11+51+0x12345678)
end
-do
+do --- s_ii s_ii
local s1 = ffi.new("s_ii", -42, 17)
local s2 = ffi.new("s_ii", 0x12345, -98765)
local sz = C.call_siisii(s1, s2)
@@ -186,7 +189,7 @@ do
assert(sz.x == -42+0x12345 and sz.y == 17-98765)
end
-do
+do --- s_ff s_ff
local s1 = ffi.new("s_ff", 12.5, -3.25)
local s2 = ffi.new("s_ff", -17.125, 100.625)
local sz = C.call_sffsff(s1, s2)
@@ -195,7 +198,7 @@ do
assert(sz.x == 12.5-17.125 and sz.y == -3.25+100.625)
end
-do
+do --- s_dd s_dd
local s1 = ffi.new("s_dd", 12.5, -3.25)
local s2 = ffi.new("s_dd", -17.125, 100.625)
local sz = C.call_sddsdd(s1, s2)
@@ -204,7 +207,7 @@ do
assert(sz.x == 12.5-17.125 and sz.y == -3.25+100.625)
end
-do
+do --- s_8i s_8i
local s1 = ffi.new("s_8i", -42, 17, 12345, 9987, -100, 11, 51, 0x12345678)
local s2 = ffi.new("s_8i", 99, 311, 98765, -51, 312, 97, 17, 0x44332211)
local sz = C.call_s8is8i(s1, s2)
@@ -215,7 +218,7 @@ do
assert(sz.h == 0x12345678+0x44332211)
end
-do
+do --- is8ii
local s1 = ffi.new("s_8i", -42, 17, 12345, 9987, -100, 11, 51, 0x12345678)
local sz = C.call_is8ii(19, s1, -51)
assert(s1.a+s1.b+s1.c+s1.d+s1.e+s1.f+s1.g+s1.h == -42+17+12345+9987-100+11+51+0x12345678)
@@ -225,42 +228,41 @@ do
end
-- target-specific
-if jit.arch == "x86" then
+do --- fastcall void int double +x86
assert(C.fastcall_void() == 1)
assert(C.fastcall_i(-42) == -41)
assert(C.fastcall_ii(-42, 17) == -42+17)
assert(C.fastcall_iii(-42, 17, 139) == -42+17+139)
assert(tonumber(C.fastcall_ji(0x123456789LL, -17)) == tonumber(0x123456789LL-17))
assert(C.fastcall_dd(12.5, -3.25) == 12.5-3.25)
+end
- do
- local a = ffi.new("int[10]", -42)
- assert(C.fastcall_pp_i(a+8, a+5) == 3)
- end
-
- do
- local s1 = ffi.new("s_ii", -42, 17)
- local s2 = ffi.new("s_ii", 0x12345, -98765)
- local sz = C.fastcall_siisii(s1, s2)
- assert(s1.x == -42 and s1.y == 17)
- assert(s2.x == 0x12345 and s2.y == -98765)
- assert(sz.x == -42+0x12345 and sz.y == 17-98765)
- end
+do --- fastcall pp_i +x86
+ local a = ffi.new("int[10]", -42)
+ assert(C.fastcall_pp_i(a+8, a+5) == 3)
+end
- do
- local s1 = ffi.new("s_dd", 12.5, -3.25)
- local s2 = ffi.new("s_dd", -17.125, 100.625)
- local sz = C.fastcall_sddsdd(s1, s2)
- assert(s1.x == 12.5 and s1.y == -3.25)
- assert(s2.x == -17.125 and s2.y == 100.625)
- assert(sz.x == 12.5-17.125 and sz.y == -3.25+100.625)
- end
+do --- fastcall s_ii s_ii +x86
+ local s1 = ffi.new("s_ii", -42, 17)
+ local s2 = ffi.new("s_ii", 0x12345, -98765)
+ local sz = C.fastcall_siisii(s1, s2)
+ assert(s1.x == -42 and s1.y == 17)
+ assert(s2.x == 0x12345 and s2.y == -98765)
+ assert(sz.x == -42+0x12345 and sz.y == 17-98765)
+end
- if jit.os == "Windows" then
- assert(C.stdcall_i(-42) == -41)
- assert(C.stdcall_ii(-42, 17) == -42+17)
- assert(C.stdcall_dd(12.5, -3.25) == 12.5-3.25)
- assert(C.stdcall_ff(12.5, -3.25) == 12.5-3.25)
- end
+do --- fastcall s_dd s_dd +x86
+ local s1 = ffi.new("s_dd", 12.5, -3.25)
+ local s2 = ffi.new("s_dd", -17.125, 100.625)
+ local sz = C.fastcall_sddsdd(s1, s2)
+ assert(s1.x == 12.5 and s1.y == -3.25)
+ assert(s2.x == -17.125 and s2.y == 100.625)
+ assert(sz.x == 12.5-17.125 and sz.y == -3.25+100.625)
end
+do --- stdcall +x86 +windows
+ assert(C.stdcall_i(-42) == -41)
+ assert(C.stdcall_ii(-42, 17) == -42+17)
+ assert(C.stdcall_dd(12.5, -3.25) == 12.5-3.25)
+ assert(C.stdcall_ff(12.5, -3.25) == 12.5-3.25)
+end
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 8d833107..599a0182 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -4,6 +4,7 @@ copy_fill.lua
err.lua
ffi_arith_ptr.lua
ffi_bitfield.lua
+ffi_call.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 05/25] test: enable <ffi_call.lua> in LuaJIT-tests
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 05/25] test: enable <ffi_call.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-23 9:32 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:46 ` Sergey Kaplun via Tarantool-patches
0 siblings, 1 reply; 45+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2024-01-23 9:32 UTC (permalink / raw)
To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches
Hi, Sergey!
thanks for the patch!
please take a look on my comments
Sergey
On 1/19/24 14:32, Sergey Kaplun wrote:
> This patch removes unused `dofile()`. Also, it uses the basename of the
> ctest library to be loaded via ffi. It adds groups with names of
> subtests and enables the test in <index>. Complex type is undefined on
> Windows, so the correponding tests are not enabled for this platform.
> Fastcalls are enabled only for the x86 architecture. Stdcalls are
> enabled only for Windows on x86. Tests with calls with 10 arguments with
> sizes less than 8 bits are dummy for M1. This suite lacks a mechanism to
> skip subtests satisfying complicated conditions, so it is done manually
> by the corresponding `if` check.
>
> Part of tarantool/tarantool#9398
> ---
> test/LuaJIT-tests/lib/ffi/ffi_call.lua | 180 +++++++++++++------------
> test/LuaJIT-tests/lib/ffi/index | 1 +
> 2 files changed, 92 insertions(+), 89 deletions(-)
>
> diff --git a/test/LuaJIT-tests/lib/ffi/ffi_call.lua b/test/LuaJIT-tests/lib/ffi/ffi_call.lua
> index 1eb5e906..c362f3e0 100644
> --- a/test/LuaJIT-tests/lib/ffi/ffi_call.lua
> +++ b/test/LuaJIT-tests/lib/ffi/ffi_call.lua
> @@ -1,8 +1,5 @@
> -
> local ffi = require("ffi")
>
> -dofile("../common/ffi_util.inc")
> -
> local tonumber = tonumber
>
> ffi.cdef[[
> @@ -73,81 +70,87 @@ double __stdcall stdcall_dd(double a, double b);
> float __stdcall stdcall_ff(float a, float b);
> ]]
>
> -local C = ffi.load("../clib/ctest")
> +local C = ffi.load("ctest")
>
> -assert(C.call_i(-42) == -41)
> -assert(C.call_ii(-42, 17) == -42+17)
> -assert(C.call_10i(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) == -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
> +do --- call int enum double float args
> + assert(C.call_i(-42) == -41)
> + assert(C.call_ii(-42, 17) == -42+17)
>
> -assert(C.call_ie(123) == 124)
> + assert(C.call_ie(123) == 124)
>
> -assert(tonumber(C.call_ji(0x123456789LL, -17)) == tonumber(0x123456789LL-17))
> -assert(tonumber(C.call_ij(-17, 0x123456789LL)) == tonumber(0x123456789LL-17))
> -assert(tonumber(C.call_jj(-42, 17)) == -42+17)
> -assert(tonumber(C.call_jj(0x123456789abcdef0LL, -0x789abcde99887766LL)) == tonumber(0x123456789abcdef0LL-0x789abcde99887766LL))
> + assert(tonumber(C.call_ji(0x123456789LL, -17)) == tonumber(0x123456789LL-17))
> + assert(tonumber(C.call_ij(-17, 0x123456789LL)) == tonumber(0x123456789LL-17))
> + assert(tonumber(C.call_jj(-42, 17)) == -42+17)
> + assert(tonumber(C.call_jj(0x123456789abcdef0LL, -0x789abcde99887766LL)) == tonumber(0x123456789abcdef0LL-0x789abcde99887766LL))
>
> -assert(C.call_dd(12.5, -3.25) == 12.5-3.25)
> -assert(C.call_10d(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x12345678, 338, -78901234.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x12345678+338-78901234.75)
> + assert(C.call_dd(12.5, -3.25) == 12.5-3.25)
>
> -assert(C.call_ff(12.5, -3.25) == 12.5-3.25)
> -assert(C.call_10f(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x123456, 338, -789012.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x123456+338-789012.75)
> + assert(C.call_ff(12.5, -3.25) == 12.5-3.25)
>
> -assert(C.call_idifjd(-42, 17.125, 0x12345, -100.625, 12345678901234, -789012.75) == -42+17.125+0x12345-100.625+12345678901234-789012.75)
> + assert(C.call_idifjd(-42, 17.125, 0x12345, -100.625, 12345678901234, -789012.75) == -42+17.125+0x12345-100.625+12345678901234-789012.75)
> +end
> +
> +do --- call 10 args
> + if not (jit.os == "OSX" and jit.arch == "arm64") then -- NYI
> + assert(C.call_10i(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) == -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
these tests totally unreadable.
I would rewrite such tests in the following manner:
local args = {-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338,
-78901234}
assert(C.call_10i(unpack(args)) == sum(args))
where `sum` is a function that sum elements in a passed table.
(Or even calculate RHS once and use it and doesn't depend on
calculations in runtime.)
Same comment for other similar tests.
> + assert(C.call_10f(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x123456, 338, -789012.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x123456+338-789012.75)
> + end
> + assert(C.call_10d(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x12345678, 338, -78901234.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x12345678+338-78901234.75)
> +end
>
> -do
> +do --- call pointer arg
> local a = ffi.new("int[10]", -42)
> assert(C.call_p_i(a) == -42+1)
> assert(tonumber(ffi.cast("intptr_t", C.call_p_p(a+3))) == tonumber(ffi.cast("intptr_t", a+4)))
> assert(C.call_pp_i(a+8, a+5) == 3)
> end
>
> --- vararg
> -assert(C.call_ividi(-42, ffi.new("int", 17), 12.5, ffi.new("int", 131)) == -42+17+12.5+131)
> +do --- vararg
> + assert(C.call_ividi(-42, ffi.new("int", 17), 12.5, ffi.new("int", 131)) == -42+17+12.5+131)
> +end
>
> -- complex
> -if pcall(function() return C.call_dd_cd end) then
> - do
> - local c = C.call_dd_cd(12.5, -3.25)
> - assert(c.re == 12.5 and c.im == -3.25*2)
> - end
> - do
> - local c1 = ffi.new("complex", 12.5, -3.25)
> - local cz = C.call_cd(c1)
> - assert(cz.re == 12.5+1 and cz.im == -3.25-2)
> - end
> - do
> - local c1 = ffi.new("complex", 12.5, -3.25)
> - local c2 = ffi.new("complex", -17.125, 100.625)
> - local cz = C.call_cdcd(c1, c2)
> - assert(cz.re == 12.5-17.125 and cz.im == -3.25+100.625)
> - end
> +do --- dd_cd -windows
> + local c = C.call_dd_cd(12.5, -3.25)
> + assert(c.re == 12.5 and c.im == -3.25*2)
> +end
> +do --- cd -windows
> + local c1 = ffi.new("complex", 12.5, -3.25)
> + local cz = C.call_cd(c1)
> + assert(cz.re == 12.5+1 and cz.im == -3.25-2)
> +end
> +do --- cdcd -windows
> + local c1 = ffi.new("complex", 12.5, -3.25)
> + local c2 = ffi.new("complex", -17.125, 100.625)
> + local cz = C.call_cdcd(c1, c2)
> + assert(cz.re == 12.5-17.125 and cz.im == -3.25+100.625)
> +end
>
> - do
> - local c = C.call_ff_cf(12.5, -3.25)
> - assert(c.re == 12.5 and c.im == -3.25*2)
> - end
> - do
> - local c1 = ffi.new("complex float", 12.5, -3.25)
> - local cz = C.call_cf(c1)
> - assert(cz.re == 12.5+1 and cz.im == -3.25-2)
> - end
> - do
> - local c1 = ffi.new("complex float", 12.5, -3.25)
> - local c2 = ffi.new("complex float", -17.125, 100.625)
> - local cz = C.call_cfcf(c1, c2)
> - assert(cz.re == 12.5-17.125 and cz.im == -3.25+100.625)
> - end
> +do --- ff_cf -windows
> + local c = C.call_ff_cf(12.5, -3.25)
> + assert(c.re == 12.5 and c.im == -3.25*2)
> +end
> +do --- cf -windows
> + local c1 = ffi.new("complex float", 12.5, -3.25)
> + local cz = C.call_cf(c1)
> + assert(cz.re == 12.5+1 and cz.im == -3.25-2)
> +end
> +do --- cfcf -windows
> + local c1 = ffi.new("complex float", 12.5, -3.25)
> + local c2 = ffi.new("complex float", -17.125, 100.625)
> + local cz = C.call_cfcf(c1, c2)
> + assert(cz.re == 12.5-17.125 and cz.im == -3.25+100.625)
> end
>
> -- structs
> -do
> +do --- s_ii
> local s1 = ffi.new("s_ii", -42, 17)
> local sz = C.call_sii(s1)
> assert(s1.x == -42 and s1.y == 17)
> assert(sz.x == -42 and sz.y == 17)
> end
>
> -do
> +do --- s_jj
> local s1 = ffi.new("s_jj", 0x123456789abcdef0LL, -0x789abcde99887766LL)
> local sz = C.call_sjj(s1)
> assert(s1.x == 0x123456789abcdef0LL)
> @@ -156,28 +159,28 @@ do
> assert(sz.y == -0x789abcde99887766LL)
> end
>
> -do
> +do --- s_ff
> local s1 = ffi.new("s_ff", 12.5, -3.25)
> local sz = C.call_sff(s1)
> assert(s1.x == 12.5 and s1.y == -3.25)
> assert(sz.x == 12.5 and sz.y == -3.25)
> end
>
> -do
> +do --- s_dd
> local s1 = ffi.new("s_dd", 12.5, -3.25)
> local sz = C.call_sdd(s1)
> assert(s1.x == 12.5 and s1.y == -3.25)
> assert(sz.x == 12.5 and sz.y == -3.25)
> end
>
> -do
> +do --- s_8i
> local s1 = ffi.new("s_8i", -42, 17, 12345, 9987, -100, 11, 51, 0x12345678)
> local sz = C.call_s8i(s1)
> assert(s1.a+s1.b+s1.c+s1.d+s1.e+s1.f+s1.g+s1.h == -42+17+12345+9987-100+11+51+0x12345678)
> assert(sz.a+sz.b+sz.c+sz.d+sz.e+sz.f+sz.g+sz.h == -42+17+12345+9987-100+11+51+0x12345678)
> end
>
> -do
> +do --- s_ii s_ii
> local s1 = ffi.new("s_ii", -42, 17)
> local s2 = ffi.new("s_ii", 0x12345, -98765)
> local sz = C.call_siisii(s1, s2)
> @@ -186,7 +189,7 @@ do
> assert(sz.x == -42+0x12345 and sz.y == 17-98765)
> end
>
> -do
> +do --- s_ff s_ff
> local s1 = ffi.new("s_ff", 12.5, -3.25)
> local s2 = ffi.new("s_ff", -17.125, 100.625)
> local sz = C.call_sffsff(s1, s2)
> @@ -195,7 +198,7 @@ do
> assert(sz.x == 12.5-17.125 and sz.y == -3.25+100.625)
> end
>
> -do
> +do --- s_dd s_dd
> local s1 = ffi.new("s_dd", 12.5, -3.25)
> local s2 = ffi.new("s_dd", -17.125, 100.625)
> local sz = C.call_sddsdd(s1, s2)
> @@ -204,7 +207,7 @@ do
> assert(sz.x == 12.5-17.125 and sz.y == -3.25+100.625)
> end
>
> -do
> +do --- s_8i s_8i
> local s1 = ffi.new("s_8i", -42, 17, 12345, 9987, -100, 11, 51, 0x12345678)
> local s2 = ffi.new("s_8i", 99, 311, 98765, -51, 312, 97, 17, 0x44332211)
> local sz = C.call_s8is8i(s1, s2)
> @@ -215,7 +218,7 @@ do
> assert(sz.h == 0x12345678+0x44332211)
> end
>
> -do
> +do --- is8ii
> local s1 = ffi.new("s_8i", -42, 17, 12345, 9987, -100, 11, 51, 0x12345678)
> local sz = C.call_is8ii(19, s1, -51)
> assert(s1.a+s1.b+s1.c+s1.d+s1.e+s1.f+s1.g+s1.h == -42+17+12345+9987-100+11+51+0x12345678)
> @@ -225,42 +228,41 @@ do
> end
>
> -- target-specific
> -if jit.arch == "x86" then
> +do --- fastcall void int double +x86
> assert(C.fastcall_void() == 1)
> assert(C.fastcall_i(-42) == -41)
> assert(C.fastcall_ii(-42, 17) == -42+17)
> assert(C.fastcall_iii(-42, 17, 139) == -42+17+139)
> assert(tonumber(C.fastcall_ji(0x123456789LL, -17)) == tonumber(0x123456789LL-17))
> assert(C.fastcall_dd(12.5, -3.25) == 12.5-3.25)
> +end
>
> - do
> - local a = ffi.new("int[10]", -42)
> - assert(C.fastcall_pp_i(a+8, a+5) == 3)
> - end
> -
> - do
> - local s1 = ffi.new("s_ii", -42, 17)
> - local s2 = ffi.new("s_ii", 0x12345, -98765)
> - local sz = C.fastcall_siisii(s1, s2)
> - assert(s1.x == -42 and s1.y == 17)
> - assert(s2.x == 0x12345 and s2.y == -98765)
> - assert(sz.x == -42+0x12345 and sz.y == 17-98765)
> - end
> +do --- fastcall pp_i +x86
> + local a = ffi.new("int[10]", -42)
> + assert(C.fastcall_pp_i(a+8, a+5) == 3)
> +end
>
> - do
> - local s1 = ffi.new("s_dd", 12.5, -3.25)
> - local s2 = ffi.new("s_dd", -17.125, 100.625)
> - local sz = C.fastcall_sddsdd(s1, s2)
> - assert(s1.x == 12.5 and s1.y == -3.25)
> - assert(s2.x == -17.125 and s2.y == 100.625)
> - assert(sz.x == 12.5-17.125 and sz.y == -3.25+100.625)
> - end
> +do --- fastcall s_ii s_ii +x86
> + local s1 = ffi.new("s_ii", -42, 17)
> + local s2 = ffi.new("s_ii", 0x12345, -98765)
> + local sz = C.fastcall_siisii(s1, s2)
> + assert(s1.x == -42 and s1.y == 17)
> + assert(s2.x == 0x12345 and s2.y == -98765)
> + assert(sz.x == -42+0x12345 and sz.y == 17-98765)
> +end
>
> - if jit.os == "Windows" then
> - assert(C.stdcall_i(-42) == -41)
> - assert(C.stdcall_ii(-42, 17) == -42+17)
> - assert(C.stdcall_dd(12.5, -3.25) == 12.5-3.25)
> - assert(C.stdcall_ff(12.5, -3.25) == 12.5-3.25)
> - end
> +do --- fastcall s_dd s_dd +x86
> + local s1 = ffi.new("s_dd", 12.5, -3.25)
> + local s2 = ffi.new("s_dd", -17.125, 100.625)
> + local sz = C.fastcall_sddsdd(s1, s2)
> + assert(s1.x == 12.5 and s1.y == -3.25)
> + assert(s2.x == -17.125 and s2.y == 100.625)
> + assert(sz.x == 12.5-17.125 and sz.y == -3.25+100.625)
> end
>
> +do --- stdcall +x86 +windows
> + assert(C.stdcall_i(-42) == -41)
> + assert(C.stdcall_ii(-42, 17) == -42+17)
> + assert(C.stdcall_dd(12.5, -3.25) == 12.5-3.25)
> + assert(C.stdcall_ff(12.5, -3.25) == 12.5-3.25)
> +end
> diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
> index 8d833107..599a0182 100644
> --- a/test/LuaJIT-tests/lib/ffi/index
> +++ b/test/LuaJIT-tests/lib/ffi/index
> @@ -4,6 +4,7 @@ copy_fill.lua
> err.lua
> ffi_arith_ptr.lua
> ffi_bitfield.lua
> +ffi_call.lua
> istype.lua
> jit_array.lua
> jit_complex.lua
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 05/25] test: enable <ffi_call.lua> in LuaJIT-tests
2024-01-23 9:32 ` Sergey Bronnikov via Tarantool-patches
@ 2024-01-23 12:46 ` Sergey Kaplun via Tarantool-patches
2024-01-24 11:05 ` Sergey Kaplun via Tarantool-patches
0 siblings, 1 reply; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-23 12:46 UTC (permalink / raw)
To: Sergey Bronnikov; +Cc: tarantool-patches
Hi, Sergey!
Thanks for the review!
Please consider my answers below.
On 23.01.24, Sergey Bronnikov wrote:
> Hi, Sergey!
>
> thanks for the patch!
>
> please take a look on my comments
>
>
> Sergey
>
> On 1/19/24 14:32, Sergey Kaplun wrote:
> > This patch removes unused `dofile()`. Also, it uses the basename of the
> > ctest library to be loaded via ffi. It adds groups with names of
> > subtests and enables the test in <index>. Complex type is undefined on
> > Windows, so the correponding tests are not enabled for this platform.
> > Fastcalls are enabled only for the x86 architecture. Stdcalls are
> > enabled only for Windows on x86. Tests with calls with 10 arguments with
> > sizes less than 8 bits are dummy for M1. This suite lacks a mechanism to
> > skip subtests satisfying complicated conditions, so it is done manually
> > by the corresponding `if` check.
> >
> > Part of tarantool/tarantool#9398
> > ---
> > test/LuaJIT-tests/lib/ffi/ffi_call.lua | 180 +++++++++++++------------
> > test/LuaJIT-tests/lib/ffi/index | 1 +
> > 2 files changed, 92 insertions(+), 89 deletions(-)
> >
> > diff --git a/test/LuaJIT-tests/lib/ffi/ffi_call.lua b/test/LuaJIT-tests/lib/ffi/ffi_call.lua
> > index 1eb5e906..c362f3e0 100644
> > --- a/test/LuaJIT-tests/lib/ffi/ffi_call.lua
> > +++ b/test/LuaJIT-tests/lib/ffi/ffi_call.lua
> > @@ -1,8 +1,5 @@
> > -
<snipped>
> > +
> > +do --- call 10 args
> > + if not (jit.os == "OSX" and jit.arch == "arm64") then -- NYI
> > + assert(C.call_10i(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) == -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
>
> these tests totally unreadable.
>
> I would rewrite such tests in the following manner:
>
> local args = {-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338,
> -78901234}
>
> assert(C.call_10i(unpack(args)) == sum(args))
>
> where `sum` is a function that sum elements in a passed table.
>
> (Or even calculate RHS once and use it and doesn't depend on
> calculations in runtime.)
>
> Same comment for other similar tests.
Obviously, there is room to improve this suite.
But as an agreement before: we don't change the semantics of this tests
(like you suggested by introducing the other function `sum()` that
may be compiled, for example).
Also, we don't refactor the whole test suite. It is not the point of
this patchset. This suite is just a good reference that Mike's (or ours)
patches don't breake some parts of the LuaJIT. In the future we may
reorganise these tests inside our own suite, for example. Now we have no
resources for this, unfortunately.
>
>
> > + assert(C.call_10f(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x123456, 338, -789012.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x123456+338-789012.75)
> > + end
> > + assert(C.call_10d(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x12345678, 338, -78901234.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x12345678+338-78901234.75)
> > +end
> >
> > -do
> > +do --- call pointer arg
<snipped>
--
Best regards,
Sergey Kaplun
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 05/25] test: enable <ffi_call.lua> in LuaJIT-tests
2024-01-23 12:46 ` Sergey Kaplun via Tarantool-patches
@ 2024-01-24 11:05 ` Sergey Kaplun via Tarantool-patches
0 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-24 11:05 UTC (permalink / raw)
To: Sergey Bronnikov, tarantool-patches
Hi, again!
On 23.01.24, Sergey Kaplun via Tarantool-patches wrote:
> Hi, Sergey!
> Thanks for the review!
>
> Please consider my answers below.
>
> On 23.01.24, Sergey Bronnikov wrote:
> > Hi, Sergey!
> >
> > thanks for the patch!
> >
> > please take a look on my comments
> >
> >
> > Sergey
> >
> > On 1/19/24 14:32, Sergey Kaplun wrote:
> > > This patch removes unused `dofile()`. Also, it uses the basename of the
> > > ctest library to be loaded via ffi. It adds groups with names of
> > > subtests and enables the test in <index>. Complex type is undefined on
> > > Windows, so the correponding tests are not enabled for this platform.
> > > Fastcalls are enabled only for the x86 architecture. Stdcalls are
> > > enabled only for Windows on x86. Tests with calls with 10 arguments with
> > > sizes less than 8 bits are dummy for M1. This suite lacks a mechanism to
> > > skip subtests satisfying complicated conditions, so it is done manually
> > > by the corresponding `if` check.
> > >
> > > Part of tarantool/tarantool#9398
> > > ---
> > > test/LuaJIT-tests/lib/ffi/ffi_call.lua | 180 +++++++++++++------------
> > > test/LuaJIT-tests/lib/ffi/index | 1 +
> > > 2 files changed, 92 insertions(+), 89 deletions(-)
> > >
> > > diff --git a/test/LuaJIT-tests/lib/ffi/ffi_call.lua b/test/LuaJIT-tests/lib/ffi/ffi_call.lua
> > > index 1eb5e906..c362f3e0 100644
> > > --- a/test/LuaJIT-tests/lib/ffi/ffi_call.lua
> > > +++ b/test/LuaJIT-tests/lib/ffi/ffi_call.lua
> > > @@ -1,8 +1,5 @@
> > > -
>
> <snipped>
>
> > > +
> > > +do --- call 10 args
> > > + if not (jit.os == "OSX" and jit.arch == "arm64") then -- NYI
> > > + assert(C.call_10i(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) == -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
> >
> > these tests totally unreadable.
> >
> > I would rewrite such tests in the following manner:
> >
> > local args = {-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338,
> > -78901234}
> >
> > assert(C.call_10i(unpack(args)) == sum(args))
> >
> > where `sum` is a function that sum elements in a passed table.
> >
> > (Or even calculate RHS once and use it and doesn't depend on
> > calculations in runtime.)
> >
> > Same comment for other similar tests.
>
> Obviously, there is room to improve this suite.
> But as an agreement before: we don't change the semantics of this tests
> (like you suggested by introducing the other function `sum()` that
> may be compiled, for example).
>
> Also, we don't refactor the whole test suite. It is not the point of
> this patchset. This suite is just a good reference that Mike's (or ours)
> patches don't breake some parts of the LuaJIT. In the future we may
> reorganise these tests inside our own suite, for example. Now we have no
> resources for this, unfortunately.
We discussed offline adding the additional padding to make the result
more readable. Like the following:
| call(-42.5, 17.125, ... ) ==
| -42.5 + 17.125 + ...
I'll fix this in the next patchset version.
>
>
> >
> >
> > > + assert(C.call_10f(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x123456, 338, -789012.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x123456+338-789012.75)
> > > + end
> > > + assert(C.call_10d(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x12345678, 338, -78901234.75) == -42.5+17.125+12345.5+9987-100.625+11+51+0x12345678+338-78901234.75)
> > > +end
> > >
> > > -do
> > > +do --- call pointer arg
>
> <snipped>
>
> --
> Best regards,
> Sergey Kaplun
--
Best regards,
Sergey Kaplun
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 06/25] test: enable <ffi_callback.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (4 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 05/25] test: enable <ffi_call.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-23 9:36 ` Sergey Bronnikov via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 07/25] test: enable <ffi_const.lua> " Sergey Kaplun via Tarantool-patches
` (19 subsequent siblings)
25 siblings, 1 reply; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch names all subtests and includes the test in <index>.
The test with calls with 10 arguments with sizes less than 8 bits are
dummy for M1. This suite lacks a mechanism to skip subtests satisfying
complicated conditions, so it is done manually by the corresponding `if`
check.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_callback.lua | 33 +++++++++++-----------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_callback.lua b/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
index 1fd14bd0..253bf1d9 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
@@ -6,7 +6,7 @@ void qsort(void *base, size_t nmemb, size_t size,
int (*compar)(const uint8_t *, const uint8_t *));
]]
-do
+do --- blacklisted callback
local cb = ffi.cast("int (*)(int, int, int)", function(a, b, c)
return a+b+c
end)
@@ -19,7 +19,7 @@ do
end
end
-do
+do --- cast to function
assert(ffi.cast("int64_t (*)(int64_t, int64_t, int64_t)", function(a, b, c)
return a+b+c
end)(12345678901234567LL, 70000000000000001LL, 10000000909090904LL) ==
@@ -37,11 +37,13 @@ do
return a+b+c
end)(7.125, -123.25, 9999.33) == 9883.205078125)
- assert(ffi.cast("int (*)(int, int, int, int, int, int, int, int, int, int)",
- function(a, b, c, d, e, f, g, h, i, j)
- return a+b+c+d+e+f+g+h+i+j
- end)(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) ==
- -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
+ if not (jit.os == "OSX" and jit.arch == "arm64") then -- NYI
+ assert(ffi.cast("int (*)(int, int, int, int, int, int, int, int, int, int)",
+ function(a, b, c, d, e, f, g, h, i, j)
+ return a+b+c+d+e+f+g+h+i+j
+ end)(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) ==
+ -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
+ end
assert(ffi.cast("double (*)(double, double, double, double, double, double, double, double, double, double)",
function(a, b, c, d, e, f, g, h, i, j)
@@ -51,7 +53,7 @@ do
end
-- Target-specific tests.
-if jit.arch == "x86" then
+do --- cast with fastcall attribute +x86
assert(ffi.cast("__fastcall int (*)(int, int, int)", function(a, b, c)
return a+b+c
end)(10, 99, 13) == 122)
@@ -67,8 +69,7 @@ if jit.arch == "x86" then
12345678901234567LL+12345+989797123)
end
--- Error handling.
-do
+do --- error handling
local function f()
return
end -- Error for result conversion triggered here.
@@ -84,7 +85,7 @@ do
assert(pcall(ffi.cast("int (*)(int,int,int,int, int,int,int,int, int)", function() error("test") end), 1,1,1,1, 1,1,1,1, 1) == false)
end
-do
+do --- qsort
local function cmp(pa, pb)
local a, b = pa[0], pb[0]
if a < b then
@@ -102,7 +103,7 @@ do
for i=0,254 do assert(arr[i] <= arr[i+1]) end
end
-if ffi.abi"win" then
+do --- EnumWindows +windows
ffi.cdef[[
typedef int (__stdcall *WNDENUMPROC)(void *hwnd, intptr_t l);
int EnumWindows(WNDENUMPROC func, intptr_t l);
@@ -123,7 +124,7 @@ if ffi.abi"win" then
assert(count > 10)
end
-do
+do --- cb.free cb.set
local cb = ffi.cast("int(*)(void)", function() return 1 end)
assert(cb() == 1)
cb:free()
@@ -136,7 +137,7 @@ do
assert(cb() == 3)
end
-do
+do --- compiled free of function
local ft = ffi.typeof("void(*)(void)")
local function f() end
local t = {}
@@ -146,11 +147,11 @@ do
end
end
-do
+do --- string.byte
assert(ffi.cast("int (*)()", function() return string.byte"A" end)() == 65)
end
-do
+do --- debug.traceback debug.sethook
local f = ffi.cast("void (*)(void)", function() debug.traceback() end)
debug.sethook(function() debug.sethook(nil, "", 0); f() end, "", 1)
local x
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 599a0182..9a22104a 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -5,6 +5,7 @@ err.lua
ffi_arith_ptr.lua
ffi_bitfield.lua
ffi_call.lua
+ffi_callback.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 06/25] test: enable <ffi_callback.lua> in LuaJIT-tests
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 06/25] test: enable <ffi_callback.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-23 9:36 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:01 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:58 ` Sergey Kaplun via Tarantool-patches
0 siblings, 2 replies; 45+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2024-01-23 9:36 UTC (permalink / raw)
To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches
[-- Attachment #1: Type: text/plain, Size: 4774 bytes --]
Hi, Sergey!
thanks for the patch!
see comments below
On 1/19/24 14:32, Sergey Kaplun wrote:
> This patch names all subtests and includes the test in <index>.
> The test with calls with 10 arguments with sizes less than 8 bits are
> dummy for M1. This suite lacks a mechanism to skip subtests satisfying
> complicated conditions, so it is done manually by the corresponding `if`
> check.
>
> Part of tarantool/tarantool#9398
> ---
> test/LuaJIT-tests/lib/ffi/ffi_callback.lua | 33 +++++++++++-----------
> test/LuaJIT-tests/lib/ffi/index | 1 +
> 2 files changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/test/LuaJIT-tests/lib/ffi/ffi_callback.lua b/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
> index 1fd14bd0..253bf1d9 100644
> --- a/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
> +++ b/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
> @@ -6,7 +6,7 @@ void qsort(void *base, size_t nmemb, size_t size,
> int (*compar)(const uint8_t *, const uint8_t *));
> ]]
>
> -do
> +do --- blacklisted callback
first letter should be uppercase and dot is missed in a comment, right?
here and below
> local cb = ffi.cast("int (*)(int, int, int)", function(a, b, c)
> return a+b+c
> end)
> @@ -19,7 +19,7 @@ do
> end
> end
>
> -do
> +do --- cast to function
> assert(ffi.cast("int64_t (*)(int64_t, int64_t, int64_t)", function(a, b, c)
> return a+b+c
> end)(12345678901234567LL, 70000000000000001LL, 10000000909090904LL) ==
> @@ -37,11 +37,13 @@ do
> return a+b+c
> end)(7.125, -123.25, 9999.33) == 9883.205078125)
>
> - assert(ffi.cast("int (*)(int, int, int, int, int, int, int, int, int, int)",
> - function(a, b, c, d, e, f, g, h, i, j)
> - return a+b+c+d+e+f+g+h+i+j
> - end)(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) ==
> - -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
> + if not (jit.os == "OSX" and jit.arch == "arm64") then -- NYI
> + assert(ffi.cast("int (*)(int, int, int, int, int, int, int, int, int, int)",
> + function(a, b, c, d, e, f, g, h, i, j)
> + return a+b+c+d+e+f+g+h+i+j
> + end)(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) ==
> + -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
My eyes are bleeding I can't read anymore...
Why you cannot add more whitespaces to expressions?
> + end
>
> assert(ffi.cast("double (*)(double, double, double, double, double, double, double, double, double, double)",
> function(a, b, c, d, e, f, g, h, i, j)
> @@ -51,7 +53,7 @@ do
> end
>
> -- Target-specific tests.
> -if jit.arch == "x86" then
> +do --- cast with fastcall attribute +x86
> assert(ffi.cast("__fastcall int (*)(int, int, int)", function(a, b, c)
> return a+b+c
> end)(10, 99, 13) == 122)
> @@ -67,8 +69,7 @@ if jit.arch == "x86" then
> 12345678901234567LL+12345+989797123)
> end
>
> --- Error handling.
> -do
> +do --- error handling
> local function f()
> return
> end -- Error for result conversion triggered here.
> @@ -84,7 +85,7 @@ do
> assert(pcall(ffi.cast("int (*)(int,int,int,int, int,int,int,int, int)", function() error("test") end), 1,1,1,1, 1,1,1,1, 1) == false)
> end
>
> -do
> +do --- qsort
> local function cmp(pa, pb)
> local a, b = pa[0], pb[0]
> if a < b then
> @@ -102,7 +103,7 @@ do
> for i=0,254 do assert(arr[i] <= arr[i+1]) end
> end
>
> -if ffi.abi"win" then
> +do --- EnumWindows +windows
> ffi.cdef[[
> typedef int (__stdcall *WNDENUMPROC)(void *hwnd, intptr_t l);
> int EnumWindows(WNDENUMPROC func, intptr_t l);
> @@ -123,7 +124,7 @@ if ffi.abi"win" then
> assert(count > 10)
> end
>
> -do
> +do --- cb.free cb.set
> local cb = ffi.cast("int(*)(void)", function() return 1 end) assert(cb() == 1) cb:free() @@ -136,7
> +137,7 @@ do assert(cb() == 3) end -do +do --- compiled free of
> function local ft = ffi.typeof("void(*)(void)")
> local function f() end
> local t = {}
> @@ -146,11 +147,11 @@ do
> end
> end
>
> -do
> +do --- string.byte
> assert(ffi.cast("int (*)()", function() return string.byte"A" end)() == 65)
> end
>
> -do
> +do --- debug.traceback debug.sethook
> local f = ffi.cast("void (*)(void)", function() debug.traceback() end)
> debug.sethook(function() debug.sethook(nil, "", 0); f() end, "", 1)
> local x
> diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
> index 599a0182..9a22104a 100644
> --- a/test/LuaJIT-tests/lib/ffi/index
> +++ b/test/LuaJIT-tests/lib/ffi/index
> @@ -5,6 +5,7 @@ err.lua
> ffi_arith_ptr.lua
> ffi_bitfield.lua
> ffi_call.lua
> +ffi_callback.lua
> istype.lua
> jit_array.lua
> jit_complex.lua
[-- Attachment #2: Type: text/html, Size: 5846 bytes --]
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 06/25] test: enable <ffi_callback.lua> in LuaJIT-tests
2024-01-23 9:36 ` Sergey Bronnikov via Tarantool-patches
@ 2024-01-23 12:01 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:58 ` Sergey Kaplun via Tarantool-patches
1 sibling, 0 replies; 45+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2024-01-23 12:01 UTC (permalink / raw)
To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches
[-- Attachment #1: Type: text/plain, Size: 703 bytes --]
Hello again,
On 1/23/24 12:36, Sergey Bronnikov via Tarantool-patches wrote:
<snipped>
>> diff --git a/test/LuaJIT-tests/lib/ffi/ffi_callback.lua b/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
>> index 1fd14bd0..253bf1d9 100644
>> --- a/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
>> +++ b/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
>> @@ -6,7 +6,7 @@ void qsort(void *base, size_t nmemb, size_t size,
>> int (*compar)(const uint8_t *, const uint8_t *));
>> ]]
>>
>> -do
>> +do --- blacklisted callback
>
> first letter should be uppercase and dot is missed in a comment, right?
>
> here and below
>
>
Please ignore.
(three dashes used before testcase name and used by test-runner)
<snipped>
[-- Attachment #2: Type: text/html, Size: 1550 bytes --]
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 06/25] test: enable <ffi_callback.lua> in LuaJIT-tests
2024-01-23 9:36 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:01 ` Sergey Bronnikov via Tarantool-patches
@ 2024-01-23 12:58 ` Sergey Kaplun via Tarantool-patches
1 sibling, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-23 12:58 UTC (permalink / raw)
To: Sergey Bronnikov; +Cc: tarantool-patches
Hi, Sergey!
Thanks for the review!
Please consider my answers below.
On 23.01.24, Sergey Bronnikov wrote:
> Hi, Sergey!
>
> thanks for the patch!
>
> see comments below
>
> On 1/19/24 14:32, Sergey Kaplun wrote:
> > This patch names all subtests and includes the test in <index>.
> > The test with calls with 10 arguments with sizes less than 8 bits are
> > dummy for M1. This suite lacks a mechanism to skip subtests satisfying
> > complicated conditions, so it is done manually by the corresponding `if`
> > check.
> >
> > Part of tarantool/tarantool#9398
> > ---
> > test/LuaJIT-tests/lib/ffi/ffi_callback.lua | 33 +++++++++++-----------
> > test/LuaJIT-tests/lib/ffi/index | 1 +
> > 2 files changed, 18 insertions(+), 16 deletions(-)
> >
> > diff --git a/test/LuaJIT-tests/lib/ffi/ffi_callback.lua b/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
> > index 1fd14bd0..253bf1d9 100644
> > --- a/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
> > +++ b/test/LuaJIT-tests/lib/ffi/ffi_callback.lua
> > @@ -6,7 +6,7 @@ void qsort(void *base, size_t nmemb, size_t size,
> > int (*compar)(const uint8_t *, const uint8_t *));
> > ]]
> >
> > -do
> > +do --- blacklisted callback
>
> first letter should be uppercase and dot is missed in a comment, right?
>
> here and below
As you mentioned, it is a test name, not a usual comment.
Also, there is no strict style for test names in this suite -- there are
with the uppercase first letter or lowcase, with a dot at the end of the
sentence, and without.
Welcome to the Wild West.
>
> > local cb = ffi.cast("int (*)(int, int, int)", function(a, b, c)
> > return a+b+c
> > end)
> > @@ -19,7 +19,7 @@ do
> > end
> > end
> >
> > -do
> > +do --- cast to function
> > assert(ffi.cast("int64_t (*)(int64_t, int64_t, int64_t)", function(a, b, c)
> > return a+b+c
> > end)(12345678901234567LL, 70000000000000001LL, 10000000909090904LL) ==
> > @@ -37,11 +37,13 @@ do
> > return a+b+c
> > end)(7.125, -123.25, 9999.33) == 9883.205078125)
> >
> > - assert(ffi.cast("int (*)(int, int, int, int, int, int, int, int, int, int)",
> > - function(a, b, c, d, e, f, g, h, i, j)
> > - return a+b+c+d+e+f+g+h+i+j
> > - end)(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) ==
> > - -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
> > + if not (jit.os == "OSX" and jit.arch == "arm64") then -- NYI
> > + assert(ffi.cast("int (*)(int, int, int, int, int, int, int, int, int, int)",
> > + function(a, b, c, d, e, f, g, h, i, j)
> > + return a+b+c+d+e+f+g+h+i+j
> > + end)(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234) ==
> > + -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
>
> My eyes are bleeding I can't read anymore...
>
> Why you cannot add more whitespaces to expressions?
Obviously, there is room to improve this suite.
Also, we don't refactor the whole test suite. It is not the point of
this patchset, only enable some tests.
This suite is just a good reference that Mike's (or ours) patches don't
breake some parts of the LuaJIT. In the future we may reorganise these
tests inside our own suite, for example. Now we have no resources for
this, unfortunately.
>
>
> > + end
<snipped>
--
Best regards,
Sergey Kaplun
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 07/25] test: enable <ffi_const.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (5 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 06/25] test: enable <ffi_callback.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-23 9:38 ` Sergey Bronnikov via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 08/25] test: enable <ffi_convert.lua> " Sergey Kaplun via Tarantool-patches
` (18 subsequent siblings)
25 siblings, 1 reply; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch changes the `dofile()` to the corresponding `require()`.
Also, it names the only one test as "misc" and includes the test in
<index>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_const.lua | 4 ++--
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_const.lua b/test/LuaJIT-tests/lib/ffi/ffi_const.lua
index d42133ad..3213156d 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_const.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_const.lua
@@ -1,6 +1,6 @@
local ffi = require("ffi")
-dofile("../common/ffi_util.inc")
+local fails = require("common.fails")
ffi.cdef[[
typedef struct s_t {
@@ -41,7 +41,7 @@ typedef struct foo_t {
} foo_t;
]]
-do
+do --- misc
local foo_t = ffi.typeof("foo_t")
local x = foo_t()
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 9a22104a..0a72daed 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -6,6 +6,7 @@ ffi_arith_ptr.lua
ffi_bitfield.lua
ffi_call.lua
ffi_callback.lua
+ffi_const.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 07/25] test: enable <ffi_const.lua> in LuaJIT-tests
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 07/25] test: enable <ffi_const.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-23 9:38 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 11:59 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:49 ` Sergey Kaplun via Tarantool-patches
0 siblings, 2 replies; 45+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2024-01-23 9:38 UTC (permalink / raw)
To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches
Hi, Sergey!
thanks for the patch!
see comment below
On 1/19/24 14:32, Sergey Kaplun wrote:
> This patch changes the `dofile()` to the corresponding `require()`.
> Also, it names the only one test as "misc" and includes the test in
> <index>.
>
> Part of tarantool/tarantool#9398
> ---
> test/LuaJIT-tests/lib/ffi/ffi_const.lua | 4 ++--
> test/LuaJIT-tests/lib/ffi/index | 1 +
> 2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/test/LuaJIT-tests/lib/ffi/ffi_const.lua b/test/LuaJIT-tests/lib/ffi/ffi_const.lua
> index d42133ad..3213156d 100644
> --- a/test/LuaJIT-tests/lib/ffi/ffi_const.lua
> +++ b/test/LuaJIT-tests/lib/ffi/ffi_const.lua
> @@ -1,6 +1,6 @@
> local ffi = require("ffi")
>
> -dofile("../common/ffi_util.inc")
> +local fails = require("common.fails")
>
> ffi.cdef[[
> typedef struct s_t {
> @@ -41,7 +41,7 @@ typedef struct foo_t {
> } foo_t;
> ]]
>
> -do
> +do --- misc
Why three dashes?
> local foo_t = ffi.typeof("foo_t")
> local x = foo_t()
>
> diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
> index 9a22104a..0a72daed 100644
> --- a/test/LuaJIT-tests/lib/ffi/index
> +++ b/test/LuaJIT-tests/lib/ffi/index
> @@ -6,6 +6,7 @@ ffi_arith_ptr.lua
> ffi_bitfield.lua
> ffi_call.lua
> ffi_callback.lua
> +ffi_const.lua
> istype.lua
> jit_array.lua
> jit_complex.lua
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 07/25] test: enable <ffi_const.lua> in LuaJIT-tests
2024-01-23 9:38 ` Sergey Bronnikov via Tarantool-patches
@ 2024-01-23 11:59 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:52 ` Sergey Kaplun via Tarantool-patches
2024-01-23 12:49 ` Sergey Kaplun via Tarantool-patches
1 sibling, 1 reply; 45+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2024-01-23 11:59 UTC (permalink / raw)
To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches
Hello again,
On 1/23/24 12:38, Sergey Bronnikov via Tarantool-patches wrote:
<snipped>
> diff --git a/test/LuaJIT-tests/lib/ffi/ffi_const.lua
> b/test/LuaJIT-tests/lib/ffi/ffi_const.lua
>> index d42133ad..3213156d 100644
>> --- a/test/LuaJIT-tests/lib/ffi/ffi_const.lua
>> +++ b/test/LuaJIT-tests/lib/ffi/ffi_const.lua
>> @@ -1,6 +1,6 @@
>> local ffi = require("ffi")
>> -dofile("../common/ffi_util.inc")
>> +local fails = require("common.fails")
>> ffi.cdef[[
>> typedef struct s_t {
>> @@ -41,7 +41,7 @@ typedef struct foo_t {
>> } foo_t;
>> ]]
>> -do
>> +do --- misc
> Why three dashes?
>>
please ignore
(three dashes used before testcase name and used by test-runner)
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 07/25] test: enable <ffi_const.lua> in LuaJIT-tests
2024-01-23 11:59 ` Sergey Bronnikov via Tarantool-patches
@ 2024-01-23 12:52 ` Sergey Kaplun via Tarantool-patches
0 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-23 12:52 UTC (permalink / raw)
To: Sergey Bronnikov; +Cc: tarantool-patches
Hi, Sergey!
Thanks for the review!
On 23.01.24, Sergey Bronnikov wrote:
> Hello again,
>
> On 1/23/24 12:38, Sergey Bronnikov via Tarantool-patches wrote:
>
> <snipped>
>
> > diff --git a/test/LuaJIT-tests/lib/ffi/ffi_const.lua
> > b/test/LuaJIT-tests/lib/ffi/ffi_const.lua
> >> index d42133ad..3213156d 100644
> >> --- a/test/LuaJIT-tests/lib/ffi/ffi_const.lua
> >> +++ b/test/LuaJIT-tests/lib/ffi/ffi_const.lua
> >> @@ -1,6 +1,6 @@
> >> local ffi = require("ffi")
> >> -dofile("../common/ffi_util.inc")
> >> +local fails = require("common.fails")
> >> ffi.cdef[[
> >> typedef struct s_t {
> >> @@ -41,7 +41,7 @@ typedef struct foo_t {
> >> } foo_t;
> >> ]]
> >> -do
> >> +do --- misc
> > Why three dashes?
> >>
> please ignore
>
> (three dashes used before testcase name and used by test-runner)
Yes, it's correct:).
>
--
Best regards,
Sergey Kaplun
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 07/25] test: enable <ffi_const.lua> in LuaJIT-tests
2024-01-23 9:38 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 11:59 ` Sergey Bronnikov via Tarantool-patches
@ 2024-01-23 12:49 ` Sergey Kaplun via Tarantool-patches
1 sibling, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-23 12:49 UTC (permalink / raw)
To: Sergey Bronnikov; +Cc: tarantool-patches
Hi, Sergey!
Thanks for the review!
Please consider my answers below.
On 23.01.24, Sergey Bronnikov wrote:
> Hi, Sergey!
>
> thanks for the patch!
>
> see comment below
>
> On 1/19/24 14:32, Sergey Kaplun wrote:
> > This patch changes the `dofile()` to the corresponding `require()`.
> > Also, it names the only one test as "misc" and includes the test in
> > <index>.
> >
> > Part of tarantool/tarantool#9398
> > ---
> > test/LuaJIT-tests/lib/ffi/ffi_const.lua | 4 ++--
> > test/LuaJIT-tests/lib/ffi/index | 1 +
> > 2 files changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/test/LuaJIT-tests/lib/ffi/ffi_const.lua b/test/LuaJIT-tests/lib/ffi/ffi_const.lua
> > index d42133ad..3213156d 100644
> > --- a/test/LuaJIT-tests/lib/ffi/ffi_const.lua
> > +++ b/test/LuaJIT-tests/lib/ffi/ffi_const.lua
> > @@ -1,6 +1,6 @@
> > local ffi = require("ffi")
> >
> > -dofile("../common/ffi_util.inc")
> > +local fails = require("common.fails")
> >
> > ffi.cdef[[
> > typedef struct s_t {
> > @@ -41,7 +41,7 @@ typedef struct foo_t {
> > } foo_t;
> > ]]
> >
> > -do
> > +do --- misc
> Why three dashes?
Three dashes are used before testcase name as a mark for test-runner.
> > local foo_t = ffi.typeof("foo_t")
> > local x = foo_t()
> >
> > diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
> > index 9a22104a..0a72daed 100644
> > --- a/test/LuaJIT-tests/lib/ffi/index
> > +++ b/test/LuaJIT-tests/lib/ffi/index
> > @@ -6,6 +6,7 @@ ffi_arith_ptr.lua
> > ffi_bitfield.lua
> > ffi_call.lua
> > ffi_callback.lua
> > +ffi_const.lua
> > istype.lua
> > jit_array.lua
> > jit_complex.lua
--
Best regards,
Sergey Kaplun
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 08/25] test: enable <ffi_convert.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (6 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 07/25] test: enable <ffi_const.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-23 9:39 ` Sergey Bronnikov via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 09/25] test: enable <ffi_enum.lua> " Sergey Kaplun via Tarantool-patches
` (17 subsequent siblings)
25 siblings, 1 reply; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch changes `dofile()` to the corresponding require and renames
the C library in the `require()` call. It adds groups with the names of
subtests and enables the test in <index>. It renames structure and enum
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_convert.lua | 35 +++++++++++------------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_convert.lua b/test/LuaJIT-tests/lib/ffi/ffi_convert.lua
index bd3fb1f9..284f2b53 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_convert.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_convert.lua
@@ -1,8 +1,7 @@
local ffi = require("ffi")
-local ctest = require("ctest")
-
-dofile("../common/ffi_util.inc")
+local ctest = require("libctest")
+local fails = require("common.fails")
local tonumber = tonumber
@@ -32,15 +31,15 @@ typedef struct arrinc_t {
int a[];
} arrinc_t;
-typedef enum uenum_t {
+typedef enum uenum_convert_t {
UE0, UE71 = 71, UE72
-} uenum_t;
+} uenum_convert_t;
-typedef enum ienum_t {
+typedef enum ienum_convert_t {
IE0, IEM12 = -12, IEM11
-} ienum_t;
+} ienum_convert_t;
-typedef struct foo_t {
+typedef struct foo_convert_t {
bool b;
int8_t i8;
uint8_t u8;
@@ -79,9 +78,9 @@ typedef struct foo_t {
int si_guard;
nest_t sn;
uni_t ui;
- uenum_t ue;
- ienum_t ie;
-} foo_t;
+ uenum_convert_t ue;
+ ienum_convert_t ie;
+} foo_convert_t;
char *strcpy(char *dest, const char *src);
typedef struct FILE FILE;
@@ -89,11 +88,11 @@ int fileno(FILE *stream);
int _fileno(FILE *stream);
]]
-do
- local foo_t = ffi.typeof("foo_t")
- local sz = ffi.sizeof(foo_t)
- local x = foo_t()
- local y = foo_t()
+do --- misc
+ local foo_convert_t = ffi.typeof("foo_convert_t")
+ local sz = ffi.sizeof(foo_convert_t)
+ local x = foo_convert_t()
+ local y = foo_convert_t()
ffi.fill(x, sz, 0xff)
ffi.fill(y, sz, 0xee)
@@ -769,7 +768,7 @@ do
x.ppf = ffi.C.strcpy
end
-do
+do --- GC cdata __index
collectgarbage()
local oc = collectgarbage("count")
local cd = ffi.new"struct { struct { int a; } x;}"
@@ -780,7 +779,7 @@ do
for i=1,2 do
f(cd)
local nc = collectgarbage("count")
- assert(nc < oc + 200, "GC step missing for cdata __index")
+ assert(nc < oc * 3, "GC step missing for cdata __index")
jit.off(f)
end
end
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 0a72daed..5c2be87f 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -7,6 +7,7 @@ ffi_bitfield.lua
ffi_call.lua
ffi_callback.lua
ffi_const.lua
+ffi_convert.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 08/25] test: enable <ffi_convert.lua> in LuaJIT-tests
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 08/25] test: enable <ffi_convert.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-23 9:39 ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:51 ` Sergey Kaplun via Tarantool-patches
0 siblings, 1 reply; 45+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2024-01-23 9:39 UTC (permalink / raw)
To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches
Hi, Sergey!
thanks for the patch!
see comments below
On 1/19/24 14:32, Sergey Kaplun wrote:
> This patch changes `dofile()` to the corresponding require and renames
> the C library in the `require()` call. It adds groups with the names of
> subtests and enables the test in <index>. It renames structure and enum
> 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_convert.lua | 35 +++++++++++------------
> test/LuaJIT-tests/lib/ffi/index | 1 +
> 2 files changed, 18 insertions(+), 18 deletions(-)
>
> diff --git a/test/LuaJIT-tests/lib/ffi/ffi_convert.lua b/test/LuaJIT-tests/lib/ffi/ffi_convert.lua
> index bd3fb1f9..284f2b53 100644
> --- a/test/LuaJIT-tests/lib/ffi/ffi_convert.lua
> +++ b/test/LuaJIT-tests/lib/ffi/ffi_convert.lua
> @@ -1,8 +1,7 @@
> local ffi = require("ffi")
>
> -local ctest = require("ctest")
> -
> -dofile("../common/ffi_util.inc")
> +local ctest = require("libctest")
> +local fails = require("common.fails")
>
> local tonumber = tonumber
>
> @@ -32,15 +31,15 @@ typedef struct arrinc_t {
> int a[];
> } arrinc_t;
>
> -typedef enum uenum_t {
> +typedef enum uenum_convert_t {
> UE0, UE71 = 71, UE72
> -} uenum_t;
> +} uenum_convert_t;
>
> -typedef enum ienum_t {
> +typedef enum ienum_convert_t {
> IE0, IEM12 = -12, IEM11
> -} ienum_t;
> +} ienum_convert_t;
>
> -typedef struct foo_t {
> +typedef struct foo_convert_t {
> bool b;
> int8_t i8;
> uint8_t u8;
> @@ -79,9 +78,9 @@ typedef struct foo_t {
> int si_guard;
> nest_t sn;
> uni_t ui;
> - uenum_t ue;
> - ienum_t ie;
> -} foo_t;
> + uenum_convert_t ue;
> + ienum_convert_t ie;
> +} foo_convert_t;
>
> char *strcpy(char *dest, const char *src);
> typedef struct FILE FILE;
> @@ -89,11 +88,11 @@ int fileno(FILE *stream);
> int _fileno(FILE *stream);
> ]]
>
> -do
> - local foo_t = ffi.typeof("foo_t")
> - local sz = ffi.sizeof(foo_t)
> - local x = foo_t()
> - local y = foo_t()
> +do --- misc
why three dashes?
> + local foo_convert_t = ffi.typeof("foo_convert_t")
> + local sz = ffi.sizeof(foo_convert_t)
> + local x = foo_convert_t()
> + local y = foo_convert_t()
> ffi.fill(x, sz, 0xff)
> ffi.fill(y, sz, 0xee)
>
> @@ -769,7 +768,7 @@ do
> x.ppf = ffi.C.strcpy
> end
>
> -do
> +do --- GC cdata __index
why three dashes?
> collectgarbage()
> local oc = collectgarbage("count")
> local cd = ffi.new"struct { struct { int a; } x;}"
> @@ -780,7 +779,7 @@ do
> for i=1,2 do
> f(cd)
> local nc = collectgarbage("count")
> - assert(nc < oc + 200, "GC step missing for cdata __index")
> + assert(nc < oc * 3, "GC step missing for cdata __index")
Hm, why?
> jit.off(f)
> end
> end
> diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
> index 0a72daed..5c2be87f 100644
> --- a/test/LuaJIT-tests/lib/ffi/index
> +++ b/test/LuaJIT-tests/lib/ffi/index
> @@ -7,6 +7,7 @@ ffi_bitfield.lua
> ffi_call.lua
> ffi_callback.lua
> ffi_const.lua
> +ffi_convert.lua
> istype.lua
> jit_array.lua
> jit_complex.lua
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 08/25] test: enable <ffi_convert.lua> in LuaJIT-tests
2024-01-23 9:39 ` Sergey Bronnikov via Tarantool-patches
@ 2024-01-23 12:51 ` Sergey Kaplun via Tarantool-patches
0 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-23 12:51 UTC (permalink / raw)
To: Sergey Bronnikov; +Cc: tarantool-patches
Hi, Sergey!
Thanks for the review!
Please consider my answers below.
On 23.01.24, Sergey Bronnikov wrote:
> Hi, Sergey!
>
> thanks for the patch!
>
> see comments below
>
> On 1/19/24 14:32, Sergey Kaplun wrote:
> > This patch changes `dofile()` to the corresponding require and renames
> > the C library in the `require()` call. It adds groups with the names of
> > subtests and enables the test in <index>. It renames structure and enum
> > 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_convert.lua | 35 +++++++++++------------
> > test/LuaJIT-tests/lib/ffi/index | 1 +
> > 2 files changed, 18 insertions(+), 18 deletions(-)
> >
> > diff --git a/test/LuaJIT-tests/lib/ffi/ffi_convert.lua b/test/LuaJIT-tests/lib/ffi/ffi_convert.lua
> > index bd3fb1f9..284f2b53 100644
> > --- a/test/LuaJIT-tests/lib/ffi/ffi_convert.lua
> > +++ b/test/LuaJIT-tests/lib/ffi/ffi_convert.lua
> > @@ -1,8 +1,7 @@
> > local ffi = require("ffi")
> >
> > -local ctest = require("ctest")
> > -
> > -dofile("../common/ffi_util.inc")
> > +local ctest = require("libctest")
> > +local fails = require("common.fails")
> >
> > local tonumber = tonumber
> >
> > @@ -32,15 +31,15 @@ typedef struct arrinc_t {
> > int a[];
> > } arrinc_t;
> >
> > -typedef enum uenum_t {
> > +typedef enum uenum_convert_t {
> > UE0, UE71 = 71, UE72
> > -} uenum_t;
> > +} uenum_convert_t;
> >
> > -typedef enum ienum_t {
> > +typedef enum ienum_convert_t {
> > IE0, IEM12 = -12, IEM11
> > -} ienum_t;
> > +} ienum_convert_t;
> >
> > -typedef struct foo_t {
> > +typedef struct foo_convert_t {
> > bool b;
> > int8_t i8;
> > uint8_t u8;
> > @@ -79,9 +78,9 @@ typedef struct foo_t {
> > int si_guard;
> > nest_t sn;
> > uni_t ui;
> > - uenum_t ue;
> > - ienum_t ie;
> > -} foo_t;
> > + uenum_convert_t ue;
> > + ienum_convert_t ie;
> > +} foo_convert_t;
> >
> > char *strcpy(char *dest, const char *src);
> > typedef struct FILE FILE;
> > @@ -89,11 +88,11 @@ int fileno(FILE *stream);
> > int _fileno(FILE *stream);
> > ]]
> >
> > -do
> > - local foo_t = ffi.typeof("foo_t")
> > - local sz = ffi.sizeof(foo_t)
> > - local x = foo_t()
> > - local y = foo_t()
> > +do --- misc
> why three dashes?
Three dashes are used before testcase name and parsed by test-runner.
> > + local foo_convert_t = ffi.typeof("foo_convert_t")
> > + local sz = ffi.sizeof(foo_convert_t)
> > + local x = foo_convert_t()
> > + local y = foo_convert_t()
> > ffi.fill(x, sz, 0xff)
> > ffi.fill(y, sz, 0xee)
> >
> > @@ -769,7 +768,7 @@ do
> > x.ppf = ffi.C.strcpy
> > end
> >
> > -do
> > +do --- GC cdata __index
> why three dashes?
Three dashes are used before testcase name and parsed by test-runner.
> > collectgarbage()
> > local oc = collectgarbage("count")
> > local cd = ffi.new"struct { struct { int a; } x;}"
> > @@ -780,7 +779,7 @@ do
> > for i=1,2 do
> > f(cd)
> > local nc = collectgarbage("count")
> > - assert(nc < oc + 200, "GC step missing for cdata __index")
> > + assert(nc < oc * 3, "GC step missing for cdata __index")
> Hm, why?
See the description in the commit message.
> > jit.off(f)
> > end
> > end
> > diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
> > index 0a72daed..5c2be87f 100644
> > --- a/test/LuaJIT-tests/lib/ffi/index
> > +++ b/test/LuaJIT-tests/lib/ffi/index
> > @@ -7,6 +7,7 @@ ffi_bitfield.lua
> > ffi_call.lua
> > ffi_callback.lua
> > ffi_const.lua
> > +ffi_convert.lua
> > istype.lua
> > jit_array.lua
> > jit_complex.lua
--
Best regards,
Sergey Kaplun
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 09/25] test: enable <ffi_enum.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (7 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 08/25] test: enable <ffi_convert.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 10/25] test: enable <ffi_gcstep_recursive.lua> Sergey Kaplun via Tarantool-patches
` (16 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch changes the `dofile()` to the corresponding `require()` call
and renames the C library in the `require()` call. Also, it names all
subtests and includes the test in <index>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_enum.lua | 11 +++++------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_enum.lua b/test/LuaJIT-tests/lib/ffi/ffi_enum.lua
index e8e40ad0..49c874c7 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_enum.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_enum.lua
@@ -1,7 +1,7 @@
local ffi = require("ffi")
-dofile("../common/ffi_util.inc")
+local fails = require("common.fails")
ffi.cdef[[
typedef enum enum_i { FOO_I = -1, II = 10 } enum_i;
@@ -13,10 +13,9 @@ int call_i_ei(enum_i a) asm("call_i");
int call_i_eu(enum_u a) asm("call_i");
]]
-local C = ffi.load("../clib/ctest")
-
-do
+local C = ffi.load("ctest")
+do --- base
local t = ffi.new("enum_i[100]")
for i=0,99 do t[i] = "II" end
for i=0,99 do assert(t[i] == "II") end
@@ -42,14 +41,14 @@ do
for i=0,99 do assert(t[i] ~= u[i]) end
end
-do
+do --- calls
for i=0,99 do assert(C.call_ei_i(9) == "II") end
for i=0,99 do assert(C.call_eu_i(9) == "UU") end
for i=0,99 do assert(C.call_i_ei("II") == 11) end
for i=0,99 do assert(C.call_i_eu("UU") == 11) end
end
-do
+do --- cast to bool
local f = ffi.cast("bool (*)(enum_i)", function(e) return e == "II" end)
assert(f("II"))
assert(not f(0))
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 5c2be87f..b11e5aa4 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -8,6 +8,7 @@ ffi_call.lua
ffi_callback.lua
ffi_const.lua
ffi_convert.lua
+ffi_enum.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 10/25] test: enable <ffi_gcstep_recursive.lua>
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (8 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 09/25] test: enable <ffi_enum.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 11/25] test: enable <ffi_jit_arith.lua> in LuaJIT-tests Sergey Kaplun via Tarantool-patches
` (15 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch declares functions as local to avoid pollution of the global
environment. It separates the body of the test in the `do` `while` block
and includes the test in <index>.
Part of tarantool/tarantool#9398
---
.../lib/ffi/ffi_gcstep_recursive.lua | 27 ++++++++++---------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_gcstep_recursive.lua b/test/LuaJIT-tests/lib/ffi/ffi_gcstep_recursive.lua
index cb19df11..f6e0b009 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_gcstep_recursive.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_gcstep_recursive.lua
@@ -1,6 +1,6 @@
-- From Robert G. Jakabosky, 2012-03-20
-local N=tonumber(arg[1] or 10000)
+local N= 10000
local ffi=require"ffi"
@@ -19,7 +19,7 @@ local function obj_to_id(ptr)
return tonumber(ffi.cast('uintptr_t', ffi.cast('void *', ptr)))
end
-function obj_type_Buffer_push(val)
+local function obj_type_Buffer_push(val)
local obj = Buffer(val)
local id = obj_to_id(obj)
nobj_obj_flags[id] = true
@@ -31,7 +31,7 @@ local function Buffer_new(len)
return obj_type_Buffer_push(buf)
end
-function obj_type_Buffer_delete(obj)
+local function obj_type_Buffer_delete(obj)
local id = obj_to_id(obj)
if not nobj_obj_flags[id] then return nil end
nobj_obj_flags[id] = nil
@@ -52,15 +52,16 @@ Buffer_mt.__index.close = Buffer_close
ffi.metatype(Buffer, Buffer_mt)
-local cdata = {}
-for x=1,2 do
- cdata = {}
- for i=1,N do
- cdata[i] = Buffer_new(1)
+do --- buffer test
+ local cdata = {}
+ for x=1,2 do
+ cdata = {}
+ for i=1,N do
+ cdata[i] = Buffer_new(1)
+ end
+ for i=1,N do
+ cdata[i]:close()
+ end
+ cdata = nil
end
- for i=1,N do
- cdata[i]:close()
- end
- cdata = nil
end
-
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index b11e5aa4..8236ab98 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -9,6 +9,7 @@ ffi_callback.lua
ffi_const.lua
ffi_convert.lua
ffi_enum.lua
+ffi_gcstep_recursive.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 11/25] test: enable <ffi_jit_arith.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (9 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 10/25] test: enable <ffi_gcstep_recursive.lua> Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 12/25] test: enable <ffi_jit_call.lua> " Sergey Kaplun via Tarantool-patches
` (14 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch names all subtests and includes the test in <index>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_jit_arith.lua | 22 ++++++++++-----------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_jit_arith.lua b/test/LuaJIT-tests/lib/ffi/ffi_jit_arith.lua
index 0554fe60..efe83cfd 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_jit_arith.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_jit_arith.lua
@@ -1,6 +1,6 @@
local ffi = require("ffi")
-do
+do --- int64_t arithmetic
local a = ffi.new("int64_t[?]", 101)
for i=1,100 do a[i] = -2 end
for i=1,100 do a[i] = i end
@@ -29,7 +29,7 @@ do
assert(w == 5050)
end
-do
+do --- uint64_t arithmetic
local a = ffi.new("uint64_t[?]", 101)
for i=1,100 do a[i] = i end
local x, y, m = 0ull, 0ull, 0ull
@@ -48,32 +48,32 @@ do
assert(z == 0x123456789abcdef0ull % 100)
end
-do
+do --- bit operations LL
local x = 0ll
for i=1,100 do x = x + (-2ll) ^ (bit.band(i, 15)+1ll) end
assert(x == 262120)
end
-do
+do --- bit operations LL, non-const base on trace
local x, a = 0ll, -2ll
for i=1,100 do x = x + a ^ (bit.band(i, 15)+1ll) end
assert(x == 262120)
end
-do
+do --- bit operations ULL
local x = 0ull
for i=1,100 do x = x + (-2ll) ^ (bit.band(i, 15)+1ull) end
assert(x == 262120)
end
-do
+do --- number vs. cdata interoperability
for i=1,200 do local j = bit.band(i, 7); assert((j == 0ll) == (j == 0)) end
for i=1,200 do assert((i < 100ll) == (i < 100)) end
for i=1,200 do assert((i <= 100ll) == (i <= 100)) end
for i=-100,100 do assert((i > 100ull) == (i < 0)) end
end
-do
+do --- comparisons checksum
local a = ffi.new("int64_t[?]", 100)
for i=0,99 do
a[i] = math.random(0, 2^32)*0x100000000LL + math.random(0, 2^32)
@@ -121,13 +121,13 @@ do
end
end
-do
+do --- pointer subtraction
local a, b = ffi.new("char *"), ffi.new("char *")
local z
for i=1,100 do z = a-b end
end
-do
+do --- char and 0LL base comparisons
local x = true
local abc = ffi.cast("const char *", "abc")
for i=1,100 do x = abc == "abc" end
@@ -142,8 +142,8 @@ do
assert(x == false)
end
--- ra_destpair
-do
+
+do --- ra_destpair
local x, y = 0, 0
for i=1,100 do
x = x + i/3LL
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 8236ab98..0c1e5e66 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -10,6 +10,7 @@ ffi_const.lua
ffi_convert.lua
ffi_enum.lua
ffi_gcstep_recursive.lua
+ffi_jit_arith.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 12/25] test: enable <ffi_jit_call.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (10 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 11/25] test: enable <ffi_jit_arith.lua> in LuaJIT-tests Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-24 14:43 ` Sergey Bronnikov via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 13/25] test: enable <ffi_jit_conv.lua> " Sergey Kaplun via Tarantool-patches
` (13 subsequent siblings)
25 siblings, 1 reply; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch uses the basename of the ctest library to be loaded via FFI.
It adds groups with the names of subtests and enables the test in
<index>. The corresponding conditions are changed to the tags checked by
analogy with other tests. Tests with calls with 10 arguments with sizes
less than 8 bits are dummy for M1. This suite lacks a mechanism to skip
subtests satisfying complicated conditions, so it is done manually by
the corresponding `if` check.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_jit_call.lua | 70 ++++++++++++----------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 39 insertions(+), 32 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_jit_call.lua b/test/LuaJIT-tests/lib/ffi/ffi_jit_call.lua
index b79d60b1..4e9a962d 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_jit_call.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_jit_call.lua
@@ -35,33 +35,37 @@ double __stdcall stdcall_dd(double a, double b);
float __stdcall stdcall_ff(float a, float b);
]]
-local lib = ffi.load("../clib/ctest")
-
-do
- local x
- for i=1,100 do
- x = lib.call_10i(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234)
+local lib = ffi.load("ctest")
+
+do --- call_10i
+ if not (jit.os == "OSX" and jit.arch == "arm64") then -- NYI
+ local x
+ for i=1,100 do
+ x = lib.call_10i(-42, 17, 12345, 9987, -100, 11, 51, 0x12345678, 338, -78901234)
+ end
+ assert(x == -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
end
- assert(x == -42+17+12345+9987-100+11+51+0x12345678+338-78901234)
end
-do
+do --- call_max
for i=1,100 do
pcall(lib.call_max, i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i)
end
end
-if ffi.abi("64bit") then
- local y = ffi.cast("void *", 0x123456789abcdefLL)
- local x
- for i=1,100 do
- lib.call_10j_p(0,0,0,0,0,0,0,0,0, y)
- x = lib.call_10j_p(0,0,0,0,0,0,0,0,0, nil)
+do --- call_10j_p +abi64
+ if not (jit.os == "OSX" and jit.arch == "arm64") then -- NYI
+ local y = ffi.cast("void *", 0x123456789abcdefLL)
+ local x
+ for i=1,100 do
+ lib.call_10j_p(0,0,0,0,0,0,0,0,0, y)
+ x = lib.call_10j_p(0,0,0,0,0,0,0,0,0, nil)
+ end
+ assert(x == 0)
end
- assert(x == 0)
end
-do
+do --- call_ij
local x = 0
for i=1,100 do
x = x + lib.call_ij(100+i, i*0x300000002LL)
@@ -69,7 +73,7 @@ do
assert(x == 0x3b2e0000623eLL)
end
-do
+do --- call_10d
local x
for i=1,100 do
x = lib.call_10d(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x12345678, 338, -78901234.75)
@@ -77,15 +81,17 @@ do
assert(x == -42.5+17.125+12345.5+9987-100.625+11+51+0x12345678+338-78901234.75)
end
-do
- local x
- for i=1,100 do
- x = lib.call_10f(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x123456, 338, -789012.75)
+do --- call_10f
+ if not (jit.os == "OSX" and jit.arch == "arm64") then -- NYI
+ local x
+ for i=1,100 do
+ x = lib.call_10f(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x123456, 338, -789012.75)
+ end
+ assert(x == -42.5+17.125+12345.5+9987-100.625+11+51+0x123456+338-789012.75)
end
- assert(x == -42.5+17.125+12345.5+9987-100.625+11+51+0x123456+338-789012.75)
end
-do
+do --- call_b
local x
for i=-100,100 do
if not lib.call_b(i) then x = i end
@@ -100,14 +106,14 @@ do
assert(x == 90)
end
-do
+do --- tail call_b
local function tail(x)
return lib.call_b(x)
end
for i=1,100 do local a,b,c = tail(1), tail(1), tail(1) end
end
-do
+do --- call i8[_i] u8[_i] i16[_i] u16[_i]
local x = 0
for i=0x01010080,0x010100ff do x = x + lib.call_i_i8(i) end
assert(x == -8128)
@@ -135,7 +141,7 @@ do
end
-- target-specific
-if jit.arch == "x86" then
+do --- fastcall +x86
for i=1,100 do assert(lib.fastcall_i(-42) == -41) end
for i=1,100 do assert(lib.fastcall_ii(-42, 17) == -42+17) end
for i=1,100 do assert(lib.fastcall_iii(-42, 17, 139) == -42+17+139) end
@@ -143,12 +149,12 @@ if jit.arch == "x86" then
for i=1,100 do assert(lib.fastcall_dd(12.5, -3.25) == 12.5-3.25) end
local x = lib.fastcall_ji
for i=1,100 do assert(x(0x123456789LL, -17) == 0x123456789LL-17) end
+end
- if jit.os == "Windows" then
- for i=1,100 do assert(lib.stdcall_i(-42) == -41) end
- for i=1,100 do assert(lib.stdcall_ii(-42, 17) == -42+17) end
- for i=1,100 do assert(lib.stdcall_dd(12.5, -3.25) == 12.5-3.25) end
- for i=1,100 do assert(lib.stdcall_ff(12.5, -3.25) == 12.5-3.25) end
- end
+do --- stdcall +x86 +windows
+ for i=1,100 do assert(lib.stdcall_i(-42) == -41) end
+ for i=1,100 do assert(lib.stdcall_ii(-42, 17) == -42+17) end
+ for i=1,100 do assert(lib.stdcall_dd(12.5, -3.25) == 12.5-3.25) end
+ for i=1,100 do assert(lib.stdcall_ff(12.5, -3.25) == 12.5-3.25) end
end
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 0c1e5e66..d6e2b64a 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -11,6 +11,7 @@ ffi_convert.lua
ffi_enum.lua
ffi_gcstep_recursive.lua
ffi_jit_arith.lua
+ffi_jit_call.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 12/25] test: enable <ffi_jit_call.lua> in LuaJIT-tests
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 12/25] test: enable <ffi_jit_call.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-24 14:43 ` Sergey Bronnikov via Tarantool-patches
0 siblings, 0 replies; 45+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2024-01-24 14:43 UTC (permalink / raw)
To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches
Hi, Sergey!
thanks for the patch
On 1/19/24 14:32, Sergey Kaplun wrote:
<snipped>
>
> -do
> +do --- call_ij
I would rename testcase. Using test function as a name is confusing.
Here and below and in other patches too.
> local x = 0
> for i=1,100 do
> x = x + lib.call_ij(100+i, i*0x300000002LL)
> @@ -69,7 +73,7 @@ do
> assert(x == 0x3b2e0000623eLL)
> end
>
> -do
> +do --- call_10d
> local x
> for i=1,100 do
> x = lib.call_10d(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x12345678, 338, -78901234.75)
> @@ -77,15 +81,17 @@ do
> assert(x == -42.5+17.125+12345.5+9987-100.625+11+51+0x12345678+338-78901234.75)
> end
>
> -do
> - local x
> - for i=1,100 do
> - x = lib.call_10f(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x123456, 338, -789012.75)
> +do --- call_10f
> + if not (jit.os == "OSX" and jit.arch == "arm64") then -- NYI
> + local x
> + for i=1,100 do
> + x = lib.call_10f(-42.5, 17.125, 12345.5, 9987, -100.625, 11, 51, 0x123456, 338, -789012.75)
> + end
> + assert(x == -42.5+17.125+12345.5+9987-100.625+11+51+0x123456+338-789012.75)
> end
> - assert(x == -42.5+17.125+12345.5+9987-100.625+11+51+0x123456+338-789012.75)
> end
>
> -do
> +do --- call_b
> local x
> for i=-100,100 do
> if not lib.call_b(i) then x = i end
> @@ -100,14 +106,14 @@ do
> assert(x == 90)
> end
>
> -do
> +do --- tail call_b
> local function tail(x)
> return lib.call_b(x)
> end
> for i=1,100 do local a,b,c = tail(1), tail(1), tail(1) end
> end
>
> -do
> +do --- call i8[_i] u8[_i] i16[_i] u16[_i]
> local x = 0
> for i=0x01010080,0x010100ff do x = x + lib.call_i_i8(i) end
> assert(x == -8128)
> @@ -135,7 +141,7 @@ do
> end
>
> -- target-specific
> -if jit.arch == "x86" then
> +do --- fastcall +x86
> for i=1,100 do assert(lib.fastcall_i(-42) == -41) end
> for i=1,100 do assert(lib.fastcall_ii(-42, 17) == -42+17) end
> for i=1,100 do assert(lib.fastcall_iii(-42, 17, 139) == -42+17+139) end
> @@ -143,12 +149,12 @@ if jit.arch == "x86" then
> for i=1,100 do assert(lib.fastcall_dd(12.5, -3.25) == 12.5-3.25) end
> local x = lib.fastcall_ji
> for i=1,100 do assert(x(0x123456789LL, -17) == 0x123456789LL-17) end
> +end
>
> - if jit.os == "Windows" then
> - for i=1,100 do assert(lib.stdcall_i(-42) == -41) end
> - for i=1,100 do assert(lib.stdcall_ii(-42, 17) == -42+17) end
> - for i=1,100 do assert(lib.stdcall_dd(12.5, -3.25) == 12.5-3.25) end
> - for i=1,100 do assert(lib.stdcall_ff(12.5, -3.25) == 12.5-3.25) end
> - end
> +do --- stdcall +x86 +windows
> + for i=1,100 do assert(lib.stdcall_i(-42) == -41) end
> + for i=1,100 do assert(lib.stdcall_ii(-42, 17) == -42+17) end
> + for i=1,100 do assert(lib.stdcall_dd(12.5, -3.25) == 12.5-3.25) end
> + for i=1,100 do assert(lib.stdcall_ff(12.5, -3.25) == 12.5-3.25) end
> end
>
> diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
> index 0c1e5e66..d6e2b64a 100644
> --- a/test/LuaJIT-tests/lib/ffi/index
> +++ b/test/LuaJIT-tests/lib/ffi/index
> @@ -11,6 +11,7 @@ ffi_convert.lua
> ffi_enum.lua
> ffi_gcstep_recursive.lua
> ffi_jit_arith.lua
> +ffi_jit_call.lua
> istype.lua
> jit_array.lua
> jit_complex.lua
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 13/25] test: enable <ffi_jit_conv.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (11 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 12/25] test: enable <ffi_jit_call.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 14/25] test: enable <ffi_lex_number.lua> " Sergey Kaplun via Tarantool-patches
` (12 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch renames the C library in the `require()` call. It adds
groups with the names of subtests and enables the test in <index>. It
renames enum definitions to avoid conflicts with cdef in other tests.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_jit_conv.lua | 70 +++++++++++-----------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 36 insertions(+), 35 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_jit_conv.lua b/test/LuaJIT-tests/lib/ffi/ffi_jit_conv.lua
index d4707db7..0e64fe75 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_jit_conv.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_jit_conv.lua
@@ -1,8 +1,8 @@
local ffi = require("ffi")
-local ctest = require("ctest")
+local ctest = require("libctest")
-do
+do --- int32_t, narrowed
local s = ffi.new("struct { int32_t x; }")
s.x = -0x12345678
for i=1,100 do
@@ -11,7 +11,7 @@ do
assert(s.x == -0x12345678+100)
end
-do
+do --- uint32_t, CONV num.u32 u32.num
local s = ffi.new("struct { uint32_t x; }")
s.x = 0x81234567
for i=1,100 do
@@ -20,7 +20,7 @@ do
assert(s.x == 0x81234567+100)
end
-do
+do --- int8_t, CONV.int.i8 forwarding
local s = ffi.new("struct { int8_t x; }")
s.x = 42
for i=1,100 do
@@ -30,7 +30,7 @@ do
assert(s.x == 142-256)
end
-do
+do --- uint8_t, CONV.int.u8 forwarding
local s = ffi.new("struct { uint8_t x; }")
s.x = 200
for i=1,100 do
@@ -40,7 +40,7 @@ do
assert(s.x == 300-256)
end
-do
+do --- int16_t, CONV.int.i16 forwarding
local s = ffi.new("struct { int16_t x; }")
s.x = 32700
for i=1,100 do
@@ -50,7 +50,7 @@ do
assert(s.x == 32800-65536)
end
-do
+do --- uint16_t, CONV.int.u16 forwarding
local s = ffi.new("struct { uint16_t x; }")
s.x = 65450
for i=1,100 do
@@ -60,7 +60,7 @@ do
assert(s.x == 65550-65536)
end
-do
+do --- union i32 u32, forwarding num.int num.u32
local s = ffi.new("union { int32_t x; uint32_t y; }")
s.x = 0x7fffffff - 60
local x,y = 0,0
@@ -75,7 +75,7 @@ do
assert(x == y - 40*2^32)
end
-do
+do --- union i32 u32, forwarding CONV.int.u32
local s = ffi.new("union { int32_t x; uint32_t y; }")
local x, z = 0, 2^31 + 42
for i=1,100 do
@@ -85,7 +85,7 @@ do
assert(x == 100*(-2^31 + 42))
end
-do
+do --- union i8 u8, forwarding CONV.int.i8 CONV.num.int
local s = ffi.new("union { int8_t x; uint8_t y; }")
s.x = 42
local x,y = 0,0
@@ -100,7 +100,7 @@ do
assert(x == y - (100-(127-42))*256)
end
-do
+do --- tobit + CONV.num.u32, 1
local a = ffi.new("uint32_t[?]", 101)
for i=1,100 do a[i] = 0x80000000+i end
local x = 0
@@ -110,7 +110,7 @@ do
assert(x == 100)
end
-do
+do --- tobit + CONV.num.u32, 2
local a = ffi.new("uint32_t[?]", 101)
for i=1,100 do a[i] = 0x80000000+i end
local x = 0
@@ -120,7 +120,7 @@ do
assert(x == -0x80000000+100)
end
-do
+do --- CONV.num.flt
local v = ffi.new("float", 12.5)
local x = 0
for i=1,100 do
@@ -129,7 +129,7 @@ do
assert(x == 100*12.5)
end
-do
+do --- CONV.num.u32
local v = ffi.new("uint32_t", 0x80000000)
local x = 0
for i=1,100 do
@@ -138,7 +138,7 @@ do
assert(x == 100*0x80000000)
end
-do
+do --- CONV.num.i64
local v = ffi.new("int64_t", 0x1234567800000000ll)
local x = 0
for i=1,100 do
@@ -147,7 +147,7 @@ do
assert(x == 100*0x12345678*2^32)
end
-do
+do --- CONV.num.u64
local v = ffi.new("uint64_t", 0x89abcdef00000000ull)
local x = 0
for i=1,100 do
@@ -156,7 +156,7 @@ do
assert(x == 100*0x89abcdef*2^32)
end
-do
+do --- CONV.num.i64, overflow
local a = ffi.new("int64_t[?]", 101)
for i=1,100 do a[i] = -i end
local x = 0
@@ -166,7 +166,7 @@ do
assert(x == -5050)
end
-do
+do --- CONV.num.u64, overflow
local a = ffi.new("uint64_t[?]", 101)
for i=1,100 do a[i] = 2^63+2^32*i end
local x = 0
@@ -176,7 +176,7 @@ do
assert(x == 2^63*100+2^32*5050)
end
-do
+do --- tonumber(complex)
local v = ffi.new("complex", 12.5, -3.25)
local x = 0
for i=1,100 do
@@ -185,7 +185,7 @@ do
assert(x == 100*12.5)
end
-do
+do --- const on trace i64
local s = ffi.new("struct { int64_t x;}")
for i=1,100 do
s.x = 0x123456789abcdef0LL
@@ -193,7 +193,7 @@ do
assert(tonumber(s.x) == tonumber(0x123456789abcdef0LL))
end
-do
+do --- const on trace u64
local s = ffi.new("struct { uint64_t x;}")
for i=1,100 do
s.x = 0x823456789abcdef0ULL
@@ -201,27 +201,27 @@ do
assert(tonumber(s.x) == tonumber(0x823456789abcdef0ULL))
end
-do
+do --- enum recording
ffi.cdef[[
- typedef enum { AA, BB, CC = -42 } foo_i;
- typedef enum { DD, EE, FF = 0x80000000u } foo_u;
+ typedef enum { AAA, BBB, CCC = -42 } foo_i;
+ typedef enum { DDD, EEE, FFF = 0x80000000u } foo_u;
]]
local s = ffi.new("struct { foo_i x; foo_u y;}")
for i=1,100 do
- s.x = "CC"
+ s.x = "CCC"
assert(s.x == -42)
- s.x = "BB"
+ s.x = "BBB"
assert(s.x == 1)
- s.y = "FF"
+ s.y = "FFF"
assert(s.y == 0x80000000)
end
local st = ffi.typeof(s)
for i=1,100 do s = st() end
assert(s.x == 0 and s.y == 0)
- for i=1,100 do s = st("CC", "EE") end
+ for i=1,100 do s = st("CCC", "EEE") end
assert(s.x == -42 and s.y == 1)
- local ei = ffi.new("foo_i", "CC")
- local eu = ffi.new("foo_u", "EE")
+ local ei = ffi.new("foo_i", "CCC")
+ local eu = ffi.new("foo_u", "EEE")
for i=1,100 do s = st(ei, eu) end
assert(s.x == -42 and s.y == 1)
local x
@@ -229,7 +229,7 @@ do
assert(x == -42)
end
-do
+do --- const char* recording
local s = ffi.new("struct { const char *x; const char *y;}")
local a, tmp = "abcd", "ab"
for i=1,100 do
@@ -240,7 +240,7 @@ do
assert(ffi.string(s.y) == "ab")
end
-do
+do --- bool int double recording
local s = ffi.new("struct { bool b[200]; int i[200]; double d[200];}")
for i=0,199 do s.i[i] = i-100; s.d[i] = i-100 end
for i=0,99 do s.b[i] = 0 end
@@ -253,13 +253,13 @@ do
for i=0,199 do assert(s.b[i] == (i ~= 100)) end
end
-do
+do --- int16_t array arithmetic
local a = ffi.new("int16_t[100]", 1)
for i=1,99 do a[i] = a[i] + a[i-1] end
assert(a[99] == 100)
end
-do
+do --- ligud to pointer
local ud = ctest.lightud(12345678)
local s = ffi.new("struct { void *p; }")
for i=1,100 do
@@ -269,7 +269,7 @@ do
assert(ffi.cast("uintptr_t", s.p) == 12345678)
end
-do
+do --- reference type initialization
local x = ffi.new("struct { int & x;}", ffi.new("int[1]", 42))
local z
for i=1,100 do z = x.x end
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index d6e2b64a..71def57b 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -12,6 +12,7 @@ ffi_enum.lua
ffi_gcstep_recursive.lua
ffi_jit_arith.lua
ffi_jit_call.lua
+ffi_jit_conv.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 14/25] test: enable <ffi_lex_number.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (12 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 13/25] test: enable <ffi_jit_conv.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 15/25] test: enable <ffi_metatype.lua> " Sergey Kaplun via Tarantool-patches
` (11 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch changes the `dofile()` to the corresponding `require()`.
Also, it adds groups with the names of subtests and enables the test in
<index>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_lex_number.lua | 72 +++++++++++---------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 39 insertions(+), 34 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_lex_number.lua b/test/LuaJIT-tests/lib/ffi/ffi_lex_number.lua
index e26650ef..ca6c65c5 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_lex_number.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_lex_number.lua
@@ -1,6 +1,6 @@
local ffi = require("ffi")
-dofile("../common/ffi_util.inc")
+local checkfail = require("common.ffi.checkfail")
local function checklex(t)
for i=1,1e9,2 do
@@ -14,38 +14,42 @@ local function checklex(t)
end
end
-checklex{
- "0LL", "0ll",
- "0LL", "0LL",
- "0ULL", "0ull",
- "0ULL", "0ULl",
- "18446744073709551615ULL", "18446744073709551615llu",
- "9223372036854775807LL", "0x7fffffffffffffffll",
- "9223372036854775808ULL", "0x8000000000000000ull",
- "1311768467463790320LL", "0x123456789abcdef0ll",
- "-1LL", "-1ll",
- "18446744073709551615ULL", "-1ull",
- "-9223372036854775807LL", "-0x7fffffffffffffffll",
- "9223372036854775808ULL", "-0x8000000000000000ull",
- "0+0i", "0i",
- "0+0i", "0I",
- "0+12.5i", "12.5i",
- "0+4660i", "0x1234i",
- "0+infI", "1e400i",
- "0-infI", "-1e400i",
- "0-12.5i", "-12.5i",
- "0-0i", "-0i",
-}
+do --- checklex
+ checklex{
+ "0LL", "0ll",
+ "0LL", "0LL",
+ "0ULL", "0ull",
+ "0ULL", "0ULl",
+ "18446744073709551615ULL", "18446744073709551615llu",
+ "9223372036854775807LL", "0x7fffffffffffffffll",
+ "9223372036854775808ULL", "0x8000000000000000ull",
+ "1311768467463790320LL", "0x123456789abcdef0ll",
+ "-1LL", "-1ll",
+ "18446744073709551615ULL", "-1ull",
+ "-9223372036854775807LL", "-0x7fffffffffffffffll",
+ "9223372036854775808ULL", "-0x8000000000000000ull",
+ "0+0i", "0i",
+ "0+0i", "0I",
+ "0+12.5i", "12.5i",
+ "0+4660i", "0x1234i",
+ "0+infI", "1e400i",
+ "0-infI", "-1e400i",
+ "0-12.5i", "-12.5i",
+ "0-0i", "-0i",
+ }
+end
-checkfail({
- "0l",
- "0lll",
- "0u",
- "0ul",
- "0ulll",
- "0wll",
- "0xll",
- ".0ll",
- "0ii",
-}, function(s) assert(loadstring("return "..s)) end)
+do --- checkfail
+ checkfail({
+ "0l",
+ "0lll",
+ "0u",
+ "0ul",
+ "0ulll",
+ "0wll",
+ "0xll",
+ ".0ll",
+ "0ii",
+ }, function(s) assert(loadstring("return "..s)) end)
+end
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 71def57b..833c31e3 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -13,6 +13,7 @@ ffi_gcstep_recursive.lua
ffi_jit_arith.lua
ffi_jit_call.lua
ffi_jit_conv.lua
+ffi_lex_number.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 15/25] test: enable <ffi_metatype.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (13 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 14/25] test: enable <ffi_lex_number.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 16/25] test: enable <ffi_new.lua> " Sergey Kaplun via Tarantool-patches
` (10 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch changes `dofile()` to the corresponding `require()` of the
helper function. It adds test names and includes the test in <index>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_metatype.lua | 16 ++++++++--------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_metatype.lua b/test/LuaJIT-tests/lib/ffi/ffi_metatype.lua
index 2db717f4..b0054b1a 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_metatype.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_metatype.lua
@@ -1,6 +1,6 @@
local ffi = require("ffi")
-dofile("../common/ffi_util.inc")
+local fails = require("common.fails")
ffi.cdef[[
typedef struct { int x; } idx1_t;
@@ -14,7 +14,7 @@ local function ptreq(a, b)
return ffi.cast("void *", a) == ffi.cast("void *", b)
end
-do
+do --- metatype index newindex
local nidx = {}
local tp = ffi.metatype("idx1_t", {
__index = { foo = 99, method = function(c, v) return v end },
@@ -45,7 +45,7 @@ do
fails(function(cp) cp.bar = 42 end, cp)
end
-do
+do --- metatype index newindex with upvalues
local uc, uk, uv
local tp = ffi.metatype("idx2_t", {
__index = function(c, k, x, y)
@@ -78,7 +78,7 @@ do
fails(function(p) p[0] = 11 end, p)
end
-do
+do --- metatype index newindex with upvalues via setmetatable
local uc, uk, uv
local ti, tn = {}, {}
local tp = ffi.metatype("idx3_t", {
@@ -103,7 +103,7 @@ do
uc, uk, uv = nil, nil, nil
end
-do
+do --- metatype arith
local tp
tp = ffi.metatype("arith_t", {
__add = function(a, b) return tp(a.x+b.x, a.y+b.y) end,
@@ -174,7 +174,7 @@ do
assert(x == 3000)
end
-do
+do --- metatype GC
local count = 0
local tp = ffi.metatype("gc_t", {
__gc = function(x) count = count + 1 end,
@@ -206,7 +206,7 @@ do
assert(count == 103)
end
-do
+do --- metatype new, type change
local tp = ffi.metatype([[
struct {
static const int Z42 = 42;
@@ -236,7 +236,7 @@ struct {
assert(o.x == 5)
end
-do
+do --- metatype is other cdata
local fb = ffi.new("struct { int x; }", 99)
local xt = ffi.metatype("struct { }", { __index = fb })
local o = xt()
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 833c31e3..338a6930 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -14,6 +14,7 @@ ffi_jit_arith.lua
ffi_jit_call.lua
ffi_jit_conv.lua
ffi_lex_number.lua
+ffi_metatype.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 16/25] test: enable <ffi_new.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (14 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 15/25] test: enable <ffi_metatype.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 17/25] test: enable <ffi_parse_array.lua> " Sergey Kaplun via Tarantool-patches
` (9 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch changes `dofile()` 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
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 17/25] test: enable <ffi_parse_array.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (15 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 16/25] test: enable <ffi_new.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 18/25] test: enable <ffi_parse_basic.lua> " Sergey Kaplun via Tarantool-patches
` (8 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch changes `dofile()` to the corresponding `require()` of the
helper functions. It adds groups with the names of subtests and enables
the test in <index>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_parse_array.lua | 106 ++++++++++--------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 58 insertions(+), 49 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_parse_array.lua b/test/LuaJIT-tests/lib/ffi/ffi_parse_array.lua
index 3a9616d7..d3b02759 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_parse_array.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_parse_array.lua
@@ -1,58 +1,66 @@
local ffi = require("ffi")
-dofile("../common/ffi_util.inc")
+local checkfail = require("common.ffi.checkfail")
+local checktypes = require("common.ffi.checktypes")
+local fails = require("common.fails")
-checkfail{
- "int [",
- "int [-1]",
- "int [[1]]",
- "int [10][]",
- "int [10][?]",
- "int [][]",
- "int [][?]",
- "int [?][]",
- "int [?][?]",
- "int [0x10000][0x2000]",
- "int [256][256][256][256]",
- "int [10](void)",
- "int (void)[10]",
- "int &[10]",
- "union { double x; int a[?]; }",
-}
+do --- checkfail
+ checkfail{
+ "int [",
+ "int [-1]",
+ "int [[1]]",
+ "int [10][]",
+ "int [10][?]",
+ "int [][]",
+ "int [][?]",
+ "int [?][]",
+ "int [?][?]",
+ "int [0x10000][0x2000]",
+ "int [256][256][256][256]",
+ "int [10](void)",
+ "int (void)[10]",
+ "int &[10]",
+ "union { double x; int a[?]; }",
+ }
+end
-ffi.cdef([[
- typedef int foo1_t[10];
- typedef foo1_t foo2_t[5];
-]])
-assert(ffi.sizeof("foo1_t") == 40)
-assert(ffi.sizeof("foo2_t") == 200)
+do --- sizeof of arrays
+ ffi.cdef([[
+ typedef int foo1_array_t[10];
+ typedef foo1_array_t foo2_array_t[5];
+ ]])
+ assert(ffi.sizeof("foo1_array_t") == 40)
+ assert(ffi.sizeof("foo2_array_t") == 200)
+end
-local P = ffi.sizeof("void *")
-checktypes{
- 10, 1, "char [10]",
- 4*10, 4, "int [10]",
- 4*10, 4, "int [10]",
- 4*10*5, 4, "int [10][5]",
- 4*10*5*3*2*7, 4, "int [10][5][3][2][7]",
- 4*10*5, 4, "int ([10])[5]",
- P*10, P, "int *[10]",
- P, P, "int (*)[10]",
- P*5, P, "int (*[5])[10]",
- 8*10, 4, "struct { int x; char y; } [10]",
- P*5*10, P, "volatile int *(* const *[5][10])(void)",
- nil, 4, "int []",
- 4*10, 8, "int __attribute__((aligned(8))) [10]",
- 4*10, 8, "__attribute__((aligned(8))) int [10]",
- 4*10, 8, "int [10] __attribute__((aligned(8)))",
- 97, 1, "char ['a']",
- 83, 1, "char ['\\123']",
- 79, 1, "char ['\x4F']",
- 5, 1, "char [sizeof(\"aa\" \"bb\")]",
- 80, 8, "double [10]",
-}
+do --- checktypes
+ local P = ffi.sizeof("void *")
+ checktypes{
+ 10, 1, "char [10]",
+ 4*10, 4, "int [10]",
+ 4*10, 4, "int [10]",
+ 4*10*5, 4, "int [10][5]",
+ 4*10*5*3*2*7, 4, "int [10][5][3][2][7]",
+ 4*10*5, 4, "int ([10])[5]",
+ P*10, P, "int *[10]",
+ P, P, "int (*)[10]",
+ P*5, P, "int (*[5])[10]",
+ 8*10, 4, "struct { int x; char y; } [10]",
+ P*5*10, P, "volatile int *(* const *[5][10])(void)",
+ nil, 4, "int []",
+ 4*10, 8, "int __attribute__((aligned(8))) [10]",
+ 4*10, 8, "__attribute__((aligned(8))) int [10]",
+ 4*10, 8, "int [10] __attribute__((aligned(8)))",
+ 97, 1, "char ['a']",
+ 83, 1, "char ['\\123']",
+ 79, 1, "char ['\x4F']",
+ 5, 1, "char [sizeof(\"aa\" \"bb\")]",
+ 80, 8, "double [10]",
+ }
+end
-do
+do --- sizeof VLA
assert(ffi.sizeof("int [?]", 10) == 4*10)
local id = ffi.typeof("const short [?]")
assert(ffi.sizeof(id, 10) == 2*10)
@@ -64,7 +72,7 @@ do
assert(ffi.sizeof(id, 0x3fffffff) == 2*0x3fffffff)
end
-do
+do --- sizeof VLS
assert(ffi.sizeof("struct { double x; int a[?]; }", 10) == 8+4*10)
local id = ffi.typeof("struct { int x; short a[?]; }")
assert(ffi.sizeof(id, 10) == 4+2*10)
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index e6c1fd0f..89773c0c 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -16,6 +16,7 @@ ffi_jit_conv.lua
ffi_lex_number.lua
ffi_metatype.lua
ffi_new.lua
+ffi_parse_array.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 18/25] test: enable <ffi_parse_basic.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (16 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 17/25] test: enable <ffi_parse_array.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 19/25] test: enable <ffi_parse_cdef.lua> " Sergey Kaplun via Tarantool-patches
` (7 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch changes `dofile()` to the corresponding `require()` of the
helper functions. It adds groups with the names of subtests and enables
the test in <index>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_parse_basic.lua | 251 +++++++++---------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 132 insertions(+), 120 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_parse_basic.lua b/test/LuaJIT-tests/lib/ffi/ffi_parse_basic.lua
index c054bcfb..3b49648c 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_parse_basic.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_parse_basic.lua
@@ -1,131 +1,142 @@
local ffi = require("ffi")
-dofile("../common/ffi_util.inc")
+local checkfail = require("common.ffi.checkfail")
+local checktypes = require("common.ffi.checktypes")
-checkfail{
- "",
- " ",
- "\n",
- "1",
- ".",
- ";",
- ",",
- "*",
- "[]",
- "()",
- "(*)",
- "//",
- "/*",
- "xyz",
- "const",
- "volatile",
- "typedef",
- "extern",
- "static",
- "auto",
- "register",
- "struct",
- "union",
- "sizeof",
- "int int",
- "int char",
- "int double",
- "int;",
-}
+do --- checkfail
+ checkfail{
+ "",
+ " ",
+ "\n",
+ "1",
+ ".",
+ ";",
+ ",",
+ "*",
+ "[]",
+ "()",
+ "(*)",
+ "//",
+ "/*",
+ "xyz",
+ "const",
+ "volatile",
+ "typedef",
+ "extern",
+ "static",
+ "auto",
+ "register",
+ "struct",
+ "union",
+ "sizeof",
+ "int int",
+ "int char",
+ "int double",
+ "int;",
+ }
+end
-checktypes{
- 1, 1, "char",
- 1, 1, " \n\r\t\vchar \n\r\t\v",
- 1, 1, "ch\\\nar",
- 1, 1, "char /* abc */",
- 1, 1, "char /* abc */ const",
- 1, 1, "char // abc\n const",
-}
+do --- char newlines
+ checktypes{
+ 1, 1, "char",
+ 1, 1, " \n\r\t\vchar \n\r\t\v",
+ 1, 1, "ch\\\nar",
+ 1, 1, "char /* abc */",
+ 1, 1, "char /* abc */ const",
+ 1, 1, "char // abc\n const",
+ }
+end
-checktypes{
- nil, 1, "void",
- 1, 1, "bool",
- 1, 1, "_Bool",
- 4, 4, "_Bool int",
- 1, 1, "char",
- 1, 1, "signed char",
- 1, 1, "unsigned char",
- 2, 2, "short",
- 2, 2, "signed short",
- 2, 2, "unsigned short",
- 4, 4, "int",
- 4, 4, "signed int",
- 4, 4, "unsigned int",
- 4, 4, "signed",
- 4, 4, "unsigned",
- 4, 4, "float",
- 8, 8, "long long",
- 8, 8, "signed long long",
- 8, 8, "unsigned long long",
- 8, 8, "double",
- -- NYI: long double is architecture- and compiler-specific.
- 8, 4, "_Complex float",
- 16, 8, "_Complex",
- 16, 8, "_Complex double",
-}
+do --- base types
+ checktypes{
+ nil, 1, "void",
+ 1, 1, "bool",
+ 1, 1, "_Bool",
+ 4, 4, "_Bool int",
+ 1, 1, "char",
+ 1, 1, "signed char",
+ 1, 1, "unsigned char",
+ 2, 2, "short",
+ 2, 2, "signed short",
+ 2, 2, "unsigned short",
+ 4, 4, "int",
+ 4, 4, "signed int",
+ 4, 4, "unsigned int",
+ 4, 4, "signed",
+ 4, 4, "unsigned",
+ 4, 4, "float",
+ 8, 8, "long long",
+ 8, 8, "signed long long",
+ 8, 8, "unsigned long long",
+ 8, 8, "double",
+ -- NYI: long double is architecture- and compiler-specific.
+ 8, 4, "_Complex float",
+ 16, 8, "_Complex",
+ 16, 8, "_Complex double",
+ }
+end
--- mode/vector_size attributes
-checktypes{
- 1, 1, "int __attribute__((mode(QI)))",
- 2, 2, "int __attribute__((mode(HI)))",
- 4, 4, "int __attribute__((mode(SI)))",
- 8, 8, "int __attribute__((mode(DI)))",
- 16, 16, "int __attribute__((mode(TI)))",
- 32, 16, "int __attribute__((mode(OI)))",
- 4, 4, "float __attribute__((mode(SF)))",
- 8, 8, "float __attribute__((mode(DF)))",
- 2, 2, "int __attribute__((mode(V2QI)))",
- 16, 16, "float __attribute__((mode(V4SF)))",
- 32, 16, "double __attribute__((mode(V8SF)))",
- 8, 8, "char __attribute__((vector_size(8)))",
- 16, 16, "int __attribute__((vector_size(16)))",
- 32, 16, "double __attribute__((vector_size(32)))",
- 64, 16, "double __attribute__((vector_size(64)))",
-}
+do --- mode/vector_size attributes
+ checktypes{
+ 1, 1, "int __attribute__((mode(QI)))",
+ 2, 2, "int __attribute__((mode(HI)))",
+ 4, 4, "int __attribute__((mode(SI)))",
+ 8, 8, "int __attribute__((mode(DI)))",
+ 16, 16, "int __attribute__((mode(TI)))",
+ 32, 16, "int __attribute__((mode(OI)))",
+ 4, 4, "float __attribute__((mode(SF)))",
+ 8, 8, "float __attribute__((mode(DF)))",
+ 2, 2, "int __attribute__((mode(V2QI)))",
+ 16, 16, "float __attribute__((mode(V4SF)))",
+ 32, 16, "double __attribute__((mode(V8SF)))",
+ 8, 8, "char __attribute__((vector_size(8)))",
+ 16, 16, "int __attribute__((vector_size(16)))",
+ 32, 16, "double __attribute__((vector_size(32)))",
+ 64, 16, "double __attribute__((vector_size(64)))",
+ }
+end
--- ABI-specific types:
-local L = (ffi.abi("32bit") or ffi.abi("win")) and 4 or 8
-local P = ffi.abi("32bit") and 4 or 8
-local W = ffi.abi("win") and 2 or 4
+do --- ABI-specific types:
+ local L = (ffi.abi("32bit") or ffi.abi("win")) and 4 or 8
+ local P = ffi.abi("32bit") and 4 or 8
+ local W = ffi.abi("win") and 2 or 4
-checktypes{
- L, L, "long",
- L, L, "signed long",
- L, L, "unsigned long",
- P, P, "int *",
- P, P, "int **",
- 4, 4, "int * __ptr32",
-}
+ checktypes{
+ L, L, "long",
+ L, L, "signed long",
+ L, L, "unsigned long",
+ P, P, "int *",
+ P, P, "int **",
+ 4, 4, "int * __ptr32",
+ }
-checktypes{
- P, P, "ptrdiff_t",
- P, P, "size_t",
- W, W, "wchar_t",
- 1, 1, "int8_t",
- 2, 2, "int16_t",
- 4, 4, "int32_t",
- 8, 8, "int64_t",
- 1, 1, "uint8_t",
- 2, 2, "uint16_t",
- 4, 4, "uint32_t",
- 8, 8, "uint64_t",
- P, P, "intptr_t",
- P, P, "uintptr_t",
-}
+ checktypes{
+ P, P, "ptrdiff_t",
+ P, P, "size_t",
+ W, W, "wchar_t",
+ 1, 1, "int8_t",
+ 2, 2, "int16_t",
+ 4, 4, "int32_t",
+ 8, 8, "int64_t",
+ 1, 1, "uint8_t",
+ 2, 2, "uint16_t",
+ 4, 4, "uint32_t",
+ 8, 8, "uint64_t",
+ P, P, "intptr_t",
+ P, P, "uintptr_t",
+ }
+end
-checktypes{
- 1, 8, "char __attribute__((aligned(8)))",
- 1, 8, "char __attribute((aligned(8)))",
- 1, 8, "char __attribute__((__aligned__(8)))",
- 1, 8, "__attribute__((aligned(8))) char",
- 1, 8, "char __declspec(align(8))",
- 1, 8, "__declspec(align(8)) char",
- 1, 2, "char __attribute__((aligned(8))) const __attribute__((aligned(2)))",
- 1, 16, "char __attribute__((aligned(8))) const __attribute__((aligned(16)))",
-}
+do --- attributes
+ checktypes{
+ 1, 8, "char __attribute__((aligned(8)))",
+ 1, 8, "char __attribute((aligned(8)))",
+ 1, 8, "char __attribute__((__aligned__(8)))",
+ 1, 8, "__attribute__((aligned(8))) char",
+ 1, 8, "char __declspec(align(8))",
+ 1, 8, "__declspec(align(8)) char",
+ 1, 2, "char __attribute__((aligned(8))) const __attribute__((aligned(2)))",
+ 1, 16, "char __attribute__((aligned(8))) const __attribute__((aligned(16)))",
+ }
+end
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 89773c0c..a805bdd0 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -17,6 +17,7 @@ ffi_lex_number.lua
ffi_metatype.lua
ffi_new.lua
ffi_parse_array.lua
+ffi_parse_basic.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 19/25] test: enable <ffi_parse_cdef.lua> in LuaJIT-tests
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (17 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 18/25] test: enable <ffi_parse_basic.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 20/25] test: enable <ffi_parse_struct.lua> LuaJIT test Sergey Kaplun via Tarantool-patches
` (6 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch changes `dofile()` to the corresponding `require()` of the
helper functions. It adds groups with the names of subtests and enables
the test in <index>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_parse_cdef.lua | 141 ++++++++++---------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 77 insertions(+), 65 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_parse_cdef.lua b/test/LuaJIT-tests/lib/ffi/ffi_parse_cdef.lua
index 4bb5d903..cc123808 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_parse_cdef.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_parse_cdef.lua
@@ -1,77 +1,88 @@
local ffi = require("ffi")
-dofile("../common/ffi_util.inc")
+local checkfail = require("common.ffi.checkfail")
+local checktypes = require("common.ffi.checktypes")
-checkfail({
- "int",
- "int aa1; int aa2 ",
- "static int x;",
- "static const long long x = 1;", -- NYI
- "static const double x = 1;", -- NYI
- "static const bool x = 1;", -- NYI (intentional, need true/false)
- "struct { static int x = 1; };",
- ";;static int y"
-}, ffi.cdef)
+do --- checkfail
+ checkfail({
+ "int",
+ "int aa1; int aa2 ",
+ "static int x;",
+ "static const long long x = 1;", -- NYI
+ "static const double x = 1;", -- NYI
+ "static const bool x = 1;", -- NYI (intentional, need true/false)
+ "struct { static int x = 1; };",
+ ";;static int y"
+ }, ffi.cdef)
+end
-ffi.cdef[[
-static const int K_42a = 42;
-static const char K_42b = 42+256;
-static const short K_M1a = 65535;
-static const unsigned short K_65535a = 65535;
-static const int K_1b = 0xffffffff >> 31;
-static const int K_1c = 0xffffffffu >> 31;
-static const int K_M1b = (int)0xffffffff >> 31;
-]]
+do --- constants declarations
+ ffi.cdef[[
+ static const int K_42a = 42;
+ static const char K_42b = 42+256;
+ static const short K_M1a = 65535;
+ static const unsigned short K_65535a = 65535;
+ static const int K_1b = 0xffffffff >> 31;
+ static const int K_1c = 0xffffffffu >> 31;
+ static const int K_M1b = (int)0xffffffff >> 31;
+ ]]
-checktypes{
- 42, 1, "char[K_42a]",
- 42, 1, "char[K_42b]",
- 1, 1, "char[-K_M1a]",
- 65535, 1, "char[K_65535a]",
- 1, 1, "char[K_1b]",
- 1, 1, "char[K_1c]",
- 1, 1, "char[-K_M1b]",
-}
+ checktypes{
+ 42, 1, "char[K_42a]",
+ 42, 1, "char[K_42b]",
+ 1, 1, "char[-K_M1a]",
+ 65535, 1, "char[K_65535a]",
+ 1, 1, "char[K_1b]",
+ 1, 1, "char[K_1c]",
+ 1, 1, "char[-K_M1b]",
+ }
+end
-ffi.cdef[[
-struct str1 {
- enum {
- K_99 = 99
- };
- static const int K_55 = 55;
-} extk;
-]]
+do --- constant struct
+ ffi.cdef[[
+ struct str1 {
+ enum {
+ K_99 = 99
+ };
+ static const int K_55 = 55;
+ } extk;
+ ]]
-checktypes{
- 99, 1, "char[K_99]",
- 99, 1, "char[extk.K_99]",
- 99, 1, "char[((struct str1)0).K_99]",
- 99, 1, "char[((struct str1 *)0)->K_99]",
- 55, 1, "char[extk.K_55]",
-}
+ checktypes{
+ 99, 1, "char[K_99]",
+ 99, 1, "char[extk.K_99]",
+ 99, 1, "char[((struct str1)0).K_99]",
+ 99, 1, "char[((struct str1 *)0)->K_99]",
+ 55, 1, "char[extk.K_55]",
+ }
-checkfail{
- "char[K_55]",
-}
+ checkfail{
+ "char[K_55]",
+ }
+end
-ffi.cdef[[
-extern int func1(void);
-extern int func2();
-static int func3();
-static inline int func4(int n)
-{
- int i, k = 0;
- float x = 1.0f;
- for (i = 0; i < n; i++) {
- k += i;
+do --- parse functions declaration
+ ffi.cdef[[
+ extern int func1(void);
+ extern int func2();
+ static int func3();
+ static inline int func4(int n)
+ {
+ int i, k = 0;
+ float x = 1.0f;
+ for (i = 0; i < n; i++) {
+ k += i;
+ }
+ return k;
}
- return k;
-}
-;;;
-]]
+ ;;;
+ ]]
+end
-ffi.cdef[[
-int ext1;
-extern int ext2;
-]]
+do --- parse extern
+ ffi.cdef[[
+ int ext1;
+ extern int ext2;
+ ]]
+end
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index a805bdd0..12b6387f 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -18,6 +18,7 @@ ffi_metatype.lua
ffi_new.lua
ffi_parse_array.lua
ffi_parse_basic.lua
+ffi_parse_cdef.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 20/25] test: enable <ffi_parse_struct.lua> LuaJIT test
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (18 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 19/25] test: enable <ffi_parse_cdef.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 21/25] test: enable <ffi_tabov.lua> " Sergey Kaplun via Tarantool-patches
` (5 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch changes `dofile()` to the corresponding `require()` of the
helper functions. It adds groups with the names of subtests and enables
the test in <index>.
Part of tarantool/tarantool#9398
---
.../LuaJIT-tests/lib/ffi/ffi_parse_struct.lua | 335 +++++++++---------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 176 insertions(+), 160 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_parse_struct.lua b/test/LuaJIT-tests/lib/ffi/ffi_parse_struct.lua
index 16a3d053..cb231c33 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_parse_struct.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_parse_struct.lua
@@ -1,113 +1,123 @@
local ffi = require("ffi")
-dofile("../common/ffi_util.inc")
+local checkfail = require("common.ffi.checkfail")
+local checktypes = require("common.ffi.checktypes")
+local fails = require("common.fails")
-checkfail{
- "struct",
- "struct {",
- "struct xx xx {}",
- "struct { int x }",
- "struct { int x, }",
- "struct { int x,y }",
- "struct { void x; }",
- "struct { int x(void); }",
- "struct recursive1 { struct recursive1 { } x; }",
- "union",
- "union {",
- "union xx xx {}",
- "union { int x }",
- "union { int x, }",
- "union { int x,y }",
- "union { void x; }",
- "union { int x(void); }",
- "union recursive1 { union recursive1 { } x; }",
-}
+local P = ffi.sizeof("void *")
+local A = (ffi.arch == "x86" and not ffi.abi("win")) and 4 or 8
+
+do --- checkfail
+ checkfail{
+ "struct",
+ "struct {",
+ "struct xx xx {}",
+ "struct { int x }",
+ "struct { int x, }",
+ "struct { int x,y }",
+ "struct { void x; }",
+ "struct { int x(void); }",
+ "struct recursive1 { struct recursive1 { } x; }",
+ "union",
+ "union {",
+ "union xx xx {}",
+ "union { int x }",
+ "union { int x, }",
+ "union { int x,y }",
+ "union { void x; }",
+ "union { int x(void); }",
+ "union recursive1 { union recursive1 { } x; }",
+ }
+end
-- NYI: rollback doesn't recover struct state
-- ffi.cdef("struct zzz")
-- fails(ffi.cdef, "struct zzz { int")
-- ffi.cdef("struct zzz { int x; }")
-ffi.cdef("struct foo; typedef struct foo foo_t;")
-assert(ffi.sizeof("struct foo") == nil)
-assert(ffi.sizeof("foo_t") == nil)
-ffi.cdef("struct foo { int x,y; };")
-assert(ffi.sizeof("struct foo") == 8)
-assert(ffi.sizeof("foo_t") == 8)
-assert(ffi.sizeof(ffi.typeof("struct foo")) == 8)
-assert(ffi.sizeof(ffi.typeof("foo_t")) == 8)
-ffi.cdef("struct foo;")
-fails(ffi.cdef, "struct foo {};")
-fails(ffi.cdef, "union foo;")
-fails(ffi.cdef, "union foo {};")
-fails(ffi.cdef, "enum foo;")
-fails(ffi.cdef, "enum foo { ZZZ1 };")
-
-local P = ffi.sizeof("void *")
-local A = (ffi.arch == "x86" and not ffi.abi("win")) and 4 or 8
+do --- siezeofs and invalid decalarations
+ ffi.cdef("struct foo; typedef struct foo struct_foo_t;")
+ assert(ffi.sizeof("struct foo") == nil)
+ assert(ffi.sizeof("struct_foo_t") == nil)
+ ffi.cdef("struct foo { int x,y; };")
+ assert(ffi.sizeof("struct foo") == 8)
+ assert(ffi.sizeof("struct_foo_t") == 8)
+ assert(ffi.sizeof(ffi.typeof("struct foo")) == 8)
+ assert(ffi.sizeof(ffi.typeof("struct_foo_t")) == 8)
+ ffi.cdef("struct foo;")
+ fails(ffi.cdef, "struct foo {};")
+ fails(ffi.cdef, "union foo;")
+ fails(ffi.cdef, "union foo {};")
+ fails(ffi.cdef, "enum foo;")
+ fails(ffi.cdef, "enum foo { ZZZ1 };")
+end
-checktypes{
- 0, 1, "struct {}",
- 1, 1, "struct { char x; }",
- 2, 1, "struct { char x,y; }",
- 4, 1, "struct { char x,y; char a,b; }",
- 4, 2, "struct { char x; short y; }",
- 4, 2, "struct { short x; char y; }",
- 8, 4, "struct { char x; int y; }",
- 8, 4, "struct { int x; char y; }",
- 12, 4, "struct { char x; int y; char z; }",
- P*4, P, "struct { char x,*y,**z,a,b,c,d; }",
- 64, 4, "struct { struct { struct { struct { int x,y; } a,b; } a,b; } a,b; }",
- 4, 4, "struct { struct { struct { struct { int x; }; }; }; }",
- 8, 4, "struct { struct foo; }",
- 8, 4, "struct { foo_t; }",
- 8, 8, "struct __attribute__((aligned(sizeof(foo_t)))) { int a; }",
- 6, 2, "struct { char a; char x; short y; char z; char c; }",
- 10, 2, "struct { char a; struct { char x; short y; char z; } b; char c; }",
- 8, A, "struct { double a; }",
- A+8, A, "struct { int a; double b; }",
- 8, A, "struct { long long a; }",
- A+8, A, "struct { int a; long long b; }",
- 16, A, "struct { _Complex a; }",
- A+16, A, "struct { int a; _Complex b; }",
- 8, 8, "struct { float __attribute__((mode(__V2SF__))) a; }",
- 16, 8, "struct { int a; float __attribute__((mode(__V2SF__))) b; }",
- 16, 8, "struct { float __attribute__((mode(__V2SF__))) a[2]; }",
- 24, 8, "struct { int a; float __attribute__((mode(__V2SF__))) b[2]; }",
- 16, 16, "struct { float __attribute__((vector_size(16))) a; }",
- 32, 16, "struct { int a; float __attribute__((vector_size(16))) b; }",
-}
+do --- struct base
+ checktypes{
+ 0, 1, "struct {}",
+ 1, 1, "struct { char x; }",
+ 2, 1, "struct { char x,y; }",
+ 4, 1, "struct { char x,y; char a,b; }",
+ 4, 2, "struct { char x; short y; }",
+ 4, 2, "struct { short x; char y; }",
+ 8, 4, "struct { char x; int y; }",
+ 8, 4, "struct { int x; char y; }",
+ 12, 4, "struct { char x; int y; char z; }",
+ P*4, P, "struct { char x,*y,**z,a,b,c,d; }",
+ 64, 4, "struct { struct { struct { struct { int x,y; } a,b; } a,b; } a,b; }",
+ 4, 4, "struct { struct { struct { struct { int x; }; }; }; }",
+ 8, 4, "struct { struct foo; }",
+ 8, 4, "struct { struct_foo_t; }",
+ 8, 8, "struct __attribute__((aligned(sizeof(struct_foo_t)))) { int a; }",
+ 6, 2, "struct { char a; char x; short y; char z; char c; }",
+ 10, 2, "struct { char a; struct { char x; short y; char z; } b; char c; }",
+ 8, A, "struct { double a; }",
+ A+8, A, "struct { int a; double b; }",
+ 8, A, "struct { long long a; }",
+ A+8, A, "struct { int a; long long b; }",
+ 16, A, "struct { _Complex a; }",
+ A+16, A, "struct { int a; _Complex b; }",
+ 8, 8, "struct { float __attribute__((mode(__V2SF__))) a; }",
+ 16, 8, "struct { int a; float __attribute__((mode(__V2SF__))) b; }",
+ 16, 8, "struct { float __attribute__((mode(__V2SF__))) a[2]; }",
+ 24, 8, "struct { int a; float __attribute__((mode(__V2SF__))) b[2]; }",
+ 16, 16, "struct { float __attribute__((vector_size(16))) a; }",
+ 32, 16, "struct { int a; float __attribute__((vector_size(16))) b; }",
+ }
+end
-checktypes{
- 0, 1, "union {}",
- 1, 1, "union { char x; }",
- 1, 1, "union { char x,y; }",
- 2, 2, "union { char x; short y; }",
- 2, 2, "union { short x; char y; }",
- 4, 4, "union { char x; int y; }",
- 4, 4, "union { int x; char y; }",
- 4, 4, "union { char x; int y; short z; }",
- P, P, "union { char x,*y,**z,a,b,c,d; }",
- 4, 4, "union { union { union { union { int x,y; } a,b; } a,b; } a,b; }",
- 4, 4, "union { union { union { union { int x; }; }; }; }",
- 2, 2, "union { union { short x; }; char y; }",
- 2, 2, "union { struct { short x; }; char y; }",
- 4, 2, "struct { union { short x; }; char y; }",
- 2, 1, "union { struct { char a,b; }; char y; }",
- 2, 1, "struct { union { char a,b; }; char y; }",
- 8, A, "union { double a; }",
- 8, A, "union { int a; double b; }",
- 8, A, "union { long long a; }",
- 8, A, "union { int a; long long b; }",
- 16, A, "union { _Complex a; }",
- 16, A, "union { int a; _Complex b; }",
- 8, 8, "union { float __attribute__((mode(__V2SF__))) a; }",
- 8, 8, "union { int a; float __attribute__((mode(__V2SF__))) b; }",
- 16, 16, "union { float __attribute__((vector_size(16))) a; }",
- 16, 16, "union { int a; float __attribute__((vector_size(16))) b; }",
-}
+do --- unions
+ checktypes{
+ 0, 1, "union {}",
+ 1, 1, "union { char x; }",
+ 1, 1, "union { char x,y; }",
+ 2, 2, "union { char x; short y; }",
+ 2, 2, "union { short x; char y; }",
+ 4, 4, "union { char x; int y; }",
+ 4, 4, "union { int x; char y; }",
+ 4, 4, "union { char x; int y; short z; }",
+ P, P, "union { char x,*y,**z,a,b,c,d; }",
+ 4, 4, "union { union { union { union { int x,y; } a,b; } a,b; } a,b; }",
+ 4, 4, "union { union { union { union { int x; }; }; }; }",
+ 2, 2, "union { union { short x; }; char y; }",
+ 2, 2, "union { struct { short x; }; char y; }",
+ 4, 2, "struct { union { short x; }; char y; }",
+ 2, 1, "union { struct { char a,b; }; char y; }",
+ 2, 1, "struct { union { char a,b; }; char y; }",
+ 8, A, "union { double a; }",
+ 8, A, "union { int a; double b; }",
+ 8, A, "union { long long a; }",
+ 8, A, "union { int a; long long b; }",
+ 16, A, "union { _Complex a; }",
+ 16, A, "union { int a; _Complex b; }",
+ 8, 8, "union { float __attribute__((mode(__V2SF__))) a; }",
+ 8, 8, "union { int a; float __attribute__((mode(__V2SF__))) b; }",
+ 16, 16, "union { float __attribute__((vector_size(16))) a; }",
+ 16, 16, "union { int a; float __attribute__((vector_size(16))) b; }",
+ }
+end
-do
+do --- struct offsetof
local ct
ct = ffi.typeof("struct { int a; char b; short c; int d; }")
assert(ffi.offsetof(ct, "a") == 0)
@@ -129,40 +139,44 @@ do
assert(ffi.offsetof(ct, "b") == A)
end
-checkfail{
- "struct { int :; }",
- "struct { int a:; }",
- "struct { int a:bad; }",
- "struct { int a:0; }",
- "struct { int a:33; }",
- "struct { int a:-1; }",
- "struct { _Bool a:2; }",
- "struct { double a:2; }",
- "struct { complex a:2; }",
- "struct { int __attribute__((mode(__TI__))) a:2; }",
- "struct { int __attribute__((vector_size(16))) a:2; }",
- "struct { int a[2]:2; }",
- "struct { void a:2; }",
-}
+do --- checkfail bitfields
+ checkfail{
+ "struct { int :; }",
+ "struct { int a:; }",
+ "struct { int a:bad; }",
+ "struct { int a:0; }",
+ "struct { int a:33; }",
+ "struct { int a:-1; }",
+ "struct { _Bool a:2; }",
+ "struct { double a:2; }",
+ "struct { complex a:2; }",
+ "struct { int __attribute__((mode(__TI__))) a:2; }",
+ "struct { int __attribute__((vector_size(16))) a:2; }",
+ "struct { int a[2]:2; }",
+ "struct { void a:2; }",
+ }
+end
-checktypes{
- 4, 4, "struct { unsigned a:1; }",
- 4, 4, "struct { unsigned a:1, b:1, c:1; }",
- 1, 1, "struct { _Bool a:1, b:1, c:1; }",
- 8, 4, "struct { unsigned a:16, b:16, c:16; }",
- 8, 4, "struct { unsigned a:17, b:16, c:16; }",
- 12, 4, "struct { unsigned a:17, b:16, c:17; }",
- 12, 4, "struct { unsigned a:16, b:17, c:16; }",
- 8, 4, "struct { unsigned a:16, :16, c:16; }",
- 8, 4, "struct { unsigned a:17, :16, c:16; }",
- 12, 4, "struct { unsigned a:17, :16, c:17; }",
- 12, 4, "struct { unsigned a:16, :17, c:16; }",
- 8, 4, "struct { unsigned a:16, :0, c:16; }",
- 4, 4, "struct { unsigned a:16, b:16, :0, :0; }",
- 8, 4, "struct { unsigned a:16, :0, :0, :0, c:16; }",
- 1, 1, "struct { char a:1; _Bool b:1; }",
- 1, 1, "struct { char a:1; signed char b:1; unsigned char c:1; }",
-}
+do --- bitfields
+ checktypes{
+ 4, 4, "struct { unsigned a:1; }",
+ 4, 4, "struct { unsigned a:1, b:1, c:1; }",
+ 1, 1, "struct { _Bool a:1, b:1, c:1; }",
+ 8, 4, "struct { unsigned a:16, b:16, c:16; }",
+ 8, 4, "struct { unsigned a:17, b:16, c:16; }",
+ 12, 4, "struct { unsigned a:17, b:16, c:17; }",
+ 12, 4, "struct { unsigned a:16, b:17, c:16; }",
+ 8, 4, "struct { unsigned a:16, :16, c:16; }",
+ 8, 4, "struct { unsigned a:17, :16, c:16; }",
+ 12, 4, "struct { unsigned a:17, :16, c:17; }",
+ 12, 4, "struct { unsigned a:16, :17, c:16; }",
+ 8, 4, "struct { unsigned a:16, :0, c:16; }",
+ 4, 4, "struct { unsigned a:16, b:16, :0, :0; }",
+ 8, 4, "struct { unsigned a:16, :0, :0, :0, c:16; }",
+ 1, 1, "struct { char a:1; _Bool b:1; }",
+ 1, 1, "struct { char a:1; signed char b:1; unsigned char c:1; }",
+ }
+end
-- NYI: bit fields > 32 bit
-- local L = ffi.alignof("struct { long long a; }")
@@ -170,35 +184,36 @@ checktypes{
-- L, L, "struct { long long a:1; }",
-- }
--- Bit field packing.
-checktypes{
- 1, 1, "struct { _Bool a:1, b:1, c:1; }",
- 4, 4, "struct { short a:9; int b:9; char c; }",
- 4, 4, "struct { char a; int b:7; }",
- 4, 4, "struct { short a; char b; int c:7; }",
- 4, 4, "struct { char a:7; int b:7; int c:7; int d:10; }",
- 4, 1, "struct { char a:7; char b:7; char c:7; char d:7; }",
- 4, 4, "struct { char a:7; int b:7, c:7, d:7; int e:4; }",
- 4, 4, "struct { char a:7; int b:7, c:7, d:7; char e:4; }",
- 5, 1, "struct { char a:7; char b:7, c:7, d:7; char e:4; }",
- 4, 1, "struct __attribute__((packed)) { char a:7; char b:7, c:7, d:7; char e:4; }",
- 4, 4, "struct { char a:7; int b:7; int c:7; int d:10; }",
- 8, 4, "struct { char a:7; int b:7; char c:7; int d:10; }",
- 4, 1, "struct __attribute__((packed)) { char a:7; int b:7; char c:7; int d:10; }",
- 4, 1, "struct { char a:7; int b:7; char c:7; int d:10; } __attribute__((packed))",
- 2, 1, "struct __attribute__((packed)) { char a:4; char b:8; }",
- 2, 1, "struct __attribute__((packed)) { char a:4; char :0; char b:4; }",
- 1, 1, "struct __attribute__((packed)) { _Bool a:1; _Bool b:1; }",
- 2, 1, "struct __attribute__((packed)) { _Bool a:1; _Bool b:1 __attribute((aligned(1))); }",
- 4, 2, "struct __attribute__((packed)) { _Bool a:1; _Bool b:1 __attribute((aligned(2))); }",
- 8, 4, "struct { _Bool a:1; int b __attribute((aligned(2))); }",
- 16, 8, "struct { _Bool a:1; int b __attribute((aligned(8))); }",
- 6, 2, "struct { _Bool a:1; int b __attribute((aligned(2))) __attribute((packed)); }",
- 6, 2, "struct __attribute__((packed)) { _Bool a:1; int b __attribute((aligned(2))); }",
- 6, 2, "struct __attribute__((packed)) { _Bool a:1; int b __attribute((aligned(2))) __attribute((packed)); }",
-}
+do --- Bit field packing.
+ checktypes{
+ 1, 1, "struct { _Bool a:1, b:1, c:1; }",
+ 4, 4, "struct { short a:9; int b:9; char c; }",
+ 4, 4, "struct { char a; int b:7; }",
+ 4, 4, "struct { short a; char b; int c:7; }",
+ 4, 4, "struct { char a:7; int b:7; int c:7; int d:10; }",
+ 4, 1, "struct { char a:7; char b:7; char c:7; char d:7; }",
+ 4, 4, "struct { char a:7; int b:7, c:7, d:7; int e:4; }",
+ 4, 4, "struct { char a:7; int b:7, c:7, d:7; char e:4; }",
+ 5, 1, "struct { char a:7; char b:7, c:7, d:7; char e:4; }",
+ 4, 1, "struct __attribute__((packed)) { char a:7; char b:7, c:7, d:7; char e:4; }",
+ 4, 4, "struct { char a:7; int b:7; int c:7; int d:10; }",
+ 8, 4, "struct { char a:7; int b:7; char c:7; int d:10; }",
+ 4, 1, "struct __attribute__((packed)) { char a:7; int b:7; char c:7; int d:10; }",
+ 4, 1, "struct { char a:7; int b:7; char c:7; int d:10; } __attribute__((packed))",
+ 2, 1, "struct __attribute__((packed)) { char a:4; char b:8; }",
+ 2, 1, "struct __attribute__((packed)) { char a:4; char :0; char b:4; }",
+ 1, 1, "struct __attribute__((packed)) { _Bool a:1; _Bool b:1; }",
+ 2, 1, "struct __attribute__((packed)) { _Bool a:1; _Bool b:1 __attribute((aligned(1))); }",
+ 4, 2, "struct __attribute__((packed)) { _Bool a:1; _Bool b:1 __attribute((aligned(2))); }",
+ 8, 4, "struct { _Bool a:1; int b __attribute((aligned(2))); }",
+ 16, 8, "struct { _Bool a:1; int b __attribute((aligned(8))); }",
+ 6, 2, "struct { _Bool a:1; int b __attribute((aligned(2))) __attribute((packed)); }",
+ 6, 2, "struct __attribute__((packed)) { _Bool a:1; int b __attribute((aligned(2))); }",
+ 6, 2, "struct __attribute__((packed)) { _Bool a:1; int b __attribute((aligned(2))) __attribute((packed)); }",
+ }
+end
-do
+do --- pragma pack pop
ffi.cdef[[
struct foo_packorig { char a; int b; short c; };
#pragma pack(1)
@@ -236,7 +251,7 @@ do
assert(ffi.sizeof("struct foo_packpop2") == 12)
end
-do
+do --- pragma pack aligment
ffi.cdef[[
#pragma pack(2)
struct foo_packalign8 {
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 12b6387f..e3a34e30 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -19,6 +19,7 @@ ffi_new.lua
ffi_parse_array.lua
ffi_parse_basic.lua
ffi_parse_cdef.lua
+ffi_parse_struct.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 21/25] test: enable <ffi_tabov.lua> LuaJIT test
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (19 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 20/25] test: enable <ffi_parse_struct.lua> LuaJIT test Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 22/25] test: enable <lightud.lua> " Sergey Kaplun via Tarantool-patches
` (4 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch moves the <ffi_tabov.lua> test from the LuaJIT-tests suite to
the tarantool-tests suite, because this test should be run separately to
avoid overflow of the table with ctypes for other tests from
LuaJIT-tests suite.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_tabov.lua | 12 -----------
test/tarantool-tests/ffi-tabov.test.lua | 27 +++++++++++++++++++++++++
2 files changed, 27 insertions(+), 12 deletions(-)
delete mode 100644 test/LuaJIT-tests/lib/ffi/ffi_tabov.lua
create mode 100644 test/tarantool-tests/ffi-tabov.test.lua
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_tabov.lua b/test/LuaJIT-tests/lib/ffi/ffi_tabov.lua
deleted file mode 100644
index ba621960..00000000
--- a/test/LuaJIT-tests/lib/ffi/ffi_tabov.lua
+++ /dev/null
@@ -1,12 +0,0 @@
-local ffi = require("ffi")
-
-local last = 0
-
-assert(pcall(function()
- for i=1,65536 do
- last = i
- ffi.typeof"struct {}"
- end
-end) == false)
-
-assert(last > 20000)
diff --git a/test/tarantool-tests/ffi-tabov.test.lua b/test/tarantool-tests/ffi-tabov.test.lua
new file mode 100644
index 00000000..7ea8b24b
--- /dev/null
+++ b/test/tarantool-tests/ffi-tabov.test.lua
@@ -0,0 +1,27 @@
+local tap = require('tap')
+local ffi = require('ffi')
+
+-- This test is moved here from the LuaJIT-tests suite since it
+-- should be run separately because it exhausts the ctype table.
+local test = tap.test('ffi-tabov')
+
+test:plan(3)
+
+-- XXX: Amount of ctypes available to the user of a platform.
+local MIN_AVAILABLE_CTYPES = 20000
+
+local last = 0
+
+local res, errmsg = pcall(function()
+ for i = 1, 2^16 do
+ last = i
+ ffi.typeof('struct {}')
+ end
+end)
+
+test:ok(res == false, 'correct status')
+test:like(errmsg, 'table overflow', 'correct error message')
+
+test:ok(last > MIN_AVAILABLE_CTYPES, 'huge enough amount of free ctypes')
+
+test:done(true)
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 22/25] test: enable <lightud.lua> LuaJIT test
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (20 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 21/25] test: enable <ffi_tabov.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 23/25] test: enable <api_call.lua> " Sergey Kaplun via Tarantool-patches
` (3 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch moves the <lightud.lua> test from the <misc> to <lang>
directory, includes it in <index>, and names subtests. Also, it enables
tests for all arches and fixes tests for 47-bit lightuserdata because it
is available since the commit
2cacfa8e7ffefb715abf55dc5b0c708c63251868 ("Add support for full-range 64
bit lightuserdata.")
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lang/index | 1 +
test/LuaJIT-tests/lang/lightud.lua | 89 ++++++++++++++++++++++++++++++
test/LuaJIT-tests/misc/lightud.lua | 88 -----------------------------
3 files changed, 90 insertions(+), 88 deletions(-)
create mode 100644 test/LuaJIT-tests/lang/lightud.lua
delete mode 100644 test/LuaJIT-tests/misc/lightud.lua
diff --git a/test/LuaJIT-tests/lang/index b/test/LuaJIT-tests/lang/index
index 88e2edfa..60cbecfb 100644
--- a/test/LuaJIT-tests/lang/index
+++ b/test/LuaJIT-tests/lang/index
@@ -5,6 +5,7 @@ compare_nan.lua
constant
for.lua
length.lua
+lightud.lua
modulo.lua
concat.lua
self.lua
diff --git a/test/LuaJIT-tests/lang/lightud.lua b/test/LuaJIT-tests/lang/lightud.lua
new file mode 100644
index 00000000..aee9e85c
--- /dev/null
+++ b/test/LuaJIT-tests/lang/lightud.lua
@@ -0,0 +1,89 @@
+local ctest = require("libctest")
+
+local lightud = ctest.lightud
+local assert = assert
+
+-- x64 lightud tests
+do --- light userdata comparison and tostring +x64
+ local ud1 = lightud(0x12345678)
+ local ud2 = lightud(0x12345678)
+ assert(ud1 == ud2)
+ assert(tostring(ud1) == "userdata: 0x12345678")
+end
+
+do --- unequal light userdata comparison +x64
+ local ud1 = lightud(1)
+ local ud2 = lightud(2)
+ assert(ud1 ~= ud2)
+end
+
+do --- big light userdata comparison and tostring +x64
+ local ud1 = lightud(2^47-1)
+ local ud2 = lightud(2^47-1)
+ assert(ud1 == ud2)
+ assert(tostring(ud1) == "userdata: 0x7fffffffffff")
+end
+
+do --- unequal light userdata comparison JIT +x64
+ local ud1 = lightud(0x12345678+123*2^32)
+ local ud2 = lightud(0x12345678+456*2^32)
+ for i=1,100 do assert(ud1 ~= ud2) end
+end
+
+do --- 47 bits light userdata +x64
+ assert(tostring(lightud(0x5abc*2^32 + 0xdef01234)) == "userdata: 0x5abcdef01234")
+ -- Now more than 47 bits are available.
+ assert(pcall(lightud, 2^47) == true)
+ assert(pcall(lightud, 2^64-2048) == true)
+end
+
+do --- metatable check
+ assert(getmetatable(lightud(1)) == nil)
+end
+
+do --- lightuserdata SLOAD value and HREF key
+ local ud = lightud(12345)
+ local t = {[ud] = 42}
+ for i=1,100 do
+ assert(t[ud] == 42)
+ end
+end
+
+do --- lightuserdata NEWREF key
+ local ud = lightud(12345)
+ for i=1,100 do
+ local t = {[ud] = 42}
+ assert(t[ud] == 42)
+ end
+end
+
+do --- lightuserdata ASTORE/HSTORE value
+ local ud = lightud(12345)
+ local t = {}
+ for i=1,100 do
+ t[i] = ud
+ end
+ assert(t[100] == ud)
+end
+
+do --- lightuserdata sync to stack
+ local ud = lightud(12345)
+ local x = nil
+ for j=1,20 do
+ for i=1,50 do
+ x = ud
+ end
+ assert(x == ud)
+ end
+end
+
+do --- lightuserdata vs. number type check
+ local t = {}
+ for i=1,200 do t[i] = i end
+ t[180] = lightud(12345)
+ local x = 0
+ assert(not pcall(function(t)
+ for i=1,200 do x = x + t[i] end
+ end, t))
+ assert(x == 16110)
+end
diff --git a/test/LuaJIT-tests/misc/lightud.lua b/test/LuaJIT-tests/misc/lightud.lua
deleted file mode 100644
index 4974d50f..00000000
--- a/test/LuaJIT-tests/misc/lightud.lua
+++ /dev/null
@@ -1,88 +0,0 @@
-local ctest = require("ctest")
-
-local lightud = ctest.lightud
-local assert = assert
-
--- x64 lightud tests
-if jit and jit.arch == "x64" then
- do
- local ud1 = lightud(0x12345678)
- local ud2 = lightud(0x12345678)
- assert(ud1 == ud2)
- assert(tostring(ud1) == "userdata: 0x12345678")
- end
- do
- local ud1 = lightud(1)
- local ud2 = lightud(2)
- assert(ud1 ~= ud2)
- end
- do
- local ud1 = lightud(2^47-1)
- local ud2 = lightud(2^47-1)
- assert(ud1 == ud2)
- assert(tostring(ud1) == "userdata: 0x7fffffffffff")
- end
- do
- local ud1 = lightud(0x12345678+123*2^32)
- local ud2 = lightud(0x12345678+456*2^32)
- for i=1,100 do assert(ud1 ~= ud2) end
- end
- assert(tostring(lightud(0x5abc*2^32 + 0xdef01234)) == "userdata: 0x5abcdef01234")
- assert(pcall(lightud, 2^47) == false)
- assert(pcall(lightud, 2^64-2048) == false)
-end
-
-assert(getmetatable(lightud(1)) == nil)
-
--- lightuserdata SLOAD value and HREF key
-do
- local ud = lightud(12345)
- local t = {[ud] = 42}
- for i=1,100 do
- assert(t[ud] == 42)
- end
-end
-
--- lightuserdata NEWREF key
-do
- local ud = lightud(12345)
- for i=1,100 do
- local t = {[ud] = 42}
- assert(t[ud] == 42)
- end
-end
-
--- lightuserdata ASTORE/HSTORE value
-do
- local ud = lightud(12345)
- local t = {}
- for i=1,100 do
- t[i] = ud
- end
- assert(t[100] == ud)
-end
-
--- lightuserdata sync to stack
-do
- local ud = lightud(12345)
- local x = nil
- for j=1,20 do
- for i=1,50 do
- x = ud
- end
- assert(x == ud)
- end
-end
-
--- lightuserdata vs. number type check
-do
- local t = {}
- for i=1,200 do t[i] = i end
- t[180] = lightud(12345)
- local x = 0
- assert(not pcall(function(t)
- for i=1,200 do x = x + t[i] end
- end, t))
- assert(x == 16110)
-end
-
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 23/25] test: enable <api_call.lua> LuaJIT test
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (21 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 22/25] test: enable <lightud.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 24/25] test: enable <catch_wrap.lua> " Sergey Kaplun via Tarantool-patches
` (2 subsequent siblings)
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch moves the <api_call.lua> test from the <misc> to <lang>
directory, includes it in <index>, and names subtests.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/{misc => lang}/api_call.lua | 32 +++++++++++--------
test/LuaJIT-tests/lang/index | 1 +
2 files changed, 19 insertions(+), 14 deletions(-)
rename test/LuaJIT-tests/{misc => lang}/api_call.lua (79%)
diff --git a/test/LuaJIT-tests/misc/api_call.lua b/test/LuaJIT-tests/lang/api_call.lua
similarity index 79%
rename from test/LuaJIT-tests/misc/api_call.lua
rename to test/LuaJIT-tests/lang/api_call.lua
index 7dbd5e40..142959c5 100644
--- a/test/LuaJIT-tests/misc/api_call.lua
+++ b/test/LuaJIT-tests/lang/api_call.lua
@@ -1,4 +1,4 @@
-local ctest = require("ctest")
+local ctest = require("libctest")
local function ret0() end
local function ret1() return 1 end
@@ -57,19 +57,10 @@ local function test_adjust_results(testfunc)
ck(cc(-1, retva, 1, 2), 1, 2)
end
-test_adjust_results(ctest.call)
-test_adjust_results(ctest.pcall_err)
-
-
local function gcshrink()
for i=1,10 do collectgarbage() end
end
-assert(select('#', ctest.call(2000, gcshrink)) == 2000)
-gcshrink()
-assert(select('#', ctest.call(7000, gcshrink)) == 7000)
-gcshrink()
-
local function test_yield(resume, yield)
local function inpcall()
ck(pack(yield(6, 7)), 18, 19)
@@ -91,8 +82,21 @@ local function test_yield(resume, yield)
assert(resume(co) == false)
end
-test_yield(coroutine.resume, coroutine.yield)
-test_yield(ctest.resume, coroutine.yield)
-test_yield(coroutine.resume, ctest.yield)
-test_yield(ctest.resume, ctest.yield)
+do --- adjust results
+ test_adjust_results(ctest.call)
+ test_adjust_results(ctest.pcall_err)
+end
+do --- GC shrink
+ assert(select('#', ctest.call(2000, gcshrink)) == 2000)
+ gcshrink()
+ assert(select('#', ctest.call(7000, gcshrink)) == 7000)
+ gcshrink()
+end
+
+do --- yield
+ test_yield(coroutine.resume, coroutine.yield)
+ test_yield(ctest.resume, coroutine.yield)
+ test_yield(coroutine.resume, ctest.yield)
+ test_yield(ctest.resume, ctest.yield)
+end
diff --git a/test/LuaJIT-tests/lang/index b/test/LuaJIT-tests/lang/index
index 60cbecfb..dc0c2e14 100644
--- a/test/LuaJIT-tests/lang/index
+++ b/test/LuaJIT-tests/lang/index
@@ -1,4 +1,5 @@
andor.lua
+api_call.lua
assignment.lua
compare.lua
compare_nan.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 24/25] test: enable <catch_wrap.lua> LuaJIT test
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (22 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 23/25] test: enable <api_call.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 25/25] test: enable <catch_cpp.lua> " Sergey Kaplun via Tarantool-patches
2024-01-23 9:01 ` [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Bronnikov via Tarantool-patches
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch moves the <catch_wrap.lua> test from the <misc> to <lang>
directory, includes it in <index>, and names subtests. Also, since the
tests may be shuffled, `cp.wrapon()` and `cp.wrapoff()` are used for
each test separately. Also, this patch adds a workaround for the
internal ASAN bug, see details in the comment in the <CMakeLists.txt>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/CMakeLists.txt | 16 ++++++++++
.../{misc => lang}/catch_wrap.lua | 29 +++++++++++++------
test/LuaJIT-tests/lang/index | 1 +
3 files changed, 37 insertions(+), 9 deletions(-)
rename test/LuaJIT-tests/{misc => lang}/catch_wrap.lua (74%)
diff --git a/test/LuaJIT-tests/CMakeLists.txt b/test/LuaJIT-tests/CMakeLists.txt
index c52bcc71..8ecfe3f6 100644
--- a/test/LuaJIT-tests/CMakeLists.txt
+++ b/test/LuaJIT-tests/CMakeLists.txt
@@ -24,6 +24,22 @@ else()
list(APPEND LUAJIT_TESTS_ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
endif()
+if(LUAJIT_USE_ASAN)
+ # When running LuaJIT-tests under ASAN, the internal ASAN check
+ # failed:
+ # AddressSanitizer: CHECK failed: asan_interceptors.cpp:356
+ # "((__interception::real___cxa_throw)) != (0)" (0x0, 0x0)
+ # This is a workaround suggested at
+ # https://github.com/google/sanitizers/issues/934.
+ execute_process(
+ COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libstdc++.so
+ OUTPUT_VARIABLE LIB_STDCPP
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ # Fortunately, we are not interested in macOS here.
+ list(APPEND LUAJIT_TESTS_ENV LD_PRELOAD="${LIB_STDCPP}")
+endif()
+
add_custom_command(TARGET LuaJIT-tests
COMMENT "Running LuaJIT-tests"
COMMAND
diff --git a/test/LuaJIT-tests/misc/catch_wrap.lua b/test/LuaJIT-tests/lang/catch_wrap.lua
similarity index 74%
rename from test/LuaJIT-tests/misc/catch_wrap.lua
rename to test/LuaJIT-tests/lang/catch_wrap.lua
index 7f656bcc..fa54cd67 100644
--- a/test/LuaJIT-tests/misc/catch_wrap.lua
+++ b/test/LuaJIT-tests/lang/catch_wrap.lua
@@ -1,45 +1,56 @@
-
local cp = require("cpptest")
-cp.wrapon()
-do
+local unwind
+
+do --- catch, no error
+ cp.wrapon()
local a, b = pcall(cp.catch, function() return "x" end)
assert(a == true and b == "x")
+ cp.wrapoff()
end
-do
+do --- pcall throw
+ cp.wrapon()
local a, b = pcall(function() cp.throw("foo") end)
assert(a == false and b == "foo")
+ cp.wrapoff()
end
-local unwind
-do
+do --- catch throw
+ cp.wrapon()
local a, b = pcall(cp.catch, function() cp.throw("foo") end)
unwind = a
assert((a == false and b == "foo") or (a == true and b == "catch ..."))
+ cp.wrapoff()
end
-do
+do --- alloc, no error
+ cp.wrapon()
local st = cp.alloc(function() return cp.isalloc() end)
assert(st == true)
assert(cp.isalloc() == false)
+ cp.wrapoff()
end
-do
+do --- throw in alloc
+ cp.wrapon()
local a, b = pcall(cp.alloc, function()
assert(cp.isalloc() == true)
return "foo", cp.throw
end)
assert(a == false and b == "foo")
assert(cp.isalloc() == false)
+ cp.wrapoff()
end
-do
+do --- error in alloc
+ cp.wrapon()
local a, b = pcall(cp.alloc, function()
assert(cp.isalloc() == true)
return "foo", error
end)
assert(a == false and b == "foo")
if unwind then assert(cp.isalloc() == false) end
+ cp.wrapoff()
end
diff --git a/test/LuaJIT-tests/lang/index b/test/LuaJIT-tests/lang/index
index dc0c2e14..87b0c5a0 100644
--- a/test/LuaJIT-tests/lang/index
+++ b/test/LuaJIT-tests/lang/index
@@ -1,6 +1,7 @@
andor.lua
api_call.lua
assignment.lua
+catch_wrap.lua
compare.lua
compare_nan.lua
constant
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* [Tarantool-patches] [PATCH luajit 25/25] test: enable <catch_cpp.lua> LuaJIT test
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (23 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 24/25] test: enable <catch_wrap.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-19 11:32 ` Sergey Kaplun via Tarantool-patches
2024-01-23 9:01 ` [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Bronnikov via Tarantool-patches
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2024-01-19 11:32 UTC (permalink / raw)
To: Maxim Kokryashkin, Sergey Bronnikov; +Cc: tarantool-patches
This patch moves the <catch_cpp.lua> test from the <sysdep> to <lang>
directory, includes it in <index>, and names subtests.
Resolves of tarantool/tarantool#7834
Part of tarantool/tarantool#9398
---
.../{sysdep => lang}/catch_cpp.lua | 36 ++++++++++---------
test/LuaJIT-tests/lang/index | 1 +
2 files changed, 20 insertions(+), 17 deletions(-)
rename test/LuaJIT-tests/{sysdep => lang}/catch_cpp.lua (77%)
diff --git a/test/LuaJIT-tests/sysdep/catch_cpp.lua b/test/LuaJIT-tests/lang/catch_cpp.lua
similarity index 77%
rename from test/LuaJIT-tests/sysdep/catch_cpp.lua
rename to test/LuaJIT-tests/lang/catch_cpp.lua
index b2251009..798b926a 100644
--- a/test/LuaJIT-tests/sysdep/catch_cpp.lua
+++ b/test/LuaJIT-tests/lang/catch_cpp.lua
@@ -1,30 +1,30 @@
-
local cp = require("cpptest")
-do
+local unwind
+
+do --- catch, no error
local a, b = pcall(cp.catch, function() return "x" end)
assert(a == true and b == "x")
end
-do
+do --- pcall throw
local a, b = pcall(function() cp.throw("foo") end)
assert(a == false and b == "C++ exception")
end
-local unwind
-do
+do --- catch throw
local a, b = pcall(cp.catch, function() cp.throw("foo") end)
unwind = a
assert((a == false and b == "C++ exception") or (a == true and b == "foo"))
end
-do
+do --- alloc, no error
local st = cp.alloc(function() return cp.isalloc() end)
assert(st == true)
assert(cp.isalloc() == false)
end
-do
+do --- throw in alloc
local a, b = pcall(cp.alloc, function()
assert(cp.isalloc() == true)
return "foo", cp.throw
@@ -33,21 +33,23 @@ do
assert(cp.isalloc() == false)
end
-if unwind then
- local a, b = pcall(cp.alloc, function()
- assert(cp.isalloc() == true)
- return "foo", error
- end)
- assert(a == false and b == "foo")
- assert(cp.isalloc() == false)
+do --- error in alloc
+ if unwind then
+ local a, b = pcall(cp.alloc, function()
+ assert(cp.isalloc() == true)
+ return "foo", error
+ end)
+ assert(a == false and b == "foo")
+ assert(cp.isalloc() == false)
+ end
end
-do
+do --- usereg nop
local a,b,c,d,e,f = cp.usereg(100, 50, function() end, false)
assert(a==164 and b==312 and c==428 and d==3696 and e==404 and f==404)
end
-do
+do --- usereg error
local function test()
cp.usereg(100, 40, error, "foo")
end
@@ -55,7 +57,7 @@ do
assert(a==164 and b==312 and c==428 and d==3696 and e==404 and f==404)
end
-do
+do --- usereg trace with self table lookup
local t = {};
t.t = t;
local function foo()
diff --git a/test/LuaJIT-tests/lang/index b/test/LuaJIT-tests/lang/index
index 87b0c5a0..41f7e7db 100644
--- a/test/LuaJIT-tests/lang/index
+++ b/test/LuaJIT-tests/lang/index
@@ -1,6 +1,7 @@
andor.lua
api_call.lua
assignment.lua
+catch_cpp.lua
catch_wrap.lua
compare.lua
compare_nan.lua
--
2.43.0
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
` (24 preceding siblings ...)
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 25/25] test: enable <catch_cpp.lua> " Sergey Kaplun via Tarantool-patches
@ 2024-01-23 9:01 ` Sergey Bronnikov via Tarantool-patches
25 siblings, 0 replies; 45+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2024-01-23 9:01 UTC (permalink / raw)
To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches
Hi, Sergey!
thanks for the patch-series!
On 1/19/24 14:32, Sergey Kaplun wrote:
> This patchset enables most of the LuaJIT-tests related to FFI and
> testing of C libraries (cpptest, ctest). More tests (from the <misc>
> directory) will be enabled in the future series.
>
> FFI tests from the <unportable> directory aren't enabled because of their
> inconsistency, see also [1].
>
> This increases coverage up to 92.5%, see here [2].
I would highlight the difference - +4%
Good job.
^ permalink raw reply [flat|nested] 45+ messages in thread