From: Thomas Weißschuh Date: Thu, 27 Apr 2023 22:04:19 +0000 (+0200) Subject: enosys: add test X-Git-Tag: v2.40-rc1~466^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4290056351ed4cc3fc3b77cc862749fa578c3769;p=thirdparty%2Futil-linux.git enosys: add test Signed-off-by: Thomas Weißschuh --- diff --git a/meson.build b/meson.build index e77db246b8..42f255d62b 100644 --- a/meson.build +++ b/meson.build @@ -3256,6 +3256,12 @@ exe = executable( include_directories : includes) exes += exe +exe = executable( + 'test_enosys', + 'tests/helpers/test_enosys.c', + include_directories : includes) +exes += exe + ############################################################ # XXX: HAVE_OPENAT diff --git a/misc-utils/enosys.c b/misc-utils/enosys.c index feb0bec299..5a337fd813 100644 --- a/misc-utils/enosys.c +++ b/misc-utils/enosys.c @@ -70,6 +70,7 @@ static const struct syscall syscalls[] = { { "move_mount", __NR_move_mount }, { "open_tree", __NR_open_tree }, { "fsopen", __NR_fsopen }, + { "fallocate", __NR_fallocate }, }; int main(int argc, char **argv) diff --git a/tests/commands.sh b/tests/commands.sh index f979fe6621..c9a5cd1294 100644 --- a/tests/commands.sh +++ b/tests/commands.sh @@ -5,6 +5,7 @@ TS_TESTUSER=${TS_TESTUSER:-"nobody"} TS_HELPER_BYTESWAP="${ts_helpersdir}test_byteswap" TS_HELPER_CPUSET="${ts_helpersdir}test_cpuset" TS_HELPER_DMESG="${ts_helpersdir}test_dmesg" +TS_HELPER_ENOSYS="${ts_helpersdir}test_enosys" TS_HELPER_ISLOCAL="${ts_helpersdir}test_islocal" TS_HELPER_ISMOUNTED="${ts_helpersdir}test_ismounted" TS_HELPER_LIBFDISK_GPT="${ts_helpersdir}test_fdisk_gpt" diff --git a/tests/expected/misc/enosys-basic b/tests/expected/misc/enosys-basic new file mode 100644 index 0000000000..6552946f56 --- /dev/null +++ b/tests/expected/misc/enosys-basic @@ -0,0 +1,4 @@ +test_enosys: fallocate r=-1 errno=Bad file descriptor +test_enosys: fallocate r=-1 errno=Function not implemented +test_enosys: fallocate r=-1 errno=Function not implemented +test_enosys: fallocate r=-1 errno=Function not implemented diff --git a/tests/helpers/Makemodule.am b/tests/helpers/Makemodule.am index 83df24b1f0..2b1df3c6ba 100644 --- a/tests/helpers/Makemodule.am +++ b/tests/helpers/Makemodule.am @@ -34,4 +34,7 @@ test_uuid_namespace_SOURCES = tests/helpers/test_uuid_namespace.c \ if LINUX check_PROGRAMS += test_mkfds test_mkfds_SOURCES = tests/helpers/test_mkfds.c + +check_PROGRAMS += test_enosys +test_enosys_SOURCES = tests/helpers/test_enosys.c endif diff --git a/tests/helpers/test_enosys.c b/tests/helpers/test_enosys.c new file mode 100644 index 0000000000..b38fba168c --- /dev/null +++ b/tests/helpers/test_enosys.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2023 Thomas Weißschuh + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int r; + + if (argc != 2) { + fprintf(stderr, "invalid options\n"); + return EXIT_FAILURE; + } + + if (strcmp(argv[1], "fallocate") == 0) { + errno = 0; + r = fallocate(-1, 0, 0, 0); + errx(EXIT_SUCCESS, "fallocate r=%d errno=%s", r, strerror(errno)); + } + + errx(EXIT_FAILURE, "invalid mode %s", argv[1]); +} diff --git a/tests/ts/misc/enosys b/tests/ts/misc/enosys new file mode 100755 index 0000000000..ea2d61f22f --- /dev/null +++ b/tests/ts/misc/enosys @@ -0,0 +1,40 @@ +#!/bin/bash + +# Copyright (C) 2022 Thomas Weißschuh +# +# 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="enosys" + +. "$TS_TOPDIR"/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_ENOSYS" +ts_check_test_command "$TS_HELPER_ENOSYS" + +"$TS_CMD_ENOSYS" true 2> /dev/null +[ "$?" -eq "$TS_EXIT_NOTSUPP" ] && ts_skip "enosys does not work" + +ts_init_subtest basic + +FALLOCATE_TEST="$TS_HELPER_ENOSYS fallocate" + +$FALLOCATE_TEST > /dev/null 2>> "$TS_OUTPUT" +"$TS_CMD_ENOSYS" -s fallocate -- $FALLOCATE_TEST > /dev/null 2>> "$TS_OUTPUT" +"$TS_CMD_ENOSYS" -s fsopen -s fallocate -- $FALLOCATE_TEST > /dev/null 2>> "$TS_OUTPUT" +"$TS_CMD_ENOSYS" -s fallocate -s fsopen -- $FALLOCATE_TEST > /dev/null 2>> "$TS_OUTPUT" + +ts_finalize_subtest + +ts_finalize