1 #!/bin/sh
   2 
   3 ##
   4 ## @test TooSmallStackSize.sh
   5 ## @bug 6762191
   6 ## @summary Setting stack size to 16K causes segmentation fault 
   7 ## @run shell TooSmallStackSize.sh
   8 ##
   9 ## some tests require path to find test source dir
  10 if [ "${TESTSRC}" = "" ]
  11 then
  12   TESTSRC=${PWD}
  13   echo "TESTSRC not set.  Using "${TESTSRC}" as default"
  14 fi
  15 echo "TESTSRC=${TESTSRC}"
  16 ## Adding common setup Variables for running shell tests.
  17 . ${TESTSRC}/../../test_env.sh
  18 
  19 JAVA=${TESTJAVA}${FS}bin${FS}java
  20 
  21 # Current directory is scratch directory, copy all the test source there
  22 # (for the subsequent moves to work).
  23 ${CP} ${TESTSRC}${FS}/TooSmallStackSize.sh ${THIS_DIR}
  24 
  25 # Run java with 16k stack size, which caused a crash on some platforms
  26 ${JAVA} ${TESTOPTS} -Xss16k -version >test.out 2>&1
  27 result=$?
  28 cat test.out
  29 
  30 # The result of a 16k stack size should be a quick exit with a complaint
  31 # that the stack size is too small. However, for some win32 builds, the
  32 # stack is always at least 64k, and this also sometimes is the minimum
  33 # allowed size, so we won't see an error in this case.
  34 if [ "$result" != "0" ]; then
  35   grep "The stack size specified is too small" test.out
  36   if [ "$?" != "0" ]; then
  37     printf "FAILED #1: Did not get expected error message with stack size of 16k\n"
  38     exit 1
  39   fi
  40   printf "PASSED #1: got expected error message with stack size of 16k\n"
  41 else
  42   printf "PASSED #1: got no error message with stack size of 16k\n"
  43 fi
  44 
  45 # Now try again with a 32k stack size, which is the size that the launcher will
  46 # set to if you try setting to anything smaller. This should produce the same 
  47 # result as setting to 16k.
  48 ${JAVA} ${TESTOPTS} -Xss32k -version >test.out 2>&1
  49 result=$?
  50 cat test.out
  51 
  52 # The result of a 32k stack size should again be a quick exit with a complaint
  53 # that the stack size is too small. Once again, this might not fail on win32.
  54 if [ "$result" != "0" ]; then
  55   grep "The stack size specified is too small" test.out
  56   if [ "$?" != "0" ]; then
  57     printf "FAILED #2: Did not get expected error message with stack size of 32k\n"
  58     exit 1
  59   fi
  60   printf "PASSED #2: got expected error message with stack size of 32k\n"
  61   # Error message contains the minimum stack size allowed. 
  62   min_stack_allowed=`grep Specify.at.least test.out | sed -e 's/.*Specify at least \(.*k\).*/\1/g'`
  63 else
  64   printf "PASSED #2: got no error message with stack size of 32k\n"
  65   # No error message, so just use the same size again on the next run.
  66   min_stack_allowed="32k"
  67 fi
  68 
  69 # Try again with a the minimum stack size that was given in the error message
  70 ${JAVA} ${TESTOPTS} -Xss${min_stack_allowed} -version >test.out 2>&1
  71 result=$?
  72 cat test.out
  73 
  74 # The result should be success running java -version.
  75 if [ "$result" != "0" ]; then
  76   printf "FAILED #3: VM failed to launch with minimum allowed stack size of %dk\n" $min_stack_allowed
  77   exit 1
  78 else
  79   printf "PASSED #3: VM launched with minimum allowed stack size of %dk\n" $min_stack_allowed
  80 fi
  81 
  82 printf "PASSED.\n"