2000-06-30 09:55:04 +00:00
|
|
|
/* Some basic tests for LFS.
|
2019-01-01 00:11:28 +00:00
|
|
|
Copyright (C) 2000-2019 Free Software Foundation, Inc.
|
2001-07-06 04:58:11 +00:00
|
|
|
This file is part of the GNU C Library.
|
2000-06-30 09:55:04 +00:00
|
|
|
Contributed by Andreas Jaeger <aj@suse.de>, 2000.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2000-06-30 09:55:04 +00:00
|
|
|
|
|
|
|
The GNU C Library 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
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
2000-06-30 09:55:04 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2000-06-30 09:55:04 +00:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <error.h>
|
|
|
|
#include <errno.h>
|
2000-10-24 21:12:01 +00:00
|
|
|
#include <sys/resource.h>
|
2018-08-21 10:56:53 +00:00
|
|
|
#include <support/check.h>
|
2000-06-30 09:55:04 +00:00
|
|
|
|
|
|
|
/* Prototype for our test function. */
|
|
|
|
extern void do_prepare (int argc, char *argv[]);
|
|
|
|
extern int do_test (int argc, char *argv[]);
|
|
|
|
|
|
|
|
/* We have a preparation function. */
|
|
|
|
#define PREPARE do_prepare
|
|
|
|
|
|
|
|
/* This defines the `main' function and some more. */
|
|
|
|
#include <test-skeleton.c>
|
|
|
|
|
|
|
|
/* These are for the temporary file we generate. */
|
|
|
|
char *name;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* 2^31 = 2GB. */
|
|
|
|
#define TWO_GB 2147483648LL
|
|
|
|
|
|
|
|
void
|
|
|
|
do_prepare (int argc, char *argv[])
|
|
|
|
{
|
2006-09-12 11:44:01 +00:00
|
|
|
size_t name_len;
|
2000-10-26 02:24:09 +00:00
|
|
|
struct rlimit64 rlim;
|
2000-06-30 09:55:04 +00:00
|
|
|
|
|
|
|
name_len = strlen (test_dir);
|
2016-06-11 21:50:16 +00:00
|
|
|
name = xmalloc (name_len + sizeof ("/lfsXXXXXX"));
|
2000-06-30 09:55:04 +00:00
|
|
|
mempcpy (mempcpy (name, test_dir, name_len),
|
|
|
|
"/lfsXXXXXX", sizeof ("/lfsXXXXXX"));
|
|
|
|
|
|
|
|
/* Open our test file. */
|
2000-10-26 02:24:09 +00:00
|
|
|
fd = mkstemp64 (name);
|
|
|
|
if (fd == -1)
|
2000-06-30 09:55:04 +00:00
|
|
|
{
|
2000-10-26 02:24:09 +00:00
|
|
|
if (errno == ENOSYS)
|
|
|
|
{
|
|
|
|
/* Fail silently. */
|
2001-06-11 08:43:24 +00:00
|
|
|
error (0, 0, "open64 is not supported");
|
2000-10-26 02:24:09 +00:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error (EXIT_FAILURE, errno, "cannot create temporary file");
|
2000-06-30 09:55:04 +00:00
|
|
|
}
|
2018-08-21 10:56:53 +00:00
|
|
|
if (!support_descriptor_supports_holes (fd))
|
|
|
|
FAIL_UNSUPPORTED ("File %s does not support holes", name);
|
2015-10-15 22:29:06 +00:00
|
|
|
add_temp_file (name);
|
2000-06-30 09:55:04 +00:00
|
|
|
|
2000-10-26 02:24:09 +00:00
|
|
|
if (getrlimit64 (RLIMIT_FSIZE, &rlim) != 0)
|
|
|
|
{
|
|
|
|
error (0, errno, "cannot get resource limit");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
if (rlim.rlim_cur < TWO_GB + 200)
|
|
|
|
{
|
|
|
|
rlim.rlim_cur = TWO_GB + 200;
|
|
|
|
if (setrlimit64 (RLIMIT_FSIZE, &rlim) != 0)
|
|
|
|
{
|
|
|
|
error (0, errno, "cannot reset file size limits");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
}
|
2000-06-30 09:55:04 +00:00
|
|
|
}
|
|
|
|
|
2001-02-05 21:38:54 +00:00
|
|
|
static void
|
|
|
|
test_ftello (void)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
int ret;
|
|
|
|
off64_t pos;
|
|
|
|
|
|
|
|
f = fopen64 (name, "w");
|
|
|
|
|
|
|
|
ret = fseeko64 (f, TWO_GB+100, SEEK_SET);
|
|
|
|
if (ret == -1 && errno == ENOSYS)
|
|
|
|
{
|
2001-06-11 08:43:24 +00:00
|
|
|
error (0, 0, "fseeko64 is not supported.");
|
2001-02-05 21:38:54 +00:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
if (ret == -1 && errno == EINVAL)
|
|
|
|
{
|
2001-06-11 08:43:24 +00:00
|
|
|
error (0, 0, "LFS seems not to be supported");
|
2001-02-05 21:38:54 +00:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
2001-06-11 08:43:24 +00:00
|
|
|
error (0, errno, "fseeko64 failed with error");
|
2001-02-05 21:38:54 +00:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = fwrite ("Hello", 1, 5, f);
|
2001-06-11 08:43:24 +00:00
|
|
|
if (ret == -1 && errno == EFBIG)
|
|
|
|
{
|
|
|
|
error (0, errno, "LFS seems not to be supported");
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == -1 && errno == ENOSPC)
|
2001-02-05 21:38:54 +00:00
|
|
|
{
|
2001-06-11 08:43:24 +00:00
|
|
|
error (0, 0, "Not enough space to write file.");
|
2001-02-05 21:38:54 +00:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != 5)
|
2001-06-11 08:43:24 +00:00
|
|
|
error (EXIT_FAILURE, errno, "Cannot write test string to large file");
|
2001-02-05 21:38:54 +00:00
|
|
|
|
|
|
|
pos = ftello64 (f);
|
|
|
|
|
|
|
|
if (pos != TWO_GB+105)
|
|
|
|
{
|
|
|
|
error (0, 0, "ftello64 gives wrong result.");
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose (f);
|
|
|
|
}
|
|
|
|
|
2000-06-30 09:55:04 +00:00
|
|
|
int
|
|
|
|
do_test (int argc, char *argv[])
|
|
|
|
{
|
2015-08-10 12:12:47 +00:00
|
|
|
int ret, fd2;
|
2000-06-30 09:55:04 +00:00
|
|
|
struct stat64 statbuf;
|
|
|
|
|
|
|
|
ret = lseek64 (fd, TWO_GB+100, SEEK_SET);
|
|
|
|
if (ret == -1 && errno == ENOSYS)
|
|
|
|
{
|
2001-06-11 08:43:24 +00:00
|
|
|
error (0, 0, "lseek64 is not supported.");
|
2000-06-30 09:55:04 +00:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
2001-01-08 22:28:15 +00:00
|
|
|
if (ret == -1 && errno == EINVAL)
|
|
|
|
{
|
2001-06-11 08:43:24 +00:00
|
|
|
error (0, 0, "LFS seems not to be supported.");
|
2001-01-08 22:28:15 +00:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
2001-02-05 21:38:54 +00:00
|
|
|
if (ret == -1)
|
|
|
|
{
|
2001-06-11 08:43:24 +00:00
|
|
|
error (0, errno, "lseek64 failed with error");
|
2001-02-05 21:38:54 +00:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
Fix MIPS n32 lseek, lseek64 (bug 21019).
The lseek consolidation broke lseek64 for MIPS n32, so resulting in
io/test-lfs failing with an incorrect return from ftello64. This
configuration uses the lseek syscall with a 64-bit return value; as
the C syscall macros return long, they cannot be used in this case and
so an assembly implementation is needed; accordingly, this patch adds
lseek64 back to syscalls.list for this configuration.
lseek was also broken, truncating the result without checking for
overflow. lseek however was already broken before the consolidation;
it aliased lseek64 so would return an out-of-range value, resulting in
architecturally undefined behavior in the caller if it tried to use a
non-sign-extended value with a 32-bit instruction. This patch adds a
custom lseek implementation in C for n32, which calls __lseek64 to get
the 64-bit value then checks for overflow.
Because the prior lseek breakage did not show in test results, and the
lseek64 breakage showed only indirectly through tests of ftello64,
test coverage was clearly inadequate. This patch extends
io/test-lfs.c to test the lseek64 return value (at a point where it
has already seeked over 2GB into a file), and then to test the lseek
return value (with the latter's expectations depending on whether
off_t is smaller than off64_t).
Tested for mips64 n32. Also tested test-lfs for x86_64 and x86, where
as expected it passes.
[BZ #21019]
* sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list (lseek64):
New syscall entry.
* sysdeps/unix/sysv/linux/mips/mips64/n32/lseek.c: New file.
* io/test-lfs.c (do_test): Test offset returned from lseek64 and
lseek.
2017-01-02 23:09:25 +00:00
|
|
|
off64_t offset64 = lseek64 (fd, 0, SEEK_CUR);
|
|
|
|
if (offset64 != TWO_GB + 100)
|
|
|
|
{
|
|
|
|
error (0, 0, "lseek64 did not return expected offset");
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
off_t offset = lseek (fd, 0, SEEK_CUR);
|
|
|
|
if (sizeof (off_t) < sizeof (off64_t))
|
|
|
|
{
|
|
|
|
if (offset != -1 || errno != EOVERFLOW)
|
|
|
|
{
|
|
|
|
error (0, 0, "lseek did not fail with EOVERFLOW");
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (offset != TWO_GB + 100)
|
|
|
|
{
|
|
|
|
error (0, 0, "lseek did not return expected offset");
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
2000-06-30 09:55:04 +00:00
|
|
|
|
|
|
|
ret = write (fd, "Hello", 5);
|
2001-06-11 08:43:24 +00:00
|
|
|
if (ret == -1 && errno == EFBIG)
|
|
|
|
{
|
|
|
|
error (0, 0, "LFS seems not to be supported.");
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == -1 && errno == ENOSPC)
|
2000-06-30 09:55:04 +00:00
|
|
|
{
|
2001-06-11 08:43:24 +00:00
|
|
|
error (0, 0, "Not enough space to write file.");
|
2000-06-30 09:55:04 +00:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
2000-09-14 06:44:19 +00:00
|
|
|
|
2000-06-30 09:55:04 +00:00
|
|
|
if (ret != 5)
|
|
|
|
error (EXIT_FAILURE, errno, "cannot write test string to large file");
|
|
|
|
|
|
|
|
ret = close (fd);
|
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
error (EXIT_FAILURE, errno, "error closing file");
|
|
|
|
|
|
|
|
ret = stat64 (name, &statbuf);
|
|
|
|
|
2000-09-14 06:44:19 +00:00
|
|
|
if (ret == -1 && (errno == ENOSYS || errno == EOVERFLOW))
|
2001-06-11 08:43:24 +00:00
|
|
|
error (0, 0, "stat64 is not supported.");
|
2000-06-30 09:55:04 +00:00
|
|
|
else if (ret == -1)
|
|
|
|
error (EXIT_FAILURE, errno, "cannot stat file `%s'", name);
|
2000-11-20 17:40:29 +00:00
|
|
|
else if (statbuf.st_size != (TWO_GB + 100 + 5))
|
2000-06-30 09:55:04 +00:00
|
|
|
error (EXIT_FAILURE, 0, "stat reported size %lld instead of %lld.",
|
2000-11-20 17:40:29 +00:00
|
|
|
(long long int) statbuf.st_size, (TWO_GB + 100 + 5));
|
2000-06-30 09:55:04 +00:00
|
|
|
|
2015-08-10 12:12:47 +00:00
|
|
|
fd2 = openat64 (AT_FDCWD, name, O_RDWR);
|
|
|
|
if (fd2 == -1)
|
|
|
|
{
|
|
|
|
if (errno == ENOSYS)
|
|
|
|
{
|
|
|
|
/* Silently ignore this test. */
|
|
|
|
error (0, 0, "openat64 is not supported");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error (EXIT_FAILURE, errno, "openat64 failed to open big file");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = close (fd2);
|
|
|
|
|
|
|
|
if (ret == -1)
|
|
|
|
error (EXIT_FAILURE, errno, "error closing file");
|
|
|
|
}
|
|
|
|
|
2001-02-05 21:38:54 +00:00
|
|
|
test_ftello ();
|
|
|
|
|
2000-06-30 09:55:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|