mirror of https://github.com/golang/go.git
misc/cgo: re-enable some tests
The testso directory still needs to be enabled. R=golang-dev, r CC=golang-dev https://golang.org/cl/5731048
This commit is contained in:
parent
0bc18811b5
commit
c3f4319a24
|
|
@ -1,38 +0,0 @@
|
||||||
# Copyright 2009 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.
|
|
||||||
|
|
||||||
include ../../../src/Make.inc
|
|
||||||
|
|
||||||
TARG=gmp
|
|
||||||
|
|
||||||
# Can have plain GOFILES too, but this example doesn't.
|
|
||||||
|
|
||||||
CGOFILES=\
|
|
||||||
gmp.go
|
|
||||||
|
|
||||||
CGO_LDFLAGS=-lgmp
|
|
||||||
|
|
||||||
# To add flags necessary for locating the library or its include files,
|
|
||||||
# set CGO_CFLAGS or CGO_LDFLAGS. For example, to use an
|
|
||||||
# alternate installation of the library:
|
|
||||||
# CGO_CFLAGS=-I/home/rsc/gmp32/include
|
|
||||||
# CGO_LDFLAGS+=-L/home/rsc/gmp32/lib
|
|
||||||
# Note the += on the second line.
|
|
||||||
|
|
||||||
CLEANFILES+=pi fib
|
|
||||||
|
|
||||||
include ../../../src/Make.pkg
|
|
||||||
|
|
||||||
# Simple test programs
|
|
||||||
|
|
||||||
# Computes 1000 digits of pi; single-threaded.
|
|
||||||
pi: install pi.go
|
|
||||||
$(GC) $(GCFLAGS) $(GCIMPORTS) pi.go
|
|
||||||
$(LD) -o $@ pi.$O
|
|
||||||
|
|
||||||
# Computes 200 Fibonacci numbers; multi-threaded.
|
|
||||||
fib: install fib.go
|
|
||||||
$(GC) $(GCFLAGS) $(GCIMPORTS) fib.go
|
|
||||||
$(LD) -o $@ fib.$O
|
|
||||||
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
// Compute Fibonacci numbers with two goroutines
|
// Compute Fibonacci numbers with two goroutines
|
||||||
// that pass integers back and forth. No actual
|
// that pass integers back and forth. No actual
|
||||||
// concurrency, just threads and synchronization
|
// concurrency, just threads and synchronization
|
||||||
|
|
@ -10,7 +12,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
big "gmp"
|
big "."
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
@ -38,8 +40,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
big "."
|
||||||
"fmt"
|
"fmt"
|
||||||
big "gmp"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
# Copyright 2010 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.
|
|
||||||
|
|
||||||
include ../../../src/Make.inc
|
|
||||||
|
|
||||||
TARG=life
|
|
||||||
|
|
||||||
CGOFILES=\
|
|
||||||
life.go\
|
|
||||||
|
|
||||||
CGO_OFILES=\
|
|
||||||
c-life.o\
|
|
||||||
|
|
||||||
ifeq ($(GOOS),windows)
|
|
||||||
ifeq ($(GOARCH),amd64)
|
|
||||||
CGO_OFILES+=\
|
|
||||||
lib64_libmingwex_a-wassert.o\
|
|
||||||
lib64_libmingw32_a-mingw_helpers.o\
|
|
||||||
|
|
||||||
lib64_libmingwex_a-wassert.o:
|
|
||||||
ar -x /mingw/x86_64-w64-mingw32/lib/libmingwex.a lib64_libmingwex_a-wassert.o
|
|
||||||
|
|
||||||
lib64_libmingw32_a-mingw_helpers.o:
|
|
||||||
ar -x /mingw/x86_64-w64-mingw32/lib/libmingw32.a lib64_libmingw32_a-mingw_helpers.o
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
CLEANFILES+=life
|
|
||||||
|
|
||||||
include ../../../src/Make.pkg
|
|
||||||
|
|
||||||
life: install main.go
|
|
||||||
$(GC) $(GCFLAGS) $(GCIMPORTS) main.go
|
|
||||||
$(LD) -o $@ main.$O
|
|
||||||
|
|
@ -2,14 +2,16 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
// Run the game of life in C using Go for parallelization.
|
// Run the game of life in C using Go for parallelization.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"."
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"life"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const MAXDIM = 100
|
const MAXDIM = 100
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,11 @@
|
||||||
# license that can be found in the LICENSE file.
|
# license that can be found in the LICENSE file.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
gomake life
|
go build -o life main.go
|
||||||
|
|
||||||
echo '*' life >run.out
|
echo '*' life >run.out
|
||||||
./life >>run.out
|
./life >>run.out
|
||||||
diff run.out golden.out
|
diff run.out golden.out
|
||||||
gomake clean
|
|
||||||
|
rm -f life
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
# Copyright 2009 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.
|
|
||||||
|
|
||||||
include ../../../src/Make.inc
|
|
||||||
|
|
||||||
TARG=stdio
|
|
||||||
CGOFILES=\
|
|
||||||
file.go\
|
|
||||||
|
|
||||||
CLEANFILES+=hello fib chain run.out
|
|
||||||
|
|
||||||
include ../../../src/Make.pkg
|
|
||||||
|
|
||||||
%: install %.go
|
|
||||||
$(GC) $(GCFLAGS) $(GCIMPORTS) $*.go
|
|
||||||
$(LD) -o $@ $*.$O
|
|
||||||
|
|
@ -2,13 +2,15 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
// Pass numbers along a chain of threads.
|
// Pass numbers along a chain of threads.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"../stdio"
|
||||||
"runtime"
|
"runtime"
|
||||||
"stdio"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
// Compute Fibonacci numbers with two goroutines
|
// Compute Fibonacci numbers with two goroutines
|
||||||
// that pass integers back and forth. No actual
|
// that pass integers back and forth. No actual
|
||||||
// concurrency, just threads and synchronization
|
// concurrency, just threads and synchronization
|
||||||
|
|
@ -10,8 +12,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"../stdio"
|
||||||
"runtime"
|
"runtime"
|
||||||
"stdio"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ var Stderr = (*File)(C.stderr)
|
||||||
|
|
||||||
// Test reference to library symbol.
|
// Test reference to library symbol.
|
||||||
// Stdout and stderr are too special to be a reliable test.
|
// Stdout and stderr are too special to be a reliable test.
|
||||||
var myerr = C.sys_errlist
|
//var = C.environ
|
||||||
|
|
||||||
func (f *File) WriteString(s string) {
|
func (f *File) WriteString(s string) {
|
||||||
p := C.CString(s)
|
p := C.CString(s)
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "stdio"
|
import "../stdio"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
stdio.Stdout.WriteString(stdio.Greeting + "\n")
|
stdio.Stdout.WriteString(stdio.Greeting + "\n")
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@
|
||||||
# license that can be found in the LICENSE file.
|
# license that can be found in the LICENSE file.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
gomake hello fib chain
|
go build hello.go
|
||||||
|
go build fib.go
|
||||||
|
go build chain.go
|
||||||
|
|
||||||
echo '*' hello >run.out
|
echo '*' hello >run.out
|
||||||
./hello >>run.out
|
./hello >>run.out
|
||||||
echo '*' fib >>run.out
|
echo '*' fib >>run.out
|
||||||
|
|
@ -12,4 +15,6 @@ echo '*' fib >>run.out
|
||||||
echo '*' chain >>run.out
|
echo '*' chain >>run.out
|
||||||
./chain >>run.out
|
./chain >>run.out
|
||||||
diff run.out golden.out
|
diff run.out golden.out
|
||||||
gomake clean
|
|
||||||
|
rm -f hello fib chain
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ int add(int x, int y) {
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"os"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
@ -110,7 +110,7 @@ func testErrno(t *testing.T) {
|
||||||
C.fclose(f)
|
C.fclose(f)
|
||||||
t.Fatalf("C.fopen: should fail")
|
t.Fatalf("C.fopen: should fail")
|
||||||
}
|
}
|
||||||
if err != os.ENOENT {
|
if err != syscall.ENOENT {
|
||||||
t.Fatalf("C.fopen: unexpected error: %v", err)
|
t.Fatalf("C.fopen: unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,12 @@ package cgotest
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void callback(void *f);
|
void callback(void *f);
|
||||||
void callGoFoo(void) {
|
void callGoFoo(void);
|
||||||
extern void goFoo(void);
|
|
||||||
goFoo();
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"./backdoor"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
@ -43,7 +41,7 @@ func testCallbackGC(t *testing.T) {
|
||||||
nestedCall(runtime.GC)
|
nestedCall(runtime.GC)
|
||||||
}
|
}
|
||||||
|
|
||||||
func lockedOSThread() bool // in runtime.c
|
var lockedOSThread = backdoor.LockedOSThread
|
||||||
|
|
||||||
func testCallbackPanic(t *testing.T) {
|
func testCallbackPanic(t *testing.T) {
|
||||||
// Make sure panic during callback unwinds properly.
|
// Make sure panic during callback unwinds properly.
|
||||||
|
|
|
||||||
|
|
@ -15,3 +15,23 @@ callback(void *f)
|
||||||
goCallback(f);
|
goCallback(f);
|
||||||
data[sizeof(data)-1] = 0;
|
data[sizeof(data)-1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
callGoFoo(void)
|
||||||
|
{
|
||||||
|
extern void goFoo(void);
|
||||||
|
goFoo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
IntoC(void)
|
||||||
|
{
|
||||||
|
BackIntoGo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
twoSleep(int n)
|
||||||
|
{
|
||||||
|
BackgroundSleep(n);
|
||||||
|
sleep(n);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ package cgotest
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
// extern void BackIntoGo(void);
|
// extern void BackIntoGo(void);
|
||||||
// void IntoC() { BackIntoGo(); }
|
// void IntoC(void);
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
//export BackIntoGo
|
//export BackIntoGo
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,7 @@ package cgotest
|
||||||
unsigned int sleep(unsigned int seconds);
|
unsigned int sleep(unsigned int seconds);
|
||||||
|
|
||||||
extern void BackgroundSleep(int);
|
extern void BackgroundSleep(int);
|
||||||
void twoSleep(int n) {
|
void twoSleep(int);
|
||||||
BackgroundSleep(n);
|
|
||||||
sleep(n);
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,19 @@ static char *okgoos[] = {
|
||||||
"windows",
|
"windows",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// The known cgo-enabled combinations.
|
||||||
|
// This list is also known to ../../pkg/go/build/build.go.
|
||||||
|
static char *okcgo[] = {
|
||||||
|
"darwin/386",
|
||||||
|
"darwin/amd64",
|
||||||
|
"linux/386",
|
||||||
|
"linux/amd64",
|
||||||
|
"freebsd/386",
|
||||||
|
"freebsd/amd64",
|
||||||
|
"windows/386",
|
||||||
|
"windows/amd64",
|
||||||
|
};
|
||||||
|
|
||||||
static void rmworkdir(void);
|
static void rmworkdir(void);
|
||||||
|
|
||||||
// find reports the first index of p in l[0:n], or else -1.
|
// find reports the first index of p in l[0:n], or else -1.
|
||||||
|
|
@ -1308,6 +1321,11 @@ cmdenv(int argc, char **argv)
|
||||||
xprintf(format, "GOTOOLDIR", tooldir);
|
xprintf(format, "GOTOOLDIR", tooldir);
|
||||||
xprintf(format, "GOCHAR", gochar);
|
xprintf(format, "GOCHAR", gochar);
|
||||||
|
|
||||||
|
if(find(bprintf(&b, "%s/%s", goos, goarch), okcgo, nelem(okcgo)))
|
||||||
|
xprintf(format, "CGO_ENABLED", "1");
|
||||||
|
else
|
||||||
|
xprintf(format, "CGO_ENABLED", "0");
|
||||||
|
|
||||||
if(pflag) {
|
if(pflag) {
|
||||||
sep = ":";
|
sep = ":";
|
||||||
if(streq(gohostos, "windows"))
|
if(streq(gohostos, "windows"))
|
||||||
|
|
|
||||||
|
|
@ -210,6 +210,7 @@ func (ctxt *Context) SrcDirs() []string {
|
||||||
// if set, or else the compiled code's GOARCH, GOOS, and GOROOT.
|
// if set, or else the compiled code's GOARCH, GOOS, and GOROOT.
|
||||||
var Default Context = defaultContext()
|
var Default Context = defaultContext()
|
||||||
|
|
||||||
|
// This list is also known to ../../../cmd/dist/build.c.
|
||||||
var cgoEnabled = map[string]bool{
|
var cgoEnabled = map[string]bool{
|
||||||
"darwin/386": true,
|
"darwin/386": true,
|
||||||
"darwin/amd64": true,
|
"darwin/amd64": true,
|
||||||
|
|
|
||||||
10
src/run.bash
10
src/run.bash
|
|
@ -35,32 +35,26 @@ go test sync -short -timeout=120s -cpu=10
|
||||||
|
|
||||||
xcd() {
|
xcd() {
|
||||||
echo
|
echo
|
||||||
echo --- cd $1
|
echo '#' $1
|
||||||
builtin cd "$GOROOT"/src/$1
|
builtin cd "$GOROOT"/src/$1
|
||||||
}
|
}
|
||||||
|
|
||||||
BROKEN=true
|
BROKEN=true
|
||||||
|
|
||||||
$BROKEN ||
|
|
||||||
[ "$CGO_ENABLED" != 1 ] ||
|
[ "$CGO_ENABLED" != 1 ] ||
|
||||||
[ "$GOHOSTOS" == windows ] ||
|
[ "$GOHOSTOS" == windows ] ||
|
||||||
(xcd ../misc/cgo/stdio
|
(xcd ../misc/cgo/stdio
|
||||||
"$GOMAKE" clean
|
|
||||||
./test.bash
|
./test.bash
|
||||||
) || exit $?
|
) || exit $?
|
||||||
|
|
||||||
$BROKEN ||
|
|
||||||
[ "$CGO_ENABLED" != 1 ] ||
|
[ "$CGO_ENABLED" != 1 ] ||
|
||||||
(xcd ../misc/cgo/life
|
(xcd ../misc/cgo/life
|
||||||
"$GOMAKE" clean
|
|
||||||
./test.bash
|
./test.bash
|
||||||
) || exit $?
|
) || exit $?
|
||||||
|
|
||||||
$BROKEN ||
|
|
||||||
[ "$CGO_ENABLED" != 1 ] ||
|
[ "$CGO_ENABLED" != 1 ] ||
|
||||||
(xcd ../misc/cgo/test
|
(xcd ../misc/cgo/test
|
||||||
"$GOMAKE" clean
|
go test
|
||||||
gotest
|
|
||||||
) || exit $?
|
) || exit $?
|
||||||
|
|
||||||
$BROKEN ||
|
$BROKEN ||
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue