diff options
Diffstat (limited to 'misc/cgo/test')
-rw-r--r-- | misc/cgo/test/callback_c_gc.c | 10 | ||||
-rw-r--r-- | misc/cgo/test/callback_c_gccgo.c | 7 | ||||
-rw-r--r-- | misc/cgo/test/cgo_test.go | 2 | ||||
-rw-r--r-- | misc/cgo/test/issue8517.go | 13 | ||||
-rw-r--r-- | misc/cgo/test/issue8517_windows.c | 24 | ||||
-rw-r--r-- | misc/cgo/test/issue8517_windows.go | 45 | ||||
-rw-r--r-- | misc/cgo/test/issue8811.c | 8 | ||||
-rw-r--r-- | misc/cgo/test/issue8811.go | 22 | ||||
-rw-r--r-- | misc/cgo/test/issue8828.go | 16 | ||||
-rw-r--r-- | misc/cgo/test/issue8828/issue8828.c | 7 | ||||
-rw-r--r-- | misc/cgo/test/issue8828/trivial.go | 8 |
11 files changed, 162 insertions, 0 deletions
diff --git a/misc/cgo/test/callback_c_gc.c b/misc/cgo/test/callback_c_gc.c index 32bfed0c0..28a62c6db 100644 --- a/misc/cgo/test/callback_c_gc.c +++ b/misc/cgo/test/callback_c_gc.c @@ -39,6 +39,16 @@ callCgoAllocate(void) int i; struct { size_t n; void *ret; } a; List *l, *head, **tail; + + // Make sure this doesn't crash. + // And make sure it returns non-nil. + a.n = 0; + a.ret = 0; + crosscall2(_cgo_allocate, &a, sizeof a); + if(a.ret == 0) { + fprintf(stderr, "callCgoAllocate: alloc 0 returned nil\n"); + exit(2); + } head = 0; tail = &head; diff --git a/misc/cgo/test/callback_c_gccgo.c b/misc/cgo/test/callback_c_gccgo.c index d92dca009..d367b7b68 100644 --- a/misc/cgo/test/callback_c_gccgo.c +++ b/misc/cgo/test/callback_c_gccgo.c @@ -35,6 +35,13 @@ callCgoAllocate(void) int i; List *l, *head, **tail; + // Make sure this doesn't crash. + // And make sure it returns non-nil. + if(_cgo_allocate(0) == 0) { + fprintf(stderr, "callCgoAllocate: alloc 0 returned nil\n"); + exit(2); + } + head = 0; tail = &head; for(i=0; i<100; i++) { diff --git a/misc/cgo/test/cgo_test.go b/misc/cgo/test/cgo_test.go index fcfad8304..3b289ba7b 100644 --- a/misc/cgo/test/cgo_test.go +++ b/misc/cgo/test/cgo_test.go @@ -58,6 +58,8 @@ func Test5242(t *testing.T) { test5242(t) } func Test8092(t *testing.T) { test8092(t) } func Test7978(t *testing.T) { test7978(t) } func Test8694(t *testing.T) { test8694(t) } +func Test8517(t *testing.T) { test8517(t) } +func Test8811(t *testing.T) { test8811(t) } func TestReturnAfterGrow(t *testing.T) { testReturnAfterGrow(t) } func TestReturnAfterGrowFromGo(t *testing.T) { testReturnAfterGrowFromGo(t) } diff --git a/misc/cgo/test/issue8517.go b/misc/cgo/test/issue8517.go new file mode 100644 index 000000000..4e431df92 --- /dev/null +++ b/misc/cgo/test/issue8517.go @@ -0,0 +1,13 @@ +// 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. + +// +build !windows + +package cgotest + +import "testing" + +func test8517(t *testing.T) { + t.Skip("skipping windows only test") +} diff --git a/misc/cgo/test/issue8517_windows.c b/misc/cgo/test/issue8517_windows.c new file mode 100644 index 000000000..a0b94c126 --- /dev/null +++ b/misc/cgo/test/issue8517_windows.c @@ -0,0 +1,24 @@ +// 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. + +#include "windows.h" + +extern void testHandleLeaksCallback(); + +DWORD WINAPI testHandleLeaksFunc(LPVOID lpThreadParameter) +{ + int i; + for(i = 0; i < 100; i++) { + testHandleLeaksCallback(); + } + return 0; +} + +void testHandleLeaks() +{ + HANDLE h; + h = CreateThread(NULL, 0, &testHandleLeaksFunc, 0, 0, NULL); + WaitForSingleObject(h, INFINITE); + CloseHandle(h); +} diff --git a/misc/cgo/test/issue8517_windows.go b/misc/cgo/test/issue8517_windows.go new file mode 100644 index 000000000..3782631e9 --- /dev/null +++ b/misc/cgo/test/issue8517_windows.go @@ -0,0 +1,45 @@ +// 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 cgotest + +//void testHandleLeaks(); +import "C" + +import ( + "syscall" + "testing" + "unsafe" +) + +var issue8517counter int + +var ( + kernel32 = syscall.MustLoadDLL("kernel32.dll") + getProcessHandleCount = kernel32.MustFindProc("GetProcessHandleCount") +) + +func processHandleCount(t *testing.T) int { + const current_process = ^uintptr(0) + var c uint32 + r, _, err := getProcessHandleCount.Call(current_process, uintptr(unsafe.Pointer(&c))) + if r == 0 { + t.Fatal(err) + } + return int(c) +} + +func test8517(t *testing.T) { + c1 := processHandleCount(t) + C.testHandleLeaks() + c2 := processHandleCount(t) + if c1+issue8517counter <= c2 { + t.Fatalf("too many handles leaked: issue8517counter=%v c1=%v c2=%v", issue8517counter, c1, c2) + } +} + +//export testHandleLeaksCallback +func testHandleLeaksCallback() { + issue8517counter++ +} diff --git a/misc/cgo/test/issue8811.c b/misc/cgo/test/issue8811.c new file mode 100644 index 000000000..584bb3934 --- /dev/null +++ b/misc/cgo/test/issue8811.c @@ -0,0 +1,8 @@ +// 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. + +int issue8811Initialized = 0; + +void issue8811Init() { +} diff --git a/misc/cgo/test/issue8811.go b/misc/cgo/test/issue8811.go new file mode 100644 index 000000000..2e217d935 --- /dev/null +++ b/misc/cgo/test/issue8811.go @@ -0,0 +1,22 @@ +// 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 cgotest + +/* +extern int issue8811Initialized; +extern void issue8811Init(); + +void issue8811Execute() { + if(!issue8811Initialized) + issue8811Init(); +} +*/ +import "C" + +import "testing" + +func test8811(t *testing.T) { + C.issue8811Execute() +} diff --git a/misc/cgo/test/issue8828.go b/misc/cgo/test/issue8828.go new file mode 100644 index 000000000..304797c92 --- /dev/null +++ b/misc/cgo/test/issue8828.go @@ -0,0 +1,16 @@ +// compile + +// 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. + +// Issue 8828: compiling a file with -compiler=gccgo fails if a .c file +// has the same name as compiled directory. + +package cgotest + +import "./issue8828" + +func p() { + issue8828.Bar() +} diff --git a/misc/cgo/test/issue8828/issue8828.c b/misc/cgo/test/issue8828/issue8828.c new file mode 100644 index 000000000..2950f87cf --- /dev/null +++ b/misc/cgo/test/issue8828/issue8828.c @@ -0,0 +1,7 @@ +// 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. + +void foo() +{ +} diff --git a/misc/cgo/test/issue8828/trivial.go b/misc/cgo/test/issue8828/trivial.go new file mode 100644 index 000000000..e7b9a4e57 --- /dev/null +++ b/misc/cgo/test/issue8828/trivial.go @@ -0,0 +1,8 @@ +package issue8828 + +//void foo(); +import "C" + +func Bar() { + C.foo() +} |