mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
misc/cgo/testcshared: test -buildmode=c-shared
Followed the same test pattern in misc/cgo/testcarchive. Change-Id: I2f863b5c24a28f0b38b0128ed3e8a92c17fb5b9f Reviewed-on: https://go-review.googlesource.com/8985 Reviewed-by: David Crawshaw <crawshaw@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
a5e48cf023
commit
92189a2be2
5 changed files with 188 additions and 0 deletions
47
misc/cgo/testcshared/src/libgo/libgo.go
Normal file
47
misc/cgo/testcshared/src/libgo/libgo.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright 2015 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 main
|
||||
|
||||
import (
|
||||
_ "p"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
import "C"
|
||||
|
||||
var initCh = make(chan int, 1)
|
||||
var ranMain bool
|
||||
|
||||
func init() {
|
||||
// emulate an exceedingly slow package initialization function
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
initCh <- 42
|
||||
}
|
||||
|
||||
func main() {
|
||||
ranMain = true
|
||||
panic("FAIL: main ran")
|
||||
}
|
||||
|
||||
//export DidInitRun
|
||||
func DidInitRun() bool {
|
||||
select {
|
||||
case x := <-initCh:
|
||||
if x != 42 {
|
||||
// Just in case initCh was not correctly made.
|
||||
println("want init value of 42, got: ", x)
|
||||
syscall.Exit(2)
|
||||
}
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
//export DidMainRun
|
||||
func DidMainRun() bool {
|
||||
return ranMain
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue