heavy.lua 1.8 KB

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