|
1 #!/bin/sh |
|
2 |
|
3 # |
|
4 # Copyright (c) 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 # CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 # have any 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 |
|
34 if [ ! -z "$TESTJAVA" ] ; then |
|
35 jdk="$TESTJAVA" |
|
36 else |
|
37 echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test." |
|
38 exit 1 |
|
39 fi |
|
40 |
|
41 if [ -z "$TESTCLASSES" ] ; then |
|
42 echo "--Error: TESTCLASSES must be defined." |
|
43 exit 1 |
|
44 fi |
|
45 |
|
46 case `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 ;; |
|
54 esac |
|
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. |
|
59 baseDir="$TESTCLASSES/jdbRead$$" |
|
60 HOME="$baseDir/home" |
|
61 mkdir -p "$HOME" |
|
62 |
|
63 tmpResult="$baseDir/result" |
|
64 fred="$baseDir/fred" |
|
65 here="$baseDir" |
|
66 jdbFiles="$HOME/jdb.ini $HOME/.jdbrc $here/jdb.ini $here/.jdbrc $tmpResult $fred" |
|
67 |
|
68 cd $here |
|
69 failed= |
|
70 |
|
71 |
|
72 mkFiles() |
|
73 { |
|
74 touch "$@" |
|
75 } |
|
76 |
|
77 doit() |
|
78 { |
|
79 echo quit | $TESTJAVA/bin/jdb -J-Duser.home=$HOME > $tmpResult 2>&1 |
|
80 } |
|
81 |
|
82 failIfNot() |
|
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 |
|
103 clean() |
|
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 |
|
114 echo |
|
115 echo "+++++++++++++++++++++++++++++++++++" |
|
116 echo "Verify each individual file is read" |
|
117 mkFiles $HOME/jdb.ini |
|
118 doit |
|
119 failIfNot 1 "from $HOME/jdb.ini" |
|
120 clean |
|
121 |
|
122 mkFiles $HOME/.jdbrc |
|
123 doit |
|
124 failIfNot 1 "from $HOME/.jdbrc" |
|
125 clean |
|
126 |
|
127 mkFiles $here/jdb.ini |
|
128 doit |
|
129 failIfNot 1 "from $here/jdb.ini" |
|
130 clean |
|
131 |
|
132 mkFiles $here/.jdbrc |
|
133 doit |
|
134 failIfNot 1 "from $here/.jdbrc" |
|
135 clean |
|
136 |
|
137 |
|
138 cd $HOME |
|
139 echo |
|
140 echo "+++++++++++++++++++++++++++++++++++" |
|
141 echo "Verify files are not read twice if cwd is ~" |
|
142 mkFiles $HOME/jdb.ini |
|
143 doit |
|
144 failIfNot 1 "from $HOME/jdb.ini" |
|
145 clean |
|
146 |
|
147 mkFiles $HOME/.jdbrc |
|
148 doit |
|
149 failIfNot 1 "from $HOME/.jdbrc" |
|
150 clean |
|
151 cd $here |
|
152 |
|
153 |
|
154 echo |
|
155 echo "+++++++++++++++++++++++++++++++++++" |
|
156 echo "If jdb.ini and both .jdbrc exist, don't read .jdbrc" |
|
157 mkFiles $HOME/jdb.ini $HOME/.jdbrc |
|
158 doit |
|
159 failIfNot 1 "from $HOME/jdb.ini" |
|
160 failIfNot 0 "from $HOME/.jdbrc" |
|
161 clean |
|
162 |
|
163 |
|
164 echo |
|
165 echo "+++++++++++++++++++++++++++++++++++" |
|
166 echo "If files exist in both ~ and ., read both" |
|
167 mkFiles $HOME/jdb.ini $here/.jdbrc |
|
168 doit |
|
169 failIfNot 1 "from $HOME/jdb.ini" |
|
170 failIfNot 1 "from $here/.jdbrc" |
|
171 clean |
|
172 |
|
173 mkFiles $HOME/.jdbrc $here/jdb.ini |
|
174 doit |
|
175 failIfNot 1 "from $HOME/.jdbrc" |
|
176 failIfNot 1 "from $here/jdb.ini" |
|
177 clean |
|
178 |
|
179 |
|
180 if [ ! -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 |
|
191 fi |
|
192 |
|
193 |
|
194 if [ ! -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 |
|
205 fi |
|
206 |
|
207 |
|
208 if [ ! -r c:/ ] ; then |
|
209 # Can't make a file unreadable under MKS. |
|
210 echo |
|
211 echo "+++++++++++++++++++++++++++++++++++" |
|
212 echo "Read an unreadable file - verify the read fails." |
|
213 # If the file exists, we try to read it. The |
|
214 # read will fail. |
|
215 mkFiles $HOME/jdb.ini |
|
216 chmod a-r $HOME/jdb.ini |
|
217 doit |
|
218 failIfNot 1 "open: $HOME/jdb.ini" |
|
219 clean |
|
220 fi |
|
221 |
|
222 |
|
223 echo |
|
224 echo "+++++++++++++++++++++++++++++++++++" |
|
225 echo "Read a directory - verify the read fails" |
|
226 # If the file (IE. directory) exists, we try to read it. The |
|
227 # read will fail. |
|
228 mkdir $HOME/jdb.ini |
|
229 doit |
|
230 failIfNot 1 "open: $HOME/jdb.ini" |
|
231 rmdir $HOME/jdb.ini |
|
232 |
|
233 |
|
234 echo "read $fred" > $here/jdb.ini |
|
235 echo |
|
236 echo "+++++++++++++++++++++++++++++++++++" |
|
237 echo "Verify the jdb read command still works" |
|
238 touch $fred |
|
239 doit |
|
240 failIfNot 1 "from $fred" |
|
241 |
|
242 if [ ! -r c:/ ] ; then |
|
243 # Can't make a file unreadable under MKS |
|
244 chmod a-r $fred |
|
245 doit |
|
246 failIfNot 1 "open: $fred" |
|
247 fi |
|
248 rm -f $fred |
|
249 mkdir $fred |
|
250 doit |
|
251 failIfNot 1 "open: $fred" |
|
252 rmdir $fred |
|
253 |
|
254 clean |
|
255 |
|
256 |
|
257 if [ "$failed" = 1 ] ; then |
|
258 echo "One or more tests failed" |
|
259 exit 1 |
|
260 fi |
|
261 |
|
262 echo "All tests passed" |