diff options
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/cstack.lua | 48 | ||||
| -rw-r--r-- | testes/errors.lua | 16 |
2 files changed, 58 insertions, 6 deletions
diff --git a/testes/cstack.lua b/testes/cstack.lua index 3cb1e4ce..c7aa740f 100644 --- a/testes/cstack.lua +++ b/testes/cstack.lua | |||
| @@ -1,8 +1,14 @@ | |||
| 1 | -- $Id: testes/cstack.lua $ | 1 | -- $Id: testes/cstack.lua $ |
| 2 | -- See Copyright Notice in file all.lua | 2 | -- See Copyright Notice in file all.lua |
| 3 | 3 | ||
| 4 | local debug = require "debug" | ||
| 5 | |||
| 4 | print"testing C-stack overflow detection" | 6 | print"testing C-stack overflow detection" |
| 5 | 7 | ||
| 8 | local origlimit = debug.setCstacklimit(400) | ||
| 9 | print("current stack limit: " .. origlimit) | ||
| 10 | debug.setCstacklimit(origlimit) | ||
| 11 | |||
| 6 | -- Segmentation faults in these tests probably result from a C-stack | 12 | -- Segmentation faults in these tests probably result from a C-stack |
| 7 | -- overflow. To avoid these errors, recompile Lua with a smaller | 13 | -- overflow. To avoid these errors, recompile Lua with a smaller |
| 8 | -- value for the constant 'LUAI_MAXCCALLS' or else ensure a larger | 14 | -- value for the constant 'LUAI_MAXCCALLS' or else ensure a larger |
| @@ -79,4 +85,46 @@ do print("testing stack-overflow in recursive 'gsub'") | |||
| 79 | print("\tfinal count: ", count) | 85 | print("\tfinal count: ", count) |
| 80 | end | 86 | end |
| 81 | 87 | ||
| 88 | |||
| 89 | do print("testing changes in C-stack limit") | ||
| 90 | |||
| 91 | assert(not debug.setCstacklimit(0)) -- limit too small | ||
| 92 | assert(not debug.setCstacklimit(50000)) -- limit too large | ||
| 93 | local co = coroutine.wrap (function () | ||
| 94 | return debug.setCstacklimit(400) | ||
| 95 | end) | ||
| 96 | assert(co() == false) -- cannot change C stack inside coroutine | ||
| 97 | |||
| 98 | local n | ||
| 99 | local function foo () n = n + 1; foo () end | ||
| 100 | |||
| 101 | local function check () | ||
| 102 | n = 0 | ||
| 103 | pcall(foo) | ||
| 104 | return n | ||
| 105 | end | ||
| 106 | |||
| 107 | assert(debug.setCstacklimit(400) == origlimit) | ||
| 108 | local lim400 = check() | ||
| 109 | -- a very low limit (given that the several calls to arive here) | ||
| 110 | local lowlimit = 38 | ||
| 111 | assert(debug.setCstacklimit(lowlimit) == 400) | ||
| 112 | assert(check() < lowlimit - 30) | ||
| 113 | assert(debug.setCstacklimit(600) == lowlimit) | ||
| 114 | local lim600 = check() | ||
| 115 | assert(lim600 == lim400 + 200) | ||
| 116 | |||
| 117 | |||
| 118 | -- 'setCstacklimit' works inside protected calls. (The new stack | ||
| 119 | -- limit is kept when 'pcall' returns.) | ||
| 120 | assert(pcall(function () | ||
| 121 | assert(debug.setCstacklimit(400) == 600) | ||
| 122 | assert(check() <= lim400) | ||
| 123 | end)) | ||
| 124 | |||
| 125 | assert(check() == lim400) | ||
| 126 | assert(debug.setCstacklimit(origlimit) == 400) -- restore original limit | ||
| 127 | end | ||
| 128 | |||
| 129 | |||
| 82 | print'OK' | 130 | print'OK' |
diff --git a/testes/errors.lua b/testes/errors.lua index 0b12410e..6e7b8004 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
| @@ -523,9 +523,13 @@ end | |||
| 523 | 523 | ||
| 524 | -- testing syntax limits | 524 | -- testing syntax limits |
| 525 | 525 | ||
| 526 | local function testrep (init, rep, close, repc) | 526 | local function testrep (init, rep, close, repc, finalresult) |
| 527 | local s = init .. string.rep(rep, 100) .. close .. string.rep(repc, 100) | 527 | local s = init .. string.rep(rep, 100) .. close .. string.rep(repc, 100) |
| 528 | assert(load(s)) -- 100 levels is OK | 528 | local res, msg = load(s) |
| 529 | assert(res) -- 100 levels is OK | ||
| 530 | if (finalresult) then | ||
| 531 | assert(res() == finalresult) | ||
| 532 | end | ||
| 529 | s = init .. string.rep(rep, 10000) | 533 | s = init .. string.rep(rep, 10000) |
| 530 | local res, msg = load(s) -- 10000 levels not ok | 534 | local res, msg = load(s) -- 10000 levels not ok |
| 531 | assert(not res and (string.find(msg, "too many registers") or | 535 | assert(not res and (string.find(msg, "too many registers") or |
| @@ -534,14 +538,14 @@ end | |||
| 534 | 538 | ||
| 535 | testrep("local a; a", ",a", "= 1", ",1") -- multiple assignment | 539 | testrep("local a; a", ",a", "= 1", ",1") -- multiple assignment |
| 536 | testrep("local a; a=", "{", "0", "}") | 540 | testrep("local a; a=", "{", "0", "}") |
| 537 | testrep("local a; a=", "(", "2", ")") | 541 | testrep("return ", "(", "2", ")", 2) |
| 538 | testrep("local a; ", "a(", "2", ")") | 542 | testrep("local function a (x) return x end; return ", "a(", "2.2", ")", 2.2) |
| 539 | testrep("", "do ", "", " end") | 543 | testrep("", "do ", "", " end") |
| 540 | testrep("", "while a do ", "", " end") | 544 | testrep("", "while a do ", "", " end") |
| 541 | testrep("local a; ", "if a then else ", "", " end") | 545 | testrep("local a; ", "if a then else ", "", " end") |
| 542 | testrep("", "function foo () ", "", " end") | 546 | testrep("", "function foo () ", "", " end") |
| 543 | testrep("local a; a=", "a..", "a", "") | 547 | testrep("local a = ''; return ", "a..", "'a'", "", "a") |
| 544 | testrep("local a; a=", "a^", "a", "") | 548 | testrep("local a = 1; return ", "a^", "a", "", 1) |
| 545 | 549 | ||
| 546 | checkmessage("a = f(x" .. string.rep(",x", 260) .. ")", "too many registers") | 550 | checkmessage("a = f(x" .. string.rep(",x", 260) .. ")", "too many registers") |
| 547 | 551 | ||
