aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/internal/atomic
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-11-12 05:58:52 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2016-11-12 06:38:40 +0000
commit37020dd510cf7da36e9eb1827a20890234e4ea79 (patch)
tree5bfaee8f22a6341f1bbcb0e964160eabd024db8c /src/runtime/internal/atomic
parentc921d8f39d6da1afd1550787464d27f015412194 (diff)
downloadgo-37020dd510cf7da36e9eb1827a20890234e4ea79.tar.xz
runtime/internal/atomic: add TestUnaligned64
Add a variant of sync/atomic's TestUnaligned64 to runtime/internal/atomic. Skips the test on arm for now where it's currently failing. Updates #17786 Change-Id: If63f9c1243e9db7b243a95205b2d27f7d1dc1e6e Reviewed-on: https://go-review.googlesource.com/33159 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/internal/atomic')
-rw-r--r--src/runtime/internal/atomic/atomic_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/runtime/internal/atomic/atomic_test.go b/src/runtime/internal/atomic/atomic_test.go
index d0a39a1433..c5fbc1a495 100644
--- a/src/runtime/internal/atomic/atomic_test.go
+++ b/src/runtime/internal/atomic/atomic_test.go
@@ -66,3 +66,39 @@ func TestXadduintptrOnUint64(t *testing.T) {
t.Fatalf("xadduintptr should increase lower-order bits, want %d, got %d", inc, val)
}
}
+
+func shouldPanic(t *testing.T, name string, f func()) {
+ defer func() {
+ if recover() == nil {
+ t.Errorf("%s did not panic", name)
+ }
+ }()
+ f()
+}
+
+// Variant of sync/atomic's TestUnaligned64:
+func TestUnaligned64(t *testing.T) {
+ // Unaligned 64-bit atomics on 32-bit systems are
+ // a continual source of pain. Test that on 32-bit systems they crash
+ // instead of failing silently.
+
+ switch runtime.GOARCH {
+ default:
+ if unsafe.Sizeof(int(0)) != 4 {
+ t.Skip("test only runs on 32-bit systems")
+ }
+ case "arm":
+ t.Skipf("TODO: implement. golang.org/issue/17786")
+ case "amd64p32", "mips", "mipsle":
+ // amd64p32 and mips can handle unaligned atomics.
+ t.Skipf("test not needed on %v", runtime.GOARCH)
+ }
+
+ x := make([]uint32, 4)
+ up64 := (*uint64)(unsafe.Pointer(&x[1])) // misaligned
+ p64 := (*int64)(unsafe.Pointer(&x[1])) // misaligned
+
+ shouldPanic(t, "Load64", func() { atomic.Load64(up64) })
+ shouldPanic(t, "Loadint64", func() { atomic.Loadint64(p64) })
+ shouldPanic(t, "Store64", func() { atomic.Store64(up64, 0) })
+}