]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
enosys: add test
authorThomas Weißschuh <thomas@t-8ch.de>
Thu, 27 Apr 2023 22:04:19 +0000 (00:04 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 16 May 2023 20:44:41 +0000 (22:44 +0200)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
meson.build
misc-utils/enosys.c
tests/commands.sh
tests/expected/misc/enosys-basic [new file with mode: 0644]
tests/helpers/Makemodule.am
tests/helpers/test_enosys.c [new file with mode: 0644]
tests/ts/misc/enosys [new file with mode: 0755]

index e77db246b8d5463a9d7ceb3ac127d0b8709aee5d..42f255d62b3c7801aa9e079494138175382898b6 100644 (file)
@@ -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
index feb0bec299183d7966b1969db61ce4014098b7e0..5a337fd81356f09c4c9950818cd8c6696e220997 100644 (file)
@@ -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)
index f979fe66215ba79ee82c86992ce57652573e76d2..c9a5cd1294b0d61e52b79c755aa531508270867e 100644 (file)
@@ -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 (file)
index 0000000..6552946
--- /dev/null
@@ -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
index 83df24b1f0e1e14f0c3a99f8ab28945faedf451c..2b1df3c6baba01fd641f0aac1a24df70a6fd29ba 100644 (file)
@@ -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 (file)
index 0000000..b38fba1
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2023 Thomas Weißschuh <thomas@t-8ch.de>
+ *
+ * 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 <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+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 (executable)
index 0000000..ea2d61f
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+# Copyright (C) 2022 Thomas Weißschuh <thomas@t-8ch.de>
+#
+# 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