0N/A#!/bin/sh
0N/A
0N/A#
2362N/A# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0N/A# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A#
0N/A# This code is free software; you can redistribute it and/or modify it
0N/A# under the terms of the GNU General Public License version 2 only, as
0N/A# published by the Free Software Foundation.
0N/A#
0N/A# This code is distributed in the hope that it will be useful, but WITHOUT
0N/A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A# version 2 for more details (a copy is included in the LICENSE file that
0N/A# accompanied this code).
0N/A#
0N/A# You should have received a copy of the GNU General Public License version
0N/A# 2 along with this work; if not, write to the Free Software Foundation,
0N/A# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A#
2362N/A# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A# or visit www.oracle.com if you need additional information or have any
2362N/A# questions.
0N/A#
0N/A
0N/A#
0N/A# @test
0N/A# @bug 4981536
0N/A# @summary TTY: .jdbrc is read twice if jdb is run in the user's home dir
0N/A# @author jjh
0N/A# @run shell JdbReadTwiceTest.sh
0N/A
0N/A#Set appropriate jdk
0N/Aif [ ! -z "$TESTJAVA" ] ; then
0N/A jdk="$TESTJAVA"
0N/Aelse
0N/A echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test."
0N/A exit 1
0N/Afi
0N/A
0N/Aif [ -z "$TESTCLASSES" ] ; then
0N/A echo "--Error: TESTCLASSES must be defined."
0N/A exit 1
0N/Afi
0N/A
0N/Acase `uname -s` in
0N/A Linux)
0N/A # Need this to convert to the /.automount/... form which
0N/A # is what jdb will report when it reads an init file.
0N/A echo TESTCLASSES=$TESTCLASSES
0N/A TESTCLASSES=`(cd $TESTCLASSES; /bin/pwd)`
0N/A echo TESTCLASSES=$TESTCLASSES
0N/A ;;
0N/Aesac
0N/A
0N/A# All output will go under this dir. We define HOME to
0N/A# be under here too, and pass it into jdb, to avoid problems
0N/A# with java choosing a value of HOME.
0N/AbaseDir="$TESTCLASSES/jdbRead$$"
0N/AHOME="$baseDir/home"
0N/Amkdir -p "$HOME"
0N/A
0N/AtmpResult="$baseDir/result"
0N/Afred="$baseDir/fred"
0N/Ahere="$baseDir"
0N/AjdbFiles="$HOME/jdb.ini $HOME/.jdbrc $here/jdb.ini $here/.jdbrc $tmpResult $fred"
0N/A
0N/Acd $here
0N/Afailed=
0N/A
0N/A
0N/AmkFiles()
0N/A{
0N/A touch "$@"
0N/A}
0N/A
0N/Adoit()
0N/A{
0N/A echo quit | $TESTJAVA/bin/jdb -J-Duser.home=$HOME > $tmpResult 2>&1
0N/A}
0N/A
0N/AfailIfNot()
0N/A{
0N/A # $1 is the expected number of occurances of $2 in the jdb output.
0N/A count=$1
0N/A shift
0N/A if [ -r c:/ ] ; then
0N/A sed -e 's@\\@/@g' $tmpResult > $tmpResult.1
0N/A mv $tmpResult.1 $tmpResult
0N/A fi
0N/A xx=`fgrep -i "$*" $tmpResult | wc -l`
0N/A if [ $xx != $count ] ; then
0N/A echo "Failed: Expected $count, got $xx: $*"
0N/A echo "-----"
0N/A cat $tmpResult
0N/A echo "-----"
0N/A failed=1
0N/A else
0N/A echo "Passed: Expected $count, got $xx: $*"
0N/A fi
0N/A}
0N/A
0N/Aclean()
0N/A{
0N/A rm -f $jdbFiles
0N/A}
0N/A
0N/A# Note: If jdb reads a file, it outputs a message containing
0N/A# from: filename
0N/A# If jdb can't read a file, it outputs a message containing
0N/A# open: filename
0N/A
0N/A
0N/Aecho
0N/Aecho "+++++++++++++++++++++++++++++++++++"
0N/Aecho "Verify each individual file is read"
0N/AmkFiles $HOME/jdb.ini
0N/A doit
0N/A failIfNot 1 "from $HOME/jdb.ini"
0N/A clean
0N/A
0N/AmkFiles $HOME/.jdbrc
0N/A doit
0N/A failIfNot 1 "from $HOME/.jdbrc"
0N/A clean
0N/A
0N/AmkFiles $here/jdb.ini
0N/A doit
0N/A failIfNot 1 "from $here/jdb.ini"
0N/A clean
0N/A
0N/AmkFiles $here/.jdbrc
0N/A doit
0N/A failIfNot 1 "from $here/.jdbrc"
0N/A clean
0N/A
0N/A
0N/Acd $HOME
0N/Aecho
0N/Aecho "+++++++++++++++++++++++++++++++++++"
0N/Aecho "Verify files are not read twice if cwd is ~"
0N/AmkFiles $HOME/jdb.ini
0N/A doit
0N/A failIfNot 1 "from $HOME/jdb.ini"
0N/A clean
0N/A
0N/AmkFiles $HOME/.jdbrc
0N/A doit
0N/A failIfNot 1 "from $HOME/.jdbrc"
0N/A clean
0N/Acd $here
0N/A
0N/A
0N/Aecho
0N/Aecho "+++++++++++++++++++++++++++++++++++"
0N/Aecho "If jdb.ini and both .jdbrc exist, don't read .jdbrc"
0N/AmkFiles $HOME/jdb.ini $HOME/.jdbrc
0N/A doit
0N/A failIfNot 1 "from $HOME/jdb.ini"
0N/A failIfNot 0 "from $HOME/.jdbrc"
0N/A clean
0N/A
0N/A
0N/Aecho
0N/Aecho "+++++++++++++++++++++++++++++++++++"
0N/Aecho "If files exist in both ~ and ., read both"
0N/AmkFiles $HOME/jdb.ini $here/.jdbrc
0N/A doit
0N/A failIfNot 1 "from $HOME/jdb.ini"
0N/A failIfNot 1 "from $here/.jdbrc"
0N/A clean
0N/A
0N/AmkFiles $HOME/.jdbrc $here/jdb.ini
0N/A doit
0N/A failIfNot 1 "from $HOME/.jdbrc"
0N/A failIfNot 1 "from $here/jdb.ini"
0N/A clean
0N/A
0N/A
0N/Aif [ ! -r c:/ ] ; then
0N/A # No symlinks on windows.
0N/A echo
0N/A echo "+++++++++++++++++++++++++++++++++++"
0N/A echo "Don't read a . file that is a symlink to a ~ file"
0N/A mkFiles $HOME/jdb.ini
0N/A ln -s $HOME/jdb.ini $here/.jdbrc
0N/A doit
0N/A failIfNot 1 "from $HOME/jdb.ini"
0N/A failIfNot 0 "from $here/.jdbrc"
0N/A clean
0N/Afi
0N/A
0N/A
0N/Aif [ ! -r c:/ ] ; then
0N/A # No symlinks on windows.
0N/A echo
0N/A echo "+++++++++++++++++++++++++++++++++++"
0N/A echo "Don't read a . file that is a target symlink of a ~ file"
0N/A mkFiles $here/jdb.ini
0N/A ln -s $here/jdbini $HOME/.jdbrc
0N/A doit
0N/A failIfNot 1 "from $here/jdb.ini"
0N/A failIfNot 0 "from $HOME/.jdbrc"
0N/A clean
0N/Afi
0N/A
0N/A
0N/Aif [ ! -r c:/ ] ; then
0N/A # Can't make a file unreadable under MKS.
0N/A echo
0N/A echo "+++++++++++++++++++++++++++++++++++"
0N/A echo "Read an unreadable file - verify the read fails."
0N/A # If the file exists, we try to read it. The
0N/A # read will fail.
0N/A mkFiles $HOME/jdb.ini
0N/A chmod a-r $HOME/jdb.ini
0N/A doit
0N/A failIfNot 1 "open: $HOME/jdb.ini"
0N/A clean
0N/Afi
0N/A
0N/A
0N/Aecho
0N/Aecho "+++++++++++++++++++++++++++++++++++"
0N/Aecho "Read a directory - verify the read fails"
0N/A# If the file (IE. directory) exists, we try to read it. The
0N/A# read will fail.
0N/Amkdir $HOME/jdb.ini
0N/A doit
0N/A failIfNot 1 "open: $HOME/jdb.ini"
0N/A rmdir $HOME/jdb.ini
0N/A
0N/A
0N/Aecho "read $fred" > $here/jdb.ini
0N/A echo
0N/A echo "+++++++++++++++++++++++++++++++++++"
0N/A echo "Verify the jdb read command still works"
0N/A touch $fred
0N/A doit
0N/A failIfNot 1 "from $fred"
0N/A
0N/A if [ ! -r c:/ ] ; then
0N/A # Can't make a file unreadable under MKS
0N/A chmod a-r $fred
0N/A doit
0N/A failIfNot 1 "open: $fred"
0N/A fi
0N/A rm -f $fred
0N/A mkdir $fred
0N/A doit
0N/A failIfNot 1 "open: $fred"
0N/A rmdir $fred
0N/A
0N/Aclean
0N/A
0N/A
0N/Aif [ "$failed" = 1 ] ; then
0N/A echo "One or more tests failed"
0N/A exit 1
0N/Afi
0N/A
0N/Aecho "All tests passed"