1 #!/bin/sh 2 3 # 4 # Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 # 7 # This code is free software; you can redistribute it and/or modify it 8 # under the terms of the GNU General Public License version 2 only, as 9 # published by the Free Software Foundation. 10 # 11 # This code is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 # version 2 for more details (a copy is included in the LICENSE file that 15 # accompanied this code). 16 # 17 # You should have received a copy of the GNU General Public License version 18 # 2 along with this work; if not, write to the Free Software Foundation, 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 # or visit www.oracle.com if you need additional information or have any 23 # questions. 24 # 25 26 # 27 # @test 28 # @bug 4981536 29 # @summary TTY: .jdbrc is read twice if jdb is run in the user's home dir 30 # @author jjh 31 # 32 # @run shell JdbReadTwiceTest.sh 33 34 #Set appropriate jdk 35 if [ ! -z "$TESTJAVA" ] ; then 36 jdk="$TESTJAVA" 37 else 38 echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test." 39 exit 1 40 fi 41 42 if [ -z "$TESTCLASSES" ] ; then 43 echo "--Error: TESTCLASSES must be defined." 44 exit 1 45 fi 46 47 case `uname -s` in 48 Linux) 49 # Need this to convert to the /.automount/... form which 50 # is what jdb will report when it reads an init file. 51 echo TESTCLASSES=$TESTCLASSES 52 TESTCLASSES=`(cd $TESTCLASSES; /bin/pwd)` 53 echo TESTCLASSES=$TESTCLASSES 54 ;; 55 esac 56 57 # All output will go under this dir. We define HOME to 58 # be under here too, and pass it into jdb, to avoid problems 59 # with java choosing a value of HOME. 60 baseDir="$TESTCLASSES/jdbRead$$" 61 HOME="$baseDir/home" 62 mkdir -p "$HOME" 63 64 tmpResult="$baseDir/result" 65 fred="$baseDir/fred" 66 here="$baseDir" 67 jdbFiles="$HOME/jdb.ini $HOME/.jdbrc $here/jdb.ini $here/.jdbrc $tmpResult $fred" 68 69 cd $here 70 failed= 71 72 73 mkFiles() 74 { 75 touch "$@" 76 } 77 78 doit() 79 { 80 echo quit | $TESTJAVA/bin/jdb -J-Duser.home=$HOME > $tmpResult 2>&1 81 } 82 83 failIfNot() 84 { 85 # $1 is the expected number of occurances of $2 in the jdb output. 86 count=$1 87 shift 88 if [ -r c:/ ] ; then 89 sed -e 's@\\@/@g' $tmpResult > $tmpResult.1 90 mv $tmpResult.1 $tmpResult 91 fi 92 xx=`fgrep -i "$*" $tmpResult | wc -l` 93 if [ $xx != $count ] ; then 94 echo "Failed: Expected $count, got $xx: $*" 95 echo "-----" 96 cat $tmpResult 97 echo "-----" 98 failed=1 99 else 100 echo "Passed: Expected $count, got $xx: $*" 101 fi 102 } 103 104 clean() 105 { 106 rm -f $jdbFiles 107 } 108 109 # Note: If jdb reads a file, it outputs a message containing 110 # from: filename 111 # If jdb can't read a file, it outputs a message containing 112 # open: filename 113 114 115 echo 116 echo "+++++++++++++++++++++++++++++++++++" 117 echo "Verify each individual file is read" 118 mkFiles $HOME/jdb.ini 119 doit 120 failIfNot 1 "from $HOME/jdb.ini" 121 clean 122 123 mkFiles $HOME/.jdbrc 124 doit 125 failIfNot 1 "from $HOME/.jdbrc" 126 clean 127 128 mkFiles $here/jdb.ini 129 doit 130 failIfNot 1 "from $here/jdb.ini" 131 clean 132 133 mkFiles $here/.jdbrc 134 doit 135 failIfNot 1 "from $here/.jdbrc" 136 clean 137 138 139 cd $HOME 140 echo 141 echo "+++++++++++++++++++++++++++++++++++" 142 echo "Verify files are not read twice if cwd is ~" 143 mkFiles $HOME/jdb.ini 144 doit 145 failIfNot 1 "from $HOME/jdb.ini" 146 clean 147 148 mkFiles $HOME/.jdbrc 149 doit 150 failIfNot 1 "from $HOME/.jdbrc" 151 clean 152 cd $here 153 154 155 echo 156 echo "+++++++++++++++++++++++++++++++++++" 157 echo "If jdb.ini and both .jdbrc exist, don't read .jdbrc" 158 mkFiles $HOME/jdb.ini $HOME/.jdbrc 159 doit 160 failIfNot 1 "from $HOME/jdb.ini" 161 failIfNot 0 "from $HOME/.jdbrc" 162 clean 163 164 165 echo 166 echo "+++++++++++++++++++++++++++++++++++" 167 echo "If files exist in both ~ and ., read both" 168 mkFiles $HOME/jdb.ini $here/.jdbrc 169 doit 170 failIfNot 1 "from $HOME/jdb.ini" 171 failIfNot 1 "from $here/.jdbrc" 172 clean 173 174 mkFiles $HOME/.jdbrc $here/jdb.ini 175 doit 176 failIfNot 1 "from $HOME/.jdbrc" 177 failIfNot 1 "from $here/jdb.ini" 178 clean 179 180 181 if [ ! -r c:/ ] ; then 182 # No symlinks on windows. 183 echo 184 echo "+++++++++++++++++++++++++++++++++++" 185 echo "Don't read a . file that is a symlink to a ~ file" 186 mkFiles $HOME/jdb.ini 187 ln -s $HOME/jdb.ini $here/.jdbrc 188 doit 189 failIfNot 1 "from $HOME/jdb.ini" 190 failIfNot 0 "from $here/.jdbrc" 191 clean 192 fi 193 194 195 if [ ! -r c:/ ] ; then 196 # No symlinks on windows. 197 echo 198 echo "+++++++++++++++++++++++++++++++++++" 199 echo "Don't read a . file that is a target symlink of a ~ file" 200 mkFiles $here/jdb.ini 201 ln -s $here/jdbini $HOME/.jdbrc 202 doit 203 failIfNot 1 "from $here/jdb.ini" 204 failIfNot 0 "from $HOME/.jdbrc" 205 clean 206 fi 207 208 echo 209 echo "+++++++++++++++++++++++++++++++++++" 210 echo "Read a directory - verify the read fails" 211 # If the file (IE. directory) exists, we try to read it. The 212 # read will fail. 213 mkdir $HOME/jdb.ini 214 doit 215 failIfNot 1 "open: $HOME/jdb.ini" 216 rmdir $HOME/jdb.ini 217 218 219 echo "read $fred" > $here/jdb.ini 220 echo 221 echo "+++++++++++++++++++++++++++++++++++" 222 echo "Verify the jdb read command still works" 223 touch $fred 224 doit 225 failIfNot 1 "from $fred" 226 227 if [ "$canMakeUnreadable" = "Yes" ] 228 then 229 chmod a-r $fred 230 doit 231 failIfNot 1 "open: $fred" 232 fi 233 rm -f $fred 234 mkdir $fred 235 doit 236 failIfNot 1 "open: $fred" 237 rmdir $fred 238 239 clean 240 241 242 if [ "$failed" = 1 ] ; then 243 echo "One or more tests failed" 244 exit 1 245 fi 246 247 echo "All tests passed"