]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
Move and rename uptime_s()
authorBart Van Assche <bvanassche@acm.org>
Thu, 24 Oct 2019 21:03:51 +0000 (14:03 -0700)
committerOmar Sandoval <osandov@fb.com>
Wed, 30 Oct 2019 20:38:56 +0000 (13:38 -0700)
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
common/rc
tests/nvmeof-mp/rc
tests/srp/014
tests/srp/rc

index 65ebb7b7f5f789074198a237d069cad7c11dc86c..545a81e8c18e390021741c97f3b1f347f12cba07 100644 (file)
@@ -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
index 41aee3aaa735d3572a5b8f4d9cb0155208757438..87b1e0718382054987ec22e846dcc5ba02824b76 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -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
+}
index 2493fcee12ded247005f3fab6cc137324070c1b8..278843a1270d8968960345b40db670282df7c206 100755 (executable)
@@ -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
index 8ecd8a439a82e881293de6b23ca202b7d50a0e4d..7afde6284b83c55916ec8fcdb1fc1b1fd0de5d84 100755 (executable)
@@ -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"
index 696d94e5fb972ac024556a14de1f7a7405a7d11d..a1bc09b496ec54ef90f0a44d5fd5c623ae47b0ff 100755 (executable)
@@ -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