From: Masatake YAMATO Date: Sun, 30 Jul 2023 09:03:03 +0000 (+0900) Subject: tests: (test_mkfds) add ppoll multiplexer X-Git-Tag: v2.40-rc1~244^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=38ffd1e3519dc3c8e785f26fe9753cf1c11b82de;p=thirdparty%2Futil-linux.git tests: (test_mkfds) add ppoll multiplexer Signed-off-by: Masatake YAMATO --- diff --git a/meson.build b/meson.build index d077fef06e..fcab1732d7 100644 --- a/meson.build +++ b/meson.build @@ -3385,6 +3385,7 @@ if LINUX 'test_mkfds', 'tests/helpers/test_mkfds.c', 'tests/helpers/test_mkfds.h', + 'tests/helpers/test_mkfds_ppoll.c', include_directories : includes, dependencies : mq_libs, build_by_default: program_tests) diff --git a/tests/helpers/Makemodule.am b/tests/helpers/Makemodule.am index 00a32c8159..860d72f0f6 100644 --- a/tests/helpers/Makemodule.am +++ b/tests/helpers/Makemodule.am @@ -33,7 +33,8 @@ test_uuid_namespace_SOURCES = tests/helpers/test_uuid_namespace.c \ if LINUX check_PROGRAMS += test_mkfds -test_mkfds_SOURCES = tests/helpers/test_mkfds.c tests/helpers/test_mkfds.h +test_mkfds_SOURCES = tests/helpers/test_mkfds.c tests/helpers/test_mkfds.h \ + tests/helpers/test_mkfds_ppoll.c test_mkfds_LDADD = $(LDADD) $(MQ_LIBS) check_PROGRAMS += test_enosys diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index 930768e295..b0bb8b71a4 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -3908,6 +3908,12 @@ static struct multiplexer multiplexers [] = { .fn = wait_event_poll, }, #endif +#ifdef __NR_ppoll + { + .name = "ppoll", + .fn = wait_event_ppoll, + }, +#endif }; static struct multiplexer *lookup_multiplexer(const char *name) diff --git a/tests/helpers/test_mkfds.h b/tests/helpers/test_mkfds.h index 068dd72e1b..7d679b44fe 100644 --- a/tests/helpers/test_mkfds.h +++ b/tests/helpers/test_mkfds.h @@ -20,6 +20,7 @@ #ifndef TEST_MKFDS_H #define TEST_MKFDS_H +#include #include #include @@ -77,4 +78,8 @@ struct fdesc { free(pfds); \ } +#ifdef __NR_ppoll +void wait_event_ppoll(bool add_stdin, struct fdesc *fdescs, size_t n_fdescs); +#endif + #endif /* TEST_MKFDS_H */ diff --git a/tests/helpers/test_mkfds_ppoll.c b/tests/helpers/test_mkfds_ppoll.c new file mode 100644 index 0000000000..33d5aa8322 --- /dev/null +++ b/tests/helpers/test_mkfds_ppoll.c @@ -0,0 +1,79 @@ +/* + * test_mkfds_ppoll.c - call ppoll(2) DIRECTLY + * + * Written by Masatake YAMATO + * + * This program 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. + * + * This program is distributed in the hope that it would 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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +/* Why this ppoll multiplexer must be defined here? + * + * Glibc defines sigset_t its own way. However, it is not what kernel + * expects. + * + * If an applicaiton uses the glibc's sigset_t via ppoll(2) wrapper, + * there is no problem; the wrapper function may translate the glibc's + * sigset_t to what kernel expects. + * + * Here, we want to ppoll(2) directly. In this case, the glibc's sigset_t + * becomes an issue. To use ppoll(2) directly, we have to include . + * Including both provided by glibc and provided by kernel + * causes "redefined ***" errors. + * + * This file is for defining the poll multiplexer only with . + * + */ +#include "test_mkfds.h" + +#include /* memset */ +#include /* err */ +#include /* EINTR */ +#include /* struct pollfd */ +#include /* sigset_t */ + +extern long syscall(long number, ...); +extern void *calloc(size_t nmemb, size_t size); +extern void free(void *ptr); + +#ifndef EXIT_FAILURE +# define EXIT_FAILURE 1 +#endif +#ifndef XALLOC_EXIT_CODE +# define XALLOC_EXIT_CODE EXIT_FAILURE +#endif + +/* Copied from include/xalloc.h */ +static void *xcalloc(const size_t nelems, const size_t size) +{ + void *ret = calloc(nelems, size); + + if (!ret && size && nelems) + err(XALLOC_EXIT_CODE, "cannot allocate %zu bytes", size); + return ret; +} + +/* sigemptyset may not be defiend and/or declared in asm/signal.h */ +static void clear_sigset(sigset_t *sigset) +{ + memset(sigset, 0, sizeof(*sigset)); +} + +#ifdef __NR_ppoll +DEFUN_WAIT_EVENT_POLL(ppoll, + "ppoll", + sigset_t sigset;, + clear_sigset(&sigset);, + syscall(__NR_ppoll, pfds, n, NULL, &sigset, sizeof(sigset))) +#endif