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# @run shell JdbReadTwiceTest.sh 32 33#Set appropriate jdk 34if [ ! -z "$TESTJAVA" ] ; then 35 jdk="$TESTJAVA" 36else 37 echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test." 38 exit 1 39fi 40 41if [ -z "$TESTCLASSES" ] ; then 42 echo "--Error: TESTCLASSES must be defined." 43 exit 1 44fi 45 46case `uname -s` in 47 Linux) 48 # Need this to convert to the /.automount/... form which 49 # is what jdb will report when it reads an init file. 50 echo TESTCLASSES=$TESTCLASSES 51 TESTCLASSES=`(cd $TESTCLASSES; /bin/pwd)` 52 echo TESTCLASSES=$TESTCLASSES 53 ;; 54esac 55 56# All output will go under this dir. We define HOME to 57# be under here too, and pass it into jdb, to avoid problems 58# with java choosing a value of HOME. 59baseDir="$TESTCLASSES/jdbRead$$" 60HOME="$baseDir/home" 61mkdir -p "$HOME" 62 63tmpResult="$baseDir/result" 64fred="$baseDir/fred" 65here="$baseDir" 66jdbFiles="$HOME/jdb.ini $HOME/.jdbrc $here/jdb.ini $here/.jdbrc $tmpResult $fred" 67 68cd $here 69failed= 70 71 72mkFiles() 73{ 74 touch "$@" 75} 76 77doit() 78{ 79 echo quit | $TESTJAVA/bin/jdb -J-Duser.home=$HOME > $tmpResult 2>&1 80} 81 82failIfNot() 83{ 84 # $1 is the expected number of occurances of $2 in the jdb output. 85 count=$1 86 shift 87 if [ -r c:/ ] ; then 88 sed -e 's@\\@/@g' $tmpResult > $tmpResult.1 89 mv $tmpResult.1 $tmpResult 90 fi 91 xx=`fgrep -i "$*" $tmpResult | wc -l` 92 if [ $xx != $count ] ; then 93 echo "Failed: Expected $count, got $xx: $*" 94 echo "-----" 95 cat $tmpResult 96 echo "-----" 97 failed=1 98 else 99 echo "Passed: Expected $count, got $xx: $*" 100 fi 101} 102 103clean() 104{ 105 rm -f $jdbFiles 106} 107 108# Note: If jdb reads a file, it outputs a message containing 109# from: filename 110# If jdb can't read a file, it outputs a message containing 111# open: filename 112 113 114echo 115echo "+++++++++++++++++++++++++++++++++++" 116echo "Verify each individual file is read" 117mkFiles $HOME/jdb.ini 118 doit 119 failIfNot 1 "from $HOME/jdb.ini" 120 clean 121 122mkFiles $HOME/.jdbrc 123 doit 124 failIfNot 1 "from $HOME/.jdbrc" 125 clean 126 127mkFiles $here/jdb.ini 128 doit 129 failIfNot 1 "from $here/jdb.ini" 130 clean 131 132mkFiles $here/.jdbrc 133 doit 134 failIfNot 1 "from $here/.jdbrc" 135 clean 136 137 138cd $HOME 139echo 140echo "+++++++++++++++++++++++++++++++++++" 141echo "Verify files are not read twice if cwd is ~" 142mkFiles $HOME/jdb.ini 143 doit 144 failIfNot 1 "from $HOME/jdb.ini" 145 clean 146 147mkFiles $HOME/.jdbrc 148 doit 149 failIfNot 1 "from $HOME/.jdbrc" 150 clean 151cd $here 152 153 154echo 155echo "+++++++++++++++++++++++++++++++++++" 156echo "If jdb.ini and both .jdbrc exist, don't read .jdbrc" 157mkFiles $HOME/jdb.ini $HOME/.jdbrc 158 doit 159 failIfNot 1 "from $HOME/jdb.ini" 160 failIfNot 0 "from $HOME/.jdbrc" 161 clean 162 163 164echo 165echo "+++++++++++++++++++++++++++++++++++" 166echo "If files exist in both ~ and ., read both" 167mkFiles $HOME/jdb.ini $here/.jdbrc 168 doit 169 failIfNot 1 "from $HOME/jdb.ini" 170 failIfNot 1 "from $here/.jdbrc" 171 clean 172 173mkFiles $HOME/.jdbrc $here/jdb.ini 174 doit 175 failIfNot 1 "from $HOME/.jdbrc" 176 failIfNot 1 "from $here/jdb.ini" 177 clean 178 179 180if [ ! -r c:/ ] ; then 181 # No symlinks on windows. 182 echo 183 echo "+++++++++++++++++++++++++++++++++++" 184 echo "Don't read a . file that is a symlink to a ~ file" 185 mkFiles $HOME/jdb.ini 186 ln -s $HOME/jdb.ini $here/.jdbrc 187 doit 188 failIfNot 1 "from $HOME/jdb.ini" 189 failIfNot 0 "from $here/.jdbrc" 190 clean 191fi 192 193 194if [ ! -r c:/ ] ; then 195 # No symlinks on windows. 196 echo 197 echo "+++++++++++++++++++++++++++++++++++" 198 echo "Don't read a . file that is a target symlink of a ~ file" 199 mkFiles $here/jdb.ini 200 ln -s $here/jdbini $HOME/.jdbrc 201 doit 202 failIfNot 1 "from $here/jdb.ini" 203 failIfNot 0 "from $HOME/.jdbrc" 204 clean 205fi 206 207echo 208echo "+++++++++++++++++++++++++++++++++++" 209echo "Read a directory - verify the read fails" 210# If the file (IE. directory) exists, we try to read it. The 211# read will fail. 212mkdir $HOME/jdb.ini 213 doit 214 failIfNot 1 "open: $HOME/jdb.ini" 215 rmdir $HOME/jdb.ini 216 217 218echo "read $fred" > $here/jdb.ini 219 echo 220 echo "+++++++++++++++++++++++++++++++++++" 221 echo "Verify the jdb read command still works" 222 touch $fred 223 doit 224 failIfNot 1 "from $fred" 225 226 if [ "$canMakeUnreadable" = "Yes" ] 227 then 228 chmod a-r $fred 229 doit 230 failIfNot 1 "open: $fred" 231 fi 232 rm -f $fred 233 mkdir $fred 234 doit 235 failIfNot 1 "open: $fred" 236 rmdir $fred 237 238clean 239 240 241if [ "$failed" = 1 ] ; then 242 echo "One or more tests failed" 243 exit 1 244fi 245 246echo "All tests passed" 247