aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/api.lua37
-rw-r--r--testes/coroutine.lua8
2 files changed, 31 insertions, 14 deletions
diff --git a/testes/api.lua b/testes/api.lua
index 85dadb69..ca4b3fb4 100644
--- a/testes/api.lua
+++ b/testes/api.lua
@@ -467,7 +467,7 @@ for i = 1,lim do
467 prog[#prog + 1] = "pushnum " .. i * 10 467 prog[#prog + 1] = "pushnum " .. i * 10
468end 468end
469 469
470prog[#prog + 1] = "rawgeti R 2" -- get global table in registry 470prog[#prog + 1] = "rawgeti R !G" -- get global table in registry
471prog[#prog + 1] = "insert " .. -(2*lim + 2) 471prog[#prog + 1] = "insert " .. -(2*lim + 2)
472 472
473for i = 1,lim do 473for i = 1,lim do
@@ -930,28 +930,30 @@ checkerr("FILE%* expected, got userdata", io.input, x)
930 930
931assert(debug.getmetatable(x) == nil and debug.getmetatable(y) == nil) 931assert(debug.getmetatable(x) == nil and debug.getmetatable(y) == nil)
932 932
933local d = T.ref(a); 933-- Test references in an arbitrary table
934local e = T.ref(b); 934local reftable = {}
935local f = T.ref(c); 935local d = T.ref(a, reftable);
936t = {T.getref(d), T.getref(e), T.getref(f)} 936local e = T.ref(b, reftable);
937local f = T.ref(c, reftable);
938t = {T.getref(d, reftable), T.getref(e, reftable), T.getref(f, reftable)}
937assert(t[1] == a and t[2] == b and t[3] == c) 939assert(t[1] == a and t[2] == b and t[3] == c)
938 940
939t=nil; a=nil; c=nil; 941t=nil; a=nil; c=nil;
940T.unref(e); T.unref(f) 942T.unref(e, reftable); T.unref(f, reftable)
941 943
942collectgarbage() 944collectgarbage()
943 945
944-- check that unref objects have been collected 946-- check that unref objects have been collected
945assert(#cl == 1 and cl[1] == nc) 947assert(#cl == 1 and cl[1] == nc)
946 948
947x = T.getref(d) 949x = T.getref(d, reftable)
948assert(type(x) == 'userdata' and debug.getmetatable(x) == tt) 950assert(type(x) == 'userdata' and debug.getmetatable(x) == tt)
949x =nil 951x =nil
950tt.b = b -- create cycle 952tt.b = b -- create cycle
951tt=nil -- frees tt for GC 953tt=nil -- frees tt for GC
952A = nil 954A = nil
953b = nil 955b = nil
954T.unref(d); 956T.unref(d, reftable);
955local n5 = T.newuserdata(0) 957local n5 = T.newuserdata(0)
956debug.setmetatable(n5, {__gc=F}) 958debug.setmetatable(n5, {__gc=F})
957n5 = T.udataval(n5) 959n5 = T.udataval(n5)
@@ -960,6 +962,21 @@ assert(#cl == 4)
960-- check order of collection 962-- check order of collection
961assert(cl[2] == n5 and cl[3] == nb and cl[4] == na) 963assert(cl[2] == n5 and cl[3] == nb and cl[4] == na)
962 964
965-- reuse a reference in 'reftable'
966T.unref(T.ref(23, reftable), reftable)
967
968do -- check reftable
969 local count = 0
970 local i = 1
971 while reftable[i] ~= 0 do
972 i = reftable[i] -- traverse linked list of free references
973 count = count + 1
974 end
975 -- maximum number of simultaneously locked objects was 3
976 assert(count == 3 and #reftable == 3 + 1) -- +1 for reserved [1]
977end
978
979
963collectgarbage"restart" 980collectgarbage"restart"
964 981
965 982
@@ -1363,8 +1380,8 @@ end)
1363 1380
1364-- testing threads 1381-- testing threads
1365 1382
1366-- get main thread from registry (at index LUA_RIDX_MAINTHREAD == 1) 1383-- get main thread from registry
1367local mt = T.testC("rawgeti R 1; return 1") 1384local mt = T.testC("rawgeti R !M; return 1")
1368assert(type(mt) == "thread" and coroutine.running() == mt) 1385assert(type(mt) == "thread" and coroutine.running() == mt)
1369 1386
1370 1387
diff --git a/testes/coroutine.lua b/testes/coroutine.lua
index 990da8c4..6c15db03 100644
--- a/testes/coroutine.lua
+++ b/testes/coroutine.lua
@@ -681,7 +681,7 @@ else
681 c == "ERRRUN" and d == 4) 681 c == "ERRRUN" and d == 4)
682 682
683 a, b, c, d = T.testC([[ 683 a, b, c, d = T.testC([[
684 rawgeti R 1 # get main thread 684 rawgeti R !M # get main thread
685 pushnum 10; 685 pushnum 10;
686 pushnum 20; 686 pushnum 20;
687 resume -3 2; 687 resume -3 2;
@@ -699,7 +699,7 @@ else
699 assert(T.testC(state, "newthread; isyieldable -1; remove 1; return 1")) 699 assert(T.testC(state, "newthread; isyieldable -1; remove 1; return 1"))
700 700
701 -- main thread is not yieldable 701 -- main thread is not yieldable
702 assert(not T.testC(state, "rawgeti R 1; isyieldable -1; remove 1; return 1")) 702 assert(not T.testC(state, "rawgeti R !M; isyieldable -1; remove 1; return 1"))
703 703
704 T.testC(state, "settop 0") 704 T.testC(state, "settop 0")
705 705
@@ -711,7 +711,7 @@ else
711 return 'ok']])) 711 return 'ok']]))
712 712
713 local t = table.pack(T.testC(state, [[ 713 local t = table.pack(T.testC(state, [[
714 rawgeti R 1 # get main thread 714 rawgeti R !M # get main thread
715 pushstring 'XX' 715 pushstring 'XX'
716 getglobal X # get function for body 716 getglobal X # get function for body
717 pushstring AA # arg 717 pushstring AA # arg
@@ -720,7 +720,7 @@ else
720 setglobal T # top 720 setglobal T # top
721 setglobal B # second yielded value 721 setglobal B # second yielded value
722 setglobal A # fist yielded value 722 setglobal A # fist yielded value
723 rawgeti R 1 # get main thread 723 rawgeti R !M # get main thread
724 pushnum 5 # arg (noise) 724 pushnum 5 # arg (noise)
725 resume 1 1 # after coroutine ends, previous stack is back 725 resume 1 1 # after coroutine ends, previous stack is back
726 pushstatus 726 pushstatus