annotate libgo/misc/cgo/test/issue8517_windows.go @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // Copyright 2014 The Go Authors. All rights reserved.
kono
parents:
diff changeset
2 // Use of this source code is governed by a BSD-style
kono
parents:
diff changeset
3 // license that can be found in the LICENSE file.
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 package cgotest
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 //void testHandleLeaks();
kono
parents:
diff changeset
8 import "C"
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 import (
kono
parents:
diff changeset
11 "syscall"
kono
parents:
diff changeset
12 "testing"
kono
parents:
diff changeset
13 "unsafe"
kono
parents:
diff changeset
14 )
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 var issue8517counter int
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 var (
kono
parents:
diff changeset
19 kernel32 = syscall.MustLoadDLL("kernel32.dll")
kono
parents:
diff changeset
20 getProcessHandleCount = kernel32.MustFindProc("GetProcessHandleCount")
kono
parents:
diff changeset
21 )
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 func processHandleCount(t *testing.T) int {
kono
parents:
diff changeset
24 const current_process = ^uintptr(0)
kono
parents:
diff changeset
25 var c uint32
kono
parents:
diff changeset
26 r, _, err := getProcessHandleCount.Call(current_process, uintptr(unsafe.Pointer(&c)))
kono
parents:
diff changeset
27 if r == 0 {
kono
parents:
diff changeset
28 t.Fatal(err)
kono
parents:
diff changeset
29 }
kono
parents:
diff changeset
30 return int(c)
kono
parents:
diff changeset
31 }
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 func test8517(t *testing.T) {
kono
parents:
diff changeset
34 c1 := processHandleCount(t)
kono
parents:
diff changeset
35 C.testHandleLeaks()
kono
parents:
diff changeset
36 c2 := processHandleCount(t)
kono
parents:
diff changeset
37 if c1+issue8517counter <= c2 {
kono
parents:
diff changeset
38 t.Fatalf("too many handles leaked: issue8517counter=%v c1=%v c2=%v", issue8517counter, c1, c2)
kono
parents:
diff changeset
39 }
kono
parents:
diff changeset
40 }
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 //export testHandleLeaksCallback
kono
parents:
diff changeset
43 func testHandleLeaksCallback() {
kono
parents:
diff changeset
44 issue8517counter++
kono
parents:
diff changeset
45 }