1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
16 // This file tests the situation where memeq is checking
17 // data very near to a page boundary. We want to make sure
18 // equal does not read across the boundary and cause a page
19 // fault where it shouldn't.
21 // This test runs only on linux. The code being tested is
22 // not OS-specific, so it does not need to be tested on all
25 func TestEqualNearPageBoundary(t
*testing
.T
) {
26 pagesize
:= syscall
.Getpagesize()
27 b
:= make([]byte, 4*pagesize
)
29 for ; uintptr(unsafe
.Pointer(&b
[i
]))%uintptr
(pagesize
) != 0; i
++ {
31 syscall
.Mprotect(b
[i
-pagesize
:i
], 0)
32 syscall
.Mprotect(b
[i
+pagesize
:i
+2*pagesize
], 0)
33 defer syscall
.Mprotect(b
[i
-pagesize
:i
], syscall
.PROT_READ|syscall
.PROT_WRITE
)
34 defer syscall
.Mprotect(b
[i
+pagesize
:i
+2*pagesize
], syscall
.PROT_READ|syscall
.PROT_WRITE
)
36 // both of these should fault
37 //pagesize += int(b[i-1])
38 //pagesize += int(b[i+pagesize])
40 for j
:= 0; j
< pagesize
; j
++ {
43 for j
:= 0; j
<= pagesize
; j
++ {
44 Equal(b
[i
:i
+j
], b
[i
+pagesize
-j
:i
+pagesize
])
45 Equal(b
[i
+pagesize
-j
:i
+pagesize
], b
[i
:i
+j
])