[Tarantool-patches] [PATCH luajit 19/25] test: enable <ffi_parse_cdef.lua> in LuaJIT-tests
Sergey Kaplun
skaplun at tarantool.org
Fri Jan 19 14:32:42 MSK 2024
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
More information about the Tarantool-patches
mailing list