From dbfd5efe46b9cea13c3703b12e14cee377859b92 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Mon, 15 Apr 2024 02:18:19 +0900 Subject: [PATCH] tests: (lsns::filedesc) skip if NS_GET_NSTYPE ioctl cmd not available Currently, Qemu userspace emulation doesn't support the ioctl cmd. Signed-off-by: Masatake YAMATO --- tests/helpers/test_sysinfo.c | 21 ++++++++++++++++++++- tests/ts/lsns/filedesc | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/helpers/test_sysinfo.c b/tests/helpers/test_sysinfo.c index c36aca2b5..058afc24f 100644 --- a/tests/helpers/test_sysinfo.c +++ b/tests/helpers/test_sysinfo.c @@ -31,6 +31,13 @@ #include "mount-api-utils.h" +#ifdef HAVE_LINUX_NSFS_H +# include +# if defined(NS_GET_NSTYPE) && defined(NS_GET_OWNER_UID) +# define USE_NS_GET_API 1 +# endif +#endif + typedef struct { const char *name; int (*fnc)(void); @@ -132,6 +139,18 @@ static int hlp_sz_time(void) return 0; } +static int hlp_get_nstype_ok(void) +{ +#ifdef USE_NS_GET_API + errno = 0; + ioctl(STDOUT_FILENO, NS_GET_NSTYPE); +#else + errno = ENOSYS; +#endif + printf("%d\n", errno != ENOSYS); + return 0; +} + static const mntHlpfnc hlps[] = { { "WORDSIZE", hlp_wordsize }, @@ -147,6 +166,7 @@ static const mntHlpfnc hlps[] = { "enotty-ok", hlp_enotty_ok }, { "fsopen-ok", hlp_fsopen_ok }, { "sz(time_t)", hlp_sz_time }, + { "ns-gettype-ok", hlp_get_nstype_ok }, { NULL, NULL } }; @@ -181,4 +201,3 @@ int main(int argc, char **argv) exit(re ? EXIT_FAILURE : EXIT_SUCCESS); } - diff --git a/tests/ts/lsns/filedesc b/tests/ts/lsns/filedesc index 334984784..1427dee0d 100755 --- a/tests/ts/lsns/filedesc +++ b/tests/ts/lsns/filedesc @@ -25,11 +25,16 @@ ts_init "$*" ts_check_test_command "$TS_CMD_LSNS" ts_check_test_command "$TS_CMD_LSFD" ts_check_test_command "$TS_HELPER_MKFDS" +ts_check_test_command "$TS_HELPER_SYSINFO" ts_check_prog "ip" ts_skip_nonroot +if [ "$($TS_HELPER_SYSINFO ns-gettype-ok)" == "0" ]; then + ts_skip "NS_GET_NSTYPE ioctl cmd not available" +fi + FD=4 NS=LSNS-TEST-FILEDESC-NS FILE=/run/netns/$NS -- 2.47.3