diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-12-30 11:45:08 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-12-30 11:45:08 -0300 |
| commit | bd1b87c5790c0c6fe23f76aa360e879922e1e738 (patch) | |
| tree | 49978c2dd847c7ff4ec84e1a153ca37deef79e2a /testes/cstack.lua | |
| parent | d7bb8df8414f71a290c8a4b1c9f7c6fe839a94df (diff) | |
| download | lua-bd1b87c5790c0c6fe23f76aa360e879922e1e738.tar.gz lua-bd1b87c5790c0c6fe23f76aa360e879922e1e738.tar.bz2 lua-bd1b87c5790c0c6fe23f76aa360e879922e1e738.zip | |
Comments (mosty typos)
Diffstat (limited to '')
| -rw-r--r-- | testes/cstack.lua | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/testes/cstack.lua b/testes/cstack.lua index 486abc1d..cd74fd28 100644 --- a/testes/cstack.lua +++ b/testes/cstack.lua | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | local debug = require "debug" | 4 | local debug = require "debug" |
| 5 | 5 | ||
| 6 | print"testing C-stack overflow detection" | 6 | print"testing C-stack overflow detection" |
| 7 | print"If this test craches, see its file ('cstack.lua')" | 7 | print"If this test crashes, see its file ('cstack.lua')" |
| 8 | 8 | ||
| 9 | -- Segmentation faults in these tests probably result from a C-stack | 9 | -- Segmentation faults in these tests probably result from a C-stack |
| 10 | -- overflow. To avoid these errors, you can use the function | 10 | -- overflow. To avoid these errors, you can use the function |
| @@ -19,10 +19,13 @@ print"If this test craches, see its file ('cstack.lua')" | |||
| 19 | -- higher than 2_000. | 19 | -- higher than 2_000. |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | -- get and print original limit | ||
| 22 | local origlimit = debug.setcstacklimit(400) | 23 | local origlimit = debug.setcstacklimit(400) |
| 23 | print("default stack limit: " .. origlimit) | 24 | print("default stack limit: " .. origlimit) |
| 24 | 25 | ||
| 25 | -- change this value for different limits for this test suite | 26 | -- Do the tests using the original limit. Or else you may want to change |
| 27 | -- 'currentlimit' to lower values to avoid a seg. fault or to higher | ||
| 28 | -- values to check whether they are reliable. | ||
| 26 | local currentlimit = origlimit | 29 | local currentlimit = origlimit |
| 27 | debug.setcstacklimit(currentlimit) | 30 | debug.setcstacklimit(currentlimit) |
| 28 | print("current stack limit: " .. currentlimit) | 31 | print("current stack limit: " .. currentlimit) |
| @@ -33,12 +36,14 @@ local function checkerror (msg, f, ...) | |||
| 33 | assert(not s and string.find(err, msg)) | 36 | assert(not s and string.find(err, msg)) |
| 34 | end | 37 | end |
| 35 | 38 | ||
| 39 | -- auxiliary function to keep 'count' on the screen even if the program | ||
| 40 | -- crashes. | ||
| 36 | local count | 41 | local count |
| 37 | local back = string.rep("\b", 8) | 42 | local back = string.rep("\b", 8) |
| 38 | local function progress () | 43 | local function progress () |
| 39 | count = count + 1 | 44 | count = count + 1 |
| 40 | local n = string.format("%-8d", count) | 45 | local n = string.format("%-8d", count) |
| 41 | io.stderr:write(back, n) | 46 | io.stderr:write(back, n) -- erase previous value and write new one |
| 42 | end | 47 | end |
| 43 | 48 | ||
| 44 | 49 | ||
| @@ -46,7 +51,7 @@ do print("testing simple recursion:") | |||
| 46 | count = 0 | 51 | count = 0 |
| 47 | local function foo () | 52 | local function foo () |
| 48 | progress() | 53 | progress() |
| 49 | foo() | 54 | foo() -- do recursive calls until a stack error (or crash) |
| 50 | end | 55 | end |
| 51 | checkerror("stack overflow", foo) | 56 | checkerror("stack overflow", foo) |
| 52 | print("\tfinal count: ", count) | 57 | print("\tfinal count: ", count) |
| @@ -118,9 +123,11 @@ do print("testing changes in C-stack limit") | |||
| 118 | return n | 123 | return n |
| 119 | end | 124 | end |
| 120 | 125 | ||
| 126 | -- set limit to 400 | ||
| 121 | assert(debug.setcstacklimit(400) == currentlimit) | 127 | assert(debug.setcstacklimit(400) == currentlimit) |
| 122 | local lim400 = check() | 128 | local lim400 = check() |
| 123 | -- a very low limit (given that the several calls to arive here) | 129 | -- set a very low limit (given that there are already several active |
| 130 | -- calls to arrive here) | ||
| 124 | local lowlimit = 38 | 131 | local lowlimit = 38 |
| 125 | assert(debug.setcstacklimit(lowlimit) == 400) | 132 | assert(debug.setcstacklimit(lowlimit) == 400) |
| 126 | assert(check() < lowlimit - 30) | 133 | assert(check() < lowlimit - 30) |
