Commit 798e0b38 authored by Russ Cox's avatar Russ Cox

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: default avatarIan Lance Taylor <iant@golang.org>
parent b8648184
......@@ -63,7 +63,7 @@ func expect(t *testing.T, file string, errors []*regexp.Regexp) {
defer os.RemoveAll(dir)
dst := filepath.Join(dir, strings.TrimSuffix(file, ".go"))
cmd := exec.Command("go", "build", "-gcflags=-L", "-o="+dst, path(file)) // TODO(gri) no need for -gcflags=-L if go tool is adjusted
cmd := exec.Command("go", "build", "-gcflags=-L -e", "-o="+dst, path(file)) // TODO(gri) no need for -gcflags=-L if go tool is adjusted
out, err := cmd.CombinedOutput()
if err == nil {
t.Errorf("expected cgo to fail but it succeeded")
......@@ -107,21 +107,10 @@ func TestReportsTypeErrors(t *testing.T) {
for _, file := range []string{
"err1.go",
"err2.go",
"err3.go",
"issue7757.go",
"issue8442.go",
"issue11097a.go",
"issue11097b.go",
"issue13129.go",
"issue13423.go",
"issue13467.go",
"issue13635.go",
"issue13830.go",
"issue16116.go",
"issue16591.go",
"issue18452.go",
"issue18889.go",
"issue26745.go",
"issue28721.go",
} {
check(t, file)
......
This diff is collapsed.
......@@ -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"
......
......@@ -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
}
// 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
}
// 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
}
// 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
}
// 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
}
// 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
)
}
// 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)
}
// 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
}
// 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
}
// 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
}
// 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
}
// 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)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment