mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-28 04:46:44 -04:00
This change syncs the IBM internal version of sys/unix with the public repository. There are a variety of new syscalls and const definitions that have been accumulated over the past few years to support developers using Go on the platform. Old simulations of calls like 'epoll' and 'fstatfs' have been replaced with their real counterparts. The zos/s390x syscalls also have extensive trampolining to handle zos systems that might not have support for some of these new system calls. Closes golang/go#67071 Change-Id: I973d9e0abca2b05365308cf2b890438e50ae5957 Reviewed-on: https://go-review.googlesource.com/c/sys/+/582035 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Bill O'Farrell <billotosyr@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
94 lines
2.0 KiB
Go
94 lines
2.0 KiB
Go
// Copyright 2021 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.
|
|
|
|
//go:build (darwin && amd64) || linux || zos
|
|
|
|
package unix_test
|
|
|
|
import (
|
|
"runtime"
|
|
"testing"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func TestSysvSharedMemory(t *testing.T) {
|
|
// create ipc
|
|
id, err := unix.SysvShmGet(unix.IPC_PRIVATE, 1024, unix.IPC_CREAT|unix.IPC_EXCL|0o600)
|
|
|
|
// ipc isn't implemented on android, should fail
|
|
if runtime.GOOS == "android" {
|
|
if err != unix.ENOSYS {
|
|
t.Fatalf("expected android to fail, but it didn't")
|
|
}
|
|
return
|
|
}
|
|
|
|
// The kernel may have been built without System V IPC support.
|
|
if err == unix.ENOSYS {
|
|
t.Skip("shmget not supported")
|
|
}
|
|
|
|
if err != nil {
|
|
t.Fatalf("SysvShmGet: %v", err)
|
|
}
|
|
defer func() {
|
|
_, err := unix.SysvShmCtl(id, unix.IPC_RMID, nil)
|
|
if err != nil {
|
|
t.Errorf("Remove failed: %v", err)
|
|
}
|
|
}()
|
|
|
|
// attach
|
|
b1, err := unix.SysvShmAttach(id, 0, 0)
|
|
if err != nil {
|
|
t.Fatalf("Attach: %v", err)
|
|
}
|
|
|
|
if runtime.GOOS == "zos" {
|
|
// The minimum shared memory size is no less than units of 1M bytes in z/OS
|
|
if len(b1) < 1024 {
|
|
t.Fatalf("b1 len = %v, less than 1024", len(b1))
|
|
}
|
|
} else {
|
|
if len(b1) != 1024 {
|
|
t.Fatalf("b1 len = %v, want 1024", len(b1))
|
|
}
|
|
}
|
|
|
|
b1[42] = 'x'
|
|
|
|
// attach again
|
|
b2, err := unix.SysvShmAttach(id, 0, 0)
|
|
if err != nil {
|
|
t.Fatalf("Attach: %v", err)
|
|
}
|
|
|
|
if runtime.GOOS == "zos" {
|
|
// The returned shared memory alligns with the pagesize.
|
|
// If pagesize is not 1024 bytes, the shared memory could be larger
|
|
if len(b2) < 1024 {
|
|
t.Fatalf("b1 len = %v, less than 1024", len(b2))
|
|
}
|
|
} else {
|
|
if len(b2) != 1024 {
|
|
t.Fatalf("b1 len = %v, want 1024", len(b2))
|
|
}
|
|
}
|
|
|
|
b2[43] = 'y'
|
|
if b2[42] != 'x' || b1[43] != 'y' {
|
|
t.Fatalf("shared memory isn't shared")
|
|
}
|
|
|
|
// detach
|
|
if err = unix.SysvShmDetach(b2); err != nil {
|
|
t.Fatalf("Detach: %v", err)
|
|
}
|
|
|
|
if b1[42] != 'x' || b1[43] != 'y' {
|
|
t.Fatalf("shared memory was invalidated")
|
|
}
|
|
}
|