github.com/mattn/go@v0.0.0-20171011075504-07f7db3ea99f/misc/cgo/testplugin/test.bash (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2016 The Go Authors. All rights reserved.
     3  # Use of this source code is governed by a BSD-style
     4  # license that can be found in the LICENSE file.
     5  
     6  set -e
     7  
     8  if [ ! -f src/host/host.go ]; then
     9  	cwd=$(pwd)
    10  	echo "misc/cgo/testplugin/test.bash is running in $cwd" 1>&2
    11  	exit 1
    12  fi
    13  
    14  goos=$(go env GOOS)
    15  goarch=$(go env GOARCH)
    16  
    17  function cleanup() {
    18  	rm -f plugin*.so unnamed*.so iface*.so issue*
    19  	rm -rf host pkg sub iface
    20  }
    21  trap cleanup EXIT
    22  
    23  rm -rf pkg sub
    24  mkdir sub
    25  
    26  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin plugin1
    27  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin plugin2
    28  cp plugin2.so plugin2-dup.so
    29  GOPATH=$(pwd)/altpath go build -gcflags "$GO_GCFLAGS" -buildmode=plugin plugin-mismatch
    30  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o=sub/plugin1.so sub/plugin1
    31  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o=unnamed1.so unnamed1/main.go
    32  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o=unnamed2.so unnamed2/main.go
    33  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" host
    34  
    35  LD_LIBRARY_PATH=$(pwd) ./host
    36  
    37  # Test that types and itabs get properly uniqified.
    38  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin iface_a
    39  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin iface_b
    40  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" iface
    41  LD_LIBRARY_PATH=$(pwd) ./iface
    42  
    43  function _timeout() (
    44  	set -e
    45  	$2 &
    46  	p=$!
    47  	(sleep $1; kill $p 2>/dev/null) &
    48  	p2=$!
    49  	wait $p 2>/dev/null
    50  	kill -0 $p2 2>/dev/null
    51  )
    52  
    53  # Test for issue 18676 - make sure we don't add the same itab twice.
    54  # The buggy code hangs forever, so use a timeout to check for that.
    55  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o plugin.so src/issue18676/plugin.go
    56  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue18676 src/issue18676/main.go
    57  _timeout 10s ./issue18676
    58  
    59  # Test for issue 19534 - that we can load a plugin built in a path with non-alpha
    60  # characters
    61  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -ldflags='-pluginpath=issue.19534' -o plugin.so src/issue19534/plugin.go
    62  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue19534 src/issue19534/main.go
    63  ./issue19534
    64  
    65  # Test for issue 18584
    66  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o plugin.so src/issue18584/plugin.go
    67  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue18584 src/issue18584/main.go
    68  ./issue18584
    69  
    70  # Test for issue 19418
    71  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin "-ldflags=-X main.Val=linkstr" -o plugin.so src/issue19418/plugin.go
    72  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue19418 src/issue19418/main.go
    73  ./issue19418
    74  
    75  # Test for issue 19529
    76  GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o plugin.so src/issue19529/plugin.go