diff options
Diffstat (limited to 'testes')
-rw-r--r-- | testes/api.lua | 37 | ||||
-rw-r--r-- | testes/coroutine.lua | 8 |
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 |
468 | end | 468 | end |
469 | 469 | ||
470 | prog[#prog + 1] = "rawgeti R 2" -- get global table in registry | 470 | prog[#prog + 1] = "rawgeti R !G" -- get global table in registry |
471 | prog[#prog + 1] = "insert " .. -(2*lim + 2) | 471 | prog[#prog + 1] = "insert " .. -(2*lim + 2) |
472 | 472 | ||
473 | for i = 1,lim do | 473 | for i = 1,lim do |
@@ -930,28 +930,30 @@ checkerr("FILE%* expected, got userdata", io.input, x) | |||
930 | 930 | ||
931 | assert(debug.getmetatable(x) == nil and debug.getmetatable(y) == nil) | 931 | assert(debug.getmetatable(x) == nil and debug.getmetatable(y) == nil) |
932 | 932 | ||
933 | local d = T.ref(a); | 933 | -- Test references in an arbitrary table |
934 | local e = T.ref(b); | 934 | local reftable = {} |
935 | local f = T.ref(c); | 935 | local d = T.ref(a, reftable); |
936 | t = {T.getref(d), T.getref(e), T.getref(f)} | 936 | local e = T.ref(b, reftable); |
937 | local f = T.ref(c, reftable); | ||
938 | t = {T.getref(d, reftable), T.getref(e, reftable), T.getref(f, reftable)} | ||
937 | assert(t[1] == a and t[2] == b and t[3] == c) | 939 | assert(t[1] == a and t[2] == b and t[3] == c) |
938 | 940 | ||
939 | t=nil; a=nil; c=nil; | 941 | t=nil; a=nil; c=nil; |
940 | T.unref(e); T.unref(f) | 942 | T.unref(e, reftable); T.unref(f, reftable) |
941 | 943 | ||
942 | collectgarbage() | 944 | collectgarbage() |
943 | 945 | ||
944 | -- check that unref objects have been collected | 946 | -- check that unref objects have been collected |
945 | assert(#cl == 1 and cl[1] == nc) | 947 | assert(#cl == 1 and cl[1] == nc) |
946 | 948 | ||
947 | x = T.getref(d) | 949 | x = T.getref(d, reftable) |
948 | assert(type(x) == 'userdata' and debug.getmetatable(x) == tt) | 950 | assert(type(x) == 'userdata' and debug.getmetatable(x) == tt) |
949 | x =nil | 951 | x =nil |
950 | tt.b = b -- create cycle | 952 | tt.b = b -- create cycle |
951 | tt=nil -- frees tt for GC | 953 | tt=nil -- frees tt for GC |
952 | A = nil | 954 | A = nil |
953 | b = nil | 955 | b = nil |
954 | T.unref(d); | 956 | T.unref(d, reftable); |
955 | local n5 = T.newuserdata(0) | 957 | local n5 = T.newuserdata(0) |
956 | debug.setmetatable(n5, {__gc=F}) | 958 | debug.setmetatable(n5, {__gc=F}) |
957 | n5 = T.udataval(n5) | 959 | n5 = T.udataval(n5) |
@@ -960,6 +962,21 @@ assert(#cl == 4) | |||
960 | -- check order of collection | 962 | -- check order of collection |
961 | assert(cl[2] == n5 and cl[3] == nb and cl[4] == na) | 963 | assert(cl[2] == n5 and cl[3] == nb and cl[4] == na) |
962 | 964 | ||
965 | -- reuse a reference in 'reftable' | ||
966 | T.unref(T.ref(23, reftable), reftable) | ||
967 | |||
968 | do -- 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] | ||
977 | end | ||
978 | |||
979 | |||
963 | collectgarbage"restart" | 980 | collectgarbage"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 |
1367 | local mt = T.testC("rawgeti R 1; return 1") | 1384 | local mt = T.testC("rawgeti R !M; return 1") |
1368 | assert(type(mt) == "thread" and coroutine.running() == mt) | 1385 | assert(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 |