Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib Test alignment of constructor / destructor calls a...



details:   https://anonhg.NetBSD.org/src/rev/98592a1800b8
branches:  trunk
changeset: 759165:98592a1800b8
user:      joerg <joerg%NetBSD.org@localhost>
date:      Tue Nov 30 18:38:53 2010 +0000

description:
Test alignment of constructor / destructor calls as well as the stack
of new threads. Currently implement for i386 and AMD64.

diffstat:

 tests/lib/csu/Makefile                |  15 +++++++++++----
 tests/lib/csu/Makefile.check_stack    |  10 ++++++++++
 tests/lib/csu/dso/Makefile            |   8 ++++++--
 tests/lib/csu/dso/h_initfini3_dso.cxx |  20 ++++++++++++++++++++
 tests/lib/csu/dso/h_initfini_align.S  |  15 +++++++++++++++
 tests/lib/csu/h_initfini_common.cxx   |  20 ++++++++++++++++++++
 tests/lib/libpthread/Makefile         |   7 ++++++-
 tests/lib/libpthread/t_join.c         |  15 +++++++++++++--
 8 files changed, 101 insertions(+), 9 deletions(-)

diffs (235 lines):

diff -r ea3b9c8998bb -r 98592a1800b8 tests/lib/csu/Makefile
--- a/tests/lib/csu/Makefile    Tue Nov 30 18:37:59 2010 +0000
+++ b/tests/lib/csu/Makefile    Tue Nov 30 18:38:53 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2010/07/28 13:51:38 joerg Exp $
+# $NetBSD: Makefile,v 1.3 2010/11/30 18:38:53 joerg Exp $
 
 NOMAN=                 # defined
 
@@ -9,12 +9,19 @@
 TESTS_SUBDIRS=
 SUBDIR+=               dso
 
+.include "Makefile.check_stack"
+
+CPPFLAGS+=     ${CPPFLAGS_CHECK_STACK}
+
 BINDIR=                        ${TESTSDIR}
 PROG_CXX=              h_initfini1 h_initfini2 h_initfini3
-SRCS.h_initfini1=      h_initfini1.cxx h_initfini_common.cxx
-SRCS.h_initfini2=      h_initfini1.cxx h_initfini_common.cxx
+SRCS.h_initfini1=      h_initfini1.cxx h_initfini_common.cxx \
+                       ${SRCS_CHECK_STACK}
+SRCS.h_initfini2=      h_initfini1.cxx h_initfini_common.cxx \
+                       ${SRCS_CHECK_STACK}
 LDADD.h_initfini2+=    -static
-SRCS.h_initfini3=      h_initfini3.cxx h_initfini_common.cxx
+SRCS.h_initfini3=      h_initfini3.cxx h_initfini_common.cxx \
+                       ${SRCS_CHECK_STACK}
 LDADD.h_initfini3+=    -Wl,-rpath,${TESTSDIR}
 
 .include <bsd.test.mk>
diff -r ea3b9c8998bb -r 98592a1800b8 tests/lib/csu/Makefile.check_stack
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/csu/Makefile.check_stack        Tue Nov 30 18:38:53 2010 +0000
@@ -0,0 +1,10 @@
+# $NetBSD: Makefile.check_stack,v 1.1 2010/11/30 18:38:53 joerg Exp $
+
+.include <bsd.own.mk>
+
+CSU_ARCHDIR=   ${.PARSEDIR}/arch/${MACHINE_ARCH}
+.PATH: ${CSU_ARCHDIR}
+.if exists(${CSU_ARCHDIR}/h_initfini_align.S)
+SRCS_CHECK_STACK=      h_initfini_align.S
+CPPFLAGS_CHECK_STACK+= -DCHECK_STACK_ALIGNMENT
+.endif
diff -r ea3b9c8998bb -r 98592a1800b8 tests/lib/csu/dso/Makefile
--- a/tests/lib/csu/dso/Makefile        Tue Nov 30 18:37:59 2010 +0000
+++ b/tests/lib/csu/dso/Makefile        Tue Nov 30 18:38:53 2010 +0000
@@ -1,11 +1,14 @@
-# $NetBSD: Makefile,v 1.3 2010/08/04 13:56:10 joerg Exp $
+# $NetBSD: Makefile,v 1.4 2010/11/30 18:38:53 joerg Exp $
 
 NOMAN=         # defined
 
 .include <bsd.own.mk>
 
+.include "${.PARSEDIR}/../Makefile.check_stack"
+
 LIB=           h_initfini3_dso
-SRCS=          h_initfini3_dso.cxx
+SRCS=          h_initfini3_dso.cxx ${SRCS_CHECK_STACK}
+CPPFLAGS+=     ${CPPFLAGS_CHECK_STACK}
 
 LIBDIR=                ${TESTSBASE}/lib/csu
 SHLIBDIR=      ${TESTSBASE}/lib/csu
@@ -14,4 +17,5 @@
 LIBISMODULE=   yes
 LIBISCXX=      yes
 
+
 .include <bsd.lib.mk>
diff -r ea3b9c8998bb -r 98592a1800b8 tests/lib/csu/dso/h_initfini3_dso.cxx
--- a/tests/lib/csu/dso/h_initfini3_dso.cxx     Tue Nov 30 18:37:59 2010 +0000
+++ b/tests/lib/csu/dso/h_initfini3_dso.cxx     Tue Nov 30 18:38:53 2010 +0000
@@ -1,16 +1,36 @@
 #include <unistd.h>
 
+#ifdef CHECK_STACK_ALIGNMENT
+#include <stdlib.h>
+
+extern "C" int check_stack_alignment(void);
+#endif
+
 class Test2 {
 public:
        Test2()
        {
                static const char msg[] = "constructor2 executed\n";
                write(STDOUT_FILENO, msg, sizeof(msg) - 1);
+#ifdef CHECK_STACK_ALIGNMENT
+               if (!check_stack_alignment()) {
+                       static const char msg2[] = "stack unaligned \n";
+                       write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
+                       exit(1);
+               }
+#endif
        }
        ~Test2()
        {
                static const char msg[] = "destructor2 executed\n";
                write(STDOUT_FILENO, msg, sizeof(msg) - 1);
+#ifdef CHECK_STACK_ALIGNMENT
+               if (!check_stack_alignment()) {
+                       static const char msg2[] = "stack unaligned \n";
+                       write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
+                       exit(1);
+               }
+#endif
        }
 };
 
diff -r ea3b9c8998bb -r 98592a1800b8 tests/lib/csu/dso/h_initfini_align.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/csu/dso/h_initfini_align.S      Tue Nov 30 18:38:53 2010 +0000
@@ -0,0 +1,15 @@
+/*     $NetBSD: h_initfini_align.S,v 1.1 2010/11/30 18:38:53 joerg Exp $       */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.1 2010/11/30 18:38:53 joerg Exp $")
+
+_ENTRY(check_stack_alignment)
+       movl    %esp, %eax
+       andl    $3, %eax
+       jz 1f
+       xorl    %eax, %eax
+       ret
+1:
+       incl    %eax
+       ret
diff -r ea3b9c8998bb -r 98592a1800b8 tests/lib/csu/h_initfini_common.cxx
--- a/tests/lib/csu/h_initfini_common.cxx       Tue Nov 30 18:37:59 2010 +0000
+++ b/tests/lib/csu/h_initfini_common.cxx       Tue Nov 30 18:38:53 2010 +0000
@@ -1,16 +1,36 @@
 #include <unistd.h>
 
+#ifdef CHECK_STACK_ALIGNMENT
+#include <stdlib.h>
+
+extern "C" int check_stack_alignment(void);
+#endif
+
 class Test {
 public:
        Test()
        {
                static const char msg[] = "constructor executed\n";
                write(STDOUT_FILENO, msg, sizeof(msg) - 1);
+#ifdef CHECK_STACK_ALIGNMENT
+               if (!check_stack_alignment()) {
+                       static const char msg2[] = "stack unaligned \n";
+                       write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
+                       exit(1);
+               }
+#endif
        }
        ~Test()
        {
                static const char msg[] = "destructor executed\n";
                write(STDOUT_FILENO, msg, sizeof(msg) - 1);
+#ifdef CHECK_STACK_ALIGNMENT
+               if (!check_stack_alignment()) {
+                       static const char msg2[] = "stack unaligned \n";
+                       write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
+                       exit(1);
+               }
+#endif
        }
 };
 
diff -r ea3b9c8998bb -r 98592a1800b8 tests/lib/libpthread/Makefile
--- a/tests/lib/libpthread/Makefile     Tue Nov 30 18:37:59 2010 +0000
+++ b/tests/lib/libpthread/Makefile     Tue Nov 30 18:38:53 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2010/07/28 21:29:15 jruoho Exp $
+# $NetBSD: Makefile,v 1.3 2010/11/30 18:38:54 joerg Exp $
 
 NOMAN=         # defined
 
@@ -7,6 +7,11 @@
 TESTSDIR=      ${TESTSBASE}/lib/libpthread
 LDADD+=                -lpthread
 
+.include "${.PARSEDIR}/../csu/Makefile.check_stack"
+
+SRCS.t_join=   t_join.c ${SRCS_CHECK_STACK}
+CPPFLAGS.t_join.c+=    ${CPPFLAGS_CHECK_STACK}
+
 TESTS_SH+=     t_atexit
 TESTS_C+=      t_barrier
 TESTS_SH+=     t_cancel
diff -r ea3b9c8998bb -r 98592a1800b8 tests/lib/libpthread/t_join.c
--- a/tests/lib/libpthread/t_join.c     Tue Nov 30 18:37:59 2010 +0000
+++ b/tests/lib/libpthread/t_join.c     Tue Nov 30 18:38:53 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_join.c,v 1.4 2010/07/29 12:56:16 hans Exp $ */
+/* $NetBSD: t_join.c,v 1.5 2010/11/30 18:38:54 joerg Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_join.c,v 1.4 2010/07/29 12:56:16 hans Exp $");
+__RCSID("$NetBSD: t_join.c,v 1.5 2010/11/30 18:38:54 joerg Exp $");
 
 #include <errno.h>
 #include <pthread.h>
@@ -38,6 +38,10 @@
 
 #include "h_common.h"
 
+#ifdef CHECK_STACK_ALIGNMENT
+extern int check_stack_alignment(void);
+#endif
+
 static bool error;
 
 static void *threadfunc1(void *);
@@ -70,6 +74,13 @@
 
        caller = pthread_self();
 
+#ifdef CHECK_STACK_ALIGNMENT
+       /*
+        * Check alignment of thread stack, if supported.
+        */
+       ATF_REQUIRE(check_stack_alignment());
+#endif
+
        /*
         * The behavior is undefined, but should error
         * out, if we try to join the calling thread.



Home | Main Index | Thread Index | Old Index