]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: (test) add a case for displaying DEV column
authorMasatake YAMATO <yamato@redhat.com>
Fri, 15 Oct 2021 17:47:03 +0000 (02:47 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Thu, 21 Oct 2021 12:06:39 +0000 (21:06 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/expected/lsfd/mkfds-ro-regular-file
tests/expected/lsfd/mkfds-rw-character-device
tests/ts/lsfd/lsfd-functions.bash [new file with mode: 0644]
tests/ts/lsfd/mkfds-ro-regular-file
tests/ts/lsfd/mkfds-rw-character-device

index 5eb1e0da140a5fc7077c1517f26f7fa08645ddb2..f57ea5cec4e5345e8f0166d91b2d71dee51200e7 100644 (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
index 5d2e7b94806861627a9dfafcf81d9c08e24ae892..e33dc97d5b7a9d1b567ed80088c0a8a13744abf4 100644 (file)
@@ -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 (file)
index 0000000..47b2499
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+#
+# Copyright (C) 2021 Masatake YAMATO <yamato@redhat.com>
+#
+# 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]:' $?
+}
index 77df054d6c5f3baa2466c3b32dafe8e46e45e896..7d991637672792edec89deede5301e0a1fb4708a 100755 (executable)
@@ -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}
index 063f71e4cb0a19df6b7e327694fd31230575291e..ea10e7d81d1fc8aaeb1b140865510d7b027955af 100755 (executable)
@@ -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