4 # Iterate over all the /proc/service entries, and
5 # for each restatability policy call the policy test function if it is
6 # supported. No accounting of failed / successful test is done, as a
7 # failed test can currently provoque cascading effects, so instead we
8 # fail the test as a whole on the first failure found. Live update tests
9 # are currently policy-agnostic.
11 # If arguments are given, use this instead of all entries found in
12 # /proc/service. Full path have to be provided on the command line, like
13 # /usr/tests/minix/testrelpol /proc/service/vfs
14 # to test vfs recovery only.
16 # Supported policies have to be in the POLICIES variable, and define a test
20 # - Currently not all recovery policies are tested
21 # - Running this test under X11 hangs the X server
22 # - Live update tests do not test rollback situations
24 # To add a new policy, you have to do the following:
25 # 1. Add the policy into the active policies array by:
26 # POLICIES="${POLICIES} <policyname>"
28 # 2. define the following shell function:
29 # pol_<policyname>() {}
30 # - it will recieve the following parameters:
31 # + service filename as $1 : the full path to the proc entry
32 # + label as $2 : the service label
33 # - which prints 'ok' on success, 'not ok' on failure.
35 # Currently known policies:
36 # /* user | endpoint */
37 # POL_RESET, /* visible | change */
38 # POL_RESTART /* transparent | preserved */
40 #######################################################################
41 # Utility functions & global state initializations
42 #######################################################################
44 MAX_RETRY
=7 # so that a single test takes at most 10 seconds
45 MAX_MULTI_LU_RETRY
=3 # how many times should we retry after bad luck?
47 # get_value(key, filename, noerror)
52 value
=$
(grep $1 $2 2>/dev
/null
)
57 echo $value | cut
-d: -f2
59 test -z "$3" && echo "Error: service $2 down" >&2
63 # wait_for_service(filename)
69 # Arbitrary timeout, found by counting the number of mice crossing
72 while test ${retry} -lt ${MAX_RETRY}
75 retry
=$
((${retry} + 1))
76 # The service might momentarily disappear from the list.
77 value
=$
(get_value restarts
$1 noerror
)
78 test -n "$value" && test $value -ne $2 && return 0
83 #######################################################################
84 # Service management routines
85 #######################################################################
92 flags
=$
(get_value flags
${service})
93 echo $flags |
grep -q 'r' ||
return 0
94 echo $flags |
grep -q 'R' && return 0
96 minix-service clone
$label
105 minix-service unclone
$label
108 #######################################################################
110 #######################################################################
111 POLICIES
="${POLICIES} restart"
114 local endpoint_pre endpoint_post
115 local restarts_pre restarts_post
120 restarts_pre
=$
(get_value restarts
${service})
121 endpoint_pre
=$
(get_value endpoint
${service})
123 minix-service
fi ${label}
124 if ! wait_for_service
${service} ${restarts_pre}
130 restarts_post
=$
(get_value restarts
${service})
131 endpoint_post
=$
(get_value endpoint
${service})
133 if [ ${restarts_post} -gt ${restarts_pre} \
134 -a ${endpoint_post} -eq ${endpoint_pre} ]
142 #######################################################################
144 #######################################################################
145 POLICIES
="${POLICIES} reset"
148 local endpoint_pre endpoint_post
149 local restarts_pre restarts_post
154 restarts_pre
=$
(get_value restarts
${service})
155 endpoint_pre
=$
(get_value endpoint
${service})
157 minix-service
fi ${label}
158 if ! wait_for_service
${service} ${restarts_pre}
164 restarts_post
=$
(get_value restarts
${service})
165 endpoint_post
=$
(get_value endpoint
${service})
167 # This policy doesn't guarantee the endpoint to be kept, but there
168 # is a slight chance that it will actualy stay the same, and fail
170 if [ ${restarts_post} -gt ${restarts_pre} \
171 -a ${endpoint_post} -ne ${endpoint_pre} ]
179 #######################################################################
181 #######################################################################
187 lu_maxtime
=${lu_maxtime:-3HZ}
188 lu_state
=${lu_state:-1}
190 minix-service
${lu_opts} update ${prog} -label ${label} -maxtime ${lu_maxtime} -state ${lu_state}
191 if [ $?
-ne $result ]
201 local endpoint_pre endpoint_post
202 local restarts_pre restarts_post
207 restarts_pre
=$
(get_value restarts
${service})
208 endpoint_pre
=$
(get_value endpoint
${service})
210 lu_test_one
${label} self
0 ||
return
212 # Test live update "prepare only"
213 if ! echo "pm rs vfs vm" |
grep -q ${label}
215 lu_opts
="-o" lu_test_one
${label} self
0 ||
return
218 # Test live update initialization crash
219 lu_opts
="-x" lu_test_one
${label} self
200 ||
return
221 # Test live update initialization failure
222 if ! echo "rs" |
grep -q ${label}
224 lu_opts
="-y" lu_test_one
${label} self
78 ||
return
227 # Test live update initialization timeout
228 if ! echo "rs" |
grep -q ${label}
230 lu_maxtime
="1HZ" lu_opts
="-z" lu_test_one
${label} self
4 ||
return
233 # Test live update from SEF_LU_STATE_EVAL state
234 lu_maxtime
="1HZ" lu_state
="5" lu_test_one
${label} self
4 ||
return
236 restarts_post
=$
(get_value restarts
${service})
237 endpoint_post
=$
(get_value endpoint
${service})
239 # Make sure endpoint and restarts are preserved
240 if [ ${restarts_post} -eq ${restarts_pre} \
241 -a ${endpoint_post} -eq ${endpoint_pre} ]
249 multi_lu_test_one
() {
259 lu_maxtime
=${lu_maxtime:-3HZ}
260 lu_state
=${lu_state:-1}
261 lu_opts_once
=${lu_opts_once:-$lu_opts}
262 lu_maxtime_once
=${lu_maxtime_once:-$lu_maxtime}
263 lu_state_once
=${lu_state_once:-$lu_state}
265 while [ $ret -eq 1 -a $retry -lt ${MAX_MULTI_LU_RETRY} ]
268 for label
in ${labels}
270 index
=`expr $index + 1`
272 if [ $index -eq $once_index ]
274 minix-service
${lu_opts_once} -q update self \
276 -maxtime ${lu_maxtime_once} \
277 -state ${lu_state_once} || ret
=2
279 minix-service
${lu_opts} -q update self \
281 -maxtime ${lu_maxtime} \
282 -state ${lu_state} || ret
=2
285 minix-service sysctl upd_run
288 # We may experience transient failures as a result of services
289 # trying to talk to each other while being prepared for the
290 # live update. In that case we get result code 4. If that is
291 # not the result code we expected, try again for a limited
293 if [ $result -eq $expected ]
296 elif [ $result -ne 4 ]
300 retry
=`expr $retry + 1`
307 local y_result z_result
311 # Some of the results depend on whether RS is part of the live update.
312 for label
in ${labels}
314 if [ "x$label" = "xrs" ]
320 if [ $have_rs -eq 1 ]
329 multi_lu_test_one
0 0 ${labels} ||
return 1
330 lu_opts_once
="-x" multi_lu_test_one
200 2 ${labels} ||
return 1
331 lu_opts_once
="-y" multi_lu_test_one
${y_result} 3 ${labels} ||
return 1
332 lu_maxtime_once
="1HZ" lu_opts_once
="-z" multi_lu_test_one
${z_result} 2 ${labels} ||
return 1
333 lu_maxtime_once
="1HZ" lu_state_once
="5" multi_lu_test_one
4 3 ${labels} ||
return 1
338 multi_lu_test_wrapper
() {
339 echo "# testing $@ :: multicomponent live update+rollback"
340 if ! multi_lu_test
"$@"
342 echo "not ok # failed multicomponent live update+rollback"
348 #######################################################################
350 #######################################################################
352 local labels service_policies X11
354 # If there is a running X server, skip the input driver
355 if ps
-ef |
grep -v grep |
grep -q /usr
/X11R
7/bin
/X
357 echo "# This test can't be run while a Xserver is running"
358 echo "not ok # A Xserver is running"
364 services
=$
(echo /proc
/service
/*)
369 for service
in ${services}
371 label
=$
(basename ${service})
372 service_policies
=$
(grep policies
${service}|cut
-d: -f2)
373 for pol
in ${service_policies}
375 # Check if the supported policy is under test
376 if echo "${POLICIES}" |
grep -q ${pol}
378 echo "# testing ${label} :: ${pol}"
380 prepare_service
${service} ${label} || cleanup
=1
381 result
=$
(pol_
${pol} ${service} ${label})
382 if [ "x${result}" != "xok" ]
384 echo "not ok # failed ${label}, ${pol}"
387 if [ $cleanup -eq 1 ]
389 cleanup_service
${label}
396 echo "ok # partial test for $@ successful"
401 for service
in ${services}
403 label
=$
(basename ${service})
404 service_policies
=$
(grep policies
${service}|cut
-d: -f2)
405 if echo "${service_policies}" |
grep -q "[a-zA-Z]"
407 echo "# testing ${label} :: live update+rollback"
408 result
=$
(lu_test
${service} ${label})
409 if [ "x${result}" != "xok" ]
411 echo "not ok # failed ${label}, live update+rollback"
414 if [ "x${label}" = "xrs" -o "x${label}" = "xvm" ]
418 service_flags
=$
(get_value flags
${service})
419 if echo $service_flags |
grep -q 's'
421 multi_lu_labels
="${multi_lu_labels} ${label}"
426 multi_lu_test_wrapper
${multi_lu_labels} ||
exit 1
427 multi_lu_test_wrapper
${multi_lu_labels} vm ||
exit 1
428 multi_lu_test_wrapper
${multi_lu_labels} rs ||
exit 1
429 multi_lu_test_wrapper
${multi_lu_labels} vm rs ||
exit 1