]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: consolidate test cases for Unix-like systems
authorMikio Hara <mikioh.mikioh@gmail.com>
Mon, 24 Feb 2014 05:41:10 +0000 (14:41 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Mon, 24 Feb 2014 05:41:10 +0000 (14:41 +0900)
As per request from minux in CL 61520049, this CL consolidates
existing test cases for Unix-like systems into one file except
Linux-specific credential test.

LGTM=bradfitz
R=iant, minux.ma, bradfitz
CC=golang-codereviews
https://golang.org/cl/67800044

src/pkg/syscall/consistency_unix_test.go [deleted file]
src/pkg/syscall/rlimit_unix_test.go [deleted file]
src/pkg/syscall/syscall_unix_test.go [moved from src/pkg/syscall/passfd_test.go with 73% similarity]

diff --git a/src/pkg/syscall/consistency_unix_test.go b/src/pkg/syscall/consistency_unix_test.go
deleted file mode 100644 (file)
index 6c9fb82..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2013 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.
-
-// +build freebsd dragonfly darwin linux netbsd openbsd
-
-// This file tests that some basic syscalls are consistent across
-// all Unixes.
-
-package syscall_test
-
-import "syscall"
-
-// {Set,Get}priority and needed constants for them
-func _() {
-       var (
-               _ func(int, int, int) error   = syscall.Setpriority
-               _ func(int, int) (int, error) = syscall.Getpriority
-       )
-       const (
-               _ int = syscall.PRIO_USER
-               _ int = syscall.PRIO_PROCESS
-               _ int = syscall.PRIO_PGRP
-       )
-}
-
-// termios functions and constants
-func _() {
-       const (
-               _ int = syscall.TCIFLUSH
-               _ int = syscall.TCIOFLUSH
-               _ int = syscall.TCOFLUSH
-       )
-}
-
-func _() {
-       _ = syscall.Flock_t{
-               Type:   int16(0),
-               Whence: int16(0),
-               Start:  int64(0),
-               Len:    int64(0),
-               Pid:    int32(0),
-       }
-}
diff --git a/src/pkg/syscall/rlimit_unix_test.go b/src/pkg/syscall/rlimit_unix_test.go
deleted file mode 100644 (file)
index fc9b026..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2013 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.
-
-// +build darwin dragonfly freebsd linux netbsd openbsd
-
-package syscall_test
-
-import (
-       "runtime"
-       "syscall"
-       "testing"
-)
-
-func TestRlimit(t *testing.T) {
-       var rlimit, zero syscall.Rlimit
-       err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit)
-       if err != nil {
-               t.Fatalf("Getrlimit: save failed: %v", err)
-       }
-       if zero == rlimit {
-               t.Fatalf("Getrlimit: save failed: got zero value %#v", rlimit)
-       }
-       set := rlimit
-       set.Cur = set.Max - 1
-       err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &set)
-       if err != nil {
-               t.Fatalf("Setrlimit: set failed: %#v %v", set, err)
-       }
-       var get syscall.Rlimit
-       err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &get)
-       if err != nil {
-               t.Fatalf("Getrlimit: get failed: %v", err)
-       }
-       set = rlimit
-       set.Cur = set.Max - 1
-       if set != get {
-               // Seems like Darwin requires some privilege to
-               // increase the soft limit of rlimit sandbox, though
-               // Setrlimit never reports an error.
-               switch runtime.GOOS {
-               case "darwin":
-               default:
-                       t.Fatalf("Rlimit: change failed: wanted %#v got %#v", set, get)
-               }
-       }
-       err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)
-       if err != nil {
-               t.Fatalf("Setrlimit: restore failed: %#v %v", rlimit, err)
-       }
-}
similarity index 73%
rename from src/pkg/syscall/passfd_test.go
rename to src/pkg/syscall/syscall_unix_test.go
index 53c7a1ffa49ceb5e1fd4f1dfa48d37c7fdd8e4ec..818dda839de9b34310a185bb5dc6d1a9f4aea12a 100644 (file)
@@ -1,8 +1,11 @@
-// Copyright 2012 The Go Authors. All rights reserved.
+// Copyright 2013 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.
 
-// +build linux dragonfly darwin freebsd netbsd openbsd
+// +build freebsd dragonfly darwin linux netbsd openbsd
+
+// This file tests that some basic syscalls are consistent across
+// all Unixes.
 
 package syscall_test
 
@@ -19,6 +22,38 @@ import (
        "time"
 )
 
+// {Set,Get}priority and needed constants for them
+func _() {
+       var (
+               _ func(int, int, int) error   = syscall.Setpriority
+               _ func(int, int) (int, error) = syscall.Getpriority
+       )
+       const (
+               _ int = syscall.PRIO_USER
+               _ int = syscall.PRIO_PROCESS
+               _ int = syscall.PRIO_PGRP
+       )
+}
+
+// termios functions and constants
+func _() {
+       const (
+               _ int = syscall.TCIFLUSH
+               _ int = syscall.TCIOFLUSH
+               _ int = syscall.TCOFLUSH
+       )
+}
+
+func _() {
+       _ = syscall.Flock_t{
+               Type:   int16(0),
+               Whence: int16(0),
+               Start:  int64(0),
+               Len:    int64(0),
+               Pid:    int32(0),
+       }
+}
+
 // TestPassFD tests passing a file descriptor over a Unix socket.
 //
 // This test involved both a parent and child process. The parent
@@ -29,7 +64,7 @@ import (
 func TestPassFD(t *testing.T) {
        if runtime.GOOS == "dragonfly" {
                // TODO(jsing): Figure out why sendmsg is returning EINVAL.
-               t.Skip("Skipping test on dragonfly")
+               t.Skip("skipping test on dragonfly")
        }
        if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" {
                passFDChild()
@@ -200,3 +235,41 @@ func TestUnixRightsRoundtrip(t *testing.T) {
                }
        }
 }
+
+func TestRlimit(t *testing.T) {
+       var rlimit, zero syscall.Rlimit
+       err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit)
+       if err != nil {
+               t.Fatalf("Getrlimit: save failed: %v", err)
+       }
+       if zero == rlimit {
+               t.Fatalf("Getrlimit: save failed: got zero value %#v", rlimit)
+       }
+       set := rlimit
+       set.Cur = set.Max - 1
+       err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &set)
+       if err != nil {
+               t.Fatalf("Setrlimit: set failed: %#v %v", set, err)
+       }
+       var get syscall.Rlimit
+       err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &get)
+       if err != nil {
+               t.Fatalf("Getrlimit: get failed: %v", err)
+       }
+       set = rlimit
+       set.Cur = set.Max - 1
+       if set != get {
+               // Seems like Darwin requires some privilege to
+               // increase the soft limit of rlimit sandbox, though
+               // Setrlimit never reports an error.
+               switch runtime.GOOS {
+               case "darwin":
+               default:
+                       t.Fatalf("Rlimit: change failed: wanted %#v got %#v", set, get)
+               }
+       }
+       err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)
+       if err != nil {
+               t.Fatalf("Setrlimit: restore failed: %#v %v", rlimit, err)
+       }
+}