[Tarantool-patches] [PATCH v2 luajit 18/26] test: enable <ffi_parse_array.lua> in LuaJIT-tests
Maxim Kokryashkin
m.kokryashkin at tarantool.org
Thu Feb 1 12:01:15 MSK 2024
Hi, Sergey!
Thanks for the patch!
Please consider my comments below.
On Mon, Jan 29, 2024 at 01:45:18PM +0300, Sergey Kaplun wrote:
> This patch changes `dofile()` (which uses an unreliable relative file
> path and mutates `_G` with global functions to be defined) to the
> corresponding `require()` of the helper 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[?]; }",
> -}
I would prefer a more elaborate name here.
> +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]",
> -}
Same here.
> +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
>
More information about the Tarantool-patches
mailing list