~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/bytes/equal_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
4
//
 
5
// +build linux
 
6
 
 
7
package bytes_test
 
8
 
 
9
import (
 
10
        . "bytes"
 
11
        "syscall"
 
12
        "testing"
 
13
        "unsafe"
 
14
)
 
15
 
 
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.
 
20
 
 
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
 
23
// operating systems.
 
24
 
 
25
func TestEqualNearPageBoundary(t *testing.T) {
 
26
        pagesize := syscall.Getpagesize()
 
27
        b := make([]byte, 4*pagesize)
 
28
        i := pagesize
 
29
        for ; uintptr(unsafe.Pointer(&b[i]))%uintptr(pagesize) != 0; i++ {
 
30
        }
 
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)
 
35
 
 
36
        // both of these should fault
 
37
        //pagesize += int(b[i-1])
 
38
        //pagesize += int(b[i+pagesize])
 
39
 
 
40
        for j := 0; j < pagesize; j++ {
 
41
                b[i+j] = 'A'
 
42
        }
 
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])
 
46
        }
 
47
}