mirror of
https://github.com/golang/sys.git
synced 2026-02-08 11:46:04 +03:00
This commit ports unix package for aix/ppc64 with gc implementation. In order to merge as much as possible gc and gccgo implementation, the mksyscall_aix_ppc64.pl creates three files. zsyscall_aix_ppc64.go is common for both implementation. It has the main syscall function and handles the pointer creations, type conversions and the error if needed. It calls a function "call..." which is available for each implementation. zsyscall_aix_ppc64_gc.go is the gc part. It implements "call..." functions using //go:cgo_import_dynamic and //go:linkname. It is based on syscall.syscall6 function. zsyscall_aix_ppc64_gccgo.go is the gccgo part. It implements "call..." functions using cgo and C functions. Some unavailable syscalls were also removed from the previous implementation. For aix/ppc, the script is left unchanged as aix/ppc won't be implemented inside gc. Change-Id: I3701095df31517c66f95874ba8e682967993090b Reviewed-on: https://go-review.googlesource.com/c/143117 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
163 lines
3.5 KiB
Go
163 lines
3.5 KiB
Go
// Copyright 2018 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 aix
|
|
|
|
package unix_test
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
"testing"
|
|
"time"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func TestIoctlGetInt(t *testing.T) {
|
|
f, err := os.Open("/dev/random")
|
|
if err != nil {
|
|
t.Fatalf("failed to open device: %v", err)
|
|
}
|
|
defer f.Close()
|
|
|
|
v, err := unix.IoctlGetInt(int(f.Fd()), unix.RNDGETENTCNT)
|
|
if err != nil {
|
|
t.Fatalf("failed to perform ioctl: %v", err)
|
|
}
|
|
|
|
t.Logf("%d bits of entropy available", v)
|
|
}
|
|
|
|
func TestTime(t *testing.T) {
|
|
var ut unix.Time_t
|
|
ut2, err := unix.Time(&ut)
|
|
if err != nil {
|
|
t.Fatalf("Time: %v", err)
|
|
}
|
|
if ut != ut2 {
|
|
t.Errorf("Time: return value %v should be equal to argument %v", ut2, ut)
|
|
}
|
|
|
|
var now time.Time
|
|
|
|
for i := 0; i < 10; i++ {
|
|
ut, err = unix.Time(nil)
|
|
if err != nil {
|
|
t.Fatalf("Time: %v", err)
|
|
}
|
|
|
|
now = time.Now()
|
|
|
|
if int64(ut) == now.Unix() {
|
|
return
|
|
}
|
|
}
|
|
|
|
t.Errorf("Time: return value %v should be nearly equal to time.Now().Unix() %v", ut, now.Unix())
|
|
}
|
|
|
|
func TestUtime(t *testing.T) {
|
|
defer chtmpdir(t)()
|
|
|
|
touch(t, "file1")
|
|
|
|
buf := &unix.Utimbuf{
|
|
Modtime: 12345,
|
|
}
|
|
|
|
err := unix.Utime("file1", buf)
|
|
if err != nil {
|
|
t.Fatalf("Utime: %v", err)
|
|
}
|
|
|
|
fi, err := os.Stat("file1")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if fi.ModTime().Unix() != 12345 {
|
|
t.Errorf("Utime: failed to change modtime: expected %v, got %v", 12345, fi.ModTime().Unix())
|
|
}
|
|
}
|
|
|
|
func TestUtimesNanoAt(t *testing.T) {
|
|
defer chtmpdir(t)()
|
|
|
|
symlink := "symlink1"
|
|
defer os.Remove(symlink)
|
|
err := os.Symlink("nonexisting", symlink)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ts := []unix.Timespec{
|
|
{Sec: 1111, Nsec: 2222},
|
|
{Sec: 3333, Nsec: 4444},
|
|
}
|
|
err = unix.UtimesNanoAt(unix.AT_FDCWD, symlink, ts, unix.AT_SYMLINK_NOFOLLOW)
|
|
if err != nil {
|
|
t.Fatalf("UtimesNanoAt: %v", err)
|
|
}
|
|
|
|
var st unix.Stat_t
|
|
err = unix.Lstat(symlink, &st)
|
|
if err != nil {
|
|
t.Fatalf("Lstat: %v", err)
|
|
}
|
|
if runtime.GOARCH == "ppc64" {
|
|
if int64(st.Atim.Sec) != int64(ts[0].Sec) || st.Atim.Nsec != int32(ts[0].Nsec) {
|
|
t.Errorf("UtimesNanoAt: wrong atime: %v", st.Atim)
|
|
}
|
|
if int64(st.Mtim.Sec) != int64(ts[1].Sec) || st.Mtim.Nsec != int32(ts[1].Nsec) {
|
|
t.Errorf("UtimesNanoAt: wrong mtime: %v", st.Mtim)
|
|
}
|
|
} else {
|
|
if int32(st.Atim.Sec) != int32(ts[0].Sec) || int32(st.Atim.Nsec) != int32(ts[0].Nsec) {
|
|
t.Errorf("UtimesNanoAt: wrong atime: %v", st.Atim)
|
|
}
|
|
if int32(st.Mtim.Sec) != int32(ts[1].Sec) || int32(st.Mtim.Nsec) != int32(ts[1].Nsec) {
|
|
t.Errorf("UtimesNanoAt: wrong mtime: %v", st.Mtim)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPselect(t *testing.T) {
|
|
if runtime.GOARCH == "ppc64" {
|
|
t.Skip("pselect issue with structure timespec on AIX 7.2 tl0, skipping test")
|
|
}
|
|
|
|
_, err := unix.Pselect(0, nil, nil, nil, &unix.Timespec{Sec: 0, Nsec: 0}, nil)
|
|
if err != nil {
|
|
t.Fatalf("Pselect: %v", err)
|
|
}
|
|
|
|
dur := 2500 * time.Microsecond
|
|
ts := unix.NsecToTimespec(int64(dur))
|
|
start := time.Now()
|
|
_, err = unix.Pselect(0, nil, nil, nil, &ts, nil)
|
|
took := time.Since(start)
|
|
if err != nil {
|
|
t.Fatalf("Pselect: %v", err)
|
|
}
|
|
|
|
if took < dur {
|
|
t.Errorf("Pselect: timeout should have been at least %v, got %v", dur, took)
|
|
}
|
|
}
|
|
|
|
// stringsFromByteSlice converts a sequence of attributes to a []string.
|
|
// On Linux, each entry is a NULL-terminated string.
|
|
func stringsFromByteSlice(buf []byte) []string {
|
|
var result []string
|
|
off := 0
|
|
for i, b := range buf {
|
|
if b == 0 {
|
|
result = append(result, string(buf[off:i]))
|
|
off = i + 1
|
|
}
|
|
}
|
|
return result
|
|
}
|