From: Masatake YAMATO Date: Fri, 15 Oct 2021 17:47:03 +0000 (+0900) Subject: lsfd: (test) add a case for displaying DEV column X-Git-Tag: v2.38-rc1~144^2~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dc01f8d29cbd5b528a7ceee83c7f53847f4ab8ca;p=thirdparty%2Futil-linux.git lsfd: (test) add a case for displaying DEV column Signed-off-by: Masatake YAMATO --- diff --git a/tests/expected/lsfd/mkfds-ro-regular-file b/tests/expected/lsfd/mkfds-ro-regular-file index 5eb1e0da14..f57ea5cec4 100644 --- a/tests/expected/lsfd/mkfds-ro-regular-file +++ b/tests/expected/lsfd/mkfds-ro-regular-file @@ -10,3 +10,7 @@ USER[RUN]: 0 USER[STR]: 0 SIZE[RUN]: 0 SIZE[STR]: 0 +MNTID[RUN]: 0 +DEV[RUN]: 0 +FINDMNT[RUN]: 0 +DEV[STR]: 0 diff --git a/tests/expected/lsfd/mkfds-rw-character-device b/tests/expected/lsfd/mkfds-rw-character-device index 5d2e7b9480..e33dc97d5b 100644 --- a/tests/expected/lsfd/mkfds-rw-character-device +++ b/tests/expected/lsfd/mkfds-rw-character-device @@ -1,2 +1,6 @@ 3 rw- CHR /dev/zero mem:5 0 1:5 mem char 1:5 ASSOC,MODE,TYPE,NAME,SOURCE,POS,MAJ:MIN,CHRDRV,DEVTYPE,RDEV: 0 +MNTID[RUN]: 0 +DEV[RUN]: 0 +FINDMNT[RUN]: 0 +DEV[STR]: 0 diff --git a/tests/ts/lsfd/lsfd-functions.bash b/tests/ts/lsfd/lsfd-functions.bash new file mode 100644 index 0000000000..47b2499be4 --- /dev/null +++ b/tests/ts/lsfd/lsfd-functions.bash @@ -0,0 +1,39 @@ +#!/bin/bash +# +# Copyright (C) 2021 Masatake YAMATO +# +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +function lsfd_compare_dev { + local LSFD=$1 + local FINDMNT=$2 + local EXPR=$3 + + ts_check_prog "grep" + + local MNTID=$("${LSFD}" --raw -n -o MNTID -Q "${EXPR}") + echo 'MNTID[RUN]:' $? + local DEV=$("${LSFD}" --raw -n -o DEV -Q "${EXPR}") + echo 'DEV[RUN]:' $? + # "stat -c" %d or "stat -c %D" can be used here instead of "findmnt". + # "stat" just prints a device id. + # Unlike "stat", "findmnt" can print the major part and minor part + # for a given device separately. + # We can save the code for extracting the major part and minor part + # if we use findmnt. + local FINDMNT_MNTID_DEV=$("${FINDMNT}" --raw -n -o ID,MAJ:MIN | grep "^${MNTID}") + echo 'FINDMNT[RUN]:' $? + [ "${MNTID} ${DEV}" == "${FINDMNT_MNTID_DEV}" ] + echo 'DEV[STR]:' $? +} diff --git a/tests/ts/lsfd/mkfds-ro-regular-file b/tests/ts/lsfd/mkfds-ro-regular-file index 77df054d6c..7d99163767 100755 --- a/tests/ts/lsfd/mkfds-ro-regular-file +++ b/tests/ts/lsfd/mkfds-ro-regular-file @@ -20,7 +20,11 @@ TS_DESC="read-only regular file" . $TS_TOPDIR/functions.sh ts_init "$*" +. $TS_SELF/lsfd-functions.bash + ts_check_test_command "$TS_CMD_LSFD" +ts_check_test_command "$TS_CMD_FINDMNT" + ts_check_test_command "$TS_HELPER_MKFDS" ts_check_prog "stat" @@ -64,6 +68,7 @@ EXPR= [ "${LSFD_SIZE}" == $(stat -c %s /etc/passwd) ] echo 'SIZE[STR]:' $? + lsfd_compare_dev "${TS_CMD_LSFD}" "${TS_CMD_FINDMNT}" "${EXPR}" kill -CONT ${PID} wait ${MKFDS_PID} diff --git a/tests/ts/lsfd/mkfds-rw-character-device b/tests/ts/lsfd/mkfds-rw-character-device index 063f71e4cb..ea10e7d81d 100755 --- a/tests/ts/lsfd/mkfds-rw-character-device +++ b/tests/ts/lsfd/mkfds-rw-character-device @@ -20,7 +20,11 @@ TS_DESC="character device with O_RDWR" . $TS_TOPDIR/functions.sh ts_init "$*" +. $TS_SELF/lsfd-functions.bash + ts_check_test_command "$TS_CMD_LSFD" +ts_check_test_command "$TS_CMD_FINDMNT" + ts_check_test_command "$TS_HELPER_MKFDS" ts_check_prog "stat" @@ -38,6 +42,8 @@ EXPR= ${TS_CMD_LSFD} -n -o ASSOC,MODE,TYPE,NAME,SOURCE,POS,MAJ:MIN,CHRDRV,DEVTYPE,RDEV -Q "${EXPR}" echo 'ASSOC,MODE,TYPE,NAME,SOURCE,POS,MAJ:MIN,CHRDRV,DEVTYPE,RDEV': $? + lsfd_compare_dev "${TS_CMD_LSFD}" "${TS_CMD_FINDMNT}" "${EXPR}" + kill -CONT ${PID} wait ${MKFDS_PID} fi