merge from gcc
[external/binutils.git] / gold / testsuite / tls_test.cc
index 995e20b..880bf23 100644 (file)
@@ -1,6 +1,6 @@
 // tls_test.cc -- test TLS variables for gold
 
-// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
 // last  Verify that the above tests left the variables set correctly.
 
 
+#include <cstdio>
+#include "config.h"
 #include "tls_test.h"
 
+#define CHECK_EQ_OR_RETURN(var, expected)                              \
+  do                                                                   \
+    {                                                                  \
+      if ((var) != (expected))                                         \
+       {                                                               \
+         printf(#var ": expected %d, found %d\n", expected, var);      \
+         return false;                                                 \
+       }                                                               \
+    }                                                                  \
+  while (0)
+
 __thread int v1;
 static __thread int v2;
+
+// We don't use these pointers, but putting them in tests alignment on
+// a 64-bit target.
+__thread char* p1;
+char dummy;
+__thread char* p2 = &dummy;
+
 __thread int v3 = 3;
 static __thread int v4 = 4;
 __thread int v5;
 static __thread int v6;
 
-// These variables are defined in tls_test_file2.cc
-extern __thread int o1;
-extern __thread int o2;
-extern __thread int o3;
+struct int128
+{
+  long long hi;
+  long long lo;
+};
+
+static __thread struct int128 v12 = { 115, 125 };
 
 bool
 t1()
 {
-  if (v1 != 0)
-    return false;
+  CHECK_EQ_OR_RETURN(v1, 0);
   v1 = 10;
   return true;
 }
@@ -70,8 +92,7 @@ t1()
 bool
 t2()
 {
-  if (v2 != 0)
-    return false;
+  CHECK_EQ_OR_RETURN(v2, 0);
   v2 = 20;
   return true;
 }
@@ -79,8 +100,7 @@ t2()
 bool
 t3()
 {
-  if (v3 != 3)
-    return false;
+  CHECK_EQ_OR_RETURN(v3, 3);
   v3 = 30;
   return true;
 }
@@ -88,8 +108,7 @@ t3()
 bool
 t4()
 {
-  if (v4 != 4)
-    return false;
+  CHECK_EQ_OR_RETURN(v4, 4);
   v4 = 40;
   return true;
 }
@@ -111,7 +130,8 @@ f5b(int* p)
 bool
 t5()
 {
-  return v5 == 50;
+  CHECK_EQ_OR_RETURN(v5, 50);
+  return true;
 }
 
 // For test 6 the main function calls f6b(f6a()), then calls t6().
@@ -131,7 +151,8 @@ f6b(int* p)
 bool
 t6()
 {
-  return v6 == 60;
+  CHECK_EQ_OR_RETURN(v6, 60);
+  return true;
 }
 
 // The slot for t7() is unused.
@@ -139,18 +160,16 @@ t6()
 bool
 t8()
 {
-  if (o1 != 0)
-    return false;
-  o1 = 10;
+  CHECK_EQ_OR_RETURN(o1, 0);
+  o1 = -10;
   return true;
 }
 
 bool
 t9()
 {
-  if (o2 != 2)
-    return false;
-  o2 = 20;
+  CHECK_EQ_OR_RETURN(o2, -2);
+  o2 = -20;
   return true;
 }
 
@@ -165,25 +184,41 @@ f10a()
 void
 f10b(int* p)
 {
-  *p = 30;
+  *p = -30;
 }
 
 bool
 t10()
 {
-  return o3 == 30;
+  CHECK_EQ_OR_RETURN(o3, -30);
+  return true;
+}
+
+bool
+t12()
+{
+  struct int128 newval = { 335, 345 };
+  CHECK_EQ_OR_RETURN((int) v12.hi, 115);
+  CHECK_EQ_OR_RETURN((int) v12.lo, 125);
+  v12 = newval;
+  return true;
 }
 
 bool
 t_last()
 {
-  return (v1 == 10
-         && v2 == 20
-         && v3 == 30
-         && v4 == 40
-         && v5 == 50
-         && v6 == 60
-          && o1 == 10
-          && o2 == 20
-          && o3 == 30);
+  CHECK_EQ_OR_RETURN(v1, 10);
+  CHECK_EQ_OR_RETURN(v2, 20);
+  CHECK_EQ_OR_RETURN(v3, 30);
+  CHECK_EQ_OR_RETURN(v4, 40);
+  CHECK_EQ_OR_RETURN(v5, 50);
+  CHECK_EQ_OR_RETURN(v6, 60);
+  CHECK_EQ_OR_RETURN((int) v12.hi, 335);
+  CHECK_EQ_OR_RETURN((int) v12.lo, 345);
+  CHECK_EQ_OR_RETURN(o1, -10);
+  CHECK_EQ_OR_RETURN(o2, -20);
+  CHECK_EQ_OR_RETURN(o3, -30);
+  int check = t11_last();
+  CHECK_EQ_OR_RETURN(check, 1);
+  return true;
 }