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