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