diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
commit | b09c6d56832eb1718c07d74abf3bc6ae3fe4e030 (patch) | |
tree | d2caec2610d4ea887803ec9e9c3cd77136c448ba /dependencies/pkg/mod/golang.org/x/sys@v0.1.0/unix/sysvshm_unix_test.go | |
parent | Initial commit. (diff) | |
download | icingadb-upstream.tar.xz icingadb-upstream.zip |
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dependencies/pkg/mod/golang.org/x/sys@v0.1.0/unix/sysvshm_unix_test.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/golang.org/x/sys@v0.1.0/unix/sysvshm_unix_test.go b/dependencies/pkg/mod/golang.org/x/sys@v0.1.0/unix/sysvshm_unix_test.go new file mode 100644 index 0000000..c1eff8d --- /dev/null +++ b/dependencies/pkg/mod/golang.org/x/sys@v0.1.0/unix/sysvshm_unix_test.go @@ -0,0 +1,79 @@ +// 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 +// +build darwin,amd64 linux + +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 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 len(b2) != 1024 { + t.Fatalf("b2 len = %v, want 1024", len(b1)) + } + + 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") + } +} |