Deleted Added
full compact
tzsetup_test.sh (259134) tzsetup_test.sh (263221)
1#!/bin/sh
2#
3# Copyright (c) 2013 Advanced Computing Technologies LLC
4# Written by: John H. Baldwin <jhb@FreeBSD.org>
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions

--- 11 unchanged lines hidden (view full) ---

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
26# SUCH DAMAGE.
27#
1#!/bin/sh
2#
3# Copyright (c) 2013 Advanced Computing Technologies LLC
4# Written by: John H. Baldwin <jhb@FreeBSD.org>
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions

--- 11 unchanged lines hidden (view full) ---

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
26# SUCH DAMAGE.
27#
28# $FreeBSD: head/tools/regression/usr.sbin/etcupdate/tzsetup.sh 259134 2013-12-09 19:31:30Z jhb $
28# $FreeBSD: head/tools/regression/usr.sbin/etcupdate/tzsetup.sh 263221 2014-03-16 02:27:27Z jmmv $
29
30# Various regression tests for the tzsetup handling in the 'update' command.
31
29
30# Various regression tests for the tzsetup handling in the 'update' command.
31
32FAILED=no
32WORKDIR=work
33
34usage()
35{
36 echo "Usage: tzsetup.sh [-s script] [-w workdir]"
37 exit 1
38}
39

--- 40 unchanged lines hidden (view full) ---

80
81}
82
83# $1 - relative path to file that should be missing from TEST
84missing()
85{
86 if [ -e $TEST/$1 -o -L $TEST/$1 ]; then
87 echo "File $1 should be missing"
33WORKDIR=work
34
35usage()
36{
37 echo "Usage: tzsetup.sh [-s script] [-w workdir]"
38 exit 1
39}
40

--- 40 unchanged lines hidden (view full) ---

81
82}
83
84# $1 - relative path to file that should be missing from TEST
85missing()
86{
87 if [ -e $TEST/$1 -o -L $TEST/$1 ]; then
88 echo "File $1 should be missing"
89 FAILED=yes
88 fi
89}
90
91# $1 - relative path to file that should be a symlink in TEST
92# $2 - optional value of the link
93link()
94{
95 local val
96
97 if ! [ -L $TEST/$1 ]; then
98 echo "File $1 should be a link"
90 fi
91}
92
93# $1 - relative path to file that should be a symlink in TEST
94# $2 - optional value of the link
95link()
96{
97 local val
98
99 if ! [ -L $TEST/$1 ]; then
100 echo "File $1 should be a link"
101 FAILED=yes
99 elif [ $# -gt 1 ]; then
100 val=`readlink $TEST/$1`
101 if [ "$val" != "$2" ]; then
102 echo "Link $1 should link to \"$2\""
102 elif [ $# -gt 1 ]; then
103 val=`readlink $TEST/$1`
104 if [ "$val" != "$2" ]; then
105 echo "Link $1 should link to \"$2\""
106 FAILED=yes
103 fi
104 fi
105}
106
107# $1 - relative path to regular file that should be present in TEST
108# $2 - optional string that should match file contents
109# $3 - optional MD5 of the flie contents, overrides $2 if present
110file()
111{
112 local contents sum
113
114 if ! [ -f $TEST/$1 ]; then
115 echo "File $1 should be a regular file"
107 fi
108 fi
109}
110
111# $1 - relative path to regular file that should be present in TEST
112# $2 - optional string that should match file contents
113# $3 - optional MD5 of the flie contents, overrides $2 if present
114file()
115{
116 local contents sum
117
118 if ! [ -f $TEST/$1 ]; then
119 echo "File $1 should be a regular file"
120 FAILED=yes
116 elif [ $# -eq 2 ]; then
117 contents=`cat $TEST/$1`
118 if [ "$contents" != "$2" ]; then
119 echo "File $1 has wrong contents"
121 elif [ $# -eq 2 ]; then
122 contents=`cat $TEST/$1`
123 if [ "$contents" != "$2" ]; then
124 echo "File $1 has wrong contents"
125 FAILED=yes
120 fi
121 elif [ $# -eq 3 ]; then
122 sum=`md5 -q $TEST/$1`
123 if [ "$sum" != "$3" ]; then
124 echo "File $1 has wrong contents"
126 fi
127 elif [ $# -eq 3 ]; then
128 sum=`md5 -q $TEST/$1`
129 if [ "$sum" != "$3" ]; then
130 echo "File $1 has wrong contents"
131 FAILED=yes
125 fi
126 fi
127}
128
129if [ `id -u` -ne 0 ]; then
130 echo "must be root"
132 fi
133 fi
134}
135
136if [ `id -u` -ne 0 ]; then
137 echo "must be root"
138 exit 0
131fi
132
133if [ -r /etc/etcupdate.conf ]; then
134 echo "WARNING: /etc/etcupdate.conf settings may break some tests."
135fi
136
137# First, test for /etc/localtime not existing
138
139build_trees
140
141$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out
142
143cat > $WORKDIR/correct.out <<EOF
144EOF
145
146echo "Differences for no /etc/localtime with -n:"
139fi
140
141if [ -r /etc/etcupdate.conf ]; then
142 echo "WARNING: /etc/etcupdate.conf settings may break some tests."
143fi
144
145# First, test for /etc/localtime not existing
146
147build_trees
148
149$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out
150
151cat > $WORKDIR/correct.out <<EOF
152EOF
153
154echo "Differences for no /etc/localtime with -n:"
147diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out
155diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out \
156 || FAILED=yes
148
149$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
150
151echo "Differences for no /etc/localtime:"
157
158$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
159
160echo "Differences for no /etc/localtime:"
152diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out
161diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out \
162 || FAILED=yes
153
154missing /etc/localtime
155missing /var/db/zoneinfo
156
157# Second, test for /etc/localtime being a symlink
158
159build_trees
160ln -s /dev/null $TEST/etc/localtime
161
162$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out
163
164cat > $WORKDIR/correct.out <<EOF
165EOF
166
167echo "Differences for symlinked /etc/localtime with -n:"
163
164missing /etc/localtime
165missing /var/db/zoneinfo
166
167# Second, test for /etc/localtime being a symlink
168
169build_trees
170ln -s /dev/null $TEST/etc/localtime
171
172$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out
173
174cat > $WORKDIR/correct.out <<EOF
175EOF
176
177echo "Differences for symlinked /etc/localtime with -n:"
168diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out
178diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out \
179 || FAILED=yes
169
170$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
171
172echo "Differences for symlinked /etc/localtime:"
180
181$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
182
183echo "Differences for symlinked /etc/localtime:"
173diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out
184diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out \
185 || FAILED=yes
174
175link /etc/localtime "/dev/null"
176missing /var/db/zoneinfo
177
178# Third, test for /etc/localtime as a file and a missing /var/db/zoneinfo
179
180build_trees
181echo "bar" > $TEST/etc/localtime
182
183$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out
184
185cat > $WORKDIR/correct.out <<EOF
186Warnings:
187 Needs update: /etc/localtime (required manual update via tzsetup(1))
188EOF
189
190echo "Differences for missing /var/db/zoneinfo with -n:"
186
187link /etc/localtime "/dev/null"
188missing /var/db/zoneinfo
189
190# Third, test for /etc/localtime as a file and a missing /var/db/zoneinfo
191
192build_trees
193echo "bar" > $TEST/etc/localtime
194
195$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out
196
197cat > $WORKDIR/correct.out <<EOF
198Warnings:
199 Needs update: /etc/localtime (required manual update via tzsetup(1))
200EOF
201
202echo "Differences for missing /var/db/zoneinfo with -n:"
191diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out
203diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out \
204 || FAILED=yes
192
193$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
194
195echo "Differences for missing /var/db/zoneinfo:"
205
206$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
207
208echo "Differences for missing /var/db/zoneinfo:"
196diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out
209diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out \
210 || FAILED=yes
197
198file /etc/localtime "bar"
199missing /var/db/zoneinfo
200
201# Finally, test the case where it should update /etc/localtime
202
203build_trees
204echo "bar" > $TEST/etc/localtime
205echo "foo" > $TEST/var/db/zoneinfo
206
207$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out
208
209cat > $WORKDIR/correct.out <<EOF
210EOF
211
212echo "Differences for real update with -n:"
211
212file /etc/localtime "bar"
213missing /var/db/zoneinfo
214
215# Finally, test the case where it should update /etc/localtime
216
217build_trees
218echo "bar" > $TEST/etc/localtime
219echo "foo" > $TEST/var/db/zoneinfo
220
221$COMMAND -nr -d $WORKDIR -D $TEST > $WORKDIR/testn.out
222
223cat > $WORKDIR/correct.out <<EOF
224EOF
225
226echo "Differences for real update with -n:"
213diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out
227diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/testn.out \
228 || FAILED=yes
214
215$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
216
217echo "Differences for real update:"
229
230$COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
231
232echo "Differences for real update:"
218diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out
233diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out \
234 || FAILED=yes
219
220file /etc/localtime "foo"
221file /var/db/zoneinfo "foo"
235
236file /etc/localtime "foo"
237file /var/db/zoneinfo "foo"
238
239[ "${FAILED}" = no ]