os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/stack.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/stack.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,96 @@
     1.4 +# Tests that the stack size is big enough for the application.
     1.5 +#
     1.6 +# This file contains a collection of tests for one or more of the Tcl
     1.7 +# built-in commands.  Sourcing this file into Tcl runs the tests and
     1.8 +# generates output for errors.  No output means no errors were found.
     1.9 +#
    1.10 +# Copyright (c) 1998-2000 Ajuba Solutions.
    1.11 +# Portions Copyright (c) 2007 Nokia Corporation and/or its subsidiaries. All rights reserved. 
    1.12 +#
    1.13 +# See the file "license.terms" for information on usage and redistribution
    1.14 +# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    1.15 +#
    1.16 +# RCS: @(#) $Id: stack.test,v 1.15.2.1 2004/05/03 18:01:36 kennykb Exp $
    1.17 +
    1.18 +if {[lsearch [namespace children] ::tcltest] == -1} {
    1.19 +    package require tcltest 2
    1.20 +    namespace import -force ::tcltest::*
    1.21 +}
    1.22 +
    1.23 +# Note that a failure in this test results in a crash of the executable.
    1.24 +# In order to avoid that, we do a basic check of the current stacksize.
    1.25 +# This size can be changed with ulimit (ksh/bash/sh) or limit (csh/tcsh).
    1.26 +
    1.27 +# This doesn't catch all cases, for example threads of lower stacksize
    1.28 +# can still squeak through.  A core check is really needed. -- JH
    1.29 +
    1.30 +if {[string equal $::tcl_platform(platform) "unix"]} {
    1.31 +    if {[string equal $tcl_platform(osSystemName) "Symbian"]} {
    1.32 +    # cannot dynamically set stack size in Symbian, and max stack size is 80K in Symbian
    1.33 +    set stackSize 80
    1.34 +    } else {
    1.35 +    set stackSize [exec /bin/sh -c "ulimit -s"] 
    1.36 +    }
    1.37 +    if {[string is integer $stackSize] && ($stackSize < 2400)} {
    1.38 +        puts stderr "WARNING: the default application stacksize of $stackSize\
    1.39 +                may cause Tcl to\ncrash due to stack overflow before the\
    1.40 +                recursion limit is reached.\nA minimum stacksize of 2400\
    1.41 +                kbytes is recommended.\nSkipping infinite recursion test."
    1.42 +        ::tcltest::testConstraint minStack2400 0
    1.43 +    } else {
    1.44 +        ::tcltest::testConstraint minStack2400 1
    1.45 +    }
    1.46 +} else {
    1.47 +    ::tcltest::testConstraint minStack2400 1
    1.48 +}
    1.49 +
    1.50 +test stack-1.1 {maxNestingDepth reached on infinite recursion} {minStack2400} {
    1.51 +    proc recurse {} { return [recurse] }
    1.52 +    catch {recurse} rv
    1.53 +    rename recurse {}
    1.54 +    set rv
    1.55 +} {too many nested evaluations (infinite loop?)}
    1.56 +
    1.57 +test stack-2.1 {maxNestingDepth reached on infinite recursion} {minStack2400} {
    1.58 +    # do this in a slave to not mess with parent
    1.59 +    set slave stack-2.1
    1.60 +    interp create $slave
    1.61 +    $slave eval { interp alias {} unknown {} notaknownproc }
    1.62 +    set msg [$slave eval { catch {foo} msg ; set msg }]
    1.63 +    interp delete $slave
    1.64 +    set msg
    1.65 +} {too many nested evaluations (infinite loop?)}
    1.66 +
    1.67 +# Make sure that there is enough stack to run regexp even if we're
    1.68 +# close to the recursion limit. [Bug 947070]
    1.69 +
    1.70 +test stack-3.1 {enough room for regexp near recursion limit} \
    1.71 +    -constraints { win } \
    1.72 +    -setup {
    1.73 +	set ::limit [interp recursionlimit {} 10000]
    1.74 +	set ::depth 0
    1.75 +	proc a { max } {
    1.76 +	    if { [info level] < $max } {
    1.77 +		set ::depth [info level]
    1.78 +		a $max
    1.79 +	    } else {
    1.80 +		regexp {^ ?} x
    1.81 +	    }
    1.82 +	}
    1.83 +	list [catch { a 10001 }]
    1.84 +	incr depth -3
    1.85 +	set depth2 $depth
    1.86 +    } -body {
    1.87 +	list [catch { a $::depth } result] \
    1.88 +	    $result [expr { $::depth2 - $::depth }]
    1.89 +    } -cleanup {
    1.90 +	interp recursionlimit {} $::limit
    1.91 +    } -result {0 1 1}
    1.92 +
    1.93 +# cleanup
    1.94 +::tcltest::cleanupTests
    1.95 +return
    1.96 +
    1.97 +# Local Variables:
    1.98 +# mode: tcl
    1.99 +# End: