| 1 | #!/usr/bin/env bash
 | 
| 2 | #
 | 
| 3 | # Potentially Long-running stress tests
 | 
| 4 | #
 | 
| 5 | # Usage:
 | 
| 6 | #   test/stress.sh <function name>
 | 
| 7 | 
 | 
| 8 | set -o nounset
 | 
| 9 | set -o pipefail
 | 
| 10 | set -o errexit
 | 
| 11 | 
 | 
| 12 | # GC bug?
 | 
| 13 | 
 | 
| 14 | replace-ysh() {
 | 
| 15 |   #local ysh=_bin/cxx-opt/ysh
 | 
| 16 |   local ysh=_bin/cxx-dbg/ysh
 | 
| 17 |   #local ysh=_bin/cxx-asan/ysh
 | 
| 18 |   ninja $ysh
 | 
| 19 | 
 | 
| 20 |   # gc_mylib.cc sets threshold to 50K
 | 
| 21 |   # it doesn't seem to matter!
 | 
| 22 |   #
 | 
| 23 |   # Oh does this have to do with recursively calling back into the interpreter?
 | 
| 24 | 
 | 
| 25 |   #GDB='gdb --args '
 | 
| 26 |   GDB=''
 | 
| 27 | 
 | 
| 28 |   # Stats show that there are 29 collections
 | 
| 29 |   OILS_GC_STATS=1 OILS_GC_VERBOSE=1 OILS_GC_THRESHOLD=10 $GDB $ysh -c '
 | 
| 30 | env | grep OILS
 | 
| 31 | 
 | 
| 32 | var x = "z"
 | 
| 33 | var r = "replace"
 | 
| 34 | 
 | 
| 35 | for i in (1 .. 2000) { 
 | 
| 36 |   #echo $i
 | 
| 37 | 
 | 
| 38 |   # creates exponentially sized strings!
 | 
| 39 |   # TODO: document string size limits
 | 
| 40 |   #setvar x = x=>replace("z", "zz")
 | 
| 41 | 
 | 
| 42 |   # Works fine
 | 
| 43 |   #setvar x = x=>replace("z", "y")
 | 
| 44 | 
 | 
| 45 |   # Hm does not crash?
 | 
| 46 |   setvar x = x=>replace("z", ^"hi $r")
 | 
| 47 | }
 | 
| 48 | echo $x
 | 
| 49 | '
 | 
| 50 | }
 | 
| 51 | 
 | 
| 52 | shvar-replace() {
 | 
| 53 |   ### failing test from Julian
 | 
| 54 | 
 | 
| 55 |   #local ysh=_bin/cxx-asan+gcalways/ysh
 | 
| 56 |   local ysh=_bin/cxx-dbg/ysh
 | 
| 57 |   #local ysh=_bin/cxx-asan/ysh
 | 
| 58 |   ninja $ysh
 | 
| 59 |   #GDB='gdb --args'
 | 
| 60 |   GDB=''
 | 
| 61 | 
 | 
| 62 |   # Takes a few tries, even with OILS_GC_THRESHOLD
 | 
| 63 | 
 | 
| 64 |   local i=0
 | 
| 65 |   while true; do
 | 
| 66 |     echo "=== try $i"
 | 
| 67 | 
 | 
| 68 |     OILS_GC_STATS=1 OILS_GC_VERBOSE=1 OILS_GC_THRESHOLD=10 $GDB $ysh -c '
 | 
| 69 | shvar FOO=bar {
 | 
| 70 |   for x in (1 .. 500) {
 | 
| 71 |     var Q = "hello"
 | 
| 72 |     setvar Q = Q=>replace("hello","world")
 | 
| 73 |   }
 | 
| 74 | }
 | 
| 75 | echo $Q
 | 
| 76 | '
 | 
| 77 |     i=$(( i + 1 ))
 | 
| 78 |   done
 | 
| 79 | }
 | 
| 80 | 
 | 
| 81 | replace-exp() {
 | 
| 82 |   local osh=_bin/cxx-opt/osh
 | 
| 83 |   ninja $osh
 | 
| 84 | 
 | 
| 85 |   # 2.791 seconds for 19 iterations, up to 1 MB
 | 
| 86 |   SH=$osh
 | 
| 87 | 
 | 
| 88 |   SH=bash
 | 
| 89 |   for sh in bash $osh; do
 | 
| 90 |     echo "=== $sh ==="
 | 
| 91 |     echo
 | 
| 92 | 
 | 
| 93 |     time $sh -c '
 | 
| 94 | x=z
 | 
| 95 | for i in {1..19}; do
 | 
| 96 |   x=${x//z/zz}
 | 
| 97 |   echo len=${#x}
 | 
| 98 | done
 | 
| 99 |   '
 | 
| 100 |   done
 | 
| 101 | }
 | 
| 102 | 
 | 
| 103 | # Reduce this bug
 | 
| 104 | # https://github.com/oilshell/oil/issues/1986
 | 
| 105 | 
 | 
| 106 | bug-1986() {
 | 
| 107 |   local ysh=_bin/cxx-dbg/ysh
 | 
| 108 |   #local ysh=_bin/cxx-asan/ysh
 | 
| 109 |   ninja $ysh
 | 
| 110 | 
 | 
| 111 |   local prefix
 | 
| 112 |   #prefix=''
 | 
| 113 |   #prefix="$PWD/$ysh -x"
 | 
| 114 |   prefix="gdb --args $PWD/$ysh"
 | 
| 115 | 
 | 
| 116 |   cd bug/code
 | 
| 117 | 
 | 
| 118 |   set -x
 | 
| 119 |   $prefix src/amd-scripts/amd-test --select imperfect aomp-amd-staging.cfg 14
 | 
| 120 | }
 | 
| 121 | 
 | 
| 122 | "$@"
 |