]> git.ipfire.org Git - thirdparty/util-linux.git/blob - tests/ts/lsfd/lsfd-functions.bash
lsfd: implement --summary and --counter options
[thirdparty/util-linux.git] / tests / ts / lsfd / lsfd-functions.bash
1 #!/bin/bash
2 #
3 # Copyright (C) 2021 Masatake YAMATO <yamato@redhat.com>
4 #
5 # This file is part of util-linux.
6 #
7 # This file is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This file is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17
18 function lsfd_wait_for_pausing {
19 ts_check_prog "sleep"
20
21 local PID=$1
22 until [[ $(ps --no-headers -ostat "${PID}") =~ S.* ]]; do
23 sleep 1
24 done
25 }
26
27 function lsfd_compare_dev {
28 local LSFD=$1
29 local FINDMNT=$2
30 local EXPR=$3
31
32 ts_check_prog "grep"
33
34 local MNTID=$("${LSFD}" --raw -n -o MNTID -Q "${EXPR}")
35 echo 'MNTID[RUN]:' $?
36 local DEV=$("${LSFD}" --raw -n -o DEV -Q "${EXPR}")
37 echo 'DEV[RUN]:' $?
38 # "stat -c" %d or "stat -c %D" can be used here instead of "findmnt".
39 # "stat" just prints a device id.
40 # Unlike "stat", "findmnt" can print the major part and minor part
41 # for a given device separately.
42 # We can save the code for extracting the major part and minor part
43 # if we use findmnt.
44 local FINDMNT_MNTID_DEV=$("${FINDMNT}" --raw -n -o ID,MAJ:MIN | grep "^${MNTID}")
45 echo 'FINDMNT[RUN]:' $?
46 [ "${MNTID} ${DEV}" == "${FINDMNT_MNTID_DEV}" ]
47 echo 'DEV[STR]:' $?
48 }