aboutsummaryrefslogtreecommitdiff
path: root/io
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-02-17 15:59:34 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-06-15 10:42:11 -0300
commit088d3291ef3dac918b002f84eace4c5a7b757f4f (patch)
treef9983979703ae380ae0450112db6b1d65c5d4051 /io
parent372d2ef1f9ef67a679ae5143ab3bac8997b80160 (diff)
downloadglibc-088d3291ef3dac918b002f84eace4c5a7b757f4f.tar
glibc-088d3291ef3dac918b002f84eace4c5a7b757f4f.tar.gz
glibc-088d3291ef3dac918b002f84eace4c5a7b757f4f.tar.bz2
glibc-088d3291ef3dac918b002f84eace4c5a7b757f4f.zip
y2038: Add test coverage
It is enabled through a new rule, tests-y2038, which is built only when the ABI supports the comapt 64-bit time_t (defined by the header time64-compat.h, which also enables the creation of the symbol Version for Linux). It means the tests are not built for ABI which already provide default 64-bit time_t. The new rule already adds the required LFS and 64-bit time_t compiler flags. The current coverage is: * libc: - adjtime tst-adjtime-time64 - adjtimex tst-adjtimex-time64 - clock_adjtime tst-clock_adjtime-time64 - clock_getres tst-clock-time64, tst-cpuclock1-time64 - clock_gettime tst-clock-time64, tst-clock2-time64, tst-cpuclock1-time64 - clock_nanosleep tst-clock_nanosleep-time64, tst-cpuclock1-time64 - clock_settime tst-clock2-time64 - cnd_timedwait tst-cnd-timedwait-time64 - ctime tst-ctime-time64 - ctime_r tst-ctime-time64 - difftime tst-difftime-time64 - fstat tst-stat-time64 - fstatat tst-stat-time64 - futimens tst-futimens-time64 - futimes tst-futimes-time64 - futimesat tst-futimesat-time64 - fts_* tst-fts-time64 - getitimer tst-itimer-timer64 - getrusage - gettimeofday tst-clock_nanosleep-time64 - glob / globfree tst-gnuglob64-time64 - gmtime tst-gmtime-time64 - gmtime_r tst-gmtime-time64 - lstat tst-stat-time64 - localtime tst-y2039-time64 - localtime_t tst-y2039-time64 - lutimes tst-lutimes-time64 - mktime tst-mktime4-time64 - mq_timedreceive tst-mqueue{1248}-time64 - mq_timedsend tst-mqueue{1248}-time64 - msgctl test-sysvmsg-time64 - mtx_timedlock tst-mtx-timedlock-time64 - nanosleep tst-cpuclock{12}-time64, tst-mqueue8-time64, tst-clock-time64 - nftw / ftw ftwtest-time64 - ntp_adjtime tst-ntp_adjtime-time64 - ntp_gettime tst-ntp_gettime-time64 - ntp_gettimex tst-ntp_gettimex-time64 - ppoll tst-ppoll-time64 - pselect tst-pselect-time64 - pthread_clockjoin_np tst-join14-time64 - pthread_cond_clockwait tst-cond11-time64 - pthread_cond_timedwait tst-abstime-time64 - pthread_mutex_clocklock tst-abstime-time64 - pthread_mutex_timedlock tst-abstime-time64 - pthread_rwlock_clockrdlock tst-abstime-time64, tst-rwlock14-time64 - pthread_rwlock_clockwrlock tst-abstime-time64, tst-rwlock14-time64 - pthread_rwlock_timedrdlock tst-abstime-time64, tst-rwlock14-time64 - pthread_rwlock_timedwrlock tst-abstime-time64, tst-rwlock14-time64 - pthread_timedjoin_np tst-join14-time64 - recvmmsg tst-cancel4_2-time64 - sched_rr_get_interval tst-sched_rr_get_interval-time64 - select tst-select-time64 - sem_clockwait tst-sem5-time64 - sem_timedwait tst-sem5-time64 - semctl test-sysvsem-time64 - semtimedop test-sysvsem-time64 - setitimer tst-mqueue2-time64, tst-itimer-timer64 - settimeofday tst-settimeofday-time64 - shmctl test-sysvshm-time64 - sigtimedwait tst-sigtimedwait-time64 - stat tst-stat-time64 - thrd_sleep tst-thrd-sleep-time64 - time tst-mqueue{1248}-time64 - timegm tst-timegm-time64 - timer_gettime tst-timer4-time64 - timer_settime tst-timer4-time64 - timerfd_gettime tst-timerfd-time64 - timerfd_settime tst-timerfd-time64 - timespec_get tst-timespec_get-time64 - timespec_getres tst-timespec_getres-time64 - utime tst-utime-time64 - utimensat tst-utimensat-time64 - utimes tst-utimes-time64 - wait3 tst-wait3-time64 - wait4 tst-wait4-time64 * librt: - aio_suspend tst-aio6-time64 - mq_timedreceive tst-mqueue{1248}-time64 - mq_timedsend tst-mqueue{1248}-time64 - timer_gettime tst-timer4-time64 - timer_settime tst-timer4-time64 * libanl: - gai_suspend Reviewed-by: Lukasz Majewski <lukma@denx.de> Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'io')
-rw-r--r--io/Makefile22
-rw-r--r--io/ftwtest-time64.c1
-rw-r--r--io/tst-fts-time64.c1
-rw-r--r--io/tst-futimens-time64.c2
-rw-r--r--io/tst-futimens.c6
-rw-r--r--io/tst-futimes-time64.c2
-rw-r--r--io/tst-futimes.c6
-rw-r--r--io/tst-futimesat-time64.c4
-rw-r--r--io/tst-futimesat.c47
-rw-r--r--io/tst-lutimes-time64.c2
-rw-r--r--io/tst-lutimes.c10
-rw-r--r--io/tst-stat-time64.c102
-rw-r--r--io/tst-utime-time64.c2
-rw-r--r--io/tst-utime.c6
-rw-r--r--io/tst-utimensat-time64.c2
-rw-r--r--io/tst-utimensat.c12
-rw-r--r--io/tst-utimes-time64.c2
-rw-r--r--io/tst-utimes.c6
18 files changed, 209 insertions, 26 deletions
diff --git a/io/Makefile b/io/Makefile
index d35e966258..ba8bd37355 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -59,7 +59,7 @@ routines := \
ftw64-time64
others := pwd
-test-srcs := ftwtest
+test-srcs := ftwtest ftwtest-time64
tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \
tst-fcntl bug-ftw1 bug-ftw2 bug-ftw3 bug-ftw4 tst-statvfs \
tst-openat tst-unlinkat tst-fstatat tst-futimesat \
@@ -78,12 +78,24 @@ tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \
tst-futimens \
tst-utimensat \
+tests-time64 := \
+ tst-futimens-time64 \
+ tst-futimes-time64\
+ tst-fts-time64 \
+ tst-lutimes-time64 \
+ tst-stat-time64 \
+ tst-futimesat-time64 \
+ tst-utime-time64 \
+ tst-utimensat-time64 \
+ tst-utimes-time64 \
+
# Likewise for statx, but we do not need static linking here.
tests-internal += tst-statx
tests-static += tst-statx
ifeq ($(run-built-tests),yes)
-tests-special += $(objpfx)ftwtest.out
+tests-special += $(objpfx)ftwtest.out \
+ $(objpfx)ftwtest-time64.out
endif
include ../Rules
@@ -125,8 +137,14 @@ tst-statvfs-ARGS = $(objpfx)tst-statvfs tst-statvfs.c /tmp
tst-open-tmpfile-ARGS = --test-dir=$(objpfx)
+CFLAGS-ftwtest-time64.c += -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64
+
ifeq ($(run-built-tests),yes)
$(objpfx)ftwtest.out: ftwtest-sh $(objpfx)ftwtest
$(SHELL) $< $(common-objpfx) '$(test-program-cmd)' > $@; \
$(evaluate-test)
+
+$(objpfx)ftwtest-time64.out: ftwtest-sh $(objpfx)ftwtest-time64
+ $(SHELL) $< $(common-objpfx) '$(test-program-cmd)' > $@; \
+ $(evaluate-test)
endif
diff --git a/io/ftwtest-time64.c b/io/ftwtest-time64.c
new file mode 100644
index 0000000000..67f1c46826
--- /dev/null
+++ b/io/ftwtest-time64.c
@@ -0,0 +1 @@
+#include "ftwtest.c"
diff --git a/io/tst-fts-time64.c b/io/tst-fts-time64.c
new file mode 100644
index 0000000000..a4a41fe1cf
--- /dev/null
+++ b/io/tst-fts-time64.c
@@ -0,0 +1 @@
+#include "tst-fts.c"
diff --git a/io/tst-futimens-time64.c b/io/tst-futimens-time64.c
new file mode 100644
index 0000000000..88fcb38489
--- /dev/null
+++ b/io/tst-futimens-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-futimens.c"
diff --git a/io/tst-futimens.c b/io/tst-futimens.c
index b3e3f3137f..4c18ede573 100644
--- a/io/tst-futimens.c
+++ b/io/tst-futimens.c
@@ -20,13 +20,17 @@
#include <support/xunistd.h>
#include <sys/stat.h>
+#ifndef struct_stat
+# define struct_stat struct stat64
+#endif
+
static int
test_futimens_helper (const char *file, int fd, const struct timespec *ts)
{
int result = futimens (fd, ts);
TEST_VERIFY_EXIT (result == 0);
- struct stat64 st;
+ struct_stat st;
xfstat (fd, &st);
/* Check if seconds for atime match */
diff --git a/io/tst-futimes-time64.c b/io/tst-futimes-time64.c
new file mode 100644
index 0000000000..d489c265d1
--- /dev/null
+++ b/io/tst-futimes-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-futimes.c"
diff --git a/io/tst-futimes.c b/io/tst-futimes.c
index bdef38d7cb..9575a4b08e 100644
--- a/io/tst-futimes.c
+++ b/io/tst-futimes.c
@@ -21,13 +21,17 @@
#include <sys/stat.h>
#include <sys/time.h>
+#ifndef struct_stat
+# define struct_stat struct stat64
+#endif
+
static int
test_futimens_helper (const char *file, int fd, const struct timeval *tv)
{
int r = futimes (fd, tv);
TEST_VERIFY_EXIT (r == 0);
- struct stat64 st;
+ struct_stat st;
xfstat (fd, &st);
/* Check if seconds for atime match */
diff --git a/io/tst-futimesat-time64.c b/io/tst-futimesat-time64.c
new file mode 100644
index 0000000000..f6c0500eef
--- /dev/null
+++ b/io/tst-futimesat-time64.c
@@ -0,0 +1,4 @@
+#define struct_stat struct stat
+#define fstat fstat
+#define fstatat fstatat
+#include "io/tst-futimesat.c"
diff --git a/io/tst-futimesat.c b/io/tst-futimesat.c
index af58ad06dd..c32ab2b668 100644
--- a/io/tst-futimesat.c
+++ b/io/tst-futimesat.c
@@ -1,4 +1,23 @@
+/* futimesat basic tests.
+ Copyright (C) 2021 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ 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.
+
+ 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
#include <dirent.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -7,19 +26,19 @@
#include <sys/stat.h>
#include <sys/time.h>
+#include <support/test-driver.h>
+#include <support/temp_file.h>
-static void prepare (void);
-#define PREPARE(argc, argv) prepare ()
-
-static int do_test (void);
-#define TEST_FUNCTION do_test ()
-
-#include "../test-skeleton.c"
+#ifndef struct_stat
+# define struct_stat struct stat64
+# define fstat fstat64
+# define fstatat fstatat64
+#endif
static int dir_fd;
static void
-prepare (void)
+prepare (int argc, char *argv[])
{
size_t test_dir_len = strlen (test_dir);
static const char dir_name[] = "/tst-futimesat.XXXXXX";
@@ -48,7 +67,7 @@ prepare (void)
exit (1);
}
}
-
+#define PREPARE prepare
static int
do_test (void)
@@ -98,8 +117,8 @@ do_test (void)
write (fd, "hello", 5);
puts ("file created");
- struct stat64 st1;
- if (fstat64 (fd, &st1) != 0)
+ struct_stat st1;
+ if (fstat (fd, &st1) != 0)
{
puts ("fstat64 failed");
return 1;
@@ -118,8 +137,8 @@ do_test (void)
return 1;
}
- struct stat64 st2;
- if (fstatat64 (dir_fd, "some-file", &st2, 0) != 0)
+ struct_stat st2;
+ if (fstatat (dir_fd, "some-file", &st2, 0) != 0)
{
puts ("fstatat64 failed");
return 1;
@@ -146,3 +165,5 @@ do_test (void)
return 0;
}
+
+#include <support/test-driver.c>
diff --git a/io/tst-lutimes-time64.c b/io/tst-lutimes-time64.c
new file mode 100644
index 0000000000..06caec0a91
--- /dev/null
+++ b/io/tst-lutimes-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-lutimes.c"
diff --git a/io/tst-lutimes.c b/io/tst-lutimes.c
index b2da3c5796..237a870415 100644
--- a/io/tst-lutimes.c
+++ b/io/tst-lutimes.c
@@ -21,23 +21,27 @@
#include <sys/stat.h>
#include <sys/time.h>
+#ifndef struct_stat
+# define struct_stat struct stat64
+#endif
+
static int
test_lutimes_helper (const char *testfile, int fd, const char *testlink,
const struct timeval *tv)
{
- struct stat64 stfile_orig;
+ struct_stat stfile_orig;
xlstat (testfile, &stfile_orig);
TEST_VERIFY_EXIT (lutimes (testlink, tv) == 0);
- struct stat64 stlink;
+ struct_stat stlink;
xlstat (testlink, &stlink);
TEST_COMPARE (stlink.st_atime, tv[0].tv_sec);
TEST_COMPARE (stlink.st_mtime, tv[1].tv_sec);
/* Check if the timestamp from original file is not changed. */
- struct stat64 stfile;
+ struct_stat stfile;
xlstat (testfile, &stfile);
TEST_COMPARE (stfile_orig.st_atime, stfile.st_atime);
diff --git a/io/tst-stat-time64.c b/io/tst-stat-time64.c
new file mode 100644
index 0000000000..8feded56d5
--- /dev/null
+++ b/io/tst-stat-time64.c
@@ -0,0 +1,102 @@
+/* Basic test of stat with 64-bit time_t interfaces.
+ Copyright (C) 2021 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ 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.
+
+ 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/xunistd.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+
+/* The idea of the test is check whether the 64-bit time_t stat implementation
+ returns the expected value for comparable fields, so it does not really
+ matter whether statx uses a fallback implementation or not. */
+
+static void
+stat_check (int fd, const char *path, struct stat *st)
+{
+ TEST_COMPARE (stat (path, st), 0);
+}
+
+static void
+lstat_check (int fd, const char *path, struct stat *st)
+{
+ TEST_COMPARE (lstat (path, st), 0);
+}
+
+static void
+fstat_check (int fd, const char *path, struct stat *st)
+{
+ TEST_COMPARE (fstat (fd, st), 0);
+}
+
+static void
+fstatat_check (int fd, const char *path, struct stat *st)
+{
+ TEST_COMPARE (fstatat (fd, path, st, 0), 0);
+}
+
+typedef void (*test_t)(int, const char *path, struct stat *);
+
+static int
+do_test (void)
+{
+ char *path;
+ int fd = create_temp_file ("tst-statx-", &path);
+ TEST_VERIFY_EXIT (fd >= 0);
+ support_write_file_string (path, "abc");
+
+ struct statx stx;
+ TEST_COMPARE (statx (fd, path, 0, STATX_BASIC_STATS, &stx), 0);
+
+ for (test_t *test = (test_t[]) { stat_check, lstat_check, fstat_check,
+ fstatat_check, NULL };
+ *test != NULL; test++)
+ {
+ struct stat st;
+ (*test) (fd, path, &st);
+
+ TEST_COMPARE (stx.stx_dev_major, major (st.st_dev));
+ TEST_COMPARE (stx.stx_dev_minor, minor (st.st_dev));
+ TEST_COMPARE (stx.stx_ino, st.st_ino);
+ TEST_COMPARE (stx.stx_mode, st.st_mode);
+ TEST_COMPARE (stx.stx_nlink, st.st_nlink);
+ TEST_COMPARE (stx.stx_uid, st.st_uid);
+ TEST_COMPARE (stx.stx_gid, st.st_gid);
+ TEST_COMPARE (stx.stx_rdev_major, major (st.st_rdev));
+ TEST_COMPARE (stx.stx_rdev_minor, minor (st.st_rdev));
+ TEST_COMPARE (stx.stx_blksize, st.st_blksize);
+ TEST_COMPARE (stx.stx_blocks, st.st_blocks);
+
+ TEST_COMPARE (stx.stx_ctime.tv_sec, st.st_ctim.tv_sec);
+ TEST_COMPARE (stx.stx_ctime.tv_nsec, st.st_ctim.tv_nsec);
+ TEST_COMPARE (stx.stx_mtime.tv_sec, st.st_mtim.tv_sec);
+ TEST_COMPARE (stx.stx_mtime.tv_nsec, st.st_mtim.tv_nsec);
+ }
+
+ xclose (fd);
+ free (path);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/io/tst-utime-time64.c b/io/tst-utime-time64.c
new file mode 100644
index 0000000000..eb62f59126
--- /dev/null
+++ b/io/tst-utime-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-utime.c"
diff --git a/io/tst-utime.c b/io/tst-utime.c
index 6269ef7929..0144e2a22a 100644
--- a/io/tst-utime.c
+++ b/io/tst-utime.c
@@ -21,13 +21,17 @@
#include <support/xunistd.h>
#include <sys/stat.h>
+#ifndef struct_stat
+# define struct_stat struct stat64
+#endif
+
static int
test_utime_helper (const char *file, int fd, const struct utimbuf *ut)
{
int result = utime (file, ut);
TEST_VERIFY_EXIT (result == 0);
- struct stat64 st;
+ struct_stat st;
xfstat (fd, &st);
/* Check if seconds for actime match */
diff --git a/io/tst-utimensat-time64.c b/io/tst-utimensat-time64.c
new file mode 100644
index 0000000000..7ac7d8df1d
--- /dev/null
+++ b/io/tst-utimensat-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-utimensat.c"
diff --git a/io/tst-utimensat.c b/io/tst-utimensat.c
index 0c7c8470bc..062abdd8d3 100644
--- a/io/tst-utimensat.c
+++ b/io/tst-utimensat.c
@@ -22,6 +22,10 @@
#include <sys/stat.h>
#include <sys/time.h>
+#ifndef struct_stat
+# define struct_stat struct stat64
+#endif
+
static int
test_utimesat_helper (const char *testfile, int fd, const char *testlink,
const struct timespec *ts)
@@ -29,7 +33,7 @@ test_utimesat_helper (const char *testfile, int fd, const char *testlink,
{
TEST_VERIFY_EXIT (utimensat (fd, testfile, ts, 0) == 0);
- struct stat64 st;
+ struct_stat st;
xfstat (fd, &st);
/* Check if seconds for atime match */
@@ -40,20 +44,20 @@ test_utimesat_helper (const char *testfile, int fd, const char *testlink,
}
{
- struct stat64 stfile_orig;
+ struct_stat stfile_orig;
xlstat (testfile, &stfile_orig);
TEST_VERIFY_EXIT (utimensat (0 /* ignored */, testlink, ts,
AT_SYMLINK_NOFOLLOW)
== 0);
- struct stat64 stlink;
+ struct_stat stlink;
xlstat (testlink, &stlink);
TEST_COMPARE (stlink.st_atime, ts[0].tv_sec);
TEST_COMPARE (stlink.st_mtime, ts[1].tv_sec);
/* Check if the timestamp from original file is not changed. */
- struct stat64 stfile;
+ struct_stat stfile;
xlstat (testfile, &stfile);
TEST_COMPARE (stfile_orig.st_atime, stfile.st_atime);
diff --git a/io/tst-utimes-time64.c b/io/tst-utimes-time64.c
new file mode 100644
index 0000000000..234ec02541
--- /dev/null
+++ b/io/tst-utimes-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-utimes.c"
diff --git a/io/tst-utimes.c b/io/tst-utimes.c
index 991ab0c7d3..e88efff45b 100644
--- a/io/tst-utimes.c
+++ b/io/tst-utimes.c
@@ -22,13 +22,17 @@
#include <sys/time.h>
#include <time.h>
+#ifndef struct_stat
+# define struct_stat struct stat64
+#endif
+
static int
test_utimes_helper (const char *file, int fd, const struct timeval *tv)
{
int result = utimes (file, tv);
TEST_VERIFY_EXIT (result == 0);
- struct stat64 st;
+ struct_stat st;
xfstat (fd, &st);
/* Check if seconds for atime match */