From: Masatake YAMATO Date: Mon, 4 Apr 2022 18:09:09 +0000 (+0900) Subject: test: (lsfd) add a case for testing ENDPOINTS column of FIFOs X-Git-Tag: v2.39-rc1~709^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9aa68bf4a905609c9d9ad0e36b53de1dd4791fe8;p=thirdparty%2Futil-linux.git test: (lsfd) add a case for testing ENDPOINTS column of FIFOs Signed-off-by: Masatake YAMATO --- diff --git a/tests/expected/lsfd/mkfds-pipe-no-fork b/tests/expected/lsfd/mkfds-pipe-no-fork index 146a618279..ba30c2395d 100644 --- a/tests/expected/lsfd/mkfds-pipe-no-fork +++ b/tests/expected/lsfd/mkfds-pipe-no-fork @@ -7,3 +7,5 @@ NAMES[RUN]: 0 NAMES[STR]: 0 INODES[RUN]: 0 INODES[STR]: 0 +ENDPOINTS[RUN]: 0 +ENDPOINTS[STR]: 0 diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index b18155611d..f2f569a406 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -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 }, }, diff --git a/tests/ts/lsfd/mkfds-pipe-no-fork b/tests/ts/lsfd/mkfds-pipe-no-fork index 171b3b82fa..f1d140b544 100755 --- a/tests/ts/lsfd/mkfds-pipe-no-fork +++ b/tests/ts/lsfd/mkfds-pipe-no-fork @@ -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