diff options
author | jhb <jhb@FreeBSD.org> | 2013-12-27 19:53:42 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2013-12-27 19:53:42 +0000 |
commit | 33f454b5c1f0354b8354b4536b45d3d1d1cc8982 (patch) | |
tree | c633811e25045e480fc8496207779de9fb64f184 /tools/regression | |
parent | 020ad1f282db55011d51031eb05015f0e3fb1161 (diff) | |
download | FreeBSD-src-33f454b5c1f0354b8354b4536b45d3d1d1cc8982.zip FreeBSD-src-33f454b5c1f0354b8354b4536b45d3d1d1cc8982.tar.gz |
MFC 258063,258064,258066,258097,258185,259134:
- Add an -s option to the regression tests that specifies a path to an
alternate etcupdate.sh script to test. This allows a non-installed
version of the script to be tested more easily.
- Add a pre-world mode of updating similar to the -p option that can be
passed to mergemaster.
- Fix a couple of issues with -F:
- Fix ALWAYS_INSTALL to take precedence over the FreeBSD ID checks.
- Fix the -F option in the case that the only upstream change is a
change in the FreeBSD ID and the local file is removed.
- Refresh /etc/localtime after each update using tzsetup -r.
- Regenerate /var/db/services.db when /etc/services changes.
Diffstat (limited to 'tools/regression')
-rwxr-xr-x | tools/regression/usr.sbin/etcupdate/always.sh | 14 | ||||
-rwxr-xr-x | tools/regression/usr.sbin/etcupdate/conflicts.sh | 30 | ||||
-rwxr-xr-x | tools/regression/usr.sbin/etcupdate/fbsdid.sh | 62 | ||||
-rwxr-xr-x | tools/regression/usr.sbin/etcupdate/ignore.sh | 18 | ||||
-rwxr-xr-x | tools/regression/usr.sbin/etcupdate/preworld.sh | 239 | ||||
-rwxr-xr-x | tools/regression/usr.sbin/etcupdate/tests.sh | 35 | ||||
-rwxr-xr-x | tools/regression/usr.sbin/etcupdate/tzsetup.sh | 221 |
7 files changed, 584 insertions, 35 deletions
diff --git a/tools/regression/usr.sbin/etcupdate/always.sh b/tools/regression/usr.sbin/etcupdate/always.sh index 5f5e586..b67fd8b 100755 --- a/tools/regression/usr.sbin/etcupdate/always.sh +++ b/tools/regression/usr.sbin/etcupdate/always.sh @@ -33,13 +33,17 @@ WORKDIR=work usage() { - echo "Usage: always.sh [-w workdir]" + echo "Usage: always.sh [-s script] [-w workdir]" exit 1 } -# Allow the user to specify an alternate work directory. -while getopts "w:" option; do +# Allow the user to specify an alternate work directory or script. +COMMAND=etcupdate +while getopts "s:w:" option; do case $option in + s) + COMMAND="sh $OPTARG" + ;; w) WORKDIR=$OPTARG ;; @@ -372,7 +376,7 @@ fi build_trees -etcupdate -r -d $WORKDIR -D $TEST > $WORKDIR/test.out +$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out cat > $WORKDIR/correct.out <<EOF D /dirchange/fromdir/extradir/file @@ -492,7 +496,7 @@ fifo /dirchange/todir/difftype build_trees -etcupdate -r -A '/first*' -A '/second* /*di*' -d $WORKDIR -D $TEST > \ +$COMMAND -r -A '/first*' -A '/second* /*di*' -d $WORKDIR -D $TEST > \ $WORKDIR/test1.out cat > $WORKDIR/correct1.out <<EOF diff --git a/tools/regression/usr.sbin/etcupdate/conflicts.sh b/tools/regression/usr.sbin/etcupdate/conflicts.sh index 0c19323..ec46927 100755 --- a/tools/regression/usr.sbin/etcupdate/conflicts.sh +++ b/tools/regression/usr.sbin/etcupdate/conflicts.sh @@ -33,13 +33,17 @@ WORKDIR=work usage() { - echo "Usage: tests.sh [-w workdir]" + echo "Usage: conflicts.sh [-s script] [-w workdir]" exit 1 } -# Allow the user to specify an alternate work directory. -while getopts "w:" option; do +# Allow the user to specify an alternate work directory or script. +COMMAND=etcupdate +while getopts "s:w:" option; do case $option in + s) + COMMAND="sh $OPTARG" + ;; w) WORKDIR=$OPTARG ;; @@ -84,7 +88,7 @@ default:\\ :welcome=/etc/motd: EOF - etcupdate -r -d $WORKDIR -D $TEST >/dev/null + $COMMAND -r -d $WORKDIR -D $TEST >/dev/null } # This is used to verify special handling for /etc/mail/aliases and @@ -122,7 +126,7 @@ MAILER-DAEMON: postmaster postmaster: foo EOF - etcupdate -r -d $WORKDIR -D $TEST >/dev/null + $COMMAND -r -d $WORKDIR -D $TEST >/dev/null } # $1 - relative path to file that should be missing from TEST @@ -201,7 +205,7 @@ build_login_conflict # Verify that 'p' doesn't do anything. echo "Checking 'p':" -echo 'p' | etcupdate resolve -d $WORKDIR -D $TEST >/dev/null +echo 'p' | $COMMAND resolve -d $WORKDIR -D $TEST >/dev/null file /etc/login.conf "" 95de92ea3f1bb1bf4f612a8b5908cddd missing /etc/login.conf.db @@ -209,7 +213,7 @@ conflict /etc/login.conf # Verify that 'mf' removes the conflict, but does nothing else. echo "Checking 'mf':" -echo 'mf' | etcupdate resolve -d $WORKDIR -D $TEST >/dev/null +echo 'mf' | $COMMAND resolve -d $WORKDIR -D $TEST >/dev/null file /etc/login.conf "" 95de92ea3f1bb1bf4f612a8b5908cddd missing /etc/login.conf.db @@ -219,7 +223,7 @@ build_login_conflict # Verify that 'tf' installs the new version of the file. echo "Checking 'tf':" -echo 'tf' | etcupdate resolve -d $WORKDIR -D $TEST >/dev/null +echo 'tf' | $COMMAND resolve -d $WORKDIR -D $TEST >/dev/null file /etc/login.conf "" 7774a0f9a3a372c7c109c32fd31c4b6b file /etc/login.conf.db @@ -238,7 +242,7 @@ default:\\ :welcome=/etc/motd: EOF -echo 'r' | etcupdate resolve -d $WORKDIR -D $TEST >/dev/null +echo 'r' | $COMMAND resolve -d $WORKDIR -D $TEST >/dev/null file /etc/login.conf "" 966e25984b9b63da8eaac8479dcb0d4d file /etc/login.conf.db @@ -248,12 +252,12 @@ build_aliases_conflict # Verify that 'p' and 'mf' do not generate the newaliases warning. echo "Checking newalias warning for 'p'": -echo 'p' | etcupdate resolve -d $WORKDIR -D $TEST | grep -q newalias +echo 'p' | $COMMAND resolve -d $WORKDIR -D $TEST | grep -q newalias if [ $? -eq 0 ]; then echo "+ Extra warning" fi echo "Checking newalias warning for 'mf'": -echo 'mf' | etcupdate resolve -d $WORKDIR -D $TEST | grep -q newalias +echo 'mf' | $COMMAND resolve -d $WORKDIR -D $TEST | grep -q newalias if [ $? -eq 0 ]; then echo "+ Extra warning" fi @@ -261,14 +265,14 @@ fi # Verify that 'tf' and 'r' do generate the newaliases warning. build_aliases_conflict echo "Checking newalias warning for 'tf'": -echo 'tf' | etcupdate resolve -d $WORKDIR -D $TEST | grep -q newalias +echo 'tf' | $COMMAND resolve -d $WORKDIR -D $TEST | grep -q newalias if [ $? -ne 0 ]; then echo "- Missing warning" fi build_aliases_conflict cp $TEST/etc/mail/aliases $CONFLICTS/etc/mail/aliases -echo 'r' | etcupdate resolve -d $WORKDIR -D $TEST | grep -q newalias +echo 'r' | $COMMAND resolve -d $WORKDIR -D $TEST | grep -q newalias if [ $? -ne 0 ]; then echo "- Missing warning" fi diff --git a/tools/regression/usr.sbin/etcupdate/fbsdid.sh b/tools/regression/usr.sbin/etcupdate/fbsdid.sh index 3a90a1e..e713c35 100755 --- a/tools/regression/usr.sbin/etcupdate/fbsdid.sh +++ b/tools/regression/usr.sbin/etcupdate/fbsdid.sh @@ -33,13 +33,17 @@ WORKDIR=work usage() { - echo "Usage: fbsdid.sh [-w workdir]" + echo "Usage: fbsdid.sh [-s script] [-w workdir]" exit 1 } -# Allow the user to specify an alternate work directory. -while getopts "w:" option; do +# Allow the user to specify an alternate work directory or script. +COMMAND=etcupdate +while getopts "s:w:" option; do case $option in + s) + COMMAND="sh $OPTARG" + ;; w) WORKDIR=$OPTARG ;; @@ -191,6 +195,17 @@ EOF these are some local mods to the file EOF + + # local-remove: A file removed locally changed it's FreeBSD ID + # but nothing else + store_id $OLD/local-remove ": head/local-remove 12000 jhb " + store_id $NEW/local-remove ": head/local-remove 12345 jhb " + for i in $OLD $NEW; do + cat >> $i/local-remove <<EOF + +this is a file +EOF + done } # $1 - relative path to file that should be missing from TEST @@ -267,7 +282,7 @@ fi build_trees -etcupdate -r -d $WORKDIR -D $TEST > $WORKDIR/test.out +$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out cat > $WORKDIR/correct.out <<EOF C /already @@ -278,6 +293,7 @@ cat > $WORKDIR/correct.out <<EOF C /add Warnings: Modified regular file remains: /remove + Removed file changed: /local-remove EOF echo "Differences for regular:" @@ -295,12 +311,13 @@ conflict /conflict 868452f666fea1c60ffb918ad9ad9607 file /local "" aa33e614b5e749449f230e2a2b0072eb conflict /local 3df93e64043c8e348fc625b93ea220f4 file /local-already "" 0298b958a603049f45ae6a109c4f7fea +missing /local-remove # Now test with -F. build_trees -etcupdate -rF -d $WORKDIR -D $TEST > $WORKDIR/testF.out +$COMMAND -rF -d $WORKDIR -D $TEST > $WORKDIR/testF.out cat > $WORKDIR/correctF.out <<EOF D /remove @@ -325,3 +342,38 @@ file /conflict "" dc27978df125b0daeb7d9b93265f03fd conflict /conflict 868452f666fea1c60ffb918ad9ad9607 file /local "" 3ed5a35e380c8a93fb5f599d4c052713 file /local-already "" 0298b958a603049f45ae6a109c4f7fea +missing /local-remove + +# Now test with -F and -A forcing all installs. (-A should have +# precedence over -F) + +build_trees + +$COMMAND -A '/*' -rF -d $WORKDIR -D $TEST > $WORKDIR/testAF.out + +cat > $WORKDIR/correctAF.out <<EOF + D /remove + U /already + U /conflict + U /local + U /local-already + A /local-remove + U /old + U /add +EOF + +echo "Differences for -A '/*' -F:" +diff -u -L "correct" $WORKDIR/correctAF.out -L "test" $WORKDIR/testAF.out + +missing /remove +file /old "" 6a9f34f109d94406a4de3bc5d72de259 +noconflict /old +file /already "" 21f4eca3aacc702c49878c8da7afd3d0 +noconflict /already +file /add "" 0208bd647111fedf6318511712ab9e97 +noconflict /add +file /conflict "" 75ee141c4136beaf14e39de92efa84e4 +noconflict /conflict +file /local "" 6a8fc5c2755b7a49015089f5e1dbe092 +file /local-already "" 49045f8b51542dd634655301cd296f66 +file /local-remove "" 5c38322efed4014797d7127f5c652d9d diff --git a/tools/regression/usr.sbin/etcupdate/ignore.sh b/tools/regression/usr.sbin/etcupdate/ignore.sh index e2249fb..d6bd2ff 100755 --- a/tools/regression/usr.sbin/etcupdate/ignore.sh +++ b/tools/regression/usr.sbin/etcupdate/ignore.sh @@ -33,13 +33,17 @@ WORKDIR=work usage() { - echo "Usage: ignore.sh [-w workdir]" + echo "Usage: ignore.sh [-s script] [-w workdir]" exit 1 } -# Allow the user to specify an alternate work directory. -while getopts "w:" option; do +# Allow the user to specify an alternate work directory or script. +COMMAND=etcupdate +while getopts "s:w:" option; do case $option in + s) + COMMAND="sh $OPTARG" + ;; w) WORKDIR=$OPTARG ;; @@ -172,7 +176,7 @@ fi build_trees -etcupdate -r -d $WORKDIR -D $TEST > $WORKDIR/test.out +$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out cat > $WORKDIR/correct.out <<EOF D /rmdir/file @@ -195,7 +199,7 @@ missing /rmdir build_trees -etcupdate -r -I '/tree/*' -d $WORKDIR -D $TEST > $WORKDIR/test1.out +$COMMAND -r -I '/tree/*' -d $WORKDIR -D $TEST > $WORKDIR/test1.out cat > $WORKDIR/correct1.out <<EOF D /rmdir/file @@ -215,7 +219,7 @@ missing /rmdir build_trees -etcupdate -r -I '/tree/*' -I '/rmdir*' -d $WORKDIR -D $TEST > \ +$COMMAND -r -I '/tree/*' -I '/rmdir*' -d $WORKDIR -D $TEST > \ $WORKDIR/test2.out cat > $WORKDIR/correct2.out <<EOF @@ -236,7 +240,7 @@ file /rmdir/file "foo" build_trees -etcupdate -r -I '/tree/* /rmdir/*' -d $WORKDIR -D $TEST > \ +$COMMAND -r -I '/tree/* /rmdir/*' -d $WORKDIR -D $TEST > \ $WORKDIR/test3.out cat > $WORKDIR/correct3.out <<EOF diff --git a/tools/regression/usr.sbin/etcupdate/preworld.sh b/tools/regression/usr.sbin/etcupdate/preworld.sh new file mode 100755 index 0000000..ccd7b75 --- /dev/null +++ b/tools/regression/usr.sbin/etcupdate/preworld.sh @@ -0,0 +1,239 @@ +#!/bin/sh +# +# Copyright (c) 2013 Advanced Computing Technologies LLC +# Written by: John H. Baldwin <jhb@FreeBSD.org> +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# Regression tests for the pre-world (-p) mode + +WORKDIR=work + +usage() +{ + echo "Usage: preworld.sh [-s script] [-w workdir]" + exit 1 +} + +# Allow the user to specify an alternate work directory or script. +COMMAND=etcupdate +while getopts "s:w:" option; do + case $option in + s) + COMMAND="sh $OPTARG" + ;; + w) + WORKDIR=$OPTARG + ;; + *) + echo + usage + ;; + esac +done +shift $((OPTIND - 1)) +if [ $# -ne 0 ]; then + usage +fi + +CONFLICTS=$WORKDIR/conflicts +SRC=$WORKDIR/src +OLD=$WORKDIR/current +TEST=$WORKDIR/test + +build_trees() +{ + + # Populate trees with pre-world files and additional files + # that should not be touched. + + rm -rf $SRC $OLD $TEST $CONFLICTS + + # Create the "old" source tree as the starting point + mkdir -p $OLD/etc + cat >> $OLD/etc/master.passwd <<EOF +# +root::0:0::0:0:Charlie &:/root:/bin/csh +toor:*:0:0::0:0:Bourne-again Superuser:/root: +daemon:*:1:1::0:0:Owner of many system processes:/root:/usr/sbin/nologin +operator:*:2:5::0:0:System &:/:/usr/sbin/nologin +_dhcp:*:65:65::0:0:dhcp programs:/var/empty:/usr/sbin/nologin +uucp:*:66:66::0:0:UUCP pseudo-user:/var/spool/uucppublic:/usr/local/libexec/uucp/uucico +pop:*:68:6::0:0:Post Office Owner:/nonexistent:/usr/sbin/nologin +www:*:80:80::0:0:World Wide Web Owner:/nonexistent:/usr/sbin/nologin +hast:*:845:845::0:0:HAST unprivileged user:/var/empty:/usr/sbin/nologin +nobody:*:65534:65534::0:0:Unprivileged user:/nonexistent:/usr/sbin/nologin +EOF + cat >> $OLD/etc/group <<EOF +# +wheel:*:0:root +daemon:*:1: +kmem:*:2: +sys:*:3: +tty:*:4: +operator:*:5:root +_dhcp:*:65: +uucp:*:66: +dialer:*:68: +network:*:69: +www:*:80: +hast:*:845: +nogroup:*:65533: +nobody:*:65534: +EOF + cat >> $OLD/etc/inetd.conf <<EOF +# Yet another file +EOF + + # Copy the "old" source tree to the test tree and make local + # modifications. + cp -R $OLD $TEST + sed -I "" -e 's/root::/root:<rpass>:/' $TEST/etc/master.passwd + cat >> $TEST/etc/master.passwd <<EOF +john:<password>:1001:1001::0:0:John Baldwin:/home/john:/bin/tcsh +messagebus:*:556:556::0:0:D-BUS Daemon User:/nonexistent:/usr/sbin/nologin +polkit:*:562:562::0:0:PolicyKit User:/nonexistent:/usr/sbin/nologin +haldaemon:*:560:560::0:0:HAL Daemon User:/nonexistent:/usr/sbin/nologin +EOF + awk '/wheel/ { printf "%s,john\n", $0; next } // { print }' \ + $OLD/etc/group > $TEST/etc/group + cat >> $TEST/etc/group <<EOF +john:*:1001: +messagebus:*:556: +polkit:*:562: +haldaemon:*:560: +EOF + rm $TEST/etc/inetd.conf + touch $TEST/etc/localtime + + # Copy the "old" source tree to the new source tree and + # make upstream modifications. + cp -R $OLD $SRC + sed -I "" -e '/:80:/i\ +auditdistd:*:78:77::0:0:Auditdistd unprivileged user:/var/empty:/usr/sbin/nologin' \ + $SRC/etc/master.passwd + sed -I "" -e '/:80:/i\ +audit:*:77:' \ + $SRC/etc/group + cat >> $SRC/etc/inetd.conf <<EOF +# Making this larger +EOF +} + +# $1 - relative path to file that should be missing from TEST +missing() +{ + if [ -e $TEST/$1 -o -L $TEST/$1 ]; then + echo "File $1 should be missing" + fi +} + +# $1 - relative path to file that should be present in TEST +present() +{ + if ! [ -e $TEST/$1 -o -L $TEST/$1 ]; then + echo "File $1 should be present" + fi +} + +# $1 - relative path to regular file that should be present in TEST +# $2 - optional string that should match file contents +# $3 - optional MD5 of the flie contents, overrides $2 if present +file() +{ + local contents sum + + if ! [ -f $TEST/$1 ]; then + echo "File $1 should be a regular file" + elif [ $# -eq 2 ]; then + contents=`cat $TEST/$1` + if [ "$contents" != "$2" ]; then + echo "File $1 has wrong contents" + fi + elif [ $# -eq 3 ]; then + sum=`md5 -q $TEST/$1` + if [ "$sum" != "$3" ]; then + echo "File $1 has wrong contents" + fi + fi +} + +# $1 - relative path to a regular file that should have a conflict +# $2 - optional MD5 of the conflict file contents +conflict() +{ + local sum + + if ! [ -f $CONFLICTS/$1 ]; then + echo "File $1 missing conflict" + elif [ $# -gt 1 ]; then + sum=`md5 -q $CONFLICTS/$1` + if [ "$sum" != "$2" ]; then + echo "Conflict $1 has wrong contents" + fi + fi +} + +check_trees() +{ + + echo "Checking tree for correct results:" + + file /etc/master.passwd "" 1385366e8b424d33d59b7d8a2bdb15d3 + file /etc/group "" 21273f845f6ec0cda9188c4ddac9ed47 + missing /etc/inetd.conf + + # These should be auto-generated by pwd_mkdb + file /etc/passwd "" 9831537874bdc99adccaa2b0293248a1 + file /etc/pwd.db + file /etc/spwd.db +} + +if [ `id -u` -ne 0 ]; then + echo "must be root" +fi + +if [ -r /etc/etcupdate.conf ]; then + echo "WARNING: /etc/etcupdate.conf settings may break some tests." +fi + +build_trees + +$COMMAND -np -s $SRC -d $WORKDIR -D $TEST > $WORKDIR/testn.out + +cat > $WORKDIR/correct.out <<EOF + M /etc/group + M /etc/master.passwd +EOF + +echo "Differences for -n:" +diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out + +$COMMAND -p -s $SRC -d $WORKDIR -D $TEST > $WORKDIR/test.out + +echo "Differences for real:" +diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out + +check_trees diff --git a/tools/regression/usr.sbin/etcupdate/tests.sh b/tools/regression/usr.sbin/etcupdate/tests.sh index 7983020..22b3d0b 100755 --- a/tools/regression/usr.sbin/etcupdate/tests.sh +++ b/tools/regression/usr.sbin/etcupdate/tests.sh @@ -33,13 +33,17 @@ WORKDIR=work usage() { - echo "Usage: tests.sh [-w workdir]" + echo "Usage: tests.sh [-s script] [-w workdir]" exit 1 } -# Allow the user to specify an alternate work directory. -while getopts "w:" option; do +# Allow the user to specify an alternate work directory or script. +COMMAND=etcupdate +while getopts "s:w:" option; do case $option in + s) + COMMAND="sh $OPTARG" + ;; w) WORKDIR=$OPTARG ;; @@ -624,6 +628,24 @@ root: someone@example.com MAILER-DAEMON: postmaster postmaster: root EOF + + # - Verify that updating an unmodified /etc/services builds + # /var/db/services.db. + cat > $OLD/etc/services <<EOF +rtmp 1/ddp #Routing Table Maintenance Protocol +tcpmux 1/tcp #TCP Port Service Multiplexer +tcpmux 1/udp #TCP Port Service Multiplexer +EOF + cat > $NEW/etc/services <<EOF +rtmp 1/ddp #Routing Table Maintenance Protocol +tcpmux 1/tcp #TCP Port Service Multiplexer +tcpmux 1/udp #TCP Port Service Multiplexer +nbp 2/ddp #Name Binding Protocol +compressnet 2/tcp #Management Utility +compressnet 2/udp #Management Utility +EOF + cp $OLD/etc/services $TEST/etc/services + mkdir -p $TEST/var/db } # $1 - relative path to file that should be missing from TEST @@ -892,6 +914,8 @@ check_trees() file /etc/login.conf "" 7774a0f9a3a372c7c109c32fd31c4b6b file /etc/login.conf.db file /etc/mail/aliases "" 7d598f89ec040ab56af54011bdb83337 + file /etc/services "" 37fb6a8d1273f3b78329d431f21d9c7d + file /var/db/services.db } if [ `id -u` -ne 0 ]; then @@ -904,7 +928,7 @@ fi build_trees -etcupdate -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out +$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out cat > $WORKDIR/correct.out <<EOF D /dirchange/fromdir/extradir/file @@ -930,6 +954,7 @@ cat > $WORKDIR/correct.out <<EOF U /dirchange/old/todir U /etc/login.conf M /etc/mail/aliases + U /etc/services A /adddir/partial/file A /dirchange/old/todir/file A /etc/master.passwd @@ -971,7 +996,7 @@ EOF echo "Differences for -n:" diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out -etcupdate -r -d $WORKDIR -D $TEST > $WORKDIR/test.out +$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out echo "Differences for real:" diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out diff --git a/tools/regression/usr.sbin/etcupdate/tzsetup.sh b/tools/regression/usr.sbin/etcupdate/tzsetup.sh new file mode 100755 index 0000000..20107f4 --- /dev/null +++ b/tools/regression/usr.sbin/etcupdate/tzsetup.sh @@ -0,0 +1,221 @@ +#!/bin/sh +# +# Copyright (c) 2013 Advanced Computing Technologies LLC +# Written by: John H. Baldwin <jhb@FreeBSD.org> +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# Various regression tests for the tzsetup handling in the 'update' command. + +WORKDIR=work + +usage() +{ + echo "Usage: tzsetup.sh [-s script] [-w workdir]" + exit 1 +} + +# Allow the user to specify an alternate work directory or script. +COMMAND=etcupdate +while getopts "s:w:" option; do + case $option in + s) + COMMAND="sh $OPTARG" + ;; + w) + WORKDIR=$OPTARG + ;; + *) + echo + usage + ;; + esac +done +shift $((OPTIND - 1)) +if [ $# -ne 0 ]; then + usage +fi + +CONFLICTS=$WORKDIR/conflicts +OLD=$WORKDIR/old +NEW=$WORKDIR/current +TEST=$WORKDIR/test + +build_trees() +{ + + # Build the base tree, but not /etc/localtime itself + local i j k + + rm -rf $OLD $NEW $TEST $CONFLICTS + mkdir -p $OLD $NEW $TEST + mkdir -p $TEST/etc + mkdir -p $TEST/var/db + mkdir -p $TEST/usr/share/zoneinfo + + # Create a dummy timezone file + echo "foo" > $TEST/usr/share/zoneinfo/foo + +} + +# $1 - relative path to file that should be missing from TEST +missing() +{ + if [ -e $TEST/$1 -o -L $TEST/$1 ]; then + echo "File $1 should be missing" + fi +} + +# $1 - relative path to file that should be a symlink in TEST +# $2 - optional value of the link +link() +{ + local val + + if ! [ -L $TEST/$1 ]; then + echo "File $1 should be a link" + elif [ $# -gt 1 ]; then + val=`readlink $TEST/$1` + if [ "$val" != "$2" ]; then + echo "Link $1 should link to \"$2\"" + fi + fi +} + +# $1 - relative path to regular file that should be present in TEST +# $2 - optional string that should match file contents +# $3 - optional MD5 of the flie contents, overrides $2 if present +file() +{ + local contents sum + + if ! [ -f $TEST/$1 ]; then + echo "File $1 should be a regular file" + elif [ $# -eq 2 ]; then + contents=`cat $TEST/$1` + if [ "$contents" != "$2" ]; then + echo "File $1 has wrong contents" + fi + elif [ $# -eq 3 ]; then + sum=`md5 -q $TEST/$1` + if [ "$sum" != "$3" ]; then + echo "File $1 has wrong contents" + fi + fi +} + +if [ `id -u` -ne 0 ]; then + echo "must be root" +fi + +if [ -r /etc/etcupdate.conf ]; then + echo "WARNING: /etc/etcupdate.conf settings may break some tests." +fi + +# First, test for /etc/localtime not existing + +build_trees + +$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out + +cat > $WORKDIR/correct.out <<EOF +EOF + +echo "Differences for no /etc/localtime with -n:" +diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out + +$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out + +echo "Differences for no /etc/localtime:" +diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out + +missing /etc/localtime +missing /var/db/zoneinfo + +# Second, test for /etc/localtime being a symlink + +build_trees +ln -s /dev/null $TEST/etc/localtime + +$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out + +cat > $WORKDIR/correct.out <<EOF +EOF + +echo "Differences for symlinked /etc/localtime with -n:" +diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out + +$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out + +echo "Differences for symlinked /etc/localtime:" +diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out + +link /etc/localtime "/dev/null" +missing /var/db/zoneinfo + +# Third, test for /etc/localtime as a file and a missing /var/db/zoneinfo + +build_trees +echo "bar" > $TEST/etc/localtime + +$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out + +cat > $WORKDIR/correct.out <<EOF +Warnings: + Needs update: /etc/localtime (required manual update via tzsetup(1)) +EOF + +echo "Differences for missing /var/db/zoneinfo with -n:" +diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out + +$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out + +echo "Differences for missing /var/db/zoneinfo:" +diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out + +file /etc/localtime "bar" +missing /var/db/zoneinfo + +# Finally, test the case where it should update /etc/localtime + +build_trees +echo "bar" > $TEST/etc/localtime +echo "foo" > $TEST/var/db/zoneinfo + +$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out + +cat > $WORKDIR/correct.out <<EOF +EOF + +echo "Differences for real update with -n:" +diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out + +$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out + +echo "Differences for real update:" +diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out + +file /etc/localtime "foo" +file /var/db/zoneinfo "foo" |