Prechádzať zdrojové kódy

unix: fix or skip failing tests on android and iOS

The mkfifo syscall is disallowed on android and iOS. sched_setaffinity
is disallowed on android. Skip all tests which use them.

/usr/bin does not exist on android. Use /system/bin in TestGetwd
instead, like TestChdirAndGetwd in the os package.

Like linux, android does not support Fchmodat with flags != 0. Adjust
TestFchmodat accordingly.

TestDevices might stat some device files which are not accessible, skip
those.

iOS cannot exec subprocesses, thus skip TestPassFD.

Fixes golang/go#25535

Change-Id: Ic764b9152f0a7b703ad4f47fdb1a9a5e94718154
Reviewed-on: https://go-review.googlesource.com/114395
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Tobias Klauser 7 rokov pred
rodič
commit
04b83988a0

+ 3 - 0
unix/dev_linux_test.go

@@ -33,6 +33,9 @@ func TestDevices(t *testing.T) {
 			var stat unix.Stat_t
 			err := unix.Stat(tc.path, &stat)
 			if err != nil {
+				if err == unix.EACCES {
+					t.Skip("no permission to stat device, skipping test")
+				}
 				t.Errorf("failed to stat device: %v", err)
 				return
 			}

+ 7 - 0
unix/syscall_linux_test.go

@@ -32,6 +32,10 @@ func TestIoctlGetInt(t *testing.T) {
 }
 
 func TestPpoll(t *testing.T) {
+	if runtime.GOOS == "android" {
+		t.Skip("mkfifo syscall is not available on android, skipping test")
+	}
+
 	f, cleanup := mktmpfifo(t)
 	defer cleanup()
 
@@ -259,6 +263,9 @@ func TestSchedSetaffinity(t *testing.T) {
 	if runtime.NumCPU() < 2 {
 		t.Skip("skipping setaffinity tests on single CPU system")
 	}
+	if runtime.GOOS == "android" {
+		t.Skip("skipping setaffinity tests on android")
+	}
 
 	err = unix.SchedSetaffinity(0, &newMask)
 	if err != nil {

+ 14 - 2
unix/syscall_unix_test.go

@@ -125,6 +125,10 @@ func TestFcntlFlock(t *testing.T) {
 // "-test.run=^TestPassFD$" and an environment variable used to signal
 // that the test should become the child process instead.
 func TestPassFD(t *testing.T) {
+	if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
+		t.Skip("cannot exec subprocess on iOS, skipping test")
+	}
+
 	if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" {
 		passFDChild()
 		return
@@ -390,6 +394,11 @@ func TestDup(t *testing.T) {
 }
 
 func TestPoll(t *testing.T) {
+	if runtime.GOOS == "android" ||
+		(runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64")) {
+		t.Skip("mkfifo syscall is not available on android and iOS, skipping test")
+	}
+
 	f, cleanup := mktmpfifo(t)
 	defer cleanup()
 
@@ -426,7 +435,10 @@ func TestGetwd(t *testing.T) {
 	// These are chosen carefully not to be symlinks on a Mac
 	// (unlike, say, /var, /etc)
 	dirs := []string{"/", "/usr/bin"}
-	if runtime.GOOS == "darwin" {
+	switch runtime.GOOS {
+	case "android":
+		dirs = []string{"/", "/system/bin"}
+	case "darwin":
 		switch runtime.GOARCH {
 		case "arm", "arm64":
 			d1, err := ioutil.TempDir("", "d1")
@@ -534,7 +546,7 @@ func TestFchmodat(t *testing.T) {
 	didChmodSymlink := true
 	err = unix.Fchmodat(unix.AT_FDCWD, "symlink1", uint32(mode), unix.AT_SYMLINK_NOFOLLOW)
 	if err != nil {
-		if (runtime.GOOS == "linux" || runtime.GOOS == "solaris") && err == unix.EOPNOTSUPP {
+		if (runtime.GOOS == "android" || runtime.GOOS == "linux" || runtime.GOOS == "solaris") && err == unix.EOPNOTSUPP {
 			// Linux and Illumos don't support flags != 0
 			didChmodSymlink = false
 		} else {