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) {
// forge argv[0] for child, so that we can verify we could correctly
// get real path of the executable without influenced by argv[0].
cmd.Args = []string{"-", "-test.run=XXXX"}
if runtime.GOOS == "openbsd" {
// OpenBSD relies on argv[0]
if runtime.GOOS == "openbsd" || runtime.GOOS == "aix" {
// OpenBSD and AIX rely on argv[0]
cmd.Args[0] = fn
}
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", executable_EnvVar))
......
......@@ -7,6 +7,7 @@
package os
import (
"runtime"
"syscall"
"time"
)
......@@ -19,6 +20,10 @@ func Readlink(name string) (string, error) {
for len := 128; ; len *= 2 {
b := make([]byte, len)
n, e := fixCount(syscall.Readlink(fixLongPath(name), b))
// buffer too small
if runtime.GOOS == "aix" && e == syscall.ERANGE {
continue
}
if e != nil {
return "", &PathError{"readlink", name, e}
}
......
......@@ -1493,7 +1493,11 @@ func runBinHostname(t *testing.T) string {
}
defer r.Close()
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 := Stat(path); IsNotExist(err) {
t.Skipf("skipping test; test requires %s but it does not exist", path)
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// 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
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !aix
// +build !darwin
// +build !dragonfly
// +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