diff options
author | Carlos Amedee <carlos@golang.org> | 2023-01-10 13:50:39 -0500 |
---|---|---|
committer | Carlos Amedee <carlos@golang.org> | 2023-01-10 13:50:39 -0500 |
commit | 7058c2cb4132291e1b6c9498a9a6f13a9a70ff85 (patch) | |
tree | 7701af5d953be20ade9ca141c562b3262c703716 /src/runtime/internal/atomic/atomic_test.go | |
parent | fc1ed37e824b2f87e287e1bc4597253f1b30b3b3 (diff) | |
parent | 581603cb7d02019bbf4ff508014038f3120a3dcb (diff) | |
download | go-dev.boringcrypto.go1.18.tar.gz go-dev.boringcrypto.go1.18.zip |
[dev.boringcrypto.go1.18] all: merge go1.18.10 into dev.boringcrypto.go1.18dev.boringcrypto.go1.18
Change-Id: I0dcc4e288cba62382f6bd06b2cf0ff843309220c
Diffstat (limited to 'src/runtime/internal/atomic/atomic_test.go')
-rw-r--r-- | src/runtime/internal/atomic/atomic_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/runtime/internal/atomic/atomic_test.go b/src/runtime/internal/atomic/atomic_test.go index 2ae60b8507..2427bfd211 100644 --- a/src/runtime/internal/atomic/atomic_test.go +++ b/src/runtime/internal/atomic/atomic_test.go @@ -345,6 +345,36 @@ func TestBitwiseContended(t *testing.T) { } } +func TestCasRel(t *testing.T) { + const _magic = 0x5a5aa5a5 + var x struct { + before uint32 + i uint32 + after uint32 + o uint32 + n uint32 + } + + x.before = _magic + x.after = _magic + for j := 0; j < 32; j += 1 { + x.i = (1 << j) + 0 + x.o = (1 << j) + 0 + x.n = (1 << j) + 1 + if !atomic.CasRel(&x.i, x.o, x.n) { + t.Fatalf("should have swapped %#x %#x", x.o, x.n) + } + + if x.i != x.n { + t.Fatalf("wrong x.i after swap: x.i=%#x x.n=%#x", x.i, x.n) + } + + if x.before != _magic || x.after != _magic { + t.Fatalf("wrong magic: %#x _ %#x != %#x _ %#x", x.before, x.after, _magic, _magic) + } + } +} + func TestStorepNoWB(t *testing.T) { var p [2]*int for i := range p { |