@@ -129,19 +129,12 @@ held_by() {
done
}
-# System uptime in seconds.
-uptime_s() {
- local a b
-
- echo "$(</proc/uptime)" | { read -r a b && echo "${a%%.*}"; }
-}
-
# Sleep until either $1 seconds have elapsed or until the deadline $2 has been
# reached. Return 1 if and only if the deadline has been met.
sleep_until() {
local duration=$1 deadline=$2 u
- u=$(uptime_s)
+ u=$(_uptime_s)
if [ $((u + duration)) -le "$deadline" ]; then
sleep "$duration"
else
@@ -246,3 +246,8 @@ _test_dev_is_partition() {
_filter_xfs_io_error() {
sed -e 's/^\(.*\)64\(: .*$\)/\1\2/'
}
+
+# System uptime in seconds.
+_uptime_s() {
+ awk '{ print int($1) }' /proc/uptime
+}
@@ -113,7 +113,7 @@ simulate_network_failure_loop() {
[ -e "$dev" ] || return $?
[ -n "$duration" ] || return $?
- deadline=$(($(uptime_s) + duration))
+ deadline=$(($(_uptime_s) + duration))
while [ $rc = 0 ]; do
sleep_until 5 ${deadline} || break
for d in $(held_by "$dev"); do
@@ -69,7 +69,7 @@ sg_reset_loop() {
[ -e "$dev" ] || return $?
[ -n "$duration" ] || return $?
reset_type=(-d -b)
- deadline=$(($(uptime_s) + duration))
+ deadline=$(($(_uptime_s) + duration))
while true; do
sleep_until 1 ${deadline} || break
cmd="sg_reset --no-esc ${reset_type[i++ % 2]} $dev"
@@ -247,7 +247,7 @@ simulate_network_failure_loop() {
[ -e "$dev" ] || return $?
[ -n "$duration" ] || return $?
- deadline=$(($(uptime_s) + duration))
+ deadline=$(($(_uptime_s) + duration))
s=5
while [ $rc = 0 ]; do
sleep_until 5 ${deadline} || break
Make it easy to use the uptime_s() function from block tests. Change the implementation of this function into something that is easier to read. Signed-off-by: Bart Van Assche <bvanassche@acm.org> --- common/multipath-over-rdma | 9 +-------- common/rc | 5 +++++ tests/nvmeof-mp/rc | 2 +- tests/srp/014 | 2 +- tests/srp/rc | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-)