3 # Copyright (c) 2010 Hudson River Trading LLC
4 # Written by: John H. Baldwin <jhb@FreeBSD.org>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Various regression tests to test the -F flag to the 'update' command.
37 echo "Usage: fbsdid.sh [-s script] [-w workdir]"
41 # Allow the user to specify an alternate work directory or script.
43 while getopts "s:w:" option; do
62 CONFLICTS=$WORKDIR/conflicts
67 # Store a FreeBSD ID string in a specified file. The first argument
68 # is the file, the remaining arguments are the comment to use.
76 echo -n '# $FreeBSD' >> $file
81 # These tests deal with FreeBSD ID string conflicts. We run the test
82 # twice, once without -F and once with -F.
87 rm -rf $OLD $NEW $TEST $CONFLICTS
88 mkdir -p $OLD $NEW $TEST
90 # remove: Remove a file where the only local difference is a
91 # change in the FreeBSD ID string.
93 store_id $TEST/remove ": head/remove 12345 jhb "
95 # old: Modify a file where the only local difference between
96 # the old and test files is a change in the FreeBSD ID string.
97 store_id $OLD/old ": src/old,v 1.1 jhb Exp "
98 store_id $NEW/old ": head/old 12345 jhb "
99 store_id $TEST/old ": head/old 12000 jhb "
100 for i in $OLD $TEST; do
106 cat >> $NEW/old <<EOF
111 # already: Modify a file where the local file already matches
112 # the new file except for a change in the FreeBSD ID string.
113 store_id $OLD/already ": src/already,v 1.1 jhb Exp "
114 store_id $NEW/already ": head/already 12345 jhb "
115 store_id $TEST/already ": src/already,v 1.2 jhb Exp "
116 cat >> $OLD/already <<EOF
120 for i in $NEW $TEST; do
121 cat >> $i/already <<EOF
127 # add: Add a file that already exists where the only local
128 # difference is a change in the FreeBSD ID string.
129 store_id $NEW/add ": head/add 12345 jhb "
130 store_id $TEST/add ""
132 # conflict: Modify a file where the local file has a different
133 # FreeBSD ID string. This should still generate a conflict
134 # even in the -F case.
135 store_id $OLD/conflict ": head/conflict 12000 jhb "
136 store_id $NEW/conflict ": head/conflict 12345 jhb "
137 store_id $TEST/conflict ""
138 cat >> $OLD/conflict <<EOF
142 cat >> $NEW/conflict <<EOF
146 cat >> $TEST/conflict <<EOF
148 this is the local file
151 # local: A file with local modifications has a different
152 # FreeBSD ID string and the only differences between the old
153 # and new versions are a change in the FreeBSD ID string.
154 # This will just update the FreeBSD ID string in the -F case.
155 for i in $OLD $NEW $TEST; do
156 cat >> $i/local <<EOF
162 store_id $OLD/local ": head/local 12000 jhb "
163 store_id $NEW/local ": head/local 12345 jhb "
164 store_id $TEST/local ": src/local,v 1.5 jhb Exp "
166 for i in $OLD $NEW $TEST; do
167 cat >> $i/local <<EOF
173 cat >> $TEST/local <<EOF
175 these are some local mods to the file
178 # local-already: A file with local modifications has the same
179 # FreeBSD ID string as the new version of the file and the
180 # only differences between the old and new versions are a
181 # change in the FreeBSD ID string. Nothing should happen in
183 store_id $OLD/local-already ": head/local 12000 jhb "
184 for i in $NEW $TEST; do
185 store_id $i/local-already ": head/local 12345 jhb "
188 for i in $OLD $NEW $TEST; do
189 cat >> $i/local-already <<EOF
195 cat >> $TEST/local-already <<EOF
197 these are some local mods to the file
200 # local-remove: A file removed locally changed it's FreeBSD ID
202 store_id $OLD/local-remove ": head/local-remove 12000 jhb "
203 store_id $NEW/local-remove ": head/local-remove 12345 jhb "
204 for i in $OLD $NEW; do
205 cat >> $i/local-remove <<EOF
212 # $1 - relative path to file that should be missing from TEST
215 if [ -e $TEST/$1 -o -L $TEST/$1 ]; then
216 echo "File $1 should be missing"
221 # $1 - relative path to file that should be present in TEST
224 if ! [ -e $TEST/$1 -o -L $TEST/$1 ]; then
225 echo "File $1 should be present"
230 # $1 - relative path to regular file that should be present in TEST
231 # $2 - optional string that should match file contents
232 # $3 - optional MD5 of the flie contents, overrides $2 if present
237 if ! [ -f $TEST/$1 ]; then
238 echo "File $1 should be a regular file"
240 elif [ $# -eq 2 ]; then
241 contents=`cat $TEST/$1`
242 if [ "$contents" != "$2" ]; then
243 echo "File $1 has wrong contents"
246 elif [ $# -eq 3 ]; then
247 sum=`md5 -q $TEST/$1`
248 if [ "$sum" != "$3" ]; then
249 echo "File $1 has wrong contents"
255 # $1 - relative path to a regular file that should have a conflict
256 # $2 - optional MD5 of the conflict file contents
261 if ! [ -f $CONFLICTS/$1 ]; then
262 echo "File $1 missing conflict"
264 elif [ $# -gt 1 ]; then
265 sum=`md5 -q $CONFLICTS/$1`
266 if [ "$sum" != "$2" ]; then
267 echo "Conflict $1 has wrong contents"
273 # $1 - relative path to a regular file that should not have a conflict
276 if [ -f $CONFLICTS/$1 ]; then
277 echo "File $1 should not have a conflict"
282 if [ `id -u` -ne 0 ]; then
287 if [ -r /etc/etcupdate.conf ]; then
288 echo "WARNING: /etc/etcupdate.conf settings may break some tests."
291 # First run the test without -F.
295 $COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
297 cat > $WORKDIR/correct.out <<EOF
305 Modified regular file remains: /remove
306 Removed file changed: /local-remove
309 echo "Differences for regular:"
310 diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out \
313 file /remove "" 1bb4776213af107077be78fead8a351c
314 file /old "" 2f799a7addc4132563ef9b44adc66157
315 conflict /old 8441be64a1540f2ff584015279682425
316 file /already "" aa53bd506f65d01d766e7ba028585e1d
317 conflict /already f44105abb1fa3293e95c5d77e428d418
318 file /add "" 1dc8c617e541d1fd1b4c70212f71d8ae
319 conflict /add f99081e0da9a07f3cfebb430c0414941
320 file /conflict "" dc27978df125b0daeb7d9b93265f03fd
321 conflict /conflict 868452f666fea1c60ffb918ad9ad9607
322 file /local "" aa33e614b5e749449f230e2a2b0072eb
323 conflict /local 3df93e64043c8e348fc625b93ea220f4
324 file /local-already "" 0298b958a603049f45ae6a109c4f7fea
325 missing /local-remove
331 $COMMAND -rF -d $WORKDIR -D $TEST > $WORKDIR/testF.out
333 cat > $WORKDIR/correctF.out <<EOF
342 echo "Differences for -F:"
343 diff -u -L "correct" $WORKDIR/correctF.out -L "test" $WORKDIR/testF.out \
347 file /old "" 6a9f34f109d94406a4de3bc5d72de259
349 file /already "" 21f4eca3aacc702c49878c8da7afd3d0
351 file /add "" 0208bd647111fedf6318511712ab9e97
353 file /conflict "" dc27978df125b0daeb7d9b93265f03fd
354 conflict /conflict 868452f666fea1c60ffb918ad9ad9607
355 file /local "" 3ed5a35e380c8a93fb5f599d4c052713
356 file /local-already "" 0298b958a603049f45ae6a109c4f7fea
357 missing /local-remove
359 # Now test with -F and -A forcing all installs. (-A should have
360 # precedence over -F)
364 $COMMAND -A '/*' -rF -d $WORKDIR -D $TEST > $WORKDIR/testAF.out
366 cat > $WORKDIR/correctAF.out <<EOF
377 echo "Differences for -A '/*' -F:"
378 diff -u -L "correct" $WORKDIR/correctAF.out -L "test" $WORKDIR/testAF.out \
382 file /old "" 6a9f34f109d94406a4de3bc5d72de259
384 file /already "" 21f4eca3aacc702c49878c8da7afd3d0
386 file /add "" 0208bd647111fedf6318511712ab9e97
388 file /conflict "" 75ee141c4136beaf14e39de92efa84e4
390 file /local "" 6a8fc5c2755b7a49015089f5e1dbe092
391 file /local-already "" 49045f8b51542dd634655301cd296f66
392 file /local-remove "" 5c38322efed4014797d7127f5c652d9d