[COMMITTED] miscellaneous test cleanups
diff mbox

Message ID 20150206205701.92C1F2C3A9B@topped-with-meat.com
State New
Headers show

Commit Message

Roland McGrath Feb. 6, 2015, 8:57 p.m. UTC
This is actually 12 non-overlapping commits, each quite small.  I'm posting
it all as one big patch to streamline reading (and posting) it.

It does various bits of cleanup in tests.  Substantially it's just
isolating Linuxisms or other overly-broad assumptions, such as existence
of SA_SIGINFO.  In many places there was no reason for those assumptions.
Only three tests touched here were actually deeply Linux-specific (once
that use clone directly to test something without also testing all of
pthread_create et al), and those are just made Linux-only.

Tested x86_64-linux-gnu.


Thanks,
Roland


	* nptl/tst-cancel25.c (tf2): Test for SIGCANCEL being blocked only if
	it's defined.
	* nptl/tst-signal7.c (do_test): Test SIGCANCEL only if it's defined.
	Test SIGSETXID only if it's defined.

	* nptl/tst-locale1.c (useless): Use SIGRTMIN only if it's defined.

	* rt/tst-timer2.c (do_test): Don't initialize SIGEV.sigev_signo, which
	will not be used.  Use NULL rather than 0 for .sigev_notify_attributes.

	* nptl/tst-align2.c: Moved ...
	* sysdeps/unix/sysv/linux/tst-align-clone.c: ... here.
	* nptl/Makefile (tests): Remove tst-align2.
	* sysdeps/unix/sysv/linux/Makefile
	[$(subdir) = nptl] (tests): Add tst-align-clone.
	* nptl/tst-getpid1.c: Moved ...
	* sysdeps/unix/sysv/linux/tst-getpid1.c: ... here.
	* nptl/tst-getpid2.c: Moved ...
	* sysdeps/unix/sysv/linux/tst-getpid2.c: ... here.
	* nptl/Makefile (tests): Move tst-getpid1 and tst-getpid2 ...
	* sysdeps/unix/sysv/linux/Makefile
	[$(subdir) = nptl] (tests): ... here.
	* nptl/Makefile (tst-getpid2-ENV): Move variable ...
	* sysdeps/unix/sysv/linux/Makefile
	[$(subdir) = nptl] (tst-getpid2-ENV): ... here.

	* nptl/tst-cleanup2.c (do_test): Use signal rather than sigaction.
	Drop trailing \n from perror argument.  Use return rather than exit.

	* nptl/tst-cancel20.c (do_test): Conditionalize SA_SIGINFO-using tests
	on [SA_SIGINFO].
	* nptl/tst-cancel21.c (do_test): Likewise.
	* debug/tst-backtrace6.c: Include <signal.h> first thing.
	Conditionalize inclusion of tst-backtrace5.c on [SA_SIGINFO].
	[!SA_SIGINFO]: Make it a stub test.

	* misc/tst-pselect.c (do_test): Don't set SA_NOCLDWAIT in sa_flags for
	SIGCHLD; it's redundant	with SIG_IGN as sa_handler.

	* posix/tst-getlogin.c: Move to ...
	* login/tst-getlogin.c: ... here.
	* posix/Makefile (tests): Move tst-getlogin to ...
	* login/Makefile (tests): ... here.

	* libio/tst-atime.c (do_test): Move local variables SV and E
	inside [ST_NOATIME] conditional.

	* dirent/tst-fdopendir.c (O_NOATIME): If not defined, #define to 0.

	* nptl/tst-kill5.c (do_test): Use INT_MAX rather than SIGRTMAX + 10.

	* nptl/tst-join5.c: Drop #include <sys/syscall.h>.
	(wait_code): New function replaces macro.
	Call nanosleep rather than syscall.

Patch
diff mbox

diff --git a/debug/tst-backtrace6.c b/debug/tst-backtrace6.c
index eb5028e..9c1ed75 100644
--- a/debug/tst-backtrace6.c
+++ b/debug/tst-backtrace6.c
@@ -17,5 +17,12 @@ 
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define SIGACTION_FLAGS SA_SIGINFO
-#include <debug/tst-backtrace5.c>
+#include <signal.h>
+
+#ifdef SA_SIGINFO
+# define SIGACTION_FLAGS SA_SIGINFO
+# include <debug/tst-backtrace5.c>
+#else
+# define TEST_FUNCTION  0
+# include "../test-skeleton.c"
+#endif
diff --git a/dirent/tst-fdopendir.c b/dirent/tst-fdopendir.c
index 3cf315d..0780c19 100644
--- a/dirent/tst-fdopendir.c
+++ b/dirent/tst-fdopendir.c
@@ -6,6 +6,9 @@ 
 #include <stdbool.h>
 #include <string.h>
 
+#ifndef O_NOATIME
+# define O_NOATIME	0
+#endif
 
 static int
 do_test (void)
diff --git a/libio/tst-atime.c b/libio/tst-atime.c
index 0b0b4f0..31ca59f 100644
--- a/libio/tst-atime.c
+++ b/libio/tst-atime.c
@@ -23,8 +23,6 @@  do_test (void)
   int ch;
   struct stat st1;
   struct stat st2;
-  struct statvfs sv;
-  int e;
 
   buf = (char *) malloc (strlen (test_dir) + sizeof "/tst-atime.XXXXXX");
   if (buf == NULL)
@@ -44,7 +42,8 @@  do_test (void)
 #ifdef ST_NOATIME
   /* Make sure the filesystem doesn't have the noatime option set.  If
      statvfs is not available just continue.  */
-  e = fstatvfs (fd, &sv);
+  struct statvfs sv;
+  int e = fstatvfs (fd, &sv);
   if (e != ENOSYS)
     {
       if (e != 0)
diff --git a/login/Makefile b/login/Makefile
index a2ebeff..0f4bb22 100644
--- a/login/Makefile
+++ b/login/Makefile
@@ -43,7 +43,7 @@  endif
 subdir-dirs = programs
 vpath %.c programs
 
-tests := tst-utmp tst-utmpx tst-grantpt tst-ptsname
+tests := tst-utmp tst-utmpx tst-grantpt tst-ptsname tst-getlogin
 
 # Build the -lutil library with these extra functions.
 extra-libs      := libutil
diff --git a/posix/tst-getlogin.c b/login/tst-getlogin.c
similarity index 100%
rename from posix/tst-getlogin.c
rename to login/tst-getlogin.c
diff --git a/misc/tst-pselect.c b/misc/tst-pselect.c
index 095d794..0d11a80 100644
--- a/misc/tst-pselect.c
+++ b/misc/tst-pselect.c
@@ -31,8 +31,6 @@  do_test (void)
     }
 
   sa.sa_handler = SIG_IGN;
-  sa.sa_flags = SA_NOCLDWAIT;
-
   if (sigaction (SIGCHLD, &sa, NULL) != 0)
     {
       puts ("2nd sigaction failed");
diff --git a/nptl/Makefile b/nptl/Makefile
index 43d8510..6ae76bb 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -229,7 +229,7 @@  tests = tst-typesizes \
 	tst-sem1 tst-sem2 tst-sem3 tst-sem4 tst-sem5 tst-sem6 tst-sem7 \
 	tst-sem8 tst-sem9 tst-sem10 tst-sem11 tst-sem12 tst-sem13 tst-sem14 \
 	tst-barrier1 tst-barrier2 tst-barrier3 tst-barrier4 \
-	tst-align tst-align2 tst-align3 \
+	tst-align tst-align3 \
 	tst-basic1 tst-basic2 tst-basic3 tst-basic4 tst-basic5 tst-basic6 \
 	tst-basic7 \
 	tst-kill1 tst-kill2 tst-kill3 tst-kill4 tst-kill5 tst-kill6 \
@@ -269,7 +269,7 @@  tests = tst-typesizes \
 	tst-backtrace1 \
 	tst-abstime \
 	tst-vfork1 tst-vfork2 tst-vfork1x tst-vfork2x \
-	tst-getpid1 tst-getpid2 tst-getpid3 \
+	tst-getpid3 \
 	tst-setuid3 \
 	tst-initializers1 $(addprefix tst-initializers1-,c89 gnu89 c99 gnu99) \
 	tst-bad-schedattr
@@ -463,11 +463,6 @@  tst-cancel7-ARGS = --command "exec $(host-test-program-cmd)"
 tst-cancelx7-ARGS = $(tst-cancel7-ARGS)
 tst-umask1-ARGS = $(objpfx)tst-umask1.temp
 
-# In this test, we create a CLONE_VM "thread" that shares TLS storage
-# with the original thread. Both threads then race in ld.so with lazy PLT
-# resolution. Avoid this race by disabling lazy binding. BZ #11214.
-tst-getpid2-ENV = LD_BIND_NOW=1
-
 $(objpfx)tst-atfork2: $(libdl) $(shared-thread-library)
 LDFLAGS-tst-atfork2 = -rdynamic
 tst-atfork2-ENV = MALLOC_TRACE=$(objpfx)tst-atfork2.mtrace
diff --git a/nptl/tst-cancel20.c b/nptl/tst-cancel20.c
index 4a964da..51b558e 100644
--- a/nptl/tst-cancel20.c
+++ b/nptl/tst-cancel20.c
@@ -227,6 +227,7 @@  do_test (void)
   if (do_one_test ())
     return 1;
 
+#ifdef SA_SIGINFO
   sa.sa_sigaction = (void (*)(int, siginfo_t *, void *)) sh;
   sigemptyset (&sa.sa_mask);
   sa.sa_flags = SA_SIGINFO;
@@ -254,6 +255,7 @@  do_test (void)
   puts ("sa_flags = SA_SIGINFO|SA_ONSTACK test");
   if (do_one_test ())
     return 1;
+#endif
 
   return 0;
 }
diff --git a/nptl/tst-cancel21.c b/nptl/tst-cancel21.c
index 35a27d4..b54f236 100644
--- a/nptl/tst-cancel21.c
+++ b/nptl/tst-cancel21.c
@@ -257,6 +257,7 @@  do_test (void)
   if (do_one_test ())
     return 1;
 
+#ifdef SA_SIGINFO
   sa.sa_sigaction = (void (*)(int, siginfo_t *, void *)) sh;
   sigemptyset (&sa.sa_mask);
   sa.sa_flags = SA_SIGINFO;
@@ -284,6 +285,7 @@  do_test (void)
   puts ("sa_flags = SA_SIGINFO|SA_ONSTACK test");
   if (do_one_test ())
     return 1;
+#endif
 
   return 0;
 }
diff --git a/nptl/tst-cancel25.c b/nptl/tst-cancel25.c
index 00b99ad..ed4205e 100644
--- a/nptl/tst-cancel25.c
+++ b/nptl/tst-cancel25.c
@@ -11,6 +11,7 @@  static pthread_t th2;
 static void *
 tf2 (void *arg)
 {
+#ifdef SIGCANCEL
   sigset_t mask;
   if (pthread_sigmask (SIG_SETMASK, NULL, &mask) != 0)
     {
@@ -22,6 +23,7 @@  tf2 (void *arg)
       puts ("SIGCANCEL blocked in new thread");
       exit (1);
     }
+#endif
 
   /* Sync with the main thread so that we do not test anything else.  */
   int e = pthread_barrier_wait (&b);
diff --git a/nptl/tst-cleanup2.c b/nptl/tst-cleanup2.c
index 8a524de..9e5a957 100644
--- a/nptl/tst-cleanup2.c
+++ b/nptl/tst-cleanup2.c
@@ -40,16 +40,11 @@  do_test (void)
      array.  Mark the return value as volatile so that it gets reloaded on
      return.  */
   volatile int ret = 0;
-  struct sigaction sa;
 
-  sa.sa_handler = sig_handler;
-  sigemptyset (&sa.sa_mask);
-  sa.sa_flags = SA_SIGINFO;
-
-  if (sigaction (SIGSEGV, &sa, 0))
+  if (signal (SIGSEGV, &sig_handler) == SIG_ERR)
     {
-      perror ("installing SIGSEGV handler\n");
-      exit (1);
+      perror ("installing SIGSEGV handler");
+      return 1;
     }
 
   puts ("Attempting to sprintf to null ptr");
diff --git a/nptl/tst-join5.c b/nptl/tst-join5.c
index e83f895..b45d210 100644
--- a/nptl/tst-join5.c
+++ b/nptl/tst-join5.c
@@ -22,15 +22,15 @@ 
 #include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
-#include <sys/syscall.h>
 
 
-#define wait_code()							      \
-  do {									      \
-    struct timespec ts = { .tv_sec = 0, .tv_nsec = 200000000 };		      \
-    while (syscall (__NR_nanosleep, &ts, &ts) < 0)			      \
-      /* nothing */;							      \
-  } while (0)
+static void
+wait_code (void)
+{
+  struct timespec ts = { .tv_sec = 0, .tv_nsec = 200000000 };
+  while (nanosleep (&ts, &ts) < 0)
+    ;
+}
 
 
 #ifdef WAIT_IN_CHILD
diff --git a/nptl/tst-kill5.c b/nptl/tst-kill5.c
index f16aae9..0717c03 100644
--- a/nptl/tst-kill5.c
+++ b/nptl/tst-kill5.c
@@ -21,6 +21,7 @@ 
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <limits.h>
 
 
 int
@@ -28,7 +29,7 @@  do_test (void)
 {
   /* XXX This test might require architecture and system specific changes.
      There is no guarantee that this signal number is invalid.  */
-  int e = pthread_kill (pthread_self (), SIGRTMAX + 10);
+  int e = pthread_kill (pthread_self (), INT_MAX);
   if (e == 0)
     {
       puts ("kill didn't failed");
diff --git a/nptl/tst-locale1.c b/nptl/tst-locale1.c
index 2ee4c3f..887b9a6 100644
--- a/nptl/tst-locale1.c
+++ b/nptl/tst-locale1.c
@@ -12,7 +12,11 @@  useless (void)
 {
   pthread_t th;
   pthread_create (&th, 0, (void *(*) (void *)) useless, 0);
+  int result = 0;
+#ifdef SIGRTMIN
   /* This is to check __libc_current_sigrt* can be used in statically
      linked apps.  */
-  return SIGRTMIN;
+  result = SIGRTMIN;
+#endif
+  return result;
 }
diff --git a/nptl/tst-signal7.c b/nptl/tst-signal7.c
index b388989..1fbf3db 100644
--- a/nptl/tst-signal7.c
+++ b/nptl/tst-signal7.c
@@ -27,6 +27,7 @@  do_test (void)
 {
   int result = 0;
 
+#ifdef SIGCANCEL
   errno = 0;
   if (sigaction (SIGCANCEL, NULL, NULL) == 0)
     {
@@ -38,7 +39,9 @@  do_test (void)
       puts ("sigaction(SIGCANCEL) did not set errno to EINVAL");
       result = 1;
     }
+#endif
 
+#ifdef SIGSETXID
   errno = 0;
   if (sigaction (SIGSETXID, NULL, NULL) == 0)
     {
@@ -50,6 +53,7 @@  do_test (void)
       puts ("sigaction(SIGSETXID) did not set errno to EINVAL");
       result = 1;
     }
+#endif
 
   return result;
 }
diff --git a/posix/Makefile b/posix/Makefile
index 5ee7b28..15e8818 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -64,7 +64,7 @@  routines :=								      \
 aux		:= init-posix environ
 tests		:= tstgetopt testfnm runtests runptests	     \
 		   tst-preadwrite tst-preadwrite64 test-vfork regexbug1 \
-		   tst-getlogin tst-mmap tst-getaddrinfo tst-truncate \
+		   tst-mmap tst-getaddrinfo tst-truncate \
 		   tst-truncate64 tst-fork tst-fnmatch tst-regexloc tst-dir \
 		   tst-chmod bug-regex1 bug-regex2 bug-regex3 bug-regex4 \
 		   tst-gnuglob tst-regex bug-regex5 bug-regex6 bug-regex7 \
diff --git a/rt/tst-timer2.c b/rt/tst-timer2.c
index 60026c1..b2ce987 100644
--- a/rt/tst-timer2.c
+++ b/rt/tst-timer2.c
@@ -30,9 +30,8 @@  do_test (void)
   itval.it_value.tv_nsec = 0;
 
   sigev.sigev_notify = SIGEV_THREAD;
-  sigev.sigev_signo = SIGRTMIN;
   sigev.sigev_notify_function = thread;
-  sigev.sigev_notify_attributes = 0;
+  sigev.sigev_notify_attributes = NULL;
   sigev.sigev_value.sival_ptr = (void *) &timerId;
 
   for (i = 0; i < 100; i++)
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 9f3718b..c26a12f 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -196,5 +196,10 @@  CFLAGS-gai.c += -DNEED_NETLINK
 endif
 
 ifeq ($(subdir),nptl)
-tests += tst-setgetname
+tests += tst-setgetname tst-align-clone tst-getpid1 tst-getpid2
+
+# In this test, we create a CLONE_VM "thread" that shares TLS storage
+# with the original thread. Both threads then race in ld.so with lazy PLT
+# resolution. Avoid this race by disabling lazy binding. BZ #11214.
+tst-getpid2-ENV = LD_BIND_NOW=1
 endif
diff --git a/nptl/tst-align2.c b/sysdeps/unix/sysv/linux/tst-align-clone.c
similarity index 100%
rename from nptl/tst-align2.c
rename to sysdeps/unix/sysv/linux/tst-align-clone.c
diff --git a/nptl/tst-getpid1.c b/sysdeps/unix/sysv/linux/tst-getpid1.c
similarity index 100%
rename from nptl/tst-getpid1.c
rename to sysdeps/unix/sysv/linux/tst-getpid1.c
diff --git a/nptl/tst-getpid2.c b/sysdeps/unix/sysv/linux/tst-getpid2.c
similarity index 100%
rename from nptl/tst-getpid2.c
rename to sysdeps/unix/sysv/linux/tst-getpid2.c