[git commit master] test_tls: Add two new tests for tls tst-tls{16, 17} taken from glibc

Carmelo Amoroso carmelo.amoroso at st.com
Fri Apr 23 14:31:55 UTC 2010


commit: http://git.uclibc.org/uClibc/commit/?id=b93ab6041d56a5a19d8a97b69f6e3202fd11e859
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/master

Signed-off-by: Filippo Arcidiacono <filippo.arcidiacono at st.com>
Signed-off-by: Carmelo Amoroso <carmelo.amoroso at st.com>
---
 test/tls/Makefile.in     |   23 ++++++++++++++++++-
 test/tls/tst-tls16.c     |   53 ++++++++++++++++++++++++++++++++++++++++++++++
 test/tls/tst-tls17.c     |   29 +++++++++++++++++++++++++
 test/tls/tst-tlsmod16a.c |    7 ++++++
 test/tls/tst-tlsmod16b.c |   13 +++++++++++
 test/tls/tst-tlsmod17a.c |   23 ++++++++++++++++++++
 test/tls/tst-tlsmod17b.c |   15 +++++++++++++
 7 files changed, 161 insertions(+), 2 deletions(-)
 create mode 100644 test/tls/tst-tls16.c
 create mode 100644 test/tls/tst-tls17.c
 create mode 100644 test/tls/tst-tlsmod16a.c
 create mode 100644 test/tls/tst-tlsmod16b.c
 create mode 100644 test/tls/tst-tlsmod17a.c
 create mode 100644 test/tls/tst-tlsmod17b.c

diff --git a/test/tls/Makefile.in b/test/tls/Makefile.in
index 41c5276..082ab1c 100644
--- a/test/tls/Makefile.in
+++ b/test/tls/Makefile.in
@@ -3,8 +3,8 @@
 
 TESTS := tst-tls1 tst-tls2 tst-tls3 tst-tls4 tst-tls5 tst-tls6 tst-tls7	\
 	tst-tls8 tst-tls9 tst-tls10 tst-tls11 tst-tls12 tst-tls13	\
-	tst-tls14 tst-tls15 tst-tls-at-ctor tst-tls1-static tst-tls2-static \
-	tst-tls9-static
+	tst-tls14 tst-tls15 tst-tls16 tst-tls17 tst-tls-at-ctor \
+	tst-tls1-static tst-tls2-static tst-tls9-static
 TESTS_DISABLED := tst-tls1-static tst-tls2-static tst-tls9-static
 
 # All these tests need tls.h, which is not installed with glibc
@@ -26,6 +26,7 @@ EXTRA_CFLAGS := -DNOT_IN_libc=1 \
 	-I$(top_builddir)include				\
 	-include $(top_builddir)include/libc-symbols.h
 
+tlsmod17a-suffixes := 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 CFLAGS_tst-tlsmod1.so := -fPIC -DSHARED -shared
 CFLAGS_tst-tlsmod2.so := -fPIC -DSHARED -shared
 CFLAGS_tst-tlsmod3.so := -fPIC -DSHARED -shared
@@ -44,6 +45,10 @@ CFLAGS_tst-tlsmod14a.so := -fPIC -DSHARED -shared
 CFLAGS_tst-tlsmod14b.so := -fPIC -DSHARED -shared
 CFLAGS_tst-tlsmod15a.so := -fPIC -DSHARED -shared
 CFLAGS_tst-tlsmod15b.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod16a.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod16b.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod17a.so := -fPIC -DSHARED -shared
+CFLAGS_tst-tlsmod17b.so := -fPIC -DSHARED -shared
 CFLAGS_tst-tlsmod-at-ctor.so := -fPIC -DSHARED -shared
 
 LDFLAGS_tst-tlsmod1.so := -shared -static-libgcc -L$(top_builddir)lib
@@ -70,6 +75,11 @@ LDFLAGS_tst-tlsmod14a.so := -shared -static-libgcc -L$(top_builddir)lib
 LDFLAGS_tst-tlsmod14b.so := -shared -static-libgcc -L$(top_builddir)lib
 LDFLAGS_tst-tlsmod15a.so := -shared -static-libgcc -L$(top_builddir)lib
 LDFLAGS_tst-tlsmod15b.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod16a.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod16b.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod17a.so := -shared -static-libgcc -L$(top_builddir)lib
+LDFLAGS_tst-tlsmod17b.so := -shared -static-libgcc -L$(top_builddir)lib \
+	$(patsubst %,tst-tlsmod17a%.so,$(tlsmod17a-suffixes))
 LDFLAGS_tst-tlsmod-at-ctor.so := -shared -static-libgcc -L$(top_builddir)lib
 
 LDFLAGS_tst-tls3 := tst-tlsmod1.so tst-tlsmod4.so
@@ -85,6 +95,8 @@ LDFLAGS_tst-tls12 := -Wl,-rpath-link=. tst-tlsmod12.so
 LDFLAGS_tst-tls13 := -ldl -Wl,-rpath-link=.
 LDFLAGS_tst-tls14 := -ldl -Wl,-rpath-link=. tst-tlsmod14a.so
 LDFLAGS_tst-tls15 := -ldl -Wl,-rpath-link=.
+LDFLAGS_tst-tls16 := -ldl -Wl,-rpath-link=.
+LDFLAGS_tst-tls17 := -ldl -Wl,-rpath-link=.
 LDFLAGS_tst-tls-at-ctor := tst-tlsmod-at-ctor.so
 
 tst-tls3: tst-tlsmod1.so tst-tlsmod4.so
@@ -100,6 +112,13 @@ tst-tls12: tst-tlsmod11.so tst-tlsmod12.so
 tst-tls13: tst-tlsmod13.so tst-tlsmod13a.so
 tst-tls14: tst-tlsmod14a.so tst-tlsmod14b.so
 tst-tls15: tst-tlsmod15b.so
+tst-tls16: tst-tlsmod16a.so tst-tlsmod16b.so
+tst-tls17: tst-tlsmod17b.so
+tst-tlsmod17b.so: $(patsubst %,tst-tlsmod17a%.so,$(tlsmod17a-suffixes))
+tst-tlsmod17a%.so: tst-tlsmod17a.c
+	$(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_tst-tlsmod17a.so) $< -o $@ \
+	-DN=$* -Wl,-soname,$@ $(LDFLAGS) $(EXTRA_LIBS) \
+	$(LDFLAGS_tst-tlsmod17a.so)
 tst-tls-at-ctor: tst-tlsmod-at-ctor.so
 
 RET_tst-tls13 := 1
diff --git a/test/tls/tst-tls16.c b/test/tls/tst-tls16.c
new file mode 100644
index 0000000..17912dc
--- /dev/null
+++ b/test/tls/tst-tls16.c
@@ -0,0 +1,53 @@
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static int
+do_test (void)
+{
+  void *h = dlopen ("tst-tlsmod16a.so", RTLD_LAZY | RTLD_GLOBAL);
+  if (h == NULL)
+    {
+      puts ("unexpectedly failed to open tst-tlsmod16a.so");
+      exit (1);
+    }
+
+  void *p = dlsym (h, "tlsvar");
+
+  /* This dlopen should indeed fail, because tlsvar was assigned to
+     dynamic TLS, and the new module requests it to be in static TLS.
+     However, there's a possibility that dlopen succeeds if the
+     variable is, for whatever reason, assigned to static TLS, or if
+     the module fails to require static TLS, or even if TLS is not
+     supported.  */
+  h = dlopen ("tst-tlsmod16b.so", RTLD_NOW | RTLD_GLOBAL);
+  if (h == NULL)
+    {
+      return 0;
+    }
+
+  puts ("unexpectedly succeeded to open tst-tlsmod16b.so");
+
+
+  void *(*fp) (void) = (void *(*) (void)) dlsym (h, "in_dso");
+  if (fp == NULL)
+    {
+      puts ("cannot find in_dso");
+      exit (1);
+    }
+
+  /* If the dlopen passes, at least make sure the address returned by
+     dlsym is the same as that returned by the initial-exec access.
+     If the variable was assigned to dynamic TLS during dlsym, this
+     portion will fail.  */
+  if (fp () != p)
+    {
+      puts ("returned values do not match");
+      exit (1);
+    }
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/test/tls/tst-tls17.c b/test/tls/tst-tls17.c
new file mode 100644
index 0000000..c1bc7d8
--- /dev/null
+++ b/test/tls/tst-tls17.c
@@ -0,0 +1,29 @@
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static int
+do_test (void)
+{
+  void *h = dlopen ("tst-tlsmod17b.so", RTLD_LAZY);
+  if (h == NULL)
+    {
+      puts ("unexpectedly failed to open tst-tlsmod17b.so");
+      exit (1);
+    }
+
+  int (*fp) (void) = (int (*) (void)) dlsym (h, "tlsmod17b");
+  if (fp == NULL)
+    {
+      puts ("cannot find tlsmod17b");
+      exit (1);
+    }
+
+  if (fp ())
+    exit (1);
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/test/tls/tst-tlsmod16a.c b/test/tls/tst-tlsmod16a.c
new file mode 100644
index 0000000..847c809
--- /dev/null
+++ b/test/tls/tst-tlsmod16a.c
@@ -0,0 +1,7 @@
+#include <tls.h>
+
+#if defined HAVE___THREAD && defined HAVE_TLS_MODEL_ATTRIBUTE
+int __thread tlsvar;
+#else
+int tlsvar;
+#endif
diff --git a/test/tls/tst-tlsmod16b.c b/test/tls/tst-tlsmod16b.c
new file mode 100644
index 0000000..308e6ba
--- /dev/null
+++ b/test/tls/tst-tlsmod16b.c
@@ -0,0 +1,13 @@
+#include <tls.h>
+
+#if defined HAVE___THREAD && defined HAVE_TLS_MODEL_ATTRIBUTE
+extern __thread int tlsvar __attribute__((tls_model("initial-exec")));
+#else
+extern int tlsvar;
+#endif
+
+void *
+in_dso (void)
+{
+  return &tlsvar;
+}
diff --git a/test/tls/tst-tlsmod17a.c b/test/tls/tst-tlsmod17a.c
new file mode 100644
index 0000000..eb599e7
--- /dev/null
+++ b/test/tls/tst-tlsmod17a.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+#ifndef N
+#define N 0
+#endif
+#define CONCAT1(s, n) s##n
+#define CONCAT(s, n) CONCAT1(s, n)
+
+__thread int CONCAT (v, N) = 4;
+
+int
+CONCAT (tlsmod17a, N) (void)
+{
+  int *p = &CONCAT (v, N);
+  /* GCC assumes &var is never NULL, add optimization barrier.  */
+  __asm __volatile ("" : "+r" (p));
+  if (p == NULL || *p != 4)
+    {
+      printf ("fail %d %p\n", N, p);
+      return 1;
+    }
+  return 0;
+}
diff --git a/test/tls/tst-tlsmod17b.c b/test/tls/tst-tlsmod17b.c
new file mode 100644
index 0000000..6178828
--- /dev/null
+++ b/test/tls/tst-tlsmod17b.c
@@ -0,0 +1,15 @@
+#define P(N) extern int tlsmod17a##N (void);
+#define PS P(0) P(1) P(2) P(3) P(4) P(5) P(6) P(7) P(8) P(9) \
+	   P(10) P(12) P(13) P(14) P(15) P(16) P(17) P(18) P(19)
+PS
+#undef P
+
+int
+tlsmod17b (void)
+{
+  int res = 0;
+#define P(N) res |= tlsmod17a##N ();
+  PS
+#undef P
+  return res;
+}
-- 
1.6.3.3



More information about the uClibc-cvs mailing list