Commit db9e15e6 authored by Clément Chigot's avatar Clément Chigot Committed by Brad Fitzpatrick

os: fix tests for AIX

This commits fixes tests for AIX inside os package.

"hostname" command on AIX returns "name.domain" and not only "name".
So, "hostname -s" must be called.

Change-Id: I75e193bcb6ad607ce54ad99aabbed9839012f707
Reviewed-on: https://go-review.googlesource.com/c/144537Reviewed-by: 's avatarTobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 43530e6b
...@@ -36,8 +36,8 @@ func TestExecutable(t *testing.T) { ...@@ -36,8 +36,8 @@ func TestExecutable(t *testing.T) {
// forge argv[0] for child, so that we can verify we could correctly // forge argv[0] for child, so that we can verify we could correctly
// get real path of the executable without influenced by argv[0]. // get real path of the executable without influenced by argv[0].
cmd.Args = []string{"-", "-test.run=XXXX"} cmd.Args = []string{"-", "-test.run=XXXX"}
if runtime.GOOS == "openbsd" { if runtime.GOOS == "openbsd" || runtime.GOOS == "aix" {
// OpenBSD relies on argv[0] // OpenBSD and AIX rely on argv[0]
cmd.Args[0] = fn cmd.Args[0] = fn
} }
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", executable_EnvVar)) cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", executable_EnvVar))
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package os package os
import ( import (
"runtime"
"syscall" "syscall"
"time" "time"
) )
...@@ -19,6 +20,10 @@ func Readlink(name string) (string, error) { ...@@ -19,6 +20,10 @@ func Readlink(name string) (string, error) {
for len := 128; ; len *= 2 { for len := 128; ; len *= 2 {
b := make([]byte, len) b := make([]byte, len)
n, e := fixCount(syscall.Readlink(fixLongPath(name), b)) n, e := fixCount(syscall.Readlink(fixLongPath(name), b))
// buffer too small
if runtime.GOOS == "aix" && e == syscall.ERANGE {
continue
}
if e != nil { if e != nil {
return "", &PathError{"readlink", name, e} return "", &PathError{"readlink", name, e}
} }
......
...@@ -1493,7 +1493,11 @@ func runBinHostname(t *testing.T) string { ...@@ -1493,7 +1493,11 @@ func runBinHostname(t *testing.T) string {
} }
defer r.Close() defer r.Close()
const path = "/bin/hostname" const path = "/bin/hostname"
p, err := StartProcess(path, []string{"hostname"}, &ProcAttr{Files: []*File{nil, w, Stderr}}) argv := []string{"hostname"}
if runtime.GOOS == "aix" {
argv = []string{"hostname", "-s"}
}
p, err := StartProcess(path, argv, &ProcAttr{Files: []*File{nil, w, Stderr}})
if err != nil { if err != nil {
if _, err := Stat(path); IsNotExist(err) { if _, err := Stat(path); IsNotExist(err) {
t.Skipf("skipping test; test requires %s but it does not exist", path) t.Skipf("skipping test; test requires %s but it does not exist", path)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// 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 darwin dragonfly freebsd netbsd openbsd solaris // +build aix darwin dragonfly freebsd netbsd openbsd solaris
package os package os
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// 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 !aix
// +build !darwin // +build !darwin
// +build !dragonfly // +build !dragonfly
// +build !freebsd // +build !freebsd
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment