On Fri, Nov 07, 2014 at 08:24:15AM -0800, Ian Taylor wrote:
> On Fri, Nov 7, 2014 at 12:51 AM, Dominik Vogt <v...@linux.vnet.ibm.com> wrote:
> > On Thu, Nov 06, 2014 at 09:06:18AM -0800, Ian Taylor wrote:
> >> On Thu, Nov 6, 2014 at 4:04 AM, Dominik Vogt <v...@linux.vnet.ibm.com> 
> >> wrote:
> >> > On Tue, Nov 04, 2014 at 08:16:51PM -0800, Ian Taylor wrote:
> >> >> The way to do it is not by
> >> >> copying the test.  If the test needs to be customized, add additional
> >> >> files that use // +build lines to pick which files is built.  Move
> >> >> them into a directory, like method4.go or other tests that use
> >> >> "rundir".
> >> >
> >> > Currently go-test.exp does not look at the "build" lines of the
> >> > files in subdirectories.  Before I add that to the gcc testsuite
> >> > start adding that, is it certain that the golang testsuite will be
> >> > able to understand that and compile only the requested files?
> >>
> >> Hmmm, that is a good point.  The testsuite doesn't use the go command
> >> to build the files in subdirectories, so it won't honor the +build
> >> lines.  I didn't think of that.  Sorry for pointing you in the wrong
> >> direction.
> >
> > That's no problem, I can enhance go-test.exp in Gcc.  The question
> > is if test cases extended in such a way would run in the master Go
> > repository too.  Are the tests there run with the Go tool?

What do you think about the attached patches?  They work for me, but I'm
not sure whether the patch to go-test.exp is good because I know
nothing about tcl.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany
>From 155982afbcaf36fc79a89d222f0ff1b9da17464a Mon Sep 17 00:00:00 2001
From: Dominik Vogt <v...@linux.vnet.ibm.com>
Date: Mon, 10 Nov 2014 13:21:42 +0100
Subject: [PATCH 1/6] go.test: Fix "// +build" lines that have only negative
 specifiers

Lines like this did not cause the file to be built on other platforms:

-- snip --
// +build !s390 !s390x
-- snip --
---
 gcc/testsuite/go.test/go-test.exp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/testsuite/go.test/go-test.exp b/gcc/testsuite/go.test/go-test.exp
index 25e405b..590aaf9 100644
--- a/gcc/testsuite/go.test/go-test.exp
+++ b/gcc/testsuite/go.test/go-test.exp
@@ -469,6 +469,9 @@ proc go-gc-tests { } {
 		    set matches_pos 1
 		} elseif { [ regexp -line "\[ 	\]windows\(\[ 	\]\|\$\)" $test_line ] } {
 		    set matches_neg 1
+		} elseif { [ regexp -line "// \\+build(\[ 	\]+!\[^ 	!\]+)*\[ 	\]*\$" $test_line ] } {
+		    # line has only negative terms, default to positive match
+		    set matches_pos 1
 		}
 		if { $matches_pos == 1 && $matches_neg == 0 } {
 		    continue
-- 
1.8.4.2

gcc/testsuite/ChangeLog
2014-11-10  Dominik Vogt  <v...@linux.vnet.ibm.com>

        * go.test/go-test.exp: Fix "// +build" lines that have only negative
        specifiers (prefixed with '!')
>From 35d0e1052dce2eabed57f3c8c76bfbb62cf48676 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <v...@linux.vnet.ibm.com>
Date: Tue, 4 Nov 2014 10:13:22 +0100
Subject: [PATCH 3/6] go.test: Do not run test nilptr.go on s390 -> platform
 specific test.

* Detects word boundaries to distinguish between s390 and s390x.
  (Switch to using regular expressions.)
* Implement the Prefix '!' to exclude targets from build.
---
 gcc/testsuite/go.test/test/nilptr.go             | 35 ++++++++----------------
 gcc/testsuite/go.test/test/nilptr_other.go       | 31 +++++++++++++++++++++
 gcc/testsuite/go.test/test/nilptr_s390.go        | 23 ++++++++++++++++
 gcc/testsuite/go.test/test/nilptr_s390_common.go | 23 ++++++++++++++++
 gcc/testsuite/go.test/test/nilptr_s390x.go       | 23 ++++++++++++++++
 5 files changed, 111 insertions(+), 24 deletions(-)
 create mode 100644 gcc/testsuite/go.test/test/nilptr_other.go
 create mode 100644 gcc/testsuite/go.test/test/nilptr_s390.go
 create mode 100644 gcc/testsuite/go.test/test/nilptr_s390_common.go
 create mode 100644 gcc/testsuite/go.test/test/nilptr_s390x.go

diff --git a/gcc/testsuite/go.test/test/nilptr.go b/gcc/testsuite/go.test/test/nilptr.go
index 9631d16..9bc8045 100644
--- a/gcc/testsuite/go.test/test/nilptr.go
+++ b/gcc/testsuite/go.test/test/nilptr.go
@@ -1,4 +1,4 @@
-// run
+// skip
 
 // Copyright 2011 The Go Authors.  All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -11,22 +11,8 @@ package main
 
 import "unsafe"
 
-// Having a big address space means that indexing
-// at a 256 MB offset from a nil pointer might not
-// cause a memory access fault. This test checks
-// that Go is doing the correct explicit checks to catch
-// these nil pointer accesses, not just relying on the hardware.
-var dummy [256 << 20]byte // give us a big address space
-
 func main() {
-	// the test only tests what we intend to test
-	// if dummy starts in the first 256 MB of memory.
-	// otherwise there might not be anything mapped
-	// at the address that might be accidentally
-	// dereferenced below.
-	if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
-		panic("dummy too far out")
-	}
+	sanityCheck()
 
 	shouldPanic(p1)
 	shouldPanic(p2)
@@ -57,14 +43,15 @@ func shouldPanic(f func()) {
 
 func p1() {
 	// Array index.
-	var p *[1 << 30]byte = nil
-	println(p[256<<20]) // very likely to be inside dummy, but should panic
+	var p *[maxlen]byte = nil
+	// very likely to be inside dummy, but should panic
+	println(p[inMaxlenArray])
 }
 
 var xb byte
 
 func p2() {
-	var p *[1 << 30]byte = nil
+	var p *[maxlen]byte = nil
 	xb = 123
 
 	// Array index.
@@ -73,12 +60,12 @@ func p2() {
 
 func p3() {
 	// Array to slice.
-	var p *[1 << 30]byte = nil
+	var p *[maxlen]byte = nil
 	var x []byte = p[0:] // should panic
 	_ = x
 }
 
-var q *[1 << 30]byte
+var q *[maxlen]byte
 
 func p4() {
 	// Array to slice.
@@ -93,18 +80,18 @@ func fb([]byte) {
 
 func p5() {
 	// Array to slice.
-	var p *[1 << 30]byte = nil
+	var p *[maxlen]byte = nil
 	fb(p[0:]) // should crash
 }
 
 func p6() {
 	// Array to slice.
-	var p *[1 << 30]byte = nil
+	var p *[maxlen]byte = nil
 	var _ []byte = p[10 : len(p)-10] // should crash
 }
 
 type T struct {
-	x [256 << 20]byte
+	x [inMemSize]byte
 	i int
 }
 
diff --git a/gcc/testsuite/go.test/test/nilptr_other.go b/gcc/testsuite/go.test/test/nilptr_other.go
new file mode 100644
index 0000000..7747f70
--- /dev/null
+++ b/gcc/testsuite/go.test/test/nilptr_other.go
@@ -0,0 +1,31 @@
+// +build !s390 !s390x
+// run nilptr.go
+
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Platform specific test configuration
+
+package main
+
+// Having a big address space means that indexing
+// at a 256 MB offset from a nil pointer might not
+// cause a memory access fault. This test checks
+// that Go is doing the correct explicit checks to catch
+// these nil pointer accesses, not just relying on the hardware.
+const inMemSize uintptr = 256 << 20 // 256 MiB
+const maxlen uintptr = (1 << 30) - 2 // 0x40000000
+const inMaxlenArray uintptr = 256 << 20
+var dummy [256 << 20]byte // give us a big address space
+
+func sanityCheck() {
+	// the test only tests what we intend to test
+	// if dummy starts in the first 256 MB of memory.
+	// otherwise there might not be anything mapped
+	// at the address that might be accidentally
+	// dereferenced below.
+	if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
+		panic("dummy too far out")
+	}
+}
diff --git a/gcc/testsuite/go.test/test/nilptr_s390.go b/gcc/testsuite/go.test/test/nilptr_s390.go
new file mode 100644
index 0000000..8a810ad
--- /dev/null
+++ b/gcc/testsuite/go.test/test/nilptr_s390.go
@@ -0,0 +1,23 @@
+// +build s390
+// run nilptr.go nilptr_s390_common.go
+
+// Copyright 2014 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Platform specific test configuration
+
+package main
+
+// Having a big address space means that indexing at a large
+// offset from a nil pointer might not cause a memory access
+// fault.  This test checks that Go is doing the correct explicit
+// checks to catch these nil pointer accesses, not just relying on
+// the hardware.
+//
+// Give us a big address space somewhere near minBssOffset.
+const inMemSize uintptr = 256 << 20 // 256 MiB
+const minBssOffset uintptr = 1 << 22 // 0x00400000
+const maxlen uintptr = (1 << 31) - 2 // 0x7ffffffe
+const inMaxlenArray uintptr = minBssOffset + inMemSize / 2
+var dummy [inMemSize]byte
diff --git a/gcc/testsuite/go.test/test/nilptr_s390_common.go b/gcc/testsuite/go.test/test/nilptr_s390_common.go
new file mode 100644
index 0000000..be76beb
--- /dev/null
+++ b/gcc/testsuite/go.test/test/nilptr_s390_common.go
@@ -0,0 +1,23 @@
+// skip
+
+// Copyright 2014 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Shared s390 and s390x specific test configuration
+
+package main
+
+import "unsafe"
+
+func sanityCheck() {
+	// The test only tests what we intend to test if dummy
+	// starts near minBssOffset uintptr.  Otherwise there
+	// might not be anything mapped at the address that might
+	// be accidentally dereferenced below.
+	if uintptr(unsafe.Pointer(&dummy)) > inMemSize + minBssOffset {
+		panic("dummy too far out")
+	} else if uintptr(unsafe.Pointer(&dummy)) < minBssOffset {
+		panic("dummy too close")
+	}
+}
diff --git a/gcc/testsuite/go.test/test/nilptr_s390x.go b/gcc/testsuite/go.test/test/nilptr_s390x.go
new file mode 100644
index 0000000..85521b5
--- /dev/null
+++ b/gcc/testsuite/go.test/test/nilptr_s390x.go
@@ -0,0 +1,23 @@
+// +build s390x
+// run nilptr.go nilptr_s390_common.go
+
+// Copyright 2014 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Platform specific test configuration
+
+package main
+
+// Having a big address space means that indexing at a large
+// offset from a nil pointer might not cause a memory access
+// fault.  This test checks that Go is doing the correct explicit
+// checks to catch these nil pointer accesses, not just relying on
+// the hardware.
+//
+// Give us a big address space somewhere near minBssOffset.
+const inMemSize uintptr = 256 << 20 // 256 MiB
+const minBssOffset uintptr = 1 << 31 // 0x80000000
+const maxlen uintptr = (1 << 32) - 1 // 0xffffffff
+const inMaxlenArray uintptr = minBssOffset + inMemSize / 2
+var dummy [inMemSize]byte
-- 
1.8.4.2

gcc/testsuite/ChangeLog
2014-11-10  Dominik Vogt  <v...@linux.vnet.ibm.com>

        * go.test/test/nilptr_s390.go: New file
        * go.test/test/nilptr_s390x.go: New file
        * go.test/test/nilptr_s390_common.go: New file
        * go.test/test/nilptr_other.go: New file
        * go.test/test/nilptr.go: Platform specific test structure
>From 728cb48a3c214d387b0b567fd6ef30c80eb0fd73 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <v...@linux.vnet.ibm.com>
Date: Thu, 13 Nov 2014 11:45:44 +0100
Subject: [PATCH 5/6] go.test: Add special handling of nilptr.go to
 go-test.exp.

---
 gcc/testsuite/go.test/go-test.exp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/gcc/testsuite/go.test/go-test.exp b/gcc/testsuite/go.test/go-test.exp
index 590aaf9..c6dbcc5 100644
--- a/gcc/testsuite/go.test/go-test.exp
+++ b/gcc/testsuite/go.test/go-test.exp
@@ -1039,6 +1039,17 @@ proc go-gc-tests { } {
 		fail $name
 	    }
 	    file delete $output_file
+	} elseif { [string match "// run nilptr.go*" $test_line] } {
+	    regsub "/\[^/\]*$" $test "" path
+	    regsub -all " " $test_line " $path/" files
+	    regsub "^// .*run " $files "" files
+	    set hold_runtests $runtests
+	    set runtests "go-test.exp"
+	    set dg-do-what-default "run"
+	    set go_compile_args ""
+	    append go_compile_args $files
+	    go-torture-execute "$test"
+	    set runtests $hold_runtests
 	} elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&" \
 		       && $test_line2 == "// ./\$A.out -pass 0 >tmp.go && \$G tmp.go && \$L -o \$A.out1 tmp.\$A && ./\$A.out1 &&" \
 		       && $test_line3 == "// ./\$A.out -pass 1 >tmp.go && errchk \$G -e tmp.go &&" \
-- 
1.8.4.2

gcc/testsuite/ChangeLog
2014-11-13  Dominik Vogt  <v...@linux.vnet.ibm.com>

        * go.test/go-test.exp (go-gc-tests): Add special handling of nilptr.go
        to go-test.exp.

Reply via email to