]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
test: (lsfd) add a case for testing ENDPOINTS column of FIFOs
authorMasatake YAMATO <yamato@redhat.com>
Mon, 4 Apr 2022 18:09:09 +0000 (03:09 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 4 Apr 2022 18:18:31 +0000 (03:18 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/expected/lsfd/mkfds-pipe-no-fork
tests/helpers/test_mkfds.c
tests/ts/lsfd/mkfds-pipe-no-fork

index 146a6182793ce4fc6ca63eb63959e61e4811e7f3..ba30c2395d0743feecadd3dc3d277c820fc01a23 100644 (file)
@@ -7,3 +7,5 @@ NAMES[RUN]: 0
 NAMES[STR]: 0
 INODES[RUN]: 0
 INODES[STR]: 0
+ENDPOINTS[RUN]: 0
+ENDPOINTS[STR]: 0
index b18155611dd4f744eb4f6dfb3eadf6f5357f0f65..f2f569a406f5aeb42bc3f0dce7c8ab4a7a4c04b2 100644 (file)
@@ -275,6 +275,16 @@ static void make_pipe(const struct factory *factory, struct fdesc fdescs[], pid_
                     "nonblock", ARG_STRING(nonblock));
        }
 
+       /* Make extra pipe descriptors for making pipe objects connected
+        * with fds more than 2.
+        * See https://github.com/util-linux/util-linux/pull/1622
+        * about the background of the requirement. */
+       struct arg rdup = decode_arg("rdup", factory->params, argc, argv);
+       struct arg wdup = decode_arg("wdup", factory->params, argc, argv);
+       int xpd[2];
+       xpd [0] = ARG_INTEGER(rdup);
+       xpd [1] = ARG_INTEGER(wdup);
+
        for (int i = 0; i < 2; i++) {
                if (ARG_STRING(nonblock)[i] == '-')
                        continue;
@@ -324,6 +334,27 @@ static void make_pipe(const struct factory *factory, struct fdesc fdescs[], pid_
                        .data  = NULL
                };
        }
+
+       /* Make extra pipe descriptors. */
+       for (int i = 0; i < 2; i++) {
+               if (xpd[i] >= 0) {
+                       if (dup2(fdescs[i].fd, xpd[i]) < 0) {
+                               int e = errno;
+                               close(fdescs[0].fd);
+                               close(fdescs[1].fd);
+                               if (i > 0 && xpd[0] >= 0)
+                                       close(xpd[0]);
+                               errno = e;
+                               err(EXIT_FAILURE, "failed to dup %d -> %d",
+                                   fdescs[i].fd, xpd[i]);
+                       }
+                       fdescs[i + 2] = (struct fdesc){
+                               .fd = xpd[i],
+                               .close = close_fdesc,
+                               .data = NULL
+                       };
+               }
+       }
 }
 
 static void close_dir(int fd, void *data)
@@ -535,7 +566,7 @@ static const struct factory factories[] = {
                .desc = "making pair of fds with pipe(2)",
                .priv = false,
                .N    = 2,
-               .EX_N = 0,
+               .EX_N = 2,
                .fork = false,
                .make = make_pipe,
                .params = (struct parameter []) {
@@ -545,6 +576,18 @@ static const struct factory factories[] = {
                                .desc = "set nonblock flag (\"--\", \"r-\", \"-w\", or \"rw\")",
                                .defv.string = "--",
                        },
+                       {
+                               .name = "rdup",
+                               .type = PTYPE_INTEGER,
+                               .desc = "file descriptor for duplicating the pipe input",
+                               .defv.integer = -1,
+                       },
+                       {
+                               .name = "wdup",
+                               .type = PTYPE_INTEGER,
+                               .desc = "file descriptor for duplicating the pipe output",
+                               .defv.integer = -1,
+                       },
                        PARAM_END
                },
        },
index 171b3b82faaf2653cfa9178f6efa84b9e3b587a2..f1d140b544c1d3322b026c9374a531183107e3a5 100755 (executable)
@@ -44,7 +44,7 @@ FD1=4
 EXPR=
 
 {
-    coproc MKFDS { "$TS_HELPER_MKFDS" pipe-no-fork $FD0 $FD1 nonblock=-w; }
+    coproc MKFDS { "$TS_HELPER_MKFDS" pipe-no-fork $FD0 $FD1 nonblock=-w rdup=$((FD0 + 2)) wdup=$((FD1 + 2)); }
     if read -u ${MKFDS[0]} PID; then
        EXPR='(PID == '"${PID}"') and ((FD == '"$FD0"') or (FD =='"$FD1"'))'
        ${TS_CMD_LSFD} -n -o ASSOC,MODE,TYPE,SOURCE,FLAGS -Q "${EXPR}"
@@ -65,6 +65,33 @@ EXPR=
        [ "${LSFD_INODES}" == "$(printf '%d\n%d' $(pipe_inode $PID $FD0) $(pipe_inode $PID $FD1))" ]
        echo 'INODES[STR]:' $?
 
+       LSFD_ENDPOINTS=$(${TS_CMD_LSFD} --raw -n -o ASSOC,ENDPOINTS -Q "${EXPR}")
+       echo 'ENDPOINTS[RUN]:' $?
+       mkfds=${TS_HELPER_MKFDS##*/}
+
+       line0=$(printf '%d ' $FD0)
+       line0+=$(printf '%d,%s,%d%c%c' $PID $mkfds $FD1 - w)
+       line0+='\x0a'
+       line0+=$(printf '%d,%s,%d%c%c' $PID $mkfds $((FD0 + 2)) r -)
+       line0+='\x0a'
+       line0+=$(printf '%d,%s,%d%c%c' $PID $mkfds $((FD1 + 2)) - w)
+
+       line1=$(printf '%d ' $FD1)
+       line1+=$(printf '%d,%s,%d%c%c' $PID $mkfds $FD0 r -)
+       line1+='\x0a'
+       line1+=$(printf '%d,%s,%d%c%c' $PID $mkfds $((FD0 + 2)) r -)
+       line1+='\x0a'
+       line1+=$(printf '%d,%s,%d%c%c' $PID $mkfds $((FD1 + 2)) - w)
+
+       expected=$(printf '%s\n%s' "${line0}" "${line1}")
+       if [ "${LSFD_ENDPOINTS}" == "${expected}" ]; then
+           echo 'ENDPOINTS[STR]:' $?
+       else
+           echo "lsfd output:"
+           echo "${LSFD_ENDPOINTS}"
+           echo "expectation:"
+           echo "${expected}"
+       fi
        kill -CONT ${PID}
        wait ${MKFDS_PID}
     fi