sl@0
|
1 |
# Tests that the stack size is big enough for the application.
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# This file contains a collection of tests for one or more of the Tcl
|
sl@0
|
4 |
# built-in commands. Sourcing this file into Tcl runs the tests and
|
sl@0
|
5 |
# generates output for errors. No output means no errors were found.
|
sl@0
|
6 |
#
|
sl@0
|
7 |
# Copyright (c) 1998-2000 Ajuba Solutions.
|
sl@0
|
8 |
# Portions Copyright (c) 2007 Nokia Corporation and/or its subsidiaries. All rights reserved.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
11 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# RCS: @(#) $Id: stack.test,v 1.15.2.1 2004/05/03 18:01:36 kennykb Exp $
|
sl@0
|
14 |
|
sl@0
|
15 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
16 |
package require tcltest 2
|
sl@0
|
17 |
namespace import -force ::tcltest::*
|
sl@0
|
18 |
}
|
sl@0
|
19 |
|
sl@0
|
20 |
# Note that a failure in this test results in a crash of the executable.
|
sl@0
|
21 |
# In order to avoid that, we do a basic check of the current stacksize.
|
sl@0
|
22 |
# This size can be changed with ulimit (ksh/bash/sh) or limit (csh/tcsh).
|
sl@0
|
23 |
|
sl@0
|
24 |
# This doesn't catch all cases, for example threads of lower stacksize
|
sl@0
|
25 |
# can still squeak through. A core check is really needed. -- JH
|
sl@0
|
26 |
|
sl@0
|
27 |
if {[string equal $::tcl_platform(platform) "unix"]} {
|
sl@0
|
28 |
if {[string equal $tcl_platform(osSystemName) "Symbian"]} {
|
sl@0
|
29 |
# cannot dynamically set stack size in Symbian, and max stack size is 80K in Symbian
|
sl@0
|
30 |
set stackSize 80
|
sl@0
|
31 |
} else {
|
sl@0
|
32 |
set stackSize [exec /bin/sh -c "ulimit -s"]
|
sl@0
|
33 |
}
|
sl@0
|
34 |
if {[string is integer $stackSize] && ($stackSize < 2400)} {
|
sl@0
|
35 |
puts stderr "WARNING: the default application stacksize of $stackSize\
|
sl@0
|
36 |
may cause Tcl to\ncrash due to stack overflow before the\
|
sl@0
|
37 |
recursion limit is reached.\nA minimum stacksize of 2400\
|
sl@0
|
38 |
kbytes is recommended.\nSkipping infinite recursion test."
|
sl@0
|
39 |
::tcltest::testConstraint minStack2400 0
|
sl@0
|
40 |
} else {
|
sl@0
|
41 |
::tcltest::testConstraint minStack2400 1
|
sl@0
|
42 |
}
|
sl@0
|
43 |
} else {
|
sl@0
|
44 |
::tcltest::testConstraint minStack2400 1
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
test stack-1.1 {maxNestingDepth reached on infinite recursion} {minStack2400} {
|
sl@0
|
48 |
proc recurse {} { return [recurse] }
|
sl@0
|
49 |
catch {recurse} rv
|
sl@0
|
50 |
rename recurse {}
|
sl@0
|
51 |
set rv
|
sl@0
|
52 |
} {too many nested evaluations (infinite loop?)}
|
sl@0
|
53 |
|
sl@0
|
54 |
test stack-2.1 {maxNestingDepth reached on infinite recursion} {minStack2400} {
|
sl@0
|
55 |
# do this in a slave to not mess with parent
|
sl@0
|
56 |
set slave stack-2.1
|
sl@0
|
57 |
interp create $slave
|
sl@0
|
58 |
$slave eval { interp alias {} unknown {} notaknownproc }
|
sl@0
|
59 |
set msg [$slave eval { catch {foo} msg ; set msg }]
|
sl@0
|
60 |
interp delete $slave
|
sl@0
|
61 |
set msg
|
sl@0
|
62 |
} {too many nested evaluations (infinite loop?)}
|
sl@0
|
63 |
|
sl@0
|
64 |
# Make sure that there is enough stack to run regexp even if we're
|
sl@0
|
65 |
# close to the recursion limit. [Bug 947070]
|
sl@0
|
66 |
|
sl@0
|
67 |
test stack-3.1 {enough room for regexp near recursion limit} \
|
sl@0
|
68 |
-constraints { win } \
|
sl@0
|
69 |
-setup {
|
sl@0
|
70 |
set ::limit [interp recursionlimit {} 10000]
|
sl@0
|
71 |
set ::depth 0
|
sl@0
|
72 |
proc a { max } {
|
sl@0
|
73 |
if { [info level] < $max } {
|
sl@0
|
74 |
set ::depth [info level]
|
sl@0
|
75 |
a $max
|
sl@0
|
76 |
} else {
|
sl@0
|
77 |
regexp {^ ?} x
|
sl@0
|
78 |
}
|
sl@0
|
79 |
}
|
sl@0
|
80 |
list [catch { a 10001 }]
|
sl@0
|
81 |
incr depth -3
|
sl@0
|
82 |
set depth2 $depth
|
sl@0
|
83 |
} -body {
|
sl@0
|
84 |
list [catch { a $::depth } result] \
|
sl@0
|
85 |
$result [expr { $::depth2 - $::depth }]
|
sl@0
|
86 |
} -cleanup {
|
sl@0
|
87 |
interp recursionlimit {} $::limit
|
sl@0
|
88 |
} -result {0 1 1}
|
sl@0
|
89 |
|
sl@0
|
90 |
# cleanup
|
sl@0
|
91 |
::tcltest::cleanupTests
|
sl@0
|
92 |
return
|
sl@0
|
93 |
|
sl@0
|
94 |
# Local Variables:
|
sl@0
|
95 |
# mode: tcl
|
sl@0
|
96 |
# End:
|