aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/syscall/syscall_unix_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2015-10-31 00:59:47 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2015-10-31 00:59:47 +0000
commitaf146490bb04205107cb23e301ec7a8ff927b5fc (patch)
tree13beeaed3698c61903fe93fb1ce70bd9b18d4e7f /libgo/go/syscall/syscall_unix_test.go
parent725e1be3406315d9bcc8195d7eef0a7082b3c7cc (diff)
downloadgcc-af146490bb04205107cb23e301ec7a8ff927b5fc.zip
gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.tar.gz
gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.tar.bz2
runtime: Remove now unnecessary pad field from ParFor.
It is not needed due to the removal of the ctx field. Reviewed-on: https://go-review.googlesource.com/16525 From-SVN: r229616
Diffstat (limited to 'libgo/go/syscall/syscall_unix_test.go')
-rw-r--r--libgo/go/syscall/syscall_unix_test.go70
1 files changed, 54 insertions, 16 deletions
diff --git a/libgo/go/syscall/syscall_unix_test.go b/libgo/go/syscall/syscall_unix_test.go
index 897ad18..c7b4560 100644
--- a/libgo/go/syscall/syscall_unix_test.go
+++ b/libgo/go/syscall/syscall_unix_test.go
@@ -9,6 +9,7 @@ package syscall_test
import (
"flag"
"fmt"
+ "internal/testenv"
"io/ioutil"
"net"
"os"
@@ -60,20 +61,58 @@ func _() {
// TestFcntlFlock tests whether the file locking structure matches
// the calling convention of each kernel.
+// On some Linux systems, glibc uses another set of values for the
+// commands and translates them to the correct value that the kernel
+// expects just before the actual fcntl syscall. As Go uses raw
+// syscalls directly, it must use the real value, not the glibc value.
+// Thus this test also verifies that the Flock_t structure can be
+// roundtripped with F_SETLK and F_GETLK.
func TestFcntlFlock(t *testing.T) {
- name := filepath.Join(os.TempDir(), "TestFcntlFlock")
- fd, err := syscall.Open(name, syscall.O_CREAT|syscall.O_RDWR|syscall.O_CLOEXEC, 0)
- if err != nil {
- t.Fatalf("Open failed: %v", err)
+ if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
+ t.Skip("skipping; no child processes allowed on iOS")
}
- defer syscall.Unlink(name)
- defer syscall.Close(fd)
flock := syscall.Flock_t{
- Type: syscall.F_RDLCK,
- Start: 0, Len: 0, Whence: 1,
+ Type: syscall.F_WRLCK,
+ Start: 31415, Len: 271828, Whence: 1,
}
- if err := syscall.FcntlFlock(uintptr(fd), syscall.F_GETLK, &flock); err != nil {
- t.Fatalf("FcntlFlock failed: %v", err)
+ if os.Getenv("GO_WANT_HELPER_PROCESS") == "" {
+ // parent
+ name := filepath.Join(os.TempDir(), "TestFcntlFlock")
+ fd, err := syscall.Open(name, syscall.O_CREAT|syscall.O_RDWR|syscall.O_CLOEXEC, 0)
+ if err != nil {
+ t.Fatalf("Open failed: %v", err)
+ }
+ defer syscall.Unlink(name)
+ defer syscall.Close(fd)
+ if err := syscall.Ftruncate(fd, 1<<20); err != nil {
+ t.Fatalf("Ftruncate(1<<20) failed: %v", err)
+ }
+ if err := syscall.FcntlFlock(uintptr(fd), syscall.F_SETLK, &flock); err != nil {
+ t.Fatalf("FcntlFlock(F_SETLK) failed: %v", err)
+ }
+ cmd := exec.Command(os.Args[0], "-test.run=^TestFcntlFlock$")
+ cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
+ cmd.ExtraFiles = []*os.File{os.NewFile(uintptr(fd), name)}
+ out, err := cmd.CombinedOutput()
+ if len(out) > 0 || err != nil {
+ t.Fatalf("child process: %q, %v", out, err)
+ }
+ } else {
+ // child
+ got := flock
+ // make sure the child lock is conflicting with the parent lock
+ got.Start--
+ got.Len++
+ if err := syscall.FcntlFlock(3, syscall.F_GETLK, &got); err != nil {
+ t.Fatalf("FcntlFlock(F_GETLK) failed: %v", err)
+ }
+ flock.Pid = int32(syscall.Getppid())
+ // Linux kernel always set Whence to 0
+ flock.Whence = 0
+ if got.Type == flock.Type && got.Start == flock.Start && got.Len == flock.Len && got.Pid == flock.Pid && got.Whence == flock.Whence {
+ os.Exit(0)
+ }
+ t.Fatalf("FcntlFlock got %v, want %v", got, flock)
}
}
@@ -93,6 +132,9 @@ func TestPassFD(t *testing.T) {
// TODO(aram): Figure out why ReadMsgUnix is returning empty message.
t.Skip("skipping test on solaris, see issue 7402")
}
+
+ testenv.MustHaveExec(t)
+
if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" {
passFDChild()
return
@@ -116,11 +158,7 @@ func TestPassFD(t *testing.T) {
defer readFile.Close()
cmd := exec.Command(os.Args[0], "-test.run=^TestPassFD$", "--", tempDir)
- cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
- path := os.Getenv("LD_LIBRARY_PATH")
- if path != "" {
- cmd.Env = append(cmd.Env, "LD_LIBRARY_PATH="+path)
- }
+ cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
cmd.ExtraFiles = []*os.File{writeFile}
out, err := cmd.CombinedOutput()
@@ -179,7 +217,7 @@ func passFDChild() {
defer os.Exit(0)
// Look for our fd. It should be fd 3, but we work around an fd leak
- // bug here (http://golang.org/issue/2603) to let it be elsewhere.
+ // bug here (https://golang.org/issue/2603) to let it be elsewhere.
var uc *net.UnixConn
for fd := uintptr(3); fd <= 10; fd++ {
f := os.NewFile(fd, "unix-conn")