From: Michael Munday Date: Wed, 30 Oct 2019 12:45:33 +0000 (+0000) Subject: runtime/internal/atomic: add tests for And8 and Or8 X-Git-Tag: go1.14beta1~490 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=10855608bc9361aec0f17f22bf24313a3d07ec85;p=gostls13.git runtime/internal/atomic: add tests for And8 and Or8 Add some simple unit tests for these atomic operations. These can't catch all the bugs that are possible with these operations but at least they provide some coverage. Change-Id: I94b9f451fcc9fecdb2a1448c5357b019563ad275 Reviewed-on: https://go-review.googlesource.com/c/go/+/204317 Run-TryBot: Michael Munday Reviewed-by: Austin Clements --- diff --git a/src/runtime/internal/atomic/atomic_test.go b/src/runtime/internal/atomic/atomic_test.go index 9e4461ce38..0c1125c558 100644 --- a/src/runtime/internal/atomic/atomic_test.go +++ b/src/runtime/internal/atomic/atomic_test.go @@ -103,3 +103,120 @@ func TestUnaligned64(t *testing.T) { shouldPanic(t, "Xchg64", func() { atomic.Xchg64(up64, 1) }) shouldPanic(t, "Cas64", func() { atomic.Cas64(up64, 1, 2) }) } + +func TestAnd8(t *testing.T) { + // Basic sanity check. + x := uint8(0xff) + for i := uint8(0); i < 8; i++ { + atomic.And8(&x, ^(1 << i)) + if r := uint8(0xff) << (i + 1); x != r { + t.Fatalf("clearing bit %#x: want %#x, got %#x", uint8(1<