Home | History | Annotate | Download | only in patch
      1 misc/cgo/testcshared: add support for -target.
      2 
      3 --- misc/cgo/testcshared/test.bash
      4 +++ misc/cgo/testcshared/test.bash
      5 @@ -14,9 +14,23 @@ if [ ! -f src/libgo/libgo.go ]; then
      6  	exit 1
      7  fi
      8  
      9 -goos=$(go env GOOS)
     10 -goarch=$(go env GOARCH)
     11 -goroot=$(go env GOROOT)
     12 +function target()
     13 +	{
     14 +	[[ -n "${target}" ]]
     15 +	}
     16 +
     17 +function go_target()
     18 +	{
     19 +	if target; then
     20 +		go_${target} "$@"
     21 +	else
     22 +		go "$@"
     23 +	fi
     24 +	}
     25 +
     26 +goos=$(go_target env GOOS)
     27 +goarch=$(go_target env GOARCH)
     28 +goroot=$(go_target env GOROOT)
     29  if [ ! -d "$goroot" ]; then
     30  	echo 'misc/cgo/testcshared/test.bash cannnot find GOROOT' 1>&2
     31  	echo '$GOROOT:' "$GOROOT" 1>&2
     32 @@ -31,8 +45,10 @@ if [ "${goos}" == "darwin" ]; then
     33  	installdir=pkg/${goos}_${goarch}_testcshared
     34  fi
     35  
     36 -# Temporary directory on the android device.
     37 -androidpath=/data/local/tmp/testcshared-$$
     38 +# Temporary directory on the android/chromeos device.
     39 +if target; then
     40 +	remotepath=$(target_tmpdir)/testcshared-$$
     41 +fi
     42  
     43  function cleanup() {
     44  	rm -f libgo.$libext libgo2.$libext libgo4.$libext libgo5.$libext
     45 @@ -40,37 +56,33 @@ function cleanup() {
     46  	rm -f testp testp2 testp3 testp4 testp5
     47  	rm -rf pkg "${goroot}/${installdir}"
     48  
     49 -	if [ "$goos" == "android" ]; then
     50 -		adb shell rm -rf "$androidpath"
     51 +	if target; then
     52 +		target_sh "${target}" "rm -rf $remotepath"
     53  	fi
     54  }
     55  trap cleanup EXIT
     56  
     57 -if [ "$goos" == "android" ]; then
     58 -	adb shell mkdir -p "$androidpath"
     59 +if target; then
     60 +	target_sh "${target}" "mkdir -p $remotepath"
     61  fi
     62  
     63  function run() {
     64 -	case "$goos" in
     65 -	"android")
     66 +	if target; then
     67  		local args=$@
     68 -		output=$(adb shell "cd ${androidpath}; $@")
     69 -		output=$(echo $output|tr -d '\r')
     70 +		output=$(target_sh "${target}" "cd ${remotepath}; $@")
     71  		case $output in
     72  			*PASS) echo "PASS";; 
     73  			*) echo "$output";;
     74  		esac
     75 -		;;
     76 -	*)
     77 +	else
     78  		echo $(env $@)
     79 -		;;
     80 -	esac
     81 +	fi
     82  }
     83  
     84  function binpush() {
     85  	bin=${1}
     86 -	if [ "$goos" == "android" ]; then
     87 -		adb push "$bin"  "${androidpath}/${bin}" 2>/dev/null
     88 +	if target; then
     89 +		target_cp "$bin" "${target}:${remotepath}/${bin}"
     90  	fi
     91  }
     92  
     93 @@ -84,9 +96,9 @@ if [ "$goos" == "darwin" ]; then
     94  fi
     95  
     96  # Create the header files.
     97 -GOPATH=$(pwd) go install -buildmode=c-shared $suffix libgo
     98 +GOPATH=$(pwd) go_target install -buildmode=c-shared $suffix libgo
     99  
    100 -GOPATH=$(pwd) go build -buildmode=c-shared $suffix -o libgo.$libext src/libgo/libgo.go
    101 +GOPATH=$(pwd) go_target build -buildmode=c-shared $suffix -o libgo.$libext src/libgo/libgo.go
    102  binpush libgo.$libext
    103  
    104  if [ "$goos" == "linux" ] || [ "$goos" == "android" ] ; then
    105 @@ -96,8 +108,8 @@ if [ "$goos" == "linux" ] || [ "$goos" == "android" ] ; then
    106      fi
    107  fi
    108  
    109 -GOGCCFLAGS=$(go env GOGCCFLAGS)
    110 -if [ "$goos" == "android" ]; then
    111 +GOGCCFLAGS=$(go_target env GOGCCFLAGS)
    112 +if target; then
    113  	GOGCCFLAGS="${GOGCCFLAGS} -pie"
    114  fi
    115  
    116 @@ -105,7 +117,7 @@ status=0
    117  
    118  # test0: exported symbols in shared lib are accessible.
    119  # TODO(iant): using _shared here shouldn't really be necessary.
    120 -$(go env CC) ${GOGCCFLAGS} -I ${installdir} -o testp main0.c libgo.$libext
    121 +$(go_target env CC) ${GOGCCFLAGS} -I ${installdir} -o testp main0.c libgo.$libext
    122  binpush testp
    123  
    124  output=$(run LD_LIBRARY_PATH=. ./testp)
    125 @@ -115,7 +127,7 @@ if [ "$output" != "PASS" ]; then
    126  fi
    127  
    128  # test1: shared library can be dynamically loaded and exported symbols are accessible.
    129 -$(go env CC) ${GOGCCFLAGS} -o testp main1.c -ldl
    130 +$(go_target env CC) ${GOGCCFLAGS} -o testp main1.c -ldl
    131  binpush testp
    132  output=$(run ./testp ./libgo.$libext)
    133  if [ "$output" != "PASS" ]; then
    134 @@ -124,13 +136,13 @@ if [ "$output" != "PASS" ]; then
    135  fi
    136  
    137  # test2: tests libgo2 which does not export any functions.
    138 -GOPATH=$(pwd) go build -buildmode=c-shared $suffix -o libgo2.$libext libgo2
    139 +GOPATH=$(pwd) go_target build -buildmode=c-shared $suffix -o libgo2.$libext libgo2
    140  binpush libgo2.$libext
    141  linkflags="-Wl,--no-as-needed"
    142  if [ "$goos" == "darwin" ]; then
    143  	linkflags=""
    144  fi
    145 -$(go env CC) ${GOGCCFLAGS} -o testp2 main2.c $linkflags libgo2.$libext
    146 +$(go_target env CC) ${GOGCCFLAGS} -o testp2 main2.c $linkflags libgo2.$libext
    147  binpush testp2
    148  output=$(run LD_LIBRARY_PATH=. ./testp2)
    149  if [ "$output" != "PASS" ]; then
    150 @@ -138,9 +150,9 @@ if [ "$output" != "PASS" ]; then
    151  	status=1
    152  fi
    153  
    154 -# test3: tests main.main is exported on android.
    155 -if [ "$goos" == "android" ]; then
    156 -	$(go env CC) ${GOGCCFLAGS} -o testp3 main3.c -ldl
    157 +# test3: tests main.main is exported on android/chromeos.
    158 +if target; then
    159 +	$(go_target env CC) ${GOGCCFLAGS} -o testp3 main3.c -ldl
    160  	binpush testp3
    161  	output=$(run ./testp ./libgo.so)
    162  	if [ "$output" != "PASS" ]; then
    163 @@ -150,14 +162,14 @@ if [ "$goos" == "android" ]; then
    164  fi
    165  
    166  # test4: tests signal handlers
    167 -GOPATH=$(pwd) go build -buildmode=c-shared $suffix -o libgo4.$libext libgo4
    168 +GOPATH=$(pwd) go_target build -buildmode=c-shared $suffix -o libgo4.$libext libgo4
    169  binpush libgo4.$libext
    170 -$(go env CC) ${GOGCCFLAGS} -pthread -o testp4 main4.c -ldl
    171 +$(go_target env CC) ${GOGCCFLAGS} -pthread -o testp4 main4.c -ldl
    172  binpush testp4
    173  output=$(run ./testp4 ./libgo4.$libext 2>&1)
    174  if test "$output" != "PASS"; then
    175      echo "FAIL test4 got ${output}"
    176 -    if test "$goos" != "android"; then
    177 +    if ! target; then
    178  	echo "re-running test4 in verbose mode"
    179  	./testp4 ./libgo4.$libext verbose
    180      fi
    181 @@ -165,14 +177,14 @@ if test "$output" != "PASS"; then
    182  fi
    183  
    184  # test5: tests signal handlers with os/signal.Notify
    185 -GOPATH=$(pwd) go build -buildmode=c-shared $suffix -o libgo5.$libext libgo5
    186 +GOPATH=$(pwd) go_target build -buildmode=c-shared $suffix -o libgo5.$libext libgo5
    187  binpush libgo5.$libext
    188 -$(go env CC) ${GOGCCFLAGS} -pthread -o testp5 main5.c -ldl
    189 +$(go_target env CC) ${GOGCCFLAGS} -pthread -o testp5 main5.c -ldl
    190  binpush testp5
    191  output=$(run ./testp5 ./libgo5.$libext 2>&1)
    192  if test "$output" != "PASS"; then
    193      echo "FAIL test5 got ${output}"
    194 -    if test "$goos" != "android"; then
    195 +    if ! target; then
    196  	echo "re-running test5 in verbose mode"
    197  	./testp5 ./libgo5.$libext verbose
    198      fi
    199