...

Source file src/cmd/cgo/internal/test/issue8517_windows.go

Documentation: cmd/cgo/internal/test

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

View as plain text