]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: (test) add a case for displaying a character device
authorMasatake YAMATO <yamato@redhat.com>
Fri, 15 Oct 2021 16:42:57 +0000 (01:42 +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-rw-character-device [new file with mode: 0644]
tests/helpers/test_mkfds.c
tests/ts/lsfd/mkfds-rw-character-device [new file with mode: 0755]

diff --git a/tests/expected/lsfd/mkfds-rw-character-device b/tests/expected/lsfd/mkfds-rw-character-device
new file mode 100644 (file)
index 0000000..5d2e7b9
--- /dev/null
@@ -0,0 +1,2 @@
+    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
index 3e0f3badc9099c5808494e0af4e13b1b518ff163..369b291c64a58bd79b177798784ad770d12fe376 100644 (file)
@@ -370,6 +370,22 @@ static void open_directory(const struct factory *factory, struct fdesc fdescs[],
        };
 }
 
+static void open_rw_chrdev(const struct factory *factory, struct fdesc fdescs[], pid_t * child _U_,
+                          int argc, char ** argv)
+{
+       struct arg chrdev = decode_arg("chrdev", factory->params, argc, argv);
+       int fd = open(ARG_STRING(chrdev), O_RDWR);
+       if (fd < 0)
+               err(EXIT_FAILURE, "failed to open: %s", ARG_STRING(chrdev));
+       free_arg(&chrdev);
+
+       fdescs[0] = (struct fdesc){
+               .fd    = fd,
+               .close = close_fdesc,
+               .data  = NULL
+       };
+}
+
 #define PARAM_END { .name = NULL, }
 static const struct factory factories[] = {
        {
@@ -435,6 +451,23 @@ static const struct factory factories[] = {
                        PARAM_END
                },
        },
+       {
+               .name = "rw-character-device",
+               .desc = "character device with O_RDWR flag",
+               .priv = false,
+               .N    = 1,
+               .fork = false,
+               .make = open_rw_chrdev,
+               .params = (struct parameter []) {
+                       {
+                               .name = "chrdev",
+                               .type = PTYPE_STRING,
+                               .desc = "character device node to be opened",
+                               .defv.string = "/dev/zero",
+                       },
+                       PARAM_END
+               },
+       },
 };
 
 static int count_parameters(const struct factory *factory)
diff --git a/tests/ts/lsfd/mkfds-rw-character-device b/tests/ts/lsfd/mkfds-rw-character-device
new file mode 100755 (executable)
index 0000000..063f71e
--- /dev/null
@@ -0,0 +1,46 @@
+#!/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.
+#
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="character device with O_RDWR"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_LSFD"
+ts_check_test_command "$TS_HELPER_MKFDS"
+
+ts_check_prog "stat"
+
+ts_cd "$TS_OUTDIR"
+
+PID=
+FD=3
+EXPR=
+
+{
+    coproc MKFDS { "$TS_HELPER_MKFDS" rw-character-device $FD chrdev=/dev/zero; }
+    if read -u ${MKFDS[0]} PID; then
+       EXPR='(PID == '"${PID}"') and (FD == '"$FD"')'
+       ${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': $?
+
+       kill -CONT ${PID}
+       wait ${MKFDS_PID}
+    fi
+} > $TS_OUTPUT 2>&1
+
+ts_finalize