Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Maxim Kokryashkin <m.kokryashkin@tarantool.org>,
	Sergey Bronnikov <sergeyb@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 05/25] test: enable <ffi_call.lua> in LuaJIT-tests
Date: Fri, 19 Jan 2024 14:32:28 +0300	[thread overview]
Message-ID: <6785a95ee05ea262eff6226bc7867c9280ea37ea.1705661401.git.skaplun@tarantool.org> (raw)
In-Reply-To: <cover.1705661401.git.skaplun@tarantool.org>

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


  parent reply	other threads:[~2024-01-19 11:39 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-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
2024-01-23  9:17   ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:35     ` Sergey Kaplun 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
2024-01-23  9:21   ` Sergey Bronnikov via Tarantool-patches
2024-01-23 13:10     ` Sergey Kaplun via Tarantool-patches
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 [this message]
2024-01-23  9:32   ` [Tarantool-patches] [PATCH luajit 05/25] test: enable <ffi_call.lua> " 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
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
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:52       ` Sergey Kaplun via Tarantool-patches
2024-01-23 12:49     ` Sergey Kaplun via Tarantool-patches
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
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 ` [Tarantool-patches] [PATCH luajit 10/25] test: enable <ffi_gcstep_recursive.lua> 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
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
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 ` [Tarantool-patches] [PATCH luajit 14/25] test: enable <ffi_lex_number.lua> " 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
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 ` [Tarantool-patches] [PATCH luajit 17/25] test: enable <ffi_parse_array.lua> " 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
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 ` [Tarantool-patches] [PATCH luajit 20/25] test: enable <ffi_parse_struct.lua> LuaJIT test 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
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 ` [Tarantool-patches] [PATCH luajit 23/25] test: enable <api_call.lua> " 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
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6785a95ee05ea262eff6226bc7867c9280ea37ea.1705661401.git.skaplun@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=m.kokryashkin@tarantool.org \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 05/25] test: enable <ffi_call.lua> in LuaJIT-tests' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox