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

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // Copyright 2012 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 // +build !windows
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 package cgotest
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 /*
kono
parents:
diff changeset
10 #include <dlfcn.h>
kono
parents:
diff changeset
11 #cgo linux LDFLAGS: -ldl
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 extern void call4029(void *arg);
kono
parents:
diff changeset
14 */
kono
parents:
diff changeset
15 import "C"
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 import (
kono
parents:
diff changeset
18 "testing"
kono
parents:
diff changeset
19 )
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 var callbacks int
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 //export IMPIsOpaque
kono
parents:
diff changeset
24 func IMPIsOpaque() {
kono
parents:
diff changeset
25 callbacks++
kono
parents:
diff changeset
26 }
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 //export IMPInitWithFrame
kono
parents:
diff changeset
29 func IMPInitWithFrame() {
kono
parents:
diff changeset
30 callbacks++
kono
parents:
diff changeset
31 }
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 //export IMPDrawRect
kono
parents:
diff changeset
34 func IMPDrawRect() {
kono
parents:
diff changeset
35 callbacks++
kono
parents:
diff changeset
36 }
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 //export IMPWindowResize
kono
parents:
diff changeset
39 func IMPWindowResize() {
kono
parents:
diff changeset
40 callbacks++
kono
parents:
diff changeset
41 }
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 func test4029(t *testing.T) {
kono
parents:
diff changeset
44 loadThySelf(t, "IMPWindowResize")
kono
parents:
diff changeset
45 loadThySelf(t, "IMPDrawRect")
kono
parents:
diff changeset
46 loadThySelf(t, "IMPInitWithFrame")
kono
parents:
diff changeset
47 loadThySelf(t, "IMPIsOpaque")
kono
parents:
diff changeset
48 if callbacks != 4 {
kono
parents:
diff changeset
49 t.Errorf("got %d callbacks, expected 4", callbacks)
kono
parents:
diff changeset
50 }
kono
parents:
diff changeset
51 }
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 func loadThySelf(t *testing.T, symbol string) {
kono
parents:
diff changeset
54 this_process := C.dlopen(nil, C.RTLD_NOW)
kono
parents:
diff changeset
55 if this_process == nil {
kono
parents:
diff changeset
56 t.Error("dlopen:", C.GoString(C.dlerror()))
kono
parents:
diff changeset
57 return
kono
parents:
diff changeset
58 }
kono
parents:
diff changeset
59 defer C.dlclose(this_process)
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 symbol_address := C.dlsym(this_process, C.CString(symbol))
kono
parents:
diff changeset
62 if symbol_address == nil {
kono
parents:
diff changeset
63 t.Error("dlsym:", C.GoString(C.dlerror()))
kono
parents:
diff changeset
64 return
kono
parents:
diff changeset
65 }
kono
parents:
diff changeset
66 t.Log(symbol, symbol_address)
kono
parents:
diff changeset
67 C.call4029(symbol_address)
kono
parents:
diff changeset
68 }