Re: [PATCH blktests 1/2] Move and rename uptime_s()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 21, 2019 at 03:57:18PM -0700, Bart Van Assche wrote:
> Make it easy to use the uptime_s() function from block tests.
> 
> Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
> ---
>  common/multipath-over-rdma | 9 +--------
>  common/rc                  | 9 +++++++++
>  tests/nvmeof-mp/rc         | 2 +-
>  tests/srp/014              | 2 +-
>  tests/srp/rc               | 2 +-
>  5 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/common/multipath-over-rdma b/common/multipath-over-rdma
> index 65ebb7b7f5f7..545a81e8c18e 100644
> --- a/common/multipath-over-rdma
> +++ b/common/multipath-over-rdma
> @@ -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
> diff --git a/common/rc b/common/rc
> index 41aee3aaa735..c00f2fe1f463 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -246,3 +246,12 @@ _test_dev_is_partition() {
>  _filter_xfs_io_error() {
>  	sed -e 's/^\(.*\)64\(: .*$\)/\1\2/'
>  }
> +
> +# System uptime in seconds.
> +_uptime_s() {
> +	local a b
> +
> +	echo "$(</proc/uptime)" | {

What's wrong with cat /proc/uptime? Or even better,

  { read ... } < /proc/uptime

> +		read -r a b && echo "$b" >/dev/null && echo "${a%%.*}";

What's the point of the echo "$b" here? Seems like this could all be
condensed to:

  { read -r s && echo "${s%%.*}" } < /proc/uptime

But that's more cryptic than it needs to be. Can we just do:

  awk '{ print int($1) }' /proc/uptime



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux