This fixes a flaw in my parallelization code that caused it to fail when
GCC_RUNTEST_PARALLELIZE_DIR wasn't set.  It worked fine with make -j1,
but failed with just make.

As there could be other tests that might need to do their own
paralellization, I'm moving the that code into it's own file under
gcc/testsuite/lib.

Signed-off-by: Daniel Santos <daniel.san...@pobox.com>
---
 .../gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp      | 48 ++++--------
 gcc/testsuite/lib/parallelize.exp                  | 88 ++++++++++++++++++++++
 2 files changed, 103 insertions(+), 33 deletions(-)
 create mode 100644 gcc/testsuite/lib/parallelize.exp

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 e317af9bd85..77c40dbf349 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
@@ -30,13 +30,11 @@ if { (![istarget x86_64-*-*] && ![istarget i?86-*-*])
     return
 }
 
-global GCC_RUNTEST_PARALLELIZE_DIR
-
 load_lib gcc-dg.exp
+load_lib parallelize.exp
 
 proc runtest_ms_sysv { cflags generator_args } {
-    global GCC_UNDER_TEST HOSTCXX HOSTCXXFLAGS tmpdir srcdir subdir \
-          parallel_dir next_test
+    global GCC_UNDER_TEST HOSTCXX HOSTCXXFLAGS tmpdir srcdir subdir
 
     set objdir "$tmpdir/ms-sysv"
     set generator "$tmpdir/ms-sysv-generate.exe"
@@ -46,22 +44,6 @@ proc runtest_ms_sysv { cflags generator_args } {
     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.
@@ -73,9 +55,17 @@ proc runtest_ms_sysv { cflags generator_args } {
     set descr "$subdir CFLAGS=\"$cflags\" generator_args=\"$generator_args\""
     verbose "$tmpdir: Running test $descr" 1
 
-    # Cleanup any previous test in objdir
-    file delete -force $objdir
-    file mkdir $objdir
+    set status [parallel-should-run-test]
+
+    if { $status == 1 } then {
+       return
+    }
+
+    if { $status == 0 } then {
+       # Cleanup any previous test in objdir
+       file delete -force $objdir
+       file mkdir $objdir
+    }
 
     # Build the generator (only needs to be done once).
     set src "$srcdir/$subdir/gen.cc"
@@ -148,16 +138,8 @@ proc runtest_ms_sysv { cflags generator_args } {
 }
 
 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
+if { [parallel-init "ms2sysv"] != 0 } then {
+    return;
 }
 
 set gen_opts "-p0-5"
diff --git a/gcc/testsuite/lib/parallelize.exp 
b/gcc/testsuite/lib/parallelize.exp
new file mode 100644
index 00000000000..346a06f0fa0
--- /dev/null
+++ b/gcc/testsuite/lib/parallelize.exp
@@ -0,0 +1,88 @@
+# Functions for parallelizing tests that cannot use the standard dg-run,
+# dg-runtest or gcc-dg-runtest for some reason.
+#
+# Copyright (C) 2017 Free Software Foundation, Inc.
+# Contributed by Daniel Santos <daniel.san...@pobox.com>
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the GCC Runtime Library Exception, version
+# 3.1, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License and
+# 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/>.
+
+set is_parallel_build 0
+set parallel_next_test 0
+set parallel_dir ""
+
+# Setup parallelization directory and variables.
+#
+# Returns 0 upon success, -1 on failure.
+proc parallel-init { uid } {
+    global is_parallel_build parallel_dir parallel_parallel_next_test env
+
+    if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR) ] } {
+       set gcc_pardir "$env(GCC_RUNTEST_PARALLELIZE_DIR)"
+       set is_parallel_build 1
+       set parallel_dir "${gcc_pardir}/${uid}"
+       if [catch {file mkdir "$gcc_pardir"}] {
+           if { [lindex $::errorCode 1] ne "EEXIST" } {
+             error "Failed to create directory $gcc_pardir: $::errorCode"
+             return -1
+           }
+       }
+       if [catch {file mkdir "$parallel_dir"}] {
+           if { [lindex $::errorCode 1] ne "EEXIST" } {
+               error "Failed to create directory $parallel_dir: $::errorCode"
+               return -1
+           }
+       }
+    }
+    return 0
+}
+
+# Test if a test should be run on by this job or not.
+#
+# Returns:
+#      0 if the test should be run by this job
+#      1 if it should not,
+#      -1 upon error.
+proc parallel-should-run-test {} {
+    global is_parallel_build parallel_dir parallel_next_test
+
+    # Not a parallel build
+    if { $is_parallel_build != 1 } {
+       return 0
+    }
+
+    set this_test $parallel_next_test
+    incr parallel_next_test
+
+    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 1
+       } else {
+           error "Failed to open $parallel_dir/$this_test: $::errorCode"
+           return -1
+       }
+    } else {
+       close $fd
+       return 0
+    }
+}
-- 
2.11.0

Reply via email to