[v2] Mount /tmp as tmpfs in test-container and run utime tests in it

Message ID 20210309225405.GA84301@aloka.lostca.se
State Under Review, archived
Headers
Series [v2] Mount /tmp as tmpfs in test-container and run utime tests in it |

Commit Message

Arjun Shankar March 9, 2021, 10:54 p.m. UTC
  From: Arjun Shankar <arjun@redhat.com>

tst-utime.c, tst-utimes.c, and tst-futimens.c create a temporary file in
/tmp to test Y2038 support in the corresponding functions.  This causes
the tests to fail when /tmp is mounted as a filesystem that has a Y2038
bug; e.g. XFS.

This commit changes test-container.c to mount /tmp as a tmpfs filesystem
and moves the utime tests to the tests-container target so that they run
in a container against a known-good filesystem.

The test-container change of mounting /tmp as tmpfs led to one of the
existing container tests, elf/tst-ldconfig-ld_so_conf-update, to fail.
This commit also adjusts the test to not use /tmp any more.
---
Notes:

v1 ("Prefer /dev/shm over /tmp in utime family tests") here:
https://sourceware.org/pipermail/libc-alpha/2021-March/123486.html

I went a different way this time.  Since we cannot touch /dev/shm and since
/tmp is not guaranteed to be tmpfs every time, I containerised the tests.
This meant modifying test-container to mount /tmp as tmpfs and adjusting one
existing container test that failed due to /tmp being a mount point.
---
 elf/tst-ldconfig-ld_so_conf-update.c | 4 ++--
 support/test-container.c             | 4 +++-
 sysdeps/unix/sysv/linux/Makefile     | 5 +++--
 3 files changed, 8 insertions(+), 5 deletions(-)
  

Comments

DJ Delorie March 11, 2021, 2:27 a.m. UTC | #1
Another patchwork test, ignore or not at your peril ;-)
  

Patch

diff --git a/elf/tst-ldconfig-ld_so_conf-update.c b/elf/tst-ldconfig-ld_so_conf-update.c
index e8bd4c3598..7462516f59 100644
--- a/elf/tst-ldconfig-ld_so_conf-update.c
+++ b/elf/tst-ldconfig-ld_so_conf-update.c
@@ -32,7 +32,7 @@ 
 
 
 #define DSO "libldconfig-ld-mod.so"
-#define DSO_DIR "/tmp/tst-ldconfig"
+#define DSO_DIR "/tst-ldconfig"
 #define CONF "/etc/ld.so.conf"
 
 
@@ -73,7 +73,7 @@  do_test (void)
      "lib" (for regular shared libraries) or "ld-" (for ld-linux-*).  */
   char *mod_src_path = xasprintf ("%s/tst-ldconfig-ld-mod.so",
 				  support_libdir_prefix);
-  if (rename (mod_src_path, "/tmp/tst-ldconfig/libldconfig-ld-mod.so"))
+  if (rename (mod_src_path, DSO_DIR "/libldconfig-ld-mod.so"))
     FAIL_EXIT1 ("Renaming/moving the DSO failed: %m");
   free (mod_src_path);
 
diff --git a/support/test-container.c b/support/test-container.c
index 28cc44d9f1..0924bdc2e7 100644
--- a/support/test-container.c
+++ b/support/test-container.c
@@ -1160,7 +1160,9 @@  main (int argc, char **argv)
   sprintf (pid_buf, "%lu", (long unsigned)child);
   setenv ("PID_OUTSIDE_CONTAINER", pid_buf, 0);
 
-  maybe_xmkdir ("/tmp", 0755);
+  maybe_xmkdir ("/tmp", 1777);
+  if (mount ("none", "/tmp", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV, NULL) < 0)
+    FAIL_EXIT1 ("can't mount tmpfs onto /tmp\n");
 
   /* Now that we're pid 1 (effectively "root") we can mount /proc  */
   maybe_xmkdir ("/proc", 0777);
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index e42bc7f13b..cdbeb81f9c 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -107,8 +107,9 @@  tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
 	 test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \
 	 tst-rlimit-infinity tst-ofdlocks tst-gettid tst-gettid-kill \
 	 tst-tgkill tst-sysvsem-linux tst-sysvmsg-linux tst-sysvshm-linux \
-	 tst-timerfd tst-ppoll tst-futimens tst-utime tst-utimes \
-	 tst-clock_adjtime tst-adjtimex tst-ntp_adjtime
+	 tst-timerfd tst-ppoll tst-clock_adjtime tst-adjtimex tst-ntp_adjtime
+
+tests-container += tst-futimens tst-utime tst-utimes
 
 # Test for the symbol version of fcntl that was replaced in glibc 2.28.
 ifeq ($(have-GLIBC_2.27)$(build-shared),yesyes)