]>
Commit | Line | Data |
---|---|---|
6bf19c94 CH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (C) 2009 Red Hat, Inc. | |
4 | # Copyright (c) 2000-2006 Silicon Graphics, Inc. All Rights Reserved. | |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 2 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 | # USA | |
20 | # | |
21 | ||
22 | dd() | |
23 | { | |
24 | if [ "$HOSTOS" == "Linux" ] | |
25 | then | |
26 | command dd --help | grep noxfer > /dev/null 2>&1 | |
27 | ||
28 | if [ "$?" -eq 0 ] | |
29 | then | |
30 | command dd status=noxfer $@ | |
31 | else | |
32 | command dd $@ | |
33 | fi | |
34 | else | |
35 | command dd $@ | |
36 | fi | |
37 | } | |
38 | ||
39 | # we need common.config | |
40 | if [ "$iam" != "check" ] | |
41 | then | |
42 | if ! . ./common.config | |
43 | then | |
44 | echo "$iam: failed to source common.config" | |
45 | exit 1 | |
46 | fi | |
47 | fi | |
48 | ||
49 | # make sure we have a standard umask | |
50 | umask 022 | |
51 | ||
52 | TEST_IMG=$TEST_DIR/t.$IMGFMT | |
53 | ||
54 | _make_test_img() | |
55 | { | |
56 | # extra qemu-img options can be added by tests | |
57 | # at least one argument (the image size) needs to be added | |
58 | local extra_img_options=$* | |
59 | ||
60 | # XXX(hch): have global image options? | |
61 | $QEMU_IMG create -f $IMGFMT $TEST_IMG $extra_img_options | \ | |
62 | sed -e "s#$TEST_DIR#TEST_DIR#g" | \ | |
63 | sed -e "s#$IMGFMT#IMGFMT#g" | \ | |
64 | sed -e "s# encryption=off##g" | \ | |
65 | sed -e "s# cluster_size=0##g" | \ | |
66 | sed -e "s# compat6=off##g" | |
67 | ||
68 | } | |
69 | ||
70 | _cleanup_test_img() | |
71 | { | |
72 | rm -f $TEST_DIR/t.$IMGFMT | |
73 | rm -f $TEST_DIR/t.$IMGFMT.orig | |
2557d865 | 74 | rm -f $TEST_DIR/t.$IMGFMT.base |
6bf19c94 CH |
75 | } |
76 | ||
77 | _check_test_img() | |
78 | { | |
e76a8e89 CH |
79 | $QEMU_IMG check -f $IMGFMT $TEST_IMG 2>&1 | \ |
80 | sed -e 's/qemu-img\: This image format does not support checks/No errors were found on the image./' | |
6bf19c94 CH |
81 | } |
82 | ||
83 | _get_pids_by_name() | |
84 | { | |
85 | if [ $# -ne 1 ] | |
86 | then | |
87 | echo "Usage: _get_pids_by_name process-name" 1>&2 | |
88 | exit 1 | |
89 | fi | |
90 | ||
91 | # Algorithm ... all ps(1) variants have a time of the form MM:SS or | |
92 | # HH:MM:SS before the psargs field, use this as the search anchor. | |
93 | # | |
94 | # Matches with $1 (process-name) occur if the first psarg is $1 | |
95 | # or ends in /$1 ... the matching uses sed's regular expressions, | |
96 | # so passing a regex into $1 will work. | |
97 | ||
98 | ps $PS_ALL_FLAGS \ | |
99 | | sed -n \ | |
100 | -e 's/$/ /' \ | |
101 | -e 's/[ ][ ]*/ /g' \ | |
102 | -e 's/^ //' \ | |
103 | -e 's/^[^ ]* //' \ | |
104 | -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \ | |
105 | -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p" | |
106 | } | |
107 | ||
108 | # fqdn for localhost | |
109 | # | |
110 | _get_fqdn() | |
111 | { | |
112 | host=`hostname` | |
113 | $NSLOOKUP_PROG $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }' | |
114 | } | |
115 | ||
116 | # check if run as root | |
117 | # | |
118 | _need_to_be_root() | |
119 | { | |
120 | id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'` | |
121 | if [ "$id" -ne 0 ] | |
122 | then | |
123 | echo "Arrgh ... you need to be root (not uid=$id) to run this test" | |
124 | exit 1 | |
125 | fi | |
126 | } | |
127 | ||
128 | ||
129 | # Do a command, log it to $seq.full, optionally test return status | |
130 | # and die if command fails. If called with one argument _do executes the | |
131 | # command, logs it, and returns its exit status. With two arguments _do | |
132 | # first prints the message passed in the first argument, and then "done" | |
133 | # or "fail" depending on the return status of the command passed in the | |
134 | # second argument. If the command fails and the variable _do_die_on_error | |
135 | # is set to "always" or the two argument form is used and _do_die_on_error | |
136 | # is set to "message_only" _do will print an error message to | |
137 | # $seq.out and exit. | |
138 | ||
139 | _do() | |
140 | { | |
141 | if [ $# -eq 1 ]; then | |
142 | _cmd=$1 | |
143 | elif [ $# -eq 2 ]; then | |
144 | _note=$1 | |
145 | _cmd=$2 | |
146 | echo -n "$_note... " | |
147 | else | |
148 | echo "Usage: _do [note] cmd" 1>&2 | |
149 | status=1; exit | |
150 | fi | |
151 | ||
152 | (eval "echo '---' \"$_cmd\"") >>$here/$seq.full | |
153 | (eval "$_cmd") >$tmp._out 2>&1; ret=$? | |
154 | cat $tmp._out >>$here/$seq.full | |
155 | if [ $# -eq 2 ]; then | |
156 | if [ $ret -eq 0 ]; then | |
157 | echo "done" | |
158 | else | |
159 | echo "fail" | |
160 | fi | |
161 | fi | |
162 | if [ $ret -ne 0 ] \ | |
163 | && [ "$_do_die_on_error" = "always" \ | |
164 | -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ] | |
165 | then | |
166 | [ $# -ne 2 ] && echo | |
167 | eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full" | |
168 | status=1; exit | |
169 | fi | |
170 | ||
171 | return $ret | |
172 | } | |
173 | ||
174 | # bail out, setting up .notrun file | |
175 | # | |
176 | _notrun() | |
177 | { | |
178 | echo "$*" >$seq.notrun | |
179 | echo "$seq not run: $*" | |
180 | status=0 | |
181 | exit | |
182 | } | |
183 | ||
184 | # just plain bail out | |
185 | # | |
186 | _fail() | |
187 | { | |
188 | echo "$*" | tee -a $here/$seq.full | |
189 | echo "(see $seq.full for details)" | |
190 | status=1 | |
191 | exit 1 | |
192 | } | |
193 | ||
194 | # tests whether $IMGFMT is one of the supported image formats for a test | |
195 | # | |
196 | _supported_fmt() | |
197 | { | |
198 | for f; do | |
199 | if [ "$f" = "$IMGFMT" -o "$f" = "generic" ]; then | |
200 | return | |
201 | fi | |
202 | done | |
203 | ||
204 | _notrun "not suitable for this image format: $IMGFMT" | |
205 | } | |
206 | ||
207 | # tests whether the host OS is one of the supported OSes for a test | |
208 | # | |
209 | _supported_os() | |
210 | { | |
211 | for h | |
212 | do | |
213 | if [ "$h" = "$HOSTOS" ] | |
214 | then | |
215 | return | |
216 | fi | |
217 | done | |
218 | ||
219 | _notrun "not suitable for this OS: $HOSTOS" | |
220 | } | |
221 | ||
222 | # this test requires that a specified command (executable) exists | |
223 | # | |
224 | _require_command() | |
225 | { | |
226 | [ -x "$1" ] || _notrun "$1 utility required, skipped this test" | |
227 | } | |
228 | ||
229 | _full_imgfmt_details() | |
230 | { | |
231 | echo "$IMGFMT" | |
232 | } | |
233 | ||
234 | _full_platform_details() | |
235 | { | |
236 | os=`uname -s` | |
237 | host=`hostname -s` | |
238 | kernel=`uname -r` | |
239 | platform=`uname -m` | |
240 | echo "$os/$platform $host $kernel" | |
241 | } | |
242 | ||
243 | _link_out_file() | |
244 | { | |
245 | if [ -z "$1" ]; then | |
246 | echo Error must pass \$seq. | |
247 | exit | |
248 | fi | |
249 | rm -f $1 | |
250 | if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then | |
251 | ln -s $1.irix $1 | |
252 | elif [ "`uname`" == "Linux" ]; then | |
253 | ln -s $1.linux $1 | |
254 | else | |
255 | echo Error test $seq does not run on the operating system: `uname` | |
256 | exit | |
257 | fi | |
258 | } | |
259 | ||
260 | _die() | |
261 | { | |
262 | echo $@ | |
263 | exit 1 | |
264 | } | |
265 | ||
266 | # make sure this script returns success | |
267 | /bin/true |