Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for fixed parsing of goto. #13

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ be run with any other Lua 5.1 or 5.2 interpreter.

## Running the test suite ##

To run the default test suite, run `test.lua` using the Lua interpreter you
wish to test, for example:
To run the default test suite, run `build.sh` (\*nix) or `build.bat` (Windows,
run from a Visual Studio command prompt) with the directory containing the
include directories of the Lua interpreter to be tested. Then run `test.lua`
using the Lua interpreter you wish to test, for example:

$ ./build.sh ~/luajit-2.0/src
$ ~/luajit-2.0/src/luajit test.lua

You don't need to rerun `build.sh` or `build.bat` unless you change one of the
C or C++ source files in `src/`.

If the test suite passes, the final line printed to stdout will be
`NNN passed`, and the exit code of the process will be zero. If any tests
fail, the exit code will be non-zero. If the failures caused catastrophic
Expand Down
12 changes: 7 additions & 5 deletions test/common/ffi_util.inc → test/common/ffi_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

local ffi = require("ffi")

function checkfail(t, f)
local ffi_util = {}
function ffi_util.checkfail(t, f)
f = f or ffi.typeof
for i=1,1e9 do
local tp = t[i]
Expand All @@ -13,8 +14,8 @@ function checkfail(t, f)
end
end

function checktypes(t)
for i=1,1e9,3 do
function ffi_util.checktypes(t)
for i=1,#t,3 do
local tp = t[i+2]
if not tp then break end
local id = ffi.typeof(tp)
Expand All @@ -23,14 +24,14 @@ function checktypes(t)
end
end

function fails(f, ...)
function ffi_util.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 ""

function include(name)
function ffi_util.include(name)
local flags = ffi.abi("32bit") and "-m32" or "-m64"
if string.sub(name, 1, 1) ~= "/" then name = incroot.."/"..name end
local fp = assert(io.popen("cc -E -P "..flags.." "..cdefs.." "..name))
Expand All @@ -39,3 +40,4 @@ function include(name)
ffi.cdef(s)
end

return ffi_util
1 change: 1 addition & 0 deletions test/index
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ bc +luajit>=2
computations.lua
trace +jit
opt +jit
misc
1 change: 1 addition & 0 deletions test/lang/goto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ do --- Basic goto and label semantics.
expect("goto a; do ::a:: end", "'a'")
expect("break", "break")
expect("if x then break end", "break")
expect("repeat goto a break until true", "undefined label 'a'")

-- Error: goto into variable scope.
expect("goto a; local x; ::a:: local y", "'x'")
Expand Down
1 change: 0 additions & 1 deletion test/lang/meta/len.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local compat52 = table.pack
local mt = { __len = function(o, o2)
if compat52 then
assert(o2 == o)
Expand Down
22 changes: 10 additions & 12 deletions test/lib/contents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ local function check(m, expected, exclude)
end

do --- base
check(_G, "_G:_VERSION:arg:assert:collectgarbage:coroutine:debug:dofile:error:getmetatable:io:ipairs:load:loadfile:math:next:os:package:pairs:pcall:print:rawequal:rawget:rawset:require:select:setmetatable:string:table:tonumber:tostring:type:xpcall", "rawlen:bit:bit32:jit:gcinfo:setfenv:getfenv:loadstring:unpack:module:newproxy")
check(_G, "_G:_VERSION:arg:assert:collectgarbage:compat52" ..
":coroutine:cpptest:ctest:" ..
"debug:dofile:error:getmetatable:io:ipairs:load:loadfile:" ..
"math:next:os:package:pairs:pcall:print:rawequal:rawget:rawset:" ..
"require:select:setmetatable:string:table:tonumber:tostring:type:xpcall",
"rawlen:bit:bit32:jit:gcinfo:setfenv:getfenv:loadstring:unpack:module:newproxy")
end

do --- pre-5.2 base +lua<5.2
Expand Down Expand Up @@ -54,8 +59,7 @@ do --- math
check(math, "abs:acos:asin:atan:atan2:ceil:cos:cosh:deg:exp:floor:fmod:frexp:huge:ldexp:log:max:min:modf:pi:pow:rad:random:randomseed:sin:sinh:sqrt:tan:tanh", "log10:mod")
end

do --- pre-5.2 math +lua<5.2 -compat5.2
assert(math.mod)
do --- pre-5.2 math +lua<5.1 -compat5.2
assert(math.log10)
end

Expand All @@ -66,18 +70,11 @@ end

do --- string
check(string, "byte:char:dump:find:format:gmatch:gsub:len:lower:match:rep:reverse:sub:upper", "gfind")
end

do --- pre-5.2 string +lua<5.2 -compat5.2
assert(string.gfind)
end

do --- 5.2 string +lua>=5.2
assert(not string.gfind)
end

do --- pre-5.2 table +lua<5.2
check(table, "concat:foreach:foreachi:getn:insert:maxn:remove:sort", "pack:unpack:setn:new")
check(table, "concat:foreach:foreachi:getn:insert:maxn:move:remove:sort", "pack:unpack:setn:new")
end

do --- 5.2 table +lua>=5.2
Expand Down Expand Up @@ -139,7 +136,8 @@ do --- package.loaded
loaded[k] = v
end
end
check(loaded, "_G:coroutine:debug:io:math:os:package:string:table", "bit:bit32:common:ffi:jit:table.new")
check(loaded, "_G:coroutine:cpptest:ctest:debug:io:math:os:package:string:table",
"bit:bit32:common:ffi:jit:table.new")
end

do --- bit +bit
Expand Down
4 changes: 2 additions & 2 deletions test/lib/ffi/bit64.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local shl, shr, sar = bit.lshift, bit.rshift, bit.arshift
local rol, ror = bit.rol, bit.ror

ffi.cdef[[
typedef enum { ZZI = -1 } ienum_t;
typedef enum { ZZI = -1 } ienum_t_;
typedef enum { ZZU } uenum_t;
]]

Expand All @@ -32,7 +32,7 @@ do --- smoke tohex
end

do --- tobit/band assorted C types
for _,tp in ipairs{"int", "ienum_t", "uenum_t", "int64_t", "uint64_t"} do
for _,tp in ipairs{"int", "ienum_t_", "uenum_t", "int64_t", "uint64_t"} do
local x = ffi.new(tp, 10)
local y = tobit(x)
local z = band(x)
Expand Down
15 changes: 8 additions & 7 deletions test/lib/ffi/ffi_arith_ptr.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local ffi = require("ffi")

dofile("../common/ffi_util.inc")
local ffi_util = require("common.ffi_util")
local fails = ffi_util.fails

ffi.cdef[[
typedef struct { int a,b,c; } foo1_t;
Expand All @@ -9,7 +10,7 @@ void *malloc(size_t);
struct incomplete;
]]

do
do --- FFI basic pointer and array operations
local a = ffi.new("int[10]")
local p1 = a+0
p1[0] = 1;
Expand Down Expand Up @@ -61,7 +62,7 @@ do
assert(b - a == 5)
end

do
do --- Null pointers (and only null pointers) act like nil.
local p1 = ffi.cast("void *", 0)
local p2 = ffi.cast("int *", 1)
assert(p1 == p1)
Expand All @@ -71,7 +72,7 @@ do
assert(p2 ~= nil)
end

do
do --- Function pointers are not nil, but do not support arithmetic.
local f1 = ffi.C.free
local f2 = ffi.C.malloc
local p1 = ffi.cast("void *", f1)
Expand All @@ -84,7 +85,7 @@ do
fails(function(f1) return f1 + 1 end, f1)
end

do
do --- FFI arrays
local s = ffi.new("foo1_t[10]")
local p1 = s+3
p1.a = 1; p1.b = 2; p1.c = 3
Expand All @@ -96,10 +97,10 @@ do
assert(p1 - p2 == -3)
end

do
do --- Cannot perform arithmetic on pointer to incomplete type
local mem = ffi.new("int[1]")
local p = ffi.cast("struct incomplete *", mem)
fails(function(p) return p+1 end, p)
ffi_util.fails(function(p) return p+1 end, p)
local ok, err = pcall(function(p) return p[1] end, p)
assert(not ok and err:match("size.*unknown"))
end
Expand Down
38 changes: 23 additions & 15 deletions test/lib/ffi/ffi_bitfield.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
local ffi = require("ffi")
local x = ffi.new([[
union {
uint32_t u;
struct { int a:10,b:10,c:11,d:1; };
struct { unsigned int e:10,f:10,g:11,h:1; };
struct { int8_t i:4,j:5,k:5,l:3; };
struct { _Bool b0:1,b1:1,b2:1,b3:1; };
}
]])

dofile("../common/ffi_util.inc")

do
local x = ffi.new([[
union {
uint32_t u;
struct { int a:10,b:10,c:11,d:1; };
struct { unsigned int e:10,f:10,g:11,h:1; };
struct { int8_t i:4,j:5,k:5,l:3; };
struct { _Bool b0:1,b1:1,b2:1,b3:1; };
}
]])

-- bitfield access
do --- Bitfield acess
x.u = 0xffffffff
assert(x.a == -1 and x.b == -1 and x.c == -1 and x.d == -1)
assert(x.e == 1023 and x.f == 1023 and x.g == 2047 and x.h == 1)
Expand Down Expand Up @@ -43,8 +40,9 @@ do
assert(x.i == -2 and x.j == -6 and x.k == 1 and x.l == -2)
assert(x.b0 == true and x.b1 == true and x.b2 == true and x.b3 == false)
end
end

-- bitfield insert
do --- bitfield insert
x.u = 0xffffffff
x.a = 0
if ffi.abi("le") then
Expand Down Expand Up @@ -73,8 +71,9 @@ do
else
assert(x.u == 0x003ff000)
end
end

-- cumulative bitfield insert
do --- cumulative bitfield insert
x.u = 0xffffffff
if ffi.abi("le") then
x.a = -392; x.b = 277; x.c = 291; x.d = 0
Expand Down Expand Up @@ -106,3 +105,12 @@ do

end

do --- bitfield JIT compilation
local bf = ffi.new'struct { int x : 2; int y : 30; }'
bf.x = 1
bf.y = 20
for i = 1, 100 do
assert(bf.x == 1)
assert(bf.y == 20)
end
end
Loading