Skip to content

Commit 9b69196

Browse files
committed
runtime: add TestCgoDLLImports
The test is a simple reproduction of issue 9356. Update #8948. Update #9356. Change-Id: Ia77bc36d12ed0c3c4a8b1214cade8be181c9ad55 Reviewed-on: https://go-review.googlesource.com/7618 Reviewed-by: Minux Ma <[email protected]>
1 parent 21aad02 commit 9b69196

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

src/runtime/crash_cgo_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ func TestCgoExternalThreadSIGPROF(t *testing.T) {
8282
}
8383
}
8484

85+
func TestCgoDLLImports(t *testing.T) {
86+
// test issue 9356
87+
if runtime.GOOS != "windows" {
88+
t.Skip("skipping windows specific test")
89+
}
90+
got := executeTest(t, cgoDLLImportsMainSource, nil, "a/a.go", cgoDLLImportsPkgSource)
91+
want := "OK\n"
92+
if got != want {
93+
t.Fatalf("expected %q, but got %v", want, got)
94+
}
95+
}
96+
8597
const cgoSignalDeadlockSource = `
8698
package main
8799
@@ -269,3 +281,43 @@ func main() {
269281
println("OK")
270282
}
271283
`
284+
285+
const cgoDLLImportsMainSource = `
286+
package main
287+
288+
/*
289+
#include <windows.h>
290+
291+
DWORD getthread() {
292+
return GetCurrentThreadId();
293+
}
294+
*/
295+
import "C"
296+
297+
import "./a"
298+
299+
func main() {
300+
C.getthread()
301+
a.GetThread()
302+
println("OK")
303+
}
304+
`
305+
306+
const cgoDLLImportsPkgSource = `
307+
package a
308+
309+
/*
310+
#cgo CFLAGS: -mnop-fun-dllimport
311+
312+
#include <windows.h>
313+
314+
DWORD agetthread() {
315+
return GetCurrentThreadId();
316+
}
317+
*/
318+
import "C"
319+
320+
func GetThread() uint32 {
321+
return uint32(C.agetthread())
322+
}
323+
`

src/runtime/crash_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ func executeTest(t *testing.T, templ string, data interface{}, extra ...string)
7272
}
7373

7474
for i := 0; i < len(extra); i += 2 {
75-
if err := ioutil.WriteFile(filepath.Join(dir, extra[i]), []byte(extra[i+1]), 0666); err != nil {
75+
fname := extra[i]
76+
contents := extra[i+1]
77+
if d, _ := filepath.Split(fname); d != "" {
78+
if err := os.Mkdir(filepath.Join(dir, d), 0755); err != nil {
79+
t.Fatal(err)
80+
}
81+
}
82+
if err := ioutil.WriteFile(filepath.Join(dir, fname), []byte(contents), 0666); err != nil {
7683
t.Fatal(err)
7784
}
7885
}

0 commit comments

Comments
 (0)