forked from lua/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heavy.lua
72 lines (61 loc) · 1.78 KB
/
heavy.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- $Id: heavy.lua,v 1.3 2015/09/08 17:18:18 roberto Exp roberto $
-- See Copyright Notice in file all.lua
print("creating a string too long")
do
local st, msg = pcall(function ()
local a = "x"
while true do
a = a .. a.. a.. a.. a.. a.. a.. a.. a.. a
.. a .. a.. a.. a.. a.. a.. a.. a.. a.. a
.. a .. a.. a.. a.. a.. a.. a.. a.. a.. a
.. a .. a.. a.. a.. a.. a.. a.. a.. a.. a
.. a .. a.. a.. a.. a.. a.. a.. a.. a.. a
.. a .. a.. a.. a.. a.. a.. a.. a.. a.. a
.. a .. a.. a.. a.. a.. a.. a.. a.. a.. a
.. a .. a.. a.. a.. a.. a.. a.. a.. a.. a
.. a .. a.. a.. a.. a.. a.. a.. a.. a.. a
.. a .. a.. a.. a.. a.. a.. a.. a.. a.. a
print(string.format("string with %d bytes", #a))
end
end)
assert(not st and
(string.find(msg, "string length overflow") or
string.find(msg, "not enough memory")))
end
print('+')
local function loadrep (x, what)
local p = 1<<20
local s = string.rep(x, p)
local count = 0
local function f()
count = count + p
if count % (0x80*p) == 0 then
io.stderr:write("(", string.format("0x%x", count), ")")
end
return s
end
local st, msg = load(f, "=big")
print(string.format("\ntotal: 0x%x %s", count, what))
return st, msg
end
print("loading chunk with too many lines")
do
local st, msg = loadrep("\n", "lines")
assert(not st and string.find(msg, "too many lines"))
end
print('+')
print("loading chunk with huge identifier")
do
local st, msg = loadrep("a", "chars")
assert(not st and
(string.find(msg, "lexical element too long") or
string.find(msg, "not enough memory")))
end
print('+')
print("loading chunk with too many instructions")
do
local st, msg = loadrep("a = 10; ", "instructions")
print(st, msg)
end
print('+')
print "OK"