aboutsummaryrefslogtreecommitdiff
path: root/misc/cgo/errors/testdata
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2019-05-16 10:00:10 -0400
committerRuss Cox <rsc@golang.org>2019-05-21 18:15:05 +0000
commit798e0b38ed8b23da010b1a8cd6c91f201248e40d (patch)
treee8b67e99c0997e11c6354d1964e6038bffafe216 /misc/cgo/errors/testdata
parentb8648184941815d1466b09071e2907323b9283c6 (diff)
downloadgo-798e0b38ed8b23da010b1a8cd6c91f201248e40d.tar.xz
misc/cgo/errors: consolidate test work
Build a single binary containing all the TestPointerChecks instead of building many small binaries, each with its own cgo+compile+link invocation. This cuts 'go test -run=TestPointerChecks' from 6.7r 35.5u 26.1s to 2.1r 2.1u 1.4s. Move as many cgo checks as possible into fewer test files for TestReportsTypeErrors too. This cuts 'go test -run=TestReportsTypeErrors' from 2.1r 6.7u 6.7s to 1.5r 2.5u 2.5s. After this change, all.bash runs in ~4:30 on my laptop. For #26473. Change-Id: I3787448b03689a1f62dd810957ab6013bb75582f Reviewed-on: https://go-review.googlesource.com/c/go/+/177599 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'misc/cgo/errors/testdata')
-rw-r--r--misc/cgo/errors/testdata/err1.go4
-rw-r--r--misc/cgo/errors/testdata/err2.go89
-rw-r--r--misc/cgo/errors/testdata/err3.go18
-rw-r--r--misc/cgo/errors/testdata/issue13129.go14
-rw-r--r--misc/cgo/errors/testdata/issue13423.go12
-rw-r--r--misc/cgo/errors/testdata/issue13467.go15
-rw-r--r--misc/cgo/errors/testdata/issue13635.go24
-rw-r--r--misc/cgo/errors/testdata/issue13830.go26
-rw-r--r--misc/cgo/errors/testdata/issue16116.go12
-rw-r--r--misc/cgo/errors/testdata/issue16591.go17
-rw-r--r--misc/cgo/errors/testdata/issue26745.go17
-rw-r--r--misc/cgo/errors/testdata/issue7757.go14
-rw-r--r--misc/cgo/errors/testdata/issue8442.go17
13 files changed, 93 insertions, 186 deletions
diff --git a/misc/cgo/errors/testdata/err1.go b/misc/cgo/errors/testdata/err1.go
index 2c232cf58a..ced7443599 100644
--- a/misc/cgo/errors/testdata/err1.go
+++ b/misc/cgo/errors/testdata/err1.go
@@ -10,6 +10,10 @@ package main
void test() {
xxx; // ERROR HERE
}
+
+// Issue 8442. Cgo output unhelpful error messages for
+// invalid C preambles.
+void issue8442foo(UNDEF*); // ERROR HERE
*/
import "C"
diff --git a/misc/cgo/errors/testdata/err2.go b/misc/cgo/errors/testdata/err2.go
index 3ab410bbaa..1d22401aee 100644
--- a/misc/cgo/errors/testdata/err2.go
+++ b/misc/cgo/errors/testdata/err2.go
@@ -4,10 +4,99 @@
package main
+/*
+#include <stdio.h>
+
+typedef struct foo foo_t;
+typedef struct bar bar_t;
+
+foo_t *foop;
+
+long double x = 0;
+
+static int transform(int x) { return x; }
+
+typedef void v;
+void F(v** p) {}
+
+void fvi(void *p, int x) {}
+
+void fppi(int** p) {}
+
+int i;
+void fi(int i) {}
+*/
import "C"
+import (
+ "unsafe"
+)
func main() {
s := ""
_ = s
C.malloc(s) // ERROR HERE
+
+ x := (*C.bar_t)(nil)
+ C.foop = x // ERROR HERE
+
+ // issue 13129: used to output error about C.unsignedshort with CC=clang
+ var x C.ushort
+ x = int(0) // ERROR HERE: C\.ushort
+
+ // issue 13423
+ _ = C.fopen() // ERROR HERE
+
+ // issue 13467
+ var x rune = '✈'
+ var _ rune = C.transform(x) // ERROR HERE: C\.int
+
+ // issue 13635: used to output error about C.unsignedchar.
+ // This test tests all such types.
+ var (
+ _ C.uchar = "uc" // ERROR HERE: C\.uchar
+ _ C.schar = "sc" // ERROR HERE: C\.schar
+ _ C.ushort = "us" // ERROR HERE: C\.ushort
+ _ C.uint = "ui" // ERROR HERE: C\.uint
+ _ C.ulong = "ul" // ERROR HERE: C\.ulong
+ _ C.longlong = "ll" // ERROR HERE: C\.longlong
+ _ C.ulonglong = "ull" // ERROR HERE: C\.ulonglong
+ _ C.complexfloat = "cf" // ERROR HERE: C\.complexfloat
+ _ C.complexdouble = "cd" // ERROR HERE: C\.complexdouble
+ )
+
+ // issue 13830
+ // cgo converts C void* to Go unsafe.Pointer, so despite appearances C
+ // void** is Go *unsafe.Pointer. This test verifies that we detect the
+ // problem at build time.
+ {
+ type v [0]byte
+
+ f := func(p **v) {
+ C.F((**C.v)(unsafe.Pointer(p))) // ERROR HERE
+ }
+ var p *v
+ f(&p)
+ }
+
+ // issue 16116
+ _ = C.fvi(1) // ERROR HERE
+
+ // Issue 16591: Test that we detect an invalid call that was being
+ // hidden by a type conversion inserted by cgo checking.
+ {
+ type x *C.int
+ var p *x
+ C.fppi(p) // ERROR HERE
+ }
+
+ // issue 26745
+ _ = func(i int) int {
+ return C.i + 1 // ERROR HERE: :13
+ }
+ _ = func(i int) {
+ C.fi(i) // ERROR HERE: :6
+ }
+
+ C.fi = C.fi // ERROR HERE
+
}
diff --git a/misc/cgo/errors/testdata/err3.go b/misc/cgo/errors/testdata/err3.go
deleted file mode 100644
index 609e1a0b74..0000000000
--- a/misc/cgo/errors/testdata/err3.go
+++ /dev/null
@@ -1,18 +0,0 @@
-// 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.
-
-package main
-
-/*
-typedef struct foo foo_t;
-typedef struct bar bar_t;
-
-foo_t *foop;
-*/
-import "C"
-
-func main() {
- x := (*C.bar_t)(nil)
- C.foop = x // ERROR HERE
-}
diff --git a/misc/cgo/errors/testdata/issue13129.go b/misc/cgo/errors/testdata/issue13129.go
deleted file mode 100644
index 057bce4b82..0000000000
--- a/misc/cgo/errors/testdata/issue13129.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2015 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.
-
-// issue 13129: used to output error about C.unsignedshort with CC=clang
-
-package main
-
-import "C"
-
-func main() {
- var x C.ushort
- x = int(0) // ERROR HERE: C\.ushort
-}
diff --git a/misc/cgo/errors/testdata/issue13423.go b/misc/cgo/errors/testdata/issue13423.go
deleted file mode 100644
index fc19157237..0000000000
--- a/misc/cgo/errors/testdata/issue13423.go
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2015 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.
-
-package main
-
-// #include <stdio.h>
-import "C"
-
-func main() {
- _ = C.fopen() // ERROR HERE
-}
diff --git a/misc/cgo/errors/testdata/issue13467.go b/misc/cgo/errors/testdata/issue13467.go
deleted file mode 100644
index e061880dda..0000000000
--- a/misc/cgo/errors/testdata/issue13467.go
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2017 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.
-
-package p
-
-/*
-static int transform(int x) { return x; }
-*/
-import "C"
-
-func F() {
- var x rune = '✈'
- var _ rune = C.transform(x) // ERROR HERE: C\.int
-}
diff --git a/misc/cgo/errors/testdata/issue13635.go b/misc/cgo/errors/testdata/issue13635.go
deleted file mode 100644
index 3f38f5df4b..0000000000
--- a/misc/cgo/errors/testdata/issue13635.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2015 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.
-
-// issue 13635: used to output error about C.unsignedchar.
-// This test tests all such types.
-
-package pkg
-
-import "C"
-
-func main() {
- var (
- _ C.uchar = "uc" // ERROR HERE: C\.uchar
- _ C.schar = "sc" // ERROR HERE: C\.schar
- _ C.ushort = "us" // ERROR HERE: C\.ushort
- _ C.uint = "ui" // ERROR HERE: C\.uint
- _ C.ulong = "ul" // ERROR HERE: C\.ulong
- _ C.longlong = "ll" // ERROR HERE: C\.longlong
- _ C.ulonglong = "ull" // ERROR HERE: C\.ulonglong
- _ C.complexfloat = "cf" // ERROR HERE: C\.complexfloat
- _ C.complexdouble = "cd" // ERROR HERE: C\.complexdouble
- )
-}
diff --git a/misc/cgo/errors/testdata/issue13830.go b/misc/cgo/errors/testdata/issue13830.go
deleted file mode 100644
index ac20c82b81..0000000000
--- a/misc/cgo/errors/testdata/issue13830.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2016 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.
-
-// cgo converts C void* to Go unsafe.Pointer, so despite appearances C
-// void** is Go *unsafe.Pointer. This test verifies that we detect the
-// problem at build time.
-
-package main
-
-// typedef void v;
-// void F(v** p) {}
-import "C"
-
-import "unsafe"
-
-type v [0]byte
-
-func f(p **v) {
- C.F((**C.v)(unsafe.Pointer(p))) // ERROR HERE
-}
-
-func main() {
- var p *v
- f(&p)
-}
diff --git a/misc/cgo/errors/testdata/issue16116.go b/misc/cgo/errors/testdata/issue16116.go
deleted file mode 100644
index 1e01cab844..0000000000
--- a/misc/cgo/errors/testdata/issue16116.go
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2016 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.
-
-package main
-
-// void f(void *p, int x) {}
-import "C"
-
-func main() {
- _ = C.f(1) // ERROR HERE
-}
diff --git a/misc/cgo/errors/testdata/issue16591.go b/misc/cgo/errors/testdata/issue16591.go
deleted file mode 100644
index 10eb8403cf..0000000000
--- a/misc/cgo/errors/testdata/issue16591.go
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2016 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.
-
-// Issue 16591: Test that we detect an invalid call that was being
-// hidden by a type conversion inserted by cgo checking.
-
-package p
-
-// void f(int** p) { }
-import "C"
-
-type x *C.int
-
-func F(p *x) {
- C.f(p) // ERROR HERE
-}
diff --git a/misc/cgo/errors/testdata/issue26745.go b/misc/cgo/errors/testdata/issue26745.go
deleted file mode 100644
index 0e224538db..0000000000
--- a/misc/cgo/errors/testdata/issue26745.go
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2018 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.
-
-package main
-
-// int a;
-// void CF(int i) {}
-import "C"
-
-func F1(i int) int {
- return C.a + 1 // ERROR HERE: :13
-}
-
-func F2(i int) {
- C.CF(i) // ERROR HERE: :6
-}
diff --git a/misc/cgo/errors/testdata/issue7757.go b/misc/cgo/errors/testdata/issue7757.go
deleted file mode 100644
index 0426e9fb7e..0000000000
--- a/misc/cgo/errors/testdata/issue7757.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// 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.
-
-package main
-
-/*
-void foo() {}
-*/
-import "C"
-
-func main() {
- C.foo = C.foo // ERROR HERE
-}
diff --git a/misc/cgo/errors/testdata/issue8442.go b/misc/cgo/errors/testdata/issue8442.go
deleted file mode 100644
index 60477ad345..0000000000
--- a/misc/cgo/errors/testdata/issue8442.go
+++ /dev/null
@@ -1,17 +0,0 @@
-// 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.
-
-package main
-
-// Issue 8442. Cgo output unhelpful error messages for
-// invalid C preambles.
-
-/*
-void issue8442foo(UNDEF*); // ERROR HERE
-*/
-import "C"
-
-func main() {
- C.issue8442foo(nil)
-}