[PATCH 1/2] [testsuite] PR80759 fix tests on Solaris and Darwin

Daniel Santos daniel.santos@pobox.com
Sun Jul 2 05:10:00 GMT 2017


The ms-sysv.exp tests were failing on Solaris and Darwin targets.  In
addition, a number of other problems have been identified.

* Assembly failed on Solaris and Darwin when not using gas due to use of
  .cfi directives and .struct.

* Tests were failing on Solaris due to hard frame pointer being always
  enabled on that platform and and not passing --omit-rbp-clobbers to
  the code generator.

* Manual compilation (via remote_exec as opposed to dg-runtest, et. al.)
  was missing TEST_ALWAYS_FLAGS, resulting in color codes in log files.
  It was also missing -m64 in some cases where it was needed.

* When built with make -j48 on an unsupported triplet, the "test
  unsupported" message appeared 48 times in the log (it appears that
  several other tests do this as well).

* Using hard-coded offsets in do-tests.S is ugly.  This is fixed by
  moving some code into inline assembly in ms-sysv.c.

* Custom parallelization code broke when running make without -j<n>

* Accessing the test_data global from assembly requires(?) use of global
  offset table on Darwin.

This patch corrects all of these problems.  The custom parallelization
code has been removed and replaced with calls to procs in gcc's standard
testing framework: gcc_parallel_test_enable, runtest_file_p and
dg-runtest.  This results in much poorer parallelization, which I hope
to address in a future patch, but has little effect when built without
checking enabled.

Previously, each test job compiled and executed around 20k individual
tests.  This high number resulted in test jobs far exceeding the default
5 minute timeout for remote_/local_exec when gcc was built with
--enable-checking=rtl.  This has been resolved by splitting the tests
out to a maximum of around 3500 tests per job.

Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
---
 .../gcc.target/x86_64/abi/ms-sysv/do-test.S        | 200 +++++++++------------
 .../gcc.target/x86_64/abi/ms-sysv/ms-sysv.c        |  83 ++++++++-
 .../gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp      | 153 +++++-----------
 3 files changed, 210 insertions(+), 226 deletions(-)

diff --git a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S
index 1395235fd1e..ffe011bcc68 100644
--- a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S
+++ b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S
@@ -23,141 +23,101 @@ a copy of the GCC Runtime Library Exception along with this program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
-#ifdef __x86_64__
-
-# ifdef __ELF__
-#  define ELFFN_BEGIN(fn)       .type fn,@function
-#  define ELFFN_END(fn)         .size fn,.-fn
-# else
-#  define ELFFN_BEGIN(fn)
-#  define ELFFN_END(fn)
-# endif
-
-# define FUNC(fn)		\
-	.global fn;		\
-	ELFFN_BEGIN(fn);	\
-fn:
-
-#define FUNC_END(fn) ELFFN_END(fn)
-
-# ifdef __AVX__
-#  define MOVAPS vmovaps
-# else
-#  define MOVAPS movaps
-# endif
-
-/* TODO: Is there a cleaner way to provide these offsets?  */
-	.struct 0
-test_data_save:
-
-	.struct test_data_save + 224
-test_data_input:
-
-	.struct test_data_save + 448
-test_data_output:
-
-	.struct test_data_save + 672
-test_data_fn:
-
-	.struct test_data_save + 680
-test_data_retaddr:
+#if defined(__x86_64__) && defined(__SSE2__)
+
+/* These macros currently support GNU/Linux, Solaris and Darwin.  */
+
+#ifdef __ELF__
+# define FN_TYPE(fn) .type fn,@function
+# define FN_SIZE(fn) .size fn,.-fn
+#else
+# define FN_TYPE(fn)
+# define FN_SIZE(fn)
+#endif
+
+#ifdef __USER_LABEL_PREFIX__
+# define ASMNAME2(prefix, name)	prefix ## name
+# define ASMNAME1(prefix, name)	ASMNAME2(prefix, name)
+# define ASMNAME(name)		ASMNAME1(__USER_LABEL_PREFIX__, name)
+#else
+# define ASMNAME(name)		name
+#endif
+
+#define FUNC_BEGIN(fn)		\
+	.globl ASMNAME(fn);	\
+	FN_TYPE (ASMNAME(fn));	\
+ASMNAME(fn):
+
+#define FUNC_END(fn) FN_SIZE(ASMNAME(fn))
+
+#ifdef __AVX__
+# define MOVAPS vmovaps
+#else
+# define MOVAPS movaps
+#endif
 
 	.text
 
-regs_to_mem:
-	MOVAPS	%xmm6, (%rax)
-	MOVAPS	%xmm7, 0x10(%rax)
-	MOVAPS	%xmm8, 0x20(%rax)
-	MOVAPS	%xmm9, 0x30(%rax)
-	MOVAPS	%xmm10, 0x40(%rax)
-	MOVAPS	%xmm11, 0x50(%rax)
-	MOVAPS	%xmm12, 0x60(%rax)
-	MOVAPS	%xmm13, 0x70(%rax)
-	MOVAPS	%xmm14, 0x80(%rax)
-	MOVAPS	%xmm15, 0x90(%rax)
-	mov	%rsi, 0xa0(%rax)
-	mov	%rdi, 0xa8(%rax)
-	mov	%rbx, 0xb0(%rax)
-	mov	%rbp, 0xb8(%rax)
-	mov	%r12, 0xc0(%rax)
-	mov	%r13, 0xc8(%rax)
-	mov	%r14, 0xd0(%rax)
-	mov	%r15, 0xd8(%rax)
+FUNC_BEGIN(regs_to_mem)
+	MOVAPS	%xmm6, (%r10)
+	MOVAPS	%xmm7, 0x10(%r10)
+	MOVAPS	%xmm8, 0x20(%r10)
+	MOVAPS	%xmm9, 0x30(%r10)
+	MOVAPS	%xmm10, 0x40(%r10)
+	MOVAPS	%xmm11, 0x50(%r10)
+	MOVAPS	%xmm12, 0x60(%r10)
+	MOVAPS	%xmm13, 0x70(%r10)
+	MOVAPS	%xmm14, 0x80(%r10)
+	MOVAPS	%xmm15, 0x90(%r10)
+	mov	%rsi, 0xa0(%r10)
+	mov	%rdi, 0xa8(%r10)
+	mov	%rbx, 0xb0(%r10)
+	mov	%rbp, 0xb8(%r10)
+	mov	%r12, 0xc0(%r10)
+	mov	%r13, 0xc8(%r10)
+	mov	%r14, 0xd0(%r10)
+	mov	%r15, 0xd8(%r10)
 	retq
-
-mem_to_regs:
-	MOVAPS	(%rax), %xmm6
-	MOVAPS	0x10(%rax),%xmm7
-	MOVAPS	0x20(%rax),%xmm8
-	MOVAPS	0x30(%rax),%xmm9
-	MOVAPS	0x40(%rax),%xmm10
-	MOVAPS	0x50(%rax),%xmm11
-	MOVAPS	0x60(%rax),%xmm12
-	MOVAPS	0x70(%rax),%xmm13
-	MOVAPS	0x80(%rax),%xmm14
-	MOVAPS	0x90(%rax),%xmm15
-	mov	0xa0(%rax),%rsi
-	mov	0xa8(%rax),%rdi
-	mov	0xb0(%rax),%rbx
-	mov	0xb8(%rax),%rbp
-	mov	0xc0(%rax),%r12
-	mov	0xc8(%rax),%r13
-	mov	0xd0(%rax),%r14
-	mov	0xd8(%rax),%r15
+FUNC_END(regs_to_mem)
+
+FUNC_BEGIN(mem_to_regs)
+	MOVAPS	(%r10), %xmm6
+	MOVAPS	0x10(%r10),%xmm7
+	MOVAPS	0x20(%r10),%xmm8
+	MOVAPS	0x30(%r10),%xmm9
+	MOVAPS	0x40(%r10),%xmm10
+	MOVAPS	0x50(%r10),%xmm11
+	MOVAPS	0x60(%r10),%xmm12
+	MOVAPS	0x70(%r10),%xmm13
+	MOVAPS	0x80(%r10),%xmm14
+	MOVAPS	0x90(%r10),%xmm15
+	mov	0xa0(%r10),%rsi
+	mov	0xa8(%r10),%rdi
+	mov	0xb0(%r10),%rbx
+	mov	0xb8(%r10),%rbp
+	mov	0xc0(%r10),%r12
+	mov	0xc8(%r10),%r13
+	mov	0xd0(%r10),%r14
+	mov	0xd8(%r10),%r15
 	retq
+FUNC_END(mem_to_regs)
 
 # NOTE: Not MT safe
-FUNC(do_test_unaligned)
-	.cfi_startproc
+FUNC_BEGIN(do_test_unaligned)
 	# The below alignment checks are to verify correctness of the test
 	# its self.
 
 	# Verify that incoming stack is aligned + 8
-	pushf
-	test	$0x8, %rsp
-	jne	L0
+	test	$0xf, %rsp
+	je	ASMNAME(do_test_body)
 	int	$3		# Stack not unaligned
+FUNC_END(do_test_unaligned)
 
-FUNC(do_test_aligned)
+FUNC_BEGIN(do_test_aligned)
 	# Verify that incoming stack is aligned
-	pushf
-	test	$0xf, %rsp
-	je	L0
+	test	$0x8, %rsp
+	jne	ASMNAME(do_test_body)
 	int	$3		# Stack not aligned
-L0:
-	popf
-
-	# Save registers
-	lea	test_data(%rip), %rax
-	call	regs_to_mem
-
-	# Load register with random data
-	lea	test_data + test_data_input(%rip), %rax
-	call	mem_to_regs
-
-	# Save original return address
-	pop	%rax
-	movq    %rax, test_data + test_data_retaddr(%rip)
-
-	# Call the test function
-	call	*test_data + test_data_fn(%rip)
-
-	# Restore the original return address
-	movq    test_data + test_data_retaddr(%rip), %rcx
-	push	%rcx
-
-	# Save test function return value and store resulting register values
-	push	%rax
-	lea	test_data + test_data_output(%rip), %rax
-	call	regs_to_mem
-
-	# Restore registers
-	lea	test_data(%rip), %rax
-	call	mem_to_regs
-	pop	%rax
-	retq
-        .cfi_endproc
 FUNC_END(do_test_aligned)
-FUNC_END(do_test_unaligned)
 
 #endif /* __x86_64__ */
diff --git a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.c b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.c
index 2a011f5103d..caf9e6b5deb 100644
--- a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.c
+++ b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.c
@@ -46,6 +46,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
   is then called.  After the function returns, the value of all volatile
   registers is verified against the random data and then restored.  */
 
+/* { dg-do run } */
+/* { dg-additional-sources "do-test.S" } */
+/* { dg-additional-options "-Wall" } */
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -58,8 +62,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include <errno.h>
 #include <ctype.h>
 
-#ifndef __x86_64__
-# error Test only valid on x86_64
+#if !defined(__x86_64__) || !defined(__SSE2__)
+# error Test only valid on x86_64 with -msse2
 #endif
 
 enum reg_data_sets
@@ -144,6 +148,81 @@ static __attribute__((ms_abi)) long
 static int arbitrarily_fail;
 static const char *argv0;
 
+
+#define PASTE_STR2(a)		#a
+#define PASTE_STR1(a, b)	PASTE_STR2(a ## b)
+#define PASTE_STR(a, b)		PASTE_STR1(a, b)
+
+#ifdef __USER_LABEL_PREFIX__
+# define ASMNAME(name)		PASTE_STR(__USER_LABEL_PREFIX__, name)
+#else
+# define ASMNAME(name)		#name
+#endif
+
+#ifdef __MACH__
+# define LOAD_TEST_DATA_ADDR(dest) \
+	"	mov	" ASMNAME(test_data) "@GOTPCREL(%%rip), " dest "\n"
+#else
+# define LOAD_TEST_DATA_ADDR(dest) \
+	"	lea	" ASMNAME(test_data) "(%%rip), " dest "\n"
+#endif
+
+#define TEST_DATA_OFFSET(f)	((int)__builtin_offsetof(struct test_data, f))
+
+void __attribute__((used))
+do_test_body0 (void)
+{
+  __asm__ ("\n"
+	"	.globl " ASMNAME(do_test_body) "\n"
+#ifdef __ELF__
+	"	.type " ASMNAME(do_test_body) ",@function\n"
+#endif
+	ASMNAME(do_test_body) ":\n"
+	"	# rax, r10 and r11 are usable here.\n"
+	"\n"
+	"	# Save registers.\n"
+		LOAD_TEST_DATA_ADDR("%%rax")
+	"	lea	%p0(%%rax), %%r10\n"
+	"	call	" ASMNAME(regs_to_mem) "\n"
+	"\n"
+	"	# Load registers with random data.\n"
+	"	lea	%p1(%%rax), %%r10\n"
+	"	call	" ASMNAME(mem_to_regs) "\n"
+	"\n"
+	"	# Pop and save original return address.\n"
+	"	pop	%%r10\n"
+	"	mov	%%r10, %p4(%%rax)\n"
+	"\n"
+	"	# Call the test function, after which rcx, rdx and r8-11\n"
+	"	# become usable.\n"
+	"	lea	%p3(%%rax), %%rax\n"
+	"	call	*(%%rax)\n"
+	"\n"
+	"	# Store resulting register values.\n"
+		LOAD_TEST_DATA_ADDR("%%rcx")
+	"	lea	%p2(%%rcx), %%r10\n"
+	"	call	" ASMNAME(regs_to_mem) "\n"
+	"\n"
+	"	# Push the original return address.\n"
+	"	lea	%p4(%%rcx), %%r10\n"
+	"	push	(%%r10)\n"
+	"\n"
+	"	# Restore registers.\n"
+	"	lea	%p0(%%rcx), %%r10\n"
+	"	call	" ASMNAME(mem_to_regs) "\n"
+	"\n"
+	"	retq\n"
+#ifdef __ELF__
+	"	.size " ASMNAME(do_test_body) ",.-" ASMNAME(do_test_body) "\n"
+#endif
+	::
+	"i"(TEST_DATA_OFFSET(regdata[REG_SET_SAVE])),
+	"i"(TEST_DATA_OFFSET(regdata[REG_SET_INPUT])),
+	"i"(TEST_DATA_OFFSET(regdata[REG_SET_OUTPUT])),
+	"i"(TEST_DATA_OFFSET(fn)),
+	"i"(TEST_DATA_OFFSET(retaddr)) : "memory");
+}
+
 static void __attribute__((noinline))
 init_test (void *fn, const char *name, enum alignment_option alignment,
 	   enum shrink_wrap_option shrink_wrap, long ret_expected)
diff --git a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp
index 26777e0b59f..87f81690bc7 100644
--- a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp
+++ b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp
@@ -56,52 +56,48 @@ proc host_supports_c++11 {} {
 
 # Exit immediately if this isn't a native x86_64 target.
 if { (![istarget x86_64-*-*] && ![istarget i?86-*-*])
-     || ![is-effective-target lp64] || ![isnative]
-     || ![host_supports_c++11] } then {
-    unsupported "$subdir"
+      || ![is-effective-target lp64] || ![isnative]
+      || ![host_supports_c++11] } then {
+
+    # Gate "unsupported" message return value of first runtest_file_p call.
+    if [runtest_file_p $runtests "$srcdir/$subdir/ms-sysv.c"] {
+	unsupported "$subdir"
+    }
     return
 }
 
-global GCC_RUNTEST_PARALLELIZE_DIR
-
 proc runtest_ms_sysv { cflags generator_args } {
     global GCC_UNDER_TEST HOSTCXX HOSTCXXFLAGS tmpdir srcdir subdir \
-	   parallel_dir next_test
+	   TEST_ALWAYS_FLAGS runtests
 
     set objdir "$tmpdir/ms-sysv"
     set generator "$tmpdir/ms-sysv-generate.exe"
     set generated_header "$objdir/ms-sysv-generated.h"
-    set do_test_o "$objdir/do-test.o"
-    set ms_sysv_o "$objdir/ms-sysv.o"
-    set ms_sysv_exe "$objdir/ms-sysv.exe"
     set status 0
     set warn_flags "-Wall"
-    set this_test $next_test
-    incr next_test
-
-    # Do parallelization here
-    if [catch {set fd [open "$parallel_dir/$this_test" \
-			    [list RDWR CREAT EXCL]]} ] {
-	if { [lindex $::errorCode 1] eq "EEXIST" } then {
-	    # Another job is running this test
-	    return
-	} else {
-	    error "Failed to open $parallel_dir/$this_test: $::errorCode"
-	    set status 1
-	}
-    } else {
-      close $fd
-    }
 
     # Detect when hard frame pointers are enabled (or required) so we know not
     # to generate bp clobbers.
-    if [regexp "^(.+ +| *)-(O0|fno-omit-frame-pointer|p|pg)( +.*)?$" \
-	       $cflags match] then {
+    if { [regexp "(^| )-(O0|fno-omit-frame-pointer|p|pg)( |$)" \
+		 "$TEST_ALWAYS_FLAGS $cflags" match]
+	 || [istarget *-*-solaris*] } then {
 	set generator_args "$generator_args --omit-rbp-clobbers"
     }
 
-    set descr "$subdir CFLAGS=\"$cflags\" generator_args=\"$generator_args\""
-    verbose "$tmpdir: Running test $descr" 1
+    # Add all other flags
+    set escaped_generator_args [regsub -all " " $generator_args "\\ "]
+    set cflags "$cflags\"-DGEN_ARGS=$escaped_generator_args\""
+
+    gcc_parallel_test_enable 1
+    if ![runtest_file_p $runtests "$srcdir/$subdir/ms-sysv.c"] then {
+	return
+    }
+
+    #verbose "runtest_ms_sysv $cflags" 0
+
+    # Make sure there's no previous header file so that we can't accidentally
+    # pass if generation fails.
+    file delete -force $generated_header
 
     # Cleanup any previous test in objdir
     file delete -force $objdir
@@ -109,18 +105,16 @@ proc runtest_ms_sysv { cflags generator_args } {
 
     # Build the generator (only needs to be done once).
     set src "$srcdir/$subdir/gen.cc"
-    if { $status == 0 } then {
-	if { (![file exists "$generator"]) || ([file mtime "$generator"]
-					    < [file mtime "$src"]) } {
-	    # Temporarily switch to the environment for the host compiler.
-	    restore_ld_library_path_env_vars
-	    set cxx "$HOSTCXX $HOSTCXXFLAGS $warn_flags -std=c++11"
-	    set status [remote_exec host "$cxx -o $generator $src"]
-	    set status [lindex $status 0]
-	    set_ld_library_path_env_vars
-	    if { $status != 0 } then {
-		warning "Could not build $subdir generator"
-	    }
+    if { (![file exists "$generator"]) || ([file mtime "$generator"]
+					   < [file mtime "$src"]) } {
+	# Temporarily switch to the environment for the host compiler.
+	restore_ld_library_path_env_vars
+	set cxx "$HOSTCXX $HOSTCXXFLAGS $TEST_ALWAYS_FLAGS $warn_flags -std=c++11"
+	set status [remote_exec host "$cxx -o $generator $src"]
+	set status [lindex $status 0]
+	set_ld_library_path_env_vars
+	if { $status != 0 } then {
+	    warning "Could not build $subdir generator"
 	}
     }
 
@@ -133,75 +127,26 @@ proc runtest_ms_sysv { cflags generator_args } {
 	}
     }
 
-    set cc "$GCC_UNDER_TEST -I$objdir -I$srcdir/$subdir $cflags $warn_flags"
-
-    # Assemble do-test.S
-    set src "$srcdir/$subdir/do-test.S"
-    if { $status == 0 } then {
-	set status [remote_exec build "$cc -c -o $do_test_o $src"]
-	set status [lindex $status 0]
-	if { $status != 0 } then {
-	    warning "Could not assemble $src"
-	}
-    }
-
-    # Build ms-sysv.c
-    set src "$srcdir/$subdir/ms-sysv.c"
-    if { $status == 0 } then {
-	set status [remote_exec build "$cc -c -o $ms_sysv_o $src" "" "" "" 1200]
-	set status [lindex $status 0]
-	if { $status != 0 } then {
-	    warning "Could not build $src."
-	}
-    }
-
-    # Link
-    if { $status == 0 } then {
-	set status [remote_exec build "$cc -o $ms_sysv_exe $ms_sysv_o $do_test_o"]
-	set status [lindex $status 0]
-	if { $status != 0 } then {
-	    warning "Link failed."
-	}
-    }
-
-    # Execute
-    if { $status == 0 } then {
-	set status [remote_exec build "$ms_sysv_exe"]
-	set status [lindex $status 0]
-    }
-
-    if { $status != 0 } then {
-	fail $descr
-    } else {
-	pass $descr
-    }
+    gcc_parallel_test_enable 0
+    dg-runtest $srcdir/$subdir/ms-sysv.c "$cflags" "-I$objdir -I$srcdir/$subdir $warn_flags"
+    gcc_parallel_test_enable 1
 }
 
 dg-init
 
-# Setup parallelization
-set next_test 0
-set parallel_dir "$env(GCC_RUNTEST_PARALLELIZE_DIR)/abi-ms-sysv"
-file mkdir "$env(GCC_RUNTEST_PARALLELIZE_DIR)"
-file mkdir "$parallel_dir"
-
-if { ![file isdirectory "$parallel_dir"] } then {
-    error "Failed to create directory $parallel_dir: $::errorCode"
-    return
-}
+# Standard test parameters.
+set gen_pcount_opts [list "-p0" "-p1" "-p5"]
+set base_cflags_arr [list " -O2 " " -O0 -g3 "]
 
-set gen_opts "-p0-5"
-set all_options [list "-O2" "-O0 -g3"]
+foreach gen_opts $gen_pcount_opts {
+    foreach cflags $base_cflags_arr {
+	# Run without -mcall-ms2sysv-xlogues always
+	runtest_ms_sysv "$cflags" "$gen_opts"
 
-# Run without -mcall-ms2sysv-xlogues always
-foreach opt $all_options {
-    runtest_ms_sysv "$opt" "$gen_opts"
-}
-
-# Skip -mcall-ms2sysv-xlogues on Windows (not supported)
-if { ![istarget *-*-cygwin*] && ![istarget *-*-mingw*] } {
-    foreach opt $all_options {
-	runtest_ms_sysv "-mcall-ms2sysv-xlogues $opt" "$gen_opts"
+	# Skip unsupported -mcall-ms2sysv-xlogues on Windows
+	if { ![istarget *-*-cygwin*] && ![istarget *-*-mingw*] } {
+	    runtest_ms_sysv "-mcall-ms2sysv-xlogues$cflags" "$gen_opts"
+	}
     }
 }
 
-- 
2.11.0



More information about the Gcc-patches mailing list